From bf6e3a7b44a3303d8019350fca122b3c4d16cd1d Mon Sep 17 00:00:00 2001
From: "wiki@winston"
Date: Tue, 29 May 2018 06:34:23 +0000
Subject: add 'Variables' extension
---
extensions/Variables/.gitignore | 7 +
extensions/Variables/.gitreview | 5 +
extensions/Variables/CODE_OF_CONDUCT.md | 1 +
extensions/Variables/COPYING | 16 +
extensions/Variables/Gruntfile.js | 29 ++
extensions/Variables/README | 19 ++
extensions/Variables/RELEASE-NOTES | 88 +++++
extensions/Variables/Variables.i18n.magic.php | 22 ++
extensions/Variables/Variables.php | 375 +++++++++++++++++++++
extensions/Variables/Variables.settings.php | 29 ++
extensions/Variables/gitinfo.json | 1 +
extensions/Variables/i18n/ast.json | 8 +
extensions/Variables/i18n/be-tarask.json | 9 +
extensions/Variables/i18n/de.json | 9 +
extensions/Variables/i18n/dsb.json | 8 +
extensions/Variables/i18n/el.json | 8 +
extensions/Variables/i18n/en.json | 8 +
extensions/Variables/i18n/es.json | 8 +
extensions/Variables/i18n/fa.json | 8 +
extensions/Variables/i18n/fr.json | 8 +
extensions/Variables/i18n/gl.json | 8 +
extensions/Variables/i18n/he.json | 8 +
extensions/Variables/i18n/hsb.json | 8 +
extensions/Variables/i18n/ia.json | 8 +
extensions/Variables/i18n/it.json | 8 +
extensions/Variables/i18n/ja.json | 8 +
extensions/Variables/i18n/ko.json | 8 +
extensions/Variables/i18n/ksh.json | 8 +
extensions/Variables/i18n/lb.json | 8 +
extensions/Variables/i18n/lij.json | 8 +
extensions/Variables/i18n/mk.json | 8 +
extensions/Variables/i18n/ms.json | 8 +
extensions/Variables/i18n/nl.json | 8 +
extensions/Variables/i18n/oc.json | 8 +
extensions/Variables/i18n/pl.json | 8 +
extensions/Variables/i18n/pms.json | 9 +
extensions/Variables/i18n/pt-br.json | 8 +
extensions/Variables/i18n/pt.json | 8 +
extensions/Variables/i18n/qqq.json | 10 +
extensions/Variables/i18n/roa-tara.json | 8 +
extensions/Variables/i18n/ru.json | 8 +
extensions/Variables/i18n/sv.json | 8 +
extensions/Variables/i18n/tl.json | 8 +
extensions/Variables/i18n/uk.json | 8 +
extensions/Variables/i18n/zh-hans.json | 8 +
extensions/Variables/i18n/zh-hant.json | 4 +
extensions/Variables/package.json | 12 +
.../Variables/tests/mwparsertests/Variables.txt | 49 +++
extensions/Variables/version | 4 +
49 files changed, 938 insertions(+)
create mode 100644 extensions/Variables/.gitignore
create mode 100644 extensions/Variables/.gitreview
create mode 100644 extensions/Variables/CODE_OF_CONDUCT.md
create mode 100644 extensions/Variables/COPYING
create mode 100644 extensions/Variables/Gruntfile.js
create mode 100644 extensions/Variables/README
create mode 100644 extensions/Variables/RELEASE-NOTES
create mode 100644 extensions/Variables/Variables.i18n.magic.php
create mode 100644 extensions/Variables/Variables.php
create mode 100644 extensions/Variables/Variables.settings.php
create mode 100644 extensions/Variables/gitinfo.json
create mode 100644 extensions/Variables/i18n/ast.json
create mode 100644 extensions/Variables/i18n/be-tarask.json
create mode 100644 extensions/Variables/i18n/de.json
create mode 100644 extensions/Variables/i18n/dsb.json
create mode 100644 extensions/Variables/i18n/el.json
create mode 100644 extensions/Variables/i18n/en.json
create mode 100644 extensions/Variables/i18n/es.json
create mode 100644 extensions/Variables/i18n/fa.json
create mode 100644 extensions/Variables/i18n/fr.json
create mode 100644 extensions/Variables/i18n/gl.json
create mode 100644 extensions/Variables/i18n/he.json
create mode 100644 extensions/Variables/i18n/hsb.json
create mode 100644 extensions/Variables/i18n/ia.json
create mode 100644 extensions/Variables/i18n/it.json
create mode 100644 extensions/Variables/i18n/ja.json
create mode 100644 extensions/Variables/i18n/ko.json
create mode 100644 extensions/Variables/i18n/ksh.json
create mode 100644 extensions/Variables/i18n/lb.json
create mode 100644 extensions/Variables/i18n/lij.json
create mode 100644 extensions/Variables/i18n/mk.json
create mode 100644 extensions/Variables/i18n/ms.json
create mode 100644 extensions/Variables/i18n/nl.json
create mode 100644 extensions/Variables/i18n/oc.json
create mode 100644 extensions/Variables/i18n/pl.json
create mode 100644 extensions/Variables/i18n/pms.json
create mode 100644 extensions/Variables/i18n/pt-br.json
create mode 100644 extensions/Variables/i18n/pt.json
create mode 100644 extensions/Variables/i18n/qqq.json
create mode 100644 extensions/Variables/i18n/roa-tara.json
create mode 100644 extensions/Variables/i18n/ru.json
create mode 100644 extensions/Variables/i18n/sv.json
create mode 100644 extensions/Variables/i18n/tl.json
create mode 100644 extensions/Variables/i18n/uk.json
create mode 100644 extensions/Variables/i18n/zh-hans.json
create mode 100644 extensions/Variables/i18n/zh-hant.json
create mode 100644 extensions/Variables/package.json
create mode 100644 extensions/Variables/tests/mwparsertests/Variables.txt
create mode 100644 extensions/Variables/version
(limited to 'extensions')
diff --git a/extensions/Variables/.gitignore b/extensions/Variables/.gitignore
new file mode 100644
index 00000000..e62fc28b
--- /dev/null
+++ b/extensions/Variables/.gitignore
@@ -0,0 +1,7 @@
+node_modules/
+vendor/
+
+.svn
+*~
+*.kate-swp
+.*.swp
diff --git a/extensions/Variables/.gitreview b/extensions/Variables/.gitreview
new file mode 100644
index 00000000..70796b30
--- /dev/null
+++ b/extensions/Variables/.gitreview
@@ -0,0 +1,5 @@
+[gerrit]
+host=gerrit.wikimedia.org
+port=29418
+project=mediawiki/extensions/Variables.git
+track=1
diff --git a/extensions/Variables/CODE_OF_CONDUCT.md b/extensions/Variables/CODE_OF_CONDUCT.md
new file mode 100644
index 00000000..d8e5d087
--- /dev/null
+++ b/extensions/Variables/CODE_OF_CONDUCT.md
@@ -0,0 +1 @@
+The development of this software is covered by a [Code of Conduct](https://www.mediawiki.org/wiki/Code_of_Conduct).
diff --git a/extensions/Variables/COPYING b/extensions/Variables/COPYING
new file mode 100644
index 00000000..de01985a
--- /dev/null
+++ b/extensions/Variables/COPYING
@@ -0,0 +1,16 @@
+Copyright (c) 2006 - 2007 by Rob Adams
+Copyright (c) 2007 by Tom Hempel
+Copyright (c) 2008 by Xiloynaha
+Copyright (c) 2009 - 2012 by Daniel Werner < danweetz@web.de >
+
+Permission to use, copy, modify, and/or distribute this software for any
+purpose with or without fee is hereby granted, provided that the above
+copyright notice and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
diff --git a/extensions/Variables/Gruntfile.js b/extensions/Variables/Gruntfile.js
new file mode 100644
index 00000000..2db815fa
--- /dev/null
+++ b/extensions/Variables/Gruntfile.js
@@ -0,0 +1,29 @@
+/*jshint node:true */
+module.exports = function ( grunt ) {
+ grunt.loadNpmTasks( 'grunt-jsonlint' );
+ grunt.loadNpmTasks( 'grunt-contrib-jshint' );
+ grunt.loadNpmTasks( 'grunt-banana-checker' );
+
+ grunt.initConfig( {
+ banana: {
+ all: 'i18n/'
+ },
+ jshint: {
+ all: [
+ '**/*.js',
+ '!node_modules/**',
+ '!vendor/**'
+ ]
+ },
+ jsonlint: {
+ all: [
+ '**/*.json',
+ '!node_modules/**',
+ '!vendor/**'
+ ]
+ }
+ } );
+
+ grunt.registerTask( 'test', [ 'jsonlint', 'banana', 'jshint' ] );
+ grunt.registerTask( 'default', 'test' );
+};
diff --git a/extensions/Variables/README b/extensions/Variables/README
new file mode 100644
index 00000000..9c5b7492
--- /dev/null
+++ b/extensions/Variables/README
@@ -0,0 +1,19 @@
+== About ==
+
+The 'Variables' extension for MediaWiki introduces parser functions for defining page-scoped
+variables within wiki pages.
+
+* Website: https://www.mediawiki.org/wiki/Extension:Variables
+* Authors: Rob Adams, Tom Hempel, Xiloynaha and Daniel Werner
+* License: Public domain
+
+
+== Installation ==
+
+Once you have downloaded the code, place the 'Variables' directory within your
+MediaWiki 'extensions' directory. Then add the following code to your
+[[Manual:LocalSettings.php|LocalSettings.php]] file:
+
+ # Variables
+ require_once( "$IP/extensions/Variables/Variables.php" );
+
diff --git a/extensions/Variables/RELEASE-NOTES b/extensions/Variables/RELEASE-NOTES
new file mode 100644
index 00000000..57ed6686
--- /dev/null
+++ b/extensions/Variables/RELEASE-NOTES
@@ -0,0 +1,88 @@
+ git era Changelog:
+ ==================
+
+ * (trunk) -- Version 2.0.1
+ - Using 'InternalParseBeforeSanitize' hook instead of 'InternalParseBeforeLinks' for MW 1.20
+ - Put into gerrit.wikimedia.org git repository.
+
+
+ svn era Changelog:
+ ==================
+
+ * (trunk) -- Version 2.0.1
+ - Localization added for various languages.
+
+ * November 16, 2010 -- Version 2.0 by Daniel Werner
+ Version 2.0 almost is a complete rewrite of the extension, just the idea remains the
+ same. It's the attempt to get rid of several bugs caused by the fact that MediaWiki
+ is using several Parser objects. Therefore in v2 each Parser has its own Variables
+ store, so nothing will get mixed up anymore. Full compatibility is given, except perhaps
+ in cases where bugs were used intentionally.
+
+ New features and bugfixes:
+ - Inclusion of special pages in the middle of the page won't reset all defined
+ variables anymore.
+ - Variables should now be compatible with all other extensions, except for those still
+ using Parser::parse() recursively in any way (which should never be done!).
+ - For MW 1.12 and later, '#var' default value no longer gets expanded when not needed.
+ - Experimental new function '#var_final' which allows to insert the variables final
+ (last) value after page processing is almost through.
+ - Global configuration variable '$egVariablesDisabledFunctions' added.
+
+ Internal changes:
+ - Parser class member $mExtVariables now contains an instance of ExtVariables where
+ only variables for that parser are getting stored. They won't be deleted by other
+ Parser actions anymore (e.g. special page inclusion doesn't reset variables anymore)
+ - ExtVariables class now has public functions which should be used by other extensions
+ for getting and setting variables information.
+ - Removed global '$wgExtVariables' variable.
+ - 'Variables_Settings.php' file for configuration settings added.
+
+ Others:
+ - Put under 'ISC License' (public domain before).
+ - In case you are using Extension:Loops, you should update it as well to remain compatibility.
+
+
+ * November 14, 2011 -- Version 1.3.1.1 (re-pack of 1.3.1 tagged version for svn)
+ - Although 1.4 is released already and 2.0 in the trunk, ensure one last version
+ compatible with MW < 1.12 still is available
+ - Some comments cleaned, 'RELEASE-NOTES' and 'README' files added.
+
+
+ * November 13, 2011 -- Version 1.4 by Daniel Werner
+ - Cleanup for use with more current MW versions:
+ + 'ParserFirstCallInit' hook in use and no more global extension functions.
+ + State of the Art internationalization files added.
+ - Dropped support for MW before 1.12
+ - 'ExtVariables::VARIABLES' constant with version info added.
+ - Put into mediawiki.org svn, 'RELEASE-NOTES' and 'README' files added.
+
+
+ Pre svn Changelog:
+ ==================
+
+ The following pre-svn changelog was composed by Daniel Werner in the hope it might
+ give an almost complete overview of all major releases of 'Variables' extension.
+ All changes can still be retrace at
+
+ https://www.mediawiki.org/w/index.php?title=Extension:VariablesExtension&action=history
+
+ * July 20, 2010 -- Version 1.3 by Daniel Werner
+ - Removed critical bug. Some kind of "Superglobal" variables. In some cases values
+ were passed from one page to another page during page imports and job queue jobs.
+
+ * March 28, 2009 -- Version 1.2 by Daniel Werner
+ - '#varexists' function introduced
+ - parameter for default value for '#var' function in case the variable doesn't exist
+ or its value is just an empty string.
+
+ * December 5, 2008 -- Version 1.1 by user 'Xiloynaha'
+ - '#vardefineecho' function introduced
+
+ * June 24, 2007 -- r3, Language file added by unknown contributor
+
+ * October 11, 2006 -- r2, Fixes for MediaWiki 1.8 compatibility by Tom Hempel
+ - '$wgExtensionCredits' and '$wgHooks' being used.
+
+ * October 11, 2006 -- r1, initial release by Rob Adams
+ - First version of 'Variables', introducing '#vardefine' and '#var'
diff --git a/extensions/Variables/Variables.i18n.magic.php b/extensions/Variables/Variables.i18n.magic.php
new file mode 100644
index 00000000..7d7292f0
--- /dev/null
+++ b/extensions/Variables/Variables.i18n.magic.php
@@ -0,0 +1,22 @@
+
+ */
+
+$magicWords = array();
+
+$magicWords['en'] = array(
+ 'var' => array( 0, 'var' ),
+ 'var_final' => array( 0, 'var_final' ),
+ 'vardefine' => array( 0, 'vardefine' ),
+ 'vardefineecho' => array( 0, 'vardefineecho' ),
+ 'varexists' => array( 0, 'varexists' ),
+);
diff --git a/extensions/Variables/Variables.php b/extensions/Variables/Variables.php
new file mode 100644
index 00000000..84d6c90c
--- /dev/null
+++ b/extensions/Variables/Variables.php
@@ -0,0 +1,375 @@
+
+ *
+ * @file Variables.php
+ * @ingroup Variables
+ */
+
+// Ensure that the script cannot be executed outside of MediaWiki.
+if ( !defined( 'MEDIAWIKI' ) ) {
+ die( 'This is an extension to MediaWiki and cannot be run standalone.' );
+}
+
+// Display extension properties on MediaWiki.
+$wgExtensionCredits['parserhook'][] = array(
+ 'path' => __FILE__,
+ 'name' => 'Variables',
+ 'descriptionmsg' => 'variables-desc',
+ 'version' => ExtVariables::VERSION,
+ 'author' => array(
+ 'Rob Adams',
+ 'Tom Hempel',
+ 'Xiloynaha',
+ '[https://www.mediawiki.org/wiki/User:Danwe Daniel Werner]',
+ '...'
+ ),
+ 'url' => 'https://www.mediawiki.org/wiki/Extension:Variables',
+ 'license-name' => 'ISC'
+);
+
+// language files:
+$wgMessagesDirs['Variables'] = __DIR__ . '/i18n';
+$wgExtensionMessagesFiles['VariablesMagic'] = ExtVariables::getDir() . '/Variables.i18n.magic.php';
+
+// hooks registration:
+$wgHooks['ParserFirstCallInit'][] = 'ExtVariables::init';
+$wgHooks['ParserClearState'][] = 'ExtVariables::onParserClearState';
+$wgHooks['InternalParseBeforeSanitize'][] = 'ExtVariables::onInternalParseBeforeSanitize';
+
+// parser tests registration:
+$wgParserTestFiles[] = ExtVariables::getDir() . '/tests/mwparsertests/Variables.txt';
+
+// Include the settings file:
+require_once ExtVariables::getDir() . '/Variables.settings.php';
+
+
+/**
+ * Extension class with basic extension information. This class serves as static
+ * class with the static parser functions but also als variables store instance
+ * as object assigned to a Parser object.
+ */
+class ExtVariables {
+
+ /**
+ * Version of the 'Variables' extension.
+ *
+ * @since 1.4
+ *
+ * @var string
+ */
+ const VERSION = '2.2.0';
+
+ /**
+ * Internal store for variable values
+ *
+ * @private
+ * @var array
+ */
+ public $mVariables = array();
+
+ /**
+ * Array with all names of variables requested by '#var_final'. Key of the values is the
+ * stripSateId of the strip-item placed where the final var should appear.
+ *
+ * @since 2.0
+ *
+ * @private
+ * @var array
+ */
+ public $mFinalizedVars = array();
+
+ /**
+ * Variables extensions own private StripState manager to manage '#final_var' placeholders
+ * and their replacement with the final var value or a defined default.
+ *
+ * @since 2.0
+ *
+ * @private
+ * @var StripState
+ */
+ public $mFinalizedVarsStripState;
+
+ /**
+ * Sets up parser functions
+ *
+ * @since 1.4
+ */
+ public static function init( Parser &$parser ) {
+
+ /*
+ * store for variables per parser object. This will solve several bugs related to
+ * 'ParserClearState' hook clearing all variables early in combination with certain
+ * other extensions. (since v2.0)
+ */
+ $parser->mExtVariables = new self();
+
+ // Parser::SFH_OBJECT_ARGS available since MW 1.12
+ self::initFunction( $parser, 'var', array( __CLASS__, 'pfObj_var' ), Parser::SFH_OBJECT_ARGS );
+ self::initFunction( $parser, 'var_final' );
+ self::initFunction( $parser, 'vardefine' );
+ self::initFunction( $parser, 'vardefineecho' );
+ self::initFunction( $parser, 'varexists' );
+
+ return true;
+ }
+ private static function initFunction( Parser &$parser, $name, $functionCallback = null, $flags = 0 ) {
+ if( $functionCallback === null ) {
+ // prefix parser functions with 'pf_'
+ $functionCallback = array( __CLASS__, 'pf_' . $name );
+ }
+ global $egVariablesDisabledFunctions;
+
+ // register function only if not disabled by configuration:
+ if( ! in_array( $name, $egVariablesDisabledFunctions ) ) {
+ $parser->setFunctionHook( $name, $functionCallback, $flags );
+ }
+ }
+
+ /**
+ * Returns the extensions base installation directory.
+ *
+ * @since 2.0
+ *
+ * @return string
+ */
+ public static function getDir() {
+ static $dir = null;
+
+ if( $dir === null ) {
+ $dir = dirname( __FILE__ );
+ }
+ return $dir;
+ }
+
+
+ ####################
+ # Parser Functions #
+ ####################
+
+ static function pf_varexists( Parser &$parser, $varName = '', $exists=true, $noexists=false ) {
+ if( self::get( $parser )->varExists( $varName ) ) {
+ return $exists;
+ } else {
+ return $noexists;
+ }
+ }
+
+ static function pf_vardefine( Parser &$parser, $varName = '', $value = '' ) {
+ self::get( $parser )->setVarValue( $varName, $value );
+ return '';
+ }
+
+ static function pf_vardefineecho( Parser &$parser, $varName = '', $value = '' ) {
+ self::get( $parser )->setVarValue( $varName, $value );
+ return $value;
+ }
+
+ static function pfObj_var( Parser &$parser, $frame, $args) {
+ $varName = trim( $frame->expand( $args[0] ) ); // first argument expanded already but lets do this anyway
+ $varVal = self::get( $parser )->getVarValue( $varName, null );
+
+ // default applies if var doesn't exist but also in case it is an empty string!
+ if( $varVal === null || $varVal === '' ) {
+ // only expand argument when needed:
+ $defaultVal = isset( $args[1] ) ? trim( $frame->expand( $args[1] ) ) : '';
+ return $defaultVal;
+ }
+ return $varVal;
+ }
+
+ static function pf_var_final( Parser &$parser, $varName, $defaultVal = '' ) {
+ return self::get( $parser )->requestFinalizedVar( $parser, $varName, $defaultVal );
+ }
+
+
+ ##############
+ # Used Hooks #
+ ##############
+
+ /**
+ * Used for '#var_final' parser function to insert the final variable values.
+ * @see http://www.mediawiki.org/wiki/Manual:Hooks/InternalParseBeforeSanitize
+ *
+ * @since 2.0.1
+ */
+ static function onInternalParseBeforeSanitize( Parser &$parser, &$text ) {
+ $varStore = self::get( $parser );
+
+ // only do this if '#var_final' was used
+ if( $varStore->mFinalizedVarsStripState === null ) {
+ return true;
+ }
+
+ /*
+ * all vars are final now, check whether requested vars can be inserted for '#final_var' or
+ * if the default has to be inserted. In any case, adjust the strip item value
+ */
+ foreach( $varStore->mFinalizedVars as $stripStateId => $varName ) {
+
+ $varVal = $varStore->getVarValue( $varName, '' );
+ if( $varVal !== '' ) {
+ // replace strip item value with final variables value or registered default:
+ $varStore->stripStatePair( $stripStateId, $varVal );
+ }
+ }
+
+ /**
+ * Unstrip all '#var_final' strip-markers with their final '#var' or default values.
+ * This HAS to be done here and can't be done through the normal unstrip process of MW.
+ * This because the default value as well as the variables value stil have to be rendered properly since they
+ * may contain links or even category links. On the other hand, they can't be parsed with Parser::recursiveTagParse()
+ * since this would parse wiki templates and functions which are intended as normal text, kind of similar to
+ * returning a parser functions value with 'noparse' => true.
+ * Also, there is no way to expand the '#var_final' default value here, just if needed, since the output could be an
+ * entirely different, e.g. if variables are used.
+ * This method also takes care of recursive '#var_final' calls (within the default value) quite well.
+ */
+ $text = $varStore->mFinalizedVarsStripState->unstripGeneral( $text );
+ return true;
+ }
+
+ /**
+ * This will clean up the variables store after parsing has finished. It will prevent strange things to happen
+ * for example during import of several pages or job queue is running for multiple pages. In these cases variables
+ * would become some kind of superglobals, being passed from one page to the other.
+ */
+ static function onParserClearState( Parser &$parser ) {
+ /**
+ * MessageCaches Parser clone will mess things up if we don't reset the entire object.
+ * Only resetting the array would unset it in the original object as well! This instead
+ * will break the entire reference to the object
+ */
+ $parser->mExtVariables = new self();
+ return true;
+ }
+
+
+ ##################
+ # Private Helper #
+ ##################
+
+ /**
+ * Takes care of setting a strip state pair
+ */
+ protected function stripStatePair( $marker, $value ) {
+ $this->mFinalizedVarsStripState->addGeneral( $marker, $value );
+ }
+
+
+ ####################################
+ # Public functions for interaction #
+ ####################################
+ #
+ # public non-parser functions, accessible for
+ # other extensions doing interactive stuff
+ # with 'Variables' (like Extension:Loops)
+ #
+
+ /**
+ * Convenience function to return the 'Variables' extensions variables store connected
+ * to a certain Parser object. Each parser has its own store which will be reset after
+ * a parsing process [Parser::parse()] has finished.
+ *
+ * @param Parser &$parser
+ *
+ * @return ExtVariables by reference so we still have the right object after 'ParserClearState'
+ */
+ public static function &get( Parser &$parser ) {
+ return $parser->mExtVariables;
+ }
+
+ /**
+ * Defines a variable, accessible by getVarValue() or '#var' parser function. Name and
+ * value will be trimmed and converted to string.
+ *
+ * @param string $varName
+ * @param string $value will be converted to string if no string is given
+ */
+ public function setVarValue( $varName, $value = '' ) {
+ $this->mVariables[ trim( $varName ) ] = trim( $value );
+ }
+
+ /**
+ * Returns a variables value or null if it doesn't exist.
+ *
+ * @param string $varName
+ * @param mixed $defaultVal
+ *
+ * @return string or mixed in case $defaultVal is being returned and not of type string
+ */
+ public function getVarValue( $varName, $defaultVal = null ) {
+ $varName = trim( $varName );
+ if ( $this->varExists( $varName ) ) {
+ return $this->mVariables[ $varName ];
+ } else {
+ return $defaultVal;
+ }
+ }
+
+ /**
+ * Checks whether a variable exists within the scope.
+ *
+ * @param string $varName
+ *
+ * @return boolean
+ */
+ public function varExists( $varName ) {
+ $varName = trim( $varName );
+ return array_key_exists( $varName, $this->mVariables );
+ }
+
+ /**
+ * Allows to unset a certain variable
+ *
+ * @param type $varName
+ */
+ public function unsetVar( $varName ) {
+ unset( $this->mVariables[ $varName ] );
+ }
+
+ /**
+ * Allows to register the usage of '#var_final'. Meaning a variable can be set as well
+ * as a default value. The return value, a strip-item then can be inserted into any
+ * wikitext processed by the same parser. Later that strip-item will be replaced with
+ * the final var text.
+ * Note: It's not possible to use the returned strip-item within other stripped text
+ * since 'Variables' unstripping will happen before the general unstripping!
+ *
+ * @param Parser $parser
+ * @param string $varName
+ * @param string $defaultVal
+ *
+ * @return string strip-item
+ */
+ function requestFinalizedVar( Parser &$parser, $varName, $defaultVal = '' ) {
+ if( $this->mFinalizedVarsStripState === null ) {
+ $this->mFinalizedVarsStripState = new StripState;
+ }
+ $id = count( $this->mFinalizedVars );
+ /*
+ * strip-item which will be unstripped in self::onInternalParseBeforeSanitize()
+ * In case the requested final variable has a value in the end, this strip-item
+ * value will be replaced with that value before unstripping.
+ */
+ $rnd = "{$parser->mUniqPrefix}-finalizedvar-{$id}-" . Parser::MARKER_SUFFIX;
+
+ $this->stripStatePair( $rnd, trim( $defaultVal ) );
+ $this->mFinalizedVars[ $rnd ] = trim( $varName );
+
+ return $rnd;
+ }
+
+}
diff --git a/extensions/Variables/Variables.settings.php b/extensions/Variables/Variables.settings.php
new file mode 100644
index 00000000..43b04cdf
--- /dev/null
+++ b/extensions/Variables/Variables.settings.php
@@ -0,0 +1,29 @@
+"Test"
+"Test 2, Test 2"
+
+!! end
+
+!! test
+#varexists
+!! input
+{{#varexists: a }}{{#vardefine: a }}
+"{{#varexists: a }}"
+!!result
+"1"
+
+!! end
+
+!! test
+#var_final
+!! input
+"{{#var_final: a }}"
+{{#vardefine: a | something }}"{{#var: a }}"
+{{#vardefine: a | final }}"{{#var_final: a }}"
+!!result
+"final"
+"something"
+"final"
+
+!! end
+
+!! test
+Variables should not be reset on special page inclusion (old bug, solved in Variables 2.0)
+!! input
+{{#vardefine: a | 1 }}{{#vardefine: | {{Special:AllPages}} }}
+"{{#var: a }}"
+!!result
+"1"
+
+!! end
diff --git a/extensions/Variables/version b/extensions/Variables/version
new file mode 100644
index 00000000..a2d7d697
--- /dev/null
+++ b/extensions/Variables/version
@@ -0,0 +1,4 @@
+Variables: REL1_30
+2017-09-21T22:24:13
+
+c75b9d4
--
cgit v1.2.2