SwiftlyTilting: usability, reusability

Sunday, September 2, 2007

Winter 2.1.0

One thing that has been bugging me about Winter is that code must be left aligned or else MediaWiki will format it with some HTML. This made it impossible to write neat code, especially in longer programs. I finally hit upon a decent workaround and now program code is much more readable.

Before:

{{#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.
{{#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

}}

After

{{#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.
   {{#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.

}}

I’ve also added features to access the various template parameter variables used on a page, as well as various other upgrades and bug fixes.

  • 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 <winterprewiki> 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

Download Winter 2.1.0
Downloaded 992 times


11 Comments Leave Comment

Winter made my wiki posoible - and great new features! But some little glitches
—-
“changed syntax so that carriage returns are ignored if followed by a space”

Doesn’t always seem to work in code executed from a template

$this->scriptVars[’_system’][’uri’] = $_SERVER[’SCRIPT_URI’];
$this->scriptVars[’_system’][’url’] = $_SERVER[’SCRIPT_URL’];

result in “Undefined index: SCRIPT_URL errors” in apache log

#count doesn’t seem to work. Modified the code as follows

case ‘count’:

$param = $this->getParams($functionString);
$param[1] = strtolower($param[1]);
$wReturn = count($localVars[$param[1]]);

//$wReturn = count( $this->getParams($functionString));

This seems to work, but I have little php experience, so it’s a guess…

Questions:

How hard would it be to add an intermediate processing hook so that one could use dynamic Categories?

Failing that, are wiki variables such as page title {{PAGENAME}} available before processing?

Comment by Frank Middleton — Tuesday, September 4, 2007 @ 9:51 am

PHP Notice: Undefined variable: templateCode in extensions/Winter.2.1.0.php on line 452

Could this explain the above?

Comment by Frank Middleton — Tuesday, September 4, 2007 @ 11:42 am

When a template contains

this shows up in the rendered page

but it doesn’t show up if you use these tags directly. I cooked up a kludge (using your neat ‘WinterFunction’ feature to get the page title directly, and so now the template itself gets categorized. But pages calling the template don’t. I suppose these problems are all connected? Oh well…

Comment by Frank Middleton — Tuesday, September 4, 2007 @ 12:12 pm

Hi Frank, Thanks for your feedback. I will look into those bugs. I do not understand the last bug you commented about at 12:12pm.

How hard would it be to add an intermediate processing hook so that one could use dynamic Categories?

look into

http://www.mediawiki.org/wiki/Extension:Winter/Documentation#.3Cwinterprewiki.3E

I guess I forgot to mention that in the change log.

Comment by swiftlytilting — Wednesday, September 5, 2007 @ 10:26 pm

#count doesn’t seem to work. Modified the code as follows

case ‘count’:

$param = $this->getParams($functionString);
$param[1] = strtolower($param[1]);
$wReturn = count($localVars[$param[1]]);

//$wReturn = count( $this->getParams($functionString));

This seems to work, but I have little php experience, so it’s a guess…

count does work but it should also have the functionality you have described above.. in the meantime try

{{#array | arrayname | 1 | 2 | 3 }}
{{#count | {{#arrayname}} }}

Comment by swiftlytilting — Wednesday, September 5, 2007 @ 10:35 pm

“changed syntax so that carriage returns are ignored if followed by a space”

Doesn’t always seem to work in code executed from a template

This cannot be helped.

When templates are used, the text of the template is included into the main page. Then the page is processed by MediaWiki for wiki markup and whatnot. There is no intermediate hook available to remove the line breaks.

 $this->scriptVars[’_system’][’uri’] = $_SERVER[’SCRIPT_URI’];
$this->scriptVars[’_system’][’url’] = $_SERVER[’SCRIPT_URL’];

result in “Undefined index: SCRIPT_URL errors” in apache log

I guess there is no SCRIPT_URL, though my server has it for some reason, but it’s not in the manual.

 PHP Notice: Undefined variable: templateCode in extensions/Winter.2.1.0.php on line 452

Could this explain the above?

This is just a minor bug that I’ve corrected.

I sent you an email about the other massage you left to try to get more info.

Comment by swiftlytilting — Sunday, September 9, 2007 @ 9:28 am

Is the bugfix for the bug:

Undefined variable: templateCode

that you mention is fixed available?

Comment by Jason — Wednesday, October 10, 2007 @ 9:05 pm

oops.. yeah I’ll make a release sometime soon. But in the meantime change $templatecode on line 452 to $v :)

Comment by swiftlytilting — Monday, October 15, 2007 @ 7:58 pm

The SCRIPT_URL and SCRIPT_URL missing variable problem can be remedied in apache by setting
RewriteEngine on

in the virtual host definition.

See this thread:
http://ubuntuforums.org/showthread.php?t=360405

Comment by Jason — Sunday, December 16, 2007 @ 12:05 pm

Sorry, I forgot to reply to this qusieton. Have you had any luck getting it to work? When are you calling stage.displayState? Make sure it is after the application is completely loaded. In my example I added a click handler on a button that set stage.displayState = StageDisplayState.FULL_SCREEN;

Comment by Daniele — Thursday, November 27, 2014 @ 12:13 am

Thanks Kyle! I will look into it. I am just getting staterd with the website and bit off a little more than I can chew but I love to learn new things so I shall perservere!

Comment by Steven — Thursday, March 5, 2015 @ 7:30 pm

Leave a Comment

Validate XHTML | Word Press