jenkins-bot has submitted this change and it was merged.
Change subject: Add mw.text.unstripNoWiki, mw.text.killMarkers, fix
mw.text.unstrip
......................................................................
Add mw.text.unstripNoWiki, mw.text.killMarkers, fix mw.text.unstrip
mw.text.unstrip is too broad, it's allowing for unstripping things that
cause problems when unstripped (e.g. bug 61268). Since the original
request was only for unstripping <nowiki>, let's add a function that
does only that.
We should also add an interface to StripState::killMarkers(), instead of
requiring everyone to roll their own work-alike.
Then, to fix the bug, we can make mw.text.unstrip be the combination of
the two. This is the most like the original behavior of mw.text.unstrip
(removes all strip markers, replacing them with text where applicable)
without causing issues.
Bug: 61268
Change-Id: I3a151fd678b365d629b71b4f1cb0d5d284b98555
(cherry picked from commit e5564cf9420c438799f27f84da45a5cd13ce44b7)
---
M engines/LuaCommon/TextLibrary.php
M engines/LuaCommon/lualib/mw.text.lua
M tests/engines/LuaCommon/TextLibraryTest.php
M tests/engines/LuaCommon/TextLibraryTests.lua
4 files changed, 69 insertions(+), 5 deletions(-)
Approvals:
MarkAHershberger: Looks good to me, approved
jenkins-bot: Verified
diff --git a/engines/LuaCommon/TextLibrary.php
b/engines/LuaCommon/TextLibrary.php
index 37a2103..d988f15 100644
--- a/engines/LuaCommon/TextLibrary.php
+++ b/engines/LuaCommon/TextLibrary.php
@@ -6,6 +6,8 @@
$lib = array(
'unstrip' => array( $this, 'textUnstrip' ),
+ 'unstripNoWiki' => array( $this, 'textUnstripNoWiki' ),
+ 'killMarkers' => array( $this, 'killMarkers' ),
'getEntityTable' => array( $this, 'getEntityTable' ),
);
$opts = array(
@@ -37,7 +39,18 @@
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 0191442..0b1cdba 100644
--- a/engines/LuaCommon/lualib/mw.text.lua
+++ b/engines/LuaCommon/lualib/mw.text.lua
@@ -199,6 +199,14 @@
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 928bb75..9da213b 100644
--- a/tests/engines/LuaCommon/TextLibraryTest.php
+++ b/tests/engines/LuaCommon/TextLibraryTest.php
@@ -7,10 +7,17 @@
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 f07bd74..30fcc4f 100644
--- a/tests/engines/LuaCommon/TextLibraryTests.lua
+++ b/tests/engines/LuaCommon/TextLibraryTests.lua
@@ -13,6 +13,19 @@
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 @@
expect = { '<b present key="value" n="42">foo</b>' }
},
- { 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',
--
To view, visit https://gerrit.wikimedia.org/r/180440
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I3a151fd678b365d629b71b4f1cb0d5d284b98555
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Scribunto
Gerrit-Branch: REL1_22
Gerrit-Owner: Mglaser <[email protected]>
Gerrit-Reviewer: Anomie <[email protected]>
Gerrit-Reviewer: Jackmcbarn <[email protected]>
Gerrit-Reviewer: MarkAHershberger <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits