r98038 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98037‎ | r98038 | r98039 >
Date:21:58, 24 September 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
made timeline compat with SMW 1.6.3
Modified paths:
  • /trunk/extensions/SemanticResultFormats/SemanticResultFormats.php (modified) (history)
  • /trunk/extensions/SemanticResultFormats/Timeline/SRF_Timeline.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticResultFormats/SemanticResultFormats.php
@@ -20,8 +20,17 @@
2121 die( 'Not an entry point.' );
2222 }
2323
24 -define( 'SRF_VERSION', '1.6.2' );
 24+// Show a warning if Semantic MediaWiki is not loaded.
 25+if ( ! defined( 'SMW_VERSION' ) ) {
 26+ 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 />' );
 27+}
2528
 29+if ( version_compare( SMW_VERSION, '1.6.2 alpha', '<' ) ) {
 30+ 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.' );
 31+}
 32+
 33+define( 'SRF_VERSION', '1.6.3 alpha' );
 34+
2635 // Require the settings file.
2736 require dirname( __FILE__ ) . '/SRF_Settings.php';
2837
Index: trunk/extensions/SemanticResultFormats/Timeline/SRF_Timeline.php
@@ -22,38 +22,27 @@
2323 protected $m_tlbands = ''; // array of band IDs (MONTH, YEAR, ...)
2424 protected $m_tlpos = ''; // position identifier (start, end, today, middle)
2525
26 - protected function readParameters( $params, $outputmode ) {
27 - parent::readParameters( $params, $outputmode );
28 -
29 - if ( array_key_exists( 'timelinestart', $params ) ) {
30 - $this->m_tlstart = smwfNormalTitleDBKey( $params['timelinestart'] );
31 - }
32 - if ( array_key_exists( 'timelineend', $params ) ) {
33 - $this->m_tlend = smwfNormalTitleDBKey( $params['timelineend'] );
34 - }
 26+ /**
 27+ * @see SMWResultPrinter::handleParameters
 28+ *
 29+ * @since 1.6.3
 30+ *
 31+ * @param array $params
 32+ * @param $outputmode
 33+ */
 34+ protected function handleParameters( array $params, $outputmode ) {
 35+ parent::handleParameters( $params, $outputmode );
3536
36 - if ( array_key_exists( 'timelinesize', $params ) ) {
37 - $this->m_tlsize = htmlspecialchars( str_replace( ';', ' ', strtolower( trim( $params['timelinesize'] ) ) ) );
 37+ $this->m_tlstart = smwfNormalTitleDBKey( $params['timelinestart'] );
 38+ $this->m_tlend = smwfNormalTitleDBKey( $params['timelineend'] );
 39+ $this->m_tlbands = $params['timelinebands'];
 40+ $this->m_tlpos = strtolower( trim( $params['timelineposition'] ) );
 41+
3842 // str_replace makes sure this is only one value, not mutliple CSS fields (prevent CSS attacks)
3943 // / 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.
40 - } else {
41 - $this->m_tlsize = '300px';
42 - }
43 -
44 - if ( array_key_exists( 'timelinebands', $params ) ) {
45 - // check for band parameter, should look like "DAY,MONTH,YEAR"
46 - $this->m_tlbands = preg_split( '/[,][\s]*/u', trim( $params['timelinebands'] ) );
47 - } else {
48 - $this->m_tlbands = array( 'MONTH', 'YEAR' ); // / TODO: check what default the JavaScript uses
49 - }
50 -
51 - if ( array_key_exists( 'timelineposition', $params ) ) {
52 - $this->m_tlpos = strtolower( trim( $params['timelineposition'] ) );
53 - } else {
54 - $this->m_tlpos = 'middle';
55 - }
 44+ $this->m_tlsize = htmlspecialchars( str_replace( ';', ' ', strtolower( $params['timelinesize'] ) ) );
5645 }
57 -
 46+
5847 public function getName() {
5948 return wfMsg( 'srf_printername_' . $this->mFormat );
6049 }
@@ -70,16 +59,7 @@
7160 if ( ( $pr->getMode() == SMWPrintRequest::PRINT_PROP ) && ( $pr->getTypeID() == '_dat' ) ) {
7261 $dataValue = $pr->getData();
7362
74 - // SMW >= 1.6
75 - if ( method_exists ( $dataValue, 'getDataItem' ) ) {
76 - $date_value = $dataValue->getDataItem()->getLabel();
77 - } // SMW 1.5.x
78 - elseif ( method_exists ( $dataValue, 'getValueKey' ) ) {
79 - $date_value = $dataValue->getValueKey();
80 - } // SMW < 1.5
81 - else {
82 - $date_value = $dataValue->getXSDValue();
83 - }
 63+ $date_value = $dataValue->getDataItem()->getLabel();
8464
8565 if ( ( $this->m_tlend == '' ) && ( $this->m_tlstart != '' ) &&
8666 ( $this->m_tlstart != $date_value ) ) {
@@ -395,12 +375,28 @@
396376 public function getParameters() {
397377 $params = parent::getParameters();
398378
399 - $params[] = array( 'name' => 'timelinebands', 'type' => 'enum-list', 'description' => wfMsg( 'srf_paramdesc_timelinebands' ), 'values' => array( 'DECADE', 'YEAR', 'MONTH', 'WEEK', 'DAY', 'HOUR', 'MINUTE' ) );
400 - $params[] = array( 'name' => 'timelineposition', 'type' => 'enumeration', 'description' => wfMsg( 'srf_paramdesc_timelineposition' ), 'values' => array( 'start', 'middle', 'end' ) );
401 - $params[] = array( 'name' => 'timelinestart', 'type' => 'string', 'description' => wfMsg( 'srf_paramdesc_timelinestart' ) );
402 - $params[] = array( 'name' => 'timelineend', 'type' => 'string', 'description' => wfMsg( 'srf_paramdesc_timelineend' ) );
403 - $params[] = array( 'name' => 'timelinesize', 'type' => 'string', 'description' => wfMsg( 'srf_paramdesc_timelinesize' ) );
 379+ $params['timelinesize'] = new Parameter( 'timelinesize' );
 380+ $params['timelinesize']->setDefault( '300px' );
 381+ $params['timelinesize']->setMessage( 'srf_paramdesc_timelinesize' );
 382+
 383+ $params['timelineposition'] = new Parameter( 'timelineposition' );
 384+ $params['timelineposition']->setDefault( 'middle' );
 385+ $params['timelineposition']->setMessage( 'srf_paramdesc_timelineposition' );
 386+ $params['timelineposition']->addCriteria( new CriterionInArray( 'start', 'middle', 'end' ) );
404387
 388+ $params['timelinestart'] = new Parameter( 'timelinestart' );
 389+ $params['timelinestart']->setDefault( '' );
 390+ $params['timelinestart']->setMessage( 'srf_paramdesc_timelinestart' );
 391+
 392+ $params['timelineend'] = new Parameter( 'timelineend' );
 393+ $params['timelineend']->setDefault( '' );
 394+ $params['timelineend']->setMessage( 'srf_paramdesc_timelineend' );
 395+
 396+ $params['timelinebands'] = new ListParameter( 'timelinebands' );
 397+ $params['timelinebands']->setDefault( array( 'MONTH', 'YEAR' ) );
 398+ $params['timelinebands']->setMessage( 'srf_paramdesc_timelinebands' );
 399+ $params['timelinebands']->addCriteria( new CriterionInArray( 'DECADE', 'YEAR', 'MONTH', 'WEEK', 'DAY', 'HOUR', 'MINUTE' ) );
 400+
405401 return $params;
406402 }
407403