r102909 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102908‎ | r102909 | r102910 >
Date:21:41, 13 November 2011
Author:danwe
Status:deferred
Tags:
Comment:
Version 1.4 of Variables extension.
Modified paths:
  • /trunk/extensions/Variables (added) (history)
  • /trunk/extensions/Variables/Variables.i18n.magic.php (added) (history)
  • /trunk/extensions/Variables/Variables.i18n.php (added) (history)
  • /trunk/extensions/Variables/Variables.php (added) (history)

Diff [purge]

Index: trunk/extensions/Variables/Variables.i18n.magic.php
@@ -0,0 +1,21 @@
 2+<?php
 3+#coding: utf-8
 4+
 5+/**
 6+ * Internationalization file for magic words of the 'Variables' extension.
 7+ *
 8+ * @since 1.4
 9+ *
 10+ * @file Variables.i18n.magic.php
 11+ * @ingroup Variables
 12+ * @author Daniel Werner < danweetz@web.de >
 13+ */
 14+
 15+$magicWords = array();
 16+
 17+$magicWords['en'] = array(
 18+ 'var' => array( 0, 'var' ),
 19+ 'vardefine' => array( 0, 'vardefine' ),
 20+ 'vardefineecho' => array( 0, 'vardefineecho' ),
 21+ 'varexists' => array( 0, 'varexists' ),
 22+);
Property changes on: trunk/extensions/Variables/Variables.i18n.magic.php
___________________________________________________________________
Added: svn:eol-style
123 + native
Index: trunk/extensions/Variables/Variables.i18n.php
@@ -0,0 +1,28 @@
 2+<?php
 3+#coding: utf-8
 4+
 5+/**
 6+ * Internationalization file of the 'Variables' extension.
 7+ *
 8+ * @since 1.4
 9+ *
 10+ * @file Variables.i18n.php
 11+ * @ingroup Variables
 12+ * @author Daniel Werner < danweetz@web.de >
 13+ */
 14+
 15+$messages = array();
 16+
 17+/** English
 18+ * @author Daniel Werner
 19+ */
 20+$messages['en'] = array(
 21+ 'variables-desc' => 'Parser functions allowing to work with dynamic variables in an article scoped context',
 22+);
 23+
 24+/** German
 25+ * @author Daniel Werner
 26+ */
 27+$messages['de'] = array(
 28+ 'variables-desc' => 'Bietet Parser-Funktionen zur Verwendung dynamischer Variablen in Wiki-Artikeln',
 29+);
Property changes on: trunk/extensions/Variables/Variables.i18n.php
___________________________________________________________________
Added: svn:eol-style
130 + native
Index: trunk/extensions/Variables/Variables.php
@@ -0,0 +1,108 @@
 2+<?php
 3+
 4+/**
 5+ * 'Variables' introduces parser functions for defining page-scoped variables within
 6+ * wiki pages.
 7+ *
 8+ * Documentation: http://www.mediawiki.org/wiki/Extension:Variables
 9+ * Support: http://www.mediawiki.org/wiki/Extension_talk:Variables
 10+ * Source code: http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/Variables
 11+ *
 12+ * @version: 1.4
 13+ * @license: Public domain
 14+ * @author: Rob Adams
 15+ * @author: Tom Hempel
 16+ * @author: Xiloynaha
 17+ * @author: Daniel Werner < danweetz@web.de >
 18+ *
 19+ * @file Variables.php
 20+ * @ingroup Variables
 21+ *
 22+ * @ToDo:
 23+ * FIXME: Fixing bugs related to the fact that there are several Parser instances within the wiki
 24+ * which all could trigger 'ParserFirstCallInit'. E.g. special page transclusion will clear
 25+ * all variables defined before! Variables should have one store per Parser instance.
 26+ */
 27+
 28+if ( ! defined( 'MEDIAWIKI' ) ) { die( ); }
 29+
 30+$wgExtensionCredits['parserhook'][] = array(
 31+ 'path' => __FILE__,
 32+ 'name' => 'Variables',
 33+ 'descriptionmsg' => 'variables-desc',
 34+ 'version' => ExtVariables::VERSION,
 35+ 'author' => array( 'Rob Adams', 'Tom Hempel', 'Xiloynaha', '[http://www.mediawiki.org/wiki/User:Danwe Daniel Werner]' ),
 36+ 'url' => 'http://www.mediawiki.org/wiki/Extension:Variables',
 37+);
 38+
 39+$dir = dirname( __FILE__ );
 40+
 41+// language files:
 42+$wgExtensionMessagesFiles['Variables' ] = $dir . '/Variables.i18n.php';
 43+$wgExtensionMessagesFiles['VariablesMagic'] = $dir . '/Variables.i18n.magic.php';
 44+
 45+unset ( $dir );
 46+
 47+// hooks registration:
 48+$wgHooks['ParserFirstCallInit'][] = 'ExtVariables::init';
 49+
 50+
 51+class ExtVariables {
 52+
 53+ /**
 54+ * Version of the 'Variables' extension.
 55+ *
 56+ * @since 1.4
 57+ *
 58+ * @var string
 59+ */
 60+ const VERSION = '1.4';
 61+
 62+ var $mVariables = array();
 63+
 64+ /**
 65+ * Sets up parser functions
 66+ *
 67+ * @since 1.4
 68+ */
 69+ static function init( Parser $parser ) {
 70+ global $wgExtVariables, $wgHooks;
 71+
 72+ $wgExtVariables = new self();
 73+ $wgHooks['ParserClearState'][] = $wgExtVariables; // hooks registration
 74+
 75+ $parser->setFunctionHook( 'vardefine', array( &$wgExtVariables, 'vardefine' ) );
 76+ $parser->setFunctionHook( 'vardefineecho', array( &$wgExtVariables, 'vardefineecho' ) );
 77+ $parser->setFunctionHook( 'var', array( &$wgExtVariables, 'varf' ) );
 78+ $parser->setFunctionHook( 'varexists', array( &$wgExtVariables, 'varexists' ) );
 79+
 80+ return true;
 81+ }
 82+
 83+ function onParserClearState( &$parser ) {
 84+ $this->mVariables = array(); //remove all variables to avoid conflicts with job queue or Special:Import
 85+ return true;
 86+ }
 87+
 88+ function vardefine( &$parser, $expr = '', $value = '' ) {
 89+ $this->mVariables[ $expr ] = $value;
 90+ return '';
 91+ }
 92+
 93+ function vardefineecho( &$parser, $expr = '', $value = '' ) {
 94+ $this->mVariables[ $expr ] = $value;
 95+ return $value;
 96+ }
 97+
 98+ function varf( &$parser, $expr = '', $defaultVal = '' ) {
 99+ if ( isset( $this->mVariables[ $expr ] ) && $this->mVariables[ $expr ] !== '' ) {
 100+ return $this->mVariables[ $expr ];
 101+ } else {
 102+ return $defaultVal;
 103+ }
 104+ }
 105+
 106+ function varexists( &$parser, $expr = '' ) {
 107+ return array_key_exists( $expr, $this->mVariables );
 108+ }
 109+}
Property changes on: trunk/extensions/Variables/Variables.php
___________________________________________________________________
Added: svn:eol-style
1110 + native

Follow-up revisions

RevisionCommit summaryAuthorDate
r103302r102909: Consistency tweaks in preparation for adding extension to translatew...raymond08:42, 16 November 2011
r103303r102909: Adding extension to translatewiki.netraymond08:43, 16 November 2011

Status & tagging log