Anomie has uploaded a new change for review.
https://gerrit.wikimedia.org/r/93019
Change subject: Add mw.isSubsting()
......................................................................
Add mw.isSubsting()
It's already possible to detect whether the current template is being
substituted via ParserFunctions (see [[en:Template:Ifsubst]]), and a
similar trick works with frame:preprocess. So we may as well provide the
flag directly.
Bug: 47828
Change-Id: Id06d27c6283ee589a8830b78c04e56978e0ac6da
---
M engines/LuaCommon/LuaCommon.php
M engines/LuaCommon/lualib/mw.lua
M tests/engines/LuaCommon/luaParserTests.txt
3 files changed, 38 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Scribunto
refs/changes/19/93019/1
diff --git a/engines/LuaCommon/LuaCommon.php b/engines/LuaCommon/LuaCommon.php
index 3cd7ea6..879a147 100644
--- a/engines/LuaCommon/LuaCommon.php
+++ b/engines/LuaCommon/LuaCommon.php
@@ -80,6 +80,7 @@
'callParserFunction',
'preprocess',
'incrementExpensiveFunctionCount',
+ 'isSubsting',
);
$lib = array();
@@ -570,6 +571,16 @@
return null;
}
+ /**
+ * Return whether the parser is currently substing
+ *
+ * @return array
+ */
+ public function isSubsting() {
+ // See Parser::braceSubstitution, OT_WIKI is the switch
+ return array( $this->getParser()->OutputType() ===
Parser::OT_WIKI );
+ }
+
function doCachedExpansion( $frame, $input, $cacheKey ) {
$hash = md5( serialize( $cacheKey ) );
if ( !isset( $this->expandCache[$hash] ) ) {
diff --git a/engines/LuaCommon/lualib/mw.lua b/engines/LuaCommon/lualib/mw.lua
index 6c2fc59..8d342ef 100644
--- a/engines/LuaCommon/lualib/mw.lua
+++ b/engines/LuaCommon/lualib/mw.lua
@@ -675,6 +675,10 @@
return currentFrame
end
+function mw.isSubsting()
+ return php.isSubsting()
+end
+
function mw.incrementExpensiveFunctionCount()
php.incrementExpensiveFunctionCount()
end
diff --git a/tests/engines/LuaCommon/luaParserTests.txt
b/tests/engines/LuaCommon/luaParserTests.txt
index ba79bab..f271cf8 100644
--- a/tests/engines/LuaCommon/luaParserTests.txt
+++ b/tests/engines/LuaCommon/luaParserTests.txt
@@ -133,6 +133,10 @@
return '\0'
end
+function p.isSubsting( frame )
+ return tostring( mw.isSubsting() )
+end
+
return p
!! endarticle
@@ -362,3 +366,22 @@
<p>�
</p>
!! end
+
+!! test
+Scribunto: isSubsting during PST
+!! options
+pst
+!! input
+{{safesubst:#invoke:test|isSubsting}}
+!! result
+true
+!! end
+
+!! test
+Scribunto: isSubsting during normal parse
+!! input
+{{safesubst:#invoke:test|isSubsting}}
+!! result
+<p>false
+</p>
+!! end
--
To view, visit https://gerrit.wikimedia.org/r/93019
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Id06d27c6283ee589a8830b78c04e56978e0ac6da
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Scribunto
Gerrit-Branch: master
Gerrit-Owner: Anomie <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits