https://www.mediawiki.org/wiki/Special:Code/MediaWiki/114490
Revision: 114490
Author: jeroendedauw
Date: 2012-03-26 16:17:19 +0000 (Mon, 26 Mar 2012)
Log Message:
-----------
clean up param handling a bit
Modified Paths:
--------------
trunk/extensions/SemanticMediaWiki/includes/SMW_DataValueFactory.php
trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php
trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Time.php
trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Time.php
trunk/extensions/SemanticMediaWiki/includes/queryprinters/SMW_QueryPrinter.php
Modified: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValueFactory.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/SMW_DataValueFactory.php
2012-03-26 14:57:26 UTC (rev 114489)
+++ trunk/extensions/SemanticMediaWiki/includes/SMW_DataValueFactory.php
2012-03-26 16:17:19 UTC (rev 114490)
@@ -134,9 +134,11 @@
$result = self::newTypeIdValue( $typeId, false, $caption,
$property );
$result->setDataItem( $dataItem );
+
if ( $caption !== false ) {
$result->setCaption( $caption );
}
+
return $result;
}
Modified: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php
2012-03-26 14:57:26 UTC (rev 114489)
+++ trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php
2012-03-26 16:17:19 UTC (rev 114490)
@@ -487,9 +487,6 @@
* A function to describe the allowed parameters of a query using
* any specific format - most query printers should override this
* function.
- *
- * TODO: refactor non-printer params up to the query processor
- * and do all param handling there.
*
* @since 1.6.2
*
@@ -544,6 +541,18 @@
$params['searchlabel'] = new Parameter( 'searchlabel' );
$params['searchlabel']->setDefault( false, false );
$params['searchlabel']->setMessage( 'smw-paramdesc-searchlabel'
);
+
+ $params['intro'] = new Parameter( 'intro' );
+ $params['intro']->setMessage( 'smw_paramdesc_intro' );
+ $params['intro']->setDefault( '' );
+
+ $params['outro'] = new Parameter( 'outro' );
+ $params['outro']->setMessage( 'smw_paramdesc_outro' );
+ $params['outro']->setDefault( '' );
+
+ $params['default'] = new Parameter( 'default' );
+ $params['default']->setMessage( 'smw_paramdesc_default' );
+ $params['default']->setDefault( '' );
return $params;
}
Modified: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Time.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Time.php
2012-03-26 14:57:26 UTC (rev 114489)
+++ trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Time.php
2012-03-26 16:17:19 UTC (rev 114490)
@@ -171,13 +171,42 @@
public function getSecond() {
return $this->m_seconds;
}
-
+
/**
+ * Creates and returns a new instance of SMWDITime from a MW timestamp.
+ *
+ * @since 1.8
+ *
+ * @param string $timestamp must be in format
+ *
+ * @return SMWDITime|false
+ */
+ public static function newFromTimestamp( $timestamp ) {
+ $timestamp = wfTimestamp( TS_MW, (string)$timestamp );
+
+ if ( $timestamp === false ) {
+ return false;
+ }
+
+ return new self(
+ SMWDITime::CM_GREGORIAN,
+ substr( $timestamp, 0, 4 ),
+ substr( $timestamp, 4, 2 ),
+ substr( $timestamp, 6, 2 ),
+ substr( $timestamp, 8, 2 ),
+ substr( $timestamp, 10, 2 ),
+ substr( $timestamp, 12, 2 )
+ );
+ }
+
+ /**
* Returns a MW timestamp representatation of the value.
*
* @since 1.6.2
*
* @param $outputtype
+ *
+ * @return mixed
*/
public function getMwTimestamp( $outputtype = TS_UNIX ) {
return wfTimestamp(
Modified: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Time.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Time.php
2012-03-26 14:57:26 UTC (rev 114489)
+++ trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Time.php
2012-03-26 16:17:19 UTC (rev 114490)
@@ -148,17 +148,7 @@
// Check if it's parseable by wfTimestamp when it's not a year
(which is wrongly interpreted).
if ( strlen( $value ) != 4 && wfTimestamp( TS_MW, $value ) !==
false ) {
- $timeStamp = wfTimestamp( TS_MW, $value );
-
- $this->m_dataitem = new SMWDITime(
- SMWDITime::CM_GREGORIAN,
- substr( $timeStamp, 0, 4 ),
- substr( $timeStamp, 4, 2 ),
- substr( $timeStamp, 6, 2 ),
- substr( $timeStamp, 8, 2 ),
- substr( $timeStamp, 10, 2 ),
- substr( $timeStamp, 12, 2 )
- );
+ $this->m_dataitem = SMWDITime::newFromMwTimestamp(
wfTimestamp( TS_MW, $value ) );
}
elseif ( $this->parseDateString( $value, $datecomponents,
$calendarmodel, $era, $hours, $minutes, $seconds, $timeoffset ) ) {
if ( ( $calendarmodel === false ) && ( $era === false )
&& ( count( $datecomponents ) == 1 ) && ( intval( end( $datecomponents ) ) >=
100000 ) ) {
Modified:
trunk/extensions/SemanticMediaWiki/includes/queryprinters/SMW_QueryPrinter.php
===================================================================
---
trunk/extensions/SemanticMediaWiki/includes/queryprinters/SMW_QueryPrinter.php
2012-03-26 14:57:26 UTC (rev 114489)
+++
trunk/extensions/SemanticMediaWiki/includes/queryprinters/SMW_QueryPrinter.php
2012-03-26 16:17:19 UTC (rev 114490)
@@ -297,13 +297,11 @@
$this->params = $params;
$this->m_params = $params; // Compat, change made in 1.6.3/1.7
- if ( array_key_exists( 'intro', $params ) ) { $this->mIntro =
$params['intro']; }
- if ( array_key_exists( 'outro', $params ) ) { $this->mOutro =
$params['outro']; }
-
- if ( array_key_exists( 'searchlabel', $params ) ) {
- $this->mSearchlabel = $params['searchlabel'] === false
? null : $params['searchlabel'];
- }
+ $this->mIntro = $params['intro'];
+ $this->mOutro = $params['outro'];
+ $this->mSearchlabel = $params['searchlabel'] === false ? null :
$params['searchlabel'];
+
switch ( $params['link'] ) {
case 'head': case 'subject':
$this->mLinkFirst = true;
@@ -319,7 +317,7 @@
break;
}
- if ( array_key_exists( 'default', $params ) ) { $this->mDefault
= str_replace( '_', ' ', $params['default'] ); }
+ $this->mDefault = str_replace( '_', ' ', $params['default'] );
if ( $params['headers'] == 'hide' ) {
$this->mShowHeaders = SMW_HEADERS_HIDE;
@@ -471,44 +469,28 @@
* formats, like 'list' and 'table', for use in their getParameters()
* functions
*
+ * @deperecated since 1.8, removal in 1.10
+ *
* @since 1.5.0
*
* @return array of Parameter
*/
protected function textDisplayParameters() {
- $params = array();
-
- $params['intro'] = new Parameter( 'intro' );
- $params['intro']->setMessage( 'smw_paramdesc_intro' );
- $params['intro']->setDefault( '' );
-
- $params['outro'] = new Parameter( 'outro' );
- $params['outro']->setMessage( 'smw_paramdesc_outro' );
- $params['outro']->setDefault( '' );
-
- $params['default'] = new Parameter( 'default' );
- $params['default']->setMessage( 'smw_paramdesc_default' );
- $params['default']->setDefault( '' );
-
- return $params;
+ return array();
}
/**
* Return an array describing the parameters of the export formats
* like 'rss' and 'csv', for use in their getParameters() functions
*
+ * @deperecated since 1.8, removal in 1.10
+ *
* @since 1.5.0
*
* @return array
*/
protected function exportFormatParameters() {
- $params = array();
-
- $params['searchlabel'] = new Parameter( 'searchlabel' );
- $params['searchlabel']->setMessage( 'smw_paramdesc_searchlabel'
);
- $params['searchlabel']->setDefault( false, false );
-
- return $params;
+ return array();
}
/**
@@ -575,9 +557,6 @@
* any specific format - most query printers should override this
* function.
*
- * TODO: refactor non-printer params up to the query processor
- * and do all param handling there.
- *
* @since 1.5
*
* @return array of Parameter
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs