Manual talk:$wgForeignFileRepos

From mediawiki.org
Latest comment: 4 years ago by Ciencia Al Poder in topic Add file repo?

Using files from Wikimedia Commons[edit]

I followed Manual:$wgForeignFileRepos#Using files from Wikimedia Commons but the wiki goes blank when I hit preview or submit with an image tag that doesn't exist in the wiki (and presumably the wiki will attempt to find for it on commons). I am using MediaWiki 1.13.3. Example: (removed) Why would this be? --Yonghokim 17:59, 20 January 2009 (UTC)Reply

As stated on the page, it requires PHP 5.2.0 or greater, you seem to have only PHP 5.1.6. iAlex 19:44, 20 January 2009 (UTC)Reply
I upgraded to PHP 5.2 and it works. Thank you! --Yonghokim 00:58, 21 January 2009 (UTC)Reply

Using files from a local folder : FSRepo[edit]

I followed the instruction on the page and I am using Php 5.2. I digged a bit into the code and it seems that GroupRepo does not see the foreign repository. Any idea what is going wrong here? 08:09, 10 June 2009 (UTC) Andreas

EXIF errors[edit]

We're running MediaWiki 1.14.0 and PHP 5.2 and everything works just fine except when viewing the images. PHP Warnings are generated: http://pastebin.vanonymous.org/pastebin.php?show=8 The page loads fine, however when attempting to view the metadata table the info doesn't exist. Forgott3n 09:25, 2 March 2009 (UTC)Reply

Similar error[edit]

@ http://wikademia.org/File:Coffee_at_King's_Road_Café.jpg I get the error:

"Warning: preg_match() expects parameter 2 to be string, array given in..."

This only appears on some images. For example:

http://wikademia.org/File:Haeckel_Florideae_Chondrus_crispus.png

That image does not display the error.

Any help would be appreciated. Thank you.

I get the same error here but not here. Is this problem related to the PNGs or does somebody experience it for other image formats ? --PiRK 02:43, 25 May 2009 (UTC)

Inline display of commons-Media[edit]

Hi,

I am Lars one of the administrators of the german PflegeWiki. In our Wiki the question for displaying images from the commons inline in our articles. I found the $wgForeignFileRepos as you see and now I have a question before defining the variable. Will the variable override the def's for images (we have a pool for sharing images with the english NursingWiki)? How will the System decide wich repo to use? Is there a different tag? We're using Bild: and/or Image:. We would be very happy if someone would takt care of our problems... Greets and thanks in advance, --Bruder Lars 06:46, 25 August 2009 (UTC)Reply


Cannot redeclare class HttpRequest[edit]

Upgrading to 16.0 lead to

Fatal error: Cannot redeclare class HttpRequest in /<sitename>/public_html/priv/includes/HttpFunctions.php on line 122

when trying to upload any file. Commenting out the piece in LocalSettings.php below resolved it:

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

Don't know why but uploading is functioning again. Arent 15:35, 20 August 2010 (UTC)Reply

This was fixed in rev:76566. Bawolff 07:56, 12 November 2010 (UTC)Reply

FSRepo (FileRepo)[edit]

Note: FSRepo has been deprecated use FileRepo instead

Is FSRepo a working functionality? I am trying to display images from a local folder without uploading them into the wiki. But UnregisteredLocalFile.php does not seem to be fully functional yet.

/**
 * A file object referring to either a standalone local file, or a file in a
 * local repository with no database, for example an FSRepo repository.
 *
 * Read-only.
 *
 * TODO: Currently it doesn't really work in the repository role, there are
 * lots of functions missing. It is used by the WebStore extension in the
 * standalone role.
 *
 * @ingroup FileRepo
 */

I would like to display images on the wiki, but maintaining their original folder structure in the file system, any ideas?--Xavier Atero 09:41, 7 June 2011 (UTC)Reply

Answering my own questions, in case someone finds this useful:
  • Yes, FSRepo is a working functionality
  • There is a way to display images on the wiki maintaining their original folder structure in the file system, although it is pretty ugly.

For the FileRepo to work:[edit]

  • 'hashLevels' must be 0
  • 'directory' has to be visible from the web
  • 'url' has to be the url that points to 'directory'
  • the files contained in the folder should NOT:
    • have the first character in lowercase
    • contain any blank spaces in the name
