r51215 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r51214‎ | r51215 | r51216 >
Date:06:55, 31 May 2009
Author:nikerabbit
Status:ok
Tags:
Comment:
* Convert windows linefeeds
* Fix oversight in groupstats, fuzzy percentages were not using inverted color
* Convert createCheckIndex to use fuzzy tags, no need to run this periodically after this
Modified paths:
  • /trunk/extensions/Translate/MessageGroups.php (modified) (history)
  • /trunk/extensions/Translate/scripts/createCheckIndex.php (modified) (history)
  • /trunk/extensions/Translate/scripts/groupStatistics.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/scripts/createCheckIndex.php
@@ -36,6 +36,7 @@
3737 $checker = MessageChecks::getInstance();
3838
3939 foreach ( $groups as $g ) {
 40+
4041 $id = $g->getId();
4142
4243 // Skip groups that are not requested
@@ -44,7 +45,6 @@
4546 continue;
4647 }
4748
48 - $problematic = array();
4949 $type = $g->getType();
5050 if ( !$checker->hasChecks( $type ) ) {
5151 unset( $g );
@@ -52,15 +52,17 @@
5353 }
5454
5555 // Initialise messages, using unique definitions if appropriate
56 - $collection_skel = $g->initCollection( 'en', true );
57 - if ( !count( $collection_skel ) ) continue;
 56+ $collection = $g->initCollection( 'en', true );
 57+ if ( !count( $collection ) ) continue;
5858
5959 STDOUT( "Working with $id: ", $id );
6060
6161 foreach ( $codes as $code ) {
6262 STDOUT( "$code ", $id );
6363
64 - $collection->reset( $code );
 64+ $problematic = array();
 65+
 66+ $collection->resetForNewLanguage( $code );
6567 $collection->loadTranslations();
6668
6769 foreach ( $collection as $key => $message ) {
@@ -74,15 +76,35 @@
7577 }
7678
7779 // Add it to the array
78 - $problematic[$code][] = $key;
 80+ $problematic[] = array( $g->namespaces[0], $key );
7981 }
8082 }
 83+
 84+ tagFuzzy( $problematic );
8185 }
 86+}
8287
83 - // Store the results
84 - $file = TRANSLATE_CHECKFILE . "-$id";
85 - wfMkdirParents( dirname( $file ) );
86 - file_put_contents( $file, serialize( $problematic ) );
 88+
 89+function tagFuzzy( $problematic ) {
 90+ if ( !count($problematic) ) return;
 91+
 92+ $db = wfGetDB( DB_MASTER );
 93+ $id = $db->selectField( 'revtag_type', 'rtt_id', array( 'rtt_name' => 'fuzzy' ), __METHOD__ );
 94+ foreach ( $problematic as $p ) {
 95+ $title = Title::makeTitleSafe( $p[0], $p[1] );
 96+ $titleText = $title->getDBKey();
 97+ $res = $db->select( 'page', array( 'page_id', 'page_latest' ),
 98+ array( 'page_namespace' => $p[0], 'page_title' => $titleText ), __METHOD__ );
 99+
 100+ $inserts = array();
 101+ foreach ( $res as $r ) {
 102+ $inserts = array(
 103+ 'rt_page' => $r->page_id,
 104+ 'rt_revision' => $r->page_latest,
 105+ 'rt_type' => $id
 106+ );
 107+ }
 108+ $db->replace( 'revtag', 'rt_type_page_revision', $inserts, __METHOD__ );
 109+ }
87110 }
88111
89 -unset( $checker );
\ No newline at end of file
Index: trunk/extensions/Translate/scripts/groupStatistics.php
@@ -145,10 +145,10 @@
146146 $cache->set( $groupName, $code, array( $fuzzy, $translated, $total ) );
147147 }
148148
149 - $rows[$code][] = array( $translated, $total );
 149+ $rows[$code][] = array( false, $translated, $total );
150150
151151 if ( isset( $options['fuzzy'] ) ) {
152 - $rows[$code][] = array( $fuzzy, $total );
 152+ $rows[$code][] = array( true, $fuzzy, $total );
153153 }
154154
155155 }
@@ -177,8 +177,8 @@
178178 $out->element( $code );
179179 $out->element( $name );
180180 foreach ( $columns as $fields ) {
181 - list( $upper, $total ) = $fields;
182 - $c = $out->formatPercent( $upper, $total, /* Inverted color */ false, /* Decimals */ 2 );
 181+ list( $invert, $upper, $total ) = $fields;
 182+ $c = $out->formatPercent( $upper, $total, $invert, /* Decimals */ 2 );
183183 $out->element( $c );
184184 }
185185 $out->blockend();
Index: trunk/extensions/Translate/MessageGroups.php
@@ -30,22 +30,6 @@
3131 public function getIgnored() { return $this->ignored; }
3232 public function setIgnored( $value ) { $this->ignored = $value; }
3333
34 - protected $problematic = null;
35 - public function getProblematic( $code ) {
36 - if ( $this->problematic === null ) {
37 - $this->problematic = array();
38 - $file = TRANSLATE_CHECKFILE . '-' . $this->id;
39 - if ( file_exists( $file ) ) {
40 - $problematic = unserialize( file_get_contents( $file ) );
41 - if ( isset( $problematic[$code] ) ) {
42 - $this->problematic = $problematic[$code];
43 - }
44 - }
45 - }
46 - return $this->problematic;
47 - }
48 -
49 - public function setProblematic( $value ) { $this->problematic = $value ; }
5034 /**
5135 * Returns a list of optional and ignored messages in 2-d array.
5236 */
@@ -438,6 +422,7 @@
439423
440424 function getDefinitions() {
441425 $data = file_get_contents( dirname( __FILE__ ) . '/wikimedia-mostused-2009.txt' );
 426+ $data = str_replace( "\r", '', $data );
442427 $messages = explode( "\n", $data );
443428 $contents = Language::getMessagesFor( 'en' );
444429 $definitions = array();

Status & tagging log