r107977 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107976‎ | r107977 | r107978 >
Date:00:46, 4 January 2012
Author:reedy
Status:ok (Comments)
Tags:
Comment:
Modified paths:
  • /branches/wmf/1.18wmf1/extensions (modified) (history)
  • /branches/wmf/1.18wmf1/extensions/Translate (modified) (history)
  • /branches/wmf/1.18wmf1/extensions/Translate/MessageCollection.php (modified) (history)
  • /branches/wmf/1.18wmf1/extensions/Translate/_autoload.php (modified) (history)
  • /branches/wmf/1.18wmf1/extensions/Translate/scripts/fuzzy.php (modified) (history)
  • /branches/wmf/1.18wmf1/extensions/Translate/scripts/languageeditstats.php (modified) (history)
  • /branches/wmf/1.18wmf1/extensions/Translate/scripts/sync-group.php (modified) (history)
  • /branches/wmf/1.18wmf1/extensions/Translate/tag/DeleteJob.php (modified) (history)
  • /branches/wmf/1.18wmf1/extensions/Translate/tag/MoveJob.php (modified) (history)
  • /branches/wmf/1.18wmf1/extensions/Translate/tag/RenderJob.php (modified) (history)
  • /branches/wmf/1.18wmf1/extensions/Translate/utils/FuzzyBot.php (added) (history)
  • /branches/wmf/1.18wmf1/extensions/Translate/utils/MessageWebImporter.php (modified) (history)
  • /branches/wmf/1.18wmf1/extensions/WebFonts/resources/ext.webfonts.js (modified) (history)

Diff [purge]

