Extension talk:GlobalUsage

About this board

Globalusage not show on File page when shared repo database like 'dbname-prefix'

1
Sunwui (talkcontribs)

If shared repo database contain a table prefix, $wgGlobalUsageDatabase should be dbname-prefix. I found getDBname() isn't contain the table prefix, so Globalusage not show on File page. I found getDomainId()result is dbname-prefix, but I don't know if it 's right use, and if my setting wrong in Globalusage.

The code in GlobalUsageImagePageHooks.php line118(Github):

$dbr->getDBname()!=$wgGlobalUsageDatabase

Reply to "Globalusage not show on File page when shared repo database like 'dbname-prefix'"

Global usage links not showing on master wiki

1
Synonymshawfinch (talkcontribs)

Hi all, I've got a wiki farm set up in several languages with file uploads centralized on the English version. GlobalUsage is enabled but I'm having the following issues:

  • The global usage section shows on all wikis but the English one (where files actually live).
  • In the other languages, the global usage section shows but file usage from the English wiki is missing.

I checked the globalimagelinks table and the only entries where gil_wiki corresponds to the English wiki are missing (wanted files). If I run refreshGlobalimagelinks.php --pages=existing,nonexisting from an empty table, only those 'wanted files' are created.

Here are the relevant bits of my config for reference:

if ($wgLang != $availableLanguages[0]) {
	$wgEnableUploads = false;
	$wgUploadNavigationUrl = "/wiki/en/Special:Upload";

	$wgUseSharedUploads = true;
	$wgSharedUploadPath = '/wiki/images';
	$wgSharedUploadDirectory = $IP . '/images';
	$wgHashedSharedUploadDirectory = true;
	
	$wgFetchCommonsDescriptions = true;
	$wgSharedUploadDBname = $databasePrefix . $availableLanguages[0];
	$wgSharedUploadDBprefix = 'wiki_';
	$wgRepositoryBaseUrl = "https://mysite.com/wiki/en/File:";
}

