Index: trunk/extensions/Translate/SpecialManageGroups.php |
— | — | @@ -1,5 +1,12 @@ |
2 | 2 | <?php |
3 | | -if ( !defined( 'MEDIAWIKI' ) ) die(); |
| 3 | +/** |
| 4 | + * @addtogroup Extensions |
| 5 | + * |
| 6 | + * @author Niklas Laxstr�m |
| 7 | + * @author Siebrand Mazeland |
| 8 | + * @copyright Copyright � 2009-2010, Niklas Laxstr�m, Siebrand Mazeland |
| 9 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 10 | + */ |
4 | 11 | |
5 | 12 | class SpecialManageGroups { |
6 | 13 | protected $skin, $user, $out; |
— | — | @@ -188,7 +195,17 @@ |
189 | 196 | $this->time = wfTimestamp(); |
190 | 197 | } |
191 | 198 | |
192 | | - $message = $this->doAction( $action, $group, $key, $code, $value ); |
| 199 | + $fuzzybot = MessageWebImporter::getFuzzyBot(); |
| 200 | + $message = MessageWebImporter::doAction( |
| 201 | + $action, |
| 202 | + $group, |
| 203 | + $key, |
| 204 | + $code, |
| 205 | + $value, |
| 206 | + '', /* default edit summary */ |
| 207 | + $fuzzybot, |
| 208 | + EDIT_FORCE_BOT |
| 209 | + ); |
193 | 210 | |
194 | 211 | $key = array_shift( $message ); |
195 | 212 | $params = $message; |
— | — | @@ -364,69 +381,10 @@ |
365 | 382 | } |
366 | 383 | } |
367 | 384 | |
368 | | - protected function doAction( $action, $group, $key, $code, $message, $comment = '' ) { |
369 | | - if ( $action === 'import' || $action === 'conflict' ) { |
370 | | - if ( $action === 'import' ) { |
371 | | - $comment = wfMsgForContentNoTrans( 'translate-manage-import-summary' ); |
372 | | - } else { |
373 | | - $comment = wfMsgForContentNoTrans( 'translate-manage-conflict-summary' ); |
374 | | - $message = TRANSLATE_FUZZY . $message; |
375 | | - } |
376 | | - |
377 | | - $title = self::makeTitle( $group, $key, $code ); |
378 | | - $fuzzybot = self::getFuzzyBot(); |
379 | | - |
380 | | - return MessageWebImporter::doImport( |
381 | | - $title, |
382 | | - $message, |
383 | | - $comment, |
384 | | - $fuzzybot, |
385 | | - EDIT_FORCE_BOT |
386 | | - ); |
387 | | - } elseif ( $action === 'ignore' ) { |
388 | | - return array( 'translate-manage-import-ignore', $key ); |
389 | | - } elseif ( $action === 'fuzzy' && $code != 'en' ) { |
390 | | - global $wgUser; |
391 | | - $title = Title::makeTitleSafe( $group->getNamespace(), $key ); |
392 | | - $comment = "[{$wgUser->getName()}] "; |
393 | | - $comment .= wfMsgForContentNoTrans( 'translate-manage-fuzzy-summary' ); |
394 | | - |
395 | | - return MessageWebImporter::doFuzzy( |
396 | | - $title, |
397 | | - $message, |
398 | | - $comment, |
399 | | - null, |
400 | | - EDIT_FORCE_BOT |
401 | | - ); |
402 | | - } else { |
403 | | - throw new MWException( "Unhandled action $action" ); |
404 | | - } |
405 | | - } |
406 | | - |
407 | 385 | protected function checkProcessTime() { |
408 | 386 | return wfTimestamp() - $this->time >= $this->processingTime; |
409 | 387 | } |
410 | 388 | |
411 | | - // FIXME: Duplicate code. See ChangeSyncer::getImportUser() in scripts/sync-group.php |
412 | | - protected static function getFuzzyBot() { |
413 | | - global $wgTranslateFuzzyBotName; |
414 | | - |
415 | | - $user = User::newFromName( $wgTranslateFuzzyBotName ); |
416 | | - |
417 | | - if ( !$user->isLoggedIn() ) { |
418 | | - $user->addToDatabase(); |
419 | | - } |
420 | | - |
421 | | - return $user; |
422 | | - } |
423 | | - |
424 | | - protected static function makeTitle( $group, $key, $code ) { |
425 | | - $ns = $group->getNamespace(); |
426 | | - $titlekey = "$key/$code"; |
427 | | - |
428 | | - return Title::makeTitleSafe( $ns, $titlekey ); |
429 | | - } |
430 | | - |
431 | 389 | protected function setSubtitle( $group, $code ) { |
432 | 390 | global $wgLang; |
433 | 391 | $links[] = $this->skin->link( |
Index: trunk/extensions/Translate/utils/MessageWebImporter.php |
— | — | @@ -6,7 +6,8 @@ |
7 | 7 | * @addtogroup Extensions |
8 | 8 | * |
9 | 9 | * @author Niklas Laxström |
10 | | - * @copyright Copyright © 2009, Niklas Laxström |
| 10 | + * @author Siebrand Mazeland |
| 11 | + * @copyright Copyright © 2009-2010, Niklas Laxström, Siebrand Mazeland |
11 | 12 | * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
12 | 13 | */ |
13 | 14 | |
— | — | @@ -142,13 +143,6 @@ |
143 | 144 | |
144 | 145 | if ( isset( $collection[$key] ) ) { |
145 | 146 | $old = $collection[$key]->translation(); |
146 | | - /* Fuzzy state of the in-wiki message is of no |
147 | | - * concern. Default action should be 'import'. |
148 | | - * If the string is marked fuzzy in the gettext, |
149 | | - * fuzzy tag is added anyway on import. |
150 | | - $fuzzy = TranslateEditAddons::hasFuzzyString( $old ) || |
151 | | - TranslateEditAddons::isFuzzy( self::makeTitle( $group, $key, $code ) ); |
152 | | - */ |
153 | 147 | } |
154 | 148 | |
155 | 149 | // No changes at all, ignore |
— | — | @@ -185,7 +179,13 @@ |
186 | 180 | // Check processing time |
187 | 181 | if ( !isset( $this->time ) ) $this->time = wfTimestamp(); |
188 | 182 | |
189 | | - $message = $this->doAction( $action, $group, $key, $code, $value ); |
| 183 | + $message = self::doAction( |
| 184 | + $action, |
| 185 | + $group, |
| 186 | + $key, |
| 187 | + $code, |
| 188 | + $value |
| 189 | + ); |
190 | 190 | |
191 | 191 | $key = array_shift( $message ); |
192 | 192 | $params = $message; |
— | — | @@ -272,23 +272,40 @@ |
273 | 273 | return $alldone; |
274 | 274 | } |
275 | 275 | |
276 | | - // FIXME: lot of duplication with SpecialManageGroups::doAction() |
277 | | - protected function doAction( $action, $group, $key, $code, $message, $comment = '' ) { |
| 276 | + /** |
| 277 | + * Perform an action on a given group/key/code |
| 278 | + * |
| 279 | + * @param $action String: import/conflict/ignore |
| 280 | + * @param $group Object: group object |
| 281 | + * @param $key String: message key |
| 282 | + * @param $code String: language code |
| 283 | + * @param $message String: contents for the $key/code combination |
| 284 | + * @param $comment String: edit summary (default: empty) - see Article::doEdit |
| 285 | + * @param $user Object: object of user that will make the edit (default: null - $wgUser) - see Article::doEdit |
| 286 | + * @param $editFlags Integer bitfield: see Article::doEdit |
| 287 | + * |
| 288 | + * @return String: action result |
| 289 | + */ |
| 290 | + public static function doAction( $action, $group, $key, $code, $message, $comment = '', $user = null, $editFlags = 0 ) { |
278 | 291 | if ( $action === 'import' || $action === 'conflict' ) { |
279 | 292 | if ( $action === 'import' ) { |
280 | 293 | $comment = wfMsgForContentNoTrans( 'translate-manage-import-summary' ); |
281 | 294 | } else { |
282 | 295 | $comment = wfMsgForContentNoTrans( 'translate-manage-conflict-summary' ); |
283 | | - $message = TRANSLATE_FUZZY . $message; |
| 296 | + $message = self::makeMessageFuzzy( $message ); |
284 | 297 | } |
285 | 298 | |
286 | 299 | $title = self::makeTitle( $group, $key, $code ); |
287 | 300 | |
288 | | - return self::doImport( $title, $message, $comment ); |
| 301 | + return self::doImport( $title, $message, $comment, $user, $editFlags ); |
289 | 302 | } elseif ( $action === 'ignore' ) { |
290 | 303 | return array( 'translate-manage-import-ignore', $key ); |
291 | 304 | } elseif ( $action === 'fuzzy' && $code != 'en' ) { |
292 | | - return self::doFuzzy( $title, $message, $comment ); |
| 305 | + $title = self::makeTitle( $group, $key, $code ); |
| 306 | + |
| 307 | + $message = self::makeMessageFuzzy( $message ); |
| 308 | + |
| 309 | + return self::doImport( $title, $message, $comment, $user, $editFlags ); |
293 | 310 | } else { |
294 | 311 | throw new MWException( "Unhandled action $action" ); |
295 | 312 | } |
— | — | @@ -298,9 +315,9 @@ |
299 | 316 | return wfTimestamp() - $this->time >= $this->processingTime; |
300 | 317 | } |
301 | 318 | |
302 | | - public static function doImport( $title, $message, $comment, $user = null, $flags = false ) { |
| 319 | + public static function doImport( $title, $message, $comment, $user = null, $editFlags = 0 ) { |
303 | 320 | $article = new Article( $title ); |
304 | | - $status = $article->doEdit( $message, $comment, $flags, false, $user ); |
| 321 | + $status = $article->doEdit( $message, $comment, $editFlags, false, $user ); |
305 | 322 | $success = $status->isOK(); |
306 | 323 | |
307 | 324 | if ( $success ) { |
— | — | @@ -340,10 +357,8 @@ |
341 | 358 | foreach ( $rows as $row ) { |
342 | 359 | $ttitle = Title::makeTitle( $row->page_namespace, $row->page_title ); |
343 | 360 | |
344 | | - // Avoid double-fuzzying |
345 | 361 | $text = Revision::getRevisionText( $row ); |
346 | | - $text = str_replace( TRANSLATE_FUZZY, '', $text ); |
347 | | - $text = TRANSLATE_FUZZY . $text; |
| 362 | + $text = self::makeTextFuzzy( $text ); |
348 | 363 | |
349 | 364 | $changed[] = self::doImport( |
350 | 365 | $ttitle, |
— | — | @@ -383,8 +398,7 @@ |
384 | 399 | return array( 'translate-manage-import-fuzzy', "\n" . $text ); |
385 | 400 | } |
386 | 401 | |
387 | | - // FIXME: duplicate of SpecialManageGroups::getFuzzyBot() |
388 | | - protected static function getFuzzyBot() { |
| 402 | + public static function getFuzzyBot() { |
389 | 403 | global $wgTranslateFuzzyBotName; |
390 | 404 | |
391 | 405 | $user = User::newFromName( $wgTranslateFuzzyBotName ); |
— | — | @@ -396,8 +410,7 @@ |
397 | 411 | return $user; |
398 | 412 | } |
399 | 413 | |
400 | | - // FIXME: duplicate of SpecialManageGroups::makeTitle() |
401 | | - protected static function makeTitle( $group, $key, $code ) { |
| 414 | + public static function makeTitle( $group, $key, $code ) { |
402 | 415 | $ns = $group->getNamespace(); |
403 | 416 | $titlekey = "$key/$code"; |
404 | 417 | |
— | — | @@ -414,4 +427,16 @@ |
415 | 428 | Xml::tags( 'div', $contentParams, $content ) |
416 | 429 | ); |
417 | 430 | } |
| 431 | + |
| 432 | + /** |
| 433 | + * Safe add fuzzy tag to text |
| 434 | + * |
| 435 | + * @param $message String: message content |
| 436 | + * |
| 437 | + * @return $message prefixed with TRANSLATE_FUZZY tag |
| 438 | + */ |
| 439 | + public static function makeTextFuzzy( $message ) { |
| 440 | + $message = str_replace( TRANSLATE_FUZZY, '', $message ); |
| 441 | + return TRANSLATE_FUZZY . $message; |
| 442 | + } |
418 | 443 | } |