VictorPorton has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/330153 )
Change subject: LinksUpdateConstructed branch ...................................................................... LinksUpdateConstructed branch Change-Id: Id6912ca1d6e2dfa986e16131303e9c32a4185b7b --- M NamespacePopups.hooks.php M extension.json 2 files changed, 33 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/NamespacePopups refs/changes/53/330153/1 diff --git a/NamespacePopups.hooks.php b/NamespacePopups.hooks.php index de11249..ab7fee6 100644 --- a/NamespacePopups.hooks.php +++ b/NamespacePopups.hooks.php @@ -28,6 +28,8 @@ // $url = wfExpandUrl( $url, $proto = PROTO_RELATIVE ); // $proto $url = preg_replace( '/\$1/', $page, $wgArticlePath ); +// $html .= "<a class='mw-pagepopup' href='$url'>$anchor</a>"; + $title = Title::newFromLinkTarget( Title::newFromText( $page ) ); if ( $title->isKnown() ) { $html .= "<a class='mw-pagepopup' href='$url'>$anchor</a>"; @@ -38,4 +40,32 @@ $ret = $html; return false; } + + public static function onLinksUpdateConstructed( LinksUpdate &$updater ) { + global $wgNamespacePopupsNamespaceMap; + + if(!$wgNamespacePopupsNamespaceMap) return; + + $oldLinks = $updater->mLinks; + + foreach(array_keys($oldLinks) as $linkPage) { + if(preg_match( '|^([^:/]+):(.*)|', $linkPage, $m )) { + $linkNS = $matches[1]; + $remains = $matches[2]; + } else { + $linkNS = ''; + $remains = $linkPage; + } + $popupNS = @$wgNamespacePopupsNamespaceMap[$linkNS] ?: @$wgNamespacePopupsNamespaceMap['*']; + if(!$popupNS) continue; + if($popupNS === '*') { + $popupPage = $linkPage; + } else { + $popupPage = $popupNS === '' ? $remains : "$popupNS:$remains"; + } + // FIXME: What's about spaces and underscores? + if(!isset($updater->mLinks[$popupPage])) // cache + $updater->mLinks[$popupPage] = Title::newFromDBkey($popupPage)->getArticleID(); + } + } } diff --git a/extension.json b/extension.json index 780499a..5e969a0 100644 --- a/extension.json +++ b/extension.json @@ -18,6 +18,9 @@ "Hooks": { "HtmlPageLinkRendererEnd": [ "NamespacePopupsHooks::onHtmlPageLinkRendererEnd" + ], + "LinksUpdateConstructed": [ + "NamespacePopupsHooks::onLinksUpdateConstructed" ] }, "ResourceFileModulePaths": { -- To view, visit https://gerrit.wikimedia.org/r/330153 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Id6912ca1d6e2dfa986e16131303e9c32a4185b7b 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