44 lines
1.6 KiB
PHP
44 lines
1.6 KiB
PHP
<?php
|
|
namespace MediaWiki\Extension\AnatImageViewer;
|
|
|
|
class AnnotationHooks {
|
|
|
|
/**
|
|
* MWHook: Display model when model file page edits are previewed
|
|
*
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/AlternateEditPreview
|
|
*
|
|
* @param EditPage $editor access to information about the edit page itself
|
|
* @param Content $content access to the current content of the editor
|
|
* @param string &$previewHTML by reference access to the resultant compiled preview html
|
|
* @param ?ParserOutput &$parserOutput
|
|
* @return bool|void True to continue default processing or false to abort for custom processing
|
|
*/
|
|
public static function onAlternateEditPreview( $editor, $content, string &$previewHTML, ?ParserOutput &$parserOutput ) {
|
|
$title = $editor->getTitle();
|
|
if ( $title->getNamespace() === NS_AV_ANNOT ) {
|
|
$out = $editor->getContext()->getOutput();
|
|
$out->addModules('ext.annot.prev');
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Small helper function to display information on the browser console
|
|
*
|
|
* Usage:
|
|
* echo '<script>';
|
|
* self::console_log('logged string');
|
|
* echo '</script>';
|
|
*
|
|
* @param $data information to display
|
|
* @param bool $add_script_tags true to put information is inside complete script tag
|
|
*/
|
|
public static function console_log($data, $add_script_tags = false) {
|
|
$command = 'console.log('. json_encode($data, JSON_HEX_TAG).');';
|
|
if ($add_script_tags) {
|
|
$command = '<script>'. $command . '</script>';
|
|
}
|
|
echo $command;
|
|
}
|
|
} |