r66792 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r66791‎ | r66792 | r66793 >
Date:13:54, 23 May 2010
Author:siebrand
Status:deferred
Tags:
Comment:
Update coding style, comments and remove trailing whitespace
Modified paths:
  • /trunk/extensions/Translate/SpecialMagic.php (modified) (history)
  • /trunk/extensions/Translate/groups/ComplexMessages.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/groups/ComplexMessages.php
@@ -36,7 +36,6 @@
3737 #
3838 # Data retrieval
3939 #
40 -
4140 protected $init = false;
4241 public function getGroups() {
4342 if ( !$this->init ) {
@@ -48,18 +47,24 @@
4948 }
5049
5150 return $this->data;
52 -
 51+
5352 }
5453
5554 public function cleanData( $defs, $current ) {
5655 foreach ( $current as $item => $values ) {
57 - if ( !$this->elementsInArray ) break;
 56+ if ( !$this->elementsInArray ) {
 57+ break;
 58+ }
 59+
5860 if ( !isset( $defs[$item] ) ) {
5961 unset( $current[$item] );
6062 continue;
6163 }
 64+
6265 foreach ( $values as $index => $value )
63 - if ( in_array( $value, $defs[$item], true ) ) unset( $current[$item][$index] );
 66+ if ( in_array( $value, $defs[$item], true ) ) {
 67+ unset( $current[$item][$index] );
 68+ }
6469 }
6570 return $current;
6671 }
@@ -74,7 +79,6 @@
7580 return $current;
7681 }
7782
78 -
7983 public function getData( &$group, $savedData ) {
8084 $defs = $this->readVariable( $group, 'en' );
8185 $code = $this->language;
@@ -87,11 +91,16 @@
8892 $chain = $current;
8993 while ( $this->chainable && $code = Language::getFallbackFor( $code ) ) {
9094 $fbdata = $this->readVariable( $group, $code );
91 - if ( $this->firstMagic ) $fbdata = $this->cleanData( $defs, $fbdata );
 95+ if ( $this->firstMagic ) {
 96+ $fbdata = $this->cleanData( $defs, $fbdata );
 97+ }
 98+
9299 $chain = array_merge_recursive( $chain, $fbdata );
93100 }
94101
95 - if ( $this->firstMagic ) $chain = $this->mergeMagic( $defs, $chain );
 102+ if ( $this->firstMagic ) {
 103+ $chain = $this->mergeMagic( $defs, $chain );
 104+ }
96105
97106 return $group['data'] = array( $defs, $chain, $current );
98107 }
@@ -125,11 +134,18 @@
126135 $lines = array_map( 'trim', explode( "\n", $data ) );
127136 $array = array();
128137 foreach ( $lines as $line ) {
129 - if ( $line === '' || $line[0] === '#' || $line[0] === '<' ) continue;
130 - if ( strpos( $line, '=' ) === false ) continue;
 138+ if ( $line === '' || $line[0] === '#' || $line[0] === '<' ) {
 139+ continue;
 140+ }
131141
 142+ if ( strpos( $line, '=' ) === false ) {
 143+ continue;
 144+ }
 145+
132146 list( $name, $values ) = array_map( 'trim', explode( '=', $line, 2 ) );
133 - if ( $name === '' || $values === '' ) continue;
 147+ if ( $name === '' || $values === '' ) {
 148+ continue;
 149+ }
134150
135151 $data = array_map( 'trim', explode( ',', $values ) );
136152 $array[$name] = $data;
@@ -151,12 +167,19 @@
152168 $array = $this->getGroups();
153169 $subarray = @$array[$group]['data'][$type][$key];
154170 if ( $this->elementsInArray ) {
155 - if ( !$subarray || !count( $subarray ) ) return array();
 171+ if ( !$subarray || !count( $subarray ) ) {
 172+ return array();
 173+ }
156174 } else {
157 - if ( !$subarray ) return array();
 175+ if ( !$subarray ) {
 176+ return array();
 177+ }
158178 }
159179
160 - if ( !is_array( $subarray ) ) $subarray = array( $subarray );
 180+ if ( !is_array( $subarray ) ) {
 181+ $subarray = array( $subarray );
 182+ }
 183+
161184 return $subarray;
162185 }
163186
@@ -169,7 +192,9 @@
170193 }
171194
172195 $ { $group['var'] } = array(); # Initialize
173 - if ( file_exists( $file ) ) require( $file ); # Include
 196+ if ( file_exists( $file ) ) {
 197+ require( $file ); # Include
 198+ }
