r62240 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62239‎ | r62240 | r62241 >
Date:12:01, 10 February 2010
Author:siebrand
Status:deferred
Tags:
Comment:
Refactor doImport() and doFuzzy() out of class SpecialManageGroups and use the methods in class MessageWebImporter.

Needs review; also see FIXME.
Modified paths:
  • /trunk/extensions/Translate/SpecialManageGroups.php (modified) (history)
  • /trunk/extensions/Translate/utils/MessageWebImporter.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/SpecialManageGroups.php
@@ -1,4 +1,5 @@
22 <?php
 3+if ( !defined( 'MEDIAWIKI' ) ) die();
34
45 class SpecialManageGroups {
56 protected $skin, $user, $out;
@@ -375,14 +376,28 @@
376377 $title = self::makeTitle( $group, $key, $code );
377378 $fuzzybot = self::getFuzzyBot();
378379
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+ );
380387 } elseif ( $action === 'ignore' ) {
381388 return array( 'translate-manage-import-ignore', $key );
382389 } elseif ( $action === 'fuzzy' && $code != 'en' ) {
 390+ global $wgUser;
383391 $title = Title::makeTitleSafe( $group->getNamespace(), $key );
384 - $comment = wfMsgForContentNoTrans( 'translate-manage-fuzzy-summary' );
 392+ $comment = "[{$wgUser->getName()}] ";
 393+ $comment .= wfMsgForContentNoTrans( 'translate-manage-fuzzy-summary' );
385394
386 - return $this->doFuzzy( $title, $message, $comment );
 395+ return MessageWebImporter::doFuzzy(
 396+ $title,
 397+ $message,
 398+ $comment,
 399+ null,
 400+ EDIT_FORCE_BOT
 401+ );
387402 } else {
388403 throw new MWException( "Unhandled action $action" );
389404 }
@@ -392,72 +407,6 @@
393408 return wfTimestamp() - $this->time >= $this->processingTime;
394409 }
395410
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 -
462411 // FIXME: Duplicate code. See ChangeSyncer::getImportUser() in scripts/sync-group.php
463412 protected static function getFuzzyBot() {
464413 global $wgTranslateFuzzyBotName;
Index: trunk/extensions/Translate/utils/MessageWebImporter.php
@@ -284,11 +284,11 @@
285285
286286 $title = self::makeTitle( $group, $key, $code );
287287
288 - return $this->doImport( $title, $message, $comment );
 288+ return self::doImport( $title, $message, $comment );
289289 } elseif ( $action === 'ignore' ) {
290290 return array( 'translate-manage-import-ignore', $key );
291291 } elseif ( $action === 'fuzzy' && $code != 'en' ) {
292 - return $this->doFuzzy( $title, $message, $comment );
 292+ return self::doFuzzy( $title, $message, $comment );
293293 } else {
294294 throw new MWException( "Unhandled action $action" );
295295 }
@@ -298,10 +298,9 @@
299299 return wfTimestamp() - $this->time >= $this->processingTime;
300300 }
301301
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 ) {
304303 $article = new Article( $title );
305 - $status = $article->doEdit( $message, $comment );
 304+ $status = $article->doEdit( $message, $comment, $flags, false, $user );
306305 $success = $status->isOK();
307306
308307 if ( $success ) {
@@ -313,10 +312,11 @@
314313 }
315314 }
316315
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 ) {
319317 $dbw = wfGetDB( DB_MASTER );
 318+
320319 $titleText = $title->getDBKey();
 320+
321321 $condArray = array(
322322 'page_namespace' => $title->getNamespace(),
323323 'page_latest=rev_id',
@@ -332,16 +332,25 @@
333333 );
334334
335335 $changed = array();
336 - $fuzzybot = self::getFuzzyBot();
 336+
 337+ if( !$user ) {
 338+ $user = self::getFuzzyBot();
 339+ }
337340
338341 foreach ( $rows as $row ) {
339342 $ttitle = Title::makeTitle( $row->page_namespace, $row->page_title );
340343
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(
342350 $ttitle,
343 - TRANSLATE_FUZZY . Revision::getRevisionText( $row ),
 351+ $text,
344352 $comment,
345 - $fuzzybot
 353+ $user,
 354+ $editFlags
346355 );
347356
348357 if ( $this->checkProcessTime() ) {
@@ -351,7 +360,18 @@
352361
353362 if ( count( $changed ) === count( $rows ) ) {
354363 $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+ );
356376 }
357377
358378 $text = '';

Status & tagging log