VictorPorton has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/330814 )
Change subject: created a version which works once per twice :-( ...................................................................... created a version which works once per twice :-( Change-Id: I167268a23cdea3817bfd942358f8427a03043d1b --- M NamespacePopups.hooks.php 1 file changed, 23 insertions(+), 31 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/NamespacePopups refs/changes/14/330814/1 diff --git a/NamespacePopups.hooks.php b/NamespacePopups.hooks.php index 7d74e27..cf51ee9 100644 --- a/NamespacePopups.hooks.php +++ b/NamespacePopups.hooks.php @@ -2,15 +2,6 @@ // use MediaWiki\Title; -function var_dump_ret($mixed = null) { - ob_start(); - var_dump($mixed); - $content = ob_get_contents(); - ob_end_clean(); - return $content; -} - - class NamespacePopupsHooks { public static function onHtmlPageLinkRendererEnd( $renderer, $target, $isKnown, &$text, &$attribs, &$ret ) { global $wgNamespacePopupsNamespaceMap, $wgNamespacePopupsAnchor, $wgArticlePath; @@ -50,34 +41,24 @@ return false; } + // FIXME: Works every odd time public static function onOutputPageParserOutput( OutputPage $page, $parserOutput ) { global $wgNamespacePopupsNamespaceMap; if(!$wgNamespacePopupsNamespaceMap) return; - $parserOutput->addLink(Title::newFromText( 'B:WithoutSpaces' )); - wfDebugLog( 'namespacepopups', var_dump_ret( $page->getPageTitle() ) ); - try { - $update = new LinksUpdate( Title::newFromText( $page->getPageTitle() ), $parserOutput ); - $update->doUpdate(); // TODO: Isn't it redundant (and thus inefficient) to call here? - } catch( InvalidArgumentException $e ) { // for example, rendering "edit" page - return; // FIXME: return value? + $flag = FALSE; + $oldLinks = []; + // The below algorithm enumerates all links. This may be a little inefficient + foreach($parserOutput->getLinks() as $linkNSid => $linksArray) { + $linkNS = MWNamespace::getCanonicalName( $linkNSid ); + foreach(array_keys($linksArray) as $remains) + $oldLinks[] = [ $linkNS, $remains ]; } - return; - $oldLinks = $parserOutput->getLinks(); // FIXME + foreach($oldLinks as $linkInfo) { + list($linkNS, $remains) = $linkInfo; - wfDebugLog( 'namespacepopups', var_dump_ret($oldLinks) ); - return; - - foreach(array_keys($oldLinks) as $linkPage) { - if(preg_match( '|^([^:/]+):(.*)|', $linkPage, $m )) { - $linkNS = $m[1]; - $remains = $m[2]; - } else { - $linkNS = ''; - $remains = $linkPage; - } $popupNS = @$wgNamespacePopupsNamespaceMap[$linkNS] ?: @$wgNamespacePopupsNamespaceMap['*']; if(!$popupNS) continue; if($popupNS === '*') { @@ -85,9 +66,20 @@ } else { $popupPage = $popupNS === '' ? $remains : "$popupNS:$remains"; } - wfDebugLog( 'namespacepopups', var_dump_ret($popupPage) ); - $parserOutput->addLink($popupPage); + $parserOutput->addLink( Title::newFromDBkey($popupPage) ); + $flag = TRUE; } + +// if(!$flag) return; // update nothing + + try { + $ourTitle = $page->getPageTitle(); + if(!$ourTitle) return; + $update = new LinksUpdate( Title::newFromText( $ourTitle ), $parserOutput ); + } catch( InvalidArgumentException $e ) { // for example, rendering "edit" page + return; + } + $update->doUpdate(); // TODO: Isn't it redundant (and thus inefficient) to call here? } } -- To view, visit https://gerrit.wikimedia.org/r/330814 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I167268a23cdea3817bfd942358f8427a03043d1b Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/NamespacePopups Gerrit-Branch: master Gerrit-Owner: VictorPorton <por...@narod.ru> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits