Extension:Winter

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
Winter

Release status: stable

Winter.png
Implementation Extended syntax, Parser extension, Tag
Description Adds an interpreted language to MediaWiki
Author(s) Swiftly Tilting (Frantiktalk)
Latest version 2.2.1 (03:58, 27 September 2010 (UTC))
MediaWiki 1.5+ (tested and working on 1.15.1)
License GNU GPL
Download Winter.2.2.1.zip
Parameters
  • $wgWinterNamespaces
  • $wgWinterMaxNesting
  • $wgWinterMaxOperations
  • $wgWinterMaxIterations
  • $wgWinterNotAllowed
Tags
* <winterprewiki>
  • <nowinter>
Hooks used
ParserBeforeTidy

ParserBeforeStrip

Translate the Winter extension if possible

Check usage and version matrix; code metrics

Winter (Wiki Interpreter) is an extension which adds an interpreted language to MediaWiki pages. It is intended to enhance the templating system but can be used on any page.

Note: While Winter can be installed along-side parser function extensions without issues, intertwining code from the two systems may have unexpected results. Please check the documentation for details.

Features[edit | edit source]

Features of the Winter language include:

  • Simple syntax
  • Alphanumeric variables & arrays
  • if-then-else conditional statement
  • for and while conditional loops
  • User definable functions (in Winter and PHP)
  • Basic arithmetic
  • String manipulation

Try out Winter[edit | edit source]

You are welcome to test out Winter in the Sandbox area.

Download[edit | edit source]

Quick Installation[edit | edit source]

  1. Place Winter.php in your wiki's extensions directory.
  2. Add require_once("extensions/Winter.php"); to the bottom of LocalSettings.php
  3. You're done!

Documentation[edit | edit source]

Extensive documentation is available.

Examples[edit | edit source]

Example 1[edit | edit source]

This example demonstrates the use of defined functions, for loops, and variable assignment

