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/subpagewill 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: FrameWorks, New Feature
