Fix general File page annotation links
Signed-off-by: Justin Georgi <justin.georgi@gmail.com>
This commit is contained in:
@@ -34,8 +34,8 @@
|
|||||||
},
|
},
|
||||||
"Hooks": {
|
"Hooks": {
|
||||||
"AlternateEditPreview": "MediaWiki\\Extension\\AnatImageViewer\\AnnotationHooks::onAlternateEditPreview",
|
"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": {
|
"ContentHandlers": {
|
||||||
"annotation": "MediaWiki\\Extension\\AnatImageViewer\\AnnotationHandler"
|
"annotation": "MediaWiki\\Extension\\AnatImageViewer\\AnnotationHandler"
|
||||||
|
|||||||
@@ -2,6 +2,9 @@
|
|||||||
namespace MediaWiki\Extension\AnatImageViewer;
|
namespace MediaWiki\Extension\AnatImageViewer;
|
||||||
|
|
||||||
use Parser;
|
use Parser;
|
||||||
|
use ImagePage;
|
||||||
|
use MediaWiki\MediaWikiServices;
|
||||||
|
use MediaWiki\Title\Title;
|
||||||
|
|
||||||
class AnnotationHooks {
|
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 ImagePage $imagePage
|
||||||
* @param string $text generated text
|
* @param string $html
|
||||||
* @return bool|void True or no return value to continue or false to abort
|
* @return bool|void True or no return value to continue or false to abort
|
||||||
*/
|
*/
|
||||||
public static function onParserAfterTidy( Parser $parser, &$text ) {
|
public static function onImagePageAfterImageLinks( ImagePage $imagePage, &$html) {
|
||||||
$title = $parser->getTitle();
|
//TODO: Skip this if this is already svg annotation
|
||||||
if ($title->getNamespace() === NS_FILE) {
|
$newText = <<<ANHEAD
|
||||||
$titleText = $title->getBaseText();
|
<h2 id="fileannotate">Annotated File</h2>
|
||||||
|
Click below to create or edit an annotated version of this image.<br/>
|
||||||
|
ANHEAD;
|
||||||
|
$titleText = $imagePage->getFile()->getTitle()->getBaseText();
|
||||||
$extPos = strpos($titleText,'.');
|
$extPos = strpos($titleText,'.');
|
||||||
if ($extPos !== false) {
|
if ($extPos !== false) {
|
||||||
$imName = substr($titleText, 0, $extPos);
|
$imName = substr($titleText, 0, $extPos);
|
||||||
} else {
|
} else {
|
||||||
$imName = $titleText;
|
$imName = $titleText;
|
||||||
}
|
}
|
||||||
$findLoc = strpos($text, "<h3 data-mw-anchor");
|
|
||||||
if ($findLoc !== false) {
|
$linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
|
||||||
$mwLink = "[[Annotation:" . $imName . "]]";
|
$title = Title::newFromText( "Annotation:" . $imName );
|
||||||
$htmlLink = $parser->recursiveTagParseFully($mwLink);
|
$mwLink = $linkRenderer->makeLink( $title );
|
||||||
$newText = <<<ANHEAD
|
$html = $newText . $mwLink . $html;
|
||||||
<h2 id="fileannotate">Annotated File</h2>
|
|
||||||
Click below to create or edit an annotated version of this image.<br/>
|
|
||||||
ANHEAD;
|
|
||||||
$text = $text . $newText . $htmlLink;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user