diff --git a/PageImages.body.php b/PageImages.body.php index 16e93f5..ad5e3e1 100644 --- a/PageImages.body.php +++ b/PageImages.body.php @@ -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 diff --git a/PageImages.php b/PageImages.php index a988b33..13e2f14 100644 --- a/PageImages.php +++ b/PageImages.php @@ -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'; diff --git a/i18n/en.json b/i18n/en.json index 27208db..7106f31 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -1,7 +1,8 @@ { - "@metadata": { - "authors": [] - }, - "pageimages-desc": "Collects information about images used on page", - "pageimages-blacklist": "" -} \ No newline at end of file + "@metadata": { + "authors": [] + }, + "pageimages-desc": "Collects information about images used on page", + "pageimages-blacklist": "", + "pageimages-info-label": "Page image" +} diff --git a/i18n/qqq.json b/i18n/qqq.json index 077252f..782bf20 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -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" }