Add annotation link to file pages
Signed-off-by: Justin Georgi <justin.georgi@gmail.com>
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
<?php
|
||||
namespace MediaWiki\Extension\AnatImageViewer;
|
||||
|
||||
use Parser;
|
||||
|
||||
class AnnotationHooks {
|
||||
|
||||
/**
|
||||
@@ -23,13 +25,23 @@ class AnnotationHooks {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* MWHook: Add preloaded text to editor on page creation
|
||||
*
|
||||
* @see https://www.mediawiki.org/wiki/Manual:Hooks/EditFormPreloadText
|
||||
*
|
||||
* @param string $text editor text
|
||||
* @param Title $Title title of the created page
|
||||
* @return bool|void True or no return value to continue or false to abort
|
||||
*/
|
||||
public static function onEditFormPreloadText( &$text, &$title ) {
|
||||
if ( $title->getNamespace() === NS_AV_ANNOT ) {
|
||||
$titleText = $title->getBaseText();
|
||||
$text = <<<NEWAN
|
||||
baseImage = ""
|
||||
baseImage = "$titleText.jpg"
|
||||
|
||||
[view]
|
||||
direction = ""
|
||||
direction = "L"
|
||||
|
||||
# [annotation.1]
|
||||
# position =
|
||||
@@ -40,6 +52,38 @@ class AnnotationHooks {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* MWHook: Add text to page after parsing
|
||||
*
|
||||
* @see https://www.mediawiki.org/wiki/Manual:Hooks/ParserAfterTidy
|
||||
*
|
||||
* @param Parser $parser wikitext parser that was created the text
|
||||
* @param string $text generated text
|
||||
* @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, "<h3 data-mw-anchor");
|
||||
if ($findLoc !== false) {
|
||||
$mwLink = "[[Annotation:" . $imName . "]]";
|
||||
$htmlLink = $parser->recursiveTagParseFully($mwLink);
|
||||
$newText = <<<ANHEAD
|
||||
<h2 id="fileannotate">Annotated File</h2>
|
||||
Click below to create or edit an annotated version of this image.<br/>
|
||||
ANHEAD;
|
||||
$text = $text . $newText . $htmlLink;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Small helper function to display information on the browser console
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user