jenkins-bot has submitted this change and it was merged.

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(-)

Approvals:
  Aaron Schulz: Looks good to me, approved
  jenkins-bot: Verified



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: merged
Gerrit-Change-Id: Id06d27c6283ee589a8830b78c04e56978e0ac6da
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Scribunto
Gerrit-Branch: master
Gerrit-Owner: Anomie <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Danny B. <[email protected]>
Gerrit-Reviewer: Tim Starling <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to