http://www.mediawiki.org/wiki/Special:Code/MediaWiki/98038

Revision: 98038
Author:   jeroendedauw
Date:     2011-09-24 21:58:43 +0000 (Sat, 24 Sep 2011)
Log Message:
-----------
made timeline compat with SMW 1.6.3

Modified Paths:
--------------
    trunk/extensions/SemanticResultFormats/SemanticResultFormats.php
    trunk/extensions/SemanticResultFormats/Timeline/SRF_Timeline.php

Modified: trunk/extensions/SemanticResultFormats/SemanticResultFormats.php
===================================================================
--- trunk/extensions/SemanticResultFormats/SemanticResultFormats.php    
2011-09-24 21:41:03 UTC (rev 98037)
+++ trunk/extensions/SemanticResultFormats/SemanticResultFormats.php    
2011-09-24 21:58:43 UTC (rev 98038)
@@ -20,8 +20,17 @@
        die( 'Not an entry point.' );
 }
 
-define( 'SRF_VERSION', '1.6.2' );
+// Show a warning if Semantic MediaWiki is not loaded.
+if ( ! defined( 'SMW_VERSION' ) ) {
+       die( '<b>Error:</b> You need to have <a 
href="http://semantic-mediawiki.org/wiki/Semantic_MediaWiki";>Semantic 
MediaWiki</a> installed in order to use <a 
href="http://www.mediawiki.org/wiki/Extension:Semantic Result Formats">Semantic 
Result Formats</a>.<br />' );
+}
 
+if ( version_compare( SMW_VERSION, '1.6.2 alpha', '<' ) ) {
+       die( '<b>Error:</b> This version of Semantic Result Formats requires 
Semantic MediaWiki 1.6.3 or above; use Semantic Result Formats <= 1.6.2 for 
older versions of SMW.' );
+}
+
+define( 'SRF_VERSION', '1.6.3 alpha' );
+
 // Require the settings file.
 require dirname( __FILE__ ) . '/SRF_Settings.php';
 

Modified: trunk/extensions/SemanticResultFormats/Timeline/SRF_Timeline.php
===================================================================
--- trunk/extensions/SemanticResultFormats/Timeline/SRF_Timeline.php    
2011-09-24 21:41:03 UTC (rev 98037)
+++ trunk/extensions/SemanticResultFormats/Timeline/SRF_Timeline.php    
2011-09-24 21:58:43 UTC (rev 98038)
@@ -22,38 +22,27 @@
        protected $m_tlbands = ''; // array of band IDs (MONTH, YEAR, ...)
        protected $m_tlpos = ''; // position identifier (start, end, today, 
middle)
 
-       protected function readParameters( $params, $outputmode ) {
-               parent::readParameters( $params, $outputmode );
-
-               if ( array_key_exists( 'timelinestart', $params ) ) {
-                       $this->m_tlstart = smwfNormalTitleDBKey( 
$params['timelinestart'] );
-               }
-               if ( array_key_exists( 'timelineend', $params ) ) {
-                       $this->m_tlend = smwfNormalTitleDBKey( 
$params['timelineend'] );
-               }
+       /**
+        * @see SMWResultPrinter::handleParameters
+        * 
+        * @since 1.6.3
+        * 
+        * @param array $params
+        * @param $outputmode
+        */
+       protected function handleParameters( array $params, $outputmode ) {
+               parent::handleParameters( $params, $outputmode );
                
-               if ( array_key_exists( 'timelinesize', $params ) ) {
-                       $this->m_tlsize = htmlspecialchars( str_replace( ';', ' 
', strtolower( trim( $params['timelinesize'] ) ) ) );
+               $this->m_tlstart = smwfNormalTitleDBKey( 
$params['timelinestart'] );
+               $this->m_tlend = smwfNormalTitleDBKey( $params['timelineend'] );
+               $this->m_tlbands = $params['timelinebands'];
+               $this->m_tlpos = strtolower( trim( $params['timelineposition'] 
) );
+               
                        // str_replace makes sure this is only one value, not 
mutliple CSS fields (prevent CSS attacks)
                        // / FIXME: this is either unsafe or redundant, since 
Timeline is Wiki-compatible. If the JavaScript makes user inputs to CSS then it 
is bad even if we block this injection path.
-               } else {
-                       $this->m_tlsize = '300px';
-               }
-               
-               if ( array_key_exists( 'timelinebands', $params ) ) {
-               // check for band parameter, should look like "DAY,MONTH,YEAR"
-                       $this->m_tlbands = preg_split( '/[,][\s]*/u', trim( 
$params['timelinebands'] ) );
-               } else {
-                       $this->m_tlbands = array( 'MONTH', 'YEAR' ); // / TODO: 
check what default the JavaScript uses
-               }
-               
-               if ( array_key_exists( 'timelineposition', $params ) ) {
-                       $this->m_tlpos = strtolower( trim( 
$params['timelineposition'] ) );
-               } else {
-                       $this->m_tlpos = 'middle';
-               }
+               $this->m_tlsize = htmlspecialchars( str_replace( ';', ' ', 
strtolower( $params['timelinesize'] ) ) );
        }
-
+       
        public function getName() {
                return wfMsg( 'srf_printername_' . $this->mFormat );
        }
@@ -70,16 +59,7 @@
                                if ( ( $pr->getMode() == 
SMWPrintRequest::PRINT_PROP ) && ( $pr->getTypeID() == '_dat' ) ) {
                                        $dataValue = $pr->getData();
                                        
-                                       // SMW >= 1.6
-                                       if ( method_exists ( $dataValue, 
'getDataItem' ) ) {
-                                               $date_value = 
$dataValue->getDataItem()->getLabel();
-                                       } // SMW 1.5.x
-                                       elseif ( method_exists ( $dataValue, 
'getValueKey' ) ) {
-                                               $date_value = 
$dataValue->getValueKey();
-                                       } // SMW < 1.5
-                                       else {
-                                               $date_value = 
$dataValue->getXSDValue();
-                                       }
+                                       $date_value = 
$dataValue->getDataItem()->getLabel();
                                        
                                        if ( ( $this->m_tlend == '' ) && ( 
$this->m_tlstart != '' ) &&
                                             ( $this->m_tlstart != $date_value 
) ) {
@@ -395,12 +375,28 @@
        public function getParameters() {
                $params = parent::getParameters();
                
-               $params[] = array( 'name' => 'timelinebands', 'type' => 
'enum-list', 'description' => wfMsg( 'srf_paramdesc_timelinebands' ), 'values' 
=> array( 'DECADE', 'YEAR', 'MONTH', 'WEEK', 'DAY', 'HOUR', 'MINUTE' ) );
-               $params[] = array( 'name' => 'timelineposition', 'type' => 
'enumeration', 'description' => wfMsg( 'srf_paramdesc_timelineposition' ), 
'values' => array( 'start', 'middle', 'end' ) );
-               $params[] = array( 'name' => 'timelinestart', 'type' => 
'string', 'description' => wfMsg( 'srf_paramdesc_timelinestart' ) );
-               $params[] = array( 'name' => 'timelineend', 'type' => 'string', 
'description' => wfMsg( 'srf_paramdesc_timelineend' ) );
-               $params[] = array( 'name' => 'timelinesize', 'type' => 
'string', 'description' => wfMsg( 'srf_paramdesc_timelinesize' ) );
+               $params['timelinesize'] = new Parameter( 'timelinesize' );
+               $params['timelinesize']->setDefault( '300px' );
+               $params['timelinesize']->setMessage( 
'srf_paramdesc_timelinesize' );
+
+               $params['timelineposition'] = new Parameter( 'timelineposition' 
);
+               $params['timelineposition']->setDefault( 'middle' );
+               $params['timelineposition']->setMessage( 
'srf_paramdesc_timelineposition' );
+               $params['timelineposition']->addCriteria( new CriterionInArray( 
'start', 'middle', 'end' ) );
                
+               $params['timelinestart'] = new Parameter( 'timelinestart' );
+               $params['timelinestart']->setDefault( '' );
+               $params['timelinestart']->setMessage( 
'srf_paramdesc_timelinestart' );
+               
+               $params['timelineend'] = new Parameter( 'timelineend' );
+               $params['timelineend']->setDefault( '' );
+               $params['timelineend']->setMessage( 'srf_paramdesc_timelineend' 
);
+               
+               $params['timelinebands'] = new ListParameter( 'timelinebands' );
+               $params['timelinebands']->setDefault( array( 'MONTH', 'YEAR' ) 
);
+               $params['timelinebands']->setMessage( 
'srf_paramdesc_timelinebands' );
+               $params['timelinebands']->addCriteria( new CriterionInArray( 
'DECADE', 'YEAR', 'MONTH', 'WEEK', 'DAY', 'HOUR', 'MINUTE' ) );
+               
                 return $params;
        }
        


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to