Index: trunk/extensions/Translate/TranslatePage.php |
— | — | @@ -1,505 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * Contains logic for special page Special:Translate. |
5 | | - * |
6 | | - * @file |
7 | | - * @author Niklas Laxström |
8 | | - * @author Siebrand Mazeland |
9 | | - * @copyright Copyright © 2006-2010 Niklas Laxström, Siebrand Mazeland |
10 | | - * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
11 | | - */ |
12 | | - |
13 | | -/** |
14 | | - * Implements the core of Translate extension - a special page which shows |
15 | | - * a list of messages in a format defined by Tasks. |
16 | | - * |
17 | | - * @ingroup SpecialPage TranslateSpecialPage |
18 | | - */ |
19 | | -class SpecialTranslate extends SpecialPage { |
20 | | - protected $task = null; |
21 | | - protected $group = null; |
22 | | - |
23 | | - protected $defaults = null; |
24 | | - protected $nondefaults = null; |
25 | | - protected $options = null; |
26 | | - |
27 | | - function __construct() { |
28 | | - parent::__construct( 'Translate' ); |
29 | | - } |
30 | | - |
31 | | - /** |
32 | | - * Access point for this special page. |
33 | | - */ |
34 | | - public function execute( $parameters ) { |
35 | | - global $wgOut, $wgTranslateBlacklist, $wgRequest; |
36 | | - |
37 | | - TranslateUtils::injectCSS(); |
38 | | - |
39 | | - $this->setHeaders(); |
40 | | - |
41 | | - if ( $parameters === 'editpage' ) { |
42 | | - $editpage = TranslationEditPage::newFromRequest( $wgRequest ); |
43 | | - |
44 | | - if ( $editpage ) { |
45 | | - $editpage->execute(); |
46 | | - return; |
47 | | - } |
48 | | - } |
49 | | - |
50 | | - $this->setup( $parameters ); |
51 | | - |
52 | | - $errors = array(); |
53 | | - |
54 | | - if ( $this->options['group'] === '' ) { |
55 | | - $wgOut->addHTML( $this->groupInformation() ); |
56 | | - return; |
57 | | - } |
58 | | - |
59 | | - $codes = Language::getLanguageNames( false ); |
60 | | - |
61 | | - if ( !$this->options['language'] || !isset( $codes[$this->options['language']] ) ) { |
62 | | - $errors['language'] = wfMsgExt( 'translate-page-no-such-language', array( 'parse' ) ); |
63 | | - $this->options['language'] = $this->defaults['language']; |
64 | | - } |
65 | | - |
66 | | - if ( !$this->task instanceof TranslateTask ) { |
67 | | - $errors['task'] = wfMsgExt( 'translate-page-no-such-task', array( 'parse' ) ); |
68 | | - $this->options['task'] = $this->defaults['task']; |
69 | | - } |
70 | | - |
71 | | - if ( !$this->group instanceof MessageGroup ) { |
72 | | - $errors['group'] = wfMsgExt( 'translate-page-no-such-group', array( 'parse' ) ); |
73 | | - $this->options['group'] = $this->defaults['group']; |
74 | | - } |
75 | | - |
76 | | - /** |
77 | | - * Show errors nicely. |
78 | | - */ |
79 | | - $wgOut->addHTML( $this->settingsForm( $errors ) ); |
80 | | - |
81 | | - if ( count( $errors ) ) { |
82 | | - return; |
83 | | - } else { |
84 | | - $checks = array( |
85 | | - $this->options['group'], |
86 | | - strtok( $this->options['group'], '-' ), |
87 | | - '*' |
88 | | - ); |
89 | | - |
90 | | - foreach ( $checks as $check ) { |
91 | | - $reason = @$wgTranslateBlacklist[$check][$this->options['language']]; |
92 | | - if ( $reason !== null ) { |
93 | | - $wgOut->addWikiMsg( 'translate-page-disabled', $reason ); |
94 | | - return; |
95 | | - } |
96 | | - } |
97 | | - } |
98 | | - |
99 | | - /** |
100 | | - * Proceed. |
101 | | - */ |
102 | | - $taskOptions = new TaskOptions( |
103 | | - $this->options['language'], |
104 | | - $this->options['limit'], |
105 | | - $this->options['offset'], |
106 | | - array( $this, 'cbAddPagingNumbers' ) |
107 | | - ); |
108 | | - |
109 | | - /** |
110 | | - * Initialise and get output. |
111 | | - */ |
112 | | - $this->task->init( $this->group, $taskOptions ); |
113 | | - $output = $this->task->execute(); |
114 | | - |
115 | | - if ( $this->task->plainOutput() ) { |
116 | | - $wgOut->disable(); |
117 | | - header( 'Content-type: text/plain; charset=UTF-8' ); |
118 | | - echo $output; |
119 | | - } else { |
120 | | - $description = $this->getGroupDescription( $this->group ); |
121 | | - if ( $description ) { |
122 | | - $description = Xml::fieldset( wfMsg( 'translate-page-description-legend' ), $description ); |
123 | | - } |
124 | | - |
125 | | - $links = $this->doStupidLinks(); |
126 | | - |
127 | | - if ( $this->paging['count'] === 0 ) { |
128 | | - $wgOut->addHTML( $description . $links ); |
129 | | - } else { |
130 | | - $wgOut->addHTML( $description . $links . $output . $links ); |
131 | | - } |
132 | | - } |
133 | | - } |
134 | | - |
135 | | - protected function setup( $parameters ) { |
136 | | - global $wgUser, $wgRequest; |
137 | | - |
138 | | - $defaults = array( |
139 | | - /* str */ 'task' => 'untranslated', |
140 | | - /* str */ 'sort' => 'normal', |
141 | | - /* str */ 'language' => $wgUser->getOption( 'language' ), |
142 | | - /* str */ 'group' => '', |
143 | | - /* int */ 'offset' => 0, |
144 | | - /* int */ 'limit' => 100, |
145 | | - ); |
146 | | - |
147 | | - // Dump everything here |
148 | | - $nondefaults = array(); |
149 | | - |
150 | | - $parameters = array_map( 'trim', explode( ';', $parameters ) ); |
151 | | - $pars = array(); |
152 | | - |
153 | | - foreach ( $parameters as $_ ) { |
154 | | - if ( $_ === '' ) { |
155 | | - continue; |
156 | | - } |
157 | | - |
158 | | - if ( strpos( $_, '=' ) !== false ) { |
159 | | - list( $key, $value ) = array_map( 'trim', explode( '=', $_, 2 ) ); |
160 | | - } else { |
161 | | - $key = 'group'; |
162 | | - $value = $_; |
163 | | - } |
164 | | - |
165 | | - $pars[$key] = $value; |
166 | | - } |
167 | | - |
168 | | - foreach ( $defaults as $v => $t ) { |
169 | | - if ( is_bool( $t ) ) { |
170 | | - $r = isset( $pars[$v] ) ? (bool) $pars[$v] : $defaults[$v]; |
171 | | - $r = $wgRequest->getBool( $v, $r ); |
172 | | - } elseif ( is_int( $t ) ) { |
173 | | - $r = isset( $pars[$v] ) ? (int) $pars[$v] : $defaults[$v]; |
174 | | - $r = $wgRequest->getInt( $v, $r ); |
175 | | - } elseif ( is_string( $t ) ) { |
176 | | - $r = isset( $pars[$v] ) ? (string) $pars[$v] : $defaults[$v]; |
177 | | - $r = $wgRequest->getText( $v, $r ); |
178 | | - } |
179 | | - |
180 | | - wfAppendToArrayIfNotDefault( $v, $r, $defaults, $nondefaults ); |
181 | | - } |
182 | | - |
183 | | - $this->defaults = $defaults; |
184 | | - $this->nondefaults = $nondefaults; |
185 | | - $this->options = $nondefaults + $defaults; |
186 | | - |
187 | | - $this->group = MessageGroups::getGroup( $this->options['group'] ); |
188 | | - $this->task = TranslateTasks::getTask( $this->options['task'] ); |
189 | | - } |
190 | | - |
191 | | - protected function settingsForm( $errors ) { |
192 | | - global $wgScript; |
193 | | - |
194 | | - // These are used, in the $$g black magic below. Do not remove! |
195 | | - $task = $this->taskSelector(); |
196 | | - $group = $this->groupSelector(); |
197 | | - $language = $this->languageSelector(); |
198 | | - $limit = $this->limitSelector(); |
199 | | - |
200 | | - $button = Xml::submitButton( wfMsg( 'translate-submit' ) ); |
201 | | - |
202 | | - $options = array(); |
203 | | - |
204 | | - foreach ( array( 'task', 'group', 'language', 'limit' ) as $g ) { |
205 | | - $options[] = self::optionRow( |
206 | | - Xml::tags( 'label', array( 'for' => $g ), wfMsgExt( 'translate-page-' . $g, 'escapenoentities' ) ), |
207 | | - $$g, |
208 | | - array_key_exists( $g, $errors ) ? $errors[$g] : null |
209 | | - ); |
210 | | - } |
211 | | - |
212 | | - $form = |
213 | | - Xml::openElement( 'fieldset', array( 'class' => 'mw-sp-translate-settings' ) ) . |
214 | | - Xml::element( 'legend', null, wfMsg( 'translate-page-settings-legend' ) ) . |
215 | | - Xml::openElement( 'form', array( 'action' => $wgScript, 'method' => 'get' ) ) . |
216 | | - Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . |
217 | | - Xml::openElement( 'table' ) . |
218 | | - implode( "", $options ) . |
219 | | - self::optionRow( $button, ' ' ) . |
220 | | - Xml::closeElement( 'table' ) . |
221 | | - Xml::closeElement( 'form' ) . |
222 | | - Xml::closeElement( 'fieldset' ); |
223 | | - return $form; |
224 | | - } |
225 | | - |
226 | | - private static function optionRow( $label, $option, $error = null ) { |
227 | | - return |
228 | | - Xml::openElement( 'tr' ) . |
229 | | - Xml::tags( 'td', null, $label ) . |
230 | | - Xml::tags( 'td', null, $option ) . |
231 | | - ( $error ? Xml::tags( 'td', array( 'class' => 'mw-sp-translate-error' ), $error ) : '' ) . |
232 | | - Xml::closeElement( 'tr' ); |
233 | | - |
234 | | - } |
235 | | - |
236 | | - /* Selectors ahead */ |
237 | | - |
238 | | - protected function groupSelector() { |
239 | | - $groups = MessageGroups::getAllGroups(); |
240 | | - $selector = new HTMLSelector( 'group', 'group', $this->options['group'] ); |
241 | | - |
242 | | - foreach ( $groups as $id => $class ) { |
243 | | - if ( MessageGroups::getGroup( $id )->exists() ) { |
244 | | - $selector->addOption( $class->getLabel(), $id ); |
245 | | - } |
246 | | - } |
247 | | - |
248 | | - return $selector->getHTML(); |
249 | | - } |
250 | | - |
251 | | - protected function taskSelector( $pageTranslation = false ) { |
252 | | - $selector = new HTMLSelector( 'task', 'task', $this->options['task'] ); |
253 | | - |
254 | | - $isPageTranslation = $this->group instanceof WikiPageMessageGroup; |
255 | | - foreach ( TranslateTasks::getTasks( $isPageTranslation ) as $id ) { |
256 | | - $label = TranslateTask::labelForTask( $id ); |
257 | | - $selector->addOption( $label, $id ); |
258 | | - } |
259 | | - |
260 | | - return $selector->getHTML(); |
261 | | - } |
262 | | - |
263 | | - protected function languageSelector() { |
264 | | - global $wgLang; |
265 | | - |
266 | | - return TranslateUtils::languageSelector( |
267 | | - $wgLang->getCode(), |
268 | | - $this->options['language'] |
269 | | - ); |
270 | | - } |
271 | | - |
272 | | - protected function limitSelector() { |
273 | | - global $wgLang; |
274 | | - |
275 | | - $items = array( 100, 250, 500, 1000, 2500 ); |
276 | | - $selector = new HTMLSelector( 'limit', 'limit', $this->options['limit'] ); |
277 | | - |
278 | | - foreach ( $items as $count ) { |
279 | | - $selector->addOption( wfMsgExt( 'translate-page-limit-option', 'parsemag', $wgLang->formatNum( $count ) ), $count ); |
280 | | - } |
281 | | - |
282 | | - return $selector->getHTML(); |
283 | | - } |
284 | | - |
285 | | - private $paging = null; |
286 | | - |
287 | | - public function cbAddPagingNumbers( $start, $count, $total ) { |
288 | | - $this->paging = array( |
289 | | - 'start' => $start, |
290 | | - 'count' => $count, |
291 | | - 'total' => $total |
292 | | - ); |
293 | | - } |
294 | | - |
295 | | - protected function doStupidLinks() { |
296 | | - if ( $this->paging === null ) { |
297 | | - return ''; |
298 | | - } |
299 | | - |
300 | | - $start = $this->paging['start'] + 1 ; |
301 | | - $stop = $start + $this->paging['count'] - 1; |
302 | | - $total = $this->paging['total']; |
303 | | - |
304 | | - $allInThisPage = $start === 1 && $total <= $this->options['limit']; |
305 | | - |
306 | | - if ( $this->paging['count'] === 0 ) { |
307 | | - $navigation = wfMsgExt( 'translate-page-showing-none', array( 'parseinline' ) ); |
308 | | - } elseif ( $allInThisPage ) { |
309 | | - $navigation = wfMsgExt( |
310 | | - 'translate-page-showing-all', |
311 | | - array( 'parseinline' ), |
312 | | - $total |
313 | | - ); |
314 | | - } else { |
315 | | - $previous = wfMsg( 'translate-prev' ); |
316 | | - if ( $this->options['offset'] > 0 ) { |
317 | | - $offset = max( 0, $this->options['offset'] - $this->options['limit'] ); |
318 | | - $previous = $this->makeOffsetLink( $previous, $offset ); |
319 | | - } |
320 | | - |
321 | | - $nextious = wfMsg( 'translate-next' ); |
322 | | - |
323 | | - if ( $this->paging['total'] != $this->paging['start'] + $this->paging['count'] ) { |
324 | | - $offset = $this->options['offset'] + $this->options['limit']; |
325 | | - $nextious = $this->makeOffsetLink( $nextious, $offset ); |
326 | | - } |
327 | | - |
328 | | - $start = $this->paging['start'] + 1 ; |
329 | | - $stop = $start + $this->paging['count'] - 1; |
330 | | - $total = $this->paging['total']; |
331 | | - |
332 | | - $showing = wfMsgExt( |
333 | | - 'translate-page-showing', |
334 | | - array( 'parseinline' ), |
335 | | - $start, |
336 | | - $stop, |
337 | | - $total ); |
338 | | - |
339 | | - $navigation = wfMsgExt( |
340 | | - 'translate-page-paging-links', |
341 | | - array( 'escape', 'replaceafter' ), |
342 | | - $previous, |
343 | | - $nextious |
344 | | - ); |
345 | | - |
346 | | - $navigation = $showing . ' ' . $navigation; |
347 | | - } |
348 | | - |
349 | | - return |
350 | | - Xml::openElement( 'fieldset' ) . |
351 | | - Xml::element( 'legend', null, wfMsg( 'translate-page-navigation-legend' ) ) . |
352 | | - $navigation . |
353 | | - Xml::closeElement( 'fieldset' ); |
354 | | - } |
355 | | - |
356 | | - private function makeOffsetLink( $label, $offset ) { |
357 | | - global $wgUser; |
358 | | - |
359 | | - $skin = $wgUser->getSkin(); |
360 | | - |
361 | | - $query = array_merge( |
362 | | - $this->nondefaults, |
363 | | - array( 'offset' => $offset ) |
364 | | - ); |
365 | | - |
366 | | - $link = $skin->link( |
367 | | - $this->getTitle(), |
368 | | - $label, |
369 | | - array(), |
370 | | - $query |
371 | | - ); |
372 | | - |
373 | | - return $link; |
374 | | - } |
375 | | - |
376 | | - protected function getGroupDescription( MessageGroup $group ) { |
377 | | - global $wgOut; |
378 | | - |
379 | | - $description = $group->getDescription(); |
380 | | - |
381 | | - if ( $description === null ) { |
382 | | - return null; |
383 | | - } |
384 | | - |
385 | | - $description = $wgOut->parse( $description, false ); |
386 | | - |
387 | | - return $description; |
388 | | - } |
389 | | - |
390 | | - /** |
391 | | - * Returns group strucuted into sub groups. First group in each subgroup is |
392 | | - * considered as the main group. |
393 | | - */ |
394 | | - public function getGroupStructure() { |
395 | | - global $wgTranslateGroupStructure; |
396 | | - |
397 | | - $groups = MessageGroups::getAllGroups(); |
398 | | - $structure = array(); |
399 | | - |
400 | | - foreach ( $groups as $id => $o ) { |
401 | | - if ( !MessageGroups::getGroup( $id )->exists() ) { |
402 | | - continue; |
403 | | - } |
404 | | - |
405 | | - foreach ( $wgTranslateGroupStructure as $pattern => $hypergroup ) { |
406 | | - if ( preg_match( $pattern, $id ) ) { |
407 | | - /** |
408 | | - * Emulate deepArraySet, because AFAIK php does not have one |
409 | | - */ |
410 | | - self::deepArraySet( $structure, $hypergroup, $id, $o ); |
411 | | - /** |
412 | | - * We need to continue the outer loop, because we have finished this item. |
413 | | - */ |
414 | | - continue 2; |
415 | | - } |
416 | | - } |
417 | | - |
418 | | - /** |
419 | | - * Does not belong to any subgroup, just shove it into main level. |
420 | | - */ |
421 | | - $structure[$id] = $o; |
422 | | - } |
423 | | - |
424 | | - return $structure; |
425 | | - } |
426 | | - |
427 | | - /** |
428 | | - * Function do do $array[level1][level2]...[levelN][$key] = $value, if we have |
429 | | - * the indexes in an array. |
430 | | - */ |
431 | | - public static function deepArraySet( &$array, array $indexes, $key, $value ) { |
432 | | - foreach ( $indexes as $index ) { |
433 | | - if ( !isset( $array[$index] ) ) $array[$index] = array(); |
434 | | - $array = &$array[$index]; |
435 | | - } |
436 | | - |
437 | | - $array[$key] = $value; |
438 | | - } |
439 | | - |
440 | | - public function groupInformation() { |
441 | | - $out = ''; |
442 | | - $structure = $this->getGroupStructure(); |
443 | | - |
444 | | - foreach ( $structure as $blocks ) { |
445 | | - $out .= $this->formatGroupInformation( $blocks ); |
446 | | - } |
447 | | - |
448 | | - $header = wfMsgExt( 'translate-grouplisting', 'parse' ); |
449 | | - return $header . "\n" . Html::rawElement( 'table', array( 'class' => 'mw-sp-translate-grouplist wikitable' ), $out ); |
450 | | - } |
451 | | - |
452 | | - public function formatGroupInformation( $blocks, $level = 2 ) { |
453 | | - global $wgUser, $wgLang; |
454 | | - |
455 | | - if ( is_array( $blocks ) ) { |
456 | | - $block = array_shift( $blocks ); |
457 | | - } else { |
458 | | - $block = $blocks; |
459 | | - } |
460 | | - |
461 | | - $id = $block->getId(); |
462 | | - |
463 | | - $title = $this->getTitle(); |
464 | | - |
465 | | - $code = $this->options['language']; |
466 | | - $queryParams = array( |
467 | | - 'group' => $id, |
468 | | - 'language' => $code |
469 | | - ); |
470 | | - |
471 | | - $label = $wgUser->getSkin()->link( |
472 | | - $title, |
473 | | - htmlspecialchars( $block->getLabel() ), |
474 | | - array(), |
475 | | - $queryParams |
476 | | - ); |
477 | | - |
478 | | - $desc = $this->getGroupDescription( $block ); |
479 | | - $hasSubblocks = is_array( $blocks ) && count( $blocks ); |
480 | | - |
481 | | - $subid = Sanitizer::escapeId( "mw-subgroup-$id" ); |
482 | | - |
483 | | - if ( $hasSubblocks ) { |
484 | | - $msg = wfMsgExt( 'translate-showsub', 'parsemag', $wgLang->formatNum( count( $blocks ) ) ); |
485 | | - $target = TranslationHelpers::jQueryPathId( $subid ); |
486 | | - $desc .= Html::element( 'a', array( 'onclick' => "jQuery($target).toggle()", 'class' => 'mw-sp-showmore' ), $msg ); |
487 | | - } |
488 | | - |
489 | | - $out = "\n<tr><td>$label</td>\n<td>$desc</td></tr>\n"; |
490 | | - if ( $hasSubblocks ) { |
491 | | - $out .= "<tr><td></td><td>\n"; |
492 | | - $tableParams = array( |
493 | | - 'id' => $subid, |
494 | | - 'style' => 'display:none;', |
495 | | - 'class' => "mw-sp-translate-subgroup depth-$level", |
496 | | - ); |
497 | | - $out .= Html::openElement( 'table', $tableParams ); |
498 | | - foreach ( $blocks as $subBlock ) { |
499 | | - $out .= $this->formatGroupInformation( $subBlock, $level + 1 ); |
500 | | - } |
501 | | - $out .= '</table></td></tr>'; |
502 | | - } |
503 | | - |
504 | | - return $out; |
505 | | - } |
506 | | -} |
Index: trunk/extensions/Translate/_autoload.php |
— | — | @@ -57,7 +57,7 @@ |
58 | 58 | * There are few more special pages in page translation section. |
59 | 59 | * @{ |
60 | 60 | */ |
61 | | -$wgAutoloadClasses['SpecialTranslate'] = $dir . 'TranslatePage.php'; |
| 61 | +$wgAutoloadClasses['SpecialTranslate'] = $dir . 'SpecialTranslate.php'; |
62 | 62 | $wgAutoloadClasses['SpecialMagic'] = $dir . 'SpecialMagic.php'; |
63 | 63 | $wgAutoloadClasses['SpecialTranslationChanges'] = $dir . 'SpecialTranslationChanges.php'; |
64 | 64 | $wgAutoloadClasses['SpecialTranslationStats'] = $dir . 'SpecialTranslationStats.php'; |
Index: trunk/extensions/Translate/SpecialTranslate.php |
— | — | @@ -0,0 +1,505 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Contains logic for special page Special:Translate. |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @author Niklas Laxström |
| 8 | + * @author Siebrand Mazeland |
| 9 | + * @copyright Copyright © 2006-2010 Niklas Laxström, Siebrand Mazeland |
| 10 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 11 | + */ |
| 12 | + |
| 13 | +/** |
| 14 | + * Implements the core of Translate extension - a special page which shows |
| 15 | + * a list of messages in a format defined by Tasks. |
| 16 | + * |
| 17 | + * @ingroup SpecialPage TranslateSpecialPage |
| 18 | + */ |
| 19 | +class SpecialTranslate extends SpecialPage { |
| 20 | + protected $task = null; |
| 21 | + protected $group = null; |
| 22 | + |
| 23 | + protected $defaults = null; |
| 24 | + protected $nondefaults = null; |
| 25 | + protected $options = null; |
| 26 | + |
| 27 | + function __construct() { |
| 28 | + parent::__construct( 'Translate' ); |
| 29 | + } |
| 30 | + |
| 31 | + /** |
| 32 | + * Access point for this special page. |
| 33 | + */ |
| 34 | + public function execute( $parameters ) { |
| 35 | + global $wgOut, $wgTranslateBlacklist, $wgRequest; |
| 36 | + |
| 37 | + TranslateUtils::injectCSS(); |
| 38 | + |
| 39 | + $this->setHeaders(); |
| 40 | + |
| 41 | + if ( $parameters === 'editpage' ) { |
| 42 | + $editpage = TranslationEditPage::newFromRequest( $wgRequest ); |
| 43 | + |
| 44 | + if ( $editpage ) { |
| 45 | + $editpage->execute(); |
| 46 | + return; |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + $this->setup( $parameters ); |
| 51 | + |
| 52 | + $errors = array(); |
| 53 | + |
| 54 | + if ( $this->options['group'] === '' ) { |
| 55 | + $wgOut->addHTML( $this->groupInformation() ); |
| 56 | + return; |
| 57 | + } |
| 58 | + |
| 59 | + $codes = Language::getLanguageNames( false ); |
| 60 | + |
| 61 | + if ( !$this->options['language'] || !isset( $codes[$this->options['language']] ) ) { |
| 62 | + $errors['language'] = wfMsgExt( 'translate-page-no-such-language', array( 'parse' ) ); |
| 63 | + $this->options['language'] = $this->defaults['language']; |
| 64 | + } |
| 65 | + |
| 66 | + if ( !$this->task instanceof TranslateTask ) { |
| 67 | + $errors['task'] = wfMsgExt( 'translate-page-no-such-task', array( 'parse' ) ); |
| 68 | + $this->options['task'] = $this->defaults['task']; |
| 69 | + } |
| 70 | + |
| 71 | + if ( !$this->group instanceof MessageGroup ) { |
| 72 | + $errors['group'] = wfMsgExt( 'translate-page-no-such-group', array( 'parse' ) ); |
| 73 | + $this->options['group'] = $this->defaults['group']; |
| 74 | + } |
| 75 | + |
| 76 | + /** |
| 77 | + * Show errors nicely. |
| 78 | + */ |
| 79 | + $wgOut->addHTML( $this->settingsForm( $errors ) ); |
| 80 | + |
| 81 | + if ( count( $errors ) ) { |
| 82 | + return; |
| 83 | + } else { |
| 84 | + $checks = array( |
| 85 | + $this->options['group'], |
| 86 | + strtok( $this->options['group'], '-' ), |
| 87 | + '*' |
| 88 | + ); |
| 89 | + |
| 90 | + foreach ( $checks as $check ) { |
| 91 | + $reason = @$wgTranslateBlacklist[$check][$this->options['language']]; |
| 92 | + if ( $reason !== null ) { |
| 93 | + $wgOut->addWikiMsg( 'translate-page-disabled', $reason ); |
| 94 | + return; |
| 95 | + } |
| 96 | + } |
| 97 | + } |
| 98 | + |
| 99 | + /** |
| 100 | + * Proceed. |
| 101 | + */ |
| 102 | + $taskOptions = new TaskOptions( |
| 103 | + $this->options['language'], |
| 104 | + $this->options['limit'], |
| 105 | + $this->options['offset'], |
| 106 | + array( $this, 'cbAddPagingNumbers' ) |
| 107 | + ); |
| 108 | + |
| 109 | + /** |
| 110 | + * Initialise and get output. |
| 111 | + */ |
| 112 | + $this->task->init( $this->group, $taskOptions ); |
| 113 | + $output = $this->task->execute(); |
| 114 | + |
| 115 | + if ( $this->task->plainOutput() ) { |
| 116 | + $wgOut->disable(); |
| 117 | + header( 'Content-type: text/plain; charset=UTF-8' ); |
| 118 | + echo $output; |
| 119 | + } else { |
| 120 | + $description = $this->getGroupDescription( $this->group ); |
| 121 | + if ( $description ) { |
| 122 | + $description = Xml::fieldset( wfMsg( 'translate-page-description-legend' ), $description ); |
| 123 | + } |
| 124 | + |
| 125 | + $links = $this->doStupidLinks(); |
| 126 | + |
| 127 | + if ( $this->paging['count'] === 0 ) { |
| 128 | + $wgOut->addHTML( $description . $links ); |
| 129 | + } else { |
| 130 | + $wgOut->addHTML( $description . $links . $output . $links ); |
| 131 | + } |
| 132 | + } |
| 133 | + } |
| 134 | + |
| 135 | + protected function setup( $parameters ) { |
| 136 | + global $wgUser, $wgRequest; |
| 137 | + |
| 138 | + $defaults = array( |
| 139 | + /* str */ 'task' => 'untranslated', |
| 140 | + /* str */ 'sort' => 'normal', |
| 141 | + /* str */ 'language' => $wgUser->getOption( 'language' ), |
| 142 | + /* str */ 'group' => '', |
| 143 | + /* int */ 'offset' => 0, |
| 144 | + /* int */ 'limit' => 100, |
| 145 | + ); |
| 146 | + |
| 147 | + // Dump everything here |
| 148 | + $nondefaults = array(); |
| 149 | + |
| 150 | + $parameters = array_map( 'trim', explode( ';', $parameters ) ); |
| 151 | + $pars = array(); |
| 152 | + |
| 153 | + foreach ( $parameters as $_ ) { |
| 154 | + if ( $_ === '' ) { |
| 155 | + continue; |
| 156 | + } |
| 157 | + |
| 158 | + if ( strpos( $_, '=' ) !== false ) { |
| 159 | + list( $key, $value ) = array_map( 'trim', explode( '=', $_, 2 ) ); |
| 160 | + } else { |
| 161 | + $key = 'group'; |
| 162 | + $value = $_; |
| 163 | + } |
| 164 | + |
| 165 | + $pars[$key] = $value; |
| 166 | + } |
| 167 | + |
| 168 | + foreach ( $defaults as $v => $t ) { |
| 169 | + if ( is_bool( $t ) ) { |
| 170 | + $r = isset( $pars[$v] ) ? (bool) $pars[$v] : $defaults[$v]; |
| 171 | + $r = $wgRequest->getBool( $v, $r ); |
| 172 | + } elseif ( is_int( $t ) ) { |
| 173 | + $r = isset( $pars[$v] ) ? (int) $pars[$v] : $defaults[$v]; |
| 174 | + $r = $wgRequest->getInt( $v, $r ); |
| 175 | + } elseif ( is_string( $t ) ) { |
| 176 | + $r = isset( $pars[$v] ) ? (string) $pars[$v] : $defaults[$v]; |
| 177 | + $r = $wgRequest->getText( $v, $r ); |
| 178 | + } |
| 179 | + |
| 180 | + wfAppendToArrayIfNotDefault( $v, $r, $defaults, $nondefaults ); |
| 181 | + } |
| 182 | + |
| 183 | + $this->defaults = $defaults; |
| 184 | + $this->nondefaults = $nondefaults; |
| 185 | + $this->options = $nondefaults + $defaults; |
| 186 | + |
| 187 | + $this->group = MessageGroups::getGroup( $this->options['group'] ); |
| 188 | + $this->task = TranslateTasks::getTask( $this->options['task'] ); |
| 189 | + } |
| 190 | + |
| 191 | + protected function settingsForm( $errors ) { |
| 192 | + global $wgScript; |
| 193 | + |
| 194 | + // These are used, in the $$g black magic below. Do not remove! |
| 195 | + $task = $this->taskSelector(); |
| 196 | + $group = $this->groupSelector(); |
| 197 | + $language = $this->languageSelector(); |
| 198 | + $limit = $this->limitSelector(); |
| 199 | + |
| 200 | + $button = Xml::submitButton( wfMsg( 'translate-submit' ) ); |
| 201 | + |
| 202 | + $options = array(); |
| 203 | + |
| 204 | + foreach ( array( 'task', 'group', 'language', 'limit' ) as $g ) { |
| 205 | + $options[] = self::optionRow( |
| 206 | + Xml::tags( 'label', array( 'for' => $g ), wfMsgExt( 'translate-page-' . $g, 'escapenoentities' ) ), |
| 207 | + $$g, |
| 208 | + array_key_exists( $g, $errors ) ? $errors[$g] : null |
| 209 | + ); |
| 210 | + } |
| 211 | + |
| 212 | + $form = |
| 213 | + Xml::openElement( 'fieldset', array( 'class' => 'mw-sp-translate-settings' ) ) . |
| 214 | + Xml::element( 'legend', null, wfMsg( 'translate-page-settings-legend' ) ) . |
| 215 | + Xml::openElement( 'form', array( 'action' => $wgScript, 'method' => 'get' ) ) . |
| 216 | + Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . |
| 217 | + Xml::openElement( 'table' ) . |
| 218 | + implode( "", $options ) . |
| 219 | + self::optionRow( $button, ' ' ) . |
| 220 | + Xml::closeElement( 'table' ) . |
| 221 | + Xml::closeElement( 'form' ) . |
| 222 | + Xml::closeElement( 'fieldset' ); |
| 223 | + return $form; |
| 224 | + } |
| 225 | + |
| 226 | + private static function optionRow( $label, $option, $error = null ) { |
| 227 | + return |
| 228 | + Xml::openElement( 'tr' ) . |
| 229 | + Xml::tags( 'td', null, $label ) . |
| 230 | + Xml::tags( 'td', null, $option ) . |
| 231 | + ( $error ? Xml::tags( 'td', array( 'class' => 'mw-sp-translate-error' ), $error ) : '' ) . |
| 232 | + Xml::closeElement( 'tr' ); |
| 233 | + |
| 234 | + } |
| 235 | + |
| 236 | + /* Selectors ahead */ |
| 237 | + |
| 238 | + protected function groupSelector() { |
| 239 | + $groups = MessageGroups::getAllGroups(); |
| 240 | + $selector = new HTMLSelector( 'group', 'group', $this->options['group'] ); |
| 241 | + |
| 242 | + foreach ( $groups as $id => $class ) { |
| 243 | + if ( MessageGroups::getGroup( $id )->exists() ) { |
| 244 | + $selector->addOption( $class->getLabel(), $id ); |
| 245 | + } |
| 246 | + } |
| 247 | + |
| 248 | + return $selector->getHTML(); |
| 249 | + } |
| 250 | + |
| 251 | + protected function taskSelector( $pageTranslation = false ) { |
| 252 | + $selector = new HTMLSelector( 'task', 'task', $this->options['task'] ); |
| 253 | + |
| 254 | + $isPageTranslation = $this->group instanceof WikiPageMessageGroup; |
| 255 | + foreach ( TranslateTasks::getTasks( $isPageTranslation ) as $id ) { |
| 256 | + $label = TranslateTask::labelForTask( $id ); |
| 257 | + $selector->addOption( $label, $id ); |
| 258 | + } |
| 259 | + |
| 260 | + return $selector->getHTML(); |
| 261 | + } |
| 262 | + |
| 263 | + protected function languageSelector() { |
| 264 | + global $wgLang; |
| 265 | + |
| 266 | + return TranslateUtils::languageSelector( |
| 267 | + $wgLang->getCode(), |
| 268 | + $this->options['language'] |
| 269 | + ); |
| 270 | + } |
| 271 | + |
| 272 | + protected function limitSelector() { |
| 273 | + global $wgLang; |
| 274 | + |
| 275 | + $items = array( 100, 250, 500, 1000, 2500 ); |
| 276 | + $selector = new HTMLSelector( 'limit', 'limit', $this->options['limit'] ); |
| 277 | + |
| 278 | + foreach ( $items as $count ) { |
| 279 | + $selector->addOption( wfMsgExt( 'translate-page-limit-option', 'parsemag', $wgLang->formatNum( $count ) ), $count ); |
| 280 | + } |
| 281 | + |
| 282 | + return $selector->getHTML(); |
| 283 | + } |
| 284 | + |
| 285 | + private $paging = null; |
| 286 | + |
| 287 | + public function cbAddPagingNumbers( $start, $count, $total ) { |
| 288 | + $this->paging = array( |
| 289 | + 'start' => $start, |
| 290 | + 'count' => $count, |
| 291 | + 'total' => $total |
| 292 | + ); |
| 293 | + } |
| 294 | + |
| 295 | + protected function doStupidLinks() { |
| 296 | + if ( $this->paging === null ) { |
| 297 | + return ''; |
| 298 | + } |
| 299 | + |
| 300 | + $start = $this->paging['start'] + 1 ; |
| 301 | + $stop = $start + $this->paging['count'] - 1; |
| 302 | + $total = $this->paging['total']; |
| 303 | + |
| 304 | + $allInThisPage = $start === 1 && $total <= $this->options['limit']; |
| 305 | + |
| 306 | + if ( $this->paging['count'] === 0 ) { |
| 307 | + $navigation = wfMsgExt( 'translate-page-showing-none', array( 'parseinline' ) ); |
| 308 | + } elseif ( $allInThisPage ) { |
| 309 | + $navigation = wfMsgExt( |
| 310 | + 'translate-page-showing-all', |
| 311 | + array( 'parseinline' ), |
| 312 | + $total |
| 313 | + ); |
| 314 | + } else { |
| 315 | + $previous = wfMsg( 'translate-prev' ); |
| 316 | + if ( $this->options['offset'] > 0 ) { |
| 317 | + $offset = max( 0, $this->options['offset'] - $this->options['limit'] ); |
| 318 | + $previous = $this->makeOffsetLink( $previous, $offset ); |
| 319 | + } |
| 320 | + |
| 321 | + $nextious = wfMsg( 'translate-next' ); |
| 322 | + |
| 323 | + if ( $this->paging['total'] != $this->paging['start'] + $this->paging['count'] ) { |
| 324 | + $offset = $this->options['offset'] + $this->options['limit']; |
| 325 | + $nextious = $this->makeOffsetLink( $nextious, $offset ); |
| 326 | + } |
| 327 | + |
| 328 | + $start = $this->paging['start'] + 1 ; |
| 329 | + $stop = $start + $this->paging['count'] - 1; |
| 330 | + $total = $this->paging['total']; |
| 331 | + |
| 332 | + $showing = wfMsgExt( |
| 333 | + 'translate-page-showing', |
| 334 | + array( 'parseinline' ), |
| 335 | + $start, |
| 336 | + $stop, |
| 337 | + $total ); |
| 338 | + |
| 339 | + $navigation = wfMsgExt( |
| 340 | + 'translate-page-paging-links', |
| 341 | + array( 'escape', 'replaceafter' ), |
| 342 | + $previous, |
| 343 | + $nextious |
| 344 | + ); |
| 345 | + |
| 346 | + $navigation = $showing . ' ' . $navigation; |
| 347 | + } |
| 348 | + |
| 349 | + return |
| 350 | + Xml::openElement( 'fieldset' ) . |
| 351 | + Xml::element( 'legend', null, wfMsg( 'translate-page-navigation-legend' ) ) . |
| 352 | + $navigation . |
| 353 | + Xml::closeElement( 'fieldset' ); |
| 354 | + } |
| 355 | + |
| 356 | + private function makeOffsetLink( $label, $offset ) { |
| 357 | + global $wgUser; |
| 358 | + |
| 359 | + $skin = $wgUser->getSkin(); |
| 360 | + |
| 361 | + $query = array_merge( |
| 362 | + $this->nondefaults, |
| 363 | + array( 'offset' => $offset ) |
| 364 | + ); |
| 365 | + |
| 366 | + $link = $skin->link( |
| 367 | + $this->getTitle(), |
| 368 | + $label, |
| 369 | + array(), |
| 370 | + $query |
| 371 | + ); |
| 372 | + |
| 373 | + return $link; |
| 374 | + } |
| 375 | + |
| 376 | + protected function getGroupDescription( MessageGroup $group ) { |
| 377 | + global $wgOut; |
| 378 | + |
| 379 | + $description = $group->getDescription(); |
| 380 | + |
| 381 | + if ( $description === null ) { |
| 382 | + return null; |
| 383 | + } |
| 384 | + |
| 385 | + $description = $wgOut->parse( $description, false ); |
| 386 | + |
| 387 | + return $description; |
| 388 | + } |
| 389 | + |
| 390 | + /** |
| 391 | + * Returns group strucuted into sub groups. First group in each subgroup is |
| 392 | + * considered as the main group. |
| 393 | + */ |
| 394 | + public function getGroupStructure() { |
| 395 | + global $wgTranslateGroupStructure; |
| 396 | + |
| 397 | + $groups = MessageGroups::getAllGroups(); |
| 398 | + $structure = array(); |
| 399 | + |
| 400 | + foreach ( $groups as $id => $o ) { |
| 401 | + if ( !MessageGroups::getGroup( $id )->exists() ) { |
| 402 | + continue; |
| 403 | + } |
| 404 | + |
| 405 | + foreach ( $wgTranslateGroupStructure as $pattern => $hypergroup ) { |
| 406 | + if ( preg_match( $pattern, $id ) ) { |
| 407 | + /** |
| 408 | + * Emulate deepArraySet, because AFAIK php does not have one |
| 409 | + */ |
| 410 | + self::deepArraySet( $structure, $hypergroup, $id, $o ); |
| 411 | + /** |
| 412 | + * We need to continue the outer loop, because we have finished this item. |
| 413 | + */ |
| 414 | + continue 2; |
| 415 | + } |
| 416 | + } |
| 417 | + |
| 418 | + /** |
| 419 | + * Does not belong to any subgroup, just shove it into main level. |
| 420 | + */ |
| 421 | + $structure[$id] = $o; |
| 422 | + } |
| 423 | + |
| 424 | + return $structure; |
| 425 | + } |
| 426 | + |
| 427 | + /** |
| 428 | + * Function do do $array[level1][level2]...[levelN][$key] = $value, if we have |
| 429 | + * the indexes in an array. |
| 430 | + */ |
| 431 | + public static function deepArraySet( &$array, array $indexes, $key, $value ) { |
| 432 | + foreach ( $indexes as $index ) { |
| 433 | + if ( !isset( $array[$index] ) ) $array[$index] = array(); |
| 434 | + $array = &$array[$index]; |
| 435 | + } |
| 436 | + |
| 437 | + $array[$key] = $value; |
| 438 | + } |
| 439 | + |
| 440 | + public function groupInformation() { |
| 441 | + $out = ''; |
| 442 | + $structure = $this->getGroupStructure(); |
| 443 | + |
| 444 | + foreach ( $structure as $blocks ) { |
| 445 | + $out .= $this->formatGroupInformation( $blocks ); |
| 446 | + } |
| 447 | + |
| 448 | + $header = wfMsgExt( 'translate-grouplisting', 'parse' ); |
| 449 | + return $header . "\n" . Html::rawElement( 'table', array( 'class' => 'mw-sp-translate-grouplist wikitable' ), $out ); |
| 450 | + } |
| 451 | + |
| 452 | + public function formatGroupInformation( $blocks, $level = 2 ) { |
| 453 | + global $wgUser, $wgLang; |
| 454 | + |
| 455 | + if ( is_array( $blocks ) ) { |
| 456 | + $block = array_shift( $blocks ); |
| 457 | + } else { |
| 458 | + $block = $blocks; |
| 459 | + } |
| 460 | + |
| 461 | + $id = $block->getId(); |
| 462 | + |
| 463 | + $title = $this->getTitle(); |
| 464 | + |
| 465 | + $code = $this->options['language']; |
| 466 | + $queryParams = array( |
| 467 | + 'group' => $id, |
| 468 | + 'language' => $code |
| 469 | + ); |
| 470 | + |
| 471 | + $label = $wgUser->getSkin()->link( |
| 472 | + $title, |
| 473 | + htmlspecialchars( $block->getLabel() ), |
| 474 | + array(), |
| 475 | + $queryParams |
| 476 | + ); |
| 477 | + |
| 478 | + $desc = $this->getGroupDescription( $block ); |
| 479 | + $hasSubblocks = is_array( $blocks ) && count( $blocks ); |
| 480 | + |
| 481 | + $subid = Sanitizer::escapeId( "mw-subgroup-$id" ); |
| 482 | + |
| 483 | + if ( $hasSubblocks ) { |
| 484 | + $msg = wfMsgExt( 'translate-showsub', 'parsemag', $wgLang->formatNum( count( $blocks ) ) ); |
| 485 | + $target = TranslationHelpers::jQueryPathId( $subid ); |
| 486 | + $desc .= Html::element( 'a', array( 'onclick' => "jQuery($target).toggle()", 'class' => 'mw-sp-showmore' ), $msg ); |
| 487 | + } |
| 488 | + |
| 489 | + $out = "\n<tr><td>$label</td>\n<td>$desc</td></tr>\n"; |
| 490 | + if ( $hasSubblocks ) { |
| 491 | + $out .= "<tr><td></td><td>\n"; |
| 492 | + $tableParams = array( |
| 493 | + 'id' => $subid, |
| 494 | + 'style' => 'display:none;', |
| 495 | + 'class' => "mw-sp-translate-subgroup depth-$level", |
| 496 | + ); |
| 497 | + $out .= Html::openElement( 'table', $tableParams ); |
| 498 | + foreach ( $blocks as $subBlock ) { |
| 499 | + $out .= $this->formatGroupInformation( $subBlock, $level + 1 ); |
| 500 | + } |
| 501 | + $out .= '</table></td></tr>'; |
| 502 | + } |
| 503 | + |
| 504 | + return $out; |
| 505 | + } |
| 506 | +} |
Property changes on: trunk/extensions/Translate/SpecialTranslate.php |
___________________________________________________________________ |
Added: svn:mergeinfo |
Added: svn:eol-style |
1 | 507 | + native |