Santhosh has uploaded a new change for review.
https://gerrit.wikimedia.org/r/56375
Change subject: Move getIcon method to TranslateUtils
......................................................................
Move getIcon method to TranslateUtils
It need to be reused in multiple places now
Change-Id: I24fb73e31ab9433bb6046014e5e6937910a8f8e4
---
M TranslateUtils.php
M api/ApiQueryMessageGroups.php
2 files changed, 33 insertions(+), 30 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Translate
refs/changes/75/56375/1
diff --git a/TranslateUtils.php b/TranslateUtils.php
index f655dc3..edef392 100644
--- a/TranslateUtils.php
+++ b/TranslateUtils.php
@@ -393,4 +393,36 @@
static $i = 0;
return "\x7fUNIQ" . dechex( mt_rand( 0, 0x7fffffff ) ) .
dechex( mt_rand( 0, 0x7fffffff ) ) . '-' . $i++;
}
+
+ /**
+ * For the give message group get the icons in vector and raster formats
+ * @return array
+ */
+ public static function getIcon( MessageGroup $g, $size ) {
+ global $wgServer;
+ $icon = $g->getIcon();
+ if ( substr( $icon, 0, 7 ) !== 'wiki://' ) {
+ return null;
+ }
+
+ $formats = array();
+
+ $filename = substr( $icon, 7 );
+ $file = wfFindFile( $filename );
+ if ( !$file ) {
+ return null;
+ }
+
+ if ( $file->isVectorized() ) {
+ $formats['vector'] = $file->getUrl();
+ }
+
+ $formats['raster'] = $wgServer . $file->createThumb( $size,
$size );
+
+ foreach ( $formats as $key => &$url ) {
+ $url = wfExpandUrl( $url, PROTO_RELATIVE );
+ }
+
+ return $formats;
+ }
}
diff --git a/api/ApiQueryMessageGroups.php b/api/ApiQueryMessageGroups.php
index a2c5532..bfc99eb 100644
--- a/api/ApiQueryMessageGroups.php
+++ b/api/ApiQueryMessageGroups.php
@@ -129,7 +129,7 @@
}
if ( isset( $props['icon'] ) ) {
- $formats = $this->getIcon( $g, $params['iconsize'] );
+ $formats = TranslateUtils::getIcon( $g,
$params['iconsize'] );
if ( $formats ) {
$a['icon'] = $formats;
}
@@ -172,35 +172,6 @@
}
return $a;
- }
-
- protected function getIcon( MessageGroup $g, $size ) {
- global $wgServer;
- $icon = $g->getIcon();
- if ( substr( $icon, 0, 7 ) !== 'wiki://' ) {
- return null;
- }
-
- $formats = array();
-
- $filename = substr( $icon, 7 );
- $file = wfFindFile( $filename );
- if ( !$file ) {
- $this->setWarning( "Unknown file $icon" );
- return null;
- }
-
- if ( $file->isVectorized() ) {
- $formats['vector'] = $file->getUrl();
- }
-
- $formats['raster'] = $wgServer . $file->createThumb( $size,
$size );
-
- foreach ( $formats as $key => &$url ) {
- $url = wfExpandUrl( $url, PROTO_RELATIVE );
- }
-
- return $formats;
}
/**
--
To view, visit https://gerrit.wikimedia.org/r/56375
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I24fb73e31ab9433bb6046014e5e6937910a8f8e4
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Translate
Gerrit-Branch: master
Gerrit-Owner: Santhosh <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits