Index: trunk/extensions/Translate/groups/ComplexMessages.php |
— | — | @@ -36,7 +36,6 @@ |
37 | 37 | # |
38 | 38 | # Data retrieval |
39 | 39 | # |
40 | | - |
41 | 40 | protected $init = false; |
42 | 41 | public function getGroups() { |
43 | 42 | if ( !$this->init ) { |
— | — | @@ -48,18 +47,24 @@ |
49 | 48 | } |
50 | 49 | |
51 | 50 | return $this->data; |
52 | | - |
| 51 | + |
53 | 52 | } |
54 | 53 | |
55 | 54 | public function cleanData( $defs, $current ) { |
56 | 55 | foreach ( $current as $item => $values ) { |
57 | | - if ( !$this->elementsInArray ) break; |
| 56 | + if ( !$this->elementsInArray ) { |
| 57 | + break; |
| 58 | + } |
| 59 | + |
58 | 60 | if ( !isset( $defs[$item] ) ) { |
59 | 61 | unset( $current[$item] ); |
60 | 62 | continue; |
61 | 63 | } |
| 64 | + |
62 | 65 | 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 | + } |
64 | 69 | } |
65 | 70 | return $current; |
66 | 71 | } |
— | — | @@ -74,7 +79,6 @@ |
75 | 80 | return $current; |
76 | 81 | } |
77 | 82 | |
78 | | - |
79 | 83 | public function getData( &$group, $savedData ) { |
80 | 84 | $defs = $this->readVariable( $group, 'en' ); |
81 | 85 | $code = $this->language; |
— | — | @@ -87,11 +91,16 @@ |
88 | 92 | $chain = $current; |
89 | 93 | while ( $this->chainable && $code = Language::getFallbackFor( $code ) ) { |
90 | 94 | $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 | + |
92 | 99 | $chain = array_merge_recursive( $chain, $fbdata ); |
93 | 100 | } |
94 | 101 | |
95 | | - if ( $this->firstMagic ) $chain = $this->mergeMagic( $defs, $chain ); |
| 102 | + if ( $this->firstMagic ) { |
| 103 | + $chain = $this->mergeMagic( $defs, $chain ); |
| 104 | + } |
96 | 105 | |
97 | 106 | return $group['data'] = array( $defs, $chain, $current ); |
98 | 107 | } |
— | — | @@ -125,11 +134,18 @@ |
126 | 135 | $lines = array_map( 'trim', explode( "\n", $data ) ); |
127 | 136 | $array = array(); |
128 | 137 | 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 | + } |
131 | 141 | |
| 142 | + if ( strpos( $line, '=' ) === false ) { |
| 143 | + continue; |
| 144 | + } |
| 145 | + |
132 | 146 | list( $name, $values ) = array_map( 'trim', explode( '=', $line, 2 ) ); |
133 | | - if ( $name === '' || $values === '' ) continue; |
| 147 | + if ( $name === '' || $values === '' ) { |
| 148 | + continue; |
| 149 | + } |
134 | 150 | |
135 | 151 | $data = array_map( 'trim', explode( ',', $values ) ); |
136 | 152 | $array[$name] = $data; |
— | — | @@ -151,12 +167,19 @@ |
152 | 168 | $array = $this->getGroups(); |
153 | 169 | $subarray = @$array[$group]['data'][$type][$key]; |
154 | 170 | if ( $this->elementsInArray ) { |
155 | | - if ( !$subarray || !count( $subarray ) ) return array(); |
| 171 | + if ( !$subarray || !count( $subarray ) ) { |
| 172 | + return array(); |
| 173 | + } |
156 | 174 | } else { |
157 | | - if ( !$subarray ) return array(); |
| 175 | + if ( !$subarray ) { |
| 176 | + return array(); |
| 177 | + } |
158 | 178 | } |
159 | 179 | |
160 | | - if ( !is_array( $subarray ) ) $subarray = array( $subarray ); |
| 180 | + if ( !is_array( $subarray ) ) { |
| 181 | + $subarray = array( $subarray ); |
| 182 | + } |
| 183 | + |
161 | 184 | return $subarray; |
162 | 185 | } |
163 | 186 | |
— | — | @@ -169,7 +192,9 @@ |
170 | 193 | } |
171 | 194 | |
172 | 195 | $ { $group['var'] } = array(); # Initialize |
173 | | - if ( file_exists( $file ) ) require( $file ); # Include |
| 196 | + if ( file_exists( $file ) ) { |
| 197 | + require( $file ); # Include |
| 198 | + } |
174 | 199 | |
175 | 200 | if ( $group['code'] ) { |
176 | 201 | $data = (array) @$ { $group['var'] } [$code]; |
— | — | @@ -220,17 +245,23 @@ |
221 | 246 | |
222 | 247 | foreach ( array_keys( $this->data ) as $group ) { |
223 | 248 | $s .= $this->header( $this->data[$group]['label'] ); |
224 | | - |
| 249 | + |
225 | 250 | foreach ( $this->getIterator( $group ) as $key ) { |
226 | 251 | $rowContents = ''; |
227 | 252 | |
228 | 253 | $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 | + |
230 | 258 | $value = array_map( 'htmlspecialchars', $value ); |
231 | 259 | $rowContents .= '<td>' . $this->formatElement( $value ) . '</td>'; |
232 | 260 | |
233 | 261 | $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 | + |
235 | 266 | $value = array_map( 'htmlspecialchars', $value ); |
236 | 267 | $value = $this->highlight( $key, $value ); |
237 | 268 | $rowContents .= '<td>' . $this->formatElement( $value ) . '</td>'; |
— | — | @@ -263,7 +294,10 @@ |
264 | 295 | } |
265 | 296 | |
266 | 297 | public function formatElement( $element ) { |
267 | | - if ( !count( $element ) ) return ''; |
| 298 | + if ( !count( $element ) ) { |
| 299 | + return ''; |
| 300 | + } |
| 301 | + |
268 | 302 | if ( is_array( $element ) ) { |
269 | 303 | $element = array_map( 'trim', $element ); |
270 | 304 | $element = implode( ', ', $element ); |
— | — | @@ -297,8 +331,9 @@ |
298 | 332 | foreach ( $this->getIterator( $group ) as $key ) { |
299 | 333 | $data = $request->getText( $this->getKeyForEdit( $key ) ); |
300 | 334 | $data = implode( ', ', array_map( 'trim', explode( ',', $data ) ) ); |
301 | | - if ( $data !== '' ) |
| 335 | + if ( $data !== '' ) { |
302 | 336 | $text .= "$key = $data\n" ; |
| 337 | + } |
303 | 338 | } |
304 | 339 | } |
305 | 340 | return $text; |
— | — | @@ -319,7 +354,6 @@ |
320 | 355 | |
321 | 356 | /* Reset outdated array */ |
322 | 357 | $this->init = false; |
323 | | - |
324 | 358 | } |
325 | 359 | |
326 | 360 | # |
— | — | @@ -332,7 +366,10 @@ |
333 | 367 | public function validate( &$errors = array(), $filter = false ) { |
334 | 368 | $used = array(); |
335 | 369 | 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 | + |
337 | 374 | $this->validateEach( $errors, $group, $used ); |
338 | 375 | } |
339 | 376 | } |
— | — | @@ -365,7 +402,10 @@ |
366 | 403 | foreach ( $errors as $_ ) $text .= "#!!# $_\n"; |
367 | 404 | |
368 | 405 | 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 | + |
370 | 410 | $text .= $this->exportEach( $group, $data ); |
371 | 411 | } |
372 | 412 | |
— | — | @@ -394,11 +434,15 @@ |
395 | 435 | |
396 | 436 | $from = self::LANG_CURRENT; |
397 | 437 | // 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 | + } |
399 | 441 | |
400 | 442 | // Check for translations |
401 | 443 | $val = $this->val( $group, self::LANG_CURRENT, $key ); |
402 | | - if ( !$val || !count( $val ) ) continue; |
| 444 | + if ( !$val || !count( $val ) ) { |
| 445 | + continue; |
| 446 | + } |
403 | 447 | |
404 | 448 | // Then get the data we really want |
405 | 449 | $val = $this->val( $group, $from, $key ); |
— | — | @@ -406,11 +450,19 @@ |
407 | 451 | // Remove duplicated entries, causes problems with magic words |
408 | 452 | // Just to be sure, it should not be possible to save invalid data anymore |
409 | 453 | $val = array_unique( $val /*FIXME:SORT_REGULAR*/ ); |
| 454 | + |
410 | 455 | // 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 | + } |
414 | 461 | |
| 462 | + // Another check |
| 463 | + if ( !count( $val ) ) { |
| 464 | + continue; |
| 465 | + } |
| 466 | + |
415 | 467 | $normalized = array_map( array( $this, 'normalize' ), $val ); |
416 | 468 | if ( $this->elementsInArray ) { |
417 | 469 | $temp .= "=> array( " . implode( ', ', $normalized ) . " ),"; |
— | — | @@ -469,9 +521,14 @@ |
470 | 522 | global $wgTranslateExtensionDirectory; |
471 | 523 | $groups = MessageGroups::singleton()->getGroups(); |
472 | 524 | foreach ( $groups as $g ) { |
473 | | - if ( !$g instanceof ExtensionMessageGroup ) continue; |
| 525 | + if ( !$g instanceof ExtensionMessageGroup ) { |
| 526 | + continue; |
| 527 | + } |
| 528 | + |
474 | 529 | $file = $g->getAliasFile(); |
475 | | - if ( $file === null ) continue; |
| 530 | + if ( $file === null ) { |
| 531 | + continue; |
| 532 | + } |
476 | 533 | |
477 | 534 | $file = "$wgTranslateExtensionDirectory/$file"; |
478 | 535 | if ( file_exists( $file ) ) { |
— | — | @@ -487,7 +544,10 @@ |
488 | 545 | |
489 | 546 | public function highlight( $key, $values ) { |
490 | 547 | 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 | + |
492 | 552 | $values[0] = "<b>$values[0]</b>"; |
493 | 553 | } |
494 | 554 | return $values; |
— | — | @@ -537,9 +597,14 @@ |
538 | 598 | global $wgTranslateExtensionDirectory; |
539 | 599 | $groups = MessageGroups::singleton()->getGroups(); |
540 | 600 | foreach ( $groups as $g ) { |
541 | | - if ( !$g instanceof ExtensionMessageGroup ) continue; |
| 601 | + if ( !$g instanceof ExtensionMessageGroup ) { |
| 602 | + continue; |
| 603 | + } |
| 604 | + |
542 | 605 | $file = $g->getMagicFile(); |
543 | | - if ( $file === null ) continue; |
| 606 | + if ( $file === null ) { |
| 607 | + continue; |
| 608 | + } |
544 | 609 | |
545 | 610 | $file = "$wgTranslateExtensionDirectory/$file"; |
546 | 611 | if ( file_exists( $file ) ) { |
— | — | @@ -554,10 +619,12 @@ |
555 | 620 | } |
556 | 621 | |
557 | 622 | 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 | + |
559 | 627 | return $values; |
560 | 628 | } |
561 | | - |
562 | 629 | } |
563 | 630 | |
564 | 631 | class NamespaceCM extends ComplexMessages { |
— | — | @@ -576,8 +643,8 @@ |
577 | 644 | } |
578 | 645 | |
579 | 646 | protected $constants = array( |
580 | | - - 2 => 'NS_MEDIA', |
581 | | - - 1 => 'NS_SPECIAL', |
| 647 | + -2 => 'NS_MEDIA', |
| 648 | + -1 => 'NS_SPECIAL', |
582 | 649 | 0 => 'NS_MAIN', |
583 | 650 | 1 => 'NS_TALK', |
584 | 651 | 2 => 'NS_USER', |
— | — | @@ -607,5 +674,4 @@ |
608 | 675 | } |
609 | 676 | } |
610 | 677 | } |
611 | | - |
612 | 678 | } |
Index: trunk/extensions/Translate/SpecialMagic.php |
— | — | @@ -26,7 +26,7 @@ |
27 | 27 | private $nondefaults = array(); |
28 | 28 | |
29 | 29 | public function __construct() { |
30 | | - SpecialPage::SpecialPage( 'Magic' ); |
| 30 | + parent::__construct( 'Magic' ); |
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
— | — | @@ -37,7 +37,7 @@ |
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
41 | | - * Returns xhtml output of the form |
| 41 | + * Returns HTML5 output of the form |
42 | 42 | * GLOBALS: $wgLang |
43 | 43 | */ |
44 | 44 | protected function getForm() { |
— | — | @@ -62,14 +62,13 @@ |
63 | 63 | Xml::submitButton( wfMsg( 'translate-magic-cm-export' ), array( 'name' => 'export' ) ) . |
64 | 64 | '</td></tr></table>' . |
65 | 65 | Xml::hidden( 'title', $this->getTitle()->getPrefixedText() ) |
66 | | - |
67 | 66 | ); |
68 | 67 | return $form; |
69 | 68 | } |
70 | 69 | |
71 | 70 | /** |
72 | 71 | * Helper function get module selector. |
73 | | - * Returns the xhtml-compatible select-element. |
| 72 | + * Returns the HTML5-compatible select-element. |
74 | 73 | * @param $selectedId which value should be selected by default |
75 | 74 | * @return string |
76 | 75 | */ |
— | — | @@ -85,10 +84,10 @@ |
86 | 85 | global $wgUser, $wgRequest; |
87 | 86 | |
88 | 87 | $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, |
93 | 92 | ); |
94 | 93 | |
95 | 94 | // Place where all non default variables will end |
— | — | @@ -118,7 +117,6 @@ |
119 | 118 | */ |
120 | 119 | public function execute( $parameters ) { |
121 | 120 | global $wgUser, $wgOut, $wgRequest, $wgLang; |
122 | | - wfLoadExtensionMessages( 'Translate' ); |
123 | 121 | |
124 | 122 | $this->setup( $parameters ); |
125 | 123 | $this->setHeaders(); |
— | — | @@ -164,7 +162,6 @@ |
165 | 163 | } |
166 | 164 | } |
167 | 165 | |
168 | | - |
169 | 166 | if ( $this->options['export'] ) { |
170 | 167 | $output = $o->export(); |
171 | 168 | if ( $output === '' ) { |
— | — | @@ -181,8 +178,6 @@ |
182 | 179 | $o->validate( $errors ); |
183 | 180 | if ( $errors ) $this->outputErrors( $errors ); |
184 | 181 | $wgOut->addHTML( $o->output() ); |
185 | | - |
186 | | - |
187 | 182 | } |
188 | 183 | |
189 | 184 | protected function outputErrors( $errors ) { |
— | — | @@ -195,5 +190,4 @@ |
196 | 191 | } |
197 | 192 | $wgOut->addHTML( '</ol>' ); |
198 | 193 | } |
199 | | - |
200 | 194 | } |