diff --git a/engines/LuaCommon/TextLibrary.php b/engines/LuaCommon/TextLibrary.php index 468066c7..4de9919a 100644 --- a/engines/LuaCommon/TextLibrary.php +++ b/engines/LuaCommon/TextLibrary.php @@ -6,6 +6,8 @@ class Scribunto_LuaTextLibrary extends Scribunto_LuaLibraryBase { $lib = array( 'unstrip' => array( $this, 'textUnstrip' ), + 'unstripNoWiki' => array( $this, 'textUnstripNoWiki' ), + 'killMarkers' => array( $this, 'killMarkers' ), 'getEntityTable' => array( $this, 'getEntityTable' ), ); $opts = array( @@ -37,7 +39,18 @@ class Scribunto_LuaTextLibrary extends Scribunto_LuaLibraryBase { function textUnstrip( $s ) { $this->checkType( 'unstrip', 1, $s, 'string' ); - return array( $this->getParser()->mStripState->unstripBoth( $s ) ); + $stripState = $this->getParser()->mStripState; + return array( $stripState->killMarkers( $stripState->unstripNoWiki( $s ) ) ); + } + + function textUnstripNoWiki( $s ) { + $this->checkType( 'unstripNoWiki', 1, $s, 'string' ); + return array( $this->getParser()->mStripState->unstripNoWiki( $s ) ); + } + + function killMarkers( $s ) { + $this->checkType( 'killMarkers', 1, $s, 'string' ); + return array( $this->getParser()->mStripState->killMarkers( $s ) ); } function getEntityTable() { diff --git a/engines/LuaCommon/lualib/mw.text.lua b/engines/LuaCommon/lualib/mw.text.lua index 248a442c..b6b4c488 100644 --- a/engines/LuaCommon/lualib/mw.text.lua +++ b/engines/LuaCommon/lualib/mw.text.lua @@ -199,6 +199,14 @@ function mwtext.unstrip( s ) return php.unstrip( s ) end +function mwtext.unstripNoWiki( s ) + return php.unstripNoWiki( s ) +end + +function mwtext.killMarkers( s ) + return php.killMarkers( s ) +end + function mwtext.split( text, pattern, plain ) local ret = {} for m in mwtext.gsplit( text, pattern, plain ) do diff --git a/tests/engines/LuaCommon/TextLibraryTest.php b/tests/engines/LuaCommon/TextLibraryTest.php index ac31e464..2e2285ff 100644 --- a/tests/engines/LuaCommon/TextLibraryTest.php +++ b/tests/engines/LuaCommon/TextLibraryTest.php @@ -7,10 +7,17 @@ class Scribunto_LuaTextLibraryTests extends Scribunto_LuaEngineTestBase { parent::setUp(); // For unstrip test + $parser = $this->getEngine()->getParser(); + $markers = array( + 'nowiki' => $parser->uniqPrefix() . '-test-nowiki-' . Parser::MARKER_SUFFIX, + 'general' => $parser->uniqPrefix() . '-test-general-' . Parser::MARKER_SUFFIX, + ); + $parser->mStripState->addNoWiki( $markers['nowiki'], 'NoWiki' ); + $parser->mStripState->addGeneral( $markers['general'], 'General' ); $interpreter = $this->getEngine()->getInterpreter(); $interpreter->callFunction( $interpreter->loadString( 'mw.text.stripTest = ...', 'fortest' ), - $this->getEngine()->getParser()->insertStripItem( 'ok' ) + $markers ); } diff --git a/tests/engines/LuaCommon/TextLibraryTests.lua b/tests/engines/LuaCommon/TextLibraryTests.lua index d1fa6838..65eb05c4 100644 --- a/tests/engines/LuaCommon/TextLibraryTests.lua +++ b/tests/engines/LuaCommon/TextLibraryTests.lua @@ -13,6 +13,19 @@ setmetatable( tagattrs, { __pairs = function ( t ) end end } ) +-- For data provider, make sure this is defined +mw.text.stripTest = mw.text.stripTest or { nowiki = '!!!', general = '!!!' } + +-- Can't directly expect the value from mw.text.stripTest, because when +-- 'expect' is processed by the data provider it's the dummy entry above. +local function stripTest( func, marker ) + local result = func( marker ) + if result == marker then + result = 'strip-marker' + end + return result +end + -- Tests local tests = { { name = 'trim', @@ -107,9 +120,32 @@ local tests = { expect = { 'foo' } }, - { name = 'unstrip', - func = mw.text.unstrip, args = { mw.text.stripTest }, - expect = { 'ok' } + { name = 'unstrip (nowiki)', + func = stripTest, + args = { mw.text.unstrip, mw.text.stripTest.nowiki }, + expect = { 'NoWiki' } + }, + { name = 'unstrip (general)', + func = stripTest, + args = { mw.text.unstrip, mw.text.stripTest.general }, + expect = { '' } + }, + + { name = 'unstripNoWiki (nowiki)', + func = stripTest, + args = { mw.text.unstripNoWiki, mw.text.stripTest.nowiki }, + expect = { 'NoWiki' } + }, + { name = 'unstripNoWiki (general)', + func = stripTest, + args = { mw.text.unstripNoWiki, mw.text.stripTest.general }, + expect = { 'strip-marker' } + }, + + { name = 'killMarkers', + func = mw.text.killMarkers, + args = { 'a' .. mw.text.stripTest.nowiki .. 'b' .. mw.text.stripTest.general .. 'c' }, + expect = { 'abc' } }, { name = 'split, simple',