The reason is that MediaWiki will capitalize the first character and will replace blank spaces by underscores _.
LocalSettings.php should contain the FileRepo definition:
$wgForeignFileRepos[] = array(
   'class'            => 'FileRepo',
   'name'             => 'sharedFileRepo',
   'directory'        => '/home/my_user/public_html/wiki/media',
   'url'              => 'http://www.my_wiki.com/media',
   'hashLevels'       => 0,
);
where 'http://www.my_wiki.com/media' has to point to '/home/my_user/public_html/wiki/media'
The file system would look something like this:
home
|-- my_user 
     |-- public_html  
          |-- wiki 
               |-- media 
                    |-- Picture_1.jpg
                    |-- Picture_2.jpg
                    +-- Picture_3.jpg
And the call from the page:

 <gallery>
 Image:Picture_1.jpg
 Image:Picture_2.jpg
 </gallery>
 [[Image:Picture_3.jpg]]

To display images on the wiki maintaining their original folder structure in the file system[edit]

I guess that it can be accomplished by defining multiple FileRepo in LocalSettings.php. But I had files with same names in different folders, which creates conflicts between the different repositories. And my folder structure will grow, which implies constant modifications to LocalSettings.php
I wanted only one FileRepo and to have the relative path associated with the image.
The folder structure looks like this:
home
|-- my_user 
     |-- public_html  
          |-- wiki 
               |-- media 
                    |-- 00-photos
                          |-- 2009_Irvine
                               |-- Picture_1.jpg
                               |-- Picture_2.jpg
                               +-- Picture_3.jpg
                          |-- 2011_Barcelona
                               |-- Picture_1.jpg
                               |-- Picture_2.jpg
                               +-- Picture_3.jpg
and the page like this:

 <gallery>
 Image:00-photos/2009_Irvine/Picture_1.jpg
 Image:00-photos/2009_Irvine/Picture_2.jpg
 </gallery>
 <gallery>
 Image:00-photos/2011_Barcelona/Picture_1.jpg
 Image:00-photos/2011_Barcelona/Picture_2.jpg
 </gallery>

The fast (but dirty) way to make it work is to rawurldecode the src attribute in includes/media/MediaTransformOutput.php toHtml function:
 $attribs = array(
  'alt' => $alt,
  'src' => rawurldecode($this->url),
  'width' => $this->width,
  'height' => $this->height,
 );
Of course this will break all the files in the other repositories that contained special characters. This problem can be restricted by checking that the url contains 00-photos (in this case) before doing the rawurldecode or by checking that the file comes from FileRepo.
Note: I named my directory 00-photos so I do not have to worry about MediaWiki changing the first character to uppercase.--Xavier Atero 13:29, 8 June 2011 (UTC)Reply

Fallback[edit]

Does this let you specify a primary repo and a secondary repo in case the file doesn't exist at the primary repo? Leucosticte (talk) 09:20, 11 November 2013 (UTC)Reply

I don't know if there is a true "fallback" mechanism, but I know that wmit: wiki uses or used to use both Commons and it.wiki as foreign repos. --Nemo 09:25, 11 November 2013 (UTC)Reply

"For all core repos"[edit]

The section name "For all core repos" feels ambiguous to me. Is it referring to "The core repository classes are LocalRepo, ForeignDBRepo, FSRepo and ForeignAPIRepo" or something else? John Vandenberg (talk) 09:23, 17 June 2015 (UTC)Reply

Confusion ForeignDBRepoViaLB or ForeignDBViaLBRepo?[edit]

I guess it’s the latter: ForeignDBViaLBRepo, right? Because at the end of section “Using files from a database that you can access : ForeignDBRepo” it documents ForeignDBRepoViaLB but as far as I see in /includes/filerepo (MW 1.26) there is no ForeignDBRepoViaLB.php but a ForeignDBViaLBRepo.php --Andreas P. 16:12, 1 February 2016 (UTC)Reply

How to disable both transformVia404 and wgGenerateThumbnailOnParse when using ForeignDBRepo??[edit]

Hi guys, I got my files all uploaded to a commons wiki, and access those file on other wikis via ForeignDBRepo as following. Although all wiki share a same DB with different name, they are on different machine where access to files on commonswiki are impossible. I tried to comment out thumbScriptUrl & transformVia404 = false. Then I get thumbnail generating error.

