jenkins-bot has submitted this change and it was merged. Change subject: fix variable scope (version 0.3.1) ......................................................................
fix variable scope (version 0.3.1) Before this change, the variables behave like static Change-Id: I4af1034a3ccfb822d6b4e0474bb6ba9a90c43be1 --- M Foxway.body.php M Foxway.php M includes/Interpreter.php M includes/Runtime.php 4 files changed, 21 insertions(+), 7 deletions(-) Approvals: Pastakhov: Looks good to me, approved jenkins-bot: Verified diff --git a/Foxway.body.php b/Foxway.body.php index c21cd37..97c0055 100644 --- a/Foxway.body.php +++ b/Foxway.body.php @@ -9,6 +9,8 @@ */ class Foxway { + static $frames=array(); + /** * Render function used in hook ParserFirstCallInit * @@ -47,6 +49,7 @@ $result = Foxway\Interpreter::run( $input, array_merge((array)$frame->getTitle()->getPrefixedText(),$frame->getArguments()), + self::getScope($frame), $is_debug ); @@ -87,4 +90,15 @@ $parser->mStripState->addNoWiki( $rnd, $text ); return $rnd; } + + private static function getScope(PPFrame $frame) { + foreach (self::$frames as $value) { + if( $value[0] === $frame ) { + return $value[1]; + } + } + $scope=count(self::$frames); + self::$frames[] = array($frame, $scope); + return $scope; + } } \ No newline at end of file diff --git a/Foxway.php b/Foxway.php index 896ea82..3ce54f1 100644 --- a/Foxway.php +++ b/Foxway.php @@ -15,7 +15,7 @@ die( 'This file is an extension to MediaWiki and thus not a valid entry point.' ); } -define( 'Foxway_VERSION' , '0.3.0' ); +define( 'Foxway_VERSION' , '0.3.1' ); // Register this extension on Special:Version $wgExtensionCredits['parserhook'][] = array( diff --git a/includes/Interpreter.php b/includes/Interpreter.php index 15831b0..34ea40a 100644 --- a/includes/Interpreter.php +++ b/includes/Interpreter.php @@ -107,7 +107,7 @@ T_SR_EQUAL, ); - public static function run($source, array $args=array(), $is_debug=false) { + public static function run($source, array $args=array(), $scope='', $is_debug=false) { $tokens = self::getTokens($source); $return = array(); @@ -123,9 +123,9 @@ $tokenLine = 1; if( $debug ) { - $runtime = new RuntimeDebug( $args ); + $runtime = new RuntimeDebug( $args, $scope ); } else { - $runtime = new Runtime( $args ); + $runtime = new Runtime( $args, $scope ); } $operators = $runtime->getOperators(); diff --git a/includes/Runtime.php b/includes/Runtime.php index 3eb88ef..5fa1b12 100644 --- a/includes/Runtime.php +++ b/includes/Runtime.php @@ -9,7 +9,6 @@ * @licence GNU General Public Licence 2.0 or later */ class Runtime { - protected $args; protected $lastCommand = false; @@ -31,6 +30,8 @@ protected $stack = array(); protected static $variables = array(); protected $thisVariables; + protected $args; + protected $scope; // @see http://www.php.net/manual/ru/language.operators.precedence.php protected static $operatorsPrecedence = array( @@ -61,9 +62,8 @@ ); private $countPrecedences; - public function __construct( array $args ) { + public function __construct( array $args, $scope ) { $this->args = $args; - $scope = isset($args[0]) ? $args[0] : ''; if( !isset(self::$variables[$scope]) ) { self::$variables[$scope] = array(); } -- To view, visit https://gerrit.wikimedia.org/r/65654 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I4af1034a3ccfb822d6b4e0474bb6ba9a90c43be1 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Foxway Gerrit-Branch: master Gerrit-Owner: Pastakhov <pastak...@yandex.ru> Gerrit-Reviewer: Pastakhov <pastak...@yandex.ru> Gerrit-Reviewer: jenkins-bot _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits