r28807 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r28806‎ | r28807 | r28808 >
Date:20:10, 23 December 2007
Author:nikerabbit
Status:old
Tags:
Comment:
* Split Stat outputs to different file for better re-usability
Modified paths:
  • /trunk/phase3/maintenance/language/StatOutputs.php (added) (history)
  • /trunk/phase3/maintenance/language/transstat.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/language/StatOutputs.php
@@ -0,0 +1,103 @@
 2+<?php
 3+if (!defined('MEDIAWIKI')) die();
 4+/**
 5+ * Statistic output classes.
 6+ *
 7+ * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
 8+ * @author Ashar Voultoiz <thoane@altern.org>
 9+ */
 10+
 11+/** A general output object. Need to be overriden */
 12+class statsOutput {
 13+ function formatPercent( $subset, $total, $revert = false, $accuracy = 2 ) {
 14+ return @sprintf( '%.' . $accuracy . 'f%%', 100 * $subset / $total );
 15+ }
 16+
 17+ # Override the following methods
 18+ function heading() {
 19+ }
 20+ function footer() {
 21+ }
 22+ function blockstart() {
 23+ }
 24+ function blockend() {
 25+ }
 26+ function element( $in, $heading = false ) {
 27+ }
 28+}
 29+
 30+/** Outputs WikiText */
 31+class wikiStatsOutput extends statsOutput {
 32+ function heading() {
 33+ global $IP;
 34+ $version = SpecialVersion::getVersion( $IP );
 35+ echo "'''Statistics are based on:''' <code>" . $version . "</code>\n\n";
 36+ echo "'''Note:''' These statistics can be generated by running <code>php maintenance/language/transstat.php</code>.\n\n";
 37+ echo "For additional information on specific languages (the message names, the actual problems, etc.), run <code>php maintenance/language/checkLanguage.php --lang=foo</code>.\n\n";
 38+ echo '{| class="sortable wikitable" border="2" cellpadding="4" cellspacing="0" style="background-color: #F9F9F9; border: 1px #AAAAAA solid; border-collapse: collapse; clear:both;" width="100%"'."\n";
 39+ }
 40+ function footer() {
 41+ echo "|}\n";
 42+ }
 43+ function blockstart() {
 44+ echo "|-\n";
 45+ }
 46+ function blockend() {
 47+ echo '';
 48+ }
 49+ function element( $in, $heading = false ) {
 50+ echo ($heading ? '!' : '|') . " $in\n";
 51+ }
 52+ function formatPercent( $subset, $total, $revert = false, $accuracy = 2 ) {
 53+ $v = @round(255 * $subset / $total);
 54+ if ( $revert ) {
 55+ $v = 255 - $v;
 56+ }
 57+ if ( $v < 128 ) {
 58+ # Red to Yellow
 59+ $red = 'FF';
 60+ $green = sprintf( '%02X', 2 * $v );
 61+ } else {
 62+ # Yellow to Green
 63+ $red = sprintf('%02X', 2 * ( 255 - $v ) );
 64+ $green = 'FF';
 65+ }
 66+ $blue = '00';
 67+ $color = $red . $green . $blue;
 68+
 69+ $percent = statsOutput::formatPercent( $subset, $total, $revert, $accuracy );
 70+ return 'bgcolor="#'. $color .'" | '. $percent;
 71+ }
 72+}
 73+
 74+/** Outputs WikiText and appends category and text only used for Meta-Wiki */
 75+class metawikiStatsOutput extends wikiStatsOutput {
 76+ function heading() {
 77+ echo "See [[MediaWiki localisation]] to learn how you can help translating MediaWiki.\n\n";
 78+ parent::heading();
 79+ }
 80+ function footer() {
 81+ parent::footer();
 82+ echo "\n[[Category:Localisation|Statistics]]\n";
 83+ }
 84+}
 85+
 86+/** Output text. To be used on a terminal for example. */
 87+class textStatsOutput extends statsOutput {
 88+ function element( $in, $heading = false ) {
 89+ echo $in."\t";
 90+ }
 91+ function blockend() {
 92+ echo "\n";
 93+ }
 94+}
 95+
 96+/** csv output. Some people love excel */
 97+class csvStatsOutput extends statsOutput {
 98+ function element( $in, $heading = false ) {
 99+ echo $in . ";";
 100+ }
 101+ function blockend() {
 102+ echo "\n";
 103+ }
 104+}
