77 lines
2.5 KiB
PHP
77 lines
2.5 KiB
PHP
<?php
|
|
namespace MediaWiki\Extension\AnatImageViewer;
|
|
|
|
use MediaWiki\MediaWikiServices;
|
|
use RequestContext;
|
|
use Html;
|
|
use ParserOutput;
|
|
|
|
class AnatImageHooks {
|
|
/**
|
|
* MWHook: Add an (fake) mime types to MimeMagic
|
|
*
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/MimeMagicInit
|
|
*
|
|
* @param MimeAnalyzer $mime Instance of MW MimeAnalyzer object
|
|
*/
|
|
public static function onMimeMagicInit($mime) {
|
|
$mime->addExtraTypes('image/annotation an');
|
|
$mime->addExtraInfo('image/annotation [METAIMAGE]');
|
|
}
|
|
|
|
/**
|
|
* MWHook: Make sure that an files (fake) get the proper mime assignement on upload
|
|
*
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/MimeMagicImproveFromExtension
|
|
*
|
|
* @param MimeAnalyzer $mimeAnalyzer Instance of MW MimeAnalyzer object
|
|
* @param string $ext extention of upload file
|
|
* @param string &$mime current assigned mime type
|
|
*/
|
|
public static function onMimeMagicImproveFromExtension( $mimeAnalyzer, $ext, &$mime ) {
|
|
if ( $mime !== 'image/annotation' && in_array( $ext, ['an'] ) ) {
|
|
$mime = 'image/annotation';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* MWHook: Called when the parser initializes for the first time
|
|
*
|
|
* @param Parser $parser: Parser object being initialized
|
|
*/
|
|
static function onParserFirstCallInit( $parser ) {
|
|
$parser->setHook('anconfig', array( __CLASS__, 'renderConfigTag'));
|
|
}
|
|
|
|
/**
|
|
* Render the config toml in a <pre> tag
|
|
*
|
|
* @param $input The text inside the custom tag
|
|
* @param array $args Any attributes given in the tag
|
|
* @param Parser $parser The parser object
|
|
* @param PPFrame $frame The parent frame calling the parser
|
|
* @return string HTML string of output
|
|
*/
|
|
static function renderConfigTag( $input, array $args, $parser, $frame ) {
|
|
return '<pre anconfig>' . $input . '</pre>';
|
|
}
|
|
|
|
/**
|
|
* 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;
|
|
}
|
|
} |