Manual:$wgForeignFileRepos

From MediaWiki.org
Jump to: navigation, search
This page is a translated version of the page Manual:$wgForeignFileRepos and the translation is 63% complete.

Other languages:
català • ‎Deutsch • ‎Ελληνικά • ‎English • ‎español • ‎suomi • ‎français • ‎italiano • ‎日本語 • ‎Bahasa Melayu • ‎Nederlands • ‎polski • ‎português • ‎português do Brasil • ‎中文
Shared uploads: $wgForeignFileRepos
外部リポジトリに対するリポジトリ構造の配列。
導入されたバージョン: 1.11.0 (r22580)
除去されたバージョン: 使用中
可能な値: 配列
既定値: (下記参照)
他の設定: アルファベット順 | 機能順

詳細[edit]

警告 警告: It is important to use HTTPS and not HTTP in the links pointing to the Wikimedia Commons. The Wikimedia Foundation has changed their setup, redirecting people from HTTP to HTTPS. Since for security reasons MediaWiki does not follow such redirects, this change broke the instant commons feature for a number of users. This change has been reverted for now (so that it's again working also with HTTP), but it is still planned to switch to HTTPS in the future (see タスク T102566).

The solution is to use HTTPS in the URLs pointing to the commons repository! If you use instant commons with the default setup as it comes from DefaultSettings.php, this issue will automatically be fixed by using MediaWiki 1.25.2 or newer. If you in contrast have defined $wgForeignFileRepos in LocalSettings.php, the URLs set there have to be adjusted accordingly!

すべてのリポジトリに対して要求されるプロパティ[edit]

class
リポジトリに対するクラス名です。コアもしくはエクステンションから由来することがあります。コアリポジトリクラスはLocalRepo、ForeignDBRepo、FileRepoです。
name
リポジトリに対するユニークな名前。

すべてのコアリポジトリに対して[edit]

url
基底の公開URL
thumbUrl
基底のサムネイルURL (URLとサムネイルの場所が異なる場合)。
hashLevels
ハッシュベースのファイルのディビジョンに対するディレクトリレベルの数
thumbScriptUrl
thumb.phpに対するURL (省略可能、推奨されません)
transformVia404
パーサ上のメディアファイルの変換をスキップして、代わりに404ハンドラに頼るかどうか。
initialCapital
$wgCapitalLinksと同等で、ファイル名を暗黙で大文字で始めるかどうか。現在の実装はローカルの$wgCapitalLinksとinitialCapitalがミスマッチする場合、 正しくない説明ページのリンクをするかもしれません。
pathDisclosureProtection
エラーメッセージからすべてのパラメータを削除したい場合は'paranoid'、パスを変更しないままにするには'none'、プレースホルダでパスを置き換える場合は'simple'デフォルトのLocalRepoは'simple'です。 Note, some image thumbnailing software puts the thumbnail path into the resulting thumb's metadata, so this setting may not provide full protection.
descBaseUrl
画像の説明ページのURLです。例: https://en.wikipedia.org/wiki/Image:
scriptDirUrl
MediaWiki のインストール先の URL であり、$wgScriptPathManual:$wgScriptPath と同等です。例: https://en.wikipedia.org/w
articleUrl
$wgArticlePathManual:$wgArticlePath と同等です。例: https://en.wikipedia.org/wiki/$1
fetchDescription
リモートファイルの説明ページのテキストを取得します。$wgFetchCommonsDescriptionsと同等です。
警告 警告: MediaWiki にバグがあるため、foreign wiki では、$wgUploadPathManual:$wgUploadPath に絶対 URL またはプロトコル相対 URL (一般的な相対 URL ではありません) を指定すべきです。指定しなかった場合、画像がある説明ページを適切に取得できません。
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 クラス[edit]

apibase
The base URL for the remote repository's API (eg: https://commons.wikimedia.org/w/api.php). ForeignAPIRepo のみに使用されます。
apiThumbCacheExpiry
サムネイルをキャッシュする期間。これを設定しないまたは0に設定するとローカルなキャッシングは無効化されます。

ForeignDBRepoクラス[edit]

directory
A path to MediaWiki's media directory local to the server, such as /var/www/wiki/images.
dbType, dbServer, dbUser, dbPassword, dbName, dbFlags
$wgDBserversの対応するメンバーと同等です。
tablePrefix
テーブルの接頭辞、外部wikiの$wgDBprefix
hasSharedCache
ローカルの$wgMemcを通してwikiの共有キャッシュがアクセスできる場合はtrueです
favicon
リモート リポジトリの favicon

既定値 (includes/Setup.php 内のコード):

if ( $wgUseSharedUploads ) {
  if ( $wgSharedUploadDBname ) {
    $wgForeignFileRepos[] = [
      '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[] = [
      'class' => 'FileRepo',
      'name' => 'shared',
      'directory' => $wgSharedUploadDirectory,
      'url' => $wgSharedUploadPath,
      'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
      'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
      'transformVia404' => !$wgGenerateThumbnailOnParse,
      'descBaseUrl' => $wgRepositoryBaseUrl,
      'fetchDescription' => $wgFetchCommonsDescriptions,
    ];
  }
}

ForeignDBViaLBRepo クラス[edit]

wiki
wiki-db-name used in $wgLBFactoryConfManual:$wgLBFactoryConf


ディレクトリのアクセス許可[edit]

You'll need rw on $IP/images and $IP/images/thumbs for whatever user php runs as.

使用法[edit]

MediaWiki バージョン: 1.13

ウィキメディア・コモンズにあるファイルの使用 : ForeignAPIRepo[edit]

Since 1.16.0 there is a more convenient shorthand to use Commons as a foreign repository: $wgUseInstantCommonsManual:$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.

これを使用するには以下が必要です:

  • MediaWiki 1.13 以降
  • 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.php returns {"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. You should place it in you "LocalSettings.php" file:

$wgForeignFileRepos[] = [
   'class'                   => 'ForeignAPIRepo',
   'name'                    => 'commonswiki', // Must be a distinct name
   'apibase'                 => 'https://commons.wikimedia.org/w/api.php',
   'hashLevels'              => 2,
   'fetchDescription'        => true, // Optional
   'descriptionCacheExpiry'  => 43200, // 12 hours, optional (values are seconds)
   'apiThumbCacheExpiry'     => 86400, // 24 hours, optional, but required for local thumb caching
   ];
If you decide to add this setting to your "LocalSettings.php" file instead of using $wgUseInstantCommons you cannot use wikimediacommons as a setting for name since it is already present in core MediaWiki code (in "Setup.php").

To pull images from another Wikimedia project, set apibase to this wiki's "api.php" file like e.g. https://en.wikipedia.org/w/api.php. 例:

$wgForeignFileRepos[] = [
   'class'                   => 'ForeignAPIRepo',
   'name'                    => 'enwiki',
   'apibase'                 => 'https://en.wikipedia.org/w/api.php',
   'hashLevels'              => 2,
   'fetchDescription'        => true,
   'descriptionCacheExpiry'  => 43200,
   'apiThumbCacheExpiry'     => 86400,
   ];

To embed an image in your installation, simply use [[image:name_of_commons_picture.jpg]].

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. Similarly, you need to set apiThumbCacheExpiry to zero if you prefer to use the foreign thumbnails.

アクセスできるデータベースにあるファイルの使用: ForeignDBRepo、ForeignDBViaLBRepo[edit]

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. This code should be deployed to LocalSettings.php.

$wgForeignFileRepos[] = [
    '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
];

Alternatively, if you have $wgLBFactoryConf set up for multiple wikis, you can use 'class' => 'ForeignDBViaLBRepo':

$wgForeignFileRepos[] = [
  'class' => 'ForeignDBViaLBRepo',
  'wiki' => 'wiki-db-name-used-with-wgLBFactoryConf',
  'name' => 'otherwiki', # displayname (eg. the vector-skin-tab “View on OtherWiki“) may be set at wiki-specific MediaWiki:Shared-repo-name-<otherwiki>
  'url' => 'http://wiki.example.com/media',
  'directory' => '/path/to/media',
  'hashLevels' => 2, # This must be the same for the other family member
  'tablePrefix' => 'mw_',
  'hasSharedCache' => false,
  'fetchDescription' => true,
  'scriptDirUrl' => 'http://wiki.example.com/w', # has effect whether description can be fetched
];

This needs not all the db* parameters as in ForeignDBRepo.

ローカルフォルダにあるファイルの使用 : FileRepo[edit]

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. This code should be deployed to LocalSettings.php.

The below code enabled media files from it:

$wgForeignFileRepos[] = [
   'class'            => 'FileRepo',
   'name'             => 'sharedFsRepo',
   'directory'        => 'media/',
   'hashLevels'       => 0,
   'url'              => 'http://your.wiki.tld/path/to/media/',
];

関連項目[edit]