r77770 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r77769‎ | r77770 | r77771 >
Date:05:22, 5 December 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Some cleanup of timeline format
Modified paths:
  • /trunk/extensions/SemanticResultFormats/Timeline/SRF_Timeline.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticResultFormats/Timeline/SRF_Timeline.php
@@ -1,9 +1,11 @@
22 <?php
33 /**
44 * Print query results in interactive timelines.
 5+ *
 6+ * @file SRF_Timeline.php
 7+ * @ingroup SemanticResultFormats
 8+ *
59 * @author Markus Krötzsch
6 - * @file
7 - * @ingroup SemanticResultFormats
810 */
911
1012 /**
@@ -27,6 +29,7 @@
2830 if ( array_key_exists( 'timelineend', $params ) ) {
2931 $this->m_tlend = smwfNormalTitleDBKey( $params['timelineend'] );
3032 }
 33+
3134 if ( array_key_exists( 'timelinesize', $params ) ) {
3235 $this->m_tlsize = htmlspecialchars( str_replace( ';', ' ', strtolower( trim( $params['timelinesize'] ) ) ) );
3336 // str_replace makes sure this is only one value, not mutliple CSS fields (prevent CSS attacks)
@@ -34,12 +37,14 @@
3538 } else {
3639 $this->m_tlsize = '300px';
3740 }
 41+
3842 if ( array_key_exists( 'timelinebands', $params ) ) {
3943 // check for band parameter, should look like "DAY,MONTH,YEAR"
4044 $this->m_tlbands = preg_split( '/[,][\s]*/u', trim( $params['timelinebands'] ) );
4145 } else {
4246 $this->m_tlbands = array( 'MONTH', 'YEAR' ); // / TODO: check what default the JavaScript uses
4347 }
 48+
4449 if ( array_key_exists( 'timelineposition', $params ) ) {
4550 $this->m_tlpos = strtolower( trim( $params['timelineposition'] ) );
4651 } else {
@@ -48,12 +53,12 @@
4954 }
5055
5156 public function getName() {
52 - wfLoadExtensionMessages( 'SemanticResultFormats' );
5357 return wfMsg( 'srf_printername_' . $this->mFormat );
5458 }
5559
5660 protected function getResultText( $res, $outputmode ) {
5761 global $smwgIQRunningNumber, $wgScriptPath;
 62+
5863 SMWOutputs::requireHeadItem( SMW_HEADER_STYLE );
5964 SMWOutputs::requireHeadItem( 'smw_tlhelper', '<script type="text/javascript" src="' . $wgScriptPath . '/extensions/SemanticResultFormats/Timeline/SRF_timeline.js"></script>' );
6065 SMWOutputs::requireHeadItem( 'smw_tl', '<script type="text/javascript" src="' . $wgScriptPath . '/extensions/SemanticResultFormats/Timeline/SimileTimeline/timeline-api.js"></script>' );
@@ -68,6 +73,7 @@
6974 } else {
7075 $date_value = $pr->getData()->getXSDValue();
7176 }
 77+
7278 if ( ( $this->m_tlend == '' ) && ( $this->m_tlstart != '' ) &&
7379 ( $this->m_tlstart != $date_value ) ) {
7480 $this->m_tlend = $date_value;
@@ -78,7 +84,6 @@
7985 }
8086 }
8187
82 - wfLoadExtensionMessages( 'SemanticMediaWiki' );
8388 // print header
8489 $link = $res->getQueryLink( wfMsgForContent( 'smw_iq_altresults' ) );
8590 $result = "<div class=\"smwtimeline\" id=\"smwtimeline$smwgIQRunningNumber\" style=\"height: $this->m_tlsize\">";
@@ -92,9 +97,11 @@
9398 // print all result rows
9499 $positions = array(); // possible positions, collected to select one for centering
95100 $curcolor = 0; // color cycling is used for eventline
 101+
