Extension:PageImages

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual
Crystal Clear action run.png
PageImages

Release status: beta

Implementation API, Parser extension
Description Stores information about images representing a page
Author(s) Max Semenik (MaxSemtalk)
Latest version continuous updates
MediaWiki 1.20+
PHP 5.3+
Database changes No
License WTFPL 2.0
Download
Parameters
  • $wgPageImagesBlacklist
  • $wgPageImagesBlacklistExpiry
  • $wgPageImagesExpandOpenSearchXml
  • $wgPageImagesNamespaces
Hooks used
ParserMakeImageParams

LinksUpdate
OpenSearchXml

Translate the PageImages extension if it is available at translatewiki.net

Check usage and version matrix; code metrics

Phabricator:

Open tasks · Report a bug

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, attempting to return only meaningful images, e.g. not those from maintenance templates, stubs or flag icons. Currently it uses the first non-meaningless image used in the page.

Installation[edit | edit source]

  • Download and extract the file(s) in a directory called PageImages in your extensions/ folder. If you're a developer and this extension is in a Git repository, then instead you should clone the repository using:
git clone https://gerrit.wikimedia.org/r/p/mediawiki/extensions/PageImages.git
  • Add the following code at the bottom of your LocalSettings.php:
require_once "$IP/extensions/PageImages/PageImages.php";
  • Done! Navigate to "Special:Version" on your wiki to verify that the extension is successfully installed.

API[edit | edit source]

Page images information is exposed via a new prop=pageimages API.

Parameters:

piprop
What information about the page images to return (can be one or more values, pipe-delimited):
  • thumbnail - URL of image thumbnail.
  • name - Image title.
pithumbsize
Width of thumbnail in pixels. If omitted a default of 50px will be used.
pilimit
Number of pages to process.
picontinue
If more imformation is available, use this parameter to request it.

Example: /w/api.php?action=query&prop=pageimages&titles=Somepage&format=json

{
	"query": {
		"pages": {
			"1": {
				"pageid": 123,
				"ns": 0,
				"title": "Somepage",
				"thumbnail": {
					"source": "http:\/\/example.com\/w\/images\/thumb\/7\/70\/Example.png\/48px-Example.png",
					"width": 48,
					"height": 50
				},
				"pageimage": "Example.png"
			},
		}
	}
}

/w/api.php?action=query&prop=pageimages&titles=Somepage&format=xml

<?xml version="1.0"?>
<api>
  <query>
    <pages>
      <page pageid="123" ns="0" title="Somepage" pageimage="Example.png">
        <thumbnail source="http://example.com/w/images/thumb/7/70/Example.png/48px-Example.png" width="48" height="50" />
      </page>
    </pages>
  </query>
</api>

Configuration[edit | edit source]

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

$wgPageImagesBlacklist = array(
	// Page on local wiki
	array(
		'type' => 'db',
		'page' => 'MediaWiki:Pageimages-blacklist',
		'db' => false,
	),
	// Page on Wikimedia Commons, for other Wikimedia projects
	array(
		'type' => 'db',
		'page' => 'MediaWiki:Pageimages-blacklist',
		'db' => 'commonswiki',
	),
	// Page on Commons, for third-party sites using our web API
	array(
		'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.

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

$wgPageImagesExpandOpenSearchXml if set to true, PageImages will override Extension:OpenSearchXml's image detection with its own, more accurate results. Default: false.

$wgPageImagesNamespaces is an array of namespaces PageImages will be activated on. Default: NS_MAIN.

How it works[edit | edit source]

On a page is saved with a local image, 2 hooks onParserMakeImageParams and onLinksUpdate are called to insert a new property for the page (page_props). The prop_name is page_image and the value is the name of the image

See also[edit | edit source]