(Translated by https://www.hiragana.jp/)
Extension:页面图片 - MediaWiki Jump to content

Extension:页面图片

From mediawiki.org
This page is a translated version of the page Extension:PageImages and the translation is 30% complete.
此扩てんずい于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
りょう 151 (Ranked 42nd)
せいざい使用しようてきおおやけ开wikiすう 2,271 (Ranked 191st)
ぜん往translatewiki.net翻譯ほんやくPageImages扩展
問題もんだい 开启てきにん · 报告错误

The PageImages extension collects information about images used on a page.

Its aim is to return the single most appropriate thumbnail associated with an article.

PageImages also provides OpenGraph protocol metadata for articles on the wiki for 3rd parties like Facebook to extract.

あんそう

  • しもぶんけん,并将かい压后てきPageImagesぶんけん夹移动到extensions/录中。
    开发しゃ和代かずよ码贡けんじじん员应从Gitあんそう扩展,输入:cd extensions/
    git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/PageImages
  • はたしも列代れつだい放置ほうちざい您的LocalSettings.php てき底部ていぶ
    wfLoadExtension( 'PageImages' );
    
  • Configure as required
  • To initially assign the page images to the pages, run the "initImageData.php" script from the extensions maintenance directory (/path/to/extensions/PageImages/maintenance/)
  • Yes 完成かんせいざい您的wikiじょう导航いたりSpecial:Version,以验证已成功せいこうやすそう扩展。

配置はいち

$wgPageImagesDenylist is an array of sources for image denylists. Listed images will never be selected as page images. Examples:

$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',
	],
];

More than one source can be used at the same time.

The denylist itself should contain wikilinks to files, the rest of the content is irrelevant (and can contain links to other pages). れい如:

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

Remember that file links that result in images being added to the page will not work (these files are denylisted for a reason, right?), so don't forget the : in front of the links.

$wgPageImagesDenylistExpiry determines how long the list will remain cached, in seconds. Default: 15 * 60 (15 minutes).

$wgPageImagesExpandOpenSearchXml if set to true, PageImages will override the image detection in the opensearch API module with its own, more accurate results. だま认值为“false”。

$wgPageImagesNamespaces is an array of namespaces PageImages will be activated on. だま认为“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

Upgrade to MediaWiki 1.37+ notes

  • 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

The PageImages extension provides image information by adding a prop=pageimages to the properties API for action=query.

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"
            }
        }
    }
}

工作こうさく原理げんり

When a page is saved with a local image, the parser runs the hooks ParserMakeImageParams and LinksUpdate. The PageImages extension responds to these (and other hooks) and inserts a new property for the page into the page_props table. The property name is page_image_free and its value is the name of the image.

The extension only stores the chosen image name. Other features may display the image, such as Page information, Hovercards, and Mobile search while typing.

图像选择

如何いか检查与页面关联てき图像什么?

页面图像かい显示あずか?action=info页面。

How does it select images?

All images in the page are collected and a score for each image is calculated. The image with the highest score is selected as the page image. If the wiki is configured such that images contain metadata that specifies images are not freely licensed, the image with the best score that is also freely licensed is also stored. If no suitable image is found or all the images score badly (i.e. have a negative score), the page will not have any images.

If $wgPageImagesLeadSectionOnly is true, only images in the lead section will be considered. Currently this is true for only Wikipedia projects; all other projects can pull images from outside the lead.


How are images scored?

The best possible page image on Wikimedia wikis is one of the first four images in an article which has a width/height between 400-600px and a height/width which is twice the value of the other dimension.

  • The algorithm is configurable.
  • Scores are calculated by a combination of:
    • Image widths as defined in $wgPageImagesScores['width']
      • In Wikimedia wikis, images smaller than 119 pixels are weighted highly negatively. Images with widths between 400px-600px are favoured, with a preference for the lower bound.
      • Images inside galleries are scored separately using $wgPageImagesScores['galleryImageWidth']
        • In Wikimedia wikis gallery images which are smaller than 100 are disregarded.
    • Position in document is also considered as defined in $wgPageImagesScores['position']
      • On Wikimedia wikis, only the first 4 images that appear in the document are considered.
    • The ratio of the image's width to height is considered $wgPageImagesScores['ratio']
      • On Wikimedia wikis a ratio of 0.4 to 3.1 is allowed, with 0.6 to 2.1 preferred.
      • 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. Any other images will score negatively and be discarded.

How are pages images updated?

Pageimages populates images whenever the LinksUpdate hook runs, e.g. when a page is being edited.

Can I exclude certain page images?

Yes!

For an entire wiki, there is a page that administrators can edit at MediaWiki:Pageimages-denylist (example). Any images that appear here will not be used as page images for any article.

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.

How can I see the page image for a page?

Using the 页面しんいき link in the sidebar (or adding ?action=info to the URL) you'll be able to see the current image choice.

如何いかきよしじょ不良ふりょう图像?

仅当文章ぶんしょうちゅうてき链接更改こうかい时,页面图像ざいかい更改こうかい。对于紧急じょう况,请在页面ちゅう添加てんか/删除链接,必要ひつよう时进ぎょう恢复。 刷新さっしん缓存はたおこり作用さよう。 对于较大てき紧急じょう况,请提交Phabricatorこう单。

为什么我てき页面图像空白くうはくかまち

可能かのうあずか文章ぶんしょうちゅうてき视频内容ないようゆう关。 如果视频ぶんけん以空しろへいまく开头,则它はたなり为视频的だま认缩りゃく图,并且如果用作ようさく页面图像,它将なり为页めん图像。 わが们目まえただしざい对此进行おさむ复,使つかい您可以更改こうかい视频てきだま认缩りゃく图。 ゆう关更しんいき,请参见:phab:T92457phab:T22647

まいり