Index: trunk/extensions/Translate/scripts/populateFuzzy.php |
— | — | @@ -1,14 +1,15 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | | - * A script to populate fuzzy tags. |
| 4 | + * A script to populate fuzzy tags to revtag table. |
5 | 5 | * |
6 | 6 | * @author Niklas Laxstrom |
7 | | - * |
8 | | - * @copyright Copyright © 2009, Niklas Laxström |
| 7 | + * @copyright Copyright © 2009-2010, Niklas Laxström |
9 | 8 | * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
10 | 9 | * @file |
11 | 10 | */ |
12 | 11 | |
| 12 | +/// @cond |
| 13 | + |
13 | 14 | require( dirname( __FILE__ ) . '/cli.inc' ); |
14 | 15 | |
15 | 16 | $db = wfGetDB( DB_MASTER ); |
— | — | @@ -60,3 +61,5 @@ |
61 | 62 | |
62 | 63 | $db->replace( 'revtag', 'rt_type_page_revision', $inserts, __METHOD__ ); |
63 | 64 | } |
| 65 | + |
| 66 | +/// @endcond |
Index: trunk/extensions/Translate/TranslateTasks.php |
— | — | @@ -5,7 +5,7 @@ |
6 | 6 | * |
7 | 7 | * @file |
8 | 8 | * @author Niklas Laxström |
9 | | - * @copyright Copyright © 2007-2008 Niklas Laxström |
| 9 | + * @copyright Copyright © 2007-2010 Niklas Laxström |
10 | 10 | * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
11 | 11 | */ |
12 | 12 | |
— | — | @@ -13,11 +13,23 @@ |
14 | 14 | * Container for options that are passed to tasks. |
15 | 15 | */ |
16 | 16 | class TaskOptions { |
17 | | - private $language = null; |
18 | | - private $limit = 0; |
19 | | - private $offset = 0; |
20 | | - private $pagingCB = null; |
| 17 | + /// \string Language code. |
| 18 | + protected $language; |
| 19 | + /// \int Number of items to show. |
| 20 | + protected $limit = 0; |
| 21 | + /// \int Offset to the results. |
| 22 | + protected $offset = 0; |
| 23 | + /// \mixed Callback which is called to provide information about the result counts. |
| 24 | + protected $pagingCB; |
21 | 25 | |
| 26 | + /** |
| 27 | + * @param $language \string Language code. |
| 28 | + * @param $limit \int Number of items to show. |
| 29 | + * @param $offset \int Offset to the results. |
| 30 | + * @param $pagingCB \mixed Callback which is called to provide information |
| 31 | + * about the result counts. The callback is provided with three parameters: |
| 32 | + * provided offset, number of messages to show, number of messages in total. |
| 33 | + */ |
22 | 34 | public function __construct( $language, $limit = 0, $offset = 0, $pagingCB = null ) { |
23 | 35 | $this->language = $language; |
24 | 36 | $this->limit = $limit; |
— | — | @@ -25,55 +37,101 @@ |
26 | 38 | $this->pagingCB = $pagingCB; |
27 | 39 | } |
28 | 40 | |
| 41 | + /** |
| 42 | + * @return \string Language code. |
| 43 | + */ |
29 | 44 | public function getLanguage() { |
30 | 45 | return $this->language; |
31 | 46 | } |
32 | 47 | |
| 48 | + /** |
| 49 | + * @return \int Number of items to show. |
| 50 | + */ |
33 | 51 | public function getLimit() { |
34 | 52 | return $this->limit; |
35 | 53 | } |
36 | 54 | |
| 55 | + /** |
| 56 | + * @return \int Offset to the results. |
| 57 | + */ |
37 | 58 | public function getOffset() { |
38 | 59 | return $this->offset; |
39 | 60 | } |
40 | 61 | |
| 62 | + /** |
| 63 | + * @return \mixed Callback which is called to provide information about the result counts. |
| 64 | + */ |
41 | 65 | public function getPagingCB() { |
42 | 66 | return $this->pagingCB; |
43 | 67 | } |
44 | 68 | } |
45 | 69 | |
46 | 70 | /** |
47 | | - * Implements the core of TranslateTask. |
| 71 | + * Basic implementation and interface for tasks. |
| 72 | + * Task is a combination of filters and output format that are applied to |
| 73 | + * messages of given message group in given language. |
48 | 74 | */ |
49 | 75 | abstract class TranslateTask { |
| 76 | + /// \string Task identifier. |
50 | 77 | protected $id = '__BUG__'; |
51 | 78 | |
| 79 | + // We need $id here because staticness prevents subclass overriding. |
52 | 80 | /** |
53 | | - * We need $id here because staticness prevents subclass overriding. |
| 81 | + * Get label for task. |
| 82 | + * @param $id \string. |
| 83 | + * @return \string |
54 | 84 | */ |
55 | 85 | public static function labelForTask( $id ) { |
56 | | - return wfMsg( TranslateUtils::MSG . 'task-' . $id ); |
| 86 | + return wfMsg( 'translate-task-' . $id ); |
57 | 87 | } |
58 | 88 | |
| 89 | + /** |
| 90 | + * Get task identifier. |
| 91 | + * @return \string |
| 92 | + */ |
59 | 93 | public function getId() { |
60 | 94 | return $this->id; |
61 | 95 | } |
62 | 96 | |
| 97 | + /** |
| 98 | + * Indicates whether the task itself will hand the full output page. |
| 99 | + * If false, the result is embedded in the normal results page. |
| 100 | + * @return \bool |
| 101 | + */ |
63 | 102 | public function plainOutput() { |
64 | 103 | return false; |
65 | 104 | } |
66 | 105 | |
67 | | - protected $group = null; |
68 | | - protected $collection = null; |
69 | | - protected $options = null; |
| 106 | + protected $group; ///< \type{MessageGroup} Message group. |
| 107 | + protected $collection; ///< \type{MessageCollection} Messages. |
| 108 | + protected $options; ///< \type{TaskOptions} Options. |
70 | 109 | |
| 110 | + /** |
| 111 | + * Constructor. |
| 112 | + * @param $group \type{MessageGroup} Message group. |
| 113 | + * @param $options \type{TaskOptions} Options. |
| 114 | + */ |
71 | 115 | public final function init( MessageGroup $group, TaskOptions $options ) { |
72 | 116 | $this->group = $group; |
73 | 117 | $this->options = $options; |
74 | 118 | } |
75 | 119 | |
| 120 | + /** |
| 121 | + * Outputs the results. |
| 122 | + * @return \string |
| 123 | + */ |
76 | 124 | abstract protected function output(); |
77 | 125 | |
| 126 | + /// Processes messages before paging is done. |
| 127 | + abstract protected function preinit(); |
| 128 | + |
| 129 | + /// Processes messages after paging is done. |
| 130 | + abstract protected function postinit(); |
| 131 | + |
| 132 | + /** |
| 133 | + * Executes the task with given options and outputs the results. |
| 134 | + * @return \string Html. |
| 135 | + */ |
78 | 136 | public final function execute() { |
79 | 137 | $this->preinit(); |
80 | 138 | $this->doPaging(); |
— | — | @@ -82,6 +140,11 @@ |
83 | 141 | return $this->output(); |
84 | 142 | } |
85 | 143 | |
| 144 | + /** |
| 145 | + * Takes a slice of messages according to limit and offset given |
| 146 | + * in option at initialisation time. Calls the callback to provide |
| 147 | + * information how much messages there is. |
| 148 | + */ |
86 | 149 | protected function doPaging() { |
87 | 150 | $total = count( $this->collection ); |
88 | 151 | $this->collection->slice( |
— | — | @@ -96,7 +159,7 @@ |
97 | 160 | } |
98 | 161 | |
99 | 162 | /** |
100 | | - * @todo Needs documentation. |
| 163 | + * Lists all non-optional messages with translation if any. |
101 | 164 | */ |
102 | 165 | class ViewMessagesTask extends TranslateTask { |
103 | 166 | protected $id = 'view'; |
— | — | @@ -122,7 +185,7 @@ |
123 | 186 | } |
124 | 187 | |
125 | 188 | /** |
126 | | - * @todo Needs documentation. |
| 189 | + * List messages which has been changed since last export. |
127 | 190 | */ |
128 | 191 | class ReviewMessagesTask extends ViewMessagesTask { |
129 | 192 | protected $id = 'review'; |
— | — | @@ -146,7 +209,7 @@ |
147 | 210 | } |
148 | 211 | |
149 | 212 | /** |
150 | | - * @todo Needs documentation. |
| 213 | + * Lists untranslated non-optional messages. |
151 | 214 | */ |
152 | 215 | class ViewUntranslatedTask extends ReviewMessagesTask { |
153 | 216 | protected $id = 'untranslated'; |
— | — | @@ -158,9 +221,7 @@ |
159 | 222 | $this->collection->filter( 'ignored' ); |
160 | 223 | $this->collection->filter( 'optional' ); |
161 | 224 | |
162 | | - /** |
163 | | - * Update the cache while we are at it. |
164 | | - */ |
| 225 | + // Update the cache while we are at it. |
165 | 226 | $total = count( $this->collection ); |
166 | 227 | $this->collection->filter( 'translated' ); |
167 | 228 | $translated = $total - count( $this->collection ); |
— | — | @@ -172,7 +233,7 @@ |
173 | 234 | } |
174 | 235 | |
175 | 236 | /** |
176 | | - * @todo Needs documentation. |
| 237 | + * Lists optional messages. |
177 | 238 | */ |
178 | 239 | class ViewOptionalTask extends ViewMessagesTask { |
179 | 240 | protected $id = 'optional'; |
— | — | @@ -187,7 +248,8 @@ |
188 | 249 | } |
189 | 250 | |
190 | 251 | /** |
191 | | - * @todo Needs documentation. |
| 252 | + * Lists messages with good translation memory suggestions. |
| 253 | + * The number of results is limited by the speed of translation memory. |
192 | 254 | */ |
193 | 255 | class ViewWithSuggestionsTask extends ViewMessagesTask { |
194 | 256 | protected $id = 'suggestions'; |
— | — | @@ -211,9 +273,7 @@ |
212 | 274 | $start = time(); |
213 | 275 | |
214 | 276 | foreach ( $this->collection->keys() as $key => $_ ) { |
215 | | - /** |
216 | | - * Allow up to 10 seconds to search for suggestions. |
217 | | - */ |
| 277 | + // Allow up to 10 seconds to search for suggestions. |
218 | 278 | if ( time() - $start > 10 || TranslationHelpers::checkTranslationServiceFailure( 'tmserver' ) ) { |
219 | 279 | unset( $this->collection[$key] ); |
220 | 280 | continue; |
— | — | @@ -226,9 +286,7 @@ |
227 | 287 | if ( $suggestions !== false ) { |
228 | 288 | $suggestions = FormatJson::decode( $suggestions, true ); |
229 | 289 | foreach ( $suggestions as $s ) { |
230 | | - /** |
231 | | - * We have a good suggestion, do not filter. |
232 | | - */ |
| 290 | + // We have a good suggestion, do not filter. |
233 | 291 | if ( $s['quality'] > 0.80 ) { |
234 | 292 | continue 2; |
235 | 293 | } |
— | — | @@ -242,7 +300,7 @@ |
243 | 301 | } |
244 | 302 | |
245 | 303 | /** |
246 | | - * @todo Needs documentation. |
| 304 | + * Lists untranslated optional messages. |
247 | 305 | */ |
248 | 306 | class ViewUntranslatedOptionalTask extends ViewOptionalTask { |
249 | 307 | protected $id = 'untranslatedoptional'; |
— | — | @@ -258,7 +316,7 @@ |
259 | 317 | } |
260 | 318 | |
261 | 319 | /** |
262 | | - * @todo Needs documentation. |
| 320 | + * Lists all translations for reviewing. |
263 | 321 | */ |
264 | 322 | class ReviewAllMessagesTask extends ReviewMessagesTask { |
265 | 323 | protected $id = 'reviewall'; |
— | — | @@ -273,15 +331,13 @@ |
274 | 332 | } |
275 | 333 | |
276 | 334 | /** |
277 | | - * @todo Needs documentation. |
| 335 | + * Exports messages to their native format with embedded textarea. |
278 | 336 | */ |
279 | 337 | class ExportMessagesTask extends ViewMessagesTask { |
280 | 338 | protected $id = 'export'; |
281 | 339 | |
282 | | - /** |
283 | | - * N/A. |
284 | | - */ |
285 | | - protected function doPaging() { } |
| 340 | + // No paging should be done. |
| 341 | + protected function doPaging() {} |
286 | 342 | |
287 | 343 | public function output() { |
288 | 344 | if ( $this->group instanceof FileBasedMessageGroup ) { |
— | — | @@ -299,7 +355,7 @@ |
300 | 356 | } |
301 | 357 | |
302 | 358 | /** |
303 | | - * @todo Needs documentation. |
| 359 | + * Exports messages to their native format as whole page. |
304 | 360 | */ |
305 | 361 | class ExportToFileMessagesTask extends ExportMessagesTask { |
306 | 362 | protected $id = 'export-to-file'; |
— | — | @@ -322,7 +378,7 @@ |
323 | 379 | } |
324 | 380 | |
325 | 381 | /** |
326 | | - * @todo Needs documentation. |
| 382 | + * Exports messages to xliff format. |
327 | 383 | */ |
328 | 384 | class ExportToXliffMessagesTask extends ExportToFileMessagesTask { |
329 | 385 | protected $id = 'export-to-xliff'; |
— | — | @@ -334,7 +390,9 @@ |
335 | 391 | } |
336 | 392 | |
337 | 393 | /** |
338 | | - * @todo Needs documentation. |
| 394 | + * Exports messages as special Gettext format that is suitable for off-line |
| 395 | + * translation with tools that support Gettext. These files can later be |
| 396 | + * imported back to the wiki. |
339 | 397 | */ |
340 | 398 | class ExportAsPoMessagesTask extends ExportMessagesTask { |
341 | 399 | protected $id = 'export-as-po'; |
— | — | @@ -343,6 +401,7 @@ |
344 | 402 | return true; |
345 | 403 | } |
346 | 404 | |
| 405 | + /// @todo Encapsulate Gettext formatter. |
347 | 406 | public function output() { |
348 | 407 | global $wgServer, $wgTranslateDocumentationLanguageCode; |
349 | 408 | |
— | — | @@ -359,13 +418,9 @@ |
360 | 419 | |
361 | 420 | $headers = array(); |
362 | 421 | $headers['Project-Id-Version'] = 'MediaWiki ' . SpecialVersion::getVersion( 'nodb' ); |
363 | | - /** |
364 | | - * @todo Make this customisable or something. |
365 | | - */ |
| 422 | + /// @todo Make this customisable or something. |
366 | 423 | $headers['Report-Msgid-Bugs-To'] = $wgServer; |
367 | | - /** |
368 | | - * @todo sprintfDate does not support any time zone flags. |
369 | | - */ |
| 424 | + /// @todo Language::sprintfDate() does not support any time zone flags. |
370 | 425 | $headers['POT-Creation-Date'] = $lang->sprintfDate( 'xnY-xnm-xnd xnH:xni:xns+0000', $now ); |
371 | 426 | $headers['Language-Team'] = TranslateUtils::getLanguageName( $this->options->getLanguage() ); |
372 | 427 | $headers['Content-Type'] = 'text-plain; charset=UTF-8'; |
— | — | @@ -386,23 +441,17 @@ |
387 | 442 | $flags = array(); |
388 | 443 | |
389 | 444 | $translation = $m->translation(); |
390 | | - /** |
391 | | - * CASE2: no translation. |
392 | | - */ |
| 445 | + // CASE2: no translation. |
393 | 446 | if ( $translation === null ) { |
394 | 447 | $translation = ''; |
395 | 448 | } |
396 | 449 | |
397 | | - /** |
398 | | - * CASE3: optional messages; accept only if different. |
399 | | - */ |
| 450 | + // CASE3: optional messages; accept only if different. |
400 | 451 | if ( $m->hasTag( 'optional' ) ) { |
401 | 452 | $flags[] = 'optional'; |
402 | 453 | } |
403 | 454 | |
404 | | - /** |
405 | | - * Remove fuzzy markings before export. |
406 | | - */ |
| 455 | + // Remove fuzzy markings before export, use the fuzzy flag. |
407 | 456 | if ( strpos( $translation, TRANSLATE_FUZZY ) !== false ) { |
408 | 457 | $translation = str_replace( TRANSLATE_FUZZY, '', $translation ); |
409 | 458 | $flags[] = 'fuzzy'; |
— | — | @@ -475,15 +524,20 @@ |
476 | 525 | } |
477 | 526 | |
478 | 527 | /** |
479 | | - * @todo Needs documentation. |
| 528 | + * Collection of functions to get tasks. |
480 | 529 | */ |
481 | 530 | class TranslateTasks { |
| 531 | + |
| 532 | + /** |
| 533 | + * Return list of available tasks. |
| 534 | + * @param $pageTranslation Whether this group is page translation group. |
| 535 | + * @todo Make the above parameter a group and check its class? |
| 536 | + * @return \list{String} Task identifiers. |
| 537 | + */ |
482 | 538 | public static function getTasks( $pageTranslation = false ) { |
483 | 539 | global $wgTranslateTasks, $wgTranslateTranslationServices; |
484 | 540 | |
485 | | - /** |
486 | | - * Tasks not to be available in page translation. |
487 | | - */ |
| 541 | + // Tasks not to be available in page translation. |
488 | 542 | $filterTasks = array( |
489 | 543 | 'optional', |
490 | 544 | 'untranslatedoptional', |
— | — | @@ -509,6 +563,11 @@ |
510 | 564 | return $allTasks; |
511 | 565 | } |
512 | 566 | |
| 567 | + /** |
| 568 | + * Get task by id. |
| 569 | + * @param $id \string Task identifier. |
| 570 | + * @return \types{TranslateTask,Null} The task or null if no such task. |
| 571 | + */ |
513 | 572 | public static function getTask( $id ) { |
514 | 573 | global $wgTranslateTasks; |
515 | 574 | |