[MediaWiki-commits] [Gerrit] mediawiki...CollaborationKit[master]: Refactored CollaborationKitImage to use parser

2017-02-17 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/338517 )

Change subject: Refactored CollaborationKitImage to use parser
..


Refactored CollaborationKitImage to use parser

This helps with HiDPI support by recycling what the parser is already doing.

Bug: T158146
Change-Id: Ie6a12381b574e0d384182f61757dbe0a9b434b87
---
M includes/content/CollaborationKitImage.php
1 file changed, 33 insertions(+), 43 deletions(-)

Approvals:
  Harej: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/content/CollaborationKitImage.php 
b/includes/content/CollaborationKitImage.php
index c7afe56..ac2fb7f 100644
--- a/includes/content/CollaborationKitImage.php
+++ b/includes/content/CollaborationKitImage.php
@@ -30,25 +30,16 @@
 */
public static function makeImage( $image, $width, $options = [] ) {
 
-   // Default options
-   if ( !isset( $options['classes'] ) ) {
-   $options['classes'] = [];
-   }
-   if ( !isset( $options['link'] ) ) {
-   $options['link'] = true;
-   }
-   if ( !isset( $options['colour'] ) ) {
-   $options['colour'] = '';
-   }
-   if ( !isset( $options['css'] ) ) {
-   $options['css'] = '';
-   }
-   if ( !isset( $options['renderAsWikitext'] ) ) {
-   $options['renderAsWikitext'] = false;
-   }
-   if ( !isset( $options['label'] ) ) {
-   $options['label'] = '';
-   }
+   $cannedIcons = self::getCannedIcons();
+
+   // Setting up options
+   $classes = isset( $options['classes'] ) ? $options['classes'] : 
[];
+   $link = isset( $options['link'] ) ? $options['link'] : true;
+   $colour = isset( $options['colour'] ) ? $options['colour'] : '';
+   $css = isset( $options['css'] ) ? $options['css'] : '';
+   $renderAsWikitext = isset( $options['renderAsWikitext'] ) ? 
$options['renderAsWikitext'] : false;
+   $label = isset( $options['label'] ) ? $options['label'] : '';
+
if ( !isset( $options['fallback'] ) ) {
if ( isset( $options['label'] ) ) {
$options['fallback'] = $options['label'];
@@ -56,8 +47,6 @@
$options['fallback'] = 'none';
}
}
-
-   $cannedIcons = self::getCannedIcons();
 
// Use fallback icon or random icon if stated image doesn't 
exist
if ( $image === null || $image == '' || ( !wfFindFile( $image ) 
&& !in_array( $image, $cannedIcons ) ) ) {
@@ -72,15 +61,15 @@
 
// Are we loading an image file or constructing a div based on 
an icon class?
if ( wfFindFile( $image ) ) {
-   $imageCode = self::makeImageFromFile( $image, 
$options['classes'], $width, $options[ 'link' ],
-   $options['renderAsWikitext'], $options['label'] 
);
+   $imageCode = self::makeImageFromFile( $image, $classes, 
$width, $link,
+   $renderAsWikitext, $label );
} elseif ( in_array( $image, $cannedIcons ) ) {
-   $imageCode = self::makeImageFromIcon( $image, 
$options['classes'], $width, $options[ 'colour' ],
-   $options['link'], $options['renderAsWikitext'], 
$options['label'] );
+   $imageCode = self::makeImageFromIcon( $image, $classes, 
$width, $colour,
+   $link, $renderAsWikitext, $label );
}
 
// Finishing up
-   $wrapperAttributes = [ 'class' => $options['classes'], 'style' 
=> $options['css'] ];
+   $wrapperAttributes = [ 'class' => $classes, 'style' => $css ];
$imageBlock = Html::rawElement( 'div', $wrapperAttributes, 
$imageCode );
return $imageBlock;
}
@@ -93,24 +82,26 @@
// This assumes that colours cannot be assigned to images.
// This is currently true, but who knows what the future might 
hold!
 
+   global $wgParser;
+
$imageObj = wfFindFile( $image );
-   $imageFullName = $imageObj->getTitle()->getFullText();
+   $imageTitle = $imageObj->getTitle();
+   $imageFullName = $imageTitle->getFullText();
+
+   $wikitext = "[[{$imageFullName}|{$width}px";
+
+   if ( $link === false || $label != '' ) {
+   $wikitext .= '|link=]]';
+   } elseif ( is_string( $link ) ) {
+   $wikitext .= "|link={$link}]]";
+   

[MediaWiki-commits] [Gerrit] mediawiki...CollaborationKit[master]: Refactored CollaborationKitImage to use parser

2017-02-17 Thread Harej (Code Review)
Harej has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/338517 )

Change subject: Refactored CollaborationKitImage to use parser
..

Refactored CollaborationKitImage to use parser

This helps with HiDPI support by recycling what the parser is already doing.

Bug: T158146
Change-Id: Ie6a12381b574e0d384182f61757dbe0a9b434b87
---
M includes/content/CollaborationKitImage.php
1 file changed, 33 insertions(+), 43 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CollaborationKit 
refs/changes/17/338517/1

diff --git a/includes/content/CollaborationKitImage.php 
b/includes/content/CollaborationKitImage.php
index c7afe56..ac2fb7f 100644
--- a/includes/content/CollaborationKitImage.php
+++ b/includes/content/CollaborationKitImage.php
@@ -30,25 +30,16 @@
 */
public static function makeImage( $image, $width, $options = [] ) {
 
-   // Default options
-   if ( !isset( $options['classes'] ) ) {
-   $options['classes'] = [];
-   }
-   if ( !isset( $options['link'] ) ) {
-   $options['link'] = true;
-   }
-   if ( !isset( $options['colour'] ) ) {
-   $options['colour'] = '';
-   }
-   if ( !isset( $options['css'] ) ) {
-   $options['css'] = '';
-   }
-   if ( !isset( $options['renderAsWikitext'] ) ) {
-   $options['renderAsWikitext'] = false;
-   }
-   if ( !isset( $options['label'] ) ) {
-   $options['label'] = '';
-   }
+   $cannedIcons = self::getCannedIcons();
+
+   // Setting up options
+   $classes = isset( $options['classes'] ) ? $options['classes'] : 
[];
+   $link = isset( $options['link'] ) ? $options['link'] : true;
+   $colour = isset( $options['colour'] ) ? $options['colour'] : '';
+   $css = isset( $options['css'] ) ? $options['css'] : '';
+   $renderAsWikitext = isset( $options['renderAsWikitext'] ) ? 
$options['renderAsWikitext'] : false;
+   $label = isset( $options['label'] ) ? $options['label'] : '';
+
if ( !isset( $options['fallback'] ) ) {
if ( isset( $options['label'] ) ) {
$options['fallback'] = $options['label'];
@@ -56,8 +47,6 @@
$options['fallback'] = 'none';
}
}
-
-   $cannedIcons = self::getCannedIcons();
 
// Use fallback icon or random icon if stated image doesn't 
exist
if ( $image === null || $image == '' || ( !wfFindFile( $image ) 
&& !in_array( $image, $cannedIcons ) ) ) {
@@ -72,15 +61,15 @@
 
// Are we loading an image file or constructing a div based on 
an icon class?
if ( wfFindFile( $image ) ) {
-   $imageCode = self::makeImageFromFile( $image, 
$options['classes'], $width, $options[ 'link' ],
-   $options['renderAsWikitext'], $options['label'] 
);
+   $imageCode = self::makeImageFromFile( $image, $classes, 
$width, $link,
+   $renderAsWikitext, $label );
} elseif ( in_array( $image, $cannedIcons ) ) {
-   $imageCode = self::makeImageFromIcon( $image, 
$options['classes'], $width, $options[ 'colour' ],
-   $options['link'], $options['renderAsWikitext'], 
$options['label'] );
+   $imageCode = self::makeImageFromIcon( $image, $classes, 
$width, $colour,
+   $link, $renderAsWikitext, $label );
}
 
// Finishing up
-   $wrapperAttributes = [ 'class' => $options['classes'], 'style' 
=> $options['css'] ];
+   $wrapperAttributes = [ 'class' => $classes, 'style' => $css ];
$imageBlock = Html::rawElement( 'div', $wrapperAttributes, 
$imageCode );
return $imageBlock;
}
@@ -93,24 +82,26 @@
// This assumes that colours cannot be assigned to images.
// This is currently true, but who knows what the future might 
hold!
 
+   global $wgParser;
+
$imageObj = wfFindFile( $image );
-   $imageFullName = $imageObj->getTitle()->getFullText();
+   $imageTitle = $imageObj->getTitle();
+   $imageFullName = $imageTitle->getFullText();
+
+   $wikitext = "[[{$imageFullName}|{$width}px";
+
+   if ( $link === false || $label != '' ) {
+   $wikitext .= '|link=]]';
+   } elseif ( is_string( $link ) ) {
+   $wikitext .= "|link={$lin