Manual:$wgForeignFileRepos
From MediaWiki.org
| Shared uploads: $wgForeignFileRepos | |
|---|---|
| An array of repository structure for foreign repositories. |
|
| Introduced in version: | 1.11.0 (r22580) |
| Removed in version: | still in use |
| Allowed values: | (array) |
| Default value: | (see below) |
Other settings: Alphabetical | By Function
Contents |
[edit] Details
Properties required for all repos:
- class
- The class name for the repository. May come from the core or an extension. The core repository classes are LocalRepo, ForeignDBRepo, FSRepo and ForeignAPIRepo.
- name
- A unique name for the repository.
For all core repos:
- url
- Base public URL
- thumbUrl
- Base thumb url, if different from url/thumb
- hashLevels
- The number of directory levels for hash-based division of files
- thumbScriptUrl
- The URL for thumb.php (optional, not recommended)
- transformVia404
- Whether to skip media file transformation on parse and rely on a 404 handler instead.
- initialCapital
- Equivalent to $wgCapitalLinks, determines whether file names implicitly start with a capital letter. The current implementation may give incorrect description page links when the local $wgCapitalLinks and initialCapital are mismatched.
- pathDisclosureProtection
- May be 'paranoid' to remove all parameters from error messages, 'none' to leave the paths in unchanged, or 'simple' to replace paths with place holders. Default for LocalRepo is 'simple'.
- descBaseUrl
- URL of image description pages, e.g. http://en.wikipedia.org/wiki/Image:
- scriptDirUrl
- URL of the MediaWiki installation, equivalent to $wgScriptPath, e.g. http://en.wikipedia.org/w
- articleUrl
- Equivalent to $wgArticlePath, e.g. http://en.wikipedia.org/wiki/$1
- fetchDescription
- Fetch the text of the remote file description page. Equivalent to $wgFetchCommonsDescriptions.
- descriptionCacheExpiry
- If set to 0, no caching will be used. Set to 1 or more (seconds) to define how long the local cache of description pages will last. Must set fetchDescription to true to use.
ForeignAPIRepo class:
- apibase
- The base URL for the remote repository's API (eg: http://commons.wikimedia.org/w/api.php). Only used for ForeignAPIRepo.
- apiThumbCacheExpiry
- How long to cache thumbs locally for. Not setting this or setting to 0 disables local thumb caching
ForeignDBRepo class:
- dbType, dbServer, dbUser, dbPassword, dbName, dbFlags
- equivalent to the corresponding member of $wgDBservers
- tablePrefix
- Table prefix, the foreign wiki's $wgDBprefix
- hasSharedCache
- True if the wiki's shared cache is accessible via the local $wgMemc
Default Value (code in Setup.php) :
if ( $wgUseSharedUploads ) { if ( $wgSharedUploadDBname ) { $wgForeignFileRepos[] = array( 'class' => 'ForeignDBRepo', 'name' => 'shared', 'directory' => $wgSharedUploadDirectory, 'url' => $wgSharedUploadPath, 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0, 'thumbScriptUrl' => $wgSharedThumbnailScriptPath, 'transformVia404' => !$wgGenerateThumbnailOnParse, 'dbType' => $wgDBtype, 'dbServer' => $wgDBserver, 'dbUser' => $wgDBuser, 'dbPassword' => $wgDBpassword, 'dbName' => $wgSharedUploadDBname, 'dbFlags' => ($wgDebugDumpSql ? DBO_DEBUG : 0) | DBO_DEFAULT, 'tablePrefix' => $wgSharedUploadDBprefix, 'hasSharedCache' => $wgCacheSharedUploads, 'descBaseUrl' => $wgRepositoryBaseUrl, 'fetchDescription' => $wgFetchCommonsDescriptions, ); } else { $wgForeignFileRepos[] = array( 'class' => 'FSRepo', 'name' => 'shared', 'directory' => $wgSharedUploadDirectory, 'url' => $wgSharedUploadPath, 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0, 'thumbScriptUrl' => $wgSharedThumbnailScriptPath, 'transformVia404' => !$wgGenerateThumbnailOnParse, 'descBaseUrl' => $wgRepositoryBaseUrl, 'fetchDescription' => $wgFetchCommonsDescriptions, ); } }
[edit] Directory permissions
You'll need rw on $IP/images and $IP/images/thumbs for whatever user php runs as.
[edit] Usage
[edit] Using files from Wikimedia Commons : ForeignAPIRepo
- Since 1.16.0 rhere is a more convenient shorthand to use Commons as a foreign repository: $wgUseInstantCommons.
You can set your wiki to use media from Wikimedia Commons (or from any other MediaWiki-powered site, see below) directly. However, please beware any legal implications.
To use this, you need:
- MediaWiki 1.13 or later
- PHP with JSON support (for the
json_decode()function). JSON is enabled by default since PHP 5.2.0, you'll need the PECL extension for older versions. Since MediaWiki 1.16, this is no longer necessary; v. 1.16 will use custom (and slower) code if JSON is not available. - The remote wiki must also use MediaWiki 1.13 or later; otherwise its
api.phpreturns{"error":{"code":"iiunknown_iiprop","info":"Unrecognised values for parameter 'iiprop'"}}and file requests fail silently (i.e. the requested files are just treated as non-existent).
The code below enables media files from Wikimedia Commons on your site:
$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 );
To pull images from another Wikimedia project, set apibase to something like http://en.wikipedia.org/w/api.php.
To embed an image in your installation, simply use [[file:name_of_commons_picture.ext]].
You may need to configure the $wgMainCacheType as well. Default it is set to CACHE_NONE, meaning it will load the image from the remote host on each page load.
[edit] Using files from a database that you can access : ForeignDBRepo
The ForeignDBRepo class is very useful for creating wiki families. In a wiki family, each wiki will have its own database or table prefix. Using this class, you can make a family member aware of the tables of another family member. Access through ForeignDBRepo is faster than through ForeignAPIRepo.
$wgForeignFileRepos[] = array( 'class' => 'ForeignDBRepo', 'name' => 'otherwiki', 'url' => "http://wiki.example.com/media", 'directory' => '/path/to/media', 'hashLevels' => 2, // This must be the same for the other family member 'dbType' => $wgDBtype, 'dbServer' => $wgDBserver, 'dbUser' => $wgDBuser, 'dbPassword' => $wgDBpassword, 'dbFlags' => DBO_DEFAULT, 'dbName' => 'mydb', 'tablePrefix' => 'mw_', 'hasSharedCache' => false, 'descBaseUrl' => 'http://wiki.example.com/Image:', 'fetchDescription' => false );
[edit] Using files from a local folder : FSRepo
You can set your wiki to use media from a single folder. This is just a demonstration feature at present, and will probably be too slow for busy wikis or slow servers due to the lack of caching.
The below code enabled media files from it:
$wgForeignFileRepos[] = array( 'class' => 'FSRepo', 'name' => 'sharedFsRepo', 'directory' => 'media/', 'hashLevels' => 0, 'url' => 'http://your.wiki.tld/path/to/media/', );