Proper file and gallery display
Signed-off-by: Justin Georgi <justin.georgi@gmail.com>
This commit is contained in:
@@ -7,11 +7,11 @@ use Devium\Toml\Toml;
|
|||||||
use Devium\Toml\TomlError;
|
use Devium\Toml\TomlError;
|
||||||
use MediaWiki\MediaWikiServices;
|
use MediaWiki\MediaWikiServices;
|
||||||
use Content;
|
use Content;
|
||||||
use Title;
|
use MediaWiki\Title\Title;
|
||||||
use CodeContentHandler;
|
use CodeContentHandler;
|
||||||
use MediaWiki\Content\Renderer\ContentParseParams;
|
use MediaWiki\Content\Renderer\ContentParseParams;
|
||||||
use ParserOutput;
|
use ParserOutput;
|
||||||
use Html;
|
use MediaWiki\Html\Html;
|
||||||
use IContextSource;
|
use IContextSource;
|
||||||
use MediaWiki\Content\ValidationParams;
|
use MediaWiki\Content\ValidationParams;
|
||||||
use Status;
|
use Status;
|
||||||
@@ -88,6 +88,8 @@ class AnnotationHandler extends CodeContentHandler {
|
|||||||
private function buildSvg($metadata) {
|
private function buildSvg($metadata) {
|
||||||
//Set SVG UID-ish for element IDs
|
//Set SVG UID-ish for element IDs
|
||||||
$svgID = bin2hex(random_bytes(6));
|
$svgID = bin2hex(random_bytes(6));
|
||||||
|
self::console_log($svgID, true);
|
||||||
|
self::console_log(wfRandomString(12), true);
|
||||||
|
|
||||||
//Check if the image to annotate has been set
|
//Check if the image to annotate has been set
|
||||||
if (isset($metadata['baseImage'])) {
|
if (isset($metadata['baseImage'])) {
|
||||||
@@ -102,18 +104,20 @@ class AnnotationHandler extends CodeContentHandler {
|
|||||||
$vbHeight = 100;
|
$vbHeight = 100;
|
||||||
$vbWidth = 100;
|
$vbWidth = 100;
|
||||||
if ($baseImage) {
|
if ($baseImage) {
|
||||||
$baseImageUrl = $baseImage->getFullUrl();
|
$imageStr = 'data:image/png;base64,' . base64_encode(file_get_contents($baseImage->getLocalRefPath()));
|
||||||
$baseHeight = $baseImage->getHeight();
|
$baseHeight = $baseImage->getHeight();
|
||||||
$baseWidth = $baseImage->getWidth();
|
$baseWidth = $baseImage->getWidth();
|
||||||
$baseAspect = $baseHeight / $baseWidth;
|
$baseAspect = $baseHeight / $baseWidth;
|
||||||
$vbWidth = 100 / sqrt($baseAspect);
|
$vbWidth = 100 / sqrt($baseAspect);
|
||||||
$vbHeight = $baseAspect * $vbWidth;
|
$fixScale = $baseWidth / 100 * sqrt($baseAspect);
|
||||||
|
self::console_log($fixScale, true);
|
||||||
|
//$vbHeight = $baseAspect * $vbWidth;
|
||||||
$attrBase = array(
|
$attrBase = array(
|
||||||
'class' => 'annot-base',
|
'class' => 'annot-base',
|
||||||
'preserveAspectRatio' => 'none',
|
'preserveAspectRatio' => 'none',
|
||||||
'width' => $vbWidth,
|
'width' => '100%',
|
||||||
'height' => $vbHeight,
|
'height' => '100%',
|
||||||
'href' => $baseImageUrl
|
'href' => $imageStr
|
||||||
);
|
);
|
||||||
$elBaseImg = Html::rawElement('image', $attrBase);
|
$elBaseImg = Html::rawElement('image', $attrBase);
|
||||||
}
|
}
|
||||||
@@ -122,7 +126,7 @@ class AnnotationHandler extends CodeContentHandler {
|
|||||||
$attrSvg = array(
|
$attrSvg = array(
|
||||||
'class' => 'annot-svg',
|
'class' => 'annot-svg',
|
||||||
'version' => '1.1',
|
'version' => '1.1',
|
||||||
'viewBox' => "0 0 {$vbWidth} {$vbHeight}",
|
'viewBox' => "0 0 {$baseWidth} {$baseHeight}",
|
||||||
'xml:space' => 'preserve',
|
'xml:space' => 'preserve',
|
||||||
'xmlns' => 'http://www.w3.org/2000/svg',
|
'xmlns' => 'http://www.w3.org/2000/svg',
|
||||||
'width' => $baseWidth,
|
'width' => $baseWidth,
|
||||||
@@ -131,12 +135,42 @@ class AnnotationHandler extends CodeContentHandler {
|
|||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (isset($metadata['view'])) {
|
||||||
|
$viewLabels = self::getCompassLabels($metadata['view']['direction'], $metadata['view']['rostral']);
|
||||||
|
$attrCompass = array(
|
||||||
|
'id' => "compass{$svgID}",
|
||||||
|
'viewBox' => '0 0 100 100',
|
||||||
|
'preserveAspectRatio' => 'xMinYMin meet',
|
||||||
|
'refX' => 'left',
|
||||||
|
'refY' => 'top',
|
||||||
|
'style' => "font-family:'TeX Gyre DejaVu Math';font-size:11.686px;letter-spacing:0px;line-height:125%;text-align:center;text-anchor:middle;word-spacing:0px;"
|
||||||
|
);
|
||||||
|
$compass = array(
|
||||||
|
Html::openElement('symbol',$attrCompass)
|
||||||
|
);
|
||||||
|
$attrCompBack = array(
|
||||||
|
'cx' => '50',
|
||||||
|
'cy' => '50',
|
||||||
|
'r' => '50',
|
||||||
|
'style' => 'fill-opacity:.35;fill:#ffffff;'
|
||||||
|
);
|
||||||
|
array_push($compass,Html::rawElement('circle',$attrCompBack));
|
||||||
|
$attrCompBkArrow = array(
|
||||||
|
'd' => 'M 50,81.3 41.4,58.6 18.7,50 41.4,41.4 50,18.7 58.6,41.4 81.3,50 58.6,58.6 Z',
|
||||||
|
'style' => 'fill:#ffffff;stroke-width:1.5025'
|
||||||
|
);
|
||||||
|
array_push($compass, Html::rawElement('path',$attrCompBkArrow));
|
||||||
|
|
||||||
|
array_push($compass,Html::closeElement('symbol'));
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($metadata['annotation'])) {
|
if (isset($metadata['annotation'])) {
|
||||||
$markers = [];
|
$annotations = [];
|
||||||
$maskCircles = [];
|
$maskCircles = [];
|
||||||
$leadLines = [];
|
$leadLines = [];
|
||||||
foreach($metadata['annotation'] as $label => $annot) {
|
foreach($metadata['annotation'] as $label => $annot) {
|
||||||
if (isset($annot['position'])) {
|
if (isset($annot['position'])) {
|
||||||
|
$marker = array(Html::openElement('g',array('transform' => "scale( {$fixScale} {$fixScale})")));
|
||||||
$attrMask = array(
|
$attrMask = array(
|
||||||
'cx' => $annot['position']['0'],
|
'cx' => $annot['position']['0'],
|
||||||
'cy' => $annot['position']['1'],
|
'cy' => $annot['position']['1'],
|
||||||
@@ -154,14 +188,14 @@ class AnnotationHandler extends CodeContentHandler {
|
|||||||
'fill' => (isset($annot['light']) && $annot['light']) ? 'white' : 'black'
|
'fill' => (isset($annot['light']) && $annot['light']) ? 'white' : 'black'
|
||||||
);
|
);
|
||||||
$markCirc = Html::rawElement('circle',$attrMarkerCirc);
|
$markCirc = Html::rawElement('circle',$attrMarkerCirc);
|
||||||
array_push($markers,$markCirc);
|
array_push($marker,$markCirc);
|
||||||
$attrMarkerText = array(
|
$attrMarkerText = array(
|
||||||
'x' => $annot['position']['0'],
|
'x' => $annot['position']['0'],
|
||||||
'y' => $annot['position']['1'],
|
'y' => $annot['position']['1'],
|
||||||
'style' => "fill: {$markColor}; font-size: 5px; stroke-linejoin: bevel; stroke-width: .6968; text-align: center; text-anchor: middle; transform: translateY(1.5px);"
|
'style' => "fill: {$markColor}; font-size: 5px; stroke-linejoin: bevel; stroke-width: .6968; text-align: center; text-anchor: middle; transform: translateY(1.5px);"
|
||||||
);
|
);
|
||||||
$markText = Html::rawElement('text',$attrMarkerText, isset($annot['label']) ? $annot['label'] : $label );
|
$markText = Html::rawElement('text',$attrMarkerText, isset($annot['label']) ? $annot['label'] : $label );
|
||||||
array_push($markers,$markText);
|
array_push($marker,$markText);
|
||||||
|
|
||||||
if(isset($annot['leader'])) {
|
if(isset($annot['leader'])) {
|
||||||
foreach($annot['leader'] as $line) {
|
foreach($annot['leader'] as $line) {
|
||||||
@@ -171,9 +205,11 @@ class AnnotationHandler extends CodeContentHandler {
|
|||||||
'style' => "fill-opacity:.35; fill: {$markColor}; stroke-linejoin:bevel; stroke-width:.4; stroke: {$markColor};"
|
'style' => "fill-opacity:.35; fill: {$markColor}; stroke-linejoin:bevel; stroke-width:.4; stroke: {$markColor};"
|
||||||
);
|
);
|
||||||
$lineText = Html::rawElement('path', $lineAttr);
|
$lineText = Html::rawElement('path', $lineAttr);
|
||||||
array_push($leadLines, $lineText);
|
array_push($marker, $lineText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
array_push($marker,Html::closeElement('g'));
|
||||||
|
array_push($annotations, implode($marker));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$attrMaskRect = array(
|
$attrMaskRect = array(
|
||||||
@@ -186,7 +222,7 @@ class AnnotationHandler extends CodeContentHandler {
|
|||||||
$svgDefs = Html::rawElement('defs',array(),$markMask);
|
$svgDefs = Html::rawElement('defs',array(),$markMask);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Html::rawElement('svg', $attrSvg, $svgDefs . $elBaseImg . implode($markers) . implode($leadLines) );
|
return Html::rawElement('svg', $attrSvg, $svgDefs. implode($compass) . $elBaseImg . implode($annotations) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function validateSave( Content $content, ValidationParams $validationParams ) {
|
public function validateSave( Content $content, ValidationParams $validationParams ) {
|
||||||
@@ -233,6 +269,32 @@ class AnnotationHandler extends CodeContentHandler {
|
|||||||
return $status;
|
return $status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the correct sequence of view compass labels based on the defined view
|
||||||
|
*
|
||||||
|
* @param string $direction the defined view direction
|
||||||
|
* @param bool true if 'rostral' should be used in place of 'cranial'
|
||||||
|
* @return string[] sequence of view labels
|
||||||
|
*/
|
||||||
|
private function getCompassLabels($direction = 'L', $rostral = false) {
|
||||||
|
self::console_log(print_r($direction,true), true);
|
||||||
|
if ($rostral && $direction == 'Cr') {
|
||||||
|
$direction = 'Ro';
|
||||||
|
}
|
||||||
|
$views = array(
|
||||||
|
'L' => array('L','D','Cd','V','Cr'),
|
||||||
|
'Lm' => array('L','D','Cd','V','Cr'),
|
||||||
|
'R' => array('R','D','Cr','V','Cd'),
|
||||||
|
'Rm' => array('R','D','Cr','V','Cd'),
|
||||||
|
'D' => array('D','Cr','R','Cd','L'),
|
||||||
|
'V' => array('V','Cr','L','Cd','R'),
|
||||||
|
'Cr' => array('Cr','D','L','V','R'),
|
||||||
|
'Ro' => array('Ro','D','L','V','R'),
|
||||||
|
'Cd' => array('Cd','D','R','V','L')
|
||||||
|
);
|
||||||
|
|
||||||
|
return $views[$direction];
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Small helper function to display information on the browser console
|
* Small helper function to display information on the browser console
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user