Merge "(bug 46405) Fix errors in mw.title.new( pageid )"

This commit is contained in:
jenkins-bot 2013-03-24 20:57:26 +00:00 committed by Gerrit Code Review
commit 47e826d082
3 changed files with 22 additions and 9 deletions

View file

@ -6,7 +6,7 @@ class Scribunto_LuaTitleLibrary extends Scribunto_LuaLibraryBase {
// addition besides the one for the current page calls
// incrementExpensiveFunctionCount()
private $titleCache = array();
private $idCache = array();
private $idCache = array( 0 => null );
function register() {
$lib = array(
@ -58,13 +58,11 @@ class Scribunto_LuaTitleLibrary extends Scribunto_LuaLibraryBase {
* @return array Lua data
*/
private function returnTitleToLua( Title $title ) {
if ( !$title ) {
return array( null );
}
// Cache it
$this->titleCache[$title->getPrefixedDBkey()] = $title;
$this->idCache[$title->getArticleID()] = $title;
if ( $title->getArticleID() > 0 ) {
$this->idCache[$title->getArticleID()] = $title;
}
// Record a link
if ( $this->getParser() && !$title->equals( $this->getTitle() ) ) {
@ -116,6 +114,9 @@ class Scribunto_LuaTitleLibrary extends Scribunto_LuaLibraryBase {
$title = Title::newFromID( $text_or_id );
$this->idCache[$text_or_id] = $title;
}
if ( !$title ) {
return array( null );
}
} elseif ( $type === 'string' ) {
$this->checkNamespace( 'title.new', 2, $defaultNamespace, NS_MAIN );

View file

@ -55,7 +55,7 @@ class Scribunto_LuaTitleLibraryTests extends Scribunto_LuaEngineTestBase {
// Indicate to the tests that it's safe to create the title objects
$interpreter = $this->getEngine()->getInterpreter();
$interpreter->callFunction(
$interpreter->loadString( 'mw.ok = true', 'fortest' )
$interpreter->loadString( "mw.title.testPageId = {$page->getId()}", 'fortest' )
);
$this->setMwGlobals( array(

View file

@ -1,7 +1,7 @@
local testframework = require 'Module:TestFramework'
local title, title_copy, title2, title3, title4, title5, title4p
if mw.ok then
local title, title_copy, title2, title3, title4, title5, title6, title4p
if mw.title.testPageId then
title = mw.title.getCurrentTitle()
title_copy = mw.title.getCurrentTitle()
title2 = mw.title.new( 'Module:TestFramework' )
@ -119,6 +119,18 @@ local tests = {
args = { '<bad title>' },
expect = { nil }
},
{ name = 'title.new with nonexistent pageid', func = mw.title.new,
args = { -1 },
expect = { nil }
},
{ name = 'title.new with pageid 0', func = mw.title.new,
args = { 0 },
expect = { nil }
},
{ name = 'title.new with existing pageid', func = mw.title.new, type = 'ToString',
args = { mw.title.testPageId },
expect = { 'ScribuntoTestPage' }
},
{ name = 'title.makeTitle', func = mw.title.makeTitle, type = 'ToString',
args = { 'Module', 'TestFramework' },