Index: trunk/extensions/SemanticResultFormats/RELEASE-NOTES |
— | — | @@ -11,6 +11,7 @@ |
12 | 12 | * Added min parameter to jqplotbar to set the minimun value for the Y-axis. |
13 | 13 | * Added pointlabel parameter to jqplotbar and chartlegend, legendlocation, |
14 | 14 | 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. |
15 | 16 | |
16 | 17 | New formats in this version are: |
17 | 18 | * valuerank (written by DaSch) |
Index: trunk/extensions/SemanticResultFormats/Array/SRF_Array.php |
— | — | @@ -1,14 +1,14 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | | - * Query format for arrays with features for Extensions ArrayExtension and HashTables |
| 4 | + * Query format for arrays with features for Extensions 'Arrays' and 'HashTables' |
5 | 5 | * @file |
6 | 6 | * @ingroup SemanticResultFormats |
7 | 7 | * @author Daniel Werner < danweetz@web.de > |
8 | 8 | * |
9 | | - * Doesn't require ArrayExtension nor HashTables but has additional features |
| 9 | + * Doesn't require 'Arrays' nor 'HashTables' exytensions but has additional features |
10 | 10 | * ('name' parameter in either result format) if they are available. |
11 | 11 | * |
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. |
13 | 13 | */ |
14 | 14 | |
15 | 15 | /** |
— | — | @@ -197,25 +197,39 @@ |
198 | 198 | } |
199 | 199 | |
200 | 200 | /** |
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'. |
202 | 203 | */ |
203 | 204 | protected function createArray( $array ) { |
204 | 205 | global $wgArrayExtension; |
205 | 206 | |
| 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 | + |
206 | 218 | if( ! isset( $wgArrayExtension ) ) { |
207 | 219 | //Hash extension is not installed in this wiki |
208 | 220 | return false; |
209 | 221 | } |
210 | | - $version = null; |
| 222 | + $version = null; |
211 | 223 | if( defined( 'ArrayExtension::VERSION' ) ) { |
212 | | - $version = ArrayExtension::VERSION; |
| 224 | + $version = ExtArrayExtension::VERSION; |
213 | 225 | } elseif( defined( 'ExtArrayExtension::VERSION' ) ) { |
214 | 226 | $version = ExtArrayExtension::VERSION; |
215 | 227 | } |
216 | 228 | 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 ); |
218 | 231 | } else { |
219 | | - $wgArrayExtension->mArrayExtension[ trim( $this->mArrayName ) ] = $array; |
| 232 | + // dirty way |
| 233 | + $wgArrayExtension->mArrays[ trim( $arrayId ) ] = $array; |
220 | 234 | } |
221 | 235 | return true; |
222 | 236 | } |
— | — | @@ -402,6 +416,7 @@ |
403 | 417 | return array( $this->mLastPageTitle, implode( $this->mPropSep, $perProperty_items ) ); |
404 | 418 | } |
405 | 419 | protected function deliverQueryResultPages( $perPage_items ) { |
| 420 | + $hash = array(); |
406 | 421 | foreach( $perPage_items as $page ) { |
407 | 422 | $hash[ $page[0] ] = $page[1]; //name of page as key, Properties as value |
408 | 423 | } |
— | — | @@ -414,19 +429,28 @@ |
415 | 430 | protected function createArray( $hash ) { |
416 | 431 | global $wgHashTables; |
417 | 432 | |
418 | | - if( ! isset( $wgHashTables ) ) { |
419 | | - //Hash extension is not installed in this wiki |
420 | | - return false; |
421 | | - } |
| 433 | + $hashId = $this->mArrayName; |
422 | 434 | $version = null; |
423 | 435 | if( defined( 'ExtHashTables::VERSION' ) ) { |
424 | 436 | $version = ExtHashTables::VERSION; |
425 | 437 | } |
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; |
430 | 446 | } |
| 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 | + } |
431 | 455 | return true; |
432 | 456 | } |
433 | 457 | |