Index: branches/wmf/1.18wmf1/extensions/Translate/MessageCollection.php
@@ -132,8 +132,6 @@
133133 * @return \list{String} List of usernames.
134134 */
135135 public function getAuthors() {
136 - global $wgTranslateFuzzyBotName;
137 -
138136 $this->loadTranslations();
139137
140138 $authors = array_flip( $this->authors );
@@ -155,8 +153,9 @@
156154
157155 # arsort( $authors, SORT_NUMERIC );
158156 ksort( $authors );
 157+ $fuzzyBot = FuzzyBot::getName();
159158 foreach ( $authors as $author => $edits ) {
160 - if ( $author !== $wgTranslateFuzzyBotName ) {
 159+ if ( $author !== $fuzzyBot ) {
161160 $filteredAuthors[] = $author;
162161 }
163162 }
Index: branches/wmf/1.18wmf1/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: branches/wmf/1.18wmf1/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: branches/wmf/1.18wmf1/extensions/Translate/scripts/fuzzy.php
@@ -151,26 +151,6 @@
152152 }
153153
154154 /**
155 - * Create FuzzyBot user if necessary.
156 - * @return \type{User}
157 - */
158 - public function getImportUser() {
159 - static $user = null;
160 -
161 - if ( $user === null ) {
162 - global $wgTranslateFuzzyBotName;
163 - $user = User::newFromName( $wgTranslateFuzzyBotName );
164 -
165 - if ( !$user->isLoggedIn() ) {
166 - STDOUT( "Creating user $wgTranslateFuzzyBotName" );
167 - $user->addToDatabase();
168 - }
169 - }
170 -
171 - return $user;
172 - }
173 -
174 - /**
175155 * Does the actual edit if possible.
176156 * @param $title \type{Title}
177157 * @param $text \string
@@ -181,7 +161,7 @@
182162 global $wgTranslateDocumentationLanguageCode, $wgUser;
183163
184164 $oldUser = $wgUser;
185 - $wgUser = $this->getImportUser();
 165+ $wgUser = FuzzyBot::getUser();
186166
187167 STDOUT( "Updating {$title->getPrefixedText()}... ", $title );
188168 if ( !$title instanceof Title ) {
Index: branches/wmf/1.18wmf1/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: branches/wmf/1.18wmf1/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: branches/wmf/1.18wmf1/extensions/Translate/tag/MoveJob.php
@@ -24,10 +24,8 @@
2525 * @return MoveJob
2626 */
2727 public static function newJob( Title $source, Title $target, $base, /*User*/ $performer ) {
28 - global $wgTranslateFuzzyBotName;
29 -
3028 $job = new self( $source );
31 - $job->setUser( $wgTranslateFuzzyBotName );
 29+ $job->setUser( FuzzyBot::getUser() );
3230 $job->setTarget( $target->getPrefixedText() );
3331 $job->setSummary( wfMsgForContent( 'pt-movepage-logreason', $target->getPrefixedText() ) );
3432 $job->setBase( $base );
Index: branches/wmf/1.18wmf1/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: branches/wmf/1.18wmf1/extensions/Translate/utils/FuzzyBot.php
@@ -0,0 +1,29 @@
 2+<?php
 3+/**
 4+ * Do it all maintenance account
 5+ *
 6+ * @file
 7+ * @author Niklas Laxström
 8+ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2 or later
 9+ * @
 10+ */
 11+
 12+/**
 13+ * FuzzyBot - the misunderstood workhorse.
 14+ * @since 2012-01-02
 15+ */
 16+
 17+class FuzzyBot {
 18+ public static function getUser() {
 19+ $bot = User::newFromName( self::getName() );
 20+ if ( $bot->isAnon() ) {
 21+ $bot->addToDatabase();
 22+ }
 23+ return $bot;
 24+ }
 25+
 26+ public static function getName() {
 27+ global $wgTranslateFuzzyBotName;
 28+ return $wgTranslateFuzzyBotName;
 29+ }
 30+}
\ No newline at end of file
Property changes on: branches/wmf/1.18wmf1/extensions/Translate/utils/FuzzyBot.php
___________________________________________________________________
Added: svn:eol-style
131 + native
Index: branches/wmf/1.18wmf1/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 *
Property changes on: branches/wmf/1.18wmf1/extensions/Translate
___________________________________________________________________
Modified: svn:mergeinfo
496481 Merged /trunk/extensions/Translate:r107816,107818
Index: branches/wmf/1.18wmf1/extensions/WebFonts/resources/ext.webfonts.js
@@ -108,8 +108,7 @@
109109 fontFormats = [],
110110 version = fontconfig.version || "0.0",
111111 versionSuffix = "?version=" + version + '&20111213',
112 - styleString = "<style type='text/css'>"
113 - + "@font-face { font-family: '"+fontFamily+"';\n",
 112+ styleString = "@font-face { font-family: '"+fontFamily+"';\n",
114113 ua = navigator.userAgent;
115114
116115 if ( fontconfig.eot !== undefined ) {
@@ -140,10 +139,8 @@
141140 styleString += fontFormats.join() + ";\n";
142141 styleString += "\tfont-weight: normal;}";
143142
144 - styleString += "\n</style>\n";
145143 // inject the css to the head of the page.
146 - // mw.util.addCSS wont work with fontface, and crashes IE.
147 - $( styleString ).appendTo( 'head' );
 144+ mw.util.addCSS( styleString );
148145 },
149146
150147 /**
Property changes on: branches/wmf/1.18wmf1/extensions
___________________________________________________________________
Modified: svn:mergeinfo
151148 Merged /trunk/extensions:r107043,107783,107816,107818

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r107043Use mw.util.addCSS for adding css. Based on bug 33305, and fixed in r106992.santhosh08:49, 22 December 2011
r107816Move FuzzyBot code into new class so that the user is created when needed...nikerabbit11:10, 2 January 2012
r107818I forgot to svn add the file again. ahoy r107816nikerabbit11:51, 2 January 2012

Comments

#Comment by Nikerabbit (talk | contribs)   07:20, 4 January 2012

You forgot r107869. Doesn't matter much since nobody uses this script on the cluster.

Status & tagging log