3131 07/02/2022 : Added Português do Brasil translation (PR by mac-sousa)
3232 26/11/2022 : Fixed PHP8.1 warnings
3333 13/12/2022 : Fixed PHP7 with str_contains polyfill
34+ 05/01/2025 : Added support for interwiki links (#35)
3435
3536 @author ThisNameIsNotAllowed
3637 17/11/2016 : Added generation of metadata
4344 18/08/2023 : Fixed deprecation warnings in PHP 8+ (#33)
4445
4546 Knwon bugs:
46- - interwiki syntax not supported
47- - handle / render repartition is not optimal regarding cachind, most of the processing should be moved (#14)
47+ - handle / render repartition is not optimal regarding caching, most of the processing should be moved (#14)
4848*/
4949
5050
@@ -342,9 +342,22 @@ function render($mode, Doku_Renderer $renderer, $data)
342342 return false ;
343343 }
344344
345+ // TODO: the way we get links from dokuwiki should be completely rewritten
346+ // - target: rework repartition between parser/renderer to match dokuwiki guidelines
347+ // - try to override $xhtml->_formatLink($link); to avoid the code duplication of the functions below
348+
345349 function dokuwiki_get_link (&$ xhtml , $ id , $ name = NULL )
346350 {
347351 global $ ID ;
352+
353+ if (link_isinterwiki ($ id )) {
354+ [$ wikiName , $ wikiUri ] = sexplode ('> ' , $ id , 2 , '' );
355+ $ exists = null ;
356+ //$url = $xhtml->_resolveInterWiki($wikiName, $wikiUri, $exists);
357+ $ link = $ this ->interwikilink ($ xhtml , $ id , $ name , $ wikiName , $ wikiUri , true );
358+ return $ link ;
359+ }
360+
348361 $ resolveid = $ id ; // To prevent resolve_pageid to change $id value
349362 $ resolveid = (new PageResolver ($ ID ))->resolveId ($ resolveid );
350363 $ exists = page_exists ($ resolveid );
@@ -507,6 +520,60 @@ function internalmedia(
507520 //if ($linking == 'nolink' || $noLink) $this->doc .= $link['name'];
508521 //else $this->doc .= $this->_formatLink($link);
509522 }
523+
524+ public function interwikilink (&$ xhtml , $ match , $ name , $ wikiName , $ wikiUri , $ returnonly = false )
525+ {
526+ global $ conf ;
527+
528+ $ link = [];
529+ $ link ['target ' ] = $ conf ['target ' ]['interwiki ' ];
530+ $ link ['pre ' ] = '' ;
531+ $ link ['suf ' ] = '' ;
532+ $ link ['more ' ] = '' ;
533+ $ link ['name ' ] = $ xhtml ->_getLinkTitle ($ name , $ wikiUri , $ isImage );
534+ $ link ['rel ' ] = '' ;
535+
536+ //get interwiki URL
537+ $ exists = null ;
538+ $ url = $ xhtml ->_resolveInterWiki ($ wikiName , $ wikiUri , $ exists );
539+
540+ if (!$ isImage ) {
541+ $ class = preg_replace ('/[^_\-a-z0-9]+/i ' , '_ ' , $ wikiName );
542+ $ link ['class ' ] = "interwiki iw_ $ class " ;
543+ } else {
544+ $ link ['class ' ] = 'media ' ;
545+ }
546+
547+ //do we stay at the same server? Use local target
548+ if (strpos ($ url , DOKU_URL ) === 0 || strpos ($ url , DOKU_BASE ) === 0 ) {
549+ $ link ['target ' ] = $ conf ['target ' ]['wiki ' ];
550+ }
551+ if ($ exists !== null && !$ isImage ) {
552+ if ($ exists ) {
553+ $ link ['class ' ] .= ' wikilink1 ' ;
554+ } else {
555+ $ link ['class ' ] .= ' wikilink2 ' ;
556+ $ link ['rel ' ] .= ' nofollow ' ;
557+ }
558+ }
559+ if ($ conf ['target ' ]['interwiki ' ]) $ link ['rel ' ] .= ' noopener ' ;
560+
561+ $ link ['url ' ] = $ url ;
562+ $ link ['title ' ] = $ xhtml ->_xmlEntities ($ link ['url ' ]);
563+
564+ // return non formatted link
565+ return $ link ;
566+
567+ /*
568+ // output formatted
569+ if ($returnonly) {
570+ if ($url == '') return $link['name'];
571+ return $this->_formatLink($link);
572+ } elseif ($url == '') {
573+ $this->doc .= $link['name'];
574+ } else $this->doc .= $this->_formatLink($link);
575+ */
576+ }
510577}
511578
512579?>
0 commit comments