diff --git a/extension.json b/extension.json index 3e818d1..9570030 100644 --- a/extension.json +++ b/extension.json @@ -34,8 +34,8 @@ }, "Hooks": { "AlternateEditPreview": "MediaWiki\\Extension\\AnatImageViewer\\AnnotationHooks::onAlternateEditPreview", - "ParserAfterTidy": "MediaWiki\\Extension\\AnatImageViewer\\AnnotationHooks::onParserAfterTidy", - "EditFormPreloadText": "MediaWiki\\Extension\\AnatImageViewer\\AnnotationHooks::onEditFormPreloadText" + "EditFormPreloadText": "MediaWiki\\Extension\\AnatImageViewer\\AnnotationHooks::onEditFormPreloadText", + "ImagePageAfterImageLinks": "MediaWiki\\Extension\\AnatImageViewer\\AnnotationHooks::onImagePageAfterImageLinks" }, "ContentHandlers": { "annotation": "MediaWiki\\Extension\\AnatImageViewer\\AnnotationHandler" diff --git a/includes/AnnotationHooks.php b/includes/AnnotationHooks.php index 18c08d0..a695c31 100644 --- a/includes/AnnotationHooks.php +++ b/includes/AnnotationHooks.php @@ -2,6 +2,9 @@ namespace MediaWiki\Extension\AnatImageViewer; use Parser; +use ImagePage; +use MediaWiki\MediaWikiServices; +use MediaWiki\Title\Title; class AnnotationHooks { @@ -53,35 +56,32 @@ class AnnotationHooks { } /** - * MWHook: Add text to page after parsing + * MWHook: Add text to page after image links created * - * @see https://www.mediawiki.org/wiki/Manual:Hooks/ParserAfterTidy + * @see https://www.mediawiki.org/wiki/Manual:Hooks/ImagePageAfterImageLinks * - * @param Parser $parser wikitext parser that was created the text - * @param string $text generated text + * @param ImagePage $imagePage + * @param string $html * @return bool|void True or no return value to continue or false to abort */ - public static function onParserAfterTidy( Parser $parser, &$text ) { - $title = $parser->getTitle(); - if ($title->getNamespace() === NS_FILE) { - $titleText = $title->getBaseText(); - $extPos = strpos($titleText,'.'); - if ($extPos !== false) { - $imName = substr($titleText, 0, $extPos); - } else { - $imName = $titleText; - } - $findLoc = strpos($text, "