Quoting of Action parameters
Currently (version 1.1.6.0 and earlier), Wikka recognizes only action parameters if they are enclosed in single quotes. That is a needless limitation, and unintuitive for those who are used to be able to single-quote attributes in HTML.
Double or Single Quotes
This page shows a small change to the Action() method in wikka.php than enables it to recognize parameters enclosed in either double or single quotes (as long as the same type quotation character is used at start and end of the value).Making the change
Find the Action() method in wikka.php (line 759 in version 1.1.6.0). A few lines into the method, find this section of code:
- if ($action) {
- // match all attributes (key and value)
- // prepare an array for extract() to work with (in $this->IncludeBuffered())
- $vars[$matches[1][$a]] = $matches[2][$a];
- }
- }
- } else {
Replace it with:
- if ($action) {
- // match all attributes (key and value)
- // prepare an array for extract() to work with (in $this->IncludeBuffered())
- $vars[$matches[1][$a]] = $matches[3][$a];
- }
- }
- } else {
How it works
In the original regular expression on line 774
"/([A-Za-z0-9]*)=\"(.*)\"/U"
the bit
=\"(.*)\"
matches an attribute value as follows:- starts with =
- immediately followed by a double quote \"
- followed by an arbitrary number of characters (.*);
the brackets allow us to pull out the value (the second bracketed expression in the whole regular expression, so we get it with a $matches[2] while the parameter name is in $matches[1] (line 779) - the first bracketed expression)
- followed by the closing double quote \"
In the new code we have this regular expression
'/([A-Za-z0-9]*)=("|\')(.*)\\2/U'
where the bit
=("|\')(.*)\\2
matches an attribute value as follows:- starts with =
- immediately followed by either a double quote or a single one ("|\')
(note that the single quote must be escaped now because we have enclosed the whole regular expression in single quotes in stead of double ones); this subexpression is bracketed so we can refer back to it
- followed by an arbitrary number of characters (.*);
as above, the brackets allow us to pull out the parameter value, but it is now the third bracketed expression, so we get at it with $matches[3] now (line 779)
- followed by the same quote character it started with \\2:
this is called a backreference - \2 matches whatever the second bracketed expression before matched; this ensures we match either two double quotes or two single quotes.
Advantages
- Freedom to use either single or double quotes around a parameter value; it's largely a matter of habit, but in some cases single quotes may actually be more readable than double quotes.
- You can now embed quotes in a parameter value, simply by enclosing the whole parameter in the "opposite" type of quote characters. This is useful for passing actual text to an action, but would also enable something like the (extended) TableAction to handle embedded (double-double quoted) HTML in table cells.
CategoryDevelopmentCore