r103909 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103908‎ | r103909 | r103910 >
Date:16:03, 22 November 2011
Author:danwe
Status:deferred
Tags:
Comment:
array and hash formats compatibility to Arrays 2.0 and HashTables 1.0 ensured.
Modified paths:
  • /trunk/extensions/SemanticResultFormats/Array/SRF_Array.php (modified) (history)
  • /trunk/extensions/SemanticResultFormats/RELEASE-NOTES (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticResultFormats/RELEASE-NOTES
@@ -11,6 +11,7 @@
1212 * Added min parameter to jqplotbar to set the minimun value for the Y-axis.
1313 * Added pointlabel parameter to jqplotbar and chartlegend, legendlocation,
1414 datalabels and datalabeltype parameters to jqplotpie based on a patches by James Hong Kong.
 15+* array and hash formats compatible with 'Array' extension 2.0 and 'HashTables' 1.0 now.
1516
1617 New formats in this version are:
1718 * valuerank (written by DaSch)
Index: trunk/extensions/SemanticResultFormats/Array/SRF_Array.php
@@ -1,14 +1,14 @@
22 <?php
33 /**
4 - * Query format for arrays with features for Extensions ArrayExtension and HashTables
 4+ * Query format for arrays with features for Extensions 'Arrays' and 'HashTables'
55 * @file
66 * @ingroup SemanticResultFormats
77 * @author Daniel Werner < danweetz@web.de >
88 *
9 - * Doesn't require ArrayExtension nor HashTables but has additional features
 9+ * Doesn't require 'Arrays' nor 'HashTables' exytensions but has additional features
1010 * ('name' parameter in either result format) if they are available.
1111 *
12 - * ArrayExtension 1.3.2+ and HashTables 0.6+ are recommended but not necessary
 12+ * Arrays 2.0+ and HashTables 1.0+ are recommended but not necessary.
1313 */
1414
1515 /**
@@ -197,25 +197,39 @@
198198 }
199199
200200 /**
201 - * @ToDo: adjust for ArrayExtension 1.4
 201+ * Helper function to create a new Array within 'Arrays' extension. Takes care of different versions
 202+ * as well as the old 'ArrayExtension'.
202203 */
203204 protected function createArray( $array ) {
204205 global $wgArrayExtension;
205206
 207+ $arrayId = $this->mArrayName;
 208+
 209+ if( defined( 'ExtArrays::VERSION' ) ) {
 210+ // 'Arrays' extension 2+
 211+ global $wgParser; /** ToDo: is there a way to get the actual parser which has started the query? */
 212+ ExtArrays::get( $wgParser )->createArray( $arrayId, $array );
 213+ return true;
 214+ }
 215+
 216+ // compatbility to 'ArrayExtension' extension before 2.0:
 217+
206218 if( ! isset( $wgArrayExtension ) ) {
207219 //Hash extension is not installed in this wiki
208220 return false;
209221 }
210 - $version = null;
 222+ $version = null;
211223 if( defined( 'ArrayExtension::VERSION' ) ) {
212 - $version = ArrayExtension::VERSION;
 224+ $version = ExtArrayExtension::VERSION;
213225 } elseif( defined( 'ExtArrayExtension::VERSION' ) ) {
214226 $version = ExtArrayExtension::VERSION;
215227 }
216228 if( $version !== null && version_compare( $version, '1.3.2', '>=' ) ) {
217 - $wgArrayExtension->createArray( $this->mArrayName, $array ); //requires Extension:ArrayExtension 1.3.2 or higher
 229+ // ArrayExtension 1.3.2+
 230+ $wgArrayExtension->createArray( $arrayId, $array );
218231 } else {
219 - $wgArrayExtension->mArrayExtension[ trim( $this->mArrayName ) ] = $array;
 232+ // dirty way
 233+ $wgArrayExtension->mArrays[ trim( $arrayId ) ] = $array;
220234 }
221235 return true;
222236 }
@@ -402,6 +416,7 @@
403417 return array( $this->mLastPageTitle, implode( $this->mPropSep, $perProperty_items ) );
404418 }
405419 protected function deliverQueryResultPages( $perPage_items ) {
 420+ $hash = array();
406421 foreach( $perPage_items as $page ) {
407422 $hash[ $page[0] ] = $page[1]; //name of page as key, Properties as value
408423 }
@@ -414,19 +429,28 @@
415430 protected function createArray( $hash ) {
416431 global $wgHashTables;
417432
418 - if( ! isset( $wgHashTables ) ) {
419 - //Hash extension is not installed in this wiki
420 - return false;
421 - }
 433+ $hashId = $this->mArrayName;
422434 $version = null;
423435 if( defined( 'ExtHashTables::VERSION' ) ) {
424436 $version = ExtHashTables::VERSION;
425437 }
426 - if( $version !== null && version_compare( $version, '0.6', '>=' ) ) {
427 - $wgHashTables->createHash( $this->mArrayName, $hash ); //requires Extension:HashTables 0.6 or higher
428 - } else {
429 - $wgHashTables->mHashTables[ trim( $this->mArrayName ) ] = $hash; //dirty way
 438+ if( $version !== null && version_compare( $version, '0.999', '>=' ) ) {
 439+ // Version 1.0+, doesn't use $wgHashTables anymore
 440+ global $wgParser; /** ToDo: is there a way to get the actual parser which has started the query? */
 441+ ExtHashTables::get( $wgParser )->createHash( $hashId, $hash );
 442+ }
 443+ elseif( ! isset( $wgHashTables ) ) {
 444+ //Hash extension is not installed in this wiki
 445+ return false;
430446 }
 447+ elseif( $version !== null && version_compare( $version, '0.6', '>=' ) ) {
 448+ // HashTables 0.6 to 1.0
 449+ $wgHashTables->createHash( $hashId, $hash );
 450+ }
 451+ else {
 452+ // old HashTables, dirty way
 453+ $wgHashTables->mHashTables[ trim( $hashId ) ] = $hash;
 454+ }
431455 return true;
432456 }
433457