Property changes on: trunk/phase3/maintenance/language/StatOutputs.php
___________________________________________________________________
Added: svn:eol-style
1105 + native
Index: trunk/phase3/maintenance/language/transstat.php
@@ -10,10 +10,13 @@
1111 * Output is posted from time to time on:
1212 * http://meta.wikimedia.org/wiki/Localization_statistics
1313 */
 14+$optionsWithArgs = array( 'output' );
1415
1516 require_once( dirname(__FILE__).'/../commandLine.inc' );
1617 require_once( 'languages.inc' );
 18+require_once( dirname(__FILE__).'/StatOutputs.php' );
1719
 20+
1821 if ( isset( $options['help'] ) ) {
1922 showUsage();
2023 }
@@ -39,101 +42,8 @@
4043 exit();
4144 }
4245
43 -/** A general output object. Need to be overriden */
44 -class statsOutput {
45 - function formatPercent( $subset, $total, $revert = false, $accuracy = 2 ) {
46 - return @sprintf( '%.' . $accuracy . 'f%%', 100 * $subset / $total );
47 - }
4846
49 - # Override the following methods
50 - function heading() {
51 - }
52 - function footer() {
53 - }
54 - function blockstart() {
55 - }
56 - function blockend() {
57 - }
58 - function element( $in, $heading = false ) {
59 - }
60 -}
6147
62 -/** Outputs WikiText */
63 -class wikiStatsOutput extends statsOutput {
64 - function heading() {
65 - global $IP;
66 - $version = SpecialVersion::getVersion( $IP );
67 - echo "'''Statistics are based on:''' <code>" . $version . "</code>\n\n";
68 - echo "'''Note:''' These statistics can be generated by running <code>php maintenance/language/transstat.php</code>.\n\n";
69 - echo "For additional information on specific languages (the message names, the actual problems, etc.), run <code>php maintenance/language/checkLanguage.php --lang=foo</code>.\n\n";
70 - echo '{| class="sortable wikitable" border="2" cellpadding="4" cellspacing="0" style="background-color: #F9F9F9; border: 1px #AAAAAA solid; border-collapse: collapse; clear:both;" width="100%"'."\n";
71 - }
72 - function footer() {
73 - echo "|}\n";
74 - }
75 - function blockstart() {
76 - echo "|-\n";
77 - }
78 - function blockend() {
79 - echo '';
80 - }
81 - function element( $in, $heading = false ) {
82 - echo ($heading ? '!' : '|') . " $in\n";
83 - }
84 - function formatPercent( $subset, $total, $revert = false, $accuracy = 2 ) {
85 - $v = @round(255 * $subset / $total);
86 - if ( $revert ) {
87 - $v = 255 - $v;
88 - }
89 - if ( $v < 128 ) {
90 - # Red to Yellow
91 - $red = 'FF';
92 - $green = sprintf( '%02X', 2 * $v );
93 - } else {
94 - # Yellow to Green
95 - $red = sprintf('%02X', 2 * ( 255 - $v ) );
96 - $green = 'FF';
97 - }
98 - $blue = '00';
99 - $color = $red . $green . $blue;
100 -
101 - $percent = statsOutput::formatPercent( $subset, $total, $revert, $accuracy );
102 - return 'bgcolor="#'. $color .'" | '. $percent;
103 - }
104 -}
105 -
106 -/** Outputs WikiText and appends category and text only used for Meta-Wiki */
107 -class metawikiStatsOutput extends wikiStatsOutput {
108 - function heading() {
109 - echo "See [[MediaWiki localisation]] to learn how you can help translating MediaWiki.\n\n";
110 - parent::heading();
111 - }
112 - function footer() {
113 - parent::footer();
114 - echo "\n[[Category:Localisation|Statistics]]\n";
115 - }
116 -}
117 -
118 -/** Output text. To be used on a terminal for example. */
119 -class textStatsOutput extends statsOutput {
120 - function element( $in, $heading = false ) {
121 - echo $in."\t";
122 - }
123 - function blockend() {
124 - echo "\n";
125 - }
126 -}
127 -
128 -/** csv output. Some people love excel */
129 -class csvStatsOutput extends statsOutput {
130 - function element( $in, $heading = false ) {
131 - echo $in . ";";
132 - }
133 - function blockend() {
134 - echo "\n";
135 - }
136 -}
137 -
13848 # Select an output engine
13949 switch ( $options['output'] ) {
14050 case 'wiki':

Status & tagging log