r97994 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97993‎ | r97994 | r97995 >
Date:12:15, 24 September 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
fixed mainlabel handling for show and migrated list qp to new param handling system
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/queryprinters/SMW_QP_List.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php
@@ -186,17 +186,28 @@
187187 return $query;
188188 }
189189
 190+ /**
 191+ *
 192+ *
 193+ * FIXME: show queries are not getting any results w/o passing any query condition
 194+ *
 195+ * @since 1.6.3
 196+ *
 197+ * @param array $printRequests
 198+ * @param array $rawParams
 199+ * @param boolean $isShow
 200+ */
190201 public static function addThisPrinteout( array &$printRequests, array $rawParams, $isShow = false ) {
191 - $rawParams['mainlabel'] = ( !$isShow && array_key_exists( 'mainlabel', $rawParams ) ) ? $rawParams['mainlabel'] : false;
192 - $noMainlabel = $rawParams['mainlabel'] === '-';
193 - // !$desc->isSingleton() || count( $printRequests ) == 0 ) && ( !$noMainlabel )
194 -
195 - if ( !is_null( $printRequests ) && !$noMainlabel ) {
196 - array_unshift( $printRequests, new SMWPrintRequest(
197 - SMWPrintRequest::PRINT_THIS,
198 - $rawParams['mainlabel']
199 - ) );
200 - }
 202+ if ( !$isShow && !is_null( $printRequests ) ) {
 203+ $hasMainlabel = array_key_exists( 'mainlabel', $rawParams );
 204+
 205+ if ( !$hasMainlabel || $rawParams['mainlabel'] === '-' ) {
 206+ array_unshift( $printRequests, new SMWPrintRequest(
 207+ SMWPrintRequest::PRINT_THIS,
 208+ $hasMainlabel ? $rawParams['mainlabel'] : ''
 209+ ) );
 210+ }
 211+ }
201212 }
202213
203214 /**
@@ -314,7 +325,7 @@
315326 */
316327 static public function getResultFromFunctionParams( array $rawparams, $outputmode, $context = self::INLINE_QUERY, $showmode = false ) {
317328 self::processFunctionParams( $rawparams, $querystring, $params, $printouts, $showmode );
318 - self::addThisPrinteout( $printouts, $params );
 329+ self::addThisPrinteout( $printouts, $params, $showmode );
319330 $params = self::getProcessedParams( $params, $printouts );
320331 return self::getResultFromQueryString( $querystring, $params, $printouts, SMW_OUTPUT_WIKI, $context );
321332 }
Index: trunk/extensions/SemanticMediaWiki/includes/queryprinters/SMW_QP_List.php
@@ -18,43 +18,34 @@
1919 */
2020 class SMWListResultPrinter extends SMWResultPrinter {
2121
22 - protected $mSep = '';
23 - protected $mTemplate = '';
24 - protected $mUserParam = '';
25 - protected $mColumns = 1;
26 - protected $mIntroTemplate = '';
27 - protected $mOutroTemplate = '';
 22+ protected $mSep;
 23+ protected $mTemplate;
 24+ protected $mUserParam;
 25+ protected $mColumns;
 26+ protected $mIntroTemplate;
 27+ protected $mOutroTemplate;
2828
29 - protected function readParameters( $params, $outputmode ) {
30 - parent::readParameters( $params, $outputmode );
31 -
32 - if ( array_key_exists( 'sep', $params ) ) {
33 - $this->mSep = str_replace( '_', ' ', $params['sep'] );
34 - }
35 -
36 - if ( array_key_exists( 'template', $params ) ) {
37 - $this->mTemplate = trim( $params['template'] );
38 - }
39 -
40 - if ( array_key_exists( 'userparam', $params ) ) {
41 - $this->mUserParam = trim( $params['userparam'] );
42 - }
43 -
44 - if ( array_key_exists( 'columns', $params ) ) {
45 - $columns = trim( $params['columns'] );
46 - if ( $columns > 1 && $columns <= 10 ) { // allow a maximum of 10 columns
47 - $this->mColumns = (int)$columns;
48 - }
49 - }
50 -
51 - if ( array_key_exists( 'introtemplate', $params ) ) {
52 - $this->mIntroTemplate = $params['introtemplate'];
53 - }
54 -
55 - if ( array_key_exists( 'outrotemplate', $params ) ) {
56 - $this->mOutroTemplate = $params['outrotemplate'];
57 - }
 29+ public function __construct( $format, $inline, $useValidator = true ) {
 30+ parent::__construct( $format, $inline );
 31+ $this->useValidator = $useValidator;
5832 }
 33+
 34+ /**
 35+ * @see SMWResultPrinter::handleParameters
 36+ *
 37+ * @since 1.6
 38+ *
 39+ * @param array $params
 40+ * @param $outputmode
 41+ */
 42+ protected function handleParameters( array $params, $outputmode ) {
 43+ $this->mSep = $this->isPlainlist() ? $params['sep'] : '';
 44+ $this->mTemplate = trim( $params['template'] );
 45+ $this->mUserParam = trim( $params['userparam'] );
 46+ $this->mColumns = !$this->isPlainlist() ? $params['columns'] : 1;
 47+ $this->mIntroTemplate = $params['introtemplate'];
 48+ $this->mOutroTemplate = $params['outrotemplate'];
 49+ }
5950
6051 public function getName() {
6152 smwfLoadExtensionMessages( 'SemanticMediaWiki' );
@@ -295,12 +286,14 @@
296287 $result .= $rowstart . ' '. $link->getText( SMW_OUTPUT_WIKI, $this->mLinker ) . $rowend;
297288 }
298289
 290+ protected function isPlainlist() {
 291+ return $this->mFormat != 'ul' && $this->mFormat != 'ol';
 292+ }
 293+
299294 public function getParameters() {
300295 $params = array_merge( parent::getParameters(), parent::textDisplayParameters() );
301296
302 - $plainlist = ( $this->mFormat != 'ul' && $this->mFormat != 'ol' );
303 -
304 - if ( $plainlist ) {
 297+ if ( $this->isPlainlist() ) {
305298 $params['sep'] = new Parameter( 'sep' );
306299 $params['sep']->setMessage( 'smw_paramdesc_sep' );
307300 $params['sep']->setDefault( '' );
@@ -310,10 +303,11 @@
311304 $params['template']->setMessage( 'smw_paramdesc_template' );
312305 $params['template']->setDefault( '' );
313306
314 - if ( !$plainlist ) {
 307+ if ( !$this->isPlainlist() ) {
315308 $params['columns'] = new Parameter( 'columns', Parameter::TYPE_INTEGER );
316309 $params['columns']->setMessage( 'smw_paramdesc_columns', 1 );
317 - $params['columns']->setDefault( '', false );
 310+ $params['columns']->setDefault( 1, false );
 311+ $params['columns']->addCriteria( new CriterionInRange( 1, 10 ) );
318312 }
319313
320314 $params['userparam'] = new Parameter( 'userparam' );