Following settings work, but using thumb.php is buggy and slow. I want other wiki generate thumb url like this: https://commonswiki.org/commons/thumb/1/1f/filename.jpg/200px-filename.jpg directly. To make this clear, I need the solution to generate right url without thumb.php or attempts on generate thumbnails of image. I have all the rest part done expect the URL.

$wgGenerateThumbnailOnParse = false;
$wgForeignFileRepos[] = array(
   'class' => 'ForeignDBRepo',
   'name' => 'commonswiki',
   'directory' => '/tmp', //NO, OTHER WIKIS DOES NOT HAVE ACCESS TO THE COMMONS' FILE THOUGH DIRECTORY!!!
   'url' => 'https://static.commonswiki.org/common',
   'thumbScriptUrl' => 'https://commonswiki.org/thumb.php',
   //'transformVia404' => false, 
   'dbType' => $wgDBtype,
   'dbServer' => $wgDBserver,
   'dbUser' => $wgDBuser,
   'dbPassword' => $wgDBpassword,
   'dbName' => 'commonswiki',
   'hasSharedCache' => false,
   'descBaseUrl' => 'https://commonswiki.org/File:',
   'fetchDescription' => false
);

Empty server array given to LoadBalancer??[edit]

I tried to set wgForeignFileRepos with the 'class' => 'ForeignDBViaLBRepo'. This settings should get Server info from $wgLBFactoryConf. But it actually return me an error: "InvalidArgumentException from line 371 of /includes/libs/rdbms/loadbalancer/LoadBalancer.php: Empty server array given to LoadBalancer". What's wrong? --Zoglun (talk) 04:17, 24 December 2017 (UTC)Reply

Maybe the $wgLBFactoryConf config isn't properly set on your LocalSettings.php. I can't say what exactly, because this configuration was so complicated that I gave up trying to set it up. --Ciencia Al Poder (talk) 11:47, 24 December 2017 (UTC)Reply

How to set 'directory' in ForeignDBRepo, ForeignDBViaLBRepo mode, but I can't access media files?[edit]

I got database perfectly shared among different wikis. But I can't share the media files by mount or any other methods.

So for the 'directory' => '/path/to/media',, what path should I entered in? Is there anyway to prevent MW look up local directory? Just forcing it to generate the url for images. --Zoglun (talk) 22:24, 31 December 2017 (UTC)Reply

Error with redirected files[edit]

When foreignapirepo enabled, then we have an error, if in source wiki this file was redirected to another.

MWException from line 199 of /includes/filerepo/file/File.php: `File:Foo.bar` is not a valid file title.

And page that uses redirected file, don't open.

I think that this is a bug and needs to fix. — Preceding unsigned comment added by StRiANON (talkcontribs)

Please file a bug --Ciencia Al Poder (talk) 09:22, 26 March 2018 (UTC)Reply

Database connection caveats[edit]

Added notes on caveats learned from working on Topic:Ta3n8f4l49wuqe9s. If those additions aren't appropriate, please at least add to the docs some notes on good or expected practices regarding shared file repo implementation on non-Wikimedia wikis or non-Commons targets. It is apparently very easy to unintentionally degrade multiple wikis' database's performance by underestimating how many requests this feature generates, and how frequently. -PFWOz (talk) 20:03, 5 December 2018 (UTC)Reply

Add file repo?[edit]

Hello! I activate by default in the installation the file repository from Commons (didn't want contributors to be able to upload files directly on the server). However I would like to put myself files on the server (/images/). I added the FileRepo code in LocalSettings but I can't seem to put the files in the articles. Should I write something different than [[File:myfile.jpg]]?

$wgForeignFileRepos[] = [
	'class' => 'FileRepo',
	'name' => 'sharedFsRepo',
	'directory' => '/images/',
	'hashLevels' => 0,
	'url' => 'http://wiki.lokal-life.org/images/',
];

Thanks! 89.157.115.94 20:08, 4 August 2019 (UTC)Reply

Replied in Topic:V4sf0mlbl3c5vjcw --Ciencia Al Poder (talk) 09:17, 5 August 2019 (UTC)Reply

nginx request coalescing[edit]

Hello, as mentioned in the performance section: A high-performance site may want to look at setting up a local proxy (like nginx) that can coalesce multiple requests into a single pipelined request to reduce round trip times from TCP & TLS handshakes. Do you have any example setting, or guide, some steps to achieve that?