Question

I am setting my own MediaWiki website locally, and am not able to get the InstantCommons feature to work (used to directly embed files from commons.wikimedia.org).

I get no error message, the files I try to load from Commons using the following syntax:

  [[File:Cervus elaphus Luc Viatour 1.jpg|Cervus elaphus Luc Viatour 1]]

are just not loaded, and I end up with a red link on my page, referring to a non-existing file. It has been 2 days now that I am looking for a solution, but so far without any success.

I am running:

  • MediaWiki v.1.19.1
  • Fedora 16 (with SElinux)
  • PHP 5.3.15
  • MySQL Ver 14.14 Distrib 5.5.25a, for Linux (x86_64)

I have tried the following two configurations in my LocalSettings.php, without success:

$wgUseInstantCommons = true;

AND

$wgForeignFileRepos[] = array(
   'class'                   => 'ForeignAPIRepo',
   'name'                    => 'shared',
   'apibase'                 => 'http://commons.wikimedia.org/w/api.php',
   'fetchDescription'        => true, // Optional
   'descriptionCacheExpiry'  => 43200, // 12 hours, optional (values are seconds)
   'apiThumbCacheExpiry'     => 43200, // 12 hours, optional, but required for local thumb caching
);

Any suggestion is most welcome.

Was it helpful?

Solution

OK, this is not (yet) an answer, but a debugging suggestion. It looks to me like the HTTP request from your server to Commons is failing for some reason, but unfortunately ForeignAPIRepo doesn't indicate the cause of the error in any way.

This is really a bug in MediaWiki, and should be fixed, but in the mean time, could you please try applying the following diff (or just manually adding the line marked with the + sign) to your includes/filerepo/ForeignAPIRepo.php file:

Index: includes/filerepo/ForeignAPIRepo.php
===================================================================
--- includes/filerepo/ForeignAPIRepo.php    (revision 97048)
+++ includes/filerepo/ForeignAPIRepo.php    (working copy)
@@ -385,6 +385,7 @@
        if ( $status->isOK() ) {
                return $req->getContent();
        } else {
+               wfDebug( "ForeignAPIRepo: HTTP GET failed: " . $status->getXML() );
                return false;
        }
    }

After applying it, try loading the file description page for a Commons image and look at the MediaWiki debug log. There should now be a line starting with ForeignAPIRepo: HTTP GET failed: followed by a few lines of XML error dump. That error data should hopefully indicate what's going wrong; please copy and paste it here.

OTHER TIPS

Mine is not a definitive answer either. Referring to Ilmari Karonen's post, I was unable to find or get the getXML() method to execute for my version of Mediawiki v1.23.0. I was looking at the reference documentation found here to try and find any other method calls on the Status class that would give me good troubleshooting info. I ended up finding the following and editing the same file as mentioned in Ilmari Karonen's post includes/filerepo/ForeignAPIRepo.php beginning at line #521:

if ( $status->isOK() ) {
    return $req->getContent();
} else {
    $error = $status->getErrorsArray();
    $dump = print_r($error, true);
    wfDebug("ForeignAPIRepo: HTTP GET failed: $dump\n");
    return false;
}

The default InstantCommons configuration of older MediaWikis is a bit silly. Due to T114098 I recommend one of the following, which will hopefully fix your problems:

  1. upgrade to MediaWiki 1.27 (when it's released), or
  2. set your LocalSettings.php to hotlink images to save on server-side requests and processing.

$wgUseInstantCommons = false; $wgForeignFileRepos[] = array( 'class' => 'ForeignAPIRepo', 'name' => 'commonshotlink', 'apibase' => 'https://commons.wikimedia.org/w/api.php', 'hashLevels' => 2, 'url' => 'https://upload.wikimedia.org/wikipedia/commons', 'thumbUrl' => 'https://upload.wikimedia.org/wikipedia/commons/thumb', 'transformVia404' => true, 'fetchDescription' => true, 'descriptionCacheExpiry' => 43200, 'apiThumbCacheExpiry' => 24 * 3600, );

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top