r81258 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r81257‎ | r81258 | r81259 >
Date:17:06, 31 January 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Follow up to r81257
Modified paths:
  • /trunk/extensions/SemanticResultFormats/Timeline/SRF_Timeline.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticResultFormats/Timeline/SRF_Timeline.php
@@ -171,96 +171,14 @@
172172 $date_value = $pr->getData()->getXSDValue();
173173 }
174174
175 - while ( ( $object = $field->getNextObject() ) !== false ) {
176 - $l = $this->getLinker( $first_col );
177 -
178 - if ( !$hastitle && $object->getTypeID() != '_wpg' ) { // "linking" non-pages in title positions confuses timeline scripts, don't try this
179 - $l = null;
 175+ while ( ( $object = $field->getNextObject() ) !== false ) { // Loop over property values
 176+ $event = $this->handlePropertyValue(
 177+ $object, $outputmode, $pr, $first_col, $hastitle, $hastime,
 178+ $first_value, $isEventline, $curmeta, $curdata, $date_value
 179+ );
 180+ if ( $event !== false ) {
 181+ $events[] = $event;
180182 }
181 -
182 - if ( $object->getTypeID() == '_wpg' ) { // use shorter "LongText" for wikipage
183 - $objectlabel = $object->getLongText( $outputmode, $l );
184 - } else {
185 - $objectlabel = $object->getShortText( $outputmode, $l );
186 - }
187 -
188 - $urlobject = ( $l !== null );
189 - $header = '';
190 -
191 - if ( $first_value ) {
192 - // find header for current value:
193 - if ( $this->mShowHeaders && ( '' != $pr->getLabel() ) ) {
194 - $header = $pr->getText( $outputmode, $this->mLinker ) . ': ';
195 - }
196 -
197 - // is this a start date?
198 - if ( ( $pr->getMode() == SMWPrintRequest::PRINT_PROP ) &&
199 - ( $date_value == $this->m_tlstart ) ) {
200 - // FIXME: Timeline scripts should support XSD format explicitly. They
201 - // currently seem to implement iso8601 which deviates from XSD in cases.
202 - // NOTE: We can assume $object to be an SMWDataValue in this case.
203 - $curmeta .= Html::element(
204 - 'span',
205 - array( 'class' => 'smwtlstart' ),
206 - $object->getXMLSchemaDate()
207 - );
208 - $positions[$object->getHash()] = $object->getXMLSchemaDate();
209 - $hastime = true;
210 - }
211 -
212 - // is this the end date?
213 - if ( ( $pr->getMode() == SMWPrintRequest::PRINT_PROP ) &&
214 - ( $date_value == $this->m_tlend ) ) {
215 - // NOTE: We can assume $object to be an SMWDataValue in this case.
216 - $curmeta .= Html::element(
217 - 'span',
218 - array( 'class' => 'smwtlend' ),
219 - $object->getXMLSchemaDate( false )
220 - );
221 - }
222 -
223 - // find title for displaying event
224 - if ( !$hastitle ) {
225 - $curmeta .= Html::element(
226 - 'span',
227 - array(
228 - 'class' => $urlobject ? 'smwtlurl' : 'smwtltitle'
229 - ),
230 - $objectlabel
231 - );
232 -
233 - if ( ( $pr->getMode() == SMWPrintRequest::PRINT_THIS ) ) {
234 - // NOTE: type Title of $object implied
235 - $curarticle = $object->getLongWikiText();
236 - }
237 - $hastitle = true;
238 - }
239 - } elseif ( $output ) {
240 - // 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
241 - $curdata .= ', ';
242 - }
243 -
244 - if ( !$first_col || !$first_value || $isEventline ) {
245 - $curdata .= $header . $objectlabel;
246 - $output = true;
247 - }
248 -
249 - if ( $isEventline && ( $pr->getMode() == SMWPrintRequest::PRINT_PROP ) && ( $pr->getTypeID() == '_dat' ) && ( '' != $pr->getLabel() ) && ( $date_value != $this->m_tlstart ) && ( $date_value != $this->m_tlend ) ) {
250 - if ( method_exists( $object, 'getValueKey' ) ) {
251 - $events[] = array(
252 - $object->getXMLSchemaDate(),
253 - $pr->getLabel(),
254 - $object->getValueKey()
255 - );
256 - }
257 - else {
258 - $events[] = array(
259 - $object->getXMLSchemaDate(),
260 - $pr->getLabel(),
261 - $object->getNumericValue()
262 - );
263 - }
264 - }
265183 $first_value = false;
266184 }
267185
@@ -313,7 +231,124 @@
314232
315233 return $result;
316234 }
 235+
 236+ /**
 237+ * Hanldes a single property value. Returns an array with data for a single event or false.
 238+ *
 239+ * @since 1.5.3
 240+ *
 241+ * @param SMWDataValue $object
 242+ * @param $outputmode
 243+ * @param SMWPrintRequest $pr
 244+ * @param boolean $first_col
 245+ * @param boolean &$hastitle
 246+ * @param boolean &$hastime
 247+ * @param boolean $first_value
 248+ * @param boolean $isEventline
 249+ * @param string &$curmeta
 250+ * @param string &$curdata
 251+ * @param &$date_value
 252+ *
 253+ * @return false or array
 254+ */
 255+ protected function handlePropertyValue( SMWDataValue $object, $outputmode, SMWPrintRequest $pr, $first_col,
 256+ &$hastitle, &$hastime, $first_value, $isEventline, &$curmeta, &$curdata, $date_value ) {
 257+
 258+ $event = false;
 259+
 260+ $l = $this->getLinker( $first_col );
 261+
 262+ if ( !$hastitle && $object->getTypeID() != '_wpg' ) { // "linking" non-pages in title positions confuses timeline scripts, don't try this
 263+ $l = null;
 264+ }
 265+
 266+ if ( $object->getTypeID() == '_wpg' ) { // use shorter "LongText" for wikipage
 267+ $objectlabel = $object->getLongText( $outputmode, $l );
 268+ } else {
 269+ $objectlabel = $object->getShortText( $outputmode, $l );
 270+ }
 271+
 272+ $urlobject = ( $l !== null );
 273+ $header = '';
 274+
 275+ if ( $first_value ) {
 276+ // find header for current value:
 277+ if ( $this->mShowHeaders && ( '' != $pr->getLabel() ) ) {
 278+ $header = $pr->getText( $outputmode, $this->mLinker ) . ': ';
 279+ }
 280+
 281+ // is this a start date?
 282+ if ( ( $pr->getMode() == SMWPrintRequest::PRINT_PROP ) &&
 283+ ( $date_value == $this->m_tlstart ) ) {
 284+ // FIXME: Timeline scripts should support XSD format explicitly. They
 285+ // currently seem to implement iso8601 which deviates from XSD in cases.
 286+ // NOTE: We can assume $object to be an SMWDataValue in this case.
 287+ $curmeta .= Html::element(
 288+ 'span',
 289+ array( 'class' => 'smwtlstart' ),
 290+ $object->getXMLSchemaDate()
 291+ );
 292+ $positions[$object->getHash()] = $object->getXMLSchemaDate();
 293+ $hastime = true;
 294+ }
 295+
 296+ // is this the end date?
 297+ if ( ( $pr->getMode() == SMWPrintRequest::PRINT_PROP ) &&
 298+ ( $date_value == $this->m_tlend ) ) {
 299+ // NOTE: We can assume $object to be an SMWDataValue in this case.
 300+ $curmeta .= Html::element(
 301+ 'span',
 302+ array( 'class' => 'smwtlend' ),
 303+ $object->getXMLSchemaDate( false )
 304+ );
 305+ }
 306+
 307+ // find title for displaying event
 308+ if ( !$hastitle ) {
 309+ $curmeta .= Html::element(
 310+ 'span',
 311+ array(
 312+ 'class' => $urlobject ? 'smwtlurl' : 'smwtltitle'
 313+ ),
 314+ $objectlabel
 315+ );
317316
 317+ if ( ( $pr->getMode() == SMWPrintRequest::PRINT_THIS ) ) {
 318+ // NOTE: type Title of $object implied
 319+ $curarticle = $object->getLongWikiText();
 320+ }
 321+ $hastitle = true;
 322+ }
 323+ } elseif ( $output ) {
 324+ // 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
 325+ $curdata .= ', ';
 326+ }
 327+
 328+ if ( !$first_col || !$first_value || $isEventline ) {
 329+ $curdata .= $header . $objectlabel;
 330+ $output = true;
 331+ }
 332+
 333+ if ( $isEventline && ( $pr->getMode() == SMWPrintRequest::PRINT_PROP ) && ( $pr->getTypeID() == '_dat' ) && ( '' != $pr->getLabel() ) && ( $date_value != $this->m_tlstart ) && ( $date_value != $this->m_tlend ) ) {
 334+ if ( method_exists( $object, 'getValueKey' ) ) {
 335+ $event = array(
 336+ $object->getXMLSchemaDate(),
 337+ $pr->getLabel(),
 338+ $object->getValueKey()
 339+ );
 340+ }
 341+ else {
 342+ $event = array(
 343+ $object->getXMLSchemaDate(),
 344+ $pr->getLabel(),
 345+ $object->getNumericValue()
 346+ );
 347+ }
 348+ }
 349+
 350+ return $event;
 351+ }
 352+
318353 /**
319354 * @see SMWResultPrinter::getParameters
320355 *

Follow-up revisions

RevisionCommit summaryAuthorDate
r81259Follow up to r81258jeroendedauw17:13, 31 January 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r81257Splitting up huge methodjeroendedauw16:44, 31 January 2011

Status & tagging log