mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Scribunto
synced 2024-11-12 01:11:55 +00:00
(bug 46405) Fix errors in mw.title.new( pageid )
mw.title.new( pageid ) should not throw an error for an nonexisting pageid, just return nil. Similarly, it should always return nil for 0, rather than returning the last non-existent title created. Change-Id: I3cdbb24fc785aef0f8e75fba1feccd26ac5b7370
This commit is contained in:
parent
1735af7847
commit
3d4a81653c
|
@ -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 );
|
||||
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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' },
|
||||
|
|
Loading…
Reference in a new issue