Extension:PageImages

This page is a translated version of the page Extension:PageImages and the translation is 80% complete.
Outdated translations are marked like this.
この拡張機能は MediaWiki 1.34 以降に同梱されています。 そのため再度ダウンロードする必要はありません。 しかし、提供されているその他の手順に従う必要はあります。
This extension is under code stewardship review and not actively maintained (タスク T252249). No new feature requests will be considered during this period.
MediaWiki 拡張機能マニュアル
PageImages
リリースの状態: 安定
実装 API , パーサー拡張機能
説明 ページを表す画像に関する情報を格納する
作者 Max Semenik (MaxSemトーク)
最新バージョン 継続的な更新
互換性の方針 MediaWiki とともにリリースされるスナップショット。 master には後方互換性がありません。
MediaWiki 1.37+
PHP 7.3.19+
データベースの変更 いいえ
ライセンス WTFPL 2.0
ダウンロード
  • $wgPageImagesOpenGraphFallbackImage
  • $wgPageImagesDenylist
  • $wgPageImagesScores
  • $wgPageImagesNamespaces
  • $wgPageImagesAPIDefaultLicense
  • $wgPageImagesExpandOpenSearchXml
  • $wgPageImagesLeadSectionOnly
  • $wgPageImagesOpenGraph
  • $wgPageImagesDenylistExpiry
Quarterly downloads 146 (Ranked 50th)
Public wikis using 2,271 (Ranked 191st)
translatewiki.net で翻訳を利用できる場合は、PageImages 拡張機能の翻訳にご協力ください
問題点 未解決のタスク · バグを報告

PageImages拡張機能は、ページ上で使用されるイメージに関する情報を収集します。

その目的は、記事に関連付けられた単一の最も適切なサムネイルを返すことです。

PageImagesは、Facebookなどのサードパーティが抽出できるように、Wiki上の記事のOpenGraphプロトコルのメタデータも提供します。

インストール

  • ダウンロードして、ファイルをextensions/フォルダー内のPageImagesという名前のディレクトリ内に配置します。
    開発者とコード寄稿者は、上記の代わりに以下を使用してGitからインストールします:cd extensions/
    git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/PageImages
  • 以下のコードを LocalSettings.php ファイルの末尾に追加します:
    wfLoadExtension( 'PageImages' );
    
  • 必要に応じて設定します
  • ページ画像を最初にページに割り当てるには、extensionsメンテナンスディレクトリから「initImageData.php」スクリプトを実行します。 (/path/to/extensions/PageImages/maintenance/)
  •   完了 – ウィキの「Special:Version」に移動して、拡張機能が正しくインストールされたことを確認します。

設定

$wgPageImagesDenylist は画像拒否リストのソースの配列です。リストに載っている画像はページの画像として決して選択されません。例:

$wgPageImagesDenylist = [
	// Page on local wiki
	[
		'type' => 'db',
		'page' => 'MediaWiki:Pageimages-denylist',
		'db' => false,
	],
	// Page on Wikimedia Commons, for other Wikimedia projects using direct DB access
	[
		'type' => 'db',
		'page' => 'MediaWiki:Pageimages-denylist',
		'db' => 'commonswiki',
	],
	// Page on Commons, for third-party sites using web access
	[
		'type' => 'url',
		'url' => 'http://commons.wikimedia.org/w/index.php?title=somepage&action=raw',
	],
];

複数のソースを同時に使用することができます。

ブラックリスト自体に、ブラックリスト指定したファイルのウィキリンクを格納すべきで、それ以外の内容は不適切(であり他のページへのリンクを含めることができます)。 例:

* [[:File:First denylisted file.png]]
* [[:File:Second denylisted file.jpeg]]
...

注意したいのは、ページに追加した画像から発生したファイルリンクは無効(そういうファイルは理由があってブラックリスト指定されましたよね?)なため、リンクの先頭に半角コロン:の入力を忘れないでください。

$wgPageImagesDenylistExpiry は、ブラックリストがキャッシュされる期間を秒単位で指定します。 既定値: 15 * 60 (15分)

$wgPageImagesExpandOpenSearchXml に true が設定されている場合、PageImagesはopensearch APIモジュール内のイメージ検出を、より正確な結果で上書きします。 既定値: false

