r66839 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r66838‎ | r66839 | r66840 >
Date:17:42, 24 May 2010
Author:siebrand
Status:deferred
Tags:
Comment:
Unbreak fuzzy translations on manage groups page.
Modified paths:
  • /trunk/extensions/Translate/Translate.php (modified) (history)
  • /trunk/extensions/Translate/utils/MessageWebImporter.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/Translate.php
@@ -12,7 +12,7 @@
1313 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
1414 */
1515
16 -define( 'TRANSLATE_VERSION', '2010-05-15' );
 16+define( 'TRANSLATE_VERSION', '2010-05-24' );
1717
1818 $wgExtensionCredits['specialpage'][] = array(
1919 'path' => __FILE__,
Index: trunk/extensions/Translate/utils/MessageWebImporter.php
@@ -275,7 +275,7 @@
276276
277277 /**
278278 * Perform an action on a given group/key/code
279 - *
 279+ *
280280 * @param $action String: import/conflict/ignore
281281 * @param $group Object: group object
282282 * @param $key String: message key
@@ -305,7 +305,8 @@
306306 } elseif ( $action === 'fuzzy' && $code !== 'en' ) {
307307 $message = self::makeTextFuzzy( $message );
308308 return self::doImport( $title, $message, $comment, $user, $editFlags );
309 -
 309+ } elseif ( $action === 'fuzzy' && $code == 'en' ) {
 310+ return self::doFuzzy( $title, $message, $comment, $user, $editFlags );
310311 } else {
311312 throw new MWException( "Unhandled action $action" );
312313 }
@@ -330,15 +331,24 @@
331332 }
332333
333334 public static function doFuzzy( $title, $message, $comment, $user, $editFlags = 0 ) {
 335+ global $wgUser;
 336+
 337+ if ( !$wgUser->isAllowed( 'translate-manage' ) ) {
 338+ return wfMsg( 'badaccess-group0' );
 339+ }
 340+
334341 $dbw = wfGetDB( DB_MASTER );
335342
336 - $titleText = $title->getDBKey();
 343+ // Work on all subpages of base title.
 344+ $titleText = $title->getBaseText();
337345
338 - $condArray = array(
339 - 'page_namespace' => $title->getNamespace(),
 346+ $namespace = $title->getNamespace();
 347+ $titleText = $dbw->escapeLike( $titleText );
 348+ $conds= array(
 349+ 'page_namespace' => $namespace,
340350 'page_latest=rev_id',
341351 'rev_text_id=old_id',
342 - "page_title LIKE '{$dbw->escapeLike( $titleText )}/%%'"
 352+ 'page_title LIKE \'' . $titleText . '\/%\''
343353 );
344354
345355 $rows = $dbw->select(
@@ -348,18 +358,26 @@
349359 __METHOD__
350360 );
351361
352 - $changed = array();
353 -
 362+ // Edit with fuzzybot if there is no user.
354363 if ( !$user ) {
355364 $user = self::getFuzzyBot();
356365 }
357366
 367+ // Process all rows.
 368+ $changed = array();
358369 foreach ( $rows as $row ) {
359370 $ttitle = Title::makeTitle( $row->page_namespace, $row->page_title );
360371
361 - $text = Revision::getRevisionText( $row );
362 - $text = self::makeTextFuzzy( $text );
 372+ // No fuzzy for English original
 373+ if( $ttitle->getSubpageText() == 'en' ) {
 374+ // Use imported text, not database text.
 375+ $text = $message;
 376+ } else {
 377+ $text = Revision::getRevisionText( $row );
 378+ $text = self::makeTextFuzzy( $text );
 379+ }
363380
 381+ // Do actual import
364382 $changed[] = self::doImport(
365383 $ttitle,
366384 $text,
@@ -367,32 +385,13 @@
368386 $user,
369387 $editFlags
370388 );
371 -
372 - if ( $this->checkProcessTime() ) {
373 - break;
374 - }
375389 }
376390
377 - if ( count( $changed ) === count( $rows ) ) {
378 - $comment = wfMsgForContentNoTrans( 'translate-manage-import-summary' );
379 - // FIXME: Leftover of refactoring from SpecialManageGroups::doFuzzy()
380 - // Did not know what to do with this. Have to ask Nikerabbit.
381 - // Probably have to add an extra parameter, but this part should
382 - // have had a comment.
383 - // $title = Title::makeTitleSafe( $title->getNamespace(), $title->getPrefixedDbKey() . '/en' );
384 - $changed[] = self::doImport(
385 - $title,
386 - $message,
387 - $comment,
388 - $user,
389 - $editFlags
390 - );
391 - }
392 -
 391+ // Format return text
393392 $text = '';
394393 foreach ( $changed as $c ) {
395394 $key = array_shift( $c );
396 - $text = "* " . wfMsgExt( $key, array(), $c );
 395+ $text .= "* " . wfMsgExt( $key, array(), $c ) . "\n";
397396 }
398397
399398 return array( 'translate-manage-import-fuzzy', "\n" . $text );

Status & tagging log