Index: trunk/extensions/Cite/Cite_body.php |
— | — | @@ -21,7 +21,7 @@ |
22 | 22 | /**#@+ |
23 | 23 | * @access private |
24 | 24 | */ |
25 | | - |
| 25 | + |
26 | 26 | /** |
27 | 27 | * Datastructure representing <ref> input, in the format of: |
28 | 28 | * <code> |
— | — | @@ -54,7 +54,7 @@ |
55 | 55 | * @var array |
56 | 56 | **/ |
57 | 57 | var $mRefs = array(); |
58 | | - |
| 58 | + |
59 | 59 | /** |
60 | 60 | * Count for user displayed output (ref[1], ref[2], ...) |
61 | 61 | * |
— | — | @@ -88,16 +88,16 @@ |
89 | 89 | * @var array |
90 | 90 | */ |
91 | 91 | var $mLinkLabels = array(); |
92 | | - |
| 92 | + |
93 | 93 | /** |
94 | 94 | * @var object |
95 | 95 | */ |
96 | 96 | var $mParser; |
97 | | - |
| 97 | + |
98 | 98 | /** |
99 | 99 | * True when a <ref> tag is being processed. |
100 | 100 | * Used to avoid infinite recursion |
101 | | - * |
| 101 | + * |
102 | 102 | * @var boolean |
103 | 103 | */ |
104 | 104 | var $mInCite = false; |
— | — | @@ -105,30 +105,30 @@ |
106 | 106 | /** |
107 | 107 | * True when a <references> tag is being processed. |
108 | 108 | * Used to detect the use of <references> to define refs |
109 | | - * |
| 109 | + * |
110 | 110 | * @var boolean |
111 | 111 | */ |
112 | 112 | var $mInReferences = false; |
113 | 113 | |
114 | 114 | /** |
115 | 115 | * Error stack used when defining refs in <references> |
116 | | - * |
| 116 | + * |
117 | 117 | * @var array |
118 | 118 | */ |
119 | 119 | var $mReferencesErrors = array(); |
120 | 120 | |
121 | 121 | /** |
122 | 122 | * Group used when in <references> block |
123 | | - * |
| 123 | + * |
124 | 124 | * @var string |
125 | 125 | */ |
126 | 126 | var $mReferencesGroup = ''; |
127 | 127 | |
128 | 128 | /** |
129 | | - * <ref> call stack |
| 129 | + * <ref> call stack |
130 | 130 | * Used to cleanup out of sequence ref calls created by #tag |
131 | 131 | * See description of function rollbackRef. |
132 | | - * |
| 132 | + * |
133 | 133 | * @var array |
134 | 134 | */ |
135 | 135 | var $mRefCallStack = array(); |
— | — | @@ -164,10 +164,10 @@ |
165 | 165 | |
166 | 166 | function guardedRef( $str, $argv, $parser, $default_group = CITE_DEFAULT_GROUP ) { |
167 | 167 | $this->mParser = $parser; |
168 | | - |
| 168 | + |
169 | 169 | # The key here is the "name" attribute. |
170 | 170 | list( $key, $group, $follow ) = $this->refArg( $argv ); |
171 | | - |
| 171 | + |
172 | 172 | # Split these into groups. |
173 | 173 | if ( $group === null ) { |
174 | 174 | if ( $this->mInReferences ) { |
— | — | @@ -176,8 +176,8 @@ |
177 | 177 | $group = $default_group; |
178 | 178 | } |
179 | 179 | } |
180 | | - |
181 | | - # This section deals with constructions of the form |
| 180 | + |
| 181 | + # This section deals with constructions of the form |
182 | 182 | # |
183 | 183 | # <references> |
184 | 184 | # <ref name="foo"> BAR </ref> |
— | — | @@ -224,7 +224,7 @@ |
225 | 225 | $str = null; |
226 | 226 | } |
227 | 227 | } |
228 | | - |
| 228 | + |
229 | 229 | if ( $key === false ) { |
230 | 230 | # TODO: Comment this case; what does this condition mean? |
231 | 231 | $this->mRefCallStack[] = false; |
— | — | @@ -236,7 +236,7 @@ |
237 | 237 | $this->mRefCallStack[] = false; |
238 | 238 | return $this->error( 'cite_error_ref_no_key' ); |
239 | 239 | } |
240 | | - |
| 240 | + |
241 | 241 | if ( preg_match( '/^[0-9]+$/', $key ) || preg_match( '/^[0-9]+$/', $follow ) ) { |
242 | 242 | # Numeric names mess up the resulting id's, potentially produ- |
243 | 243 | # cing duplicate id's in the XHTML. The Right Thing To Do |
— | — | @@ -283,7 +283,7 @@ |
284 | 284 | |
285 | 285 | /** |
286 | 286 | * Parse the arguments to the <ref> tag |
287 | | - * |
| 287 | + * |
288 | 288 | * "name" : Key of the reference. |
289 | 289 | * "group" : Group to which it belongs. Needs to be passed to <references /> too. |
290 | 290 | * "follow" : If the current reference is the continuation of another, key of that reference. |
— | — | @@ -301,11 +301,11 @@ |
302 | 302 | $key = null; |
303 | 303 | $follow = null; |
304 | 304 | |
305 | | - if ( $cnt > 2 ) |
| 305 | + if ( $cnt > 2 ) { |
306 | 306 | // There should only be one key or follow parameter, and one group parameter |
307 | | - // FIXME : this looks inconsistent, it should probably return a tuple |
| 307 | + // FIXME : this looks inconsistent, it should probably return a tuple |
308 | 308 | return false; |
309 | | - else if ( $cnt >= 1 ) { |
| 309 | + } elseif ( $cnt >= 1 ) { |
310 | 310 | if ( isset( $argv['name'] ) && isset( $argv['follow'] ) ) { |
311 | 311 | return array( false, false, false ); |
312 | 312 | } |
— | — | @@ -322,22 +322,26 @@ |
323 | 323 | --$cnt; |
324 | 324 | } |
325 | 325 | if ( isset( $argv['group'] ) ) { |
326 | | - if ( ! $wgAllowCiteGroups ) return array( false ); // remove when groups are fully tested. |
| 326 | + if ( !$wgAllowCiteGroups ) { |
| 327 | + // remove when groups are fully tested. |
| 328 | + return array( false ); |
| 329 | + } |
327 | 330 | // Group given. |
328 | 331 | $group = $argv['group']; |
329 | 332 | unset( $argv['group'] ); |
330 | 333 | --$cnt; |
331 | 334 | } |
332 | 335 | |
333 | | - if ( $cnt == 0 ) |
| 336 | + if ( $cnt == 0 ) { |
334 | 337 | return array ( $key, $group, $follow ); |
335 | | - else |
| 338 | + } else { |
336 | 339 | // Invalid key |
337 | 340 | return array( false, false, false ); |
338 | | - } |
339 | | - else |
| 341 | + } |
| 342 | + } else { |
340 | 343 | // No key |
341 | 344 | return array( null, $group, false ); |
| 345 | + } |
342 | 346 | } |
343 | 347 | |
344 | 348 | /** |
— | — | @@ -345,31 +349,35 @@ |
346 | 350 | * |
347 | 351 | * @param string $str Input from the <ref> tag |
348 | 352 | * @param mixed $key Argument to the <ref> tag as returned by $this->refArg() |
349 | | - * @return string |
| 353 | + * @return string |
350 | 354 | */ |
351 | 355 | function stack( $str, $key = null, $group, $follow, $call ) { |
352 | | - if ( ! isset( $this->mRefs[$group] ) ) |
| 356 | + if ( !isset( $this->mRefs[$group] ) ) { |
353 | 357 | $this->mRefs[$group] = array(); |
354 | | - if ( ! isset( $this->mGroupCnt[$group] ) ) |
| 358 | + } |
| 359 | + if ( !isset( $this->mGroupCnt[$group] ) ) { |
355 | 360 | $this->mGroupCnt[$group] = 0; |
| 361 | + } |
356 | 362 | |
357 | 363 | if ( $follow != null ) { |
358 | 364 | if ( isset( $this->mRefs[$group][$follow] ) && is_array( $this->mRefs[$group][$follow] ) ) { |
359 | 365 | // add text to the note that is being followed |
360 | | - $this->mRefs[$group][$follow]['text'] = $this->mRefs[$group][$follow]['text'] . ' '. $str; |
| 366 | + $this->mRefs[$group][$follow]['text'] = $this->mRefs[$group][$follow]['text'] . ' ' . $str; |
361 | 367 | } else { |
362 | 368 | // insert part of note at the beginning of the group |
363 | | - for( $k=0 ; $k< count( $this->mRefs[$group] ) ; $k++) { |
364 | | - if( $this->mRefs[$group][$k]['follow'] == null ) break; |
| 369 | + for ( $k = 0 ; $k < count( $this->mRefs[$group] ) ; $k++ ) { |
| 370 | + if ( $this->mRefs[$group][$k]['follow'] == null ) { |
| 371 | + break; |
| 372 | + } |
365 | 373 | } |
366 | | - array_splice( $this->mRefs[$group], $k, 0, |
367 | | - array( array( 'count' => - 1, |
368 | | - 'text' => $str, |
369 | | - 'key' => ++$this->mOutCnt , |
370 | | - 'follow' => $follow) ) ); |
371 | | - array_splice( $this->mRefCallStack, $k, 0, |
| 374 | + array_splice( $this->mRefs[$group], $k, 0, |
| 375 | + array( array( 'count' => - 1, |
| 376 | + 'text' => $str, |
| 377 | + 'key' => ++$this->mOutCnt , |
| 378 | + 'follow' => $follow ) ) ); |
| 379 | + array_splice( $this->mRefCallStack, $k, 0, |
372 | 380 | array( array( 'new', $call, $str, $key, $group, $this->mOutCnt ) ) ); |
373 | | - $this->mInCnt++; |
| 381 | + $this->mInCnt++; |
374 | 382 | } |
375 | 383 | // return an empty string : this is not a reference |
376 | 384 | return ''; |
— | — | @@ -381,10 +389,10 @@ |
382 | 390 | $this->mRefCallStack[] = array( 'new', $call, $str, $key, $group, $this->mOutCnt ); |
383 | 391 | |
384 | 392 | return $this->linkRef( $group, $this->mInCnt++ ); |
385 | | - } else if ( is_string( $key ) ) { |
| 393 | + } elseif ( is_string( $key ) ) { |
386 | 394 | // Valid key |
387 | | - if ( ! isset( $this->mRefs[$group][$key] ) || ! is_array( $this->mRefs[$group][$key] ) ) { |
388 | | - // First occurance |
| 395 | + if ( !isset( $this->mRefs[$group][$key] ) || !is_array( $this->mRefs[$group][$key] ) ) { |
| 396 | + // First occurrence |
389 | 397 | $this->mRefs[$group][$key] = array( |
390 | 398 | 'text' => $str, |
391 | 399 | 'count' => 0, |
— | — | @@ -420,19 +428,19 @@ |
421 | 429 | $this->mRefs[$group][$key]['key'] . "-" . ++$this->mRefs[$group][$key]['count'], |
422 | 430 | $this->mRefs[$group][$key]['number'], |
423 | 431 | "-" . $this->mRefs[$group][$key]['key'] |
424 | | - ); } |
| 432 | + ); |
| 433 | + } |
| 434 | + } else { |
| 435 | + $this->croak( 'cite_error_stack_invalid_input', serialize( array( $key, $str ) ) ); |
425 | 436 | } |
| 437 | + } |
426 | 438 | |
427 | | - else |
428 | | - $this->croak( 'cite_error_stack_invalid_input', serialize( array( $key, $str ) ) ); |
429 | | - } |
430 | | - |
431 | 439 | /** |
432 | 440 | * Partially undoes the effect of calls to stack() |
433 | | - * |
| 441 | + * |
434 | 442 | * Called by guardedReferences() |
435 | 443 | * |
436 | | - * The option to define <ref> within <references> makes the |
| 444 | + * The option to define <ref> within <references> makes the |
437 | 445 | * behavior of <ref> context dependent. This is normally fine |
438 | 446 | * but certain operations (especially #tag) lead to out-of-order |
439 | 447 | * parser evaluation with the <ref> tags being processed before |
— | — | @@ -444,7 +452,9 @@ |
445 | 453 | * corrupting certain links. |
446 | 454 | */ |
447 | 455 | function rollbackRef( $type, $key, $group, $index ) { |
448 | | - if ( !isset( $this->mRefs[$group] ) ) { return; } |
| 456 | + if ( !isset( $this->mRefs[$group] ) ) { |
| 457 | + return; |
| 458 | + } |
449 | 459 | |
450 | 460 | if ( $key === null ) { |
451 | 461 | foreach ( $this->mRefs[$group] as $k => $v ) { |
— | — | @@ -456,11 +466,17 @@ |
457 | 467 | } |
458 | 468 | |
459 | 469 | # Sanity checks that specified element exists. |
460 | | - if ( $key === null ) { return; } |
461 | | - if ( !isset( $this->mRefs[$group][$key] ) ) { return; } |
462 | | - if ( $this->mRefs[$group][$key]['key'] != $index ) { return; } |
| 470 | + if ( $key === null ) { |
| 471 | + return; |
| 472 | + } |
| 473 | + if ( !isset( $this->mRefs[$group][$key] ) ) { |
| 474 | + return; |
| 475 | + } |
| 476 | + if ( $this->mRefs[$group][$key]['key'] != $index ) { |
| 477 | + return; |
| 478 | + } |
463 | 479 | |
464 | | - switch( $type ) { |
| 480 | + switch ( $type ) { |
465 | 481 | case 'new': |
466 | 482 | # Rollback the addition of new elements to the stack. |
467 | 483 | unset( $this->mRefs[$group][$key] ); |
— | — | @@ -506,22 +522,24 @@ |
507 | 523 | global $wgAllowCiteGroups; |
508 | 524 | |
509 | 525 | $this->mParser = $parser; |
510 | | - |
| 526 | + |
511 | 527 | if ( isset( $argv['group'] ) and $wgAllowCiteGroups ) { |
512 | 528 | $group = $argv['group']; |
513 | 529 | unset ( $argv['group'] ); |
514 | 530 | } |
515 | | - |
| 531 | + |
516 | 532 | if ( strval( $str ) !== '' ) { |
517 | 533 | $this->mReferencesGroup = $group; |
518 | | - |
| 534 | + |
519 | 535 | # Detect whether we were sent already rendered <ref>s |
520 | 536 | # Mostly a side effect of using #tag to call references |
521 | 537 | $count = substr_count( $str, $parser->uniqPrefix() . "-ref-" ); |
522 | 538 | for ( $i = 1; $i <= $count; $i++ ) { |
523 | | - if ( count( $this->mRefCallStack ) < 1 ) break; |
| 539 | + if ( count( $this->mRefCallStack ) < 1 ) { |
| 540 | + break; |
| 541 | + } |
524 | 542 | |
525 | | - # The following assumes that the parsed <ref>s sent within |
| 543 | + # The following assumes that the parsed <ref>s sent within |
526 | 544 | # the <references> block were the most recent calls to |
527 | 545 | # <ref>. This assumption is true for all known use cases, |
528 | 546 | # but not strictly enforced by the parser. It is possible |
— | — | @@ -533,7 +551,7 @@ |
534 | 552 | list( $type, $ref_argv, $ref_str, |
535 | 553 | $ref_key, $ref_group, $ref_index ) = $call; |
536 | 554 | |
537 | | - # Undo effects of calling <ref> while unaware of containing <references> |
| 555 | + # Undo effects of calling <ref> while unaware of containing <references> |
538 | 556 | $this->rollbackRef( $type, $ref_key, $ref_group, $ref_index ); |
539 | 557 | |
540 | 558 | # Rerun <ref> call now that mInReferences is set. |
— | — | @@ -548,14 +566,16 @@ |
549 | 567 | $this->mRefCallStack = array(); |
550 | 568 | } |
551 | 569 | |
552 | | - if ( count( $argv ) && $wgAllowCiteGroups ) |
| 570 | + if ( count( $argv ) && $wgAllowCiteGroups ) { |
553 | 571 | return $this->error( 'cite_error_references_invalid_parameters_group' ); |
554 | | - elseif ( count( $argv ) ) |
| 572 | + } elseif ( count( $argv ) ) { |
555 | 573 | return $this->error( 'cite_error_references_invalid_parameters' ); |
556 | | - else { |
| 574 | + } else { |
557 | 575 | $s = $this->referencesFormat( $group ); |
558 | | - if ( $parser->getOptions()->getIsSectionPreview() ) return $s; |
559 | | - |
| 576 | + if ( $parser->getOptions()->getIsSectionPreview() ) { |
| 577 | + return $s; |
| 578 | + } |
| 579 | + |
560 | 580 | # Append errors generated while processing <references> |
561 | 581 | if ( count( $this->mReferencesErrors ) > 0 ) { |
562 | 582 | $s .= "\n" . implode( "<br />\n", $this->mReferencesErrors ); |
— | — | @@ -571,15 +591,17 @@ |
572 | 592 | * @return string XHTML ready for output |
573 | 593 | */ |
574 | 594 | function referencesFormat( $group ) { |
575 | | - if ( ( count( $this->mRefs ) == 0 ) or ( empty( $this->mRefs[$group] ) ) ) |
| 595 | + if ( ( count( $this->mRefs ) == 0 ) or ( empty( $this->mRefs[$group] ) ) ) { |
576 | 596 | return ''; |
577 | | - |
| 597 | + } |
| 598 | + |
578 | 599 | wfProfileIn( __METHOD__ ); |
579 | 600 | wfProfileIn( __METHOD__ . '-entries' ); |
580 | 601 | $ent = array(); |
581 | | - foreach ( $this->mRefs[$group] as $k => $v ) |
| 602 | + foreach ( $this->mRefs[$group] as $k => $v ) { |
582 | 603 | $ent[] = $this->referencesFormatEntry( $k, $v ); |
583 | | - |
| 604 | + } |
| 605 | + |
584 | 606 | $prefix = wfMsgForContentNoTrans( 'cite_references_prefix' ); |
585 | 607 | $suffix = wfMsgForContentNoTrans( 'cite_references_suffix' ); |
586 | 608 | $content = implode( "\n", $ent ); |
— | — | @@ -590,36 +612,36 @@ |
591 | 613 | $cacheKey = wfMemcKey( 'citeref', md5( $parserInput ), $this->mParser->Title()->getArticleID() ); |
592 | 614 | |
593 | 615 | wfProfileOut( __METHOD__ . '-entries' ); |
594 | | - |
| 616 | + |
595 | 617 | global $wgCiteCacheReferences; |
596 | 618 | if ( $wgCiteCacheReferences ) { |
597 | 619 | wfProfileIn( __METHOD__ . '-cache-get' ); |
598 | 620 | $data = $wgMemc->get( $cacheKey ); |
599 | 621 | wfProfileOut( __METHOD__ . '-cache-get' ); |
600 | 622 | } |
601 | | - |
| 623 | + |
602 | 624 | if ( empty( $data ) ) { |
603 | 625 | wfProfileIn( __METHOD__ . '-parse' ); |
604 | | - |
| 626 | + |
605 | 627 | // Live hack: parse() adds two newlines on WM, can't reproduce it locally -ævar |
606 | 628 | $ret = rtrim( $this->parse( $parserInput ), "\n" ); |
607 | | - |
| 629 | + |
608 | 630 | if ( $wgCiteCacheReferences ) { |
609 | 631 | $serData = $this->mParser->serialiseHalfParsedText( $ret ); |
610 | 632 | $wgMemc->set( $cacheKey, $serData, 86400 ); |
611 | 633 | } |
612 | | - |
| 634 | + |
613 | 635 | wfProfileOut( __METHOD__ . '-parse' ); |
614 | 636 | } else { |
615 | 637 | $ret = $this->mParser->unserialiseHalfParsedText( $data ); |
616 | 638 | } |
617 | 639 | |
618 | 640 | wfProfileOut( __METHOD__ ); |
619 | | - |
| 641 | + |
620 | 642 | // done, clean up so we can reuse the group |
621 | | - unset ( $this->mRefs[$group] ); |
| 643 | + unset( $this->mRefs[$group] ); |
622 | 644 | unset( $this->mGroupCnt[$group] ); |
623 | | - |
| 645 | + |
624 | 646 | return $ret; |
625 | 647 | } |
626 | 648 | |
— | — | @@ -640,13 +662,13 @@ |
641 | 663 | $this->refKey( $key ), |
642 | 664 | $val |
643 | 665 | ); |
644 | | - } else if ( isset( $val['follow'] ) ) { |
| 666 | + } elseif ( isset( $val['follow'] ) ) { |
645 | 667 | return wfMsgForContentNoTrans( |
646 | 668 | 'cite_references_no_link', |
647 | 669 | $this->referencesKey( $val['follow'] ), |
648 | 670 | $val['text'] |
649 | 671 | ); |
650 | | - } else if ( $val['text'] == '' ) { |
| 672 | + } elseif ( $val['text'] == '' ) { |
651 | 673 | return wfMsgForContentNoTrans( |
652 | 674 | 'cite_references_link_one', |
653 | 675 | $this->referencesKey( $key ), |
— | — | @@ -668,7 +690,7 @@ |
669 | 691 | // anonymous reference because displaying "1. 1.1 Ref text" is |
670 | 692 | // overkill and users frequently use named references when they |
671 | 693 | // don't need them for convenience |
672 | | - } else if ( $val['count'] === 0 ) { |
| 694 | + } elseif ( $val['count'] === 0 ) { |
673 | 695 | return wfMsgForContentNoTrans( |
674 | 696 | 'cite_references_link_one', |
675 | 697 | $this->referencesKey( $key . "-" . $val['key'] ), |
— | — | @@ -744,8 +766,8 @@ |
745 | 767 | |
746 | 768 | /** |
747 | 769 | * Generate a custom format link for a group given an offset, e.g. |
748 | | - * the second <ref group="foo"> is b if $this->mLinkLabels["foo"] = |
749 | | - * array( 'a', 'b', 'c', ...). |
| 770 | + * the second <ref group="foo"> is b if $this->mLinkLabels["foo"] = |
| 771 | + * array( 'a', 'b', 'c', ...). |
750 | 772 | * Return an error if the offset > the # of array items |
751 | 773 | * |
752 | 774 | * @param int $offset The offset |
— | — | @@ -754,16 +776,16 @@ |
755 | 777 | * |
756 | 778 | * @return string |
757 | 779 | */ |
758 | | - function getLinkLabel( $offset, $group, $label) { |
| 780 | + function getLinkLabel( $offset, $group, $label ) { |
759 | 781 | $message = "cite_link_label_group-$group"; |
760 | 782 | if ( !isset( $this->mLinkLabels[$group] ) ) { |
761 | | - $this->genLinkLabels($group, $message); |
| 783 | + $this->genLinkLabels( $group, $message ); |
762 | 784 | } |
763 | | - if ($this->mLinkLabels[$group] === false) { |
| 785 | + if ( $this->mLinkLabels[$group] === false ) { |
764 | 786 | // Use normal representation, ie. "$group 1", "$group 2"... |
765 | 787 | return $label; |
766 | 788 | } |
767 | | - |
| 789 | + |
768 | 790 | if ( isset( $this->mLinkLabels[$group][$offset - 1] ) ) { |
769 | 791 | return $this->mLinkLabels[$group][$offset - 1]; |
770 | 792 | } else { |
— | — | @@ -786,10 +808,11 @@ |
787 | 809 | function refKey( $key, $num = null ) { |
788 | 810 | $prefix = wfMsgForContent( 'cite_reference_link_prefix' ); |
789 | 811 | $suffix = wfMsgForContent( 'cite_reference_link_suffix' ); |
790 | | - if ( isset( $num ) ) |
| 812 | + if ( isset( $num ) ) { |
791 | 813 | $key = wfMsgForContentNoTrans( 'cite_reference_link_key_with_num', $key, $num ); |
792 | | - |
793 | | - return $prefix . $key . $suffix; |
| 814 | + } |
| 815 | + |
| 816 | + return "$prefix$key$suffix"; |
794 | 817 | } |
795 | 818 | |
796 | 819 | /** |
— | — | @@ -806,10 +829,11 @@ |
807 | 830 | function referencesKey( $key, $num = null ) { |
808 | 831 | $prefix = wfMsgForContent( 'cite_references_link_prefix' ); |
809 | 832 | $suffix = wfMsgForContent( 'cite_references_link_suffix' ); |
810 | | - if ( isset( $num ) ) |
| 833 | + if ( isset( $num ) ) { |
811 | 834 | $key = wfMsgForContentNoTrans( 'cite_reference_link_key_with_num', $key, $num ); |
812 | | - |
813 | | - return $prefix . $key . $suffix; |
| 835 | + } |
| 836 | + |
| 837 | + return "$prefix$key$suffix"; |
814 | 838 | } |
815 | 839 | |
816 | 840 | /** |
— | — | @@ -827,14 +851,14 @@ |
828 | 852 | function linkRef( $group, $key, $count = null, $label = null, $subkey = '' ) { |
829 | 853 | global $wgContLang; |
830 | 854 | $label = is_null( $label ) ? ++$this->mGroupCnt[$group] : $label; |
831 | | - |
| 855 | + |
832 | 856 | return |
833 | 857 | $this->parse( |
834 | 858 | wfMsgForContentNoTrans( |
835 | 859 | 'cite_reference_link', |
836 | 860 | $this->refKey( $key, $count ), |
837 | 861 | $this->referencesKey( $key . $subkey ), |
838 | | - $this->getLinkLabel( $label, $group, |
| 862 | + $this->getLinkLabel( $label, $group, |
839 | 863 | ( ( $group == CITE_DEFAULT_GROUP ) ? '':"$group " ) . $wgContLang->formatNum( $label ) ) |
840 | 864 | ) |
841 | 865 | ); |
— | — | @@ -858,10 +882,10 @@ |
859 | 883 | $sep = wfMsgForContentNoTrans( 'cite_references_link_many_sep' ); |
860 | 884 | $and = wfMsgForContentNoTrans( 'cite_references_link_many_and' ); |
861 | 885 | |
862 | | - if ( $cnt == 1 ) |
| 886 | + if ( $cnt == 1 ) { |
863 | 887 | // Enforce always returning a string |
864 | 888 | return (string)$arr[0]; |
865 | | - else { |
| 889 | + } else { |
866 | 890 | $t = array_slice( $arr, 0, $cnt - 1 ); |
867 | 891 | return implode( $sep, $t ) . $and . $arr[$cnt - 1]; |
868 | 892 | } |
— | — | @@ -893,7 +917,7 @@ |
894 | 918 | false |
895 | 919 | ); |
896 | 920 | $text = $ret->getText(); |
897 | | - |
| 921 | + |
898 | 922 | return $this->fixTidy( $text ); |
899 | 923 | } |
900 | 924 | } |
— | — | @@ -910,13 +934,13 @@ |
911 | 935 | function fixTidy( $text ) { |
912 | 936 | global $wgUseTidy; |
913 | 937 | |
914 | | - if ( ! $wgUseTidy ) |
| 938 | + if ( !$wgUseTidy ) { |
915 | 939 | return $text; |
916 | | - else { |
| 940 | + } else { |
917 | 941 | $text = preg_replace( '~^<p>\s*~', '', $text ); |
918 | 942 | $text = preg_replace( '~\s*</p>\s*~', '', $text ); |
919 | 943 | $text = preg_replace( '~\n$~', '', $text ); |
920 | | - |
| 944 | + |
921 | 945 | return $text; |
922 | 946 | } |
923 | 947 | } |
— | — | @@ -938,13 +962,14 @@ |
939 | 963 | * 'cite_reference_link' message instead of numbers, the format is an |
940 | 964 | * arbitrary number of tokens separated by [\t\n ] |
941 | 965 | */ |
942 | | - function genLinkLabels($group, $message) { |
| 966 | + function genLinkLabels( $group, $message ) { |
943 | 967 | wfProfileIn( __METHOD__ ); |
944 | 968 | $text = false; |
945 | 969 | $msg = wfMessage( $message )->inContentLanguage(); |
946 | | - if ( $msg->exists() ) |
| 970 | + if ( $msg->exists() ) { |
947 | 971 | $text = $msg->plain(); |
948 | | - $this->mLinkLabels[$group] = ($text == '') ? false : preg_split( '#[\n\t ]#', $text ); |
| 972 | + } |
| 973 | + $this->mLinkLabels[$group] = ( $text == '' ) ? false : preg_split( '#[\n\t ]#', $text ); |
949 | 974 | wfProfileOut( __METHOD__ ); |
950 | 975 | } |
951 | 976 | |
— | — | @@ -955,9 +980,10 @@ |
956 | 981 | function clearState() { |
957 | 982 | # Don't clear state when we're in the middle of parsing |
958 | 983 | # a <ref> tag |
959 | | - if ( $this->mInCite || $this->mInReferences ) |
| 984 | + if ( $this->mInCite || $this->mInReferences ) { |
960 | 985 | return true; |
961 | | - |
| 986 | + } |
| 987 | + |
962 | 988 | $this->mGroupCnt = array(); |
963 | 989 | $this->mOutCnt = - 1; |
964 | 990 | $this->mInCnt = 0; |
— | — | @@ -969,14 +995,18 @@ |
970 | 996 | } |
971 | 997 | |
972 | 998 | /** |
973 | | - * Called at the end of page processing to append an error if refs were |
| 999 | + * Called at the end of page processing to append an error if refs were |
974 | 1000 | * used without a references tag. |
975 | 1001 | */ |
976 | 1002 | function checkRefsNoReferences( &$parser, &$text ) { |
977 | | - if ( $parser->getOptions()->getIsSectionPreview() ) return true; |
| 1003 | + if ( $parser->getOptions()->getIsSectionPreview() ) { |
| 1004 | + return true; |
| 1005 | + } |
978 | 1006 | |
979 | 1007 | foreach ( $this->mRefs as $group => $refs ) { |
980 | | - if ( count( $refs ) == 0 ) continue; |
| 1008 | + if ( count( $refs ) == 0 ) { |
| 1009 | + continue; |
| 1010 | + } |
981 | 1011 | $text .= "\n<br />"; |
982 | 1012 | if ( $group == CITE_DEFAULT_GROUP ) { |
983 | 1013 | $text .= $this->error( 'cite_error_refs_without_references' ); |