I've added support for result format aliases to SMW. In essenece this means you can have multiple values for the format parameter, which will have identical output. The reason for doing this is that Semantic Maps uses an aliasing system for mapping services (example: googlemap, gmap and google will do the same as googlemaps, which is the actual result format). Before this change to SMW, an instance of a query printer needed to be created for every alias, which does not make much sense, is bad for performance and brought with it several other issues.

I've made changes to 2 files:

1. SMW_Settings.php:
Added: $smwgResultAliases = array();
This array holds result formats as the keys, and the aliases as (array) value.
Example: $smwgResultAliases['googlemaps'] = array('googlemap', 'gmap', 'google');
2. SMW_QueryProCessor.php:
I've changed getResultFormat to the following:
    static protected function getResultFormat($params) {
        global $smwgResultAliases;
        $format = 'auto';
        if (array_key_exists('format', $params)) {
            $format = strtolower(trim($params['format']));
            global $smwgResultFormats;

            if ( !array_key_exists($format, $smwgResultFormats) ) {
                foreach($smwgResultAliases as $mainFormat => $aliases) {
                    if (in_array($format, $aliases)) {
                        $format = $mainFormat;
                        $isAlias = true;
                if (! $isAlias) $format = 'auto';  // If it is an unknown format, defaults to list/table again
        return $format;

Does anyone have an objection or suggestion for improvement related to this little change?


Jeroen De Dauw
* Forum: code.bn2vs.com
* Blog: blog.bn2vs.com
* Skype: rts.bn.vs

Don't panic. Don't be evil. 70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!