$wgPageImagesNamespaces は PageImages が有効になる名前空間の配列です。 既定値: NS_MAIN

After the change, you'll have to run refreshLinks.php to generate the Page image information for those namespaces (hopefully, you can use the --namespace parameter to process only pages on the affected namespaces, since that script is very resource-intensive)

$wgPageImagesOpenGraph enables or disables the OpenGraph meta tags (could be useful if other extensions manage these tags) (1.39+). Default: true

$wgPageImagesOpenGraphFallbackImage is a URL to fallback image that will be shown when there is no image on a page. Default: false

MediaWiki 1.37+へのアップグレード

  • Since MediaWiki 1.37, $wgPageImagesBlacklist and $wgPageImagesBlacklistExpiry have been renamed to $wgPageImagesDenylist and $wgPageImagesDenylistExpiry respectively. There's no backwards compatibility code added to accept the old variable names, which means you should change the variable names during the upgrade, or define both variables in advance in preparation for the upgrade.
  • Since MediaWiki 1.37, the default page value for $wgPageImagesDenylist has been changed from MediaWiki:Pageimages-blacklist to MediaWiki:Pageimages-denylist. If you've added content to MediaWiki:Pageimages-blacklist on your wiki, you should rename it during the upgrade. If you want to prepare in advance for the upgrade, you can rename the page to the new name, and also set $wgPageImagesBlacklist (the old variable name) to the new page name, and the default value will be used when upgrading, which should match your previous change.

API

PageImages拡張機能は、action=queryproperties APIにprop=pageimagesを追加することによって画像情報を提供します。

prop=pageimages (pi)

(main | query | pageimages)
  • This module requires read rights.
  • Source: PageImages
  • License: WTFPL

Returns information about images on the page, such as thumbnail and presence of photos.

Specific parameters:
Other general parameters are available.
piprop

Which information to return:

thumbnail
URL and dimensions of thumbnail image associated with page, if any.
name
Image title.
original
URL and original dimensions of image associated with page, if any.
Values (separate with | or alternative): name, original, thumbnail
Default: thumbnail|name
pithumbsize

Maximum width in pixels of thumbnail images.

Type: integer
Default: 50
pilimit

Properties of how many pages to return.

Type: integer or max
The value must be between 1 and 50.
Default: 50
pilicense

Limit page images to a certain license type:

free
Only free images.
any
Best image, whether free or non-free.
One of the following values: any, free
Default: free
picontinue

When more results are available, use this to continue. More detailed information on how to continue queries can be found on mediawiki.org.

Type: integer
pilangcode

Code for the language the image is going to be rendered in if multiple languages are supported

Example:
Get name and 100-pixel thumbnail of an image on the Albert Einstein page.
api.php?action=query&prop=pageimages&titles=Albert%20Einstein&pithumbsize=100 [open in sandbox]


反応

{
  // piprop.name (and image exists)
  pageimage?: string // Source image filename (basename of original.source).
  // piprop.thumbnail (and image exists)
  thumbnail?: {
    source: string // Thumbnail image URL.
    width: number // Thumbnail image width in pixels.
    height: number // Thumbnail image height in pixels.
  }
  // piprop.original (and image exists)
  original?: {
    source: string // Source image URL.
    width: number // Source image width in pixels.
    height: number // Source image height in pixels.
  }
}

サンプル リクエスト

記事のページ画像をリクエストします。

結果
{
    "query": {
        "normalized": [
            {
                "from": "Lightbox_demo",
                "to": "Lightbox demo"
            }
        ],
        "pages": {
            "162510": {
                "pageid": 162510,
                "ns": 0,
                "title": "Lightbox demo",
                "thumbnail": {
                    "source": "https://upload.wikimedia.org/wikipedia/commons/thumb/e/e9/Crystal_Clear_app_korganizer.png/50px-Crystal_Clear_app_korganizer.png",
                    "width": 50,
                    "height": 50
                },
                "pageimage": "Crystal_Clear_app_korganizer.png"
            }
        }
    }
}

動作の仕組み

ローカル画像を含むページを保存するとパーサーParserMakeImageParamsLinksUpdateフックを実行します。 PageImages拡張機能はこれら(とその他のフック)に反応して page_props テーブルにそのページの新しい属性を挿入します。 属性は page_image_free という名前で値にはその画像の名前が入ります。

