https://www.mediawiki.org/wiki/Special:Code/MediaWiki/114481
Revision: 114481
Author: jeroendedauw
Date: 2012-03-25 19:20:43 +0000 (Sun, 25 Mar 2012)
Log Message:
-----------
apply modified patch by nischayn22 from bug 26027
Modified Paths:
--------------
trunk/extensions/SemanticResultFormats/SRF_Settings.php
trunk/extensions/SemanticResultFormats/SemanticResultFormats.php
Added Paths:
-----------
trunk/extensions/SemanticResultFormats/Time/
trunk/extensions/SemanticResultFormats/Time/SRF_Time.php
Modified: trunk/extensions/SemanticResultFormats/SRF_Settings.php
===================================================================
--- trunk/extensions/SemanticResultFormats/SRF_Settings.php 2012-03-25
14:59:48 UTC (rev 114480)
+++ trunk/extensions/SemanticResultFormats/SRF_Settings.php 2012-03-25
19:20:43 UTC (rev 114481)
@@ -48,6 +48,8 @@
'D3Line',
'D3Bar',
'D3Treemap',
+ 'latest',
+ 'earliest',
// Still in alpha:
// 'filtered',
Modified: trunk/extensions/SemanticResultFormats/SemanticResultFormats.php
===================================================================
--- trunk/extensions/SemanticResultFormats/SemanticResultFormats.php
2012-03-25 14:59:48 UTC (rev 114480)
+++ trunk/extensions/SemanticResultFormats/SemanticResultFormats.php
2012-03-25 19:20:43 UTC (rev 114481)
@@ -95,8 +95,9 @@
$wgAutoloadClasses['SRFD3Line'] = $formatDir . 'D3/SRF_D3Line.php';
$wgAutoloadClasses['SRFD3Bar'] = $formatDir . 'D3/SRF_D3Bar.php';
$wgAutoloadClasses['SRFD3Treemap'] = $formatDir . 'D3/SRF_D3Treemap.php';
-$wgAutoloadClasses['SRFTree'] = $formatDir . 'Tree/SRF_Tree.php';
-$wgAutoloadClasses['SRFFiltered'] = $formatDir . 'Filtered/SRF_Filtered.php';
+$wgAutoloadClasses['SRFTree'] = $formatDir . 'Tree/SRF_Tree.php';
+$wgAutoloadClasses['SRFFiltered'] = $formatDir . 'Filtered/SRF_Filtered.php';
+$wgAutoloadClasses['SRFTime'] = $formatDir . 'Time/SRF_Time.php';
unset( $formatDir );
@@ -149,6 +150,8 @@
'ultree' => 'SRFTree',
'oltree' => 'SRFTree',
'filtered' => 'SRFFiltered',
+ 'latest' => 'SRFTime',
+ 'earliest' => 'SRFTime',
);
$formatAliases = array(
Added: trunk/extensions/SemanticResultFormats/Time/SRF_Time.php
===================================================================
--- trunk/extensions/SemanticResultFormats/Time/SRF_Time.php
(rev 0)
+++ trunk/extensions/SemanticResultFormats/Time/SRF_Time.php 2012-03-25
19:20:43 UTC (rev 114481)
@@ -0,0 +1,88 @@
+<?php
+
+/**
+ *
+ * @file
+ * @ingroup SemanticResultFormats
+ * @licence GNU GPL v3+
+ *
+ */
+class SRFTime extends SMWResultPrinter {
+
+ /**
+ * (non-PHPdoc)
+ * @see SMWResultPrinter::getName()
+ */
+ public function getName() {
+ return wfMsg( 'srf_printername_' . $this->mFormat );
+ }
+
+ /**
+ * (non-PHPdoc)
+ * @see SMWResultPrinter::getResultText()
+ */
+ protected function getResultText( SMWQueryResult $res, $outputmode ) {
+ $dataItems = $this->getSortKeys( $res );
+
+ if ( empty( $dataItems ) ) {
+ return $this->params['default'];
+ }
+
+ $sortKeys = array_keys( $dataItems );
+
+ switch ( $this->mFormat ) {
+ case 'latest':
+ $result = max( $sortKeys );
+ break;
+ case 'earliest':
+ $result = min( $sortKeys );
+ break;
+ }
+
+ $dataValue = SMWDataValueFactory::newDataItemValue(
$dataItems[$result], null );
+ return $dataValue->getLongHTMLText();
+ }
+
+ /**
+ * Gets a list of SortKeys for all dates.
+ *
+ *
+ * @param SMWQueryResult $res
+ *
+ * @return array
+ */
+ protected function getSortKeys( SMWQueryResult $res ) {
+ $seconds = array();
+
+ while ( $row = $res->getNext() ) {
+ foreach( $row as /* SMWResultArray */ $resultArray ) {
+ foreach ( $resultArray->getContent() as /*
SMWDataItem */ $dataItem ) {
+ if ( $dataItem->getDIType() ===
SMWDataItem::TYPE_TIME ) {
+
$seconds[$dataItem->getSortKey()] = $dataItem;
+ }
+ }
+ }
+ }
+
+ return $seconds;
+ }
+
+ /**
+ * (non-PHPdoc)
+ * @see SMWResultPrinter::getParameters()
+ */
+ public function getParameters() {
+ $params = parent::getParameters();
+
+ $params['limit'] = new Parameter( 'limit',
Parameter::TYPE_INTEGER );
+ $params['limit']->setMessage( 'srf_paramdesc_limit' );
+ $params['limit']->setDefault( 1000 );
+
+ $params['default'] = new Parameter( 'default' );
+ $params['default']->setMessage( 'srf-paramdesc-default' );
+ $params['default']->setDefault( 'default' );
+
+ return $params;
+ }
+
+}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs