r37692 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r37691‎ | r37692 | r37693 >
Date:14:07, 15 July 2008
Author:nikerabbit
Status:old
Tags:
Comment:
* 2008-07-14:2 new check for unaltered namespaces in pagename messages of MediaWiki
* make cache more effective
Modified paths:
  • /trunk/extensions/Translate/MessageChecks.php (modified) (history)
  • /trunk/extensions/Translate/README (modified) (history)
  • /trunk/extensions/Translate/Translate.php (modified) (history)
  • /trunk/extensions/Translate/TranslateUtils.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/Translate.php
@@ -11,7 +11,7 @@
1212 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
1313 */
1414
15 -define( 'TRANSLATE_VERSION', '9 (2008-07-15:1)' );
 15+define( 'TRANSLATE_VERSION', '9 (2008-07-15:2)' );
1616
1717 $wgExtensionCredits['specialpage'][] = array(
1818 'name' => 'Translate',
Index: trunk/extensions/Translate/MessageChecks.php
@@ -13,12 +13,13 @@
1414 // Fastest first
1515 var $checksForType = array(
1616 'mediawiki' => array(
17 - 'checkPlural',
 17+ /*'checkPlural',
1818 'checkParameters',
1919 'checkUnknownParameters',
2020 'checkBalance',
2121 'checkLinks',
22 - 'checkXHTML',
 22+ 'checkXHTML',*/
 23+ 'checkPagename',
2324 ),
2425 'freecol' => array(
2526 'checkFreeColMissingVars',
@@ -271,6 +272,28 @@
272273 }
273274
274275
 276+ /**
 277+ * Checks for page names having untranslated namespace.
 278+ *
 279+ * @param $message Instance of TMessage.
 280+ * @return True if namespace has been tampered with.
 281+ */
 282+ protected function checkPagename( TMessage $message, $code, &$desc = null ) {
 283+ $definition = $message->definition;
 284+ $translation = $message->translation;
 285+
 286+ $namespaces = 'help|project|\{\{ns:project}}|mediawiki';
 287+ $matches = array();
 288+ if ( preg_match( "/^($namespaces):[\w\s]+$/ui", $definition, $matches ) ) {
 289+ if ( !preg_match( "/^{$matches[1]}:.+$/u", $translation) ) {
 290+ $desc = array( 'translate-checks-pagename' );
 291+ return true;
 292+ }
 293+ }
 294+ return false;
 295+ }
 296+
 297+
275298 protected function checkFreeColMissingVars( TMessage $message, $code, &$desc = null ) {
276299 if ( !preg_match_all( '/%[^% ]+%/U', $message->definition, $defVars ) ) {
277300 return false;
Index: trunk/extensions/Translate/README
@@ -34,7 +34,8 @@
3535
3636 == Changes in version 10 ==
3737
38 -* 2008-07-14:1
 38+* 2008-07-15:2 new check for unaltered namespaces in pagename messages of MediaWiki
 39+* 2008-07-15:1
3940 - improved message checks
4041 - can now work for meta groups too
4142 - fixed messages not shown in the list anymore, but script still needed to find
Index: trunk/extensions/Translate/TranslateUtils.php
@@ -23,7 +23,7 @@
2424
2525 // Cache some amount of titles for speed
2626 static $cache = array();
27 - if ( count($cache)>500 ) $cache = array();
 27+ if ( count($cache)>5000 ) $cache = array();
2828 if ( !isset($cache[$message]) ) {
2929 $cache[$message] = $wgContLang->ucfirst($message);
3030 }

Status & tagging log