r36887 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r36886‎ | r36887 | r36888 >
Date:08:39, 2 July 2008
Author:mkroetzsch
Status:old
Tags:
Comment:
Two new helper parser functions:
#show to make very simple queries that just show the property value of a single thing, and
#info to create SMW-style info tooltips directly (uses JavaScript but diplays in any case, though less pretty)
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_GlobalFunctions.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php
@@ -151,8 +151,9 @@
152152 * produced by the #ask parser function. The parsing results in a querystring,
153153 * an array of additional parameters, and an array of additional SMWPrintRequest
154154 * objects, which are filled into call-by-ref parameters.
 155+ * $showmode is true if the input should be treated as if given by #show
155156 */
156 - static public function processFunctionParams($rawparams, &$querystring, &$params, &$printouts) {
 157+ static public function processFunctionParams($rawparams, &$querystring, &$params, &$printouts, $showmode=false) {
157158 global $wgContLang;
158159 $querystring = '';
159160 $printouts = array();
@@ -176,7 +177,7 @@
177178 $title = NULL;
178179 $printmode = SMWPrintRequest::PRINT_CATS;
179180 if (count($parts) == 1) { // no label found, use category label
180 - $parts[] = $wgContLang->getNSText(NS_CATEGORY);
 181+ $parts[] = $showmode?'':$wgContLang->getNSText(NS_CATEGORY);
181182 }
182183 } else { // print property or check category
183184 $title = Title::newFromText(trim($propparts[0]), SMW_NS_PROPERTY); // trim needed for \n
@@ -189,7 +190,7 @@
190191 $printmode = SMWPrintRequest::PRINT_CCAT;
191192 } //else?
192193 if (count($parts) == 1) { // no label found, use property/category name
193 - $parts[] = $title->getText();
 194+ $parts[] = $showmode?'':$title->getText();
194195 }
195196 }
196197 if (count($propparts) == 1) { // no outputformat found, leave empty
@@ -206,6 +207,7 @@
207208 }
208209 }
209210 $querystring = str_replace(array('&lt;','&gt;'), array('<','>'), $querystring);
 211+ if ($showmode) $querystring = "[[:$querystring]]";
210212 }
211213
212214 /**
@@ -219,8 +221,8 @@
220222 * obtain actual parameters, printout requests, and the query string for
221223 * further processing.
222224 */
223 - static public function getResultFromFunctionParams($rawparams, $outputmode, $inline = true) {
224 - SMWQueryProcessor::processFunctionParams($rawparams,$querystring,$params,$printouts);
 225+ static public function getResultFromFunctionParams($rawparams, $outputmode, $inline = true, $showmode = false) {
 226+ SMWQueryProcessor::processFunctionParams($rawparams,$querystring,$params,$printouts,$showmode);
225227 return SMWQueryProcessor::getResultFromQueryString($querystring,$params,$printouts, SMW_OUTPUT_WIKI, $inline);
226228 }
227229
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_GlobalFunctions.php
@@ -237,6 +237,8 @@
238238 function smwfRegisterInlineQueries( &$parser, &$text, &$stripstate ) {
239239 $parser->setHook( 'ask', 'smwfProcessInlineQuery' );
240240 $parser->setFunctionHook( 'ask', 'smwfProcessInlineQueryParserFunction' );
 241+ $parser->setFunctionHook( 'show', 'smwfProcessShowParserFunction' );
 242+ $parser->setFunctionHook( 'info', 'smwfProcessInfoParserFunction' );
241243 return true; // always return true, in order not to stop MW's hook processing!
242244 }
243245
@@ -268,6 +270,31 @@
269271 }
270272 }
271273
 274+/**
 275+ * The {{#show }} parser function processing part.
 276+ */
 277+function smwfProcessShowParserFunction(&$parser) {
 278+ global $smwgQEnabled, $smwgIQRunningNumber;
 279+ if ($smwgQEnabled) {
 280+ $smwgIQRunningNumber++;
 281+ $params = func_get_args();
 282+ array_shift( $params ); // we already know the $parser ...
 283+ return SMWQueryProcessor::getResultFromFunctionParams($params,SMW_OUTPUT_WIKI,true,true);
 284+ } else {
 285+ return smwfEncodeMessages(array(wfMsgForContent('smw_iq_disabled')));
 286+ }
 287+}
 288+
 289+/**
 290+ * The {{#info }} parser function processing part.
 291+ */
 292+function smwfProcessInfoParserFunction(&$parser) {
 293+ $params = func_get_args();
 294+ array_shift( $params ); // we already know the $parser ...
 295+ $content = array_shift( $params ); // use only first parameter, ignore rest (may get meaning later)
 296+ return smwfEncodeMessages(array($content), 'info');
 297+}
 298+
272299 /**********************************************/
273300 /***** Header modifications *****/
274301 /**********************************************/
@@ -409,21 +436,14 @@
410437 * Set up (possibly localised) names for SMW's parser functions.
411438 */
412439 function smwfAddMagicWords(&$magicWords, $langCode) {
413 - $magicWords['ask'] = array( 0, 'ask' );
 440+ $magicWords['ask'] = array( 0, 'ask' );
 441+ $magicWords['show'] = array( 0, 'show' );
 442+ $magicWords['info'] = array( 0, 'info' );
414443 $magicWords['SMW_NOFACTBOX'] = array( 0, '__NOFACTBOX__' );
415444 $magicWords['SMW_SHOWFACTBOX'] = array( 0, '__SHOWFACTBOX__' );
416445 return true;
417446 }
418447
419 -// function smwfAddMagicWords(&$magicWords) {
420 -// $magicWords[] = 'MAG_NOTITLE';
421 -// return true;
422 -// }
423 -//
424 -// function smwfAddMagicWordIds(&$magicWords) {
425 -// $magicWords[] = MAG_NOTITLE;
426 -// }
427 -
428448 /**
429449 * Initialise a global language object for content language. This
430450 * must happen early on, even before user language is known, to

Status & tagging log