Index: trunk/extensions/Translate/SpecialManageGroups.php |
— | — | @@ -1,4 +1,5 @@ |
2 | 2 | <?php |
| 3 | +if ( !defined( 'MEDIAWIKI' ) ) die(); |
3 | 4 | |
4 | 5 | class SpecialManageGroups { |
5 | 6 | protected $skin, $user, $out; |
— | — | @@ -375,14 +376,28 @@ |
376 | 377 | $title = self::makeTitle( $group, $key, $code ); |
377 | 378 | $fuzzybot = self::getFuzzyBot(); |
378 | 379 | |
379 | | - return $this->doImport( $title, $message, $comment, $fuzzybot ); |
| 380 | + return MessageWebImporter::doImport( |
| 381 | + $title, |
| 382 | + $message, |
| 383 | + $comment, |
| 384 | + $fuzzybot, |
| 385 | + EDIT_FORCE_BOT |
| 386 | + ); |
380 | 387 | } elseif ( $action === 'ignore' ) { |
381 | 388 | return array( 'translate-manage-import-ignore', $key ); |
382 | 389 | } elseif ( $action === 'fuzzy' && $code != 'en' ) { |
| 390 | + global $wgUser; |
383 | 391 | $title = Title::makeTitleSafe( $group->getNamespace(), $key ); |
384 | | - $comment = wfMsgForContentNoTrans( 'translate-manage-fuzzy-summary' ); |
| 392 | + $comment = "[{$wgUser->getName()}] "; |
| 393 | + $comment .= wfMsgForContentNoTrans( 'translate-manage-fuzzy-summary' ); |
385 | 394 | |
386 | | - return $this->doFuzzy( $title, $message, $comment ); |
| 395 | + return MessageWebImporter::doFuzzy( |
| 396 | + $title, |
| 397 | + $message, |
| 398 | + $comment, |
| 399 | + null, |
| 400 | + EDIT_FORCE_BOT |
| 401 | + ); |
387 | 402 | } else { |
388 | 403 | throw new MWException( "Unhandled action $action" ); |
389 | 404 | } |
— | — | @@ -392,72 +407,6 @@ |
393 | 408 | return wfTimestamp() - $this->time >= $this->processingTime; |
394 | 409 | } |
395 | 410 | |
396 | | - protected function doImport( $title, $message, $comment, $user = null ) { |
397 | | - $flags = EDIT_FORCE_BOT; |
398 | | - $article = new Article( $title ); |
399 | | - $status = $article->doEdit( $message, $comment, $flags, false, $user ); |
400 | | - $success = $status->isOK(); |
401 | | - |
402 | | - if ( $success ) { |
403 | | - return array( 'translate-manage-import-ok', |
404 | | - wfEscapeWikiText( $title->getPrefixedText() ) |
405 | | - ); |
406 | | - } else { |
407 | | - throw new MWException( "Failed to import new version of page {$title->getPrefixedText()}\n{$status->getWikiText()}" ); |
408 | | - } |
409 | | - } |
410 | | - |
411 | | - protected function doFuzzy( $title, $message, $comment ) { |
412 | | - global $wgUser; |
413 | | - |
414 | | - $dbw = wfGetDB( DB_MASTER ); |
415 | | - $titleText = $title->getDBKey(); |
416 | | - $conds = array( |
417 | | - 'page_namespace' => $title->getNamespace(), |
418 | | - 'page_latest=rev_id', |
419 | | - 'rev_text_id=old_id', |
420 | | - "page_title LIKE '{$dbw->escapeLike( $titleText )}/%%'" |
421 | | - ); |
422 | | - |
423 | | - $rows = $dbw->select( |
424 | | - array( 'page', 'revision', 'text' ), |
425 | | - array( 'page_title', 'page_namespace', 'old_text', 'old_flags' ), |
426 | | - $conds, |
427 | | - __METHOD__ |
428 | | - ); |
429 | | - |
430 | | - $changed = array(); |
431 | | - $fuzzybot = self::getFuzzyBot(); |
432 | | - |
433 | | - foreach ( $rows as $row ) { |
434 | | - $ttitle = Title::makeTitle( $row->page_namespace, $row->page_title ); |
435 | | - |
436 | | - // Avoid double-fuzzying |
437 | | - $text = Revision::getRevisionText( $row ); |
438 | | - $text = str_replace( TRANSLATE_FUZZY, '', $text ); |
439 | | - $text = TRANSLATE_FUZZY . $text; |
440 | | - |
441 | | - $changed[] = $this->doImport( $ttitle, $text, "[{$wgUser->getName()}] " . $comment, $fuzzybot ); |
442 | | - if ( $this->checkProcessTime() ) break; |
443 | | - } |
444 | | - |
445 | | - if ( count( $changed ) === $rows->numRows() ) { |
446 | | - $comment = "[{$wgUser->getName()}] " . wfMsgForContentNoTrans( 'translate-manage-import-summary' ); |
447 | | - $title = Title::makeTitleSafe( $title->getNamespace(), $title->getPrefixedDbKey() . '/en' ); |
448 | | - $changed[] = $this->doImport( $title, $message, $comment, $fuzzybot ); |
449 | | - } |
450 | | - |
451 | | - $text = ''; |
452 | | - foreach ( $changed as $c ) { |
453 | | - $key = array_shift( $c ); |
454 | | - $text .= "* " . wfMsgExt( $key, array(), $c ) . "\n"; |
455 | | - } |
456 | | - |
457 | | - return array( 'translate-manage-import-fuzzy', |
458 | | - "\n" . $text |
459 | | - ); |
460 | | - } |
461 | | - |
462 | 411 | // FIXME: Duplicate code. See ChangeSyncer::getImportUser() in scripts/sync-group.php |
463 | 412 | protected static function getFuzzyBot() { |
464 | 413 | global $wgTranslateFuzzyBotName; |
Index: trunk/extensions/Translate/utils/MessageWebImporter.php |
— | — | @@ -284,11 +284,11 @@ |
285 | 285 | |
286 | 286 | $title = self::makeTitle( $group, $key, $code ); |
287 | 287 | |
288 | | - return $this->doImport( $title, $message, $comment ); |
| 288 | + return self::doImport( $title, $message, $comment ); |
289 | 289 | } elseif ( $action === 'ignore' ) { |
290 | 290 | return array( 'translate-manage-import-ignore', $key ); |
291 | 291 | } elseif ( $action === 'fuzzy' && $code != 'en' ) { |
292 | | - return $this->doFuzzy( $title, $message, $comment ); |
| 292 | + return self::doFuzzy( $title, $message, $comment ); |
293 | 293 | } else { |
294 | 294 | throw new MWException( "Unhandled action $action" ); |
295 | 295 | } |
— | — | @@ -298,10 +298,9 @@ |
299 | 299 | return wfTimestamp() - $this->time >= $this->processingTime; |
300 | 300 | } |
301 | 301 | |
302 | | - // FIXME: lot of duplication with SpecialManageGroups::doImport() |
303 | | - protected function doImport( $title, $message, $comment, $user = null ) { |
| 302 | + public static function doImport( $title, $message, $comment, $user = null, $flags = false ) { |
304 | 303 | $article = new Article( $title ); |
305 | | - $status = $article->doEdit( $message, $comment ); |
| 304 | + $status = $article->doEdit( $message, $comment, $flags, false, $user ); |
306 | 305 | $success = $status->isOK(); |
307 | 306 | |
308 | 307 | if ( $success ) { |
— | — | @@ -313,10 +312,11 @@ |
314 | 313 | } |
315 | 314 | } |
316 | 315 | |
317 | | - // FIXME: lot of duplication with SpecialManageGroups::doFuzzy() |
318 | | - protected function doFuzzy( $title, $message, $comment ) { |
| 316 | + public static function doFuzzy( $title, $message, $comment, $user, $editFlags = 0 ) { |
319 | 317 | $dbw = wfGetDB( DB_MASTER ); |
| 318 | + |
320 | 319 | $titleText = $title->getDBKey(); |
| 320 | + |
321 | 321 | $condArray = array( |
322 | 322 | 'page_namespace' => $title->getNamespace(), |
323 | 323 | 'page_latest=rev_id', |
— | — | @@ -332,16 +332,25 @@ |
333 | 333 | ); |
334 | 334 | |
335 | 335 | $changed = array(); |
336 | | - $fuzzybot = self::getFuzzyBot(); |
| 336 | + |
| 337 | + if( !$user ) { |
| 338 | + $user = self::getFuzzyBot(); |
| 339 | + } |
337 | 340 | |
338 | 341 | foreach ( $rows as $row ) { |
339 | 342 | $ttitle = Title::makeTitle( $row->page_namespace, $row->page_title ); |
340 | 343 | |
341 | | - $changed[] = $this->doImport( |
| 344 | + // Avoid double-fuzzying |
| 345 | + $text = Revision::getRevisionText( $row ); |
| 346 | + $text = str_replace( TRANSLATE_FUZZY, '', $text ); |
| 347 | + $text = TRANSLATE_FUZZY . $text; |
| 348 | + |
| 349 | + $changed[] = self::doImport( |
342 | 350 | $ttitle, |
343 | | - TRANSLATE_FUZZY . Revision::getRevisionText( $row ), |
| 351 | + $text, |
344 | 352 | $comment, |
345 | | - $fuzzybot |
| 353 | + $user, |
| 354 | + $editFlags |
346 | 355 | ); |
347 | 356 | |
348 | 357 | if ( $this->checkProcessTime() ) { |
— | — | @@ -351,7 +360,18 @@ |
352 | 361 | |
353 | 362 | if ( count( $changed ) === count( $rows ) ) { |
354 | 363 | $comment = wfMsgForContentNoTrans( 'translate-manage-import-summary' ); |
355 | | - $changed[] = $this->doImport( $title, $message, $comment ); |
| 364 | + // FIXME: Leftover of refactoring from SpecialManageGroups::doFuzzy() |
| 365 | + // Did not know what to do with this. Have to ask Nikerabbit. |
| 366 | + // Probably have to add an extra parameter, but this part should |
| 367 | + // have had a comment. |
| 368 | + // $title = Title::makeTitleSafe( $title->getNamespace(), $title->getPrefixedDbKey() . '/en' ); |
| 369 | + $changed[] = self::doImport( |
| 370 | + $title, |
| 371 | + $message, |
| 372 | + $comment, |
| 373 | + $user, |
| 374 | + $editFlags |
| 375 | + ); |
356 | 376 | } |
357 | 377 | |
358 | 378 | $text = ''; |