Display page image on action=info

Show the page image as one item under "Basic information" on action=info.

Bug: 64178
Change-Id: Id561c817fdda057c9dd8beae275c3b978b4dd20a
This commit is contained in:
wctaiwan 2014-05-02 02:29:28 -04:00 committed by Max Semenik
parent 566ce74936
commit 587bf22f51
4 changed files with 49 additions and 7 deletions

View file

@ -133,6 +133,45 @@ class PageImages {
return true;
}
/**
* InfoAction hook handler, adds the page image to the info=action page
* @see https://www.mediawiki.org/wiki/Manual:Hooks/InfoAction
* @param IContextSource $context
* @param array $pageInfo
* @return bool
*/
public static function onInfoAction( IContextSource $context, &$pageInfo ) {
global $wgDefaultUserOptions, $wgThumbLimits;
wfProfileIn( __METHOD__ );
$imageFile = self::getPageImage( $context->getTitle() );
if ( $imageFile === null ) {
// The page has no image
wfProfileOut( __METHOD__ );
return true;
}
$thumbSetting = $context->getUser()->getOption(
'thumbsize',
$wgDefaultUserOptions['thumbsize']
);
$thumbSize = $wgThumbLimits[$thumbSetting];
$imageHtml = $imageFile->transform( array( 'width' => $thumbSize ) )->toHtml(
array(
'alt' => $imageFile->getTitle()->getText(),
'desc-link' => true,
)
);
$pageInfo['header-basic'][] = array(
$context->msg( 'pageimages-info-label' ),
$imageHtml
);
wfProfileOut( __METHOD__ );
return true;
}
/**
* OpenSearchXml hook handler, enhances Extension:OpenSearchXml results with this extension's data
* @param array $results

View file

@ -23,6 +23,7 @@ $wgExtensionMessagesFiles['PageImages'] = __DIR__ . "/PageImages.i18n.php";
$wgHooks['ParserMakeImageParams'][] = 'PageImages::onParserMakeImageParams';
$wgHooks['LinksUpdate'][] = 'PageImages::onLinksUpdate';
$wgHooks['OpenSearchXml'][] = 'PageImages::onOpenSearchXml';
$wgHooks['InfoAction'][] = 'PageImages::onInfoAction';
$wgAPIPropModules['pageimages'] = 'ApiQueryPageImages';

View file

@ -1,7 +1,8 @@
{
"@metadata": {
"authors": []
},
"pageimages-desc": "Collects information about images used on page",
"pageimages-blacklist": ""
}
"@metadata": {
"authors": []
},
"pageimages-desc": "Collects information about images used on page",
"pageimages-blacklist": "",
"pageimages-info-label": "Page image"
}

View file

@ -5,5 +5,6 @@
]
},
"pageimages-desc": "{{desc|name=Page Images|url=http://www.mediawiki.org/wiki/Extension:PageImages}}",
"pageimages-blacklist": "List of images. They will never be selected as page images"
"pageimages-blacklist": "List of images. They will never be selected as page images",
"pageimages-info-label": "Label for the page image field on the info=action page"
}