MaxSem has uploaded a new change for review. https://gerrit.wikimedia.org/r/316033
Change subject: WIP: frames ...................................................................... WIP: frames No captions yet Change-Id: I1d4cb7b1d2482c00ca9ad2162ca59923515abdd8 --- M includes/ParserTag.php M tests/parserTests.txt 2 files changed, 52 insertions(+), 9 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Graph refs/changes/33/316033/1 diff --git a/includes/ParserTag.php b/includes/ParserTag.php index a681a08..8259480 100644 --- a/includes/ParserTag.php +++ b/includes/ParserTag.php @@ -95,6 +95,13 @@ } } + private function getSize( $data ) { + $width = property_exists( $data, 'width' ) && is_int( $data->width ) ? $data->width : 0; + $height = + property_exists( $data, 'height' ) && is_int( $data->height ) ? $data->height : 0; + return [ $width, $height ]; + } + /** * @param string $mode * @param mixed $data @@ -105,9 +112,7 @@ $attribs = [ 'class' => 'mw-graph' ]; if ( is_object( $data ) ) { - $width = property_exists( $data, 'width' ) && is_int( $data->width ) ? $data->width : 0; - $height = - property_exists( $data, 'height' ) && is_int( $data->height ) ? $data->height : 0; + list( $width, $height ) = $this->getSize( $data ); if ( $width && $height ) { $attribs['style'] = "min-width:{$width}px;min-height:{$height}px"; } @@ -120,6 +125,17 @@ } return $attribs; + } + + private function wrapInThumb( $graph, $data, $args ) { + $attrs = []; + return Html::rawElement( 'div', + [ 'class' => 'thumb mw-graph-thumb', 'style' => 'width: min-content' ], + Html::rawElement( 'div', + [ 'class' => 'thumbinner mw-graph-thumbinner' ], + $graph + ) + ); } private function formatError( Message $msg ) { @@ -136,10 +152,10 @@ * @param string $jsonText * @param Title $title * @param int $revid - * @param array $args + * @param string[] $args * @return string */ - public function buildHtml( $jsonText, Title $title, $revid, $args = null ) { + public function buildHtml( $jsonText, Title $title, $revid, $args = [] ) { global $wgGraphImgServiceUrl, $wgServerName; $jsonText = trim( $jsonText ); @@ -150,6 +166,8 @@ if ( !$status->isOK() ) { return $this->formatStatus( $status ); } + + $framed = !isset( $args['frameless'] ); $isInteractive = isset( $args['mode'] ) && $args['mode'] === 'interactive'; $graphTitle = isset( $args['title'] ) ? $args['title'] : ''; @@ -228,6 +246,11 @@ } } - return Html::rawElement( 'div', $attribs, $html ); + $graph = Html::rawElement( 'div', $attribs, $html ); + if ( $framed ) { + $graph = $this->wrapInThumb( $graph, $data, $args ); + } + + return $graph; } } diff --git a/tests/parserTests.txt b/tests/parserTests.txt index 435302d..6de10a6 100644 --- a/tests/parserTests.txt +++ b/tests/parserTests.txt @@ -11,8 +11,8 @@ } </graph> !! result -<div class="mw-graph mw-graph-always" data-graph-id="cb66159a7f0070f4faaef2f353cb67c0d178d678"></div> -<div class="mw-graph mw-graph-always" style="min-width:100px;min-height:200px" data-graph-id="35d4ad35da17b39e7e4464fd7af741dadda01a91"></div> +<div class="thumb mw-graph-thumb" style="width: min-content"><div class="thumbinner mw-graph-thumbinner"><div class="mw-graph mw-graph-always" data-graph-id="cb66159a7f0070f4faaef2f353cb67c0d178d678"></div></div></div> +<div class="thumb mw-graph-thumb" style="width: min-content"><div class="thumbinner mw-graph-thumbinner"><div class="mw-graph mw-graph-always" style="min-width:100px;min-height:200px" data-graph-id="35d4ad35da17b39e7e4464fd7af741dadda01a91"></div></div></div> !! end @@ -33,5 +33,25 @@ <span class="error">Syntax error</span> <span class="error">The JSON provided is not a valid Vega JSON</span> </p> +!! end - !! end +!! test +<graph> - frameless +!! input +<graph frameless> +{ + "width": 320, + "height": 240 +} +</graph> +<graph frameless=yep> +{ + "width": 320, + "height": 240 +} +</graph> +!! result +<div class="mw-graph mw-graph-always" style="min-width:320px;min-height:240px" data-graph-id="bccfa79d9556be77aebf7d3e936b2fa24fc0b3b6"></div> +<div class="mw-graph mw-graph-always" style="min-width:320px;min-height:240px" data-graph-id="bccfa79d9556be77aebf7d3e936b2fa24fc0b3b6"></div> + +!! end -- To view, visit https://gerrit.wikimedia.org/r/316033 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I1d4cb7b1d2482c00ca9ad2162ca59923515abdd8 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Graph Gerrit-Branch: master Gerrit-Owner: MaxSem <maxsem.w...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits