Index: trunk/extensions/Translate/SpecialManageGroups.php |
— | — | @@ -4,6 +4,7 @@ |
5 | 5 | * groups are be managed. |
6 | 6 | * |
7 | 7 | * @ingroup SpecialPage |
| 8 | + * @file |
8 | 9 | * @author Niklas Laxström |
9 | 10 | * @author Siebrand Mazeland |
10 | 11 | * @copyright Copyright © 2009-2010, Niklas Laxström, Siebrand Mazeland |
Index: trunk/extensions/Translate/SpecialTranslationStats.php |
— | — | @@ -1,7 +1,6 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | 4 | * Contains logic for special page Special:TranslationStats. |
5 | | - * @defgroup Stats Statistics |
6 | 5 | * |
7 | 6 | * @file |
8 | 7 | * @author Niklas Laxström |
— | — | @@ -10,10 +9,14 @@ |
11 | 10 | */ |
12 | 11 | |
13 | 12 | /** |
| 13 | + * @defgroup Stats Statistics |
| 14 | + * Collection of code to produce various kinds of statistics. |
| 15 | + */ |
| 16 | + |
| 17 | +/** |
14 | 18 | * Includable special page for generating graphs on translations. |
15 | 19 | * |
16 | 20 | * @ingroup SpecialPage TranslateSpecialPage Stats |
17 | | - * @todo Needs documentation. |
18 | 21 | */ |
19 | 22 | class SpecialTranslationStats extends IncludableSpecialPage { |
20 | 23 | public function __construct() { |
— | — | @@ -103,7 +106,11 @@ |
104 | 107 | } |
105 | 108 | } |
106 | 109 | |
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 ) { |
108 | 115 | global $wgOut, $wgScript; |
109 | 116 | |
110 | 117 | $this->setHeaders(); |
— | — | @@ -173,6 +180,12 @@ |
174 | 181 | ); |
175 | 182 | } |
176 | 183 | |
| 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 | + */ |
177 | 190 | protected function eInput( $name, FormOptions $opts ) { |
178 | 191 | $value = $opts[$name]; |
179 | 192 | |
— | — | @@ -182,6 +195,11 @@ |
183 | 196 | '</td></tr>' . "\n"; |
184 | 197 | } |
185 | 198 | |
| 199 | + /** |
| 200 | + * Constructs a label for option. |
| 201 | + * @param $name \string Option name. |
| 202 | + * @return \string Html. |
| 203 | + */ |
186 | 204 | protected function eLabel( $name ) { |
187 | 205 | $label = 'translate-statsf-' . $name; |
188 | 206 | $label = wfMsgExt( $label, array( 'parsemag', 'escapenoentities' ) ); |
— | — | @@ -189,6 +207,13 @@ |
190 | 208 | return Xml::tags( 'label', array( 'for' => $name ), $label ); |
191 | 209 | } |
192 | 210 | |
| 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 | + */ |
193 | 218 | protected function eRadio( $name, FormOptions $opts, array $alts ) { |
194 | 219 | $label = 'translate-statsf-' . $name; |
195 | 220 | $label = wfMsgExt( $label, array( 'parsemag', 'escapenoentities' ) ); |
— | — | @@ -208,6 +233,12 @@ |
209 | 234 | return $s; |
210 | 235 | } |
211 | 236 | |
| 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 | + */ |
212 | 243 | protected function eLanguage( $name, FormOptions $opts ) { |
213 | 244 | $value = $opts[$name]; |
214 | 245 | |
— | — | @@ -221,6 +252,10 @@ |
222 | 253 | '</td></tr>' . "\n"; |
223 | 254 | } |
224 | 255 | |
| 256 | + /** |
| 257 | + * Constructs a JavaScript enhanced language selector. |
| 258 | + * @return \type{JsSelectToInput} |
| 259 | + */ |
225 | 260 | protected function languageSelector() { |
226 | 261 | global $wgLang; |
227 | 262 | if ( is_callable( array( 'LanguageNames', 'getNames' ) ) ) { |
— | — | @@ -244,6 +279,12 @@ |
245 | 280 | return $jsSelect; |
246 | 281 | } |
247 | 282 | |
| 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 | + */ |
248 | 289 | protected function eGroup( $name, FormOptions $opts ) { |
249 | 290 | $value = $opts[$name]; |
250 | 291 | |
— | — | @@ -257,6 +298,10 @@ |
258 | 299 | '</td></tr>' . "\n"; |
259 | 300 | } |
260 | 301 | |
| 302 | + /** |
| 303 | + * Constructs a JavaScript enhanced group selector. |
| 304 | + * @return \type{JsSelectToInput} |
| 305 | + */ |
261 | 306 | protected function groupSelector() { |
262 | 307 | $groups = MessageGroups::singleton()->getGroups(); |
263 | 308 | foreach ( $groups as $key => $group ) { |
— | — | @@ -279,7 +324,12 @@ |
280 | 325 | return $jsSelect; |
281 | 326 | } |
282 | 327 | |
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 ) { |
284 | 334 | $title = $this->getTitle(); |
285 | 335 | $cgiparams = wfArrayToCgi( array( 'graphit' => true ), $opts->getAllValues() ); |
286 | 336 | $href = $title->getLocalUrl( $cgiparams ); |
— | — | @@ -293,6 +343,11 @@ |
294 | 344 | ); |
295 | 345 | } |
296 | 346 | |
| 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 | + */ |
297 | 352 | protected function getData( FormOptions $opts ) { |
298 | 353 | global $wgLang; |
299 | 354 | $dbr = wfGetDB( DB_SLAVE ); |
— | — | @@ -389,6 +444,10 @@ |
390 | 445 | return array( $labels, $data ); |
391 | 446 | } |
392 | 447 | |
| 448 | + /** |
| 449 | + * Adds raw image data of the graph to the output. |
| 450 | + * @param $opts FormOptions |
| 451 | + */ |
393 | 452 | public function draw( FormOptions $opts ) { |
394 | 453 | global $wgTranslatePHPlotFont, $wgLang; |
395 | 454 | |
— | — | @@ -466,6 +525,18 @@ |
467 | 526 | $plot->DrawGraph(); |
468 | 527 | } |
469 | 528 | |
| 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 | + */ |
470 | 541 | public static function roundToSignificant( $number, $significant = 1 ) { |
471 | 542 | $log = (int) log( $number, 10 ); |
472 | 543 | $nonSignificant = max( 0, $log - $significant + 1 ); |
— | — | @@ -473,6 +544,14 @@ |
474 | 545 | return intval( ceil( $number / $factor ) * $factor ); |
475 | 546 | } |
476 | 547 | |
| 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 | + */ |
477 | 556 | public static function getIncrement( $scale ) { |
478 | 557 | $increment = 3600 * 24; |
479 | 558 | if ( $scale === 'months' ) { |
— | — | @@ -490,24 +569,65 @@ |
491 | 570 | } |
492 | 571 | |
493 | 572 | /** |
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 |
495 | 576 | */ |
496 | 577 | interface TranslationStatsInterface { |
| 578 | + /** |
| 579 | + * Constructor. The implementation can access the graph options, but not |
| 580 | + * define new ones. |
| 581 | + * @param $opts FormOptions |
| 582 | + */ |
497 | 583 | 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 | + */ |
498 | 594 | 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 | + */ |
499 | 601 | 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 | + */ |
500 | 609 | 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 | + */ |
501 | 616 | public function getTimestamp( $row ); |
| 617 | + |
| 618 | + /** |
| 619 | + * Return time formatting string. |
| 620 | + * @see Language::sprintfDate() |
| 621 | + * @return \string |
| 622 | + */ |
502 | 623 | public function getDateFormat(); |
503 | 624 | } |
504 | 625 | |
505 | 626 | /** |
506 | | - * @todo Needs documentation. |
| 627 | + * Provides some hand default implementations for TranslationStatsInterface. |
| 628 | + * @ingroup Stats |
507 | 629 | */ |
508 | 630 | abstract class TranslationStatsBase implements TranslationStatsInterface { |
509 | | - /** |
510 | | - * FormOptions |
511 | | - */ |
| 631 | + /// \type{FormOptions} Graph options. |
512 | 632 | protected $opts; |
513 | 633 | |
514 | 634 | public function __construct( FormOptions $opts ) { |
— | — | @@ -537,16 +657,16 @@ |
538 | 658 | } |
539 | 659 | |
540 | 660 | /** |
541 | | - * @todo Needs documentation. |
| 661 | + * Graph which provides statistics on active users and number of translations. |
| 662 | + * @ingroup Stats |
542 | 663 | */ |
543 | 664 | class TranslatePerLanguageStats extends TranslationStatsBase { |
| 665 | + /// \arrayof{String,\bool} Cache used to count active users only once per day. |
544 | 666 | protected $usercache; |
545 | 667 | |
546 | 668 | public function __construct( FormOptions $opts ) { |
547 | 669 | parent::__construct( $opts ); |
548 | | - /** |
549 | | - * This query is slow... ensure a slower limit. |
550 | | - */ |
| 670 | + // This query is slow... ensure a lower limit. |
551 | 671 | $opts->validateIntBounds( 'days', 1, 200 ); |
552 | 672 | } |
553 | 673 | |
— | — | @@ -607,9 +727,7 @@ |
608 | 728 | } |
609 | 729 | |
610 | 730 | 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. |
614 | 732 | if ( $this->opts['count'] === 'users' ) { |
615 | 733 | $date = $this->formatTimestamp( $row->rc_timestamp ); |
616 | 734 | |
— | — | @@ -620,30 +738,24 @@ |
621 | 739 | } |
622 | 740 | } |
623 | 741 | |
624 | | - /** |
625 | | - * Do not consider language-less pages. |
626 | | - */ |
| 742 | + // Do not consider language-less pages. |
627 | 743 | if ( strpos( $row->rc_title, '/' ) === false ) { |
628 | 744 | return false; |
629 | 745 | } |
630 | 746 | |
631 | | - /** |
632 | | - * No filters, just one key to track. |
633 | | - */ |
| 747 | + // No filters, just one key to track. |
634 | 748 | if ( !$this->groups && !$this->codes ) { |
635 | 749 | return 'all'; |
636 | 750 | } |
637 | 751 | |
638 | | - /** |
639 | | - * The key-building needs to be in sync with ::labels(). |
640 | | - */ |
| 752 | + // The key-building needs to be in sync with ::labels(). |
641 | 753 | list( $key, $code ) = TranslateUtils::figureMessage( $row->rc_title ); |
642 | 754 | |
643 | 755 | $groups = array(); |
644 | 756 | $codes = array(); |
645 | 757 | |
646 | 758 | if ( $this->groups ) { |
647 | | - /** |
| 759 | + /* |
648 | 760 | * Get list of keys that the message belongs to, and filter |
649 | 761 | * out those which are not requested. |
650 | 762 | */ |
— | — | @@ -666,6 +778,13 @@ |
667 | 779 | return $row->rc_timestamp; |
668 | 780 | } |
669 | 781 | |
| 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 | + */ |
670 | 789 | protected function makeLabel( $group, $code ) { |
671 | 790 | if ( $code ) { |
672 | 791 | global $wgLang; |
— | — | @@ -681,6 +800,13 @@ |
682 | 801 | } |
683 | 802 | } |
684 | 803 | |
| 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 | + */ |
685 | 811 | protected function combineTwoArrays( $groups, $codes ) { |
686 | 812 | if ( !count( $groups ) ) { |
687 | 813 | $groups[] = false; |
— | — | @@ -699,6 +825,12 @@ |
700 | 826 | return $items; |
701 | 827 | } |
702 | 828 | |
| 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 | + */ |
703 | 835 | protected function formatTimestamp( $timestamp ) { |
704 | 836 | global $wgContLang; |
705 | 837 | |
— | — | @@ -721,7 +853,8 @@ |
722 | 854 | } |
723 | 855 | |
724 | 856 | /** |
725 | | - * @todo Needs documentation. |
| 857 | + * Graph which provides statistics about amount of registered users in a given time. |
| 858 | + * @ingroup Stats |
726 | 859 | */ |
727 | 860 | class TranslateRegistrationStats extends TranslationStatsBase { |
728 | 861 | public function preQuery( &$tables, &$fields, &$conds, &$type, &$options, $cutoff ) { |
Index: trunk/extensions/Translate/tag/TranslatablePage.php |
— | — | @@ -1,7 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | 4 | * Translatable page model. |
5 | | - * @defgroup PageTranslation Page Translation |
| 5 | + * |
6 | 6 | * @file |
7 | 7 | * @author Niklas Laxström |
8 | 8 | * @copyright Copyright © 2009-2010 Niklas Laxström |
Index: trunk/extensions/Translate/tag/RenderJob.php |
— | — | @@ -2,17 +2,17 @@ |
3 | 3 | /** |
4 | 4 | * Job for updating translation pages. |
5 | 5 | * |
6 | | - * @ingroup Extensions |
7 | | - * |
| 6 | + * @file |
8 | 7 | * @author Niklas Laxström |
9 | | - * @copyright Copyright © 2008-2009, Niklas Laxström |
| 8 | + * @copyright Copyright © 2008-2010, Niklas Laxström |
10 | 9 | * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
11 | 10 | */ |
12 | 11 | |
13 | 12 | /** |
14 | | - * @todo Needs documentation. |
15 | | - * @ingroup PageTranslation |
| 13 | + * Job for updating translation pages when translation or template changes. |
16 | 14 | */ |
| 15 | + * @ingroup PageTranslation JobQueue |
| 16 | + */ |
17 | 17 | class RenderJob extends Job { |
18 | 18 | public static function newJob( Title $target ) { |
19 | 19 | global $wgTranslateFuzzyBotName; |
Index: trunk/extensions/Translate/tag/MoveJob.php |
— | — | @@ -11,7 +11,7 @@ |
12 | 12 | /** |
13 | 13 | * Contains class with job for moving translation pages. |
14 | 14 | * |
15 | | - * @ingroup PageTranslation |
| 15 | + * @ingroup PageTranslation JobQueue |
16 | 16 | * @todo Get rid of direct reference to $wgMemc. |
17 | 17 | */ |
18 | 18 | class MoveJob extends Job { |