Index: trunk/extensions/ZeroRatedMobileAccess/ZeroRatedMobileAccess.body.php |
— | — | @@ -326,76 +326,89 @@ |
327 | 327 | return true; |
328 | 328 | } |
329 | 329 | |
| 330 | + /** |
| 331 | + * @param $formatter array |
| 332 | + * @param $wikiText string |
| 333 | + * @param $nChild bool |
| 334 | + * @return array |
| 335 | + */ |
330 | 336 | public function parseWikiTextToArray( Array $formatter, $wikiText, $nChild = false ) { |
| 337 | + $options = array(); |
| 338 | + if ( !is_array( $formatter ) ) { |
| 339 | + return $options; |
| 340 | + } |
331 | 341 | wfProfileIn( __METHOD__ ); |
332 | | - $options = array(); |
333 | 342 | $data = explode( PHP_EOL, $wikiText ); |
334 | | - if ( is_array( $formatter ) && !$nChild ) { |
335 | | - $arrayKeys = array_keys( $formatter ); |
336 | | - $keyCount = count( $arrayKeys ); |
337 | | - $index = 0; |
| 343 | + if( $nChild ) { |
338 | 344 | foreach ( $data as $key => $rawData ) { |
339 | | - $index = ( intval( $key ) % $keyCount === 0 ) ? 0 : $index + 1; |
340 | | - if ( in_array( $index, $arrayKeys ) ) { |
| 345 | + if ( strpos( $rawData, '*' ) === 0 && strpos( $rawData, '**' ) !== 0 && $key >= 0 ) { |
341 | 346 | $data = trim( str_replace( '*', '', $rawData ) ); |
342 | | - if ( is_array( $formatter[$index] ) ) { |
343 | | - $name = $formatter[$index]['name']; |
344 | | - if ( isset( $formatter[$index]['callback'] ) ) { |
345 | | - $callback = $formatter[$index]['callback']; |
346 | | - if ( method_exists( $this, $callback ) ) { |
347 | | - if ( isset( $formatter[$index]['parameters'] ) ) { |
348 | | - if ( is_array( $formatter[$index]['parameters'] ) ) { |
349 | | - $parameters = array(); |
350 | | - foreach ( $formatter[$index]['parameters'] as $parameter ) { |
351 | | - if ( isset( $options[$prefixName][$parameter] ) ) { |
352 | | - $parameters[$parameter] = $options[$prefixName][$parameter]; |
353 | | - } |
354 | | - } |
355 | | - $data = $this->$callback( $data, $parameters ); |
356 | | - } else { |
357 | | - $parameter = $formatter[$index]['parameters']; |
358 | | - if ( isset( $options[$prefixName][$parameter] ) ) { |
359 | | - $parameterValue = $options[$prefixName][$parameter]; |
360 | | - $data = $this->$callback( $data, $parameterValue ); |
361 | | - } |
362 | | - } |
363 | | - } else { |
364 | | - $data = $this->$callback( $data ); |
365 | | - } |
366 | | - } |
| 347 | + $prefixName = strtoupper( $data ); |
| 348 | + $options[$prefixName] = ''; |
| 349 | + } elseif ( strpos( $rawData, '**' ) === 0 && $key > 0 ) { |
| 350 | + $data = trim( str_replace( '*', '', $rawData ) ); |
| 351 | + if ( !is_array( $formatter ) ) { |
| 352 | + $options[$prefixName][] = $data; |
| 353 | + continue; |
| 354 | + } |
| 355 | + if ( !isset( $formatter[0]['callback'] ) ) { |
| 356 | + continue; |
| 357 | + } |
| 358 | + $callback = $formatter[0]['callback']; |
| 359 | + if ( method_exists( $this, $callback ) ) { |
| 360 | + $data = $this->$callback( $data ); |
| 361 | + if ( $data ) { |
| 362 | + $options[$prefixName][] = $data; |
367 | 363 | } |
368 | | - } else { |
369 | | - $name = $formatter[$index]; |
370 | 364 | } |
371 | | - if ( $index === 0 ) { |
372 | | - $prefixName = strtoupper( $data ); |
373 | | - } |
374 | | - $options[$prefixName][$name] = $data; |
375 | 365 | } |
376 | 366 | } |
377 | | - } else if ( is_array( $formatter ) && $nChild ) { |
378 | | - foreach ( $data as $key => $rawData ) { |
379 | | - if ( strpos( $rawData, '*' ) === 0 && strpos( $rawData, '**' ) !== 0 && $key >= 0 ) { |
380 | | - $data = trim( str_replace( '*', '', $rawData ) ); |
381 | | - $prefixName = strtoupper( $data ); |
382 | | - $options[$prefixName] = ''; |
383 | | - } else if ( strpos( $rawData, '**' ) === 0 && $key > 0 ) { |
384 | | - $data = trim( str_replace( '*', '', $rawData ) ); |
385 | | - if ( is_array( $formatter ) ) { |
386 | | - if ( isset( $formatter[0]['callback'] ) ) { |
387 | | - $callback = $formatter[0]['callback']; |
388 | | - if ( method_exists( $this, $callback ) ) { |
389 | | - $data = $this->$callback( $data ); |
390 | | - if ( $data ) { |
391 | | - $options[$prefixName][] = $data; |
| 367 | + wfProfileOut( __METHOD__ ); |
| 368 | + return $options; |
| 369 | + } |
| 370 | + |
| 371 | + $arrayKeys = array_keys( $formatter ); |
| 372 | + $keyCount = count( $arrayKeys ); |
| 373 | + $index = 0; |
| 374 | + foreach ( $data as $key => $rawData ) { |
| 375 | + $index = ( intval( $key ) % $keyCount === 0 ) ? 0 : $index + 1; |
| 376 | + if ( !in_array( $index, $arrayKeys ) ) { |
| 377 | + continue; |
| 378 | + } |
| 379 | + $data = trim( str_replace( '*', '', $rawData ) ); |
| 380 | + if ( is_array( $formatter[$index] ) ) { |
| 381 | + $name = $formatter[$index]['name']; |
| 382 | + if ( isset( $formatter[$index]['callback'] ) ) { |
| 383 | + $callback = $formatter[$index]['callback']; |
| 384 | + if ( method_exists( $this, $callback ) ) { |
| 385 | + if ( isset( $formatter[$index]['parameters'] ) ) { |
| 386 | + if ( is_array( $formatter[$index]['parameters'] ) ) { |
| 387 | + $parameters = array(); |
| 388 | + foreach ( $formatter[$index]['parameters'] as $parameter ) { |
| 389 | + if ( isset( $options[$prefixName][$parameter] ) ) { |
| 390 | + $parameters[$parameter] = $options[$prefixName][$parameter]; |
| 391 | + } |
392 | 392 | } |
| 393 | + $data = $this->$callback( $data, $parameters ); |
| 394 | + } else { |
| 395 | + $parameter = $formatter[$index]['parameters']; |
| 396 | + if ( isset( $options[$prefixName][$parameter] ) ) { |
| 397 | + $parameterValue = $options[$prefixName][$parameter]; |
| 398 | + $data = $this->$callback( $data, $parameterValue ); |
| 399 | + } |
393 | 400 | } |
| 401 | + } else { |
| 402 | + $data = $this->$callback( $data ); |
394 | 403 | } |
395 | | - } else { |
396 | | - $options[$prefixName][] = $data; |
397 | 404 | } |
398 | 405 | } |
| 406 | + } else { |
| 407 | + $name = $formatter[$index]; |
399 | 408 | } |
| 409 | + if ( $index === 0 ) { |
| 410 | + $prefixName = strtoupper( $data ); |
| 411 | + } |
| 412 | + $options[$prefixName][$name] = $data; |
400 | 413 | } |
401 | 414 | wfProfileOut( __METHOD__ ); |
402 | 415 | return $options; |
— | — | @@ -435,12 +448,12 @@ |
436 | 449 | if ( !$carrierOptions ) { |
437 | 450 | if ( $rev ) { |
438 | 451 | $formatter = array( |
439 | | - 0 => 'name', |
440 | | - 1 => array( 'name' => 'link', |
| 452 | + 0 => 'name', |
| 453 | + 1 => array( 'name' => 'link', |
441 | 454 | 'callback' => 'createUrlCallback', |
442 | 455 | 'parameters' => 'name', |
443 | 456 | ), |
444 | | - 2 => array( 'name' => 'partnerId', |
| 457 | + 2 => array( 'name' => 'partnerId', |
445 | 458 | 'callback' => 'intValCallback' |
446 | 459 | ), |
447 | 460 | ); |