r85131 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85130‎ | r85131 | r85132 >
Date:16:07, 1 April 2011
Author:maxsem
Status:reverted (Comments)
Tags:
Comment:
Translate: check for bug 28152 (Special:Preferences explode if some messages are the same)
Modified paths:
  • /trunk/extensions/Translate/MessageGroups.php (modified) (history)
  • /trunk/extensions/Translate/Translate.i18n.php (modified) (history)
  • /trunk/extensions/Translate/groups/MediaWiki/Checker.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/MessageGroups.php
@@ -353,7 +353,8 @@
354354 array( $checker, 'XhtmlCheck' ),
355355 array( $checker, 'braceBalanceCheck' ),
356356 array( $checker, 'pagenameMessagesCheck' ),
357 - array( $checker, 'miscMWChecks' )
 357+ array( $checker, 'miscMWChecks' ),
 358+ array( $checker, 'prefMessagesCheck' ),
358359 ) );
359360
360361 return $checker;
Index: trunk/extensions/Translate/groups/MediaWiki/Checker.php
@@ -247,4 +247,65 @@
248248 }
249249 }
250250 }
 251+
 252+ /**
 253+ * Checks that messages used for some preferences are not equal, otherwise Special:Preferences may explode
 254+ * (bug 28152).
 255+ *
 256+ * @param $messages \array Iterable list of TMessage objects.
 257+ * @param $code \string Language code of the translations.
 258+ * @param $warnings \array Array where warnings are appended to.
 259+ */
 260+ protected function prefMessagesCheck( $messages, $code, &$warnings ) {
 261+ $prefs = self::getPrefMessages();
 262+
 263+ foreach ( $messages as $message ) {
 264+ foreach ( $prefs as $group ) {
 265+ if ( !in_array( $message->key(), $group ) ) {
 266+ continue;
 267+ }
 268+ $conflicts = array();
 269+ foreach ( $group as $key ) {
 270+ if ( $key == $message->key() ) {
 271+ continue;
 272+ }
 273+ if ( $message->translation() == wfMessage( $key )->inLanguage( $code )->text() ) {
 274+ $conflicts[] = $key;
 275+ }
 276+ }
 277+ if ( count( $conflicts ) ) {
 278+ $conflicts = preg_replace( '/^(.*)$/', "[[MediaWiki:$1/$code|$1]]", $conflicts );
 279+ global $wgLang;
 280+ $warnings[$message->key()][] = array(
 281+ array( 'prefmessages', 'match', $message->key(), $code ),
 282+ 'translate-checks-prefs',
 283+ $wgLang->listToText( $conflicts ),
 284+ );
 285+ }
 286+ }
 287+ }
 288+ }
 289+
 290+ /**
 291+ * Returns an array of message keys that may cause conflicts for prefMessagesCheck()
 292+ * @return \array
 293+ */
 294+ protected static function getPrefMessages() {
 295+ // @todo: moar?
 296+ return array(
 297+ array(
 298+ 'Mw_math_png',
 299+ 'Mw_math_simple',
 300+ 'Mw_math_html',
 301+ 'Mw_math_source',
 302+ 'Mw_math_modern',
 303+ 'Mw_math_mathml',
 304+ ),
 305+ array(
 306+ 'Gender-male',
 307+ 'Gender-female',
 308+ 'Gender-unknown',
 309+ ),
 310+ );
 311+ }
251312 }
Index: trunk/extensions/Translate/Translate.i18n.php
@@ -145,6 +145,7 @@
146146 'translate-checks-format' => 'This translation does not follow the definition or has invalid syntax: $1',
147147 'translate-checks-escape' => 'The following escapes may be accidental: <strong>$1</strong>',
148148 'translate-checks-fudforum-syntax' => 'Use <nowiki>$1</nowiki> instead of <nowiki>$2</nowiki> in this project.',
 149+ 'translate-checks-prefs' => 'Message conflicts with $1. These messages must not be the same.',
149150
150151 'translate-pref-nonewsletter' => 'Do not send me e-mail newsletters',
151152 'translate-pref-editassistlang' => 'Assistant languages:',

Follow-up revisions

RevisionCommit summaryAuthorDate
r97844Backing out r85131 for now. See CR for the reasons.nikerabbit20:02, 22 September 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r84449Add warnings about how the math options must all be different; two of these b...catrope14:56, 21 March 2011

Comments

#Comment by Nikerabbit (talk | contribs)   17:09, 1 April 2011

That looks awfully slow. For each and every message it executes 2x in_array(), after which it calls wfMessage multiple times, transforms the message texts and uses == for comparison.

Besides, using wfMessage() will fail once we no longer user mediawiki-namespace for mediawiki translations. I don't think this is the right approach.

#Comment by Happy-melon (talk | contribs)   17:19, 1 April 2011

Besides, using wfMessage() will fail once we no longer user mediawiki-namespace for mediawiki translations.

When do we plan to do that?!?

#Comment by Nikerabbit (talk | contribs)   17:31, 1 April 2011

we = twn and as soon as I have time to look at it.

#Comment by MaxSem (talk | contribs)   19:31, 1 April 2011

So what would be the proper way to get message content?

#Comment by Nikerabbit (talk | contribs)   19:54, 22 September 2011

We will definitely need something like this. However the check system is not really good for this. Besides, messages can also be customised in Mediawiki-namespace, and this will not prevent that.

Status & tagging log