CIMSU OTS Technical Blog

Thursday, March 8, 2007

Parser 1.4.1 , Pages, Request & Ajax

Parser 1.4.1

Major updates on the Parser object. Version 1.3 included Parser Extensions. Version 1.4.1 includes Parser Extensions and Link formatting, in 3.5 different flavors.

First, two FrameWorks-style tags were added, "link" and "url". They do about what you'd expect, ie: "link" generates an internal link and "url" generates an internal URL. Here's the syntax:
{link:page}
{link:page|Link Text}
{url:page}

These work with the new global $fgLinkStyle. Those familiar with MediaWiki will recognize this, it's essentially the same thing, just a string with $1 in it somewhere that tells the parser how to format links.

There's also two pseudo-WikiMarkup additions: [[link]] and [http://link], which work exactly as they do in MediaWiki, including the | deliminator.

Pages

The way we'll handle pages has finally been worked out. This is fairly intricate, but also entirely encapsulated and modular, so I think it's a fair deal. New pages are stored in their own files (though you could, of course, store multiple pages in the same file). This file calls a function, ffAddPage, which takes 2-4 parameters. First is the "label" for the page, ie: some kind of text name that will appear in the URL or querystring. Second is a unique callback function (I've been starting callbacks with "fc") that actually does the processing for the page. More on this in a minute. The third and fourth parameters are booleans, setting the #3 to true will make this page the default, setting #4 true will make it the error page. This is pretty unnecessary, as there's a built-in error page you can use.

The callback functions need to take four parameters, preferably by reference—at least for the first three. Here's the format:
fcPageCallback( &$Parser, &$User, &$Request, $Subpage = false ) {...}

The $Parser parameter is the global fgParser object. The $User parameter is the global fgUser, and the $Request parameter is the global fgRequest object. The subpage is any part of the parameter after the first '/' character.

So, calling
index.php?page=page/subpage
will result in the following: if "page" exists, and the callback is defined, say fcPage, fcPage will be called with the parameters above, including the $Subpage = "subpage". It's the responsibility of the callback fcPage to output material to the browser. This lets pages generate RSS feeds using RSSFeed.

Request & Ajax

Request is a new object that handles getting variables from the HTTP request for you, including escaping quotes if magic_quotes is off. Use the method $fgRequest->getVar('varname'); to get either any request var. Note that POST vars take precedence over GET vars, and that, even if you use the POST method, if there are no POST vars, it will interpret this as essentially GET.

Ajax is almost identical to the AjaxDispatcher object in MediaWiki, that is, if $fgUseAjax is set to true, and you pass a request var called "action" set to "ajax", it will call the Ajax object and use a user-defined callback function. (Note you actually need to set "action=ajax", "rs=callback", and "rsargs=functionarguments" in your request. Though, of course, you could always global in the $fgRequest object and access anything that way.) User-defined callback functions have to be added using the void ffAddAjaxFunction( string Callback ) function.

The Ajax callback has to do two things: 1) accept a string or array as the only parameter, and 2) if necessary, it needs to handle any output to the browser.

Labels: ,

Tuesday, March 6, 2007

Bug Reports

There is a new method of bug reporting in town. Basically, I got sick of people e-mailing me directly with problems. Now the OTS uses something called the Bug Reporting and Tracking Service to handle bug reports. I always intended to get around to coding this, but didn't get to it until this week.

It's fairly straightforward. Instead of bothering with logins I just created a password protected directory to allow "admin" access. And each user can create a "bug password," which is stored in plaintext, to limit who can respond to the bug.

The real point of this new Service is to test some of the FrameWorks components. It uses DB2, Parser1.2, and RSSFeed1.1 to generate RSS feeds tracking the progress of each bug or to see the latest bugs—which I'm using to keep track of people submitting them. So far, the new components seem to be performing admirably.

Labels:

Lots of Small Changes

In the past week, there have been several small changes made throughout the FrameWorks system. Let me 'splain. No, there is too much. Let me sum up:

Parser 1.2.2: Parser got a little upgrade, to have a little more in common with Smarty and to simplify the code in pages that use it. The "addVariable" method was shortened to "set" (with an alias left for backwards compatibility) and the "setTemplate" method was made private (this may cause scripts to crash) and template selection was limited to the output function, as in Smarty. So now, code should look something like:

$parser = new Parser;
$parser->set('name', 'value');
echo $parser->output('default.htm');

It also now gets the default template directory from LocalSettings.php, which means you must first include LocalSettings.php, which means you must first define the security constant.

Calendar 1.2.1: Calendar just got updates to follow the new Parser code formats.

RSSFeed 1.1: RSSFeed got similar updates to Calendar 1.1. It now uses Parser to generate code, instead of encoding raw XML. The "addItem" method was also shortened to "add" (with an alias for backwards compatibility).

User 2.0.1 and Userdata 1.0.1: To streamline the process of accessing user information, the Rights array and associated functions were moved to the Userdata object. The User method "hasRight" is now a reference to the mUserdata object's "getRight" method.

The only major update planned for any of these at this time is the addition of ParserExtensions to the Parser object. These would use callback functions to allow custom extensions, as in the MediaWiki parser. I am currently undecided about the format for such tags or how data will be passed to the callback.

Labels: