Move to namespace specific svg annotations #1
@@ -1,8 +1,8 @@
|
|||||||
{
|
{
|
||||||
"name": "AnatImageViewer",
|
"name": "AnnotatedImages",
|
||||||
"author": "Justin Georgi",
|
"author": "Justin Georgi",
|
||||||
"url": "https://gitea.azgeorgis.net/jgeorgi/AnatImageViewer",
|
"url": "https://gitea.azgeorgis.net/jgeorgi/AnatImageViewer",
|
||||||
"description": "This extension allows the creation of .an pages in the Files namespace which will be annotated images.",
|
"description": "This extension allows the creation of pages in the Annotation namespace which will create annotated images.",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"license-name": "MIT",
|
"license-name": "MIT",
|
||||||
"type": "media",
|
"type": "media",
|
||||||
@@ -12,23 +12,27 @@
|
|||||||
"id": 2218,
|
"id": 2218,
|
||||||
"constant": "NS_AV_ANNOT",
|
"constant": "NS_AV_ANNOT",
|
||||||
"name": "Annotation",
|
"name": "Annotation",
|
||||||
"protection": "annotations-edit"
|
"protection": "annotations-edit",
|
||||||
|
"subpages": false,
|
||||||
|
"content": true,
|
||||||
|
"defaultcontentmodel": "annotation"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 2219,
|
"id": 2219,
|
||||||
"constant": "NS_AV_ANNOT_TALK",
|
"constant": "NS_AV_ANNOT_TALK",
|
||||||
"name": "Annotation_talk"
|
"name": "Annotation_talk",
|
||||||
|
"subpages": true,
|
||||||
|
"content": false,
|
||||||
|
"defaultcontentmodel": "wikitext"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
"callback": "MediaWiki\\Extension\\AnatImageViewer\\AnnotationHooks::registrationCallback",
|
||||||
"AutoloadNamespaces": {
|
"AutoloadNamespaces": {
|
||||||
"MediaWiki\\Extension\\AnatImageViewer\\": "includes/"
|
"MediaWiki\\Extension\\AnatImageViewer\\": "includes/"
|
||||||
},
|
},
|
||||||
"MediaHandlers": {
|
"ContentHandlers": {
|
||||||
"image/annotation": "MediaWiki\\Extension\\AnatImageViewer\\AnatImageHandler"
|
"annotation": "MediaWiki\\Extension\\AnatImageViewer\\AnnotationHandler"
|
||||||
},
|
},
|
||||||
"Hooks": {
|
"Hooks": {
|
||||||
"MimeMagicInit": "MediaWiki\\Extension\\AnatImageViewer\\AnatImageHooks::onMimeMagicInit",
|
|
||||||
"MimeMagicImproveFromExtension": "MediaWiki\\Extension\\AnatImageViewer\\AnatImageHooks::onMimeMagicImproveFromExtension",
|
|
||||||
"ParserFirstCallInit": "MediaWiki\\Extension\\AnatImageViewer\\AnatImageHooks::onParserFirstCallInit"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace MediaWiki\Extension\AnatImageViewer;
|
|
||||||
|
|
||||||
use ImageHandler;
|
|
||||||
use BitmapMetadataHandler;
|
|
||||||
use Html;
|
|
||||||
|
|
||||||
class AnatImageHandler extends ImageHandler {
|
|
||||||
private const ANNOT_VERSION = '0.1';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Model cannot be displayed directly in a browser but can be rendered.
|
|
||||||
*
|
|
||||||
* @param File $file
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function mustRender( $file ) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Model can be rendered.
|
|
||||||
*
|
|
||||||
* @param File $file
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function canRender( $file ) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a MediaTransformOutput object representing the transformed output.
|
|
||||||
*
|
|
||||||
* @param File $image
|
|
||||||
* @param string $dstPath Filesystem destination path
|
|
||||||
* @param string $dstUrl Destination URL to use in output HTML
|
|
||||||
* @param array $params Arbitrary set of parameters validated by $this->validateParam()
|
|
||||||
* @param int $flags A bitfield, may contain self::TRANSFORM_LATER
|
|
||||||
* @return MediaTransformOutput
|
|
||||||
*/
|
|
||||||
public function doTransform($image, $dstPath, $dstUrl, $params, $flags = 0) {
|
|
||||||
return new AnatImageTransformOutput($image, $params);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
<?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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
32
includes/AnnotationContent.php
Normal file
32
includes/AnnotationContent.php
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
namespace MediaWiki\Extension\AnatImageViewer;
|
||||||
|
|
||||||
|
use TextContent;
|
||||||
|
|
||||||
|
class AnnotationContent extends TextContent {
|
||||||
|
|
||||||
|
public function __construct( $modelId = 'annotation' ) {
|
||||||
|
parent::__construct( $modelId );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
public function getTextForSearchIndex() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getWikitextForTransclusion() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTextForSummary( $maxLength = 250 ) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSize() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public function copy() {
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function isCountable( $hasLinks = null ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,60 +1,54 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MediaWiki\Extension\AnatImageViewer;
|
namespace MediaWiki\Extension\AnatImageViewer;
|
||||||
|
|
||||||
require_once __DIR__ . '/../vendor/autoload.php';
|
|
||||||
|
|
||||||
use Devium\Toml\Toml;
|
use Devium\Toml\Toml;
|
||||||
use MediaWiki\MediaWikiServices;
|
use MediaWiki\MediaWikiServices;
|
||||||
use MediaTransformOutput;
|
use Content;
|
||||||
|
use TextContentHandler;
|
||||||
|
use MediaWiki\Content\Renderer\ContentParseParams;
|
||||||
|
use ParserOutput;
|
||||||
use ConfigFactory;
|
use ConfigFactory;
|
||||||
use RequestContext;
|
use RequestContext;
|
||||||
use Html;
|
use Html;
|
||||||
|
|
||||||
class AnatImageTransformOutput extends MediaTransformOutput {
|
class AnnotationHandler extends TextContentHandler {
|
||||||
/**
|
private const ANNOT_VERSION = '0.1';
|
||||||
* Main Constructor
|
|
||||||
*
|
public function __construct( $modelId = 'annotation' ) {
|
||||||
* @access public
|
parent::__construct( $modelId, [ CONTENT_FORMAT_TEXT ] );
|
||||||
* @param File $file
|
|
||||||
* @param array $parameters Parameters for constructing HTML.
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct($file, $parameters) {
|
|
||||||
$this->file = $file;
|
|
||||||
$this->parameters = $parameters;
|
|
||||||
self::console_log($parameters, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* Fetch HTML for this transform output
|
public function serializeContent( Content $content, $format = null ) {
|
||||||
*
|
}
|
||||||
* @access public
|
|
||||||
* @param array $options Associative array of options. Boolean options
|
public function unserializeContent( $blob, $format = null ) {
|
||||||
* should be indicated with a value of true for true, and false or
|
}
|
||||||
* absent for false.
|
|
||||||
* alt Alternate text or caption
|
|
||||||
* desc-link Boolean, show a description link
|
|
||||||
* file-link Boolean, show a file download link
|
|
||||||
* custom-url-link Custom URL to link to
|
|
||||||
* custom-title-link Custom Title object to link to
|
|
||||||
* valign vertical-align property, if the output is an inline element
|
|
||||||
* img-class Class applied to the "<img>" tag, if there is such a tag
|
|
||||||
* preview Boolean, render is being called from a preview page
|
|
||||||
*
|
|
||||||
* @return string HTML
|
|
||||||
*/
|
*/
|
||||||
public function toHtml($options = []) {
|
|
||||||
$descriptText = $this->file->getDescriptionText();
|
public function makeEmptyContent() {
|
||||||
preg_match('/<pre anconfig.*?>([\S\s]*?)<\/pre>/',$descriptText,$annotDescript);
|
return new AnnotationContent();
|
||||||
$metadata = toml_decode($annotDescript[1], true);
|
}
|
||||||
|
|
||||||
|
public function supportsDirectEditing() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function fillParserOutput( Content $content, ContentParseParams $cpoParams, ParserOutput &$output ) {
|
||||||
|
// define $html somewhere
|
||||||
|
// e.g. $output->setText( $html );
|
||||||
|
|
||||||
|
self::console_log($content, true);
|
||||||
|
|
||||||
|
$metadata = toml_decode($content->getNativeData(), true);
|
||||||
|
|
||||||
if (isset($metadata['baseImage'])) {
|
if (isset($metadata['baseImage'])) {
|
||||||
$baseImage = MediaWikiServices::getInstance()->getRepoGroup()->findFile(`File:` . $metadata['baseImage']);
|
$baseImage = MediaWikiServices::getInstance()->getRepoGroup()->findFile('File:' . $metadata['baseImage']);
|
||||||
} else {
|
} else {
|
||||||
$baseImage = false;
|
$baseImage = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::buildSvg($metadata,$baseImage);
|
$output->setText( self::buildSvg($metadata,$baseImage) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
33
includes/AnnotationHooks.php
Normal file
33
includes/AnnotationHooks.php
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
namespace MediaWiki\Extension\AnatImageViewer;
|
||||||
|
|
||||||
|
use MediaWiki\MediaWikiServices;
|
||||||
|
use RequestContext;
|
||||||
|
use Html;
|
||||||
|
use ParserOutput;
|
||||||
|
|
||||||
|
class AnnotationHooks {
|
||||||
|
public static function registrationCallback() {
|
||||||
|
// Must match the name used in the 'ContentHandlers' section of extension.json
|
||||||
|
define( 'CONTENT_MODEL_ANNOTATION', 'annotation' );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user