r114490 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r114489‎ | r114490 | r114491 >
Date:16:17, 26 March 2012
Author:jeroendedauw
Status:deferred (Comments)
Tags:
Comment:
clean up param handling a bit
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DataValueFactory.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Time.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Time.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/queryprinters/SMW_QueryPrinter.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Time.php
@@ -171,13 +171,42 @@
172172 public function getSecond() {
173173 return $this->m_seconds;
174174 }
175 -
 175+
176176 /**
 177+ * Creates and returns a new instance of SMWDITime from a MW timestamp.
 178+ *
 179+ * @since 1.8
 180+ *
 181+ * @param string $timestamp must be in format
 182+ *
 183+ * @return SMWDITime|false
 184+ */
 185+ public static function newFromTimestamp( $timestamp ) {
 186+ $timestamp = wfTimestamp( TS_MW, (string)$timestamp );
 187+
 188+ if ( $timestamp === false ) {
 189+ return false;
 190+ }
 191+
 192+ return new self(
 193+ SMWDITime::CM_GREGORIAN,
 194+ substr( $timestamp, 0, 4 ),
 195+ substr( $timestamp, 4, 2 ),
 196+ substr( $timestamp, 6, 2 ),
 197+ substr( $timestamp, 8, 2 ),
 198+ substr( $timestamp, 10, 2 ),
 199+ substr( $timestamp, 12, 2 )
 200+ );
 201+ }
 202+
 203+ /**
177204 * Returns a MW timestamp representatation of the value.
178205 *
179206 * @since 1.6.2
180207 *
181208 * @param $outputtype
 209+ *
 210+ * @return mixed
182211 */
183212 public function getMwTimestamp( $outputtype = TS_UNIX ) {
184213 return wfTimestamp(
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php
@@ -487,9 +487,6 @@
488488 * A function to describe the allowed parameters of a query using
489489 * any specific format - most query printers should override this
490490 * function.
491 - *
492 - * TODO: refactor non-printer params up to the query processor
493 - * and do all param handling there.
494491 *
495492 * @since 1.6.2
496493 *
@@ -544,6 +541,18 @@
545542 $params['searchlabel'] = new Parameter( 'searchlabel' );
546543 $params['searchlabel']->setDefault( false, false );
547544 $params['searchlabel']->setMessage( 'smw-paramdesc-searchlabel' );
 545+
 546+ $params['intro'] = new Parameter( 'intro' );
 547+ $params['intro']->setMessage( 'smw_paramdesc_intro' );
 548+ $params['intro']->setDefault( '' );
 549+
 550+ $params['outro'] = new Parameter( 'outro' );
 551+ $params['outro']->setMessage( 'smw_paramdesc_outro' );
 552+ $params['outro']->setDefault( '' );
 553+
 554+ $params['default'] = new Parameter( 'default' );
 555+ $params['default']->setMessage( 'smw_paramdesc_default' );
 556+ $params['default']->setDefault( '' );
548557
549558 return $params;
550559 }
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Time.php
@@ -148,17 +148,7 @@
149149
150150 // Check if it's parseable by wfTimestamp when it's not a year (which is wrongly interpreted).
151151 if ( strlen( $value ) != 4 && wfTimestamp( TS_MW, $value ) !== false ) {
152 - $timeStamp = wfTimestamp( TS_MW, $value );
153 -
154 - $this->m_dataitem = new SMWDITime(
155 - SMWDITime::CM_GREGORIAN,
156 - substr( $timeStamp, 0, 4 ),
157 - substr( $timeStamp, 4, 2 ),
158 - substr( $timeStamp, 6, 2 ),
159 - substr( $timeStamp, 8, 2 ),
160 - substr( $timeStamp, 10, 2 ),
161 - substr( $timeStamp, 12, 2 )
162 - );
 152+ $this->m_dataitem = SMWDITime::newFromMwTimestamp( wfTimestamp( TS_MW, $value ) );
163153 }
164154 elseif ( $this->parseDateString( $value, $datecomponents, $calendarmodel, $era, $hours, $minutes, $seconds, $timeoffset ) ) {
165155 if ( ( $calendarmodel === false ) && ( $era === false ) && ( count( $datecomponents ) == 1 ) && ( intval( end( $datecomponents ) ) >= 100000 ) ) {
Index: trunk/extensions/SemanticMediaWiki/includes/queryprinters/SMW_QueryPrinter.php
@@ -297,13 +297,11 @@
298298 $this->params = $params;
299299 $this->m_params = $params; // Compat, change made in 1.6.3/1.7
300300
301 - if ( array_key_exists( 'intro', $params ) ) { $this->mIntro = $params['intro']; }
302 - if ( array_key_exists( 'outro', $params ) ) { $this->mOutro = $params['outro']; }
303 -
304 - if ( array_key_exists( 'searchlabel', $params ) ) {
305 - $this->mSearchlabel = $params['searchlabel'] === false ? null : $params['searchlabel'];
306 - }
 301+ $this->mIntro = $params['intro'];
 302+ $this->mOutro = $params['outro'];
307303
 304+ $this->mSearchlabel = $params['searchlabel'] === false ? null : $params['searchlabel'];
 305+
308306 switch ( $params['link'] ) {
309307 case 'head': case 'subject':
310308 $this->mLinkFirst = true;
@@ -319,7 +317,7 @@
320318 break;
321319 }
322320
323 - if ( array_key_exists( 'default', $params ) ) { $this->mDefault = str_replace( '_', ' ', $params['default'] ); }
 321+ $this->mDefault = str_replace( '_', ' ', $params['default'] );
324322
325323 if ( $params['headers'] == 'hide' ) {
326324 $this->mShowHeaders = SMW_HEADERS_HIDE;
@@ -471,44 +469,28 @@
472470 * formats, like 'list' and 'table', for use in their getParameters()
473471 * functions
474472 *
 473+ * @deperecated since 1.8, removal in 1.10
 474+ *
475475 * @since 1.5.0
476476 *
477477 * @return array of Parameter
478478 */
479479 protected function textDisplayParameters() {
480 - $params = array();
481 -
482 - $params['intro'] = new Parameter( 'intro' );
483 - $params['intro']->setMessage( 'smw_paramdesc_intro' );
484 - $params['intro']->setDefault( '' );
485 -
486 - $params['outro'] = new Parameter( 'outro' );
487 - $params['outro']->setMessage( 'smw_paramdesc_outro' );
488 - $params['outro']->setDefault( '' );
489 -
490 - $params['default'] = new Parameter( 'default' );
491 - $params['default']->setMessage( 'smw_paramdesc_default' );
492 - $params['default']->setDefault( '' );
493 -
494 - return $params;
 480+ return array();
495481 }
496482
497483 /**
498484 * Return an array describing the parameters of the export formats
499485 * like 'rss' and 'csv', for use in their getParameters() functions
500486 *
 487+ * @deperecated since 1.8, removal in 1.10
 488+ *
501489 * @since 1.5.0
502490 *
503491 * @return array
504492 */
505493 protected function exportFormatParameters() {
506 - $params = array();
507 -
508 - $params['searchlabel'] = new Parameter( 'searchlabel' );
509 - $params['searchlabel']->setMessage( 'smw_paramdesc_searchlabel' );
510 - $params['searchlabel']->setDefault( false, false );
511 -
512 - return $params;
 494+ return array();
513495 }
514496
515497 /**
@@ -575,9 +557,6 @@
576558 * any specific format - most query printers should override this
577559 * function.
578560 *
579 - * TODO: refactor non-printer params up to the query processor
580 - * and do all param handling there.
581 - *
582561 * @since 1.5
583562 *
584563 * @return array of Parameter
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValueFactory.php
@@ -134,9 +134,11 @@
135135
136136 $result = self::newTypeIdValue( $typeId, false, $caption, $property );
137137 $result->setDataItem( $dataItem );
 138+
138139 if ( $caption !== false ) {
139140 $result->setCaption( $caption );
140141 }
 142+
141143 return $result;
142144 }
143145

Comments

#Comment by Yaron Koren (talk | contribs)   21:35, 1 May 2012

It looks like the call to SMWDITime::newFromMwTimestamp() should just be SMWDITime::newFromTimestamp().

#Comment by Jeroen De Dauw (talk | contribs)   23:30, 12 May 2012

Good catch, should be fixed in https://gerrit.wikimedia.org/r/#/c/7524/

Status & tagging log