Index: trunk/extensions/Translate/scripts/poimport.php |
— | — | @@ -97,7 +97,7 @@ |
98 | 98 | $data = str_replace( "\r\n", "\n", $data ); |
99 | 99 | |
100 | 100 | $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 ) ) { |
102 | 102 | $code = $matches[1]; |
103 | 103 | STDOUT( "Detected language as $code" ); |
104 | 104 | } else { |
— | — | @@ -105,7 +105,7 @@ |
106 | 106 | return false; |
107 | 107 | } |
108 | 108 | |
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 ) ) { |
110 | 110 | $groupId = $matches[1]; |
111 | 111 | STDOUT( "Detected message group as $groupId" ); |
112 | 112 | } else { |
— | — | @@ -179,6 +179,7 @@ |
180 | 180 | private $dryrun = true; |
181 | 181 | private $allclear = false; |
182 | 182 | private $group = null; |
| 183 | + protected $user; |
183 | 184 | |
184 | 185 | /** |
185 | 186 | * @param $changes \array Array of key/langcode => translation. |
— | — | @@ -190,12 +191,13 @@ |
191 | 192 | $this->changes = $changes; |
192 | 193 | $this->dryrun = $dryrun; |
193 | 194 | $this->group = MessageGroups::getGroup( $groupId ); |
| 195 | + if ( !$this->group ) { |
| 196 | + STDERR( "Group $groupId does not exist." ); |
| 197 | + return; |
| 198 | + } |
194 | 199 | |
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() ) { |
200 | 202 | STDERR( "User $user does not exist." ); |
201 | 203 | return; |
202 | 204 | } |
— | — | @@ -224,25 +226,23 @@ |
225 | 227 | /** |
226 | 228 | * Actually adds the new translation. |
227 | 229 | */ |
228 | | - private function updateMessage( $namespace, $title, $text ) { |
229 | | - global $wgTitle, $wgArticle; |
| 230 | + private function updateMessage( $namespace, $page, $text ) { |
| 231 | + $title = Title::makeTitleSafe( $namespace, $page ); |
230 | 232 | |
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 ); |
236 | 235 | return; |
237 | 236 | } |
| 237 | + STDOUT( "Updating {$title->getPrefixedText()}... ", $title ); |
238 | 238 | |
239 | 239 | if ( $this->dryrun ) { |
240 | 240 | STDOUT( "DRY RUN!", $title ); |
241 | 241 | return; |
242 | 242 | } |
243 | 243 | |
244 | | - $wgArticle = new Article( $wgTitle ); |
| 244 | + $article = new Article( $title, 0 ); |
245 | 245 | |
246 | | - $status = $wgArticle->doEdit( $text, 'Updating translation from gettext import' ); |
| 246 | + $status = $article->doEdit( $text, 'Updating translation from gettext import', 0, false, $this->user ); |
247 | 247 | |
248 | 248 | if ( $status === true || ( is_object( $status ) && $status->isOK() ) ) { |
249 | 249 | STDOUT( "OK!", $title ); |