Index: trunk/extensions/Arrays/Arrays.php |
— | — | @@ -15,7 +15,7 @@ |
16 | 16 | * @author Li Ding < lidingpku@gmail.com > |
17 | 17 | * @author Jie Bao |
18 | 18 | * @author Daniel Werner < danweetz@web.de > (since version 1.3) |
19 | | - * |
| 19 | + * |
20 | 20 | * @ToDo: |
21 | 21 | * use $egArrayExtensionCompatbilityMode to finally get rid of unlogic behavior of certain functions |
22 | 22 | * who create a new array from the data of one or more old arrays. In case only the new array name is |
— | — | @@ -46,9 +46,9 @@ |
47 | 47 | * Full compatbility to versions before 1.4. |
48 | 48 | * Set to true by default since version 2.0. |
49 | 49 | * Regretable, this one has a speclling error... |
50 | | - * |
| 50 | + * |
51 | 51 | * @since 1.4 alpha |
52 | | - * |
| 52 | + * |
53 | 53 | * @var boolean |
54 | 54 | */ |
55 | 55 | $egArrayExtensionCompatbilityMode = false; |
— | — | @@ -57,32 +57,32 @@ |
58 | 58 | /** |
59 | 59 | * Extension class with all the array functionality, also serves as store for arrays per |
60 | 60 | * Parser object and offers public accessors for interaction with the 'Arrays' extension. |
61 | | - * |
| 61 | + * |
62 | 62 | * @since 2.0 ('ArrayExtension' before and one global instance, also non-static parser functions) |
63 | 63 | */ |
64 | 64 | class ExtArrays { |
65 | 65 | |
66 | 66 | /** |
67 | 67 | * Version of the 'Arrays' extension. |
68 | | - * |
| 68 | + * |
69 | 69 | * @since 2.0 (before in 'Arrays' class since 1.3.2) |
70 | 70 | */ |
71 | 71 | const VERSION = '2.0 alpha'; |
72 | 72 | |
73 | 73 | /** |
74 | 74 | * Store for arrays. |
75 | | - * |
| 75 | + * |
76 | 76 | * @var array |
77 | 77 | * @private |
78 | 78 | */ |
79 | | - var $mArrays = array(); |
| 79 | + var $mArrays = array(); |
80 | 80 | |
81 | 81 | /** |
82 | 82 | * Sets up parser functions |
83 | | - * |
| 83 | + * |
84 | 84 | * @since 2.0 |
85 | 85 | */ |
86 | | - public static function init( Parser &$parser ) { |
| 86 | + public static function init( Parser &$parser ) { |
87 | 87 | /* |
88 | 88 | * store for arrays per Parser object. This will solve several bugs related to |
89 | 89 | * 'ParserClearState' hook clearing all variables early in combination with certain |
— | — | @@ -94,8 +94,8 @@ |
95 | 95 | self::initFunction( $parser, 'arraydefine' ); |
96 | 96 | self::initFunction( $parser, 'arrayprint', SFH_OBJECT_ARGS ); |
97 | 97 | self::initFunction( $parser, 'arrayindex', SFH_OBJECT_ARGS ); |
98 | | - self::initFunction( $parser, 'arraysize' ); |
99 | | - self::initFunction( $parser, 'arraysearch', SFH_OBJECT_ARGS ); |
| 98 | + self::initFunction( $parser, 'arraysize' ); |
| 99 | + self::initFunction( $parser, 'arraysearch', SFH_OBJECT_ARGS ); |
100 | 100 | self::initFunction( $parser, 'arraysearcharray' ); |
101 | 101 | self::initFunction( $parser, 'arrayslice' ); |
102 | 102 | self::initFunction( $parser, 'arrayreset', SFH_OBJECT_ARGS ); |
— | — | @@ -105,22 +105,22 @@ |
106 | 106 | self::initFunction( $parser, 'arrayunion', SFH_OBJECT_ARGS ); |
107 | 107 | self::initFunction( $parser, 'arraydiff', SFH_OBJECT_ARGS ); |
108 | 108 | self::initFunction( $parser, 'arrayintersect', SFH_OBJECT_ARGS ); |
109 | | - |
| 109 | + |
110 | 110 | return true; |
111 | 111 | } |
112 | | - private static function initFunction( Parser &$parser, $name, $flags = 0 ) { |
| 112 | + private static function initFunction( Parser &$parser, $name, $flags = 0 ) { |
113 | 113 | // all parser functions with prefix: |
114 | | - $prefix = ( $flags & SFH_OBJECT_ARGS ) ? 'pfObj_' : 'pf_'; |
| 114 | + $prefix = ( $flags & SFH_OBJECT_ARGS ) ? 'pfObj_' : 'pf_'; |
115 | 115 | $functionCallback = array( __CLASS__, $prefix . $name ); |
116 | | - |
117 | | - $parser->setFunctionHook( $name, $functionCallback, $flags ); |
118 | | - } |
119 | | - |
| 116 | + |
| 117 | + $parser->setFunctionHook( $name, $functionCallback, $flags ); |
| 118 | + } |
| 119 | + |
120 | 120 | /** |
121 | 121 | * Returns the extensions base installation directory. |
122 | 122 | * |
123 | 123 | * @since 2.0 |
124 | | - * |
| 124 | + * |
125 | 125 | * @return boolean |
126 | 126 | */ |
127 | 127 | public static function getDir() { |
— | — | @@ -130,8 +130,8 @@ |
131 | 131 | } |
132 | 132 | return $dir; |
133 | 133 | } |
134 | | - |
135 | | - |
| 134 | + |
| 135 | + |
136 | 136 | #################### |
137 | 137 | # Parser Functions # |
138 | 138 | #################### |
— | — | @@ -149,31 +149,31 @@ |
150 | 150 | * http://us2.php.net/manual/en/book.pcre.php |
151 | 151 | * see also: http://us2.php.net/manual/en/function.preg-split.php |
152 | 152 | */ |
153 | | - static function pf_arraydefine( |
| 153 | + static function pf_arraydefine( |
154 | 154 | Parser &$parser, |
155 | 155 | $arrayId, |
156 | 156 | $value = null, |
157 | 157 | $delimiter = '/\s*,\s*/', |
158 | 158 | $options = '' |
159 | 159 | ) { |
160 | | - if ( !isset( $arrayId ) ) { |
161 | | - return ''; |
162 | | - } |
163 | | - |
| 160 | + if ( !isset( $arrayId ) ) { |
| 161 | + return ''; |
| 162 | + } |
| 163 | + |
164 | 164 | $out = ''; |
165 | 165 | $array = array(); |
166 | 166 | $trimDone = false; // whether or not we can be sure that all array elements are trimmed |
167 | | - |
168 | | - // normalize |
169 | | - $delimiter = trim( $delimiter ); |
170 | 167 | |
171 | | - if( $value === null ) { |
| 168 | + // normalize |
| 169 | + $delimiter = trim( $delimiter ); |
| 170 | + |
| 171 | + if( $value === null ) { |
172 | 172 | // no element set, not even an empty one |
173 | | - $array = array(); |
174 | | - } |
| 173 | + $array = array(); |
| 174 | + } |
175 | 175 | else { |
176 | 176 | $value = trim( $value ); // just in case... |
177 | | - |
| 177 | + |
178 | 178 | // fill array with user input: |
179 | 179 | if( $delimiter === '' ) { |
180 | 180 | // whole input one element, also takes care of special case empty '' value and 'unique' option set |
— | — | @@ -188,21 +188,21 @@ |
189 | 189 | } |
190 | 190 | $array = preg_split( $delimiter, $value ); |
191 | 191 | } |
192 | | - |
| 192 | + |
193 | 193 | // trim all values before unique if still necessary, otherwise unique might not work correctly |
194 | 194 | if( ! $trimDone ) { |
195 | 195 | $array = self::sanitizeArray( $array ); |
196 | 196 | } |
197 | 197 | |
198 | | - // now parse the options, and do posterior process on the created array |
199 | | - $arrayOptions = self::parse_options( $options ); |
200 | | - |
201 | | - // make it unique if option is set |
202 | | - if( array_key_exists( 'unique', $arrayOptions ) ) { |
| 198 | + // now parse the options, and do posterior process on the created array |
| 199 | + $arrayOptions = self::parse_options( $options ); |
| 200 | + |
| 201 | + // make it unique if option is set |
| 202 | + if( array_key_exists( 'unique', $arrayOptions ) ) { |
203 | 203 | // unique like the parser function would do it |
204 | 204 | $array = self::array_unique( $array ); |
205 | | - } |
206 | | - |
| 205 | + } |
| 206 | + |
207 | 207 | /** |
208 | 208 | * @ToDo: |
209 | 209 | * The 'empty' option was introduced in r81676 but actually breaks old functionality since it will remove |
— | — | @@ -213,19 +213,19 @@ |
214 | 214 | */ |
215 | 215 | /* |
216 | 216 | // remove all empty '' elements if option is NOT set |
217 | | - if( ! array_key_exists( 'empty', $arrayOptions ) ) { |
| 217 | + if( ! array_key_exists( 'empty', $arrayOptions ) ) { |
218 | 218 | $values = array(); // temp array so we won't have gaps (don't use unset!) |
219 | | - foreach ( $array as $key => $value ) { |
220 | | - if( $value !== '' ) { |
221 | | - $values[] = $elem; |
222 | | - } |
223 | | - } |
| 219 | + foreach ( $array as $key => $value ) { |
| 220 | + if( $value !== '' ) { |
| 221 | + $values[] = $elem; |
| 222 | + } |
| 223 | + } |
224 | 224 | $array = $values; |
225 | 225 | unset( $values ); |
226 | | - } |
| 226 | + } |
227 | 227 | */ |
228 | 228 | |
229 | | - // sort array if the option is set |
| 229 | + // sort array if the option is set |
230 | 230 | if( array_key_exists( 'sort', $arrayOptions ) ) { |
231 | 231 | $array = self::arraySort( $array, self::array_value( $arrayOptions, 'sort' ) ); |
232 | 232 | } |
— | — | @@ -238,11 +238,11 @@ |
239 | 239 | break; |
240 | 240 | } |
241 | 241 | } |
242 | | - |
| 242 | + |
243 | 243 | self::get( $parser )->setArray( $arrayId, $array ); |
244 | 244 | |
245 | 245 | return $out; |
246 | | - } |
| 246 | + } |
247 | 247 | |
248 | 248 | |
249 | 249 | /////////////////////////////////////////////////////////// |
— | — | @@ -265,21 +265,21 @@ |
266 | 266 | * {{#arrayprint:b|<br/>|@@@|{{f.tag{{f.print.vbar}}prop{{f.print.vbar}}@@@}} }} -- embed template function |
267 | 267 | * {{#arrayprint:b|<br/>|@@@|[[name::@@@]]}} -- make SMW links |
268 | 268 | */ |
269 | | - static function pfObj_arrayprint( Parser &$parser, $frame, $args ) { |
270 | | - // Get Parameters |
271 | | - $arrayId = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : ''; |
272 | | - $delimiter = isset( $args[1] ) ? trim( $frame->expand( $args[1] ) ) : ', '; |
| 269 | + static function pfObj_arrayprint( Parser &$parser, $frame, $args ) { |
| 270 | + // Get Parameters |
| 271 | + $arrayId = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : ''; |
| 272 | + $delimiter = isset( $args[1] ) ? trim( $frame->expand( $args[1] ) ) : ', '; |
273 | 273 | /* |
274 | 274 | * PPFrame::NO_ARGS and PPFrame::NO_TEMPLATES for expansion make a lot of sense here since the patterns getting replaced |
275 | 275 | * in $subject before $subject is being parsed. So any template or argument influence in the patterns wouldn't make any |
276 | 276 | * sense in any sane scenario. |
277 | 277 | */ |
278 | | - $search = isset( $args[2] ) ? trim( $frame->expand( $args[2], PPFrame::NO_ARGS | PPFrame::NO_TEMPLATES ) ) : '@@@@'; |
279 | | - $subject = isset( $args[3] ) ? trim( $frame->expand( $args[3], PPFrame::NO_ARGS | PPFrame::NO_TEMPLATES ) ) : '@@@@'; |
280 | | - |
| 278 | + $search = isset( $args[2] ) ? trim( $frame->expand( $args[2], PPFrame::NO_ARGS | PPFrame::NO_TEMPLATES ) ) : '@@@@'; |
| 279 | + $subject = isset( $args[3] ) ? trim( $frame->expand( $args[3], PPFrame::NO_ARGS | PPFrame::NO_TEMPLATES ) ) : '@@@@'; |
| 280 | + |
281 | 281 | // get array, null if non-existant: |
282 | 282 | $array = self::get( $parser )->getArray( $arrayId ); |
283 | | - |
| 283 | + |
284 | 284 | if( $array === null ) { |
285 | 285 | // array we want to print doesn't exist! |
286 | 286 | global $egArrayExtensionCompatbilityMode; |
— | — | @@ -292,11 +292,11 @@ |
293 | 293 | } |
294 | 294 | |
295 | 295 | $rendered_values = array(); |
296 | | - |
| 296 | + |
297 | 297 | foreach( $array as $val ) { |
298 | 298 | // replace place holder with current value: |
299 | 299 | $rawResult = str_replace( $search, $val, $subject ); |
300 | | - |
| 300 | + |
301 | 301 | /* |
302 | 302 | * $subjectd still is un-expanded (this allows to use some parser functions like |
303 | 303 | * {{FULLPAGENAME:@@@@}} directly without getting parsed before @@@@ is replaced. |
— | — | @@ -307,8 +307,8 @@ |
308 | 308 | |
309 | 309 | $rendered_values[] = $rawResult; |
310 | 310 | } |
311 | | - |
312 | | - $output = implode( $delimiter, $rendered_values ); |
| 311 | + |
| 312 | + $output = implode( $delimiter, $rendered_values ); |
313 | 313 | $noparse = false; |
314 | 314 | |
315 | 315 | /* |
— | — | @@ -319,10 +319,10 @@ |
320 | 320 | |
321 | 321 | $output = $parser->preprocessToDom( $output, $frame->isTemplate() ? Parser::PTD_FOR_INCLUSION : 0 ); |
322 | 322 | $output = trim( $frame->expand( $output ) ); |
323 | | - |
| 323 | + |
324 | 324 | return $output; |
325 | | - } |
326 | | - |
| 325 | + } |
| 326 | + |
327 | 327 | /** |
328 | 328 | * print the value of an array (identified by arrayid) by the index, invalid index results in the default value being printed. note the index is 0-based. |
329 | 329 | * usage: |
— | — | @@ -330,26 +330,26 @@ |
331 | 331 | */ |
332 | 332 | static function pfObj_arrayindex( Parser &$parser, PPFrame $frame, $args ) { |
333 | 333 | global $egArrayExtensionCompatbilityMode; |
334 | | - |
| 334 | + |
335 | 335 | // Get Parameters |
336 | | - $arrayId = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : ''; |
| 336 | + $arrayId = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : ''; |
337 | 337 | $rawOptions = isset( $args[2] ) ? $args[2] : ''; |
338 | | - |
| 338 | + |
339 | 339 | if( ! isset( $args[1] ) ) { |
340 | 340 | return ''; |
341 | 341 | } |
342 | 342 | $index = trim( $frame->expand( $args[1] ) ); |
343 | | - |
| 343 | + |
344 | 344 | // get value or null if it doesn't exist. Takes care of negative index as well |
345 | 345 | $val = self::get( $parser )->getArrayValue( $arrayId, $index ); |
346 | | - |
347 | | - if( $val === null || ( $val === '' && !$egArrayExtensionCompatbilityMode ) ) { |
348 | | - // index doesn't exist, return default (parameter 3)! |
| 346 | + |
| 347 | + if( $val === null || ( $val === '' && !$egArrayExtensionCompatbilityMode ) ) { |
| 348 | + // index doesn't exist, return default (parameter 3)! |
349 | 349 | // without compatibility, also return default in case of empty string '' |
350 | | - |
| 350 | + |
351 | 351 | // only expand default when needed |
352 | 352 | $defaultOrOptions = trim( $frame->expand( $rawOptions ) ); |
353 | | - |
| 353 | + |
354 | 354 | if( $egArrayExtensionCompatbilityMode ) { |
355 | 355 | // COMPATIBILITY-MODE |
356 | 356 | // now parse the options, and do posterior process on the created array |
— | — | @@ -358,13 +358,13 @@ |
359 | 359 | } else { |
360 | 360 | $default = $defaultOrOptions; |
361 | 361 | } |
362 | | - |
| 362 | + |
363 | 363 | return $default; |
364 | | - } |
365 | | - |
| 364 | + } |
| 365 | + |
366 | 366 | return $val; |
367 | | - } |
368 | | - |
| 367 | + } |
| 368 | + |
369 | 369 | /** |
370 | 370 | * returns the size of an array. |
371 | 371 | * Print the size (number of elements) in the specified array and '' if array doesn't exist |
— | — | @@ -373,17 +373,17 @@ |
374 | 374 | * |
375 | 375 | * See: http://www.php.net/manual/en/function.count.php |
376 | 376 | */ |
377 | | - static function pf_arraysize( Parser &$parser, $arrayId ) { |
| 377 | + static function pf_arraysize( Parser &$parser, $arrayId ) { |
378 | 378 | $store = self::get( $parser ); |
379 | | - |
380 | | - if( ! $store->arrayExists( $arrayId ) ) { |
381 | | - return ''; |
382 | | - } |
383 | | - |
384 | | - return count( $store->getArray( $arrayId ) ); |
385 | | - } |
386 | 379 | |
387 | | - |
| 380 | + if( ! $store->arrayExists( $arrayId ) ) { |
| 381 | + return ''; |
| 382 | + } |
| 383 | + |
| 384 | + return count( $store->getArray( $arrayId ) ); |
| 385 | + } |
| 386 | + |
| 387 | + |
388 | 388 | /** |
389 | 389 | * locate the index of the first occurence of an element starting from the 'index' |
390 | 390 | * - print "-1" (not found) or index (found) to show the index of the first occurence of 'value' in the array identified by arrayid |
— | — | @@ -396,25 +396,25 @@ |
397 | 397 | * note it is extended to support regular expression match and index |
398 | 398 | */ |
399 | 399 | static function pfObj_arraysearch( Parser &$parser, PPFrame $frame, $args ) { |
400 | | - |
| 400 | + |
401 | 401 | $arrayId = trim( $frame->expand( $args[0] ) ); |
402 | 402 | $index = isset( $args[2] ) ? trim( $frame->expand( $args[2] ) ) : 0; |
403 | | - |
| 403 | + |
404 | 404 | $store = self::get( $parser ); |
405 | | - |
406 | | - if( $store->arrayExists( $arrayId ) |
407 | | - && $store->validate_array_index( $arrayId, $index, false ) |
| 405 | + |
| 406 | + if( $store->arrayExists( $arrayId ) |
| 407 | + && $store->validate_array_index( $arrayId, $index, false ) |
408 | 408 | ) { |
409 | 409 | $array = $store->getArray( $arrayId ); |
410 | | - |
| 410 | + |
411 | 411 | // validate/build search regex: |
412 | 412 | if( isset( $args[1] ) ) { |
413 | | - |
| 413 | + |
414 | 414 | $needle = trim( $frame->expand( $args[1] ) ); |
415 | | - |
| 415 | + |
416 | 416 | if ( ! self::isValidRegEx( $needle ) ) { |
417 | 417 | $needle = '/^\s*' . preg_quote( trim( $needle ), '/' ) . '\s*$/'; |
418 | | - } |
| 418 | + } |
419 | 419 | } |
420 | 420 | else { |
421 | 421 | $needle = '/^\s*$/'; |
— | — | @@ -428,7 +428,7 @@ |
429 | 429 | if ( preg_match( $needle, $value ) ) { |
430 | 430 | // found! |
431 | 431 | if ( isset( $args[3] ) ) { |
432 | | - // Expand only when needed! |
| 432 | + // Expand only when needed! |
433 | 433 | return trim( $frame->expand( $args[3] ) ); |
434 | 434 | } |
435 | 435 | else { |
— | — | @@ -438,15 +438,15 @@ |
439 | 439 | } |
440 | 440 | } |
441 | 441 | } |
442 | | - |
| 442 | + |
443 | 443 | global $egArrayExtensionCompatbilityMode; |
444 | | - |
| 444 | + |
445 | 445 | // no match! (Expand only when needed!) |
446 | 446 | $no = isset( $args[4] ) |
447 | | - ? trim( $frame->expand( $args[4] ) ) |
448 | | - : $egArrayExtensionCompatbilityMode ? '-1' : ''; // COMPATIBILITY-MODE |
449 | | - return $no; |
450 | | - } |
| 447 | + ? trim( $frame->expand( $args[4] ) ) |
| 448 | + : $egArrayExtensionCompatbilityMode ? '-1' : ''; // COMPATIBILITY-MODE |
| 449 | + return $no; |
| 450 | + } |
451 | 451 | |
452 | 452 | /** |
453 | 453 | * search an array and create a new array with all the results. Transforming the new entries before storing them is possible too. |
— | — | @@ -466,47 +466,47 @@ |
467 | 467 | $transform = '' |
468 | 468 | ) { |
469 | 469 | $store = self::get( $parser ); |
470 | | - |
| 470 | + |
471 | 471 | if( $arrayId === null ) { |
472 | 472 | global $egArrayExtensionCompatbilityMode; |
473 | 473 | if( ! $egArrayExtensionCompatbilityMode ) { // COMPATIBILITY-MODE |
474 | 474 | $store->setArray( $arrayId_new ); |
475 | 475 | } |
476 | 476 | return ''; |
477 | | - } |
| 477 | + } |
478 | 478 | // also takes care of negative index by calculating start index: |
479 | 479 | $validIndex = $store->validate_array_index( $arrayId, $index, false ); |
480 | | - |
| 480 | + |
481 | 481 | // make sure at least empty array exists but don't overwrite data |
482 | 482 | // we still need in case new array ID same as target array ID |
483 | 483 | $array = $store->getArray( $arrayId ); |
484 | 484 | $store->setArray( $arrayId_new ); |
485 | | - |
486 | | - if( $array === null || !$validIndex ) { |
| 485 | + |
| 486 | + if( $array === null || !$validIndex ) { |
487 | 487 | return ''; |
488 | 488 | } |
489 | | - |
| 489 | + |
490 | 490 | // non-numeric limit will be set to 0, except limit was omitted ('') |
491 | 491 | $limit = $limit === '' ? -1 : (int)$limit; |
492 | 492 | if( $limit === 0 ) { |
493 | 493 | return ''; |
494 | 494 | } |
495 | | - |
496 | | - $newArr = array(); |
497 | | - |
| 495 | + |
| 496 | + $newArr = array(); |
| 497 | + |
498 | 498 | $regexFunSupport = self::hasRegexFunSupport(); |
499 | | - if( ! self::isValidRegEx( $needle, $regexFunSupport ) ) { |
| 499 | + if( ! self::isValidRegEx( $needle, $regexFunSupport ) ) { |
500 | 500 | $needle = '/^\s*(' . preg_quote( $needle, '/' ) . ')\s*$/'; |
501 | 501 | } |
502 | 502 | |
503 | 503 | // search the array for all matches and put them in the new array |
504 | 504 | $total = count( $array ); |
505 | | - for( $i = $index; $i < $total; $i++ ) { |
506 | | - |
| 505 | + for( $i = $index; $i < $total; $i++ ) { |
| 506 | + |
507 | 507 | $value = $array[ $i ]; |
508 | 508 | |
509 | 509 | if( preg_match( $needle, $value ) ) { |
510 | | - // Found something! |
| 510 | + // Found something! |
511 | 511 | if( $transform !== '' ) { |
512 | 512 | // Transform the found string. Can we use 'Regex Fun' ? |
513 | 513 | if( $regexFunSupport ) { |
— | — | @@ -526,19 +526,19 @@ |
527 | 527 | } |
528 | 528 | } |
529 | 529 | $newArr[] = trim( $value ); |
530 | | - |
| 530 | + |
531 | 531 | // stop if limit is reached, limit -1 means no limit |
532 | 532 | if( --$limit === 0 ) { |
533 | 533 | break; |
534 | 534 | } |
535 | 535 | } |
536 | | - } |
537 | | - |
| 536 | + } |
| 537 | + |
538 | 538 | // set new array: |
539 | 539 | $store->setArray( $arrayId_new, $newArr ); |
540 | 540 | return ''; |
541 | 541 | } |
542 | | - |
| 542 | + |
543 | 543 | /** |
544 | 544 | * extract a slice from an array |
545 | 545 | * usage: |
— | — | @@ -561,7 +561,7 @@ |
562 | 562 | |
563 | 563 | // make sure at least an empty array exists if we return early |
564 | 564 | $store->setArray( $arrayId_new ); |
565 | | - |
| 565 | + |
566 | 566 | if( $array === null |
567 | 567 | || ! is_numeric( $offset ) // don't ignore invalid offset |
568 | 568 | ) { |
— | — | @@ -571,15 +571,15 @@ |
572 | 572 | if( ! is_numeric( $length ) ) { |
573 | 573 | $length = null; // ignore invalid input, slice till end |
574 | 574 | } |
575 | | - |
576 | | - // array_slice will re-organize keys |
| 575 | + |
| 576 | + // array_slice will re-organize keys |
577 | 577 | $newArray = array_slice( $array, $offset, $length ); |
578 | 578 | $store->setArray( $arrayId_new, $newArray ); |
579 | | - |
| 579 | + |
580 | 580 | return ''; |
581 | 581 | } |
582 | | - |
583 | | - |
| 582 | + |
| 583 | + |
584 | 584 | /////////////////////////////////////////////////////////// |
585 | 585 | // PART 3. Array Alteration |
586 | 586 | /////////////////////////////////////////////////////////// |
— | — | @@ -592,7 +592,7 @@ |
593 | 593 | */ |
594 | 594 | static function pfObj_arrayreset( Parser &$parser, PPFrame $frame, $args) { |
595 | 595 | global $egArrayExtensionCompatbilityMode; |
596 | | - |
| 596 | + |
597 | 597 | if( $egArrayExtensionCompatbilityMode && count( $args ) == 1 ) { |
598 | 598 | /* |
599 | 599 | * COMPATIBILITY-MODE: before arrays were separated by ';' which is an bad idea since |
— | — | @@ -600,9 +600,9 @@ |
601 | 601 | */ |
602 | 602 | $args = preg_split( '/\s*,\s*/', trim( $frame->expand( $args[0] ) ) ); |
603 | 603 | } |
604 | | - |
| 604 | + |
605 | 605 | $store = self::get( $parser ); |
606 | | - |
| 606 | + |
607 | 607 | // reset all hash tables if no specific tables are given: |
608 | 608 | if( ! isset( $args[0] ) || ( $args[0] === '' && count( $args ) == 1 ) ) { |
609 | 609 | // reset ALL arrays! |
— | — | @@ -612,13 +612,13 @@ |
613 | 613 | // reset specific hash tables: |
614 | 614 | foreach( $args as $arg ) { |
615 | 615 | $arrayId = trim( $frame->expand( $arg ) ); |
616 | | - $store->unsetArray( $arrayId ); |
| 616 | + $store->unsetArray( $arrayId ); |
617 | 617 | } |
618 | 618 | } |
619 | 619 | return ''; |
620 | | - } |
621 | | - |
| 620 | + } |
622 | 621 | |
| 622 | + |
623 | 623 | /** |
624 | 624 | * convert an array to a set |
625 | 625 | * convert the array identified by arrayid into a set (all elements are unique) |
— | — | @@ -628,16 +628,16 @@ |
629 | 629 | * |
630 | 630 | * see: http://www.php.net/manual/en/function.array-unique.php |
631 | 631 | */ |
632 | | - static function pf_arrayunique( Parser &$parser, $arrayId ) { |
| 632 | + static function pf_arrayunique( Parser &$parser, $arrayId ) { |
633 | 633 | $store = self::get( $parser ); |
634 | | - |
635 | | - if( $store->arrayExists( $arrayId ) ) { |
| 634 | + |
| 635 | + if( $store->arrayExists( $arrayId ) ) { |
636 | 636 | $array = $store->getArray( $arrayId ); |
637 | 637 | $array = self::array_unique( $array ); |
638 | 638 | $store->setArray( $arrayId, $array ); |
639 | | - } |
640 | | - return ''; |
641 | | - } |
| 639 | + } |
| 640 | + return ''; |
| 641 | + } |
642 | 642 | |
643 | 643 | |
644 | 644 | /** |
— | — | @@ -653,32 +653,32 @@ |
654 | 654 | * see: http://www.php.net/manual/en/function.sort.php |
655 | 655 | * http://www.php.net/manual/en/function.rsort.php |
656 | 656 | * http://www.php.net/manual/en/function.shuffle.php |
657 | | - * http://us3.php.net/manual/en/function.array-reverse.php |
| 657 | + * http://us3.php.net/manual/en/function.array-reverse.php |
658 | 658 | */ |
659 | | - static function pf_arraysort( Parser &$parser, $arrayId , $sort = 'none' ) { |
| 659 | + static function pf_arraysort( Parser &$parser, $arrayId , $sort = 'none' ) { |
660 | 660 | $store = self::get( $parser ); |
661 | | - |
| 661 | + |
662 | 662 | $array = $store->getArray( $arrayId ); |
663 | | - |
664 | | - if( $array === null ) { |
665 | | - return ''; |
666 | | - } |
667 | | - |
| 663 | + |
| 664 | + if( $array === null ) { |
| 665 | + return ''; |
| 666 | + } |
| 667 | + |
668 | 668 | // sort array and store it |
669 | 669 | $array = self::arraySort( $array, $sort ); |
670 | 670 | $store->setArray( $arrayId, $array ); |
671 | 671 | return ''; |
672 | | - } |
| 672 | + } |
673 | 673 | |
674 | 674 | |
675 | 675 | /////////////////////////////////////////////////////////// |
676 | 676 | // PART 4. Array Interaction |
677 | 677 | /////////////////////////////////////////////////////////// |
678 | | - |
| 678 | + |
679 | 679 | /** |
680 | 680 | * Merge values two arrayes identified by arrayid1 and arrayid2 into a new array identified by arrayid_new. |
681 | 681 | * This merge differs from array_merge of php because it merges values. |
682 | | - * |
| 682 | + * |
683 | 683 | * Usage: |
684 | 684 | * {{#arraymerge:arrayid_new |array1 |array2 |... |array n}} |
685 | 685 | * See: http://www.php.net/manual/en/function.array-merge.php |
— | — | @@ -691,12 +691,12 @@ |
692 | 692 | // keys will not be re-organized |
693 | 693 | return array_merge( $array1, $array2 ); |
694 | 694 | } |
695 | | - |
696 | | - /** |
| 695 | + |
| 696 | + /** |
697 | 697 | * Usage: |
698 | 698 | * {{#arrayunion:arrayid_new|arrayid1|arrayid2}} |
699 | | - * |
700 | | - * Set operation, {red, white} = {red, white} union {red} |
| 699 | + * |
| 700 | + * Set operation, {red, white} = {red, white} union {red} |
701 | 701 | * Similar to arraymerge but with unique values. This union works on values. |
702 | 702 | */ |
703 | 703 | static function pfObj_arrayunion( &$parser, $frame, $args) { |
— | — | @@ -707,11 +707,11 @@ |
708 | 708 | // keys will not be re-organized |
709 | 709 | return array_unique( array_merge( $array1, $array2 ) ); |
710 | 710 | } |
711 | | - |
| 711 | + |
712 | 712 | /** |
713 | 713 | * Usage: |
714 | 714 | * {{#arrayintersect:arrayid_new |array1 |array2 |... |array n}} |
715 | | - * |
| 715 | + * |
716 | 716 | * Set operation, {red} = {red, white} intersect {red,black} |
717 | 717 | * See: http://www.php.net/manual/en/function.array-intersect.php |
718 | 718 | */ |
— | — | @@ -740,22 +740,22 @@ |
741 | 741 | // keys will be preserved! |
742 | 742 | return array_diff( $array1, $array2 ); |
743 | 743 | } |
744 | | - |
745 | | - |
| 744 | + |
| 745 | + |
746 | 746 | ################## |
747 | 747 | # Private helper # |
748 | 748 | ################## |
749 | | - |
| 749 | + |
750 | 750 | /** |
751 | 751 | * Base function for operations with multiple arrays given thru n parameters |
752 | 752 | * $operationFunc expects a function name prefix (suffix 'multi_') with two parameters |
753 | 753 | * $array1 and $array2 which will perform an action between $array1 and $array2 which |
754 | 754 | * will result into a new $array1. There can be 1 to n $hash2 in the whole process. |
755 | | - * |
| 755 | + * |
756 | 756 | * Note: This function is similar to that of Extension:HashTables. |
757 | | - * |
| 757 | + * |
758 | 758 | * @since 2.0 |
759 | | - * |
| 759 | + * |
760 | 760 | * @param $frame PPFrame |
761 | 761 | * @param $args array |
762 | 762 | * @param $operationFunc string name of the function calling this. There must be a counterpart |
— | — | @@ -769,7 +769,7 @@ |
770 | 770 | $operationRan = false; |
771 | 771 | $finalArrayId = trim( $frame->expand( $args[0] ) ); |
772 | 772 | $operationFunc = 'multi_' . preg_replace( '/^pfObj_/', '', $operationFunc ); |
773 | | - |
| 773 | + |
774 | 774 | // For all arrays given in parameters 2 to n (ignore 1 because this is the name of the new array) |
775 | 775 | for( $i = 1; $i < count( $args ); $i++ ) { |
776 | 776 | // just make sure we don't fall into gaps of given arguments: |
— | — | @@ -777,10 +777,10 @@ |
778 | 778 | continue; |
779 | 779 | } |
780 | 780 | $argArrayId = trim( $frame->expand( $args[ $i ] ) ); |
781 | | - |
| 781 | + |
782 | 782 | // ignore all tables which do not exist |
783 | 783 | if( $this->arrayExists( $argArrayId ) ) { |
784 | | - $argArray = $this->getArray( $argArrayId ); |
| 784 | + $argArray = $this->getArray( $argArrayId ); |
785 | 785 | if( $lastArray === null ) { |
786 | 786 | // first valid array, process together with second... |
787 | 787 | $lastArray = $argArray; |
— | — | @@ -792,14 +792,14 @@ |
793 | 793 | } |
794 | 794 | } |
795 | 795 | } |
796 | | - |
| 796 | + |
797 | 797 | // in case no array was given at all: |
798 | 798 | if( $lastArray === null ) { |
799 | 799 | $lastArray = array(); |
800 | 800 | } |
801 | | - |
| 801 | + |
802 | 802 | global $egArrayExtensionCompatbilityMode; |
803 | | - |
| 803 | + |
804 | 804 | if( ! $operationRan && $egArrayExtensionCompatbilityMode |
805 | 805 | && $operationFunc !== 'multi_arraymerge' // only exception was 'arraymerge' |
806 | 806 | ) { |
— | — | @@ -810,33 +810,33 @@ |
811 | 811 | */ |
812 | 812 | return ''; |
813 | 813 | } |
814 | | - |
| 814 | + |
815 | 815 | // if the operation didn't run because there was only one or no array: |
816 | 816 | if( ! $operationRan && $runFuncOnSingleArray ) { |
817 | 817 | $lastArray = $this->{ $operationFunc }( $lastArray ); |
818 | 818 | } |
819 | | - |
| 819 | + |
820 | 820 | // re-organize all keys since some 'multi_' functions will preserve keys! |
821 | 821 | $lastArray = array_merge( $lastArray ); |
822 | | - |
| 822 | + |
823 | 823 | $this->setArray( $finalArrayId, $lastArray ); |
824 | | - } |
| 824 | + } |
825 | 825 | |
826 | | - /** |
| 826 | + /** |
827 | 827 | * Validates an index for an array and returns true in case the index is a valid index within |
828 | 828 | * the array. This also changes the index value, which is given by reference, in case it is |
829 | 829 | * set to a negative value. In case $strictIndex is set to false, further transforming of |
830 | 830 | * $index might be done - in the same cases normally the function would return false. |
831 | | - * |
| 831 | + * |
832 | 832 | * @param string $arrayId |
833 | 833 | * @param mixed &$index |
834 | 834 | * @param bool $strictIndex Whether non-numeric indexes and negative indexes which would |
835 | 835 | * end up out of range, below 0, should be set to 0 automatically. |
836 | | - * |
| 836 | + * |
837 | 837 | * @return boolean |
838 | 838 | */ |
839 | | - protected function validate_array_index( $arrayId, &$index, $strictIndex = false ) { |
840 | | - if( ! is_numeric( $index ) ) { |
| 839 | + protected function validate_array_index( $arrayId, &$index, $strictIndex = false ) { |
| 840 | + if( ! is_numeric( $index ) ) { |
841 | 841 | if( $strictIndex ) { |
842 | 842 | return false; |
843 | 843 | } else { |
— | — | @@ -844,13 +844,13 @@ |
845 | 845 | } |
846 | 846 | } |
847 | 847 | $index = (int)$index; |
848 | | - |
| 848 | + |
849 | 849 | if( ! array_key_exists( $arrayId, $this->mArrays ) ) { |
850 | 850 | return false; |
851 | 851 | } |
852 | | - |
| 852 | + |
853 | 853 | $array = $this->mArrays[ $arrayId ]; |
854 | | - |
| 854 | + |
855 | 855 | // calculate start index for negative start indexes: |
856 | 856 | if( $index < 0 ) { |
857 | 857 | $index = count( $array ) + $index; |
— | — | @@ -858,22 +858,22 @@ |
859 | 859 | $index = 0; |
860 | 860 | } |
861 | 861 | } |
862 | | - |
863 | | - if( ! isset( $array ) ) { |
| 862 | + |
| 863 | + if( ! isset( $array ) ) { |
864 | 864 | return false; |
865 | 865 | } |
866 | | - if( ! array_key_exists( $index, $array ) ) { |
| 866 | + if( ! array_key_exists( $index, $array ) ) { |
867 | 867 | return false; |
868 | 868 | } |
869 | | - return true; |
870 | | - } |
871 | | - |
| 869 | + return true; |
| 870 | + } |
| 871 | + |
872 | 872 | /** |
873 | 873 | * private function for validating array by name |
874 | 874 | * @ToDo: get rid of this! |
875 | 875 | * @deprecated |
876 | 876 | */ |
877 | | - protected function validate_array_by_arrayId( $arrayId ) { |
| 877 | + protected function validate_array_by_arrayId( $arrayId ) { |
878 | 878 | if( ! isset( $arrayId ) ) { |
879 | 879 | return ''; |
880 | 880 | } |
— | — | @@ -890,27 +890,27 @@ |
891 | 891 | } |
892 | 892 | |
893 | 893 | return true; |
894 | | - } |
895 | | - |
| 894 | + } |
| 895 | + |
896 | 896 | /** |
897 | 897 | * Convenience function to get a value from an array. Returns '' in case the |
898 | 898 | * value doesn't exist or no array was given |
899 | | - * |
| 899 | + * |
900 | 900 | * @return string |
901 | 901 | */ |
902 | | - protected static function array_value( $array, $field ) { |
903 | | - if ( is_array( $array ) && array_key_exists( $field, $array ) ) { |
| 902 | + protected static function array_value( $array, $field ) { |
| 903 | + if ( is_array( $array ) && array_key_exists( $field, $array ) ) { |
904 | 904 | return $array[ $field ]; |
905 | 905 | } |
906 | 906 | return ''; |
907 | | - } |
908 | | - |
| 907 | + } |
| 908 | + |
909 | 909 | /** |
910 | 910 | * Parses a string of options separated by ','. Options can be just certain key-words or |
911 | 911 | * key-value pairs separated by '='. Options are case-insensitive and spacing between |
912 | 912 | * separators will be ignored. |
913 | 913 | */ |
914 | | - protected static function parse_options( $options ) { |
| 914 | + protected static function parse_options( $options ) { |
915 | 915 | if( ! isset( $options ) ) { |
916 | 916 | return array(); |
917 | 917 | } |
— | — | @@ -918,25 +918,25 @@ |
919 | 919 | // now parse the options, and do posterior process on the created array |
920 | 920 | $options = preg_split( '/\s*,\s*/', strtolower( $options ) ); |
921 | 921 | |
922 | | - $ret = array(); |
| 922 | + $ret = array(); |
923 | 923 | foreach( $options as $option ) { |
924 | 924 | $optPair = preg_split( '/\s*\=\s*/', $option, 2 ); |
925 | | - if( sizeof( $optPair ) == 1 ) { |
| 925 | + if( sizeof( $optPair ) == 1 ) { |
926 | 926 | $ret[ $optPair[0] ] = true; |
927 | 927 | } else { |
928 | 928 | $ret[ $optPair[0] ] = $optPair[1]; |
929 | 929 | } |
930 | 930 | } |
931 | 931 | return $ret; |
932 | | - } |
933 | | - |
| 932 | + } |
| 933 | + |
934 | 934 | /** |
935 | 935 | * same as self::arrayUnique() but without sanitazation, only for internal use. |
936 | 936 | */ |
937 | 937 | protected static function array_unique( array $array ) { |
938 | 938 | // delete duplicate values |
939 | 939 | $array = array_unique( $array ); |
940 | | - |
| 940 | + |
941 | 941 | $values = array(); |
942 | 942 | foreach( $array as $key => $val ) { |
943 | 943 | // don't put emty elements into the array |
— | — | @@ -944,7 +944,7 @@ |
945 | 945 | $values[] = $val; |
946 | 946 | } |
947 | 947 | } |
948 | | - |
| 948 | + |
949 | 949 | return $values; |
950 | 950 | } |
951 | 951 | |
— | — | @@ -952,7 +952,7 @@ |
953 | 953 | ############## |
954 | 954 | # Used Hooks # |
955 | 955 | ############## |
956 | | - |
| 956 | + |
957 | 957 | static function onParserClearState( Parser &$parser ) { |
958 | 958 | // remove all arrays to avoid conflicts with job queue or Special:Import or SMW semantic updates |
959 | 959 | $parser->mExtArrays = new self(); |
— | — | @@ -968,43 +968,43 @@ |
969 | 969 | # other extensions doing interactive stuff |
970 | 970 | # with the Array extension. |
971 | 971 | # |
972 | | - |
| 972 | + |
973 | 973 | /** |
974 | 974 | * Convenience function to return the 'Arrays' extensions array store connected |
975 | 975 | * to a certain Parser object. Each parser has its own store which will be reset after |
976 | 976 | * a parsing process [Parser::parse()] has finished. |
977 | | - * |
| 977 | + * |
978 | 978 | * @since 2.0 |
979 | | - * |
| 979 | + * |
980 | 980 | * @param Parser &$parser |
981 | | - * |
| 981 | + * |
982 | 982 | * @return ExtArrays by reference so we still have the right object after 'ParserClearState' |
983 | 983 | */ |
984 | 984 | public static function &get( Parser &$parser ) { |
985 | 985 | return $parser->mExtArrays; |
986 | 986 | } |
987 | | - |
| 987 | + |
988 | 988 | /** |
989 | 989 | * Returns an array identified by $arrayId. If it doesn't exist, null will be returned. |
990 | | - * |
| 990 | + * |
991 | 991 | * @since 2.0 |
992 | | - * |
| 992 | + * |
993 | 993 | * @param string $arrayId |
994 | | - * |
| 994 | + * |
995 | 995 | * @return array|null |
996 | 996 | */ |
997 | | - function getArray( $arrayId ) { |
| 997 | + function getArray( $arrayId ) { |
998 | 998 | $arrayId = trim( $arrayId ); |
999 | 999 | if( $this->arrayExists( $arrayId ) ) { |
1000 | 1000 | return $this->mArrays[ $arrayId ]; |
1001 | 1001 | } |
1002 | 1002 | return null; |
1003 | | - } |
1004 | | - |
| 1003 | + } |
| 1004 | + |
1005 | 1005 | /** |
1006 | 1006 | * This will add a new array or overwrite an existing one. Values should be delliverd as array |
1007 | 1007 | * values in form of a string. The array will be sanitized internally. |
1008 | | - * |
| 1008 | + * |
1009 | 1009 | * @param string $arrayId |
1010 | 1010 | * @param array $array |
1011 | 1011 | */ |
— | — | @@ -1012,64 +1012,64 @@ |
1013 | 1013 | $array = self::sanitizeArray( $array ); |
1014 | 1014 | $this->mArrays[ trim( $arrayId ) ] = $array; |
1015 | 1015 | } |
1016 | | - |
| 1016 | + |
1017 | 1017 | /** |
1018 | 1018 | * Same as the public function createArray() but without sanitizing the array automatically. |
1019 | 1019 | * This is save and faster for internal usage, just be sure your array doesn't have un-trimmed |
1020 | 1020 | * values or non-numeric or negative array keys and no gaps between keys. |
1021 | | - * |
| 1021 | + * |
1022 | 1022 | * @param type $arrayId |
1023 | | - * @param type $array |
| 1023 | + * @param type $array |
1024 | 1024 | */ |
1025 | 1025 | protected function setArray( $arrayId, $array = array() ) { |
1026 | 1026 | $this->mArrays[ trim( $arrayId ) ] = $array; |
1027 | 1027 | } |
1028 | | - |
| 1028 | + |
1029 | 1029 | /** |
1030 | 1030 | * Returns whether a certain array is defined within the page scope. |
1031 | | - * |
| 1031 | + * |
1032 | 1032 | * @param string $arrayId |
1033 | | - * |
| 1033 | + * |
1034 | 1034 | * @return boolean |
1035 | 1035 | */ |
1036 | 1036 | function arrayExists( $arrayId ) { |
1037 | 1037 | return array_key_exists( trim( $arrayId ), $this->mArrays ); |
1038 | 1038 | } |
1039 | | - |
| 1039 | + |
1040 | 1040 | /** |
1041 | 1041 | * Returns a value within an array. If key or array do not exist, this will return null |
1042 | 1042 | * or another predefined default. $index can also be a negative value, in this case the |
1043 | 1043 | * value that far from the end of the array will be returned. |
1044 | | - * |
| 1044 | + * |
1045 | 1045 | * @since 2.0 |
1046 | | - * |
| 1046 | + * |
1047 | 1047 | * @param string $arrayId |
1048 | 1048 | * @param string $index |
1049 | 1049 | * @param mixed $default value to return in case the value doesn't exist. null by default. |
1050 | | - * |
| 1050 | + * |
1051 | 1051 | * @return string|null |
1052 | 1052 | */ |
1053 | | - function getArrayValue( $arrayId, $index, $default = null ) { |
1054 | | - $arrayId = trim( $arrayId ); |
| 1053 | + function getArrayValue( $arrayId, $index, $default = null ) { |
| 1054 | + $arrayId = trim( $arrayId ); |
1055 | 1055 | if( $this->arrayExists( $arrayId ) |
1056 | 1056 | && $this->validate_array_index( $arrayId, $index, true ) |
1057 | | - && array_key_exists( $index, $this->mArrays[ $arrayId ] ) |
| 1057 | + && array_key_exists( $index, $this->mArrays[ $arrayId ] ) |
1058 | 1058 | ) { |
1059 | 1059 | return $this->mArrays[ $arrayId ][ $index ]; |
1060 | 1060 | } |
1061 | 1061 | else { |
1062 | 1062 | return $default; |
1063 | 1063 | } |
1064 | | - } |
| 1064 | + } |
1065 | 1065 | |
1066 | 1066 | |
1067 | 1067 | /** |
1068 | 1068 | * Removes an existing array. If array didn't exist this will return false, otherwise true. |
1069 | | - * |
| 1069 | + * |
1070 | 1070 | * @since 2.0 |
1071 | | - * |
| 1071 | + * |
1072 | 1072 | * @param string $arrayId |
1073 | | - * |
| 1073 | + * |
1074 | 1074 | * @return boolean whether the array existed and has been removed |
1075 | 1075 | */ |
1076 | 1076 | public function unsetArray( $arrayId ) { |
— | — | @@ -1084,9 +1084,9 @@ |
1085 | 1085 | /** |
1086 | 1086 | * Rebuild the array and reorganize all keys, trim all values. |
1087 | 1087 | * All gaps between array items will be closed. |
1088 | | - * |
| 1088 | + * |
1089 | 1089 | * @since 2.0 |
1090 | | - * |
| 1090 | + * |
1091 | 1091 | * @param array $arr array to be reorganized |
1092 | 1092 | * @return array |
1093 | 1093 | */ |
— | — | @@ -1097,36 +1097,36 @@ |
1098 | 1098 | } |
1099 | 1099 | return $newArray; |
1100 | 1100 | } |
1101 | | - |
| 1101 | + |
1102 | 1102 | /** |
1103 | 1103 | * Removes duplicate values and all empty elements from an array just like the |
1104 | 1104 | * '#arrayunique' parser function would do it. The array will be sanitized internally. |
1105 | | - * |
| 1105 | + * |
1106 | 1106 | * @since 2.0 |
1107 | | - * |
| 1107 | + * |
1108 | 1108 | * @param array $array |
1109 | | - * |
| 1109 | + * |
1110 | 1110 | * @return array |
1111 | 1111 | */ |
1112 | 1112 | public static function arrayUnique( array $array ) { |
1113 | 1113 | $arr = $this->sanitizeArray( $arr ); |
1114 | 1114 | $array = self::array_unique( $array ); |
1115 | 1115 | } |
1116 | | - |
| 1116 | + |
1117 | 1117 | /** |
1118 | 1118 | * Sorts an array just like parser function '#arraysort' would do it and allows the |
1119 | 1119 | * same sort modes. |
1120 | | - * |
| 1120 | + * |
1121 | 1121 | * @since 2.0 |
1122 | | - * |
| 1122 | + * |
1123 | 1123 | * @param array $array |
1124 | 1124 | * @param string $sortMode |
1125 | | - * |
| 1125 | + * |
1126 | 1126 | * @return array |
1127 | 1127 | */ |
1128 | 1128 | public static function arraySort( array $array, $sortMode ) { |
1129 | 1129 | // do the requested sorting of the given array: |
1130 | | - switch( $sortMode ) { |
| 1130 | + switch( $sortMode ) { |
1131 | 1131 | case 'asc': |
1132 | 1132 | case 'asce': |
1133 | 1133 | case 'ascending': |
— | — | @@ -1153,19 +1153,19 @@ |
1154 | 1154 | /** |
1155 | 1155 | * Decides for the given $pattern whether its a valid regular expression acceptable for |
1156 | 1156 | * Arrays parser functions or not. |
1157 | | - * |
| 1157 | + * |
1158 | 1158 | * @param string $pattern regular expression including delimiters and optional flags |
1159 | 1159 | * @param bool $forRegexFun whether the regular expression is inteded to be used with 'Regex Fun' |
1160 | 1160 | * if supported by the wikis infrastructure. In case 'Regex Fun' is not available, |
1161 | 1161 | * the default validation will be used. |
1162 | | - * |
| 1162 | + * |
1163 | 1163 | * @return boolean |
1164 | 1164 | */ |
1165 | 1165 | static function isValidRegEx( $pattern, $forRegexFun = false ) { |
1166 | 1166 | if( $forRegexFun && self::hasRegexFunSupport() ) { |
1167 | 1167 | return ExtRegexFun::validateRegex( $pattern ); |
1168 | 1168 | } |
1169 | | - |
| 1169 | + |
1170 | 1170 | if( ! preg_match( '/^([\\/\\|%]).*\\1[imsSuUx]*$/', $pattern ) ) { |
1171 | 1171 | return false; |
1172 | 1172 | } |
— | — | @@ -1174,7 +1174,7 @@ |
1175 | 1175 | wfRestoreWarnings(); |
1176 | 1176 | return $isValid; |
1177 | 1177 | } |
1178 | | - |
| 1178 | + |
1179 | 1179 | /** |
1180 | 1180 | * Whether 'Regex Fun' extension is available in this wiki to take over preg_replace handling |
1181 | 1181 | * for '#arraysearcharray' function. |