r107816 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107815‎ | r107816 | r107817 >
Date:11:10, 2 January 2012
Author:nikerabbit
Status:resolved (Comments)
Tags:
Comment:
Move FuzzyBot code into new class so that the user is created when needed
Bug 33466
Modified paths:
  • /trunk/extensions/Translate/MessageCollection.php (modified) (history)
  • /trunk/extensions/Translate/_autoload.php (modified) (history)
  • /trunk/extensions/Translate/scripts/fuzzy.php (modified) (history)
  • /trunk/extensions/Translate/scripts/languageeditstats.php (modified) (history)
  • /trunk/extensions/Translate/scripts/sync-group.php (modified) (history)
  • /trunk/extensions/Translate/tag/DeleteJob.php (modified) (history)
  • /trunk/extensions/Translate/tag/MoveJob.php (modified) (history)
  • /trunk/extensions/Translate/tag/RenderJob.php (modified) (history)
  • /trunk/extensions/Translate/utils/MessageWebImporter.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/MessageCollection.php
@@ -164,8 +164,6 @@
165165 * @return \list{String} List of usernames.
166166 */
167167 public function getAuthors() {
168 - global $wgTranslateFuzzyBotName;
169 -
170168 $this->loadTranslations();
171169
172170 $authors = array_flip( $this->authors );
@@ -187,8 +185,9 @@
188186
189187 # arsort( $authors, SORT_NUMERIC );
190188 ksort( $authors );
 189+ $fuzzyBot = FuzzyBot::getName();
191190 foreach ( $authors as $author => $edits ) {
192 - if ( $author !== $wgTranslateFuzzyBotName ) {
 191+ if ( $author !== $fuzzyBot ) {
193192 $filteredAuthors[] = $author;
194193 }
195194 }
Index: trunk/extensions/Translate/scripts/sync-group.php
@@ -363,27 +363,6 @@
364364 }
365365
366366 /**
367 - * Initialises FuzzyBot if necessary.
368 - * @return \type{User}
369 - */
370 - public function getImportUser() {
371 - static $user = null;
372 -
373 - if ( $user === null ) {
374 - global $wgTranslateFuzzyBotName;
375 -
376 - $user = User::newFromName( $wgTranslateFuzzyBotName );
377 -
378 - if ( !$user->isLoggedIn() ) {
379 - STDOUT( "Creating user $wgTranslateFuzzyBotName" );
380 - $user->addToDatabase();
381 - }
382 - }
383 -
384 - return $user;
385 - }
386 -
387 - /**
388367 * Does the actual edit.
389368 * @param $title Title
390369 * @param $translation \string
@@ -393,7 +372,7 @@
394373 global $wgUser;
395374
396375 $old = $wgUser;
397 - $wgUser = $this->getImportUser();
 376+ $wgUser = FuzzyBot::getUser();
398377
399378 $flags = EDIT_FORCE_BOT;
400379 if ( $this->norc ) {
Index: trunk/extensions/Translate/scripts/languageeditstats.php
@@ -81,8 +81,7 @@
8282 $rows = TranslateUtils::translationChanges( $hours, $bots, $namespaces );
8383
8484 /**
85 - * Get counts for edits per language code after filtering out edits by
86 - * $wgTranslateFuzzyBotName.
 85+ * Get counts for edits per language code after filtering out edits by FuzzyBot
8786 */
8887 $codes = array();
8988 foreach ( $rows as $_ ) {
Index: trunk/extensions/Translate/scripts/fuzzy.php
@@ -147,26 +147,6 @@
148148 }
149149
150150 /**
151 - * Create FuzzyBot user if necessary.
152 - * @return \type{User}
153 - */
154 - public function getImportUser() {
155 - static $user = null;
156 -
157 - if ( $user === null ) {
158 - global $wgTranslateFuzzyBotName;
159 - $user = User::newFromName( $wgTranslateFuzzyBotName );
160 -
161 - if ( !$user->isLoggedIn() ) {
162 - STDOUT( "Creating user $wgTranslateFuzzyBotName" );
163 - $user->addToDatabase();
164 - }
165 - }
166 -
167 - return $user;
168 - }
169 -
170 - /**
171151 * Does the actual edit if possible.
172152 * @param $title \type{Title}
173153 * @param $text \string
@@ -177,7 +157,7 @@
178158 global $wgTranslateDocumentationLanguageCode, $wgUser;
179159
180160 $oldUser = $wgUser;
181 - $wgUser = $this->getImportUser();
 161+ $wgUser = FuzzyBot::getUser();
182162
183163 STDOUT( "Updating {$title->getPrefixedText()}... ", $title );
184164 if ( !$title instanceof Title ) {
Index: trunk/extensions/Translate/tag/RenderJob.php
@@ -20,10 +20,8 @@
2121 * @return RenderJob
2222 */
2323 public static function newJob( Title $target ) {
24 - global $wgTranslateFuzzyBotName;
25 -
2624 $job = new self( $target );
27 - $job->setUser( $wgTranslateFuzzyBotName );
 25+ $job->setUser( FuzzyBot::getUser() );
2826 $job->setFlags( EDIT_FORCE_BOT );
2927 $job->setSummary( wfMsgForContent( 'tpt-render-summary' ) );
3028
@@ -62,7 +60,7 @@
6361
6462 $article = new Article( $title, 0 );
6563
66 - // @todo Fuzzybot hack
 64+ // @todo FuzzyBot hack
6765 PageTranslationHooks::$allowTargetEdit = true;
6866
6967 // Do the edit
Index: trunk/extensions/Translate/tag/DeleteJob.php
@@ -25,10 +25,8 @@
2626 * @return DeleteJob
2727 */
2828 public static function newJob( Title $target, $base, $full, /*User*/ $performer ) {
29 - global $wgTranslateFuzzyBotName;
30 -
3129 $job = new self( $target );
32 - $job->setUser( $wgTranslateFuzzyBotName );
 30+ $job->setUser( FuzzyBot::getUser() );
3331 $job->setFull( $full );
3432 $job->setBase( $base );
3533 $msg = $job->getFull() ? 'pt-deletepage-full-logreason' : 'pt-deletepage-lang-logreason';
Index: trunk/extensions/Translate/tag/MoveJob.php
@@ -23,10 +23,8 @@
2424 * @return MoveJob
2525 */
2626 public static function newJob( Title $source, Title $target, array $params, /*User*/ $performer ) {
27 - global $wgTranslateFuzzyBotName;
28 -
2927 $job = new self( $source );
30 - $job->setUser( $wgTranslateFuzzyBotName );
 28+ $job->setUser( FuzzyBot::getUser() );
3129 $job->setTarget( $target->getPrefixedText() );
3230 $job->setSummary( wfMsgForContent( 'pt-movepage-logreason', $params['base-source'] ) );
3331 $job->setParams( $params );
Index: trunk/extensions/Translate/_autoload.php
@@ -94,6 +94,7 @@
9595 $wgAutoloadClasses['StringMangler'] = $dir . 'utils/StringMatcher.php';
9696 $wgAutoloadClasses['StringMatcher'] = $dir . 'utils/StringMatcher.php';
9797 $wgAutoloadClasses['FCFontFinder'] = $dir . 'utils/Font.php';
 98+$wgAutoloadClasses['FuzzyBot'] = $dir . 'utils/FuzzyBot.php';
9899
99100 $wgAutoloadClasses['TranslatePreferences'] = $dir . 'utils/UserToggles.php';
100101 $wgAutoloadClasses['TranslateToolbox'] = $dir . 'utils/ToolBox.php';
Index: trunk/extensions/Translate/utils/MessageWebImporter.php
@@ -434,7 +434,7 @@
435435
436436 // Edit with fuzzybot if there is no user.
437437 if ( !$user ) {
438 - $user = self::getFuzzyBot();
 438+ $user = FuzzyBot::getUser();
439439 }
440440
441441 // Process all rows.
@@ -474,21 +474,6 @@
475475 }
476476
477477 /**
478 - * @return User
479 - */
480 - public static function getFuzzyBot() {
481 - global $wgTranslateFuzzyBotName;
482 -
483 - $user = User::newFromName( $wgTranslateFuzzyBotName );
484 -
485 - if ( !$user->isLoggedIn() ) {
486 - $user->addToDatabase();
487 - }
488 -
489 - return $user;
490 - }
491 -
492 - /**
493478 * Given a group, message key and language code, creates a title for the
494479 * translation page.
495480 *

Follow-up revisions

RevisionCommit summaryAuthorDate
r107818I forgot to svn add the file again. ahoy r107816nikerabbit11:51, 2 January 2012
r107977MFT r107043, r107816, r107818reedy00:46, 4 January 2012
r108200Follow-up r107816: Update forgotten FuzzyBot reference.siebrand08:43, 6 January 2012

Comments

#Comment by Siebrand (talk | contribs)   11:50, 2 January 2012

You forgot to add utils/FuzzyBot.php.

Status & tagging log