r28812 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r28811‎ | r28812 | r28813 >
Date:21:55, 23 December 2007
Author:vrandezo
Status:old
Tags:
Comment:
Fixed set of result printers replaces by an array of formats mapped to the printer classes. Now extensions can introduce new result printers.
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php
@@ -20,7 +20,17 @@
2121 * formats. The formats 'table' and 'list' are defaults that cannot be disabled. The format 'broadtable'
2222 * should not be disabled either in order not to break Special:ask.
2323 */
24 - static $formats = array('table', 'list', 'ol', 'ul', 'broadtable', 'embedded', 'timeline', 'eventline', 'template', 'count', 'debug');
 24+ static $formats = array('table' => "SMWTableResultPrinter",
 25+ 'list' => "SMWListResultPrinter",
 26+ 'ol' => "SMWListResultPrinter",
 27+ 'ul' => "SMWListResultPrinter",
 28+ 'broadtable' => "SMWTableResultPrinter",
 29+ 'embedded' => "SMWEmbeddedResultPrinter",
 30+ 'timeline' => "SMWTimelineResultPrinter",
 31+ 'eventline' => "SMWTimelineResultPrinter",
 32+ 'template' => "SMWTemplateResultPrinter",
 33+ 'count' => "SMWListResultPrinter",
 34+ 'debug' => "SMWListResultPrinter");
2535
2636 /**
2737 * Parse a query string given in SMW's query language to create
@@ -239,7 +249,7 @@
240250 $format = 'auto';
241251 if (array_key_exists('format', $params)) {
242252 $format = strtolower(trim($params['format']));
243 - if ( !in_array($format,SMWQueryProcessor::$formats) ) {
 253+ if ( !array_key_exists($format, SMWQueryProcessor::$formats) ) {
244254 $format = 'auto'; // If it is an unknown format, defaults to list/table again
245255 }
246256 }
@@ -255,19 +265,12 @@
256266 $format = 'table';
257267 else $format = 'list';
258268 }
259 - switch ($format) {
260 - case 'table': case 'broadtable':
261 - return new SMWTableResultPrinter($format,$inline);
262 - case 'ul': case 'ol': case 'list':
263 - return new SMWListResultPrinter($format,$inline);
264 - case 'timeline': case 'eventline':
265 - return new SMWTimelineResultPrinter($format,$inline);
266 - case 'embedded':
267 - return new SMWEmbeddedResultPrinter($format,$inline);
268 - case 'template':
269 - return new SMWTemplateResultPrinter($format,$inline);
270 - default: return new SMWListResultPrinter($format,$inline);
271 - }
 269+
 270+ if (array_key_exists($format, SMWQueryProcessor::$formats))
 271+ $formatclass = SMWQueryProcessor::$formats[$format];
 272+ else
 273+ $formatclass = "SMWListResultPrinter";
 274+ return new $formatclass($format,$inline);
272275 }
273276
274277 }

Status & tagging log