r96235 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96234‎ | r96235 | r96236 >
Date:16:47, 4 September 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
fixed several param related issue; fix bug 30741
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/RELEASE-NOTES (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_Setup.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/params (added) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/params/SMW_ParamFormat.php (added) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/queryprinters/SMW_QueryPrinter.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/languages/SMW_Messages.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/specials/SearchTriple/SMW_SpecialSearchByProperty.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/specials/SearchTriple/SMW_SpecialSearchByProperty.php
@@ -208,7 +208,7 @@
209209 $html .= '  ' . SMWInfolink::newBrowsingLink( '+', $result[0]->getShortHTMLText() )->getHTML( smwfGetLinker() );
210210 }
211211
212 - if ( ( $this->value != $result[1] ) || $highlight ) {
 212+ if ( is_object( $result[1] ) && ( ( $this->value != $result[1] ) || $highlight ) ) {
213213 $html .= " <em><small>(" . $result[1]->getLongHTMLText( smwfGetLinker() ) . ")</small></em>";
214214 }
215215
Index: trunk/extensions/SemanticMediaWiki/RELEASE-NOTES
@@ -5,6 +5,8 @@
66
77 * Use of native MediaWiki sortable tables for the table formats.
88 * Fixed separator and filename parameters for the DSV format.
 9+* Added definitions for missing params (sort, order, searchlabel) to the base query printer.
 10+* Added validation and manipulation of the format paremeter using Validator.
911
1012 == SMW 1.6.1 ==
1113
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php
@@ -36,9 +36,13 @@
3737 */
3838 static public function createQuery( $querystring, array $params, $context = self::INLINE_QUERY, $format = '', $extraprintouts = array() ) {
3939 global $smwgQDefaultNamespaces, $smwgQFeatures, $smwgQConceptFeatures;
40 - if ( $format == '' ) {
41 - $format = self::getResultFormat( $params );
42 - }
 40+
 41+ // TODO: this is a hack
 42+ // Idially one round of Validation would be done through Validator on this level
 43+ // instead of on query printer level and then have weirdness here.
 44+ $formatParam = new SMWParamFormat();
 45+ $p = array();
 46+ $formatParam->doManipulation( $format, new Parameter( 'format' ), $p );
4347
4448 // parse query:
4549 $queryfeatures = ( $context == self::CONCEPT_DESC ) ? $smwgQConceptFeatures : $smwgQFeatures;
@@ -266,7 +270,7 @@
267271 static public function getResultFromQueryString( $querystring, array $params, $extraprintouts, $outputmode, $context = self::INLINE_QUERY ) {
268272 wfProfileIn( 'SMWQueryProcessor::getResultFromQueryString (SMW)' );
269273
270 - $format = self::getResultFormat( $params );
 274+ $format = array_key_exists( 'format', $params ) ? $params['format'] : '';
271275 $query = self::createQuery( $querystring, $params, $context, $format, $extraprintouts );
272276 $result = self::getResultFromQuery( $query, $params, $extraprintouts, $outputmode, $context, $format );
273277
@@ -278,6 +282,13 @@
279283 static public function getResultFromQuery( SMWQuery $query, array $params, $extraprintouts, $outputmode, $context = self::INLINE_QUERY, $format = '' ) {
280284 wfProfileIn( 'SMWQueryProcessor::getResultFromQuery (SMW)' );
281285
 286+ // TODO: this is a hack
 287+ // Idially one round of Validation would be done through Validator on this level
 288+ // instead of on query printer level and then have weirdness here.
 289+ $formatParam = new SMWParamFormat();
 290+ $p = array();
 291+ $formatParam->doManipulation( $format, new Parameter( 'format' ), $p );
 292+
282293 // Query routing allows extensions to provide alternative stores as data sources
283294 // The while feature is experimental and is not properly integrated with most of SMW's architecture. For instance, some query printers just fetch their own store.
284295 // @todo FIXME: case-insensitive
@@ -329,55 +340,6 @@
330341 }
331342
332343 /**
333 - * Determines the format from an array of parameters, and returns it.
334 - *
335 - * @param array $params
336 - *
337 - * @return string
338 - */
339 - static protected function getResultFormat( array $params ) {
340 - $format = 'auto';
341 -
342 - if ( array_key_exists( 'format', $params ) ) {
343 - global $smwgResultFormats;
344 -
345 - $format = strtolower( trim( $params['format'] ) );
346 -
347 - if ( !array_key_exists( $format, $smwgResultFormats ) ) {
348 - $isAlias = self::resolveFormatAliases( $format );
349 - if ( !$isAlias ) {
350 - $format = 'auto'; // If it is an unknown format, defaults to list/table again
351 - }
352 - }
353 - }
354 -
355 - return $format;
356 - }
357 -
358 - /**
359 - * Turns format aliases into main formats.
360 - *
361 - * @param string $format
362 - *
363 - * @return boolean Indicates if the passed format was an alias, and thus was changed.
364 - */
365 - static protected function resolveFormatAliases( &$format ) {
366 - global $smwgResultAliases;
367 -
368 - $isAlias = false;
369 -
370 - foreach ( $smwgResultAliases as $mainFormat => $aliases ) {
371 - if ( in_array( $format, $aliases ) ) {
372 - $format = $mainFormat;
373 - $isAlias = true;
374 - break;
375 - }
376 - }
377 -
378 - return $isAlias;
379 - }
380 -
381 - /**
382344 * Find suitable SMWResultPrinter for the given format. The context in which the query is to be
383345 * used determines some basic settings of the returned printer object. Possible contexts are
384346 * SMWQueryProcessor::SPECIAL_PAGE, SMWQueryProcessor::INLINE_QUERY, SMWQueryProcessor::CONCEPT_DESC.
@@ -390,9 +352,6 @@
391353 static public function getResultPrinter( $format, $context = self::SPECIAL_PAGE ) {
392354 global $smwgResultFormats;
393355
394 - self::resolveFormatAliases( $format );
395 -
396 - // TODO: this seems to contain the same logic as found in getResultFormat - a single function for this might be better.
397356 $formatClass = array_key_exists( $format, $smwgResultFormats ) ? $smwgResultFormats[$format] : 'SMWAutoResultPrinter';
398357
399358 return new $formatClass( $format, ( $context != self::SPECIAL_PAGE ) );
Index: trunk/extensions/SemanticMediaWiki/includes/params/SMW_ParamFormat.php
@@ -0,0 +1,66 @@
 2+<?php
 3+
 4+/**
 5+ * Parameter manipulation ensuring the value is an file url.
 6+ *
 7+ * @since 1.6.2
 8+ *
 9+ * @file SMW_ParamFormat.php
 10+ * @ingroup SMW
 11+ * @ingroup ParameterManipulations
 12+ *
 13+ * @licence GNU GPL v3
 14+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 15+ */
 16+class SMWParamFormat extends ItemParameterManipulation {
 17+
 18+ /**
 19+ * Constructor.
 20+ *
 21+ * @since 1.6.2
 22+ */
 23+ public function __construct() {
 24+ parent::__construct();
 25+ }
 26+
 27+ /**
 28+ * @see ItemParameterManipulation::doManipulation
 29+ *
 30+ * @since 0.7
 31+ */
 32+ public function doManipulation( &$value, Parameter $parameter, array &$parameters ) {
 33+ global $smwgResultFormats;
 34+
 35+ if ( !array_key_exists( $value, $smwgResultFormats ) ) {
 36+ $isAlias = self::resolveFormatAliases( $value );
 37+
 38+ if ( !$isAlias ) {
 39+ $value = 'auto'; // If it is an unknown format, defaults to list/table again
 40+ }
 41+ }
 42+ }
 43+
 44+ /**
 45+ * Turns format aliases into main formats.
 46+ *
 47+ * @param string $format
 48+ *
 49+ * @return boolean Indicates if the passed format was an alias, and thus was changed.
 50+ */
 51+ static protected function resolveFormatAliases( &$format ) {
 52+ global $smwgResultAliases;
 53+
 54+ $isAlias = false;
 55+
 56+ foreach ( $smwgResultAliases as $mainFormat => $aliases ) {
 57+ if ( in_array( $format, $aliases ) ) {
 58+ $format = $mainFormat;
 59+ $isAlias = true;
 60+ break;
 61+ }
 62+ }
 63+
 64+ return $isAlias;
 65+ }
 66+
 67+}
Property changes on: trunk/extensions/SemanticMediaWiki/includes/params/SMW_ParamFormat.php
___________________________________________________________________
Added: svn:eol-style
168 + native
Index: trunk/extensions/SemanticMediaWiki/includes/queryprinters/SMW_QueryPrinter.php
@@ -622,7 +622,10 @@
623623 /**
624624 * A function to describe the allowed parameters of a query using
625625 * any specific format - most query printers should override this
626 - * function
 626+ * function.
 627+ *
 628+ * TODO: refactor non-printer params up to the query processor
 629+ * and do all param handling there.
627630 *
628631 * @since 1.5.0
629632 *
@@ -631,7 +634,16 @@
632635 public function getParameters() {
633636 $params = array();
634637
 638+ $allowedFormats = $GLOBALS['smwgResultFormats'];
 639+
 640+ foreach ( $GLOBALS['smwgResultAliases'] as $aliases ) {
 641+ $allowedFormats += $aliases;
 642+ }
 643+
635644 $params['format'] = new Parameter( 'format' );
 645+ $params['format']->setDefault( 'auto' );
 646+ //$params['format']->addCriteria( new CriterionInArray( $allowedFormats ) );
 647+ $params['format']->addManipulations( new SMWParamFormat() );
636648
637649 $params['limit'] = new Parameter( 'limit', Parameter::TYPE_INTEGER );
638650 $params['limit']->setMessage( 'smw_paramdesc_limit' );
@@ -660,10 +672,14 @@
661673 $params['mainlabel']->setDefault( false, false );
662674
663675 $params['link'] = new Parameter( 'link' );
664 - $params['link']->setMessage( 'smw_paramdesc_link' );
 676+ $params['link']->setMessage( 'smw_paramdesc_link' );
665677 $params['link']->addCriteria( new CriterionInArray( 'all', 'subject', 'none' ) );
666678 $params['link']->setDefault( 'all' );
667679
 680+ $params['searchlabel'] = new Parameter( 'searchlabel' );
 681+ $params['searchlabel']->setDefault( '' );
 682+ $params['searchlabel']->setMessage( 'smw-paramdesc-searchlabel' );
 683+
668684 return $params;
669685 }
670686
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Setup.php
@@ -231,7 +231,7 @@
232232 // Datavalues
233233 $dvDir = $smwgIP . 'includes/datavalues/';
234234 $wgAutoloadClasses['SMWDataValue'] = $dvDir . 'SMW_DataValue.php';
235 - $wgAutoloadClasses['SMWContainerValue'] = $dvDir . 'SMW_DV_Container.php';
 235+ $wgAutoloadClasses['SMWContainerValue'] = $dvDir . 'SMW_DV_Container.php';
236236 $wgAutoloadClasses['SMWRecordValue'] = $dvDir . 'SMW_DV_Record.php';
237237 $wgAutoloadClasses['SMWErrorValue'] = $dvDir . 'SMW_DV_Error.php';
238238 $wgAutoloadClasses['SMWStringValue'] = $dvDir . 'SMW_DV_String.php';
@@ -239,7 +239,7 @@
240240 $wgAutoloadClasses['SMWPropertyValue'] = $dvDir . 'SMW_DV_Property.php';
241241 $wgAutoloadClasses['SMWURIValue'] = $dvDir . 'SMW_DV_URI.php';
242242 $wgAutoloadClasses['SMWTypesValue'] = $dvDir . 'SMW_DV_Types.php';
243 - $wgAutoloadClasses['SMWPropertyListValue'] = $dvDir . 'SMW_DV_PropertyList.php';
 243+ $wgAutoloadClasses['SMWPropertyListValue'] = $dvDir . 'SMW_DV_PropertyList.php';
244244 $wgAutoloadClasses['SMWNumberValue'] = $dvDir . 'SMW_DV_Number.php';
245245 $wgAutoloadClasses['SMWTemperatureValue'] = $dvDir . 'SMW_DV_Temperature.php';
246246 $wgAutoloadClasses['SMWQuantityValue'] = $dvDir . 'SMW_DV_Quantity.php';
@@ -256,11 +256,15 @@
257257 $wgAutoloadClasses['SMWExpLiteral'] = $expDir . 'SMW_Exp_Element.php';
258258 $wgAutoloadClasses['SMWExpResource'] = $expDir . 'SMW_Exp_Element.php';
259259 $wgAutoloadClasses['SMWExpNsResource'] = $expDir . 'SMW_Exp_Element.php';
260 - $wgAutoloadClasses['SMWExportController'] = $expDir . 'SMW_ExportController.php';
261 - $wgAutoloadClasses['SMWSerializer'] = $expDir . 'SMW_Serializer.php';
 260+ $wgAutoloadClasses['SMWExportController'] = $expDir . 'SMW_ExportController.php';
 261+ $wgAutoloadClasses['SMWSerializer'] = $expDir . 'SMW_Serializer.php';
262262 $wgAutoloadClasses['SMWRDFXMLSerializer'] = $expDir . 'SMW_Serializer_RDFXML.php';
263263 $wgAutoloadClasses['SMWTurtleSerializer'] = $expDir . 'SMW_Serializer_Turtle.php';
264264
 265+ // Parameter classes
 266+ $parDir = $smwgIP . 'includes/params/';
 267+ $wgAutoloadClasses['SMWParamFormat'] = $parDir . 'SMW_ParamFormat.php';
 268+
265269 // Parser hooks
266270 $phDir = $smwgIP . 'includes/parserhooks/';
267271 $wgAutoloadClasses['SMWAsk'] = $phDir . 'SMW_Ask.php';
Index: trunk/extensions/SemanticMediaWiki/languages/SMW_Messages.php
@@ -95,6 +95,7 @@
9696 'smw-smwdoc-par-format' => 'The result format to display parameter documentation for.',
9797 'smw-paramdesc-sort' => 'Property to sort the query by',
9898 'smw-paramdesc-order' => 'Order of the query sort',
 99+ 'smw-paramdesc-searchlabel' => 'Text for continuing the search (default is «… further results»)',
99100
100101 // Messages and strings for inline queries
101102 'smw_iq_disabled' => "Semantic queries have been disabled for this wiki.",