r72427 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72426‎ | r72427 | r72428 >
Date:13:58, 5 September 2010
Author:nikerabbit
Status:ok
Tags:
Comment:
Documentation updates. Now all files have a description.
Modified paths:
  • /trunk/extensions/Translate/SpecialManageGroups.php (modified) (history)
  • /trunk/extensions/Translate/SpecialTranslationStats.php (modified) (history)
  • /trunk/extensions/Translate/tag/MoveJob.php (modified) (history)
  • /trunk/extensions/Translate/tag/RenderJob.php (modified) (history)
  • /trunk/extensions/Translate/tag/TranslatablePage.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/SpecialManageGroups.php
@@ -4,6 +4,7 @@
55 * groups are be managed.
66 *
77 * @ingroup SpecialPage
 8+ * @file
89 * @author Niklas Laxström
910 * @author Siebrand Mazeland
1011 * @copyright Copyright © 2009-2010, Niklas Laxström, Siebrand Mazeland
Index: trunk/extensions/Translate/SpecialTranslationStats.php
@@ -1,7 +1,6 @@
22 <?php
33 /**
44 * Contains logic for special page Special:TranslationStats.
5 - * @defgroup Stats Statistics
65 *
76 * @file
87 * @author Niklas Laxström
@@ -10,10 +9,14 @@
1110 */
1211
1312 /**
 13+ * @defgroup Stats Statistics
 14+ * Collection of code to produce various kinds of statistics.
 15+ */
 16+
 17+/**
1418 * Includable special page for generating graphs on translations.
1519 *
1620 * @ingroup SpecialPage TranslateSpecialPage Stats
17 - * @todo Needs documentation.
1821 */
1922 class SpecialTranslationStats extends IncludableSpecialPage {
2023 public function __construct() {
@@ -103,7 +106,11 @@
104107 }
105108 }
106109
107 - protected function form( $opts ) {
 110+ /**
 111+ * Constructs the form which can be used to generate custom graphs.
 112+ * @param $opts FormOptions
 113+ */
 114+ protected function form( FormOptions $opts ) {
108115 global $wgOut, $wgScript;
109116
110117 $this->setHeaders();
@@ -173,6 +180,12 @@
174181 );
175182 }
176183
 184+ /**
 185+ * Constructs a table row with label and input in two columns.
 186+ * @param $name \string Option name.
 187+ * @param $opts FormOptions
 188+ * @return \string Html.
 189+ */
177190 protected function eInput( $name, FormOptions $opts ) {
178191 $value = $opts[$name];
179192
@@ -182,6 +195,11 @@
183196 '</td></tr>' . "\n";
184197 }
185198
 199+ /**
 200+ * Constructs a label for option.
 201+ * @param $name \string Option name.
 202+ * @return \string Html.
 203+ */
186204 protected function eLabel( $name ) {
187205 $label = 'translate-statsf-' . $name;
188206 $label = wfMsgExt( $label, array( 'parsemag', 'escapenoentities' ) );
@@ -189,6 +207,13 @@
190208 return Xml::tags( 'label', array( 'for' => $name ), $label );
191209 }
192210
 211+ /**
 212+ * Constructs a table row with label and radio input in two columns.
 213+ * @param $name Option name.
 214+ * @param $opts FormOptions
 215+ * @param $alts \list{String} List of alternatives.
 216+ * @return \string Html.
 217+ */
193218 protected function eRadio( $name, FormOptions $opts, array $alts ) {
194219 $label = 'translate-statsf-' . $name;
195220 $label = wfMsgExt( $label, array( 'parsemag', 'escapenoentities' ) );
@@ -208,6 +233,12 @@
209234 return $s;
210235 }
211236
 237+ /**
 238+ * Constructs a table row with label and language selector in two columns.
 239+ * @param $name \string Option name.
 240+ * @param $opts FormOptions
 241+ * @return \string Html.
 242+ */
212243 protected function eLanguage( $name, FormOptions $opts ) {
213244 $value = $opts[$name];
214245
@@ -221,6 +252,10 @@
222253 '</td></tr>' . "\n";
223254 }
224255
 256+ /**
 257+ * Constructs a JavaScript enhanced language selector.
 258+ * @return \type{JsSelectToInput}
 259+ */
225260 protected function languageSelector() {
226261 global $wgLang;
227262 if ( is_callable( array( 'LanguageNames', 'getNames' ) ) ) {
@@ -244,6 +279,12 @@
245280 return $jsSelect;
246281 }
247282
 283+ /**
 284+ * Constructs a table row with label and group selector in two columns.
 285+ * @param $name \string Option name.
 286+ * @param $opts FormOptions
 287+ * @return \string Html.
 288+ */
248289 protected function eGroup( $name, FormOptions $opts ) {
249290 $value = $opts[$name];
250291
@@ -257,6 +298,10 @@
258299 '</td></tr>' . "\n";
259300 }
260301
 302+ /**
 303+ * Constructs a JavaScript enhanced group selector.
 304+ * @return \type{JsSelectToInput}
 305+ */
261306 protected function groupSelector() {
262307 $groups = MessageGroups::singleton()->getGroups();
263308 foreach ( $groups as $key => $group ) {
@@ -279,7 +324,12 @@
280325 return $jsSelect;
281326 }
282327
283 - protected function image( $opts ) {
 328+ /**
 329+ * Returns an \<img> tag for graph.
 330+ * @param $opts FormOptions
 331+ * @return \string Html.
 332+ */
 333+ protected function image( FormOptions $opts ) {
284334 $title = $this->getTitle();
285335 $cgiparams = wfArrayToCgi( array( 'graphit' => true ), $opts->getAllValues() );
286336 $href = $title->getLocalUrl( $cgiparams );
@@ -293,6 +343,11 @@
294344 );
295345 }
296346
 347+ /**
 348+ * Fetches and preprocesses graph data that can be fed to graph drawer.
 349+ * @param $opts FormOptions
 350+ * @return \arrayof{String,Array} Data indexed by their date labels.
 351+ */
297352 protected function getData( FormOptions $opts ) {
298353 global $wgLang;
299354 $dbr = wfGetDB( DB_SLAVE );
@@ -389,6 +444,10 @@
390445 return array( $labels, $data );
391446 }
392447
 448+ /**
 449+ * Adds raw image data of the graph to the output.
 450+ * @param $opts FormOptions
 451+ */
393452 public function draw( FormOptions $opts ) {
394453 global $wgTranslatePHPlotFont, $wgLang;
395454
@@ -466,6 +525,18 @@
467526 $plot->DrawGraph();
468527 }
469528
 529+ /**
 530+ * Enhanced version of round that supports rounding up to a given scale
 531+ * relative to the number itself. Examples:
 532+ * - roundToSignificant( 1234, 0 ) = 10000
 533+ * - roundToSignificant( 1234, 1 ) = 2000
 534+ * - roundToSignificant( 1234, 2 ) = 1300
 535+ * - roundToSignificant( 1234, 3 ) = 1240
 536+ *
 537+ * @param $number \int Number to round.
 538+ * @param $significant \int How many signficant numbers to keep.
 539+ * @return \int Rounded number.
 540+ */
470541 public static function roundToSignificant( $number, $significant = 1 ) {
471542 $log = (int) log( $number, 10 );
472543 $nonSignificant = max( 0, $log - $significant + 1 );
@@ -473,6 +544,14 @@
474545 return intval( ceil( $number / $factor ) * $factor );
475546 }
476547
 548+ /**
 549+ * Returns an increment in seconds for a given scale.
 550+ * The increment must be small enough that we will hit every item in the
 551+ * scale when using different multiples of the increment. It should be
 552+ * large enough to avoid hitting the same item multiple times.
 553+ * @param $scale \string Either months, weeks, days or hours.
 554+ * @return \int Number of seconds in the increment.
 555+ */
477556 public static function getIncrement( $scale ) {
478557 $increment = 3600 * 24;
479558 if ( $scale === 'months' ) {
@@ -490,24 +569,65 @@
491570 }
492571
493572 /**
494 - * @todo Needs documentation.
 573+ * Interface for producing different kinds of graphs.
 574+ * The graphs are based on data queried from the database.
 575+ * @ingroup Stats
495576 */
496577 interface TranslationStatsInterface {
 578+ /**
 579+ * Constructor. The implementation can access the graph options, but not
 580+ * define new ones.
 581+ * @param $opts FormOptions
 582+ */
497583 public function __construct( FormOptions $opts );
 584+
 585+ /**
 586+ * Query details that the graph must fill.
 587+ * @param $tables \array Empty list. Append table names.
 588+ * @param $fields \array Empty list. Append field names.
 589+ * @param $conds \array Empty array. Append select conditions.
 590+ * @param $type \string Append graph type (used to identify queries).
 591+ * @param $options \array Empty array. Append extra query options.
 592+ * @param $cutoff \string Precalculated cutoff timestamp in unix format.
 593+ */
498594 public function preQuery( &$tables, &$fields, &$conds, &$type, &$options, $cutoff );
 595+
 596+ /**
 597+ * Return the indexes which this result contributes to.
 598+ * Return 'all' if only one variable is measured. Return false if none.
 599+ * @param $row \type{Database Result Row}
 600+ */
499601 public function indexOf( $row );
 602+
 603+ /**
 604+ * Return the names of the variables being measured.
 605+ * Return 'all' if only one variable is measured. Must match indexes
 606+ * returned by indexOf() and contain them all.
 607+ * @return \list{String}
 608+ */
500609 public function labels();
 610+
 611+ /**
 612+ * Return the timestamp associated with this result row.
 613+ * @param $row \type{Database Result Row}
 614+ * @return \string Timestamp.
 615+ */
501616 public function getTimestamp( $row );
 617+
 618+ /**
 619+ * Return time formatting string.
 620+ * @see Language::sprintfDate()
 621+ * @return \string
 622+ */
502623 public function getDateFormat();
503624 }
504625
505626 /**
506 - * @todo Needs documentation.
 627+ * Provides some hand default implementations for TranslationStatsInterface.
 628+ * @ingroup Stats
507629 */
508630 abstract class TranslationStatsBase implements TranslationStatsInterface {
509 - /**
510 - * FormOptions
511 - */
 631+ /// \type{FormOptions} Graph options.
512632 protected $opts;
513633
514634 public function __construct( FormOptions $opts ) {
@@ -537,16 +657,16 @@
538658 }
539659
540660 /**
541 - * @todo Needs documentation.
 661+ * Graph which provides statistics on active users and number of translations.
 662+ * @ingroup Stats
542663 */
543664 class TranslatePerLanguageStats extends TranslationStatsBase {
 665+ /// \arrayof{String,\bool} Cache used to count active users only once per day.
544666 protected $usercache;
545667
546668 public function __construct( FormOptions $opts ) {
547669 parent::__construct( $opts );
548 - /**
549 - * This query is slow... ensure a slower limit.
550 - */
 670+ // This query is slow... ensure a lower limit.
551671 $opts->validateIntBounds( 'days', 1, 200 );
552672 }
553673
@@ -607,9 +727,7 @@
608728 }
609729
610730 public function indexOf( $row ) {
611 - /**
612 - * We need to check that there is only one user per day.
613 - */
 731+ // We need to check that there is only one user per day.
614732 if ( $this->opts['count'] === 'users' ) {
615733 $date = $this->formatTimestamp( $row->rc_timestamp );
616734
@@ -620,30 +738,24 @@
621739 }
622740 }
623741
624 - /**
625 - * Do not consider language-less pages.
626 - */
 742+ // Do not consider language-less pages.
627743 if ( strpos( $row->rc_title, '/' ) === false ) {
628744 return false;
629745 }
630746
631 - /**
632 - * No filters, just one key to track.
633 - */
 747+ // No filters, just one key to track.
634748 if ( !$this->groups && !$this->codes ) {
635749 return 'all';
636750 }
637751
638 - /**
639 - * The key-building needs to be in sync with ::labels().
640 - */
 752+ // The key-building needs to be in sync with ::labels().
641753 list( $key, $code ) = TranslateUtils::figureMessage( $row->rc_title );
642754
643755 $groups = array();
644756 $codes = array();
645757
646758 if ( $this->groups ) {
647 - /**
 759+ /*
648760 * Get list of keys that the message belongs to, and filter
649761 * out those which are not requested.
650762 */
@@ -666,6 +778,13 @@
667779 return $row->rc_timestamp;
668780 }
669781
 782+ /**
 783+ * Makes a label for variable. If group or language code filters, or both
 784+ * are used, combine those in a pretty way.
 785+ * @param $group \string Group name.
 786+ * @param $code \string Language code.
 787+ * @return \string Label.
 788+ */
670789 protected function makeLabel( $group, $code ) {
671790 if ( $code ) {
672791 global $wgLang;
@@ -681,6 +800,13 @@
682801 }
683802 }
684803
 804+ /**
 805+ * Cross-product of two lists with string results, where either
 806+ * list can be empty.
 807+ * @param $groups \list{String} Group names.
 808+ * @param $codes \list{String} Language codes.
 809+ * @return \list{String} Labels.
 810+ */
685811 protected function combineTwoArrays( $groups, $codes ) {
686812 if ( !count( $groups ) ) {
687813 $groups[] = false;
@@ -699,6 +825,12 @@
700826 return $items;
701827 }
702828
 829+ /**
 830+ * Returns unique index for given item in the scale being used.
 831+ * Called a lot, so performance intensive.
 832+ * @param $timestamp \string Timestamp in mediawiki format.
 833+ * @return \string
 834+ */
703835 protected function formatTimestamp( $timestamp ) {
704836 global $wgContLang;
705837
@@ -721,7 +853,8 @@
722854 }
723855
724856 /**
725 - * @todo Needs documentation.
 857+ * Graph which provides statistics about amount of registered users in a given time.
 858+ * @ingroup Stats
726859 */
727860 class TranslateRegistrationStats extends TranslationStatsBase {
728861 public function preQuery( &$tables, &$fields, &$conds, &$type, &$options, $cutoff ) {
Index: trunk/extensions/Translate/tag/TranslatablePage.php
@@ -1,7 +1,7 @@
22 <?php
33 /**
44 * Translatable page model.
5 - * @defgroup PageTranslation Page Translation
 5+ *
66 * @file
77 * @author Niklas Laxström
88 * @copyright Copyright © 2009-2010 Niklas Laxström
Index: trunk/extensions/Translate/tag/RenderJob.php
@@ -2,17 +2,17 @@
33 /**
44 * Job for updating translation pages.
55 *
6 - * @ingroup Extensions
7 - *
 6+ * @file
87 * @author Niklas Laxström
9 - * @copyright Copyright © 2008-2009, Niklas Laxström
 8+ * @copyright Copyright © 2008-2010, Niklas Laxström
109 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
1110 */
1211
1312 /**
14 - * @todo Needs documentation.
15 - * @ingroup PageTranslation
 13+ * Job for updating translation pages when translation or template changes.
1614 */
 15+ * @ingroup PageTranslation JobQueue
 16+ */
1717 class RenderJob extends Job {
1818 public static function newJob( Title $target ) {
1919 global $wgTranslateFuzzyBotName;
Index: trunk/extensions/Translate/tag/MoveJob.php
@@ -11,7 +11,7 @@
1212 /**
1313 * Contains class with job for moving translation pages.
1414 *
15 - * @ingroup PageTranslation
 15+ * @ingroup PageTranslation JobQueue
1616 * @todo Get rid of direct reference to $wgMemc.
1717 */
1818 class MoveJob extends Job {

Status & tagging log