拡張機能が保存するのは選択した画像のファイル名のみです。例えばPage informationHovercardsなどその他の拡張機能や、モバイル版では検索語を入力中に画像が表示されることがあります。

画像の選択

どの画像が特定のページに関連付けされたか識別する方法は?

ページ画像の一覧は ?action=info ページにあります。

どのように画像を選択しているのか?

ページ内の画像をすべて集め、1点ごとに採点します。 その中で最も得点が多かった画像をページ画像に選びます。 画像がライセンスフリーではないとするメタデータをウィキが検出した場合、ライセンスフリーで最も得点が高い画像も合わせて保存します。 適する画像が見つからない、またはどの画像も得点が低い (例えばマイナス点であるなど) 場合には、ページ画像を保管しない状態になります。

$wgPageImagesLeadSectionOnly が真の場合は、処理の対象をリード文内の画像のみに限定します。 現状で真が既定なのはウィキペディアのプロジェクト群だけであり、その他すべてのプロジェクト群では指定する画像の範囲はリード文に限定されません。


画像はどのようにスコアリングされるのか?

ウィキメディアの理想的なページ画像とは縦か横のサイズが400-600px、横か縦がその2倍、記事内の1–4番目に置かれた画像です。

  • アルゴリズムは設定変更できます。
  • 評価は以下の条件の組み合わせで算出します:
    • 画像の幅の定義は $wgPageImagesScores['width'] のとおり
      • ウィキメディアのウィキ群では一辺 119 ピクセル以下の画像は大きく評価を下げます。 条件がよい幅とは 400px–600px の範囲で、できるだけこの下限に近いほうが評価は上がります。
      • ギャラリー内の画像の評価には別途、$wgPageImagesScores['galleryImageWidth'] を使います
        • ギャラリーで一辺 100 ピクセルより小さい画像はウィキメディアのウィキ群では対象外です。
    • 文書内の位置も、$wgPageImagesScores['position']で定義されているように考慮されます
      • ウィキメディアのウィキ群の文書で最初の4点の画像のみ対象にします。
    • 画像の縦横比は $wgPageImagesScores['ratio'] として扱います
      • ウィキメディアのウィキでは0.4~3.1の比率が認め、0.6~2.1が好まれます。
      • The default value is $wgPageImagesScores['ratio'] = ["3" => -100, "5" => 0, "20" => 5, "30"=> 0, "31"=> -100]; with the key representing the width divided by height, rounded to the tenths place, and the decimal shifted one position to the right. An image 400px wide by 300px high would have a value of 13. The key's value is the scoring multiple associated with that ratio. Keys are selected increasing from zero with a new scoring multiple not taking effect until the key has been met or exceeded its value but not exceeded the next key. 他の画像は評価が下がり削除処分されます。

How are pages images updated?

PageImages 拡張機能は、LinksUpdate フックを実行するごとに画像をデータベースに登録します。

特定のページ画像を除外できますか?

Yes!

ウィキ全体では、管理者がMediaWiki:Pageimages-denylistで編集できるページがあります()。 ここに載った画像はどの記事でもページ画像にはなりません。

For specific pages, add |class=notpageimage to each image you want to exclude. For example, [[File:Example.png|class=notpageimage]]. More details are at phab:T301588.

特定のページのページ画像を見るには?

サイドメニューにあるページ情報リンクを使用(もしくはURLの末尾に ?action=info を追加)すると、現状で選択された画像を表示します。

不適切な画像をパージしたいのですが方法は?

ページ画像は記事内のリンクを修正した時のみ変更されます。緊急の場合にはページにあるリンクの追加や削除、必要なら特定版の巻き戻しをします。 キャッシュの廃棄(パージ)では効果はありません。 緊急の処理を要する問題の規模が大きい場合はPhabricatorにチケットという作業依頼を投稿します。

ページ画像がただの四角い箱になってしまった理由は?

おそらくページの動画コンテンツと関係があると考えられます。 動画ファイルの冒頭に白紙の部分があると、それがその動画の既定のサムネイルになるため、ページ画像に使用すると白紙になってしまいます。 この現象は修正作業中で、動画のサムネイルを利用者が選べるようにする予定です。 詳細はphab:T92457phab:T22647を参照してください。

関連項目