Jump to content

Extension:页面图片

From mediawiki.org
This page is a translated version of the page Extension:PageImages and the translation is 76% 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
季度下載量 123 (Ranked 43rd)
正在使用的公开wiki数 2,271 (Ranked 191st)
前往translatewiki.net翻譯PageImages扩展
問題 开启的任务 · 报告错误

PageImages收集页面中使用图片的信息。

它的目的是返回一张与文章相关度最高的缩略图。

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' );
    
  • 按需求配置
  • 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是一个不被采用的图像文件列表数组。被列出的文件永远不会被选为页面图像。例如:

$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 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]]
...

请记住,导致图像被添加到页面的文件链接将不起作用(这些文件被拒绝是有原因的,对吧?),所以不要忘记链接前的:

$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 a 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 backward 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. 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页面。

它用什么方式选择图像?

收集页面中的所有图像,并计算每个图像的分数。 其中得分最高的图像将被选为页面图像。 如果该图像包含了wiki已配置的无自由许可的元数据,则会选择分数最高且自由许可的图像。 如果没有找到合适的图像或所有图像分数都很差(即分数为负),页面将没有任何图像。

如果$wgPageImagesLeadSectionOnly为true,则只有导言段落中的图像会作为备选。 目前,只有Wikipedia中该选项为true;所有其他项目都可以从导言段落外提取图像。

图像分数如何计算?

Wikimedia上预估最好的页面图像是文章中前四个图像之一,其宽/高为400-600px,且宽/高中的一项为另一项的二倍。

  • 该计算方法可进行配置。
  • 分数由以下因素组合计算:
    • 宽度被定义为 $wgPageImagesScores['width']
      • 在Wikimedia中,小于119像素的图像会扣很多分。 宽400px-600px的图像更被偏爱,它有一个下限分数。
      • galleries中的图片使用$wgPageImagesScores['galleryImageWidth']单独评分
        • 在Wikimedia中,小于100的gallery图像将被忽略。
    • 在文档中的位置也参照$wgPageImagesScores['position']中定义的值进行计算
      • 在Wikimedia中,只有文档中的前四张图像会入选。
    • 图像的最佳宽高比被定义在$wgPageImagesScores['ratio']
      • 在Wikimedia中,允许的比例为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 and increase from zero, with a new scoring multiple not taking effect until the key has met or exceeded its value but not exceeded the next key. 任何其他图像都将得分为负并被弃选。

页面图像如何被更新?

页面图像在LinksUpdate 钩子运行时填充图像,例如在页面被编辑时。

我可以排除某些页面图像吗?

可以!

对于整个wiki而言,有一个允许管理员编辑的配置页面MediaWiki:Pageimages-denylist(示例) 定义在这其中的图像不会被作为任何主题的页面图像。

对于特定页面,将|class=notpageimage添加到要排除的每个图像中。例如,[[File:Example.png|class=notpageimage]]。 更多详情请访问phab:T301588

How can I see the image of a page?

使用侧边栏中的“页面信息”链接(或向URL添加?action=info),您将能够看到当前选择的图像。

如何清除不合适的图像?

仅当文章中的链接更改时,页面图像才会更改。对于紧急情况,请在页面中添加/删除链接,必要时进行恢复。 刷新缓存将不起作用。 对于较大的紧急情况,请提交Phabricator工单。

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

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

參見