174199
175200 if ( $group['code'] ) {
176201 $data = (array) @$ { $group['var'] } [$code];
@@ -220,17 +245,23 @@
221246
222247 foreach ( array_keys( $this->data ) as $group ) {
223248 $s .= $this->header( $this->data[$group]['label'] );
224 -
 249+
225250 foreach ( $this->getIterator( $group ) as $key ) {
226251 $rowContents = '';
227252
228253 $value = $this->val( $group, self::LANG_MASTER, $key );
229 - if ( $this->firstMagic ) array_shift( $value );
 254+ if ( $this->firstMagic ) {
 255+ array_shift( $value );
 256+ }
 257+
230258 $value = array_map( 'htmlspecialchars', $value );
231259 $rowContents .= '<td>' . $this->formatElement( $value ) . '</td>';
232260
233261 $value = $this->val( $group, self::LANG_CHAIN, $key );
234 - if ( $this->firstMagic ) array_shift( $value );
 262+ if ( $this->firstMagic ) {
 263+ array_shift( $value );
 264+ }
 265+
235266 $value = array_map( 'htmlspecialchars', $value );
236267 $value = $this->highlight( $key, $value );
237268 $rowContents .= '<td>' . $this->formatElement( $value ) . '</td>';
@@ -263,7 +294,10 @@
264295 }
265296
266297 public function formatElement( $element ) {
267 - if ( !count( $element ) ) return '';
 298+ if ( !count( $element ) ) {
 299+ return '';
 300+ }
 301+
268302 if ( is_array( $element ) ) {
269303 $element = array_map( 'trim', $element );
270304 $element = implode( ', ', $element );
@@ -297,8 +331,9 @@
298332 foreach ( $this->getIterator( $group ) as $key ) {
299333 $data = $request->getText( $this->getKeyForEdit( $key ) );
300334 $data = implode( ', ', array_map( 'trim', explode( ',', $data ) ) );
301 - if ( $data !== '' )
 335+ if ( $data !== '' ) {
302336 $text .= "$key = $data\n" ;
 337+ }
303338 }
304339 }
305340 return $text;
@@ -319,7 +354,6 @@
320355
321356 /* Reset outdated array */
322357 $this->init = false;
323 -
324358 }
325359
326360 #
@@ -332,7 +366,10 @@
333367 public function validate( &$errors = array(), $filter = false ) {
334368 $used = array();
335369 foreach ( array_keys( $this->data ) as $group ) {
336 - if ( $filter !== false && !in_array( $group, (array) $filter, true ) ) continue;
 370+ if ( $filter !== false && !in_array( $group, (array) $filter, true ) ) {
 371+ continue;
 372+ }
 373+
337374 $this->validateEach( $errors, $group, $used );
338375 }
339376 }
@@ -365,7 +402,10 @@
366403 foreach ( $errors as $_ ) $text .= "#!!# $_\n";
367404
368405 foreach ( $groups = $this->getGroups() as $group => $data ) {
369 - if ( $filter !== false && !in_array( $group, (array) $filter, true ) ) continue;
 406+ if ( $filter !== false && !in_array( $group, (array) $filter, true ) ) {
 407+ continue;
 408+ }
 409+
370410 $text .= $this->exportEach( $group, $data );
371411 }
372412
@@ -394,11 +434,15 @@
395435
396436 $from = self::LANG_CURRENT;
397437 // Abuse of the firstMagic property, should use something proper
398 - if ( $this->firstMagic ) $from = self::LANG_CHAIN;
 438+ if ( $this->firstMagic ) {
 439+ $from = self::LANG_CHAIN;
 440+ }
399441
400442 // Check for translations
401443 $val = $this->val( $group, self::LANG_CURRENT, $key );
402 - if ( !$val || !count( $val ) ) continue;
 444+ if ( !$val || !count( $val ) ) {
 445+ continue;
 446+ }
403447
404448 // Then get the data we really want
405449 $val = $this->val( $group, $from, $key );
@@ -406,11 +450,19 @@
407451 // Remove duplicated entries, causes problems with magic words
408452 // Just to be sure, it should not be possible to save invalid data anymore
409453 $val = array_unique( $val /*FIXME:SORT_REGULAR*/ );
 454+
410455 // So do empty elements...
411 - foreach ( $val as $k => $v ) if ( $v === '' ) unset( $val[$k] );
412 - // Another check
413 - if ( !count( $val ) ) continue;
 456+ foreach ( $val as $k => $v ) {
 457+ if ( $v === '' ) {
 458+ unset( $val[$k] );
 459+ }
 460+ }
414461
 462+ // Another check
 463+ if ( !count( $val ) ) {
 464+ continue;
 465+ }
 466+
415467 $normalized = array_map( array( $this, 'normalize' ), $val );
416468 if ( $this->elementsInArray ) {
417469 $temp .= "=> array( " . implode( ', ', $normalized ) . " ),";
@@ -469,9 +521,14 @@
470522 global $wgTranslateExtensionDirectory;
471523 $groups = MessageGroups::singleton()->getGroups();
472524 foreach ( $groups as $g ) {
473 - if ( !$g instanceof ExtensionMessageGroup ) continue;
 525+ if ( !$g instanceof ExtensionMessageGroup ) {
 526+ continue;
 527+ }
 528+
474529 $file = $g->getAliasFile();
475 - if ( $file === null ) continue;
 530+ if ( $file === null ) {
 531+ continue;
 532+ }
476533
477534 $file = "$wgTranslateExtensionDirectory/$file";
478535 if ( file_exists( $file ) ) {
@@ -487,7 +544,10 @@
488545
489546 public function highlight( $key, $values ) {
490547 if ( count( $values ) ) {
491 - if ( !isset( $values[0] ) ) throw new MWException( "Something missing from values: " . print_r( $values, true ) );
 548+ if ( !isset( $values[0] ) ) {
 549+ throw new MWException( "Something missing from values: " . print_r( $values, true ) );
 550+ }
 551+
492552 $values[0] = "<b>$values[0]</b>";
493553 }
494554 return $values;
@@ -537,9 +597,14 @@
538598 global $wgTranslateExtensionDirectory;
539599 $groups = MessageGroups::singleton()->getGroups();
540600 foreach ( $groups as $g ) {
541 - if ( !$g instanceof ExtensionMessageGroup ) continue;
 601+ if ( !$g instanceof ExtensionMessageGroup ) {
 602+ continue;
 603+ }
 604+
542605 $file = $g->getMagicFile();
543 - if ( $file === null ) continue;
 606+ if ( $file === null ) {
 607+ continue;
 608+ }
544609
545610 $file = "$wgTranslateExtensionDirectory/$file";
546611 if ( file_exists( $file ) ) {
@@ -554,10 +619,12 @@
555620 }
556621
557622 public function highlight( $key, $values ) {
558 - if ( count( $values ) && $key === 'redirect' ) $values[0] = "<b>$values[0]</b>";
 623+ if ( count( $values ) && $key === 'redirect' ) {
 624+ $values[0] = "<b>$values[0]</b>";
 625+ }
 626+
559627 return $values;
560628 }
561 -
562629 }
563630
564631 class NamespaceCM extends ComplexMessages {
@@ -576,8 +643,8 @@
577644 }
578645
579646 protected $constants = array(
580 - - 2 => 'NS_MEDIA',
581 - - 1 => 'NS_SPECIAL',
 647+ -2 => 'NS_MEDIA',
 648+ -1 => 'NS_SPECIAL',
582649 0 => 'NS_MAIN',
583650 1 => 'NS_TALK',
584651 2 => 'NS_USER',
@@ -607,5 +674,4 @@
608675 }
609676 }
610677 }
611 -
612678 }
Index: trunk/extensions/Translate/SpecialMagic.php
@@ -26,7 +26,7 @@
2727 private $nondefaults = array();
2828
2929 public function __construct() {
30 - SpecialPage::SpecialPage( 'Magic' );
 30+ parent::__construct( 'Magic' );
3131 }
3232
3333 /**
@@ -37,7 +37,7 @@
3838 }
3939
4040 /**
41 - * Returns xhtml output of the form
 41+ * Returns HTML5 output of the form
4242 * GLOBALS: $wgLang
4343 */
4444 protected function getForm() {
@@ -62,14 +62,13 @@
6363 Xml::submitButton( wfMsg( 'translate-magic-cm-export' ), array( 'name' => 'export' ) ) .
6464 '</td></tr></table>' .
6565 Xml::hidden( 'title', $this->getTitle()->getPrefixedText() )
66 -
6766 );
6867 return $form;
6968 }
7069
7170 /**
7271 * Helper function get module selector.
73 - * Returns the xhtml-compatible select-element.
 72+ * Returns the HTML5-compatible select-element.
7473 * @param $selectedId which value should be selected by default
7574 * @return string
7675 */
@@ -85,10 +84,10 @@
8685 global $wgUser, $wgRequest;
8786
8887 $defaults = array(
89 - /* str */ 'module' => '',
90 - /* str */ 'language' => $wgUser->getOption( 'language' ),
91 - /* bool */ 'export' => false,
92 - /* bool */ 'savetodb' => false,
 88+ /* str */ 'module' => '',
 89+ /* str */ 'language' => $wgUser->getOption( 'language' ),
 90+ /* bool */ 'export' => false,
 91+ /* bool */ 'savetodb' => false,
9392 );
9493
9594 // Place where all non default variables will end
@@ -118,7 +117,6 @@
119118 */
120119 public function execute( $parameters ) {
121120 global $wgUser, $wgOut, $wgRequest, $wgLang;
122 - wfLoadExtensionMessages( 'Translate' );
123121
124122 $this->setup( $parameters );
125123 $this->setHeaders();
@@ -164,7 +162,6 @@
165163 }
166164 }
167165
168 -
169166 if ( $this->options['export'] ) {
170167 $output = $o->export();
171168 if ( $output === '' ) {
@@ -181,8 +178,6 @@
182179 $o->validate( $errors );
183180 if ( $errors ) $this->outputErrors( $errors );
184181 $wgOut->addHTML( $o->output() );
185 -
186 -
187182 }
188183
189184 protected function outputErrors( $errors ) {
@@ -195,5 +190,4 @@
196191 }
197192 $wgOut->addHTML( '</ol>' );
198193 }
199 -
200194 }

Status & tagging log