96102 if ( ( $this->m_tlstart != '' ) || $eventline ) {
97103 $output = false; // true if output for the popup was given on current line
98104 if ( $eventline ) $events = array(); // array of events that are to be printed
 105+
99106 while ( $row = $res->getNext() ) {
100107 $hastime = false; // true as soon as some startdate value was found
101108 $hastitle = false; // true as soon as some label for the event was found
@@ -102,9 +109,11 @@
103110 $curmeta = ''; // current event meta data
104111 $curarticle = ''; // label of current article, if it was found; needed only for eventline labeling
105112 $first_col = true;
 113+
106114 foreach ( $row as $field ) {
107115 $first_value = true;
108116 $pr = $field->getPrintRequest();
 117+
109118 if ( $pr->getData() == '' ) {
110119 $date_value = null;
111120 } elseif ( method_exists ( $pr->getData(), 'getValueKey' ) ) {
@@ -112,23 +121,29 @@
113122 } else {
114123 $date_value = $pr->getData()->getXSDValue();
115124 }
 125+
116126 while ( ( $object = $field->getNextObject() ) !== false ) {
117127 $l = $this->getLinker( $first_col );
 128+
118129 if ( !$hastitle && $object->getTypeID() != '_wpg' ) { // "linking" non-pages in title positions confuses timeline scripts, don't try this
119130 $l = null;
120131 }
 132+
121133 if ( $object->getTypeID() == '_wpg' ) { // use shorter "LongText" for wikipage
122134 $objectlabel = $object->getLongText( $outputmode, $l );
123135 } else {
124136 $objectlabel = $object->getShortText( $outputmode, $l );
125137 }
 138+
126139 $urlobject = ( $l !== null );
127140 $header = '';
 141+
128142 if ( $first_value ) {
129143 // find header for current value:
130144 if ( $this->mShowHeaders && ( '' != $pr->getLabel() ) ) {
131145 $header = $pr->getText( $outputmode, $this->mLinker ) . ': ';
132146 }
 147+
133148 // is this a start date?
134149 if ( ( $pr->getMode() == SMWPrintRequest::PRINT_PROP ) &&
135150 ( $date_value == $this->m_tlstart ) ) {
@@ -139,30 +154,40 @@
140155 $positions[$object->getHash()] = $object->getXMLSchemaDate();
141156 $hastime = true;
142157 }
 158+
143159 // is this the end date?
144160 if ( ( $pr->getMode() == SMWPrintRequest::PRINT_PROP ) &&
145161 ( $date_value == $this->m_tlend ) ) {
146162 // NOTE: We can assume $object to be an SMWDataValue in this case.
147163 $curmeta .= '<span class="smwtlend">' . $object->getXMLSchemaDate( false ) . '</span>';
148164 }
 165+
149166 // find title for displaying event
150167 if ( !$hastitle ) {
151 - if ( $urlobject ) {
152 - $curmeta .= '<span class="smwtlurl">' . $objectlabel . '</span>';
153 - } else {
154 - $curmeta .= '<span class="smwtltitle">' . $objectlabel . '</span>';
155 - }
 168+ $curmeta .= Html::element(
 169+ 'span',
 170+ array(
 171+ 'class' => $urlobject ? 'smwtlurl' : 'smwtltitle'
 172+ ),
 173+ $objectlabel
 174+ );
 175+
156176 if ( ( $pr->getMode() == SMWPrintRequest::PRINT_THIS ) ) {
157177 // NOTE: type Title of $object implied
158178 $curarticle = $object->getLongWikiText();
159179 }
160180 $hastitle = true;
161181 }
162 - } elseif ( $output ) $curdata .= ', '; // it *can* happen that output is false here, if the subject was not printed (fixed subject query) and mutliple items appear in the first row
 182+ } elseif ( $output ) {
 183+ // it *can* happen that output is false here, if the subject was not printed (fixed subject query) and mutliple items appear in the first row
 184+ $curdata .= ', ';
 185+ }
 186+
163187 if ( !$first_col || !$first_value || $eventline ) {
164188 $curdata .= $header . $objectlabel;
165189 $output = true;
166190 }
 191+
167192 if ( $eventline && ( $pr->getMode() == SMWPrintRequest::PRINT_PROP ) && ( $pr->getTypeID() == '_dat' ) && ( '' != $pr->getLabel() ) && ( $date_value != $this->m_tlstart ) && ( $date_value != $this->m_tlend ) ) {
168193 if ( method_exists( $object, 'getValueKey' ) ) {
169194 $events[] = array( $object->getXMLSchemaDate(), $pr->getLabel(), $object->getValueKey() );
@@ -173,6 +198,7 @@
174199 }
175200 $first_value = false;
176201 }
 202+
177203 if ( $output ) $curdata .= "<br />";
178204 $output = false;
179205 $first_col = false;
@@ -181,6 +207,7 @@
182208 if ( $hastime ) {
183209 $result .= '<span class="smwtlevent">' . $curmeta . '<span class="smwtlcoloricon">' . $curcolor . '</span>' . $curdata . '</span>';
184210 }
 211+
185212 if ( $eventline ) {
186213 foreach ( $events as $event ) {
187214 $result .= '<span class="smwtlevent"><span class="smwtlstart">' . $event[0] . '</span><span class="smwtlurl">' . $event[1] . '</span><span class="smwtlcoloricon">' . $curcolor . '</span>';
@@ -192,9 +219,11 @@
193220 $curcolor = ( $curcolor + 1 ) % 10;
194221 }
195222 }
 223+
196224 if ( count( $positions ) > 0 ) {
197225 ksort( $positions );
198226 $positions = array_values( $positions );
 227+
199228 switch ( $this->m_tlpos ) {
200229 case 'start':
201230 $result .= '<span class="smwtlposition">' . $positions[0] . '</span>';
@@ -217,7 +246,7 @@
218247 return $result;
219248 }
220249
221 - function getParameters() {
 250+ public function getParameters() {
222251 $params = parent::getParameters();
223252 $params[] = array( 'name' => 'timelinebands', 'type' => 'enum-list', 'description' => wfMsg( 'srf_paramdesc_timelinebands' ), 'values' => array( 'DECADE', 'YEAR', 'MONTH', 'WEEK', 'DAY', 'HOUR', 'MINUTE' ) );
224253 $params[] = array( 'name' => 'timelineposition', 'type' => 'enumeration', 'description' => wfMsg( 'srf_paramdesc_timelineposition' ), 'values' => array( 'start', 'middle', 'end' ) );
@@ -226,4 +255,5 @@
227256 $params[] = array( 'name' => 'timelinesize', 'type' => 'string', 'description' => wfMsg( 'srf_paramdesc_timelinesize' ) );
228257 return $params;
229258 }
 259+
230260 }

Status & tagging log