Fixes for LanguageConverter::parseCachedTable() (seems really broken for subpages...
authorAlexandre Emsenhuber <ialex@users.mediawiki.org>
Sat, 26 Nov 2011 15:12:23 +0000 (15:12 +0000)
committerAlexandre Emsenhuber <ialex@users.mediawiki.org>
Sat, 26 Nov 2011 15:12:23 +0000 (15:12 +0000)
* Use Revsion::newFromTitle() to get the text instead of Article, avoids interference with "oldid" URL parameter. Also Article::getContents() (with final "s") does not exist and would throw a fatal error.
* Check if $subpage is empty before using the message cache instead of '/' in $code
* Early return if the page contains no text

languages/LanguageConverter.php

index a0e17ba..38d1ab6 100644 (file)
@@ -889,26 +889,26 @@ class LanguageConverter {
                        return array();
                }
 
-               if ( strpos( $code, '/' ) === false ) {
-                       $txt = MessageCache::singleton()->get( 'Conversiontable', true, $code );
-                       if ( $txt === false ) {
-                               # @todo FIXME: This method doesn't seem to be expecting
-                               # this possible outcome...
-                               $txt = '&lt;Conversiontable&gt;';
-                       }
+               $parsed[$key] = true;
+
+               if ( $subpage === '' ) {
+                       $txt = MessageCache::singleton()->get( 'conversiontable', true, $code );
                } else {
-                       $title = Title::makeTitleSafe(
-                               NS_MEDIAWIKI,
-                               "Conversiontable/$code"
-                       );
+                       $txt = false;
+                       $title = Title::makeTitleSafe( NS_MEDIAWIKI, $key );
                        if ( $title && $title->exists() ) {
-                               $article = new Article( $title );
-                               $txt = $article->getContents();
-                       } else {
-                               $txt = '';
+                               $revision = Revision::newFromTitle( $title );
+                               if ( $revision ) {
+                                       $txt = $revision->getRawText();
+                               }
                        }
                }
 
+               # Nothing to parse if there's no text
+               if ( $txt === false || $txt === null || $txt === '' ) {
+                       return array();
+               }
+
                // get all subpage links of the form
                // [[MediaWiki:Conversiontable/zh-xx/...|...]]
                $linkhead = $this->mLangObj->getNsText( NS_MEDIAWIKI ) .
@@ -957,7 +957,6 @@ class LanguageConverter {
                                $ret[trim( $m[0] )] = trim( $tt[0] );
                        }
                }
-               $parsed[$key] = true;
 
                // recursively parse the subpages
                if ( $recursive ) {