(Here $wgLang is the language code of the wiki and $availableLanguages[0] is just en for English. All I'm doing is setting up a shared uploads wiki for all languages but English.)

wfLoadExtension('GlobalUsage');

$wgGlobalUsageDatabase = $databasePrefix . $availableLanguages[0] . '-' . $wgDBprefix;

foreach ($availableLanguages as $availableLanguage) {
	$wgConf->suffixes[] = $databasePrefix . $availableLanguage . '-' . $wgDBprefix;
	$wgConf->settings["wgCanonicalServer"]["$databasePrefix$availableLanguage-$wgDBprefix"] = "https://mysite.com";
	$wgConf->settings["wgArticlePath"]["$databasePrefix$availableLanguage-$wgDBprefix"] = "/wiki/$availableLanguage/$1";
}

(Here the loop on $availableLanguages just sets up $wgConf for each wiki.)

I have also tried to add a $wgLBFactoryConf, but to no avail.

Any help on the matter would be greatly appreciated.

Reply to "Global usage links not showing on master wiki"

How to generate links under File usage on other wikis session?

5
Deletedaccount4567435 (talkcontribs)

Hi all, after a long long period of hardworking we finally got the GlobalUsage work with two separate database across pacific ocean.

We got the "File usage on other wikis" part show as following. It is clear that some setting need to be set. (May be $wgConf?) Can anyone provide help on the linking part?

THX

The following other wikis use this file:

Usage on enmoegirl

*pagename1

Usage on zhmoegirl

*pagename2

.....

Bawolff (talkcontribs)

Yes, if links don't work, it means $wgConf isn't set correctly, and MediaWiki doesn't know what the $wgArticlePath and related variables are for the other wiki.

Bawolff (talkcontribs)

I should add, this extension also supports manual:Sites table as an alternative to $wgConf if you prefer that.

Deletedaccount4567435 (talkcontribs)

I have add the sites table through importSites.php.

However after purge/runjob, no links generated. This table do exist in database, But its empty & and nothing using this table before importSites. I do saw extensions use "interwiki" table. Does the "sites" table still in use?

<sites version="1.0">

<site type="mediawiki">

<globalid>enmoegirl</globalid>

<localid type="interwiki">enmoegirl</localid>

<localid type="language">en</localid>

<group>moegirlpedia</group>

<path type="link">https://en.moegirl.org/</path>

<path type="page_path">https://en.moegirl.org/$1</path>

<path type="file_path">https://en.moegirl.org/$1</path>

<source>wikidata</source>

</site>

</sites>

Deletedaccount4567435 (talkcontribs)

After few hours of wait, the link shows up as it suppose to! Yeah!

I guess problem caused by cache delay.

Thank you!!!!! Bawolff!

Reply to "How to generate links under File usage on other wikis session?"
Aschroet (talkcontribs)

Hello all, can someone here be so kind to give me a pointer to the mechanism that triggers the update of the data that is displayed by this extension? In the concrete example i try to find out why a lot of GlobalUsage data in WikiCommons is not up-to-date related to pages in German Wikisource and maybe others. (https://phabricator.wikimedia.org/T108799) I will be thankful for every hint.

Matma Rex (talkcontribs)

It piggy-backs on MediaWiki's built-in LinksUpdate jobs, using the LinksUpdateComplete hook.

Gettign "Param pages required!"

2
Deletedaccount4567435 (talkcontribs)

Gettign "Param pages required!"

with

php extensions/GlobalUsage/refreshGlobalimagelinks.php

Matma Rex (talkcontribs)

You need to pass the --pages=existing,nonexisting parameter. I updated the documentation page.

Reply to "Gettign "Param pages required!""

usage of API features

2
Kghbln (talkcontribs)

Can you please provide documentation on how to use the API features of this extension? Thanks

This post was posted by Kghbln, but signed as Tisane.

Kghbln (talkcontribs)

See the example on the api.php page.

This post was posted by Kghbln, but signed as Bryan.

Reply to "usage of API features"
FlightTime (talkcontribs)

How do I change the usage display from "DataBase name" to "Sitename" ?

Reply to "Change display"

Links under Global file usage

3
Egel (talkcontribs)

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

Egel (talkcontribs)

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.

Egel (talkcontribs)

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;
 	}

----------------------------------------------
Reply to "Links under Global file usage"

easier way for $wgGlobalUsageDatabase

2
Cboltz (talkcontribs)

There is an easier way than setting $wgGlobalUsageDatabase using Manual:$wgLBFactoryConf: using $wgSharedDB and $wgSharedTables :-)

Add the following to LocalSettings.php in all your wikis:

(I'm assuming you have "images-wiki" as your shared images wiki)

if ( $wgDBname != "images-wiki" ) {
   $wgSharedDB         = "images-wiki";
   $wgSharedTables[] = 'globalimagelinks';
}
require_once("$IP/extensions/GlobalUsage/GlobalUsage.php");
if ( $wgDBname == "images-wiki" ) {
   $wgGlobalUsageDatabase = 'images-wiki'; # workaround to enforce displaying the "global usage" section
}

(Note: $wgSharedTables defaults to ('user', 'user_properties') - remove them if you want)

HTH ;-)

Till Kraemer (talkcontribs)

That was pretty helpful, thanks a lot!

Cheers,

Reply to "easier way for $wgGlobalUsageDatabase"

Prefix of table globalimagelinks

2
Llamaggot (talkcontribs)

Hi,

GlobalUsage.sql creates a table named 'prefix_globalimagelinks' (if 'prefix_' is the value of $wgDBprefix), but the extension is only working if this table is called 'globalimagelinks' instead, without the prefix.

Should GlobalUsage.sql be fixed? Or is there a way to make the extension work with the prefixed table name?

Thanks in advance,

Krinkle (talkcontribs)

The database code resolves the canonical name into the actual name (adding the prefix) automatically. If this doesn't happen that can mean one of two things:

  • There is a bug in MediaWiki core where it doesn't do it properly
  • The GlobalUsage extension is using raw queries instead of abstracted through MediaWiki's handler.

Please file a bug on Bugzilla (Product: MediaWiki extensions; Component: GlobalUsage). Be sure to include the version of your wiki and the version of GlobalUsage (you can get this information by going to Special:Version on your wiki). If possible, also include a link to your wiki in the bug report. Thanks!

Reply to "Prefix of table globalimagelinks"
Return to "GlobalUsage" page.