Manual:$wgForeignFileRepos

From mediawiki.org
This page is a translated version of the page Manual:$wgForeignFileRepos and the translation is 54% complete.
共有アップロード: $wgForeignFileRepos
外部リポジトリに対するリポジトリ構造の配列。
導入されたバージョン:1.11.0 (r22580)
除去されたバージョン:使用中
許容される値:(配列)
既定値:(下記参照)

詳細

警告 警告: When using Wikimedia Commons it is required to use HTTPS for links, instead of HTTP. As of 2015, Wikimedia Foundation redirects traffic from HTTP to HTTPS. For security reasons MediaWiki does not follow such redirects (see タスク T102566).

The solution is to use HTTPS in the URLs for Wikimedia Commons! If you use $wgUseInstantCommons , this issue is automatically fixed by using MediaWiki 1.25.2 or newer. If you have defined custom settings with $wgForeignFileRepos for Wikimedia Commons, then the URLs must be adjusted accordingly!

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

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

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

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 であり、$wgScriptPath と同等です。例: https://en.wikipedia.org/w
articleUrl
$wgArticlePath と同等です。例: https://en.wikipedia.org/wiki/$1
fetchDescription
リモートファイルの説明ページのテキストを取得します。$wgFetchCommonsDescriptions と同等です。
警告 警告: MediaWiki にバグがあるため、foreign wiki では、$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 クラス

apibase
The base URL for the remote repository's API (e.g. https://commons.wikimedia.org/w/api.php). ForeignAPIRepo のみに使用されます。
apiThumbCacheExpiry
サムネイルをキャッシュする期間。これに 0 を設定するとローカルなキャッシングは無効化されます。 Local thumb caching will reduce load on the foreign server, and improve user privacy. However it may cause your wiki to be slightly slower.

ForeignDBRepoクラス

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
テーブルの接頭辞、外部ウィキの $wgDBprefix
hasSharedCache
ローカルの $wgMemc を通してウィキの共有キャッシュがアクセスできる場合は true です
favicon
リモート リポジトリの favicon

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

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

ForeignDBViaLBRepo クラス

wiki
wiki-db-name used in $wgLBFactoryConf

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

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

使用法

MediaWiki バージョン:
1.31

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

Since 1.16.0 there 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.

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

  • 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 your "LocalSettings.php" file:

$wgForeignFileRepos[] = [
	'class' => ForeignAPIRepo::class,
	'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)
    'apiMetadataExpiry' => 14400, // 4 hours, optional. Consider increasing for better performance.
	'apiThumbCacheExpiry' => 86400, // 24 hours, optional, but required for local thumb caching (Note local thumb caching is often slower than not doing it)
];
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::class,
	'name' => 'enwikipedia',
	'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 [[File:name_of_commons_picture.jpg]].

Performance

$wgMainCacheType の設定も必要かもしれません。 Default is often CACHE_NONE, meaning it will load the image from the remote host on each page load which will be very slow. Similarly, you need to set apiThumbCacheExpiry to zero if you prefer to use the foreign thumbnails which will be faster. The default for apiMetadataExpiry is 4 hours. This is one of the most impactful settings for performance. Consider setting to a really high value, such as 604,800 (1 week) for best performance. However this may mean that it can take up to that long for changes to the file to get to your wiki.

Setting $wgResponsiveImages = false; may improve performance of instant commons at the cost of making images be lower quality on high resolution displays.

Currently MediaWiki does not support pipelining foreign api requests. 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.

There is also an alternative implementation at Extension:QuickInstantCommons which may be much faster

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

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::class,
	'name' => 'otherwiki',
	'url' => "https://example.org/w/images",
	'directory' => '/path/to/uploads',
	'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' => 'https://example.org/wiki/File:',
	'fetchDescription' => false
];

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

$wgForeignFileRepos[] = [
	'class' => ForeignDBViaLBRepo::class,
	'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' => 'https://example.org/w/images',
	'directory' => '/path/to/uploads',
	'hashLevels' => 2, # This must be the same for the other family member
	'tablePrefix' => 'mw_',
	'hasSharedCache' => false,
	'fetchDescription' => true,
	'scriptDirUrl' => 'https://example.org/w', # has effect whether description can be fetched
];

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

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

ご利用のウィキでメディアは単一のフォルダに入れておいて使います。現状ではまだ見本用の機能でキャッシュ機能がないため、活発なウィキや重いサーバにとっては遅すぎるかもしれません。このコードを設定 LocalSettings.php の末尾に追加します。

以下のコードはそこからメディアファイルを読み込みます。

$wgForeignFileRepos[] = [
	'class' => FileRepo::class,
	'name' => 'sharedFsRepo',
	'directory' => 'media',
	'hashLevels' => 0,
	'url' => 'https://shared.example.org/path/to/media',
];

注意点

最大の効果を得るには、ウィキの根本的な目的がコモンズとして$wgForeignFileReposのターゲットになるものを使います。 複数のコンテンツウィキでファイルを共有するからと言って、2件の間で相互に相手を未知のリポジトリとして指定することは避けなければなりません。ページの閲覧や編集のたび、両方のウィキからファイルを呼びに行き、無用なファイル要求が発生してしまいます。

同様に、コモンズウィキとコンテンツ用ウィキで単一のデータベースを共用することも回避してください。特に、サービスプロバイダもしくは管理者による制約でForeignDBRepo の代わりにForeignAPIRepo を使う必要がある場合は、厳守するしかありません。 これが原因で、長く使われていた多くのデータベースが一時的ながら正常に機能せず、あるいは非常に流通量や活動の少ないウィキでさえデータベースの接続上限を超えてしまう現象が発生します。

関連項目