Result format aliases for SMW

From the archive: written in 2009 and kept for the record. Much of it is out of date.

Today I’ve wrote a small change to Semantic MediaWiki that adds aliasing supports to it’s result formats. I’ve been working (mainly theorizing) on this for quite a while, and came up with some rather complex solutions, that where not feasible since they required PHP 5.3. The implementation I ended up with is ridiculously easy, and works with an $smwgResultAliases array. This array holds result formats as the keys, and the aliases as (array) value. A simple example of adding aliases using this array is:

$smwgResultAliases[‘googlemaps’] = array(‘googlemap’, ‘gmap’, ‘google’);

Here googlemap, gmap and google will do the same as googlemaps, which is the actual result format. To hold into account these aliases, I only needed to add some simple code to the getResultFormat function in SMWQueryProcessor. This is the code:

	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;
						continue;
					}
				}
				
				if (! $isAlias) $format = 'auto';  // If it is an unknown format, defaults to list/table again
			}
		}
		return $format;
	}

Semantic result formats displayed on a special:ask page
This implementation is fully working with Semantic Maps, and has fixed an issue this extension had with the display of it’s result formats on the special:ask page (see screenshot).

Anyway, my first direct contribution to SMW – yay 🙂

Jeroen De Dauw is founder and CEO of Professional Wiki and builds NeoWiki. More about me. Reply by email or on Mastodon, Bluesky or X.

One comment on “Result format aliases for SMW”

  1. In conclusion, there’s also remote controlled a lock. Most of these (keyless locks) involve any deadbolt that would be set off along with the force on the screen. These are typically similar to the fastens of the automobiles. A lot of private versions feature two remotes but also from many cases the sheer number of remotes to one fasten might be grew. It happens to be pushed away from 2 bottle A good electric batteries many of the rc devices function within the unique space for the fastening. These types of tresses tend to be simple if your hands are actually full or possibly if you happen to quickly have a preference for instant entry within the home or office.

Comments are closed.