{{#function | foo || " foobar{{#1}} " }}

{{#for | {{#a = 1}} || {{#a <=  5}} || {{#a ++}} ||
.{{#foo | {{#a}} }}.                                                                                        
}}

Will return

. foobar1 .. foobar2 .. foobar3 .. foobar4 .. foobar5 .

Example 2[edit | edit source]

Template parameters can be accessed easily

{{#set_param_default|1|}}
{{#if| {{{1}}} || First parameter is set to:{{{1}}} || First parameter not set }}

Using the code above in a template will return First parameter is set to:param1 if the template is called with a first paramter set to param1 (eg [[Template:xyz|param1]]). If the first parameter is blank or not used, the template would return nothing.

Example 3 - 99 Bottles of Beer on the Wall[edit | edit source]

{{#function | formatNum ||
   {{#if | {{#1}} || {{#1}} || no more }} bottle{{#if | {{#1 == 1}} || || s}}
}}

{{#for | {{#i @= 99}} || {{#i >= 0}} || {{#i --}} ||  
   {{#bottles | @= | {{#formatNum | {{#i}} }} }}
   {{#ucfirst | {{#bottles}} }} of beer on the wall, {{#bottles}} of beer.<br />
   {{#if | {{#i}} ||
      Take one down and pass it around, {{#formatNum| {{#i - 1}} }}
   ||
      Go to the store and buy some more, 99 bottles
   }} of beer on the wall.<br /><br />
}}

Example 4 - Creating a Calendar[edit | edit source]

This example is too large to include on this page.

View Example 4

Release History & Change Log[edit | edit source]

v2.2.1[edit | edit source]

  • added ^o and ^c escape characters
  • added + to allowed characters in function names and functions
  • added #reset_all_vars function
  • added ++ and -- functions
  • fixed bug with #strpos and #substr returning false when it shouldn't
  • added #is_numeric, #is_int and #is_string functions
  • fixed bug with array assignment
  • other minor bug fixes

v2.2.0[edit | edit source]

  • added #include and #include_raw functions
  • fixed bug with long template content introduced in 2.1.1
  • fixed NOTICE of missing variables (some server configs don't supply SCRIPT_URL or SCRIPT_URI)

v2.1.1[edit | edit source]

  • fixed NOTICE of undefined variable
  • fixed count command which would return the incorrect value

v2.1.0[edit | edit source]

  • changed syntax so that carriage returns are ignored if followed by a space
  • added template variable access
  • added time, microtime, date, urlencode, explode, implode, request_var, template_var, to_str, to_int, show_page_text, version, wordwrap, keep_nl
  • added ^. escape char
  • added tag which allows winter to be used before mediawiki processes it
  • added addVar for external user functions to add variables
  • added WinterBeforeProcess and WinterAfterProcess hooks
  • added various information available at runtime such as user name, page name, etc
  • fixed bug with nowinter tag
  • fixed bug when using foreach with noexistent array
  • fixed bugs with & and ? operators (they’re turned into html entities)
  • fixed bug caused by pipes being returned in error messages
  • updated error messages

v2.0.2[edit | edit source]

  • Fixed allow_call_time_pass_reference bug
  • Fixed bug with <nowinter> tag
  • Fixed bug when undefined variables were referenced
  • Added alternative comment syntax

v2.0.1[edit | edit source]

  • Fixed some bugs with #eval
  • Changed the | (bitwise or) operator to ? since | is a reserved symbol in Winter
  • Improved #comment so that it does not evaluate code
  • Improved the escape character system

v2.0.0[edit | edit source]

  • fixed bug in operation count which severely under counted operations
  • fixed bug when trying to loop inside of a function
  • improved #if so that it does not evaluate all parameters unnecessarily
  • improved <nowinter> tag
  • improved error messages
  • deprecated #define in favor of #str_replace_all
  • deprecated #default in favor of #set_param_default
  • added ability to nest control structures
  • added installation settings $wgWinterMaxNesting, $wgWinterMaxOperations, $wgWinterMaxIterations, $wgWinterNotAllowed
  • added external function definition support
  • added charachters - and $ to acceptable function and variable name characters, also explicitly defined _
  • added @ (silence) modifier for variable assignment operators
  • added <- and <=> variable assignment operators
  • added & | xor << >> bitwise operators
  • added ^ arithmetic operator
  • added #add, #subtract, #multiply, #divide arithmetic functions
  • added #strtoupper, #strtolower, #ucfirst, #trim, #ltrim, #rtrim, #strip_tags string functions
  • added #comment as another name for #null
  • added #debug for easy debugging stub display
  • added #rand function
  • added #html_to_xml and #xml_xpath xml function
  • added array variable type (2 dimensions maximum)
  • added #foreach loop construct for traversing arrays
  • added []= and [][]= operators for array assignment
  • added #count, #array_rand, #array_rand_value, #sort, #rsort, #asort, #arsort, #natsort, #ksort, #krsort array functions

v1.5.0[edit | edit source]

  • Added new shortcut syntax: {{#command param1 param2 ... paramN}} is the same as {{#command| #param1 | #param2 | ... | paramN }}. Each span of whitespace is converted to a pipe character. This is especially useful for math operations: {{#op 1 + 1}} = {{#op| 1 | +| 1}}
  • #op can now accept any amount of operations. However, the order of operations is only left to right. ie {{#op 2 - 2 * 3}} will return 0 and not 4.
  • Added #formula command
  • Added #eval command
  • Added #repeat command
  • fixed some bugs in #strpos

v1.4.1[edit | edit source]

  • <nowinter> tag added to replace #noeval command

v1.4.0[edit | edit source]

  • Added #noeval command to allow Winter code to be displayed without being evaluated.
  • Reworked escape character code. Escape characters are now only translated inside of a Winter command instead of anywhere on the page. This ensures that users who are unaware Winter is installed are not confused.
  • #define actually works now.
  • Switched to x.y.z version numbering system.

v1.3[edit | edit source]

  • Fixed problems with certain commands inside of a for loop. Also fixed the problem with newlines in variable values.
  • Added mod (modulus) operator.

v1.2[edit | edit source]

  • Introduced new shortcut syntax for variables:
    {{#a}} and {{#var|a}} are now equivalent, as are {{#a|+|1}} and {{#var|a|+|1}} (an all other operators), assuming a has already been defined by a #setvar or #var command.

v1.1[edit | edit source]

  • Fixed a few bugs
    • Nesting didn't always work right depending on syntax
    •  != didn't work

v1.0[edit | edit source]

  • Original Public release

Updates by RSS[edit | edit source]

Winter updates are published on my blog.

RSS Feed

User feedback desired[edit | edit source]

Please feel free to submit feedback either on the talk pages here on mediawiki.org or leave a comment on my blog. You may also find my email address inside the Winter.php file. Questions, comments, bug reports, example code, etc are all welcome. I'm also interested to know for what purpose you are using Winter; let me know your site name and I'll give you a shout out on my blog.

Language: English  • 日本語