2

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.

Nemo
  • 2,441
  • 2
  • 29
  • 63
Alexandre Bourlier
  • 3,972
  • 4
  • 44
  • 76
  • Which MeediaWiki version are you running? And show us the relevant lines from your config files – Bergi Aug 28 '12 at 15:37
  • Thanks for your return. I update my post with your requirements in a minute. – Alexandre Bourlier Aug 28 '12 at 15:50
  • You noticed that there is no [`Some file.jpg`](http://commons.wikimedia.org/wiki/File:Some_file.jpg) at Commons? – Bergi Aug 28 '12 at 16:00
  • Sorry, this was meant to say I have tried several files from Commons, with the following extensions: .png, .jpg and .svg. I'll change that also so that no more confusion happens. – Alexandre Bourlier Aug 28 '12 at 17:23
  • I suspect that your server may be unable to contact Commons. Could you [enable PHP and MediaWiki debug logging](http://www.mediawiki.org/wiki/Manual:How_to_debug) and see if there's anything that looks possibly relevant in the logs? – Ilmari Karonen Aug 28 '12 at 17:55
  • Ok I did that and in the debug logs, I have only the two following messages repeated several times: `Warning: Cannot modify header information - headers already sent` AND `Notice: require() [function.require]`. It doesn't seem related to the `instantCommons` feature. – Alexandre Bourlier Aug 28 '12 at 20:22
  • @Euloiix: OK, do you see any lines beginning with `ForeignAPIRepo:` in the MediaWiki debug log (not the PHP log)? There should be plenty, at least if you visit the image description page for a Commons image on your wiki. – Ilmari Karonen Aug 28 '12 at 23:28
  • @llmari: only this one: `ForeignAPIRepo: HTTP GET: http://commons.wikimedia.org/w/api.php?titles=File%3ACervus_elaphus_Luc_Viatour_1.jpg&iiprop=timestamp%7Cuser%7Ccomment%7Curl%7Csize%7Csha1%7Cmetadata%7Cmime&prop=imageinfo&iimetadataversion=2&format=json&action=query&redirects=true`. – Alexandre Bourlier Aug 29 '12 at 11:53
  • I may add that if I click on the red like of the image, it brings me to the upload page as I have activated it. The upload page works fine with local images. – Alexandre Bourlier Aug 29 '12 at 11:57
  • @Christian: No, I do not operate behind a proxy. I use a standard GVT connection (a Brazilian internet service provider). – Alexandre Bourlier Aug 29 '12 at 19:48
  • 1
    For SELinux config, see https://www.mediawiki.org/wiki/SELinux#Enabling_InstantCommons – Nemo Nov 08 '15 at 11:17
  • @Nemo : I wrote a fair part of this article ;) – Alexandre Bourlier Nov 08 '15 at 14:42
  • 1
    @AlexandreBourlier great, maybe provide your own self-answer linking to it because the current answers aren't even really answers. :) – Nemo Nov 08 '15 at 14:43
  • Please do so if you feel confident enough. I can't remember that topic properly, that was 5 years ago. – Alexandre Bourlier Nov 08 '15 at 14:45

3 Answers3

1

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.

Ilmari Karonen
  • 49,047
  • 9
  • 93
  • 153
  • Thank you very much for your help. Here is what I got as a result: `ForeignAPIRepo: HTTP GET failed: http-curl-error Error fetching URL: Failed to connect to 208.80.154.224: Permission denied Failed to connect to 208.80.154.224: Permission denied `. – Alexandre Bourlier Aug 29 '12 at 19:43
  • 2
    Aha, [looks like it's an SELinux issue](http://www.lightenna.com/news/tech_report/selinux_will_mess_with_your_curl). According to the linked page, enabling the _"Allow HTTPD scripts and modules to connect to the network"_ permission might fix the problem. – Ilmari Karonen Aug 29 '12 at 21:28
  • Thank you very much ! This did the tricks, the image is now loading properly. I am very grateful. I will update the SElinux and the InstantCommons pages on MediaWiki to reference this. One last thing is bothering me though: on the picture description page load, I get this debug msg for each thumbnail size: `ForeignAPIRepo::getThumbUrl got remote thumb http://path/to/image ForeignAPIRepo::getThumbUrlFromCache Thumbnail was already downloaded before ForeignAPIRepo: HTTP GET: http://path/to/image ForeignAPIRepo::getThumbUrlFromCache could not write to thumb path`. It seems to dl them everytime – Alexandre Bourlier Aug 29 '12 at 23:36
  • I applied [this patch](https://www.mediawiki.org/wiki/Thread:Talk:MediaWiki_1.19/Thumbnails_didn't_work_since_Update_to_1.19) but it did not solved the problem. – Alexandre Bourlier Aug 30 '12 at 14:28
  • The `could not write to thumb path` error sounds like a directory permissions problem, or possibly more SELinux weirdness. Are you sure your webserver/PHP is allowed to write to the `images/thumb` directory? – Ilmari Karonen Aug 30 '12 at 14:42
  • I found (this thread)[http://comments.gmane.org/gmane.org.wikimedia.mediawiki/31352] dealing with the same issue. But the patch it references targets a part of the code that seems to have fairly changed since then. – Alexandre Bourlier Aug 30 '12 at 14:44
  • I am sure my apache server is allowed to write to the `images/thumb` directory because the thumbnails of the local images I uploaded are stored there. – Alexandre Bourlier Aug 30 '12 at 14:46
  • The [patch](http://www.mediawiki.org/wiki/Special:Code/MediaWiki/49381) you mentioned is from 2009, and should already be part of MediaWiki 1.19. If the permissions are OK, I'm not sure what might be wrong. You could try editing ForeignAPIRepo.php, finding the part that generates that message (search for `could not write`), commenting out the `wfSuppressWarnings()` call before it and seeing if any useful warnings end up in the PHP log. – Ilmari Karonen Aug 30 '12 at 14:55
  • Anyway, the fact that it's reloading the thumbs may not be an error, depending on what you've set the [`apiThumbCacheExpiry`](http://www.mediawiki.org/wiki/Manual:$wgForeignFileRepos#Using_files_from_Wikimedia_Commons_:_ForeignAPIRepo) parameter to. The default is fairly low, so old thumbs will be overwritten fairly often; you may want to increase it to something like one month (30*24*60*60 = 2592000) or, alternatively, set it to zero to load thumbnails directly from Commons (only recommended for very small wikis). – Ilmari Karonen Aug 30 '12 at 15:00
  • I did comment out the `wfSuppressWarnings()` call, but no additional debug message were displayed. I also changed the default `apiThumbCacheExpiry` value in Setup.php but once again to no avail. I will continue to investigate on this. Once again, thank you very much for your help, you made me save quite some time there. – Alexandre Bourlier Aug 30 '12 at 16:43
0

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;
}
Community
  • 1
  • 1
0

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, );

Nemo
  • 2,441
  • 2
  • 29
  • 63