扩展:页面图像

From mediawiki.org
Jump to navigation Jump to search
This page is a translated version of the page Extension:PageImages and the translation is 26% complete.
Outdated translations are marked like this.
Other languages:
Deutsch • ‎English • ‎Türkçe • ‎français • ‎polski • ‎русский • ‎中文 • ‎日本語
此扩展已绑定在MediaWiki 1.34及以上版本 因此您不需要再次下载。 然而,您仍需要跟随提供的其他指示。
MediaWiki擴充功能手冊
OOjs UI icon advanced.svg
PageImages
发布状态: 稳定版
实现 API , 解析器扩展
描述 儲存代表一個頁面的圖像信息
作者 Max Semenik (MaxSem讨论)
最新版本 持续更新
兼容性方针 发行分支
MediaWiki 1.25+
PHP 5.4+
数据庫更改
许可协议 WTFPL 2.0
下载
  • $wgPageImagesNamespaces
  • $wgPageImagesBlacklistExpiry
  • $wgPageImagesScores
  • $wgPageImagesBlacklist
  • $wgPageImagesLeadSectionOnly
  • $wgPageImagesAPIDefaultLicense
  • $wgPageImagesExpandOpenSearchXml
翻譯PageImages擴充功能如在translatewiki.net可用
检查使用和版本矩阵。
问题 尚未完成的工作 · 回報錯誤

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.

Since MediaWiki 1.29, PageImages provides OpenGraph protocol metadata for articles on the wiki for 3rd parties like Facebook to extract.

安装

  • 下载文件,并将其放置在您extensions/文件夹中的PageImages目录内。
  • 将下列代码放置在您的LocalSettings.php的底部:
    wfLoadExtension( 'PageImages' );
    
  • Yes 完成 – 在您的wiki上导航至Special:Version,以验证扩展已成功安装。

致使用MediaWiki 1.27或更早版本的用户:

上面的说明介绍的是安装此扩展的新方法,它使用wfLoadExtension()。 如果您需要在早期版本(MediaWiki 1.27和更早版本)中安装此扩展,而不是wfLoadExtension( 'PageImages' );,您需要使用:

require_once "$IP/extensions/PageImages/PageImages.php";

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.

Parameters:
piprop

Which information to return:

thumbnail
URL and dimensions of thumbnail image associated with page, if any.
original
URL and original dimensions of image associated with page, if any.
name
Image title.
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

One of the following values: any, free
Default: free
picontinue

When more results are available, use this to continue.

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]

Response

{
  // 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.
  }
}

请求示例

请求一個條目的页面图片。

配置

$wgPageImagesBlacklist is an array of sources for image blacklists. Blacklisted images will never be selected as page images. Examples:

$wgPageImagesBlacklist = [
	// Page on local wiki
	[
		'type' => 'db',
		'page' => 'MediaWiki:Pageimages-blacklist',
		'db' => false,
	],
	// Page on Wikimedia Commons, for other Wikimedia projects using direct DB access
	[
		'type' => 'db',
		'page' => 'MediaWiki:Pageimages-blacklist',
		'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 blacklist itself should contain a wikilinks to blacklisted files, the rest of content is irrelevant (and can contain links to other pages). 例如:

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

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

$wgPageImagesBlacklistExpiry determines how long the blacklist 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”。

工作原理

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.

Image choice

How can I check which image is associated with a page?

Page images will be listed on the ?action=info page.

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. has a negative score), the page will not have any images.

If $wgPageImagesLeadSectionOnly is true, only images in the lead section will be considered. Currently it 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 the best possible images are images where the height is half the width or the height is double the width. Any images for which the ratio is less than 0.5 will score negatively and be discarded.

Be more technical please...

Pageimages populates images whenever the LinksUpdate hook runs.

In PageImages this is executed in LinksUpdateHookHandler::doLinksUpdate

Can I exclude certain page images?

Yes! There is a blacklist on every wiki that administrators can edit, at MediaWiki:Pageimages-blacklist (example). Any images that appear here will not be page images for any article.

What about just for one particular article?

Sadly not at the current time. Please use the blacklist or move the image outside the lead section.

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门票。

Purging will not work. For larger emergencies please file a Phabricator ticket.

为什么我的页面图像是空白框?

这可能与您文章中的视频内容有关。 如果视频文件以空白屏幕开头,则它将成为视频的默认缩略图,并且如果用作页面图像,它将成为页面图像。 我们目前正在对此进行修复,使您可以更改视频的默认缩略图。 有关更多信息,请参见:phab:T92457phab:T22647

参见