What must you do to get links to the sites and pages under Global file usage? I only get the database name and the names of the pages with underscores. example
Topic on Extension talk:GlobalUsage
What I have found is that the functions that take care of this are very wikipedia specific. Those functions only work right when the database name is like enwiki, with "en" the language code and "wiki" the sitename.
I have put a version that should work on all database naming conventions here, please test
the patch:
-------------------------------------- diff -u GlobalUsage/ApiQueryGlobalUsage.php mediawiki-extensions-GlobalUsage/ApiQueryGlobalUsage.php --- GlobalUsage/ApiQueryGlobalUsage.php 2014-09-11 14:58:21.571751756 +0200 +++ mediawiki-extensions-GlobalUsage/ApiQueryGlobalUsage.php 2014-09-11 14:56:48.934133602 +0200 @@ -30,6 +30,7 @@ public function execute() { $params = $this->extractRequestParams(); $prop = array_flip( $params['prop'] ); + foreach(Interwiki::getAllPrefixes(1) as $k) { $interWikis[$k[iw_wikiid]] = $k[iw_prefix];}; $pageIds = $this->getPageSet()->getAllTitlesByNamespace(); if ( !empty( $pageIds[NS_FILE] ) ) { @@ -52,6 +53,7 @@ foreach ( $query->getResult() as $image => $wikis ) { $pageId = intval( $pageIds[$image] ); foreach ( $wikis as $wiki => $result ) { + $interwiki = Interwiki::fetch($interWikis[$wiki]); foreach ( $result as $item ) { if ( $item['namespace'] ) { $title = "{$item['namespace']}:{$item['title']}"; @@ -60,11 +62,11 @@ } $result = array( 'title' => $title, - 'wiki' => WikiMap::getWikiName( $wiki ) + 'wiki' => parse_url($interwiki->getURL(), PHP_URL_HOST) ); if ( isset( $prop['url'] ) ) { /* We expand the url because we don't want protocol relative urls in API results */ - $result['url'] = wfExpandUrl( WikiMap::getForeignUrl( $item['wiki'], $title ), PROTO_CURRENT ); + $result['url'] = $interwiki->getURL($title); } if ( isset( $prop['pageid'] ) ) { $result['pageid'] = $item['id']; Gemeenschappelijke submappen: GlobalUsage/.git en mediawiki-extensions-GlobalUsage/.git diff -u GlobalUsage/GlobalUsageImagePageHooks.php mediawiki-extensions-GlobalUsage/GlobalUsageImagePageHooks.php --- GlobalUsage/GlobalUsageImagePageHooks.php 2014-09-11 14:58:21.571751756 +0200 +++ mediawiki-extensions-GlobalUsage/GlobalUsageImagePageHooks.php 2014-09-11 14:56:48.938133662 +0200 @@ -42,18 +42,20 @@ $context = $imagePage->getContext(); $title = $imagePage->getFile()->getTitle(); $targetName = $title->getText(); + foreach(Interwiki::getAllPrefixes(1) as $k) { $interWikis[$k[iw_wikiid]] = $k[iw_prefix];}; $query = self::getImagePageQuery( $title ); $guHtml = ''; foreach ( $query->getSingleImageResult() as $wiki => $result ) { - $wikiName = WikiMap::getWikiName( $wiki ); + $interwiki = Interwiki::fetch($interWikis[$wiki]); + $wikiName = parse_url($interwiki->getURL(), PHP_URL_HOST); $escWikiName = Sanitizer::escapeClass( $wikiName ); $guHtml .= "<li class='mw-gu-onwiki-$escWikiName'>" . $context->msg( 'globalusage-on-wiki', $targetName, $wikiName )->parse() . "\n<ul>"; foreach ( $result as $item ) - $guHtml .= "\t<li>" . SpecialGlobalUsage::formatItem( $item ) . "</li>\n"; + $guHtml .= "\t<li>" . SpecialGlobalUsage::formatItem( $item, $interwiki ) . "</li>\n"; $guHtml .= "</ul></li>\n"; } Gemeenschappelijke submappen: GlobalUsage/i18n en mediawiki-extensions-GlobalUsage/i18n Gemeenschappelijke submappen: GlobalUsage/patches en mediawiki-extensions-GlobalUsage/patches diff -u GlobalUsage/SpecialGlobalUsage.php mediawiki-extensions-GlobalUsage/SpecialGlobalUsage.php --- GlobalUsage/SpecialGlobalUsage.php 2014-09-11 14:58:21.571751756 +0200 +++ mediawiki-extensions-GlobalUsage/SpecialGlobalUsage.php 2014-09-11 14:56:48.938133662 +0200 @@ -91,6 +91,7 @@ private function showResult() { $query = new GlobalUsageQuery( $this->target ); $request = $this->getRequest(); + foreach(Interwiki::getAllPrefixes(1) as $k) { $interWikis[$k[iw_wikiid]] = $k[iw_prefix];}; // Extract params from $request. if ( $request->getText( 'from' ) ) { @@ -119,13 +120,14 @@ $out->addHtml( '<div id="mw-globalusage-result">' ); foreach ( $query->getSingleImageResult() as $wiki => $result ) { + $interwiki = Interwiki::fetch($interWikis[$wiki]); $out->addHtml( '<h2>' . $this->msg( 'globalusage-on-wiki', - $targetName, WikiMap::getWikiName( $wiki ) )->parse() + $targetName, parse_url($interwiki->getURL(), PHP_URL_HOST) )->parse() . "</h2><ul>\n" ); foreach ( $result as $item ) { - $out->addHtml( "\t<li>" . self::formatItem( $item ) . "</li>\n" ); + $out->addHtml( "\t<li>" . self::formatItem( $item, $interwiki ) . "</li>\n" ); } $out->addHtml( "</ul>\n" ); } @@ -140,15 +142,14 @@ * @param $item array * @return String */ - public static function formatItem( $item ) { + public static function formatItem( $item, $interwiki ) { if ( !$item['namespace'] ) { $page = $item['title']; } else { $page = "{$item['namespace']}:{$item['title']}"; } - $link = WikiMap::makeForeignLink( $item['wiki'], $page, - str_replace( '_', ' ', $page ) ); + $link = Linker::makeExternalLink( $interwiki->getURL($page) , str_replace( '_', ' ', $page )); // Return only the title if no link can be constructed return $link === false ? $page : $link; } ----------------------------------------------