r73940 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73939‎ | r73940 | r73941 >
Date:08:59, 29 September 2010
Author:nikerabbit
Status:ok
Tags:
Comment:
Modernise poimport.

Get rid of globals like $wgTitle and fixed a bug that didn't detect translatable page message groups properly
Modified paths:
  • /trunk/extensions/Translate/scripts/poimport.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/scripts/poimport.php
@@ -97,7 +97,7 @@
9898 $data = str_replace( "\r\n", "\n", $data );
9999
100100 $matches = array();
101 - if ( preg_match( '/X-Language-Code:\s+([a-zA-Z-_]+)/', $data, $matches ) ) {
 101+ if ( preg_match( '/X-Language-Code:\s+(.*)\\\n/', $data, $matches ) ) {
102102 $code = $matches[1];
103103 STDOUT( "Detected language as $code" );
104104 } else {
@@ -105,7 +105,7 @@
106106 return false;
107107 }
108108
109 - if ( preg_match( '/X-Message-Group:\s+([a-zA-Z0-9-._\|]+)/', $data, $matches ) ) {
 109+ if ( preg_match( '/X-Message-Group:\s+(.*)\\\n/', $data, $matches ) ) {
110110 $groupId = $matches[1];
111111 STDOUT( "Detected message group as $groupId" );
112112 } else {
@@ -179,6 +179,7 @@
180180 private $dryrun = true;
181181 private $allclear = false;
182182 private $group = null;
 183+ protected $user;
183184
184185 /**
185186 * @param $changes \array Array of key/langcode => translation.
@@ -190,12 +191,13 @@
191192 $this->changes = $changes;
192193 $this->dryrun = $dryrun;
193194 $this->group = MessageGroups::getGroup( $groupId );
 195+ if ( !$this->group ) {
 196+ STDERR( "Group $groupId does not exist." );
 197+ return;
 198+ }
194199
195 - global $wgUser;
196 -
197 - $wgUser = User::newFromName( $user );
198 -
199 - if ( !$wgUser->idForName() ) {
 200+ $this->user = User::newFromName( $user );
 201+ if ( !$this->user->idForName() ) {
200202 STDERR( "User $user does not exist." );
201203 return;
202204 }
@@ -224,25 +226,23 @@
225227 /**
226228 * Actually adds the new translation.
227229 */
228 - private function updateMessage( $namespace, $title, $text ) {
229 - global $wgTitle, $wgArticle;
 230+ private function updateMessage( $namespace, $page, $text ) {
 231+ $title = Title::makeTitleSafe( $namespace, $page );
230232
231 - $wgTitle = Title::makeTitleSafe( $namespace, $title );
232 -
233 - STDOUT( "Updating {$wgTitle->getPrefixedText()}... ", $title );
234 - if ( !$wgTitle instanceof Title ) {
235 - STDOUT( "INVALID TITLE!", $title );
 233+ if ( !$title instanceof Title ) {
 234+ STDOUT( "INVALID TITLE!", $page );
236235 return;
237236 }
 237+ STDOUT( "Updating {$title->getPrefixedText()}... ", $title );
238238
239239 if ( $this->dryrun ) {
240240 STDOUT( "DRY RUN!", $title );
241241 return;
242242 }
243243
244 - $wgArticle = new Article( $wgTitle );
 244+ $article = new Article( $title, 0 );
245245
246 - $status = $wgArticle->doEdit( $text, 'Updating translation from gettext import' );
 246+ $status = $article->doEdit( $text, 'Updating translation from gettext import', 0, false, $this->user );
247247
248248 if ( $status === true || ( is_object( $status ) && $status->isOK() ) ) {
249249 STDOUT( "OK!", $title );

Status & tagging log