http://www.mediawiki.org/wiki/Special:Code/MediaWiki/73940
Revision: 73940
Author: nikerabbit
Date: 2010-09-29 08:59:40 +0000 (Wed, 29 Sep 2010)
Log Message:
-----------
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: trunk/extensions/Translate/scripts/poimport.php
===================================================================
--- trunk/extensions/Translate/scripts/poimport.php 2010-09-29 08:40:03 UTC
(rev 73939)
+++ trunk/extensions/Translate/scripts/poimport.php 2010-09-29 08:59:40 UTC
(rev 73940)
@@ -97,7 +97,7 @@
$data = str_replace( "\r\n", "\n", $data );
$matches = array();
- if ( preg_match( '/X-Language-Code:\s+([a-zA-Z-_]+)/', $data,
$matches ) ) {
+ if ( preg_match( '/X-Language-Code:\s+(.*)\\\n/', $data,
$matches ) ) {
$code = $matches[1];
STDOUT( "Detected language as $code" );
} else {
@@ -105,7 +105,7 @@
return false;
}
- if ( preg_match( '/X-Message-Group:\s+([a-zA-Z0-9-._\|]+)/',
$data, $matches ) ) {
+ if ( preg_match( '/X-Message-Group:\s+(.*)\\\n/', $data,
$matches ) ) {
$groupId = $matches[1];
STDOUT( "Detected message group as $groupId" );
} else {
@@ -179,6 +179,7 @@
private $dryrun = true;
private $allclear = false;
private $group = null;
+ protected $user;
/**
* @param $changes \array Array of key/langcode => translation.
@@ -190,12 +191,13 @@
$this->changes = $changes;
$this->dryrun = $dryrun;
$this->group = MessageGroups::getGroup( $groupId );
+ if ( !$this->group ) {
+ STDERR( "Group $groupId does not exist." );
+ return;
+ }
- global $wgUser;
-
- $wgUser = User::newFromName( $user );
-
- if ( !$wgUser->idForName() ) {
+ $this->user = User::newFromName( $user );
+ if ( !$this->user->idForName() ) {
STDERR( "User $user does not exist." );
return;
}
@@ -224,25 +226,23 @@
/**
* Actually adds the new translation.
*/
- private function updateMessage( $namespace, $title, $text ) {
- global $wgTitle, $wgArticle;
+ private function updateMessage( $namespace, $page, $text ) {
+ $title = Title::makeTitleSafe( $namespace, $page );
- $wgTitle = Title::makeTitleSafe( $namespace, $title );
-
- STDOUT( "Updating {$wgTitle->getPrefixedText()}... ", $title );
- if ( !$wgTitle instanceof Title ) {
- STDOUT( "INVALID TITLE!", $title );
+ if ( !$title instanceof Title ) {
+ STDOUT( "INVALID TITLE!", $page );
return;
}
+ STDOUT( "Updating {$title->getPrefixedText()}... ", $title );
if ( $this->dryrun ) {
STDOUT( "DRY RUN!", $title );
return;
}
- $wgArticle = new Article( $wgTitle );
+ $article = new Article( $title, 0 );
- $status = $wgArticle->doEdit( $text, 'Updating translation from
gettext import' );
+ $status = $article->doEdit( $text, 'Updating translation from
gettext import', 0, false, $this->user );
if ( $status === true || ( is_object( $status ) &&
$status->isOK() ) ) {
STDOUT( "OK!", $title );
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs