r67092 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r67091‎ | r67092 | r67093 >
Date:17:55, 30 May 2010
Author:siebrand
Status:deferred
Tags:
Comment:
Removed trailing whitespace, updated indentation and code formatting.
Modified paths:
  • /trunk/extensions/Translate/TranslateUtils.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/TranslateUtils.php
@@ -26,6 +26,7 @@
2727 if ( !isset( $cache[$message] ) ) {
2828 $cache[$message] = $wgContLang->ucfirst( $message );
2929 }
 30+
3031 if ( $code ) {
3132 return $cache[$message] . '/' . $code;
3233 } else {
@@ -37,6 +38,7 @@
3839 $pos = strrpos( $text, '/' );
3940 $code = substr( $text, $pos + 1 );
4041 $key = substr( $text, 0, $pos );
 42+
4143 return array( $key, $code );
4244 }
4345
@@ -45,6 +47,7 @@
4648
4749 $title = self::title( $key, $language );
4850 $data = self::getContents( array( $title ), $namespace );
 51+
4952 return isset( $data[$title][0] ) ? $data[$title][0] : null;
5053 }
5154
@@ -115,6 +118,7 @@
116119 $rows[] = $row;
117120 }
118121 $dbr->freeResult( $res );
 122+
119123 return $rows;
120124 }
121125
@@ -126,10 +130,12 @@
127131
128132 public static function simpleSelector( $name, $items, $selected ) {
129133 $options = array();
 134+
130135 foreach ( $items as $item ) {
131136 $item = strval( $item );
132137 $options[] = Xml::option( $item, $item, $item == $selected );
133138 }
 139+
134140 return self::selector( $name, implode( "\n", $options ) );
135141 }
136142
@@ -156,11 +162,13 @@
157163 break;
158164 }
159165 $code = implode( '-', $parts );
 166+
160167 return isset( $languages[$code] ) ? $languages[$code] . $suffix : false;
161168 }
162169
163170 public static function languageSelector( $language, $selectedId ) {
164171 global $wgLang;
 172+
165173 if ( is_callable( array( 'LanguageNames', 'getNames' ) ) ) {
166174 $languages = LanguageNames::getNames( $language,
167175 LanguageNames::FALLBACK_NORMAL,
@@ -176,25 +184,33 @@
177185 foreach ( $languages as $code => $name ) {
178186 $selector->addOption( "$code - $name", $code );
179187 }
 188+
180189 return $selector->getHTML();
181190 }
182191
183192 static $mi = null;
184193
185194 public static function messageKeyToGroup( $namespace, $key ) {
186 - if ( self::$mi === null ) self::messageIndex();
 195+ if ( self::$mi === null ) {
 196+ self::messageIndex();
 197+ }
187198
188199 # Performance hotspot
189200 # $normkey = self::normaliseKey( $namespace, $key );
190201 $normkey = str_replace( " ", "_", strtolower( "$namespace:$key" ) );
191202
192203 $group = @self::$mi[$normkey];
193 - if ( is_array( $group ) ) $group = $group[0];
 204+ if ( is_array( $group ) ) {
 205+ $group = $group[0];
 206+ }
 207+
194208 return $group;
195209 }
196210
197211 public static function messageKeyToGroups( $namespace, $key ) {
198 - if ( self::$mi === null ) self::messageIndex();
 212+ if ( self::$mi === null ) {
 213+ self::messageIndex();
 214+ }
199215
200216 # Performance hotspot
201217 # $normkey = self::normaliseKey( $namespace, $key );
@@ -225,9 +241,8 @@
226242 }
227243
228244 public static function fieldset( $legend, $contents, $attributes = array() ) {
229 - return
230 - Xml::openElement( 'fieldset', $attributes ) .
231 - Xml::tags( 'legend', null, $legend ) . $contents .
 245+ return Xml::openElement( 'fieldset', $attributes ) .
 246+ Xml::tags( 'legend', null, $legend ) . $contents .
232247 Xml::closeElement( 'fieldset' );
233248 }
234249
@@ -251,10 +266,15 @@
252267
253268 public static function injectCSS() {
254269 static $done = false;
255 - if ( $done ) return;
 270+
 271+ if ( $done ) {
 272+ return;
 273+ }
 274+
256275 $done = true;
257276
258277 global $wgOut;
 278+
259279 $wgOut->addExtensionStyle( self::assetPath( 'Translate.css' ) );
260280 }
261281
@@ -265,6 +285,7 @@
266286 */
267287 public static function assetPath( $path ) {
268288 global $wgExtensionAssetsPath, $wgScriptPath, $wgVersion;
 289+
269290 if ( version_compare( $wgVersion, '1.16', '>=' ) ) {
270291 return "$wgExtensionAssetsPath/Translate/$path";
271292 } else {
@@ -274,13 +295,14 @@
275296
276297 public static function snippet( &$text, $length = 10 ) {
277298 global $wgLegalTitleChars, $wgContLang;
 299+
278300 $snippet = preg_replace( "/[^\p{L}]/u", ' ', $text );
279301 $snippet = preg_replace( "/ {2,}/u", ' ', $snippet );
280302 $snippet = $wgContLang->truncate( $snippet, $length, '' );
281303 $snippet = str_replace( ' ', '_', trim( $snippet ) );
 304+
282305 return $snippet;
283306 }
284 -
285307 }
286308
287309 class HTMLSelector {
@@ -289,9 +311,17 @@
290312 private $attributes = array();
291313
292314 public function __construct( $name = false, $id = false, $selected = false ) {
293 - if ( $name ) $this->setAttribute( 'name', $name );
294 - if ( $id ) $this->setAttribute( 'id', $id );
295 - if ( $selected ) $this->selected = $selected;
 315+ if ( $name ) {
 316+ $this->setAttribute( 'name', $name );
 317+ }
 318+
 319+ if ( $id ) {
 320+ $this->setAttribute( 'id', $id );
 321+ }
 322+
 323+ if ( $selected ) {
 324+ $this->selected = $selected;
 325+ }
296326 }
297327
298328 public function setSelected( $selected ) {

Status & tagging log