r72161 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72160‎ | r72161 | r72162 >
Date:20:17, 1 September 2010
Author:nikerabbit
Status:ok
Tags:
Comment:
Documentation updates
Modified paths:
  • /trunk/extensions/Translate/TranslateTasks.php (modified) (history)
  • /trunk/extensions/Translate/scripts/populateFuzzy.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/scripts/populateFuzzy.php
@@ -1,14 +1,15 @@
22 <?php
33 /**
4 - * A script to populate fuzzy tags.
 4+ * A script to populate fuzzy tags to revtag table.
55 *
66 * @author Niklas Laxstrom
7 - *
8 - * @copyright Copyright © 2009, Niklas Laxström
 7+ * @copyright Copyright © 2009-2010, Niklas Laxström
98 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
109 * @file
1110 */
1211
 12+/// @cond
 13+
1314 require( dirname( __FILE__ ) . '/cli.inc' );
1415
1516 $db = wfGetDB( DB_MASTER );
@@ -60,3 +61,5 @@
6162
6263 $db->replace( 'revtag', 'rt_type_page_revision', $inserts, __METHOD__ );
6364 }
 65+
 66+/// @endcond
Index: trunk/extensions/Translate/TranslateTasks.php
@@ -5,7 +5,7 @@
66 *
77 * @file
88 * @author Niklas Laxström
9 - * @copyright Copyright © 2007-2008 Niklas Laxström
 9+ * @copyright Copyright © 2007-2010 Niklas Laxström
1010 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
1111 */
1212
@@ -13,11 +13,23 @@
1414 * Container for options that are passed to tasks.
1515 */
1616 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;
2125
 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+ */
2234 public function __construct( $language, $limit = 0, $offset = 0, $pagingCB = null ) {
2335 $this->language = $language;
2436 $this->limit = $limit;
@@ -25,55 +37,101 @@
2638 $this->pagingCB = $pagingCB;
2739 }
2840
 41+ /**
 42+ * @return \string Language code.
 43+ */
2944 public function getLanguage() {
3045 return $this->language;
3146 }
3247
 48+ /**
 49+ * @return \int Number of items to show.
 50+ */
3351 public function getLimit() {
3452 return $this->limit;
3553 }
3654
 55+ /**
 56+ * @return \int Offset to the results.
 57+ */
3758 public function getOffset() {
3859 return $this->offset;
3960 }
4061
 62+ /**
 63+ * @return \mixed Callback which is called to provide information about the result counts.
 64+ */
4165 public function getPagingCB() {
4266 return $this->pagingCB;
4367 }
4468 }
4569
4670 /**
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.
4874 */
4975 abstract class TranslateTask {
 76+ /// \string Task identifier.
5077 protected $id = '__BUG__';
5178
 79+ // We need $id here because staticness prevents subclass overriding.
5280 /**
53 - * We need $id here because staticness prevents subclass overriding.
 81+ * Get label for task.
 82+ * @param $id \string.
 83+ * @return \string
5484 */
5585 public static function labelForTask( $id ) {
56 - return wfMsg( TranslateUtils::MSG . 'task-' . $id );
 86+ return wfMsg( 'translate-task-' . $id );
5787 }
5888
 89+ /**
 90+ * Get task identifier.
 91+ * @return \string
 92+ */
5993 public function getId() {
6094 return $this->id;
6195 }
6296
 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+ */
63102 public function plainOutput() {
64103 return false;
65104 }
66105
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.
70109
 110+ /**
 111+ * Constructor.
 112+ * @param $group \type{MessageGroup} Message group.
 113+ * @param $options \type{TaskOptions} Options.
 114+ */
71115 public final function init( MessageGroup $group, TaskOptions $options ) {
72116 $this->group = $group;
73117 $this->options = $options;
74118 }
75119
 120+ /**
 121+ * Outputs the results.
 122+ * @return \string
 123+ */
76124 abstract protected function output();
77125
 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+ */
78136 public final function execute() {
79137 $this->preinit();
80138 $this->doPaging();
@@ -82,6 +140,11 @@
83141 return $this->output();
84142 }
85143
 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+ */
86149 protected function doPaging() {
87150 $total = count( $this->collection );
88151 $this->collection->slice(
@@ -96,7 +159,7 @@
97160 }
98161
99162 /**
100 - * @todo Needs documentation.
 163+ * Lists all non-optional messages with translation if any.
101164 */
102165 class ViewMessagesTask extends TranslateTask {
103166 protected $id = 'view';
@@ -122,7 +185,7 @@
123186 }
124187
125188 /**
126 - * @todo Needs documentation.
 189+ * List messages which has been changed since last export.
127190 */
128191 class ReviewMessagesTask extends ViewMessagesTask {
129192 protected $id = 'review';
@@ -146,7 +209,7 @@
147210 }
148211
149212 /**
150 - * @todo Needs documentation.
 213+ * Lists untranslated non-optional messages.
151214 */
152215 class ViewUntranslatedTask extends ReviewMessagesTask {
153216 protected $id = 'untranslated';
@@ -158,9 +221,7 @@
159222 $this->collection->filter( 'ignored' );
160223 $this->collection->filter( 'optional' );
161224
162 - /**
163 - * Update the cache while we are at it.
164 - */
 225+ // Update the cache while we are at it.
165226 $total = count( $this->collection );
166227 $this->collection->filter( 'translated' );
167228 $translated = $total - count( $this->collection );
@@ -172,7 +233,7 @@
173234 }
174235
175236 /**
176 - * @todo Needs documentation.
 237+ * Lists optional messages.
177238 */
178239 class ViewOptionalTask extends ViewMessagesTask {
179240 protected $id = 'optional';
@@ -187,7 +248,8 @@
188249 }
189250
190251 /**
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.
192254 */
193255 class ViewWithSuggestionsTask extends ViewMessagesTask {
194256 protected $id = 'suggestions';
@@ -211,9 +273,7 @@
212274 $start = time();
213275
214276 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.
218278 if ( time() - $start > 10 || TranslationHelpers::checkTranslationServiceFailure( 'tmserver' ) ) {
219279 unset( $this->collection[$key] );
220280 continue;
@@ -226,9 +286,7 @@
227287 if ( $suggestions !== false ) {
228288 $suggestions = FormatJson::decode( $suggestions, true );
229289 foreach ( $suggestions as $s ) {
230 - /**
231 - * We have a good suggestion, do not filter.
232 - */
 290+ // We have a good suggestion, do not filter.
233291 if ( $s['quality'] > 0.80 ) {
234292 continue 2;
235293 }
@@ -242,7 +300,7 @@
243301 }
244302
245303 /**
246 - * @todo Needs documentation.
 304+ * Lists untranslated optional messages.
247305 */
248306 class ViewUntranslatedOptionalTask extends ViewOptionalTask {
249307 protected $id = 'untranslatedoptional';
@@ -258,7 +316,7 @@
259317 }
260318
261319 /**
262 - * @todo Needs documentation.
 320+ * Lists all translations for reviewing.
263321 */
264322 class ReviewAllMessagesTask extends ReviewMessagesTask {
265323 protected $id = 'reviewall';
@@ -273,15 +331,13 @@
274332 }
275333
276334 /**
277 - * @todo Needs documentation.
 335+ * Exports messages to their native format with embedded textarea.
278336 */
279337 class ExportMessagesTask extends ViewMessagesTask {
280338 protected $id = 'export';
281339
282 - /**
283 - * N/A.
284 - */
285 - protected function doPaging() { }
 340+ // No paging should be done.
 341+ protected function doPaging() {}
286342
287343 public function output() {
288344 if ( $this->group instanceof FileBasedMessageGroup ) {
@@ -299,7 +355,7 @@
300356 }
301357
302358 /**
303 - * @todo Needs documentation.
 359+ * Exports messages to their native format as whole page.
304360 */
305361 class ExportToFileMessagesTask extends ExportMessagesTask {
306362 protected $id = 'export-to-file';
@@ -322,7 +378,7 @@
323379 }
324380
325381 /**
326 - * @todo Needs documentation.
 382+ * Exports messages to xliff format.
327383 */
328384 class ExportToXliffMessagesTask extends ExportToFileMessagesTask {
329385 protected $id = 'export-to-xliff';
@@ -334,7 +390,9 @@
335391 }
336392
337393 /**
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.
339397 */
340398 class ExportAsPoMessagesTask extends ExportMessagesTask {
341399 protected $id = 'export-as-po';
@@ -343,6 +401,7 @@
344402 return true;
345403 }
346404
 405+ /// @todo Encapsulate Gettext formatter.
347406 public function output() {
348407 global $wgServer, $wgTranslateDocumentationLanguageCode;
349408
@@ -359,13 +418,9 @@
360419
361420 $headers = array();
362421 $headers['Project-Id-Version'] = 'MediaWiki ' . SpecialVersion::getVersion( 'nodb' );
363 - /**
364 - * @todo Make this customisable or something.
365 - */
 422+ /// @todo Make this customisable or something.
366423 $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.
370425 $headers['POT-Creation-Date'] = $lang->sprintfDate( 'xnY-xnm-xnd xnH:xni:xns+0000', $now );
371426 $headers['Language-Team'] = TranslateUtils::getLanguageName( $this->options->getLanguage() );
372427 $headers['Content-Type'] = 'text-plain; charset=UTF-8';
@@ -386,23 +441,17 @@
387442 $flags = array();
388443
389444 $translation = $m->translation();
390 - /**
391 - * CASE2: no translation.
392 - */
 445+ // CASE2: no translation.
393446 if ( $translation === null ) {
394447 $translation = '';
395448 }
396449
397 - /**
398 - * CASE3: optional messages; accept only if different.
399 - */
 450+ // CASE3: optional messages; accept only if different.
400451 if ( $m->hasTag( 'optional' ) ) {
401452 $flags[] = 'optional';
402453 }
403454
404 - /**
405 - * Remove fuzzy markings before export.
406 - */
 455+ // Remove fuzzy markings before export, use the fuzzy flag.
407456 if ( strpos( $translation, TRANSLATE_FUZZY ) !== false ) {
408457 $translation = str_replace( TRANSLATE_FUZZY, '', $translation );
409458 $flags[] = 'fuzzy';
@@ -475,15 +524,20 @@
476525 }
477526
478527 /**
479 - * @todo Needs documentation.
 528+ * Collection of functions to get tasks.
480529 */
481530 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+ */
482538 public static function getTasks( $pageTranslation = false ) {
483539 global $wgTranslateTasks, $wgTranslateTranslationServices;
484540
485 - /**
486 - * Tasks not to be available in page translation.
487 - */
 541+ // Tasks not to be available in page translation.
488542 $filterTasks = array(
489543 'optional',
490544 'untranslatedoptional',
@@ -509,6 +563,11 @@
510564 return $allTasks;
511565 }
512566
 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+ */
513572 public static function getTask( $id ) {
514573 global $wgTranslateTasks;
515574

Status & tagging log