Index: trunk/phase3/includes/parser/Parser.php |
— | — | @@ -45,8 +45,7 @@ |
46 | 46 | * |
47 | 47 | * @ingroup Parser |
48 | 48 | */ |
49 | | -class Parser |
50 | | -{ |
| 49 | +class Parser { |
51 | 50 | /** |
52 | 51 | * Update this version number when the ParserOutput format |
53 | 52 | * changes in an incompatible way, so the parser cache |
— | — | @@ -93,10 +92,10 @@ |
94 | 93 | * @private |
95 | 94 | */ |
96 | 95 | # Persistent: |
97 | | - var $mTagHooks, $mTransparentTagHooks, $mFunctionHooks, $mFunctionSynonyms, $mVariables, |
98 | | - $mSubstWords, $mImageParams, $mImageParamsMagicArray, $mStripList, $mMarkerIndex, |
99 | | - $mPreprocessor, $mExtLinkBracketedRegex, $mUrlProtocols, $mDefaultStripList, |
100 | | - $mVarCache, $mConf, $mFunctionTagHooks; |
| 96 | + var $mTagHooks, $mTransparentTagHooks, $mFunctionHooks, $mFunctionSynonyms, $mVariables; |
| 97 | + var $mSubstWords, $mImageParams, $mImageParamsMagicArray, $mStripList, $mMarkerIndex; |
| 98 | + var $mPreprocessor, $mExtLinkBracketedRegex, $mUrlProtocols, $mDefaultStripList; |
| 99 | + var $mVarCache, $mConf, $mFunctionTagHooks; |
101 | 100 | |
102 | 101 | |
103 | 102 | # Cleared with clearState(): |
— | — | @@ -110,13 +109,13 @@ |
111 | 110 | |
112 | 111 | # Temporary |
113 | 112 | # These are variables reset at least once per parse regardless of $clearState |
114 | | - var $mOptions, // ParserOptions object |
115 | | - $mTitle, // Title context, used for self-link rendering and similar things |
116 | | - $mOutputType, // Output type, one of the OT_xxx constants |
117 | | - $ot, // Shortcut alias, see setOutputType() |
118 | | - $mRevisionId, // ID to display in {{REVISIONID}} tags |
119 | | - $mRevisionTimestamp, // The timestamp of the specified revision ID |
120 | | - $mRevIdForTs; // The revision ID which was used to fetch the timestamp |
| 113 | + var $mOptions; // ParserOptions object |
| 114 | + var $mTitle; // Title context, used for self-link rendering and similar things |
| 115 | + var $mOutputType; // Output type, one of the OT_xxx constants |
| 116 | + var $ot; // Shortcut alias, see setOutputType() |
| 117 | + var $mRevisionId; // ID to display in {{REVISIONID}} tags |
| 118 | + var $mRevisionTimestamp; // The timestamp of the specified revision ID |
| 119 | + var $mRevIdForTs; // The revision ID which was used to fetch the timestamp |
121 | 120 | |
122 | 121 | /**#@-*/ |
123 | 122 | |
— | — | @@ -216,7 +215,7 @@ |
217 | 216 | * Must not consist of all title characters, or else it will change |
218 | 217 | * the behaviour of <nowiki> in a link. |
219 | 218 | */ |
220 | | - #$this->mUniqPrefix = "\x07UNIQ" . Parser::getRandomString(); |
| 219 | + # $this->mUniqPrefix = "\x07UNIQ" . Parser::getRandomString(); |
221 | 220 | # Changed to \x7f to allow XML double-parsing -- TS |
222 | 221 | $this->mUniqPrefix = "\x7fUNIQ" . self::getRandomString(); |
223 | 222 | |
— | — | @@ -279,14 +278,14 @@ |
280 | 279 | * @public |
281 | 280 | */ |
282 | 281 | function uniqPrefix() { |
283 | | - if( !isset( $this->mUniqPrefix ) ) { |
| 282 | + if ( !isset( $this->mUniqPrefix ) ) { |
284 | 283 | // @todo Fixme: this is probably *horribly wrong* |
285 | 284 | // LanguageConverter seems to want $wgParser's uniqPrefix, however |
286 | 285 | // if this is called for a parser cache hit, the parser may not |
287 | 286 | // have ever been initialized in the first place. |
288 | 287 | // Not really sure what the heck is supposed to be going on here. |
289 | 288 | return ''; |
290 | | - //throw new MWException( "Accessing uninitialized mUniqPrefix" ); |
| 289 | + // throw new MWException( "Accessing uninitialized mUniqPrefix" ); |
291 | 290 | } |
292 | 291 | return $this->mUniqPrefix; |
293 | 292 | } |
— | — | @@ -323,7 +322,7 @@ |
324 | 323 | |
325 | 324 | $oldRevisionId = $this->mRevisionId; |
326 | 325 | $oldRevisionTimestamp = $this->mRevisionTimestamp; |
327 | | - if( $revid !== null ) { |
| 326 | + if ( $revid !== null ) { |
328 | 327 | $this->mRevisionId = $revid; |
329 | 328 | $this->mRevisionTimestamp = null; |
330 | 329 | } |
— | — | @@ -342,9 +341,9 @@ |
343 | 342 | '/(.) (?=\\?|:|;|!|%|\\302\\273)/' => '\\1 \\2', |
344 | 343 | # french spaces, Guillemet-right |
345 | 344 | '/(\\302\\253) /' => '\\1 ', |
346 | | - '/ (!\s*important)/' => ' \\1', #Beware of CSS magic word !important, bug #11874. |
| 345 | + '/ (!\s*important)/' => ' \\1', # Beware of CSS magic word !important, bug #11874. |
347 | 346 | ); |
348 | | - $text = preg_replace( array_keys($fixtags), array_values($fixtags), $text ); |
| 347 | + $text = preg_replace( array_keys( $fixtags ), array_values( $fixtags ), $text ); |
349 | 348 | |
350 | 349 | $text = $this->doBlockLevels( $text, $linestart ); |
351 | 350 | |
— | — | @@ -379,12 +378,11 @@ |
380 | 379 | $elements = array_keys( $this->mTransparentTagHooks ); |
381 | 380 | $text = self::extractTagsAndParams( $elements, $text, $matches, $uniq_prefix ); |
382 | 381 | |
383 | | - foreach( $matches as $marker => $data ) { |
| 382 | + foreach ( $matches as $marker => $data ) { |
384 | 383 | list( $element, $content, $params, $tag ) = $data; |
385 | 384 | $tagName = strtolower( $element ); |
386 | | - if( isset( $this->mTransparentTagHooks[$tagName] ) ) { |
387 | | - $output = call_user_func_array( $this->mTransparentTagHooks[$tagName], |
388 | | - array( $content, $params, $this ) ); |
| 385 | + if ( isset( $this->mTransparentTagHooks[$tagName] ) ) { |
| 386 | + $output = call_user_func_array( $this->mTransparentTagHooks[$tagName], array( $content, $params, $this ) ); |
389 | 387 | } else { |
390 | 388 | $output = $tag; |
391 | 389 | } |
— | — | @@ -481,7 +479,7 @@ |
482 | 480 | $this->setOutputType( self::OT_PREPROCESS ); |
483 | 481 | $this->mOptions = $options; |
484 | 482 | $this->setTitle( $title ); |
485 | | - if( $revid !== null ) { |
| 483 | + if ( $revid !== null ) { |
486 | 484 | $this->mRevisionId = $revid; |
487 | 485 | } |
488 | 486 | wfRunHooks( 'ParserBeforeStrip', array( &$this, &$text, &$this->mStripState ) ); |
— | — | @@ -517,7 +515,7 @@ |
518 | 516 | * @static |
519 | 517 | */ |
520 | 518 | function getRandomString() { |
521 | | - return dechex(mt_rand(0, 0x7fffffff)) . dechex(mt_rand(0, 0x7fffffff)); |
| 519 | + return dechex( mt_rand( 0, 0x7fffffff ) ) . dechex( mt_rand( 0, 0x7fffffff ) ); |
522 | 520 | } |
523 | 521 | |
524 | 522 | function &getTitle() { return $this->mTitle; } |
— | — | @@ -566,7 +564,7 @@ |
567 | 565 | * @public |
568 | 566 | * @static |
569 | 567 | */ |
570 | | - function extractTagsAndParams($elements, $text, &$matches, $uniq_prefix = ''){ |
| 568 | + function extractTagsAndParams( $elements, $text, &$matches, $uniq_prefix = '' ) { |
571 | 569 | static $n = 1; |
572 | 570 | $stripped = ''; |
573 | 571 | $matches = array(); |
— | — | @@ -577,10 +575,10 @@ |
578 | 576 | while ( $text != '' ) { |
579 | 577 | $p = preg_split( $start, $text, 2, PREG_SPLIT_DELIM_CAPTURE ); |
580 | 578 | $stripped .= $p[0]; |
581 | | - if( count( $p ) < 5 ) { |
| 579 | + if ( count( $p ) < 5 ) { |
582 | 580 | break; |
583 | 581 | } |
584 | | - if( count( $p ) > 5 ) { |
| 582 | + if ( count( $p ) > 5 ) { |
585 | 583 | // comment |
586 | 584 | $element = $p[4]; |
587 | 585 | $attributes = ''; |
— | — | @@ -594,7 +592,7 @@ |
595 | 593 | $inside = $p[4]; |
596 | 594 | } |
597 | 595 | |
598 | | - $marker = "$uniq_prefix-$element-" . sprintf('%08X', $n++) . self::MARKER_SUFFIX; |
| 596 | + $marker = "$uniq_prefix-$element-" . sprintf( '%08X', $n++ ) . self::MARKER_SUFFIX; |
599 | 597 | $stripped .= $marker; |
600 | 598 | |
601 | 599 | if ( $close === '/>' ) { |
— | — | @@ -603,14 +601,14 @@ |
604 | 602 | $text = $inside; |
605 | 603 | $tail = null; |
606 | 604 | } else { |
607 | | - if( $element === '!--' ) { |
| 605 | + if ( $element === '!--' ) { |
608 | 606 | $end = '/(-->)/'; |
609 | 607 | } else { |
610 | 608 | $end = "/(<\\/$element\\s*>)/i"; |
611 | 609 | } |
612 | 610 | $q = preg_split( $end, $inside, 2, PREG_SPLIT_DELIM_CAPTURE ); |
613 | 611 | $content = $q[0]; |
614 | | - if( count( $q ) < 3 ) { |
| 612 | + if ( count( $q ) < 3 ) { |
615 | 613 | # No end tag -- let it run out to the end of the text. |
616 | 614 | $tail = ''; |
617 | 615 | $text = ''; |
— | — | @@ -638,7 +636,7 @@ |
639 | 637 | /** |
640 | 638 | * @deprecated use replaceVariables |
641 | 639 | */ |
642 | | - function strip( $text, $state, $stripcomments = false , $dontstrip = array () ) { |
| 640 | + function strip( $text, $state, $stripcomments = false , $dontstrip = array() ) { |
643 | 641 | return $text; |
644 | 642 | } |
645 | 643 | |
— | — | @@ -698,22 +696,22 @@ |
699 | 697 | * |
700 | 698 | * @private |
701 | 699 | */ |
702 | | - function doTableStuff ( $text ) { |
| 700 | + function doTableStuff( $text ) { |
703 | 701 | wfProfileIn( __METHOD__ ); |
704 | 702 | |
705 | 703 | $lines = StringUtils::explode( "\n", $text ); |
706 | 704 | $out = ''; |
707 | | - $td_history = array (); // Is currently a td tag open? |
708 | | - $last_tag_history = array (); // Save history of last lag activated (td, th or caption) |
709 | | - $tr_history = array (); // Is currently a tr tag open? |
710 | | - $tr_attributes = array (); // history of tr attributes |
| 705 | + $td_history = array(); // Is currently a td tag open? |
| 706 | + $last_tag_history = array(); // Save history of last lag activated (td, th or caption) |
| 707 | + $tr_history = array(); // Is currently a tr tag open? |
| 708 | + $tr_attributes = array(); // history of tr attributes |
711 | 709 | $has_opened_tr = array(); // Did this table open a <tr> element? |
712 | 710 | $indent_level = 0; // indent level of the table |
713 | 711 | |
714 | 712 | foreach ( $lines as $outLine ) { |
715 | 713 | $line = trim( $outLine ); |
716 | 714 | |
717 | | - if( $line == '' ) { // empty line, go to next line |
| 715 | + if ( $line == '' ) { // empty line, go to next line |
718 | 716 | $out .= $outLine."\n"; |
719 | 717 | continue; |
720 | 718 | } |
— | — | @@ -725,7 +723,7 @@ |
726 | 724 | $indent_level = strlen( $matches[1] ); |
727 | 725 | |
728 | 726 | $attributes = $this->mStripState->unstripBoth( $matches[2] ); |
729 | | - $attributes = Sanitizer::fixTagAttributes ( $attributes , 'table' ); |
| 727 | + $attributes = Sanitizer::fixTagAttributes( $attributes , 'table' ); |
730 | 728 | |
731 | 729 | $outLine = str_repeat( '<dl><dd>' , $indent_level ) . "<table{$attributes}>"; |
732 | 730 | array_push( $td_history , false ); |
— | — | @@ -733,29 +731,29 @@ |
734 | 732 | array_push( $tr_history , false ); |
735 | 733 | array_push( $tr_attributes , '' ); |
736 | 734 | array_push( $has_opened_tr , false ); |
737 | | - } else if ( count ( $td_history ) == 0 ) { |
| 735 | + } elseif ( count( $td_history ) == 0 ) { |
738 | 736 | // Don't do any of the following |
739 | 737 | $out .= $outLine."\n"; |
740 | 738 | continue; |
741 | | - } else if ( substr ( $line , 0 , 2 ) === '|}' ) { |
| 739 | + } elseif ( substr( $line , 0 , 2 ) === '|}' ) { |
742 | 740 | // We are ending a table |
743 | | - $line = '</table>' . substr ( $line , 2 ); |
744 | | - $last_tag = array_pop ( $last_tag_history ); |
| 741 | + $line = '</table>' . substr( $line , 2 ); |
| 742 | + $last_tag = array_pop( $last_tag_history ); |
745 | 743 | |
746 | | - if ( !array_pop ( $has_opened_tr ) ) { |
| 744 | + if ( !array_pop( $has_opened_tr ) ) { |
747 | 745 | $line = "<tr><td></td></tr>{$line}"; |
748 | 746 | } |
749 | 747 | |
750 | | - if ( array_pop ( $tr_history ) ) { |
| 748 | + if ( array_pop( $tr_history ) ) { |
751 | 749 | $line = "</tr>{$line}"; |
752 | 750 | } |
753 | 751 | |
754 | | - if ( array_pop ( $td_history ) ) { |
| 752 | + if ( array_pop( $td_history ) ) { |
755 | 753 | $line = "</{$last_tag}>{$line}"; |
756 | 754 | } |
757 | | - array_pop ( $tr_attributes ); |
| 755 | + array_pop( $tr_attributes ); |
758 | 756 | $outLine = $line . str_repeat( '</dd></dl>' , $indent_level ); |
759 | | - } else if ( substr ( $line , 0 , 2 ) === '|-' ) { |
| 757 | + } elseif ( substr( $line , 0 , 2 ) === '|-' ) { |
760 | 758 | // Now we have a table row |
761 | 759 | $line = preg_replace( '#^\|-+#', '', $line ); |
762 | 760 | |
— | — | @@ -766,34 +764,33 @@ |
767 | 765 | array_push( $tr_attributes, $attributes ); |
768 | 766 | |
769 | 767 | $line = ''; |
770 | | - $last_tag = array_pop ( $last_tag_history ); |
771 | | - array_pop ( $has_opened_tr ); |
772 | | - array_push ( $has_opened_tr , true ); |
| 768 | + $last_tag = array_pop( $last_tag_history ); |
| 769 | + array_pop( $has_opened_tr ); |
| 770 | + array_push( $has_opened_tr , true ); |
773 | 771 | |
774 | | - if ( array_pop ( $tr_history ) ) { |
| 772 | + if ( array_pop( $tr_history ) ) { |
775 | 773 | $line = '</tr>'; |
776 | 774 | } |
777 | 775 | |
778 | | - if ( array_pop ( $td_history ) ) { |
| 776 | + if ( array_pop( $td_history ) ) { |
779 | 777 | $line = "</{$last_tag}>{$line}"; |
780 | 778 | } |
781 | 779 | |
782 | 780 | $outLine = $line; |
783 | | - array_push ( $tr_history , false ); |
784 | | - array_push ( $td_history , false ); |
785 | | - array_push ( $last_tag_history , '' ); |
786 | | - } |
787 | | - else if ( $first_character === '|' || $first_character === '!' || substr ( $line , 0 , 2 ) === '|+' ) { |
| 781 | + array_push( $tr_history , false ); |
| 782 | + array_push( $td_history , false ); |
| 783 | + array_push( $last_tag_history , '' ); |
| 784 | + } elseif ( $first_character === '|' || $first_character === '!' || substr( $line , 0 , 2 ) === '|+' ) { |
788 | 785 | // This might be cell elements, td, th or captions |
789 | | - if ( substr ( $line , 0 , 2 ) === '|+' ) { |
| 786 | + if ( substr( $line , 0 , 2 ) === '|+' ) { |
790 | 787 | $first_character = '+'; |
791 | | - $line = substr ( $line , 1 ); |
| 788 | + $line = substr( $line , 1 ); |
792 | 789 | } |
793 | 790 | |
794 | | - $line = substr ( $line , 1 ); |
| 791 | + $line = substr( $line , 1 ); |
795 | 792 | |
796 | 793 | if ( $first_character === '!' ) { |
797 | | - $line = str_replace ( '!!' , '||' , $line ); |
| 794 | + $line = str_replace( '!!' , '||' , $line ); |
798 | 795 | } |
799 | 796 | |
800 | 797 | // Split up multiple cells on the same line. |
— | — | @@ -805,71 +802,68 @@ |
806 | 803 | $outLine = ''; |
807 | 804 | |
808 | 805 | // Loop through each table cell |
809 | | - foreach ( $cells as $cell ) |
810 | | - { |
| 806 | + foreach ( $cells as $cell ) { |
811 | 807 | $previous = ''; |
812 | | - if ( $first_character !== '+' ) |
813 | | - { |
814 | | - $tr_after = array_pop ( $tr_attributes ); |
815 | | - if ( !array_pop ( $tr_history ) ) { |
| 808 | + if ( $first_character !== '+' ) { |
| 809 | + $tr_after = array_pop( $tr_attributes ); |
| 810 | + if ( !array_pop( $tr_history ) ) { |
816 | 811 | $previous = "<tr{$tr_after}>\n"; |
817 | 812 | } |
818 | | - array_push ( $tr_history , true ); |
819 | | - array_push ( $tr_attributes , '' ); |
820 | | - array_pop ( $has_opened_tr ); |
821 | | - array_push ( $has_opened_tr , true ); |
| 813 | + array_push( $tr_history , true ); |
| 814 | + array_push( $tr_attributes , '' ); |
| 815 | + array_pop( $has_opened_tr ); |
| 816 | + array_push( $has_opened_tr , true ); |
822 | 817 | } |
823 | 818 | |
824 | | - $last_tag = array_pop ( $last_tag_history ); |
| 819 | + $last_tag = array_pop( $last_tag_history ); |
825 | 820 | |
826 | | - if ( array_pop ( $td_history ) ) { |
| 821 | + if ( array_pop( $td_history ) ) { |
827 | 822 | $previous = "</{$last_tag}>{$previous}"; |
828 | 823 | } |
829 | 824 | |
830 | 825 | if ( $first_character === '|' ) { |
831 | 826 | $last_tag = 'td'; |
832 | | - } else if ( $first_character === '!' ) { |
| 827 | + } elseif ( $first_character === '!' ) { |
833 | 828 | $last_tag = 'th'; |
834 | | - } else if ( $first_character === '+' ) { |
| 829 | + } elseif ( $first_character === '+' ) { |
835 | 830 | $last_tag = 'caption'; |
836 | 831 | } else { |
837 | 832 | $last_tag = ''; |
838 | 833 | } |
839 | 834 | |
840 | | - array_push ( $last_tag_history , $last_tag ); |
| 835 | + array_push( $last_tag_history , $last_tag ); |
841 | 836 | |
842 | 837 | // A cell could contain both parameters and data |
843 | | - $cell_data = explode ( '|' , $cell , 2 ); |
| 838 | + $cell_data = explode( '|' , $cell , 2 ); |
844 | 839 | |
845 | 840 | // Bug 553: Note that a '|' inside an invalid link should not |
846 | 841 | // be mistaken as delimiting cell parameters |
847 | 842 | if ( strpos( $cell_data[0], '[[' ) !== false ) { |
848 | 843 | $cell = "{$previous}<{$last_tag}>{$cell}"; |
849 | | - } else if ( count ( $cell_data ) == 1 ) |
| 844 | + } elseif ( count( $cell_data ) == 1 ) { |
850 | 845 | $cell = "{$previous}<{$last_tag}>{$cell_data[0]}"; |
851 | | - else { |
| 846 | + } else { |
852 | 847 | $attributes = $this->mStripState->unstripBoth( $cell_data[0] ); |
853 | 848 | $attributes = Sanitizer::fixTagAttributes( $attributes , $last_tag ); |
854 | 849 | $cell = "{$previous}<{$last_tag}{$attributes}>{$cell_data[1]}"; |
855 | 850 | } |
856 | 851 | |
857 | 852 | $outLine .= $cell; |
858 | | - array_push ( $td_history , true ); |
| 853 | + array_push( $td_history , true ); |
859 | 854 | } |
860 | 855 | } |
861 | 856 | $out .= $outLine . "\n"; |
862 | 857 | } |
863 | 858 | |
864 | 859 | // Closing open td, tr && table |
865 | | - while ( count ( $td_history ) > 0 ) |
866 | | - { |
867 | | - if ( array_pop ( $td_history ) ) { |
| 860 | + while ( count( $td_history ) > 0 ) { |
| 861 | + if ( array_pop( $td_history ) ) { |
868 | 862 | $out .= "</td>\n"; |
869 | 863 | } |
870 | | - if ( array_pop ( $tr_history ) ) { |
| 864 | + if ( array_pop( $tr_history ) ) { |
871 | 865 | $out .= "</tr>\n"; |
872 | 866 | } |
873 | | - if ( !array_pop ( $has_opened_tr ) ) { |
| 867 | + if ( !array_pop( $has_opened_tr ) ) { |
874 | 868 | $out .= "<tr><td></td></tr>\n" ; |
875 | 869 | } |
876 | 870 | |
— | — | @@ -882,7 +876,7 @@ |
883 | 877 | } |
884 | 878 | |
885 | 879 | // special case: don't return empty table |
886 | | - if( $out === "<table>\n<tr><td></td></tr>\n</table>" ) { |
| 880 | + if ( $out === "<table>\n<tr><td></td></tr>\n</table>" ) { |
887 | 881 | $out = ''; |
888 | 882 | } |
889 | 883 | |
— | — | @@ -909,18 +903,18 @@ |
910 | 904 | } |
911 | 905 | |
912 | 906 | // if $frame is provided, then use $frame for replacing any variables |
913 | | - if ($frame) { |
| 907 | + if ( $frame ) { |
914 | 908 | // use frame depth to infer how include/noinclude tags should be handled |
915 | 909 | // depth=0 means this is the top-level document; otherwise it's an included document |
916 | | - if( !$frame->depth ) |
| 910 | + if ( !$frame->depth ) { |
917 | 911 | $flag = 0; |
918 | | - else |
| 912 | + } else { |
919 | 913 | $flag = Parser::PTD_FOR_INCLUSION; |
920 | 914 | $dom = $this->preprocessToDom( $text, $flag ); |
921 | 915 | $text = $frame->expand( $dom ); |
922 | | - } |
923 | | - // if $frame is not provided, then use old-style replaceVariables |
924 | | - else { |
| 916 | + } |
| 917 | + } else { |
| 918 | + // if $frame is not provided, then use old-style replaceVariables |
925 | 919 | $text = $this->replaceVariables( $text ); |
926 | 920 | } |
927 | 921 | |
— | — | @@ -938,7 +932,7 @@ |
939 | 933 | $text = $this->doDoubleUnderscore( $text ); |
940 | 934 | |
941 | 935 | $text = $this->doHeadings( $text ); |
942 | | - if( $this->mOptions->getUseDynamicDates() ) { |
| 936 | + if ( $this->mOptions->getUseDynamicDates() ) { |
943 | 937 | $df = DateFormatter::getInstance(); |
944 | 938 | $text = $df->reformat( $this->mOptions->getDateFormat(), $text ); |
945 | 939 | } |
— | — | @@ -948,7 +942,7 @@ |
949 | 943 | |
950 | 944 | # replaceInternalLinks may sometimes leave behind |
951 | 945 | # absolute URLs, which have to be masked to hide them from replaceExternalLinks |
952 | | - $text = str_replace($this->mUniqPrefix.'NOPARSE', '', $text); |
| 946 | + $text = str_replace( $this->mUniqPrefix.'NOPARSE', '', $text ); |
953 | 947 | |
954 | 948 | $text = $this->doMagicLinks( $text ); |
955 | 949 | $text = $this->formatHeadings( $text, $origText, $isMain ); |
— | — | @@ -1009,7 +1003,7 @@ |
1010 | 1004 | $id = $m[4]; |
1011 | 1005 | } else { |
1012 | 1006 | throw new MWException( __METHOD__.': unrecognised match type "' . |
1013 | | - substr($m[0], 0, 20 ) . '"' ); |
| 1007 | + substr( $m[0], 0, 20 ) . '"' ); |
1014 | 1008 | } |
1015 | 1009 | $url = wfMsg( $urlmsg, $id); |
1016 | 1010 | $sk = $this->mOptions->getSkin(); |
— | — | @@ -1048,9 +1042,9 @@ |
1049 | 1043 | # removeHTMLtags()) should not be included in |
1050 | 1044 | # URLs, per RFC 2396. |
1051 | 1045 | $m2 = array(); |
1052 | | - if (preg_match('/&(lt|gt);/', $url, $m2, PREG_OFFSET_CAPTURE)) { |
1053 | | - $trail = substr($url, $m2[0][1]) . $trail; |
1054 | | - $url = substr($url, 0, $m2[0][1]); |
| 1046 | + if ( preg_match( '/&(lt|gt);/', $url, $m2, PREG_OFFSET_CAPTURE ) ) { |
| 1047 | + $trail = substr( $url, $m2[0][1] ) . $trail; |
| 1048 | + $url = substr( $url, 0, $m2[0][1] ); |
1055 | 1049 | } |
1056 | 1050 | |
1057 | 1051 | # Move trailing punctuation to $trail |
— | — | @@ -1112,7 +1106,7 @@ |
1113 | 1107 | foreach ( $lines as $line ) { |
1114 | 1108 | $outtext .= $this->doQuotes( $line ) . "\n"; |
1115 | 1109 | } |
1116 | | - $outtext = substr($outtext, 0,-1); |
| 1110 | + $outtext = substr( $outtext, 0,-1 ); |
1117 | 1111 | wfProfileOut( __METHOD__ ); |
1118 | 1112 | return $outtext; |
1119 | 1113 | } |
— | — | @@ -1122,39 +1116,38 @@ |
1123 | 1117 | */ |
1124 | 1118 | public function doQuotes( $text ) { |
1125 | 1119 | $arr = preg_split( "/(''+)/", $text, -1, PREG_SPLIT_DELIM_CAPTURE ); |
1126 | | - if ( count( $arr ) == 1 ) |
| 1120 | + if ( count( $arr ) == 1 ) { |
1127 | 1121 | return $text; |
1128 | | - else |
1129 | | - { |
| 1122 | + } else { |
1130 | 1123 | # First, do some preliminary work. This may shift some apostrophes from |
1131 | 1124 | # being mark-up to being text. It also counts the number of occurrences |
1132 | 1125 | # of bold and italics mark-ups. |
1133 | 1126 | $i = 0; |
1134 | 1127 | $numbold = 0; |
1135 | 1128 | $numitalics = 0; |
1136 | | - foreach ( $arr as $r ) |
1137 | | - { |
1138 | | - if ( ( $i % 2 ) == 1 ) |
1139 | | - { |
| 1129 | + foreach ( $arr as $r ) { |
| 1130 | + if ( ( $i % 2 ) == 1 ) { |
1140 | 1131 | # If there are ever four apostrophes, assume the first is supposed to |
1141 | 1132 | # be text, and the remaining three constitute mark-up for bold text. |
1142 | | - if ( strlen( $arr[$i] ) == 4 ) |
1143 | | - { |
| 1133 | + if ( strlen( $arr[$i] ) == 4 ) { |
1144 | 1134 | $arr[$i-1] .= "'"; |
1145 | 1135 | $arr[$i] = "'''"; |
1146 | | - } |
1147 | | - # If there are more than 5 apostrophes in a row, assume they're all |
1148 | | - # text except for the last 5. |
1149 | | - else if ( strlen( $arr[$i] ) > 5 ) |
1150 | | - { |
| 1136 | + } elseif ( strlen( $arr[$i] ) > 5 ) { |
| 1137 | + # If there are more than 5 apostrophes in a row, assume they're all |
| 1138 | + # text except for the last 5. |
1151 | 1139 | $arr[$i-1] .= str_repeat( "'", strlen( $arr[$i] ) - 5 ); |
1152 | 1140 | $arr[$i] = "'''''"; |
1153 | 1141 | } |
1154 | 1142 | # Count the number of occurrences of bold and italics mark-ups. |
1155 | 1143 | # We are not counting sequences of five apostrophes. |
1156 | | - if ( strlen( $arr[$i] ) == 2 ) { $numitalics++; } |
1157 | | - else if ( strlen( $arr[$i] ) == 3 ) { $numbold++; } |
1158 | | - else if ( strlen( $arr[$i] ) == 5 ) { $numitalics++; $numbold++; } |
| 1144 | + if ( strlen( $arr[$i] ) == 2 ) { |
| 1145 | + $numitalics++; |
| 1146 | + } elseif ( strlen( $arr[$i] ) == 3 ) { |
| 1147 | + $numbold++; |
| 1148 | + } elseif ( strlen( $arr[$i] ) == 5 ) { |
| 1149 | + $numitalics++; |
| 1150 | + $numbold++; |
| 1151 | + } |
1159 | 1152 | } |
1160 | 1153 | $i++; |
1161 | 1154 | } |
— | — | @@ -1163,49 +1156,47 @@ |
1164 | 1157 | # that one of the bold ones was meant to be an apostrophe followed |
1165 | 1158 | # by italics. Which one we cannot know for certain, but it is more |
1166 | 1159 | # likely to be one that has a single-letter word before it. |
1167 | | - if ( ( $numbold % 2 == 1 ) && ( $numitalics % 2 == 1 ) ) |
1168 | | - { |
| 1160 | + if ( ( $numbold % 2 == 1 ) && ( $numitalics % 2 == 1 ) ) { |
1169 | 1161 | $i = 0; |
1170 | 1162 | $firstsingleletterword = -1; |
1171 | 1163 | $firstmultiletterword = -1; |
1172 | 1164 | $firstspace = -1; |
1173 | | - foreach ( $arr as $r ) |
1174 | | - { |
1175 | | - if ( ( $i % 2 == 1 ) and ( strlen( $r ) == 3 ) ) |
1176 | | - { |
1177 | | - $x1 = substr ($arr[$i-1], -1); |
1178 | | - $x2 = substr ($arr[$i-1], -2, 1); |
1179 | | - if ($x1 === ' ') { |
1180 | | - if ($firstspace == -1) $firstspace = $i; |
1181 | | - } else if ($x2 === ' ') { |
1182 | | - if ($firstsingleletterword == -1) $firstsingleletterword = $i; |
| 1165 | + foreach ( $arr as $r ) { |
| 1166 | + if ( ( $i % 2 == 1 ) and ( strlen( $r ) == 3 ) ) { |
| 1167 | + $x1 = substr( $arr[$i-1], -1 ); |
| 1168 | + $x2 = substr( $arr[$i-1], -2, 1 ); |
| 1169 | + if ( $x1 === ' ' ) { |
| 1170 | + if ( $firstspace == -1 ) { |
| 1171 | + $firstspace = $i; |
| 1172 | + } |
| 1173 | + } elseif ( $x2 === ' ') { |
| 1174 | + if ( $firstsingleletterword == -1 ) { |
| 1175 | + $firstsingleletterword = $i; |
| 1176 | + } |
1183 | 1177 | } else { |
1184 | | - if ($firstmultiletterword == -1) $firstmultiletterword = $i; |
| 1178 | + if ( $firstmultiletterword == -1 ) { |
| 1179 | + $firstmultiletterword = $i; |
| 1180 | + } |
1185 | 1181 | } |
1186 | 1182 | } |
1187 | 1183 | $i++; |
1188 | 1184 | } |
1189 | 1185 | |
1190 | 1186 | # If there is a single-letter word, use it! |
1191 | | - if ($firstsingleletterword > -1) |
1192 | | - { |
1193 | | - $arr [ $firstsingleletterword ] = "''"; |
1194 | | - $arr [ $firstsingleletterword-1 ] .= "'"; |
| 1187 | + if ( $firstsingleletterword > -1 ) { |
| 1188 | + $arr[$firstsingleletterword] = "''"; |
| 1189 | + $arr[$firstsingleletterword-1] .= "'"; |
| 1190 | + } elseif ( $firstmultiletterword > -1 ) { |
| 1191 | + # If not, but there's a multi-letter word, use that one. |
| 1192 | + $arr[$firstmultiletterword] = "''"; |
| 1193 | + $arr[$firstmultiletterword-1] .= "'"; |
| 1194 | + } elseif ( $firstspace > -1 ) { |
| 1195 | + # ... otherwise use the first one that has neither. |
| 1196 | + # (notice that it is possible for all three to be -1 if, for example, |
| 1197 | + # there is only one pentuple-apostrophe in the line) |
| 1198 | + $arr[$firstspace] = "''"; |
| 1199 | + $arr[$firstspace-1] .= "'"; |
1195 | 1200 | } |
1196 | | - # If not, but there's a multi-letter word, use that one. |
1197 | | - else if ($firstmultiletterword > -1) |
1198 | | - { |
1199 | | - $arr [ $firstmultiletterword ] = "''"; |
1200 | | - $arr [ $firstmultiletterword-1 ] .= "'"; |
1201 | | - } |
1202 | | - # ... otherwise use the first one that has neither. |
1203 | | - # (notice that it is possible for all three to be -1 if, for example, |
1204 | | - # there is only one pentuple-apostrophe in the line) |
1205 | | - else if ($firstspace > -1) |
1206 | | - { |
1207 | | - $arr [ $firstspace ] = "''"; |
1208 | | - $arr [ $firstspace-1 ] .= "'"; |
1209 | | - } |
1210 | 1201 | } |
1211 | 1202 | |
1212 | 1203 | # Now let's actually convert our apostrophic mush to HTML! |
— | — | @@ -1213,71 +1204,70 @@ |
1214 | 1205 | $buffer = ''; |
1215 | 1206 | $state = ''; |
1216 | 1207 | $i = 0; |
1217 | | - foreach ($arr as $r) |
1218 | | - { |
1219 | | - if (($i % 2) == 0) |
1220 | | - { |
1221 | | - if ($state === 'both') |
| 1208 | + foreach ( $arr as $r ) { |
| 1209 | + if ( ( $i % 2 ) == 0 ) { |
| 1210 | + if ( $state === 'both' ) { |
1222 | 1211 | $buffer .= $r; |
1223 | | - else |
| 1212 | + } else { |
1224 | 1213 | $output .= $r; |
1225 | | - } |
1226 | | - else |
1227 | | - { |
1228 | | - if (strlen ($r) == 2) |
1229 | | - { |
1230 | | - if ($state === 'i') |
1231 | | - { $output .= '</i>'; $state = ''; } |
1232 | | - else if ($state === 'bi') |
1233 | | - { $output .= '</i>'; $state = 'b'; } |
1234 | | - else if ($state === 'ib') |
1235 | | - { $output .= '</b></i><b>'; $state = 'b'; } |
1236 | | - else if ($state === 'both') |
1237 | | - { $output .= '<b><i>'.$buffer.'</i>'; $state = 'b'; } |
1238 | | - else # $state can be 'b' or '' |
1239 | | - { $output .= '<i>'; $state .= 'i'; } |
1240 | 1214 | } |
1241 | | - else if (strlen ($r) == 3) |
1242 | | - { |
1243 | | - if ($state === 'b') |
1244 | | - { $output .= '</b>'; $state = ''; } |
1245 | | - else if ($state === 'bi') |
1246 | | - { $output .= '</i></b><i>'; $state = 'i'; } |
1247 | | - else if ($state === 'ib') |
1248 | | - { $output .= '</b>'; $state = 'i'; } |
1249 | | - else if ($state === 'both') |
1250 | | - { $output .= '<i><b>'.$buffer.'</b>'; $state = 'i'; } |
1251 | | - else # $state can be 'i' or '' |
1252 | | - { $output .= '<b>'; $state .= 'b'; } |
| 1215 | + } else { |
| 1216 | + if ( strlen( $r ) == 2 ) { |
| 1217 | + if ( $state === 'i' ) { |
| 1218 | + $output .= '</i>'; $state = ''; |
| 1219 | + } elseif ( $state === 'bi' ) { |
| 1220 | + $output .= '</i>'; $state = 'b'; |
| 1221 | + } elseif ( $state === 'ib' ) { |
| 1222 | + $output .= '</b></i><b>'; $state = 'b'; |
| 1223 | + } elseif ( $state === 'both' ) { |
| 1224 | + $output .= '<b><i>'.$buffer.'</i>'; $state = 'b'; |
| 1225 | + } else { # $state can be 'b' or '' |
| 1226 | + $output .= '<i>'; $state .= 'i'; |
| 1227 | + } |
| 1228 | + } elseif ( strlen( $r ) == 3 ) { |
| 1229 | + if ( $state === 'b' ) { |
| 1230 | + $output .= '</b>'; $state = ''; |
| 1231 | + } elseif ( $state === 'bi' ) { |
| 1232 | + $output .= '</i></b><i>'; $state = 'i'; |
| 1233 | + } elseif ( $state === 'ib' ) { |
| 1234 | + $output .= '</b>'; $state = 'i'; |
| 1235 | + } elseif ( $state === 'both' ) { |
| 1236 | + $output .= '<i><b>'.$buffer.'</b>'; $state = 'i'; |
| 1237 | + } else { # $state can be 'i' or '' |
| 1238 | + $output .= '<b>'; $state .= 'b'; |
| 1239 | + } |
| 1240 | + } elseif ( strlen( $r ) == 5 ) { |
| 1241 | + if ( $state === 'b' ) { |
| 1242 | + $output .= '</b><i>'; $state = 'i'; |
| 1243 | + } elseif ( $state === 'i' ) { |
| 1244 | + $output .= '</i><b>'; $state = 'b'; |
| 1245 | + } elseif ( $state === 'bi' ) { |
| 1246 | + $output .= '</i></b>'; $state = ''; |
| 1247 | + } elseif ( $state === 'ib' ) { |
| 1248 | + $output .= '</b></i>'; $state = ''; |
| 1249 | + } elseif ( $state === 'both' ) { |
| 1250 | + $output .= '<i><b>'.$buffer.'</b></i>'; $state = ''; |
| 1251 | + } else { # ($state == '') |
| 1252 | + $buffer = ''; $state = 'both'; |
| 1253 | + } |
1253 | 1254 | } |
1254 | | - else if (strlen ($r) == 5) |
1255 | | - { |
1256 | | - if ($state === 'b') |
1257 | | - { $output .= '</b><i>'; $state = 'i'; } |
1258 | | - else if ($state === 'i') |
1259 | | - { $output .= '</i><b>'; $state = 'b'; } |
1260 | | - else if ($state === 'bi') |
1261 | | - { $output .= '</i></b>'; $state = ''; } |
1262 | | - else if ($state === 'ib') |
1263 | | - { $output .= '</b></i>'; $state = ''; } |
1264 | | - else if ($state === 'both') |
1265 | | - { $output .= '<i><b>'.$buffer.'</b></i>'; $state = ''; } |
1266 | | - else # ($state == '') |
1267 | | - { $buffer = ''; $state = 'both'; } |
1268 | | - } |
1269 | 1255 | } |
1270 | 1256 | $i++; |
1271 | 1257 | } |
1272 | 1258 | # Now close all remaining tags. Notice that the order is important. |
1273 | | - if ($state === 'b' || $state === 'ib') |
| 1259 | + if ( $state === 'b' || $state === 'ib' ) { |
1274 | 1260 | $output .= '</b>'; |
1275 | | - if ($state === 'i' || $state === 'bi' || $state === 'ib') |
| 1261 | + } |
| 1262 | + if ( $state === 'i' || $state === 'bi' || $state === 'ib' ) { |
1276 | 1263 | $output .= '</i>'; |
1277 | | - if ($state === 'bi') |
| 1264 | + } |
| 1265 | + if ( $state === 'bi' ) { |
1278 | 1266 | $output .= '</b>'; |
| 1267 | + } |
1279 | 1268 | # There might be lonely ''''', so make sure we have a buffer |
1280 | | - if ($state === 'both' && $buffer) |
| 1269 | + if ( $state === 'both' && $buffer ) { |
1281 | 1270 | $output .= '<b><i>'.$buffer.'</i></b>'; |
| 1271 | + } |
1282 | 1272 | return $output; |
1283 | 1273 | } |
1284 | 1274 | } |
— | — | @@ -1310,9 +1300,9 @@ |
1311 | 1301 | # removeHTMLtags()) should not be included in |
1312 | 1302 | # URLs, per RFC 2396. |
1313 | 1303 | $m2 = array(); |
1314 | | - if (preg_match('/&(lt|gt);/', $url, $m2, PREG_OFFSET_CAPTURE)) { |
1315 | | - $text = substr($url, $m2[0][1]) . ' ' . $text; |
1316 | | - $url = substr($url, 0, $m2[0][1]); |
| 1304 | + if ( preg_match( '/&(lt|gt);/', $url, $m2, PREG_OFFSET_CAPTURE ) ) { |
| 1305 | + $text = substr( $url, $m2[0][1] ) . ' ' . $text; |
| 1306 | + $url = substr( $url, 0, $m2[0][1] ); |
1317 | 1307 | } |
1318 | 1308 | |
1319 | 1309 | # If the link text is an image URL, replace it with an <img> tag |
— | — | @@ -1325,12 +1315,12 @@ |
1326 | 1316 | $dtrail = ''; |
1327 | 1317 | |
1328 | 1318 | # Set linktype for CSS - if URL==text, link is essentially free |
1329 | | - $linktype = ($text === $url) ? 'free' : 'text'; |
| 1319 | + $linktype = ( $text === $url ) ? 'free' : 'text'; |
1330 | 1320 | |
1331 | 1321 | # No link text, e.g. [http://domain.tld/some.link] |
1332 | 1322 | if ( $text == '' ) { |
1333 | 1323 | # Autonumber if allowed. See bug #5918 |
1334 | | - if ( strpos( wfUrlProtocols(), substr($protocol, 0, strpos($protocol, ':')) ) !== false ) { |
| 1324 | + if ( strpos( wfUrlProtocols(), substr( $protocol, 0, strpos( $protocol, ':' ) ) ) !== false ) { |
1335 | 1325 | $langObj = $this->getFunctionLang(); |
1336 | 1326 | $text = '[' . $langObj->formatNum( ++$this->mAutonumber ) . ']'; |
1337 | 1327 | $linktype = 'autonumber'; |
— | — | @@ -1345,7 +1335,7 @@ |
1346 | 1336 | list( $dtrail, $trail ) = Linker::splitTrail( $trail ); |
1347 | 1337 | } |
1348 | 1338 | |
1349 | | - $text = $wgContLang->markNoConversion($text); |
| 1339 | + $text = $wgContLang->markNoConversion( $text ); |
1350 | 1340 | |
1351 | 1341 | $url = Sanitizer::cleanUrl( $url ); |
1352 | 1342 | |
— | — | @@ -1381,7 +1371,7 @@ |
1382 | 1372 | $attribs = array(); |
1383 | 1373 | global $wgNoFollowLinks, $wgNoFollowNsExceptions; |
1384 | 1374 | $ns = $this->mTitle->getNamespace(); |
1385 | | - if( $wgNoFollowLinks && !in_array($ns, $wgNoFollowNsExceptions) ) { |
| 1375 | + if ( $wgNoFollowLinks && !in_array( $ns, $wgNoFollowNsExceptions ) ) { |
1386 | 1376 | $attribs['rel'] = 'nofollow'; |
1387 | 1377 | |
1388 | 1378 | global $wgNoFollowDomainExceptions; |
— | — | @@ -1389,8 +1379,7 @@ |
1390 | 1380 | $bits = wfParseUrl( $url ); |
1391 | 1381 | if ( is_array( $bits ) && isset( $bits['host'] ) ) { |
1392 | 1382 | foreach ( $wgNoFollowDomainExceptions as $domain ) { |
1393 | | - if( substr( $bits['host'], -strlen( $domain ) ) |
1394 | | - == $domain ) { |
| 1383 | + if ( substr( $bits['host'], -strlen( $domain ) ) == $domain ) { |
1395 | 1384 | unset( $attribs['rel'] ); |
1396 | 1385 | break; |
1397 | 1386 | } |
— | — | @@ -1447,19 +1436,19 @@ |
1448 | 1437 | function maybeMakeExternalImage( $url ) { |
1449 | 1438 | $sk = $this->mOptions->getSkin(); |
1450 | 1439 | $imagesfrom = $this->mOptions->getAllowExternalImagesFrom(); |
1451 | | - $imagesexception = !empty($imagesfrom); |
| 1440 | + $imagesexception = !empty( $imagesfrom ); |
1452 | 1441 | $text = false; |
1453 | 1442 | # $imagesfrom could be either a single string or an array of strings, parse out the latter |
1454 | | - if( $imagesexception && is_array( $imagesfrom ) ) { |
| 1443 | + if ( $imagesexception && is_array( $imagesfrom ) ) { |
1455 | 1444 | $imagematch = false; |
1456 | | - foreach( $imagesfrom as $match ) { |
1457 | | - if( strpos( $url, $match ) === 0 ) { |
| 1445 | + foreach ( $imagesfrom as $match ) { |
| 1446 | + if ( strpos( $url, $match ) === 0 ) { |
1458 | 1447 | $imagematch = true; |
1459 | 1448 | break; |
1460 | 1449 | } |
1461 | 1450 | } |
1462 | | - } elseif( $imagesexception ) { |
1463 | | - $imagematch = (strpos( $url, $imagesfrom ) === 0); |
| 1451 | + } elseif ( $imagesexception ) { |
| 1452 | + $imagematch = ( strpos( $url, $imagesfrom ) === 0 ); |
1464 | 1453 | } else { |
1465 | 1454 | $imagematch = false; |
1466 | 1455 | } |
— | — | @@ -1470,14 +1459,15 @@ |
1471 | 1460 | $text = $sk->makeExternalImage( $url ); |
1472 | 1461 | } |
1473 | 1462 | } |
1474 | | - if( !$text && $this->mOptions->getEnableImageWhitelist() |
| 1463 | + if ( !$text && $this->mOptions->getEnableImageWhitelist() |
1475 | 1464 | && preg_match( self::EXT_IMAGE_REGEX, $url ) ) { |
1476 | 1465 | $whitelist = explode( "\n", wfMsgForContent( 'external_image_whitelist' ) ); |
1477 | | - foreach( $whitelist as $entry ) { |
| 1466 | + foreach ( $whitelist as $entry ) { |
1478 | 1467 | # Sanitize the regex fragment, make it case-insensitive, ignore blank entries/comments |
1479 | | - if( strpos( $entry, '#' ) === 0 || $entry === '' ) |
| 1468 | + if ( strpos( $entry, '#' ) === 0 || $entry === '' ) { |
1480 | 1469 | continue; |
1481 | | - if( preg_match( '/' . str_replace( '/', '\\/', $entry ) . '/i', $url ) ) { |
| 1470 | + } |
| 1471 | + if ( preg_match( '/' . str_replace( '/', '\\/', $entry ) . '/i', $url ) ) { |
1482 | 1472 | # Image matches a whitelist entry |
1483 | 1473 | $text = $sk->makeExternalImage( $url ); |
1484 | 1474 | break; |
— | — | @@ -1523,9 +1513,9 @@ |
1524 | 1514 | $sk = $this->mOptions->getSkin(); |
1525 | 1515 | $holders = new LinkHolderArray( $this ); |
1526 | 1516 | |
1527 | | - #split the entire text string on occurences of [[ |
| 1517 | + # split the entire text string on occurences of [[ |
1528 | 1518 | $a = StringUtils::explode( '[[', ' ' . $s ); |
1529 | | - #get the first element (all text up to first [[), and remove the space we added |
| 1519 | + # get the first element (all text up to first [[), and remove the space we added |
1530 | 1520 | $s = $a->current(); |
1531 | 1521 | $a->next(); |
1532 | 1522 | $line = $a->current(); # Workaround for broken ArrayIterator::next() that returns "void" |
— | — | @@ -1539,7 +1529,7 @@ |
1540 | 1530 | $e2 = wfMsgForContent( 'linkprefix' ); |
1541 | 1531 | } |
1542 | 1532 | |
1543 | | - if( is_null( $this->mTitle ) ) { |
| 1533 | + if ( is_null( $this->mTitle ) ) { |
1544 | 1534 | wfProfileOut( __METHOD__.'-setup' ); |
1545 | 1535 | wfProfileOut( __METHOD__ ); |
1546 | 1536 | throw new MWException( __METHOD__.": \$this->mTitle is null\n" ); |
— | — | @@ -1557,10 +1547,10 @@ |
1558 | 1548 | $prefix = ''; |
1559 | 1549 | } |
1560 | 1550 | |
1561 | | - if($wgContLang->hasVariants()) { |
1562 | | - $selflink = $wgContLang->convertLinkToAllVariants($this->mTitle->getPrefixedText()); |
| 1551 | + if ( $wgContLang->hasVariants() ) { |
| 1552 | + $selflink = $wgContLang->convertLinkToAllVariants( $this->mTitle->getPrefixedText() ); |
1563 | 1553 | } else { |
1564 | | - $selflink = array($this->mTitle->getPrefixedText()); |
| 1554 | + $selflink = array( $this->mTitle->getPrefixedText() ); |
1565 | 1555 | } |
1566 | 1556 | $useSubpages = $this->areSubpagesAllowed(); |
1567 | 1557 | wfProfileOut( __METHOD__.'-setup' ); |
— | — | @@ -1584,7 +1574,7 @@ |
1585 | 1575 | $prefix=''; |
1586 | 1576 | } |
1587 | 1577 | # first link |
1588 | | - if($first_prefix) { |
| 1578 | + if ( $first_prefix ) { |
1589 | 1579 | $prefix = $first_prefix; |
1590 | 1580 | $first_prefix = false; |
1591 | 1581 | } |
— | — | @@ -1600,29 +1590,29 @@ |
1601 | 1591 | # [[Image:Foo.jpg|[http://example.com desc]]] <- having three ] in a row fucks up, |
1602 | 1592 | # the real problem is with the $e1 regex |
1603 | 1593 | # See bug 1300. |
1604 | | - # |
| 1594 | + # |
1605 | 1595 | # Still some problems for cases where the ] is meant to be outside punctuation, |
1606 | 1596 | # and no image is in sight. See bug 2095. |
1607 | | - # |
1608 | | - if( $text !== '' && |
| 1597 | + # |
| 1598 | + if ( $text !== '' && |
1609 | 1599 | substr( $m[3], 0, 1 ) === ']' && |
1610 | | - strpos($text, '[') !== false |
| 1600 | + strpos( $text, '[' ) !== false |
1611 | 1601 | ) |
1612 | 1602 | { |
1613 | 1603 | $text .= ']'; # so that replaceExternalLinks($text) works later |
1614 | 1604 | $m[3] = substr( $m[3], 1 ); |
1615 | 1605 | } |
1616 | 1606 | # fix up urlencoded title texts |
1617 | | - if( strpos( $m[1], '%' ) !== false ) { |
| 1607 | + if ( strpos( $m[1], '%' ) !== false ) { |
1618 | 1608 | # Should anchors '#' also be rejected? |
1619 | | - $m[1] = str_replace( array('<', '>'), array('<', '>'), urldecode($m[1]) ); |
| 1609 | + $m[1] = str_replace( array('<', '>'), array('<', '>'), urldecode( $m[1] ) ); |
1620 | 1610 | } |
1621 | 1611 | $trail = $m[3]; |
1622 | | - } elseif( preg_match($e1_img, $line, $m) ) { # Invalid, but might be an image with a link in its caption |
| 1612 | + } elseif ( preg_match( $e1_img, $line, $m ) ) { # Invalid, but might be an image with a link in its caption |
1623 | 1613 | $might_be_img = true; |
1624 | 1614 | $text = $m[2]; |
1625 | 1615 | if ( strpos( $m[1], '%' ) !== false ) { |
1626 | | - $m[1] = urldecode($m[1]); |
| 1616 | + $m[1] = urldecode( $m[1] ); |
1627 | 1617 | } |
1628 | 1618 | $trail = ""; |
1629 | 1619 | } else { # Invalid form; output directly |
— | — | @@ -1649,8 +1639,8 @@ |
1650 | 1640 | $link = $m[1]; |
1651 | 1641 | } |
1652 | 1642 | |
1653 | | - $noforce = (substr( $m[1], 0, 1 ) !== ':'); |
1654 | | - if (!$noforce) { |
| 1643 | + $noforce = ( substr( $m[1], 0, 1 ) !== ':' ); |
| 1644 | + if ( !$noforce ) { |
1655 | 1645 | # Strip off leading ':' |
1656 | 1646 | $link = substr( $link, 1 ); |
1657 | 1647 | } |
— | — | @@ -1670,10 +1660,10 @@ |
1671 | 1661 | |
1672 | 1662 | if ( $might_be_img ) { # if this is actually an invalid link |
1673 | 1663 | wfProfileIn( __METHOD__."-might_be_img" ); |
1674 | | - if ( $ns == NS_FILE && $noforce ) { #but might be an image |
| 1664 | + if ( $ns == NS_FILE && $noforce ) { # but might be an image |
1675 | 1665 | $found = false; |
1676 | 1666 | while ( true ) { |
1677 | | - #look at the next 'line' to see if we can close it there |
| 1667 | + # look at the next 'line' to see if we can close it there |
1678 | 1668 | $a->next(); |
1679 | 1669 | $next_line = $a->current(); |
1680 | 1670 | if ( $next_line === false || $next_line === null ) { |
— | — | @@ -1687,24 +1677,24 @@ |
1688 | 1678 | $trail = $m[2]; |
1689 | 1679 | break; |
1690 | 1680 | } elseif ( count( $m ) == 2 ) { |
1691 | | - #if there's exactly one ]] that's fine, we'll keep looking |
| 1681 | + # if there's exactly one ]] that's fine, we'll keep looking |
1692 | 1682 | $text .= "[[{$m[0]}]]{$m[1]}"; |
1693 | 1683 | } else { |
1694 | | - #if $next_line is invalid too, we need look no further |
| 1684 | + # if $next_line is invalid too, we need look no further |
1695 | 1685 | $text .= '[[' . $next_line; |
1696 | 1686 | break; |
1697 | 1687 | } |
1698 | 1688 | } |
1699 | 1689 | if ( !$found ) { |
1700 | 1690 | # we couldn't find the end of this imageLink, so output it raw |
1701 | | - #but don't ignore what might be perfectly normal links in the text we've examined |
| 1691 | + # but don't ignore what might be perfectly normal links in the text we've examined |
1702 | 1692 | $holders->merge( $this->replaceInternalLinks2( $text ) ); |
1703 | 1693 | $s .= "{$prefix}[[$link|$text"; |
1704 | 1694 | # note: no $trail, because without an end, there *is* no trail |
1705 | 1695 | wfProfileOut( __METHOD__."-might_be_img" ); |
1706 | 1696 | continue; |
1707 | 1697 | } |
1708 | | - } else { #it's not an image, so output it raw |
| 1698 | + } else { # it's not an image, so output it raw |
1709 | 1699 | $s .= "{$prefix}[[$link|$text"; |
1710 | 1700 | # note: no $trail, because without an end, there *is* no trail |
1711 | 1701 | wfProfileOut( __METHOD__."-might_be_img" ); |
— | — | @@ -1714,7 +1704,9 @@ |
1715 | 1705 | } |
1716 | 1706 | |
1717 | 1707 | $wasblank = ( $text == '' ); |
1718 | | - if ( $wasblank ) $text = $link; |
| 1708 | + if ( $wasblank ) { |
| 1709 | + $text = $link; |
| 1710 | + } |
1719 | 1711 | |
1720 | 1712 | # Link not escaped by : , create the various objects |
1721 | 1713 | if ( $noforce ) { |
— | — | @@ -1723,8 +1715,8 @@ |
1724 | 1716 | wfProfileIn( __METHOD__."-interwiki" ); |
1725 | 1717 | if ( $iw && $this->mOptions->getInterwikiMagic() && $nottalk && $wgContLang->getLanguageName( $iw ) ) { |
1726 | 1718 | $this->mOutput->addLanguageLink( $nt->getFullText() ); |
1727 | | - $s = rtrim($s . $prefix); |
1728 | | - $s .= trim($trail, "\n") == '' ? '': $prefix . $trail; |
| 1719 | + $s = rtrim( $s . $prefix ); |
| 1720 | + $s .= trim( $trail, "\n" ) == '' ? '': $prefix . $trail; |
1729 | 1721 | wfProfileOut( __METHOD__."-interwiki" ); |
1730 | 1722 | continue; |
1731 | 1723 | } |
— | — | @@ -1743,7 +1735,7 @@ |
1744 | 1736 | # recursively parse links inside the image caption |
1745 | 1737 | # actually, this will parse them in any other parameters, too, |
1746 | 1738 | # but it might be hard to fix that, and it doesn't matter ATM |
1747 | | - $text = $this->replaceExternalLinks($text); |
| 1739 | + $text = $this->replaceExternalLinks( $text ); |
1748 | 1740 | $holders->merge( $this->replaceInternalLinks2( $text ) ); |
1749 | 1741 | } |
1750 | 1742 | # cloak any absolute URLs inside the image markup, so replaceExternalLinks() won't touch them |
— | — | @@ -1759,7 +1751,7 @@ |
1760 | 1752 | |
1761 | 1753 | if ( $ns == NS_CATEGORY ) { |
1762 | 1754 | wfProfileIn( __METHOD__."-category" ); |
1763 | | - $s = rtrim($s . "\n"); # bug 87 |
| 1755 | + $s = rtrim( $s . "\n" ); # bug 87 |
1764 | 1756 | |
1765 | 1757 | if ( $wasblank ) { |
1766 | 1758 | $sortkey = $this->getDefaultSort(); |
— | — | @@ -1775,7 +1767,7 @@ |
1776 | 1768 | * Strip the whitespace Category links produce, see bug 87 |
1777 | 1769 | * @todo We might want to use trim($tmp, "\n") here. |
1778 | 1770 | */ |
1779 | | - $s .= trim($prefix . $trail, "\n") == '' ? '': $prefix . $trail; |
| 1771 | + $s .= trim( $prefix . $trail, "\n" ) == '' ? '': $prefix . $trail; |
1780 | 1772 | |
1781 | 1773 | wfProfileOut( __METHOD__."-category" ); |
1782 | 1774 | continue; |
— | — | @@ -1783,8 +1775,8 @@ |
1784 | 1776 | } |
1785 | 1777 | |
1786 | 1778 | # Self-link checking |
1787 | | - if( $nt->getFragment() === '' && $ns != NS_SPECIAL ) { |
1788 | | - if( in_array( $nt->getPrefixedText(), $selflink, true ) ) { |
| 1779 | + if ( $nt->getFragment() === '' && $ns != NS_SPECIAL ) { |
| 1780 | + if ( in_array( $nt->getPrefixedText(), $selflink, true ) ) { |
1789 | 1781 | $s .= $prefix . $sk->makeSelfLinkObj( $nt, $text, '', $trail ); |
1790 | 1782 | continue; |
1791 | 1783 | } |
— | — | @@ -1792,7 +1784,7 @@ |
1793 | 1785 | |
1794 | 1786 | # NS_MEDIA is a pseudo-namespace for linking directly to a file |
1795 | 1787 | # FIXME: Should do batch file existence checks, see comment below |
1796 | | - if( $ns == NS_MEDIA ) { |
| 1788 | + if ( $ns == NS_MEDIA ) { |
1797 | 1789 | wfProfileIn( __METHOD__."-media" ); |
1798 | 1790 | # Give extensions a chance to select the file revision for us |
1799 | 1791 | $skip = $time = false; |
— | — | @@ -1812,10 +1804,10 @@ |
1813 | 1805 | wfProfileIn( __METHOD__."-always_known" ); |
1814 | 1806 | # Some titles, such as valid special pages or files in foreign repos, should |
1815 | 1807 | # be shown as bluelinks even though they're not included in the page table |
1816 | | - # |
| 1808 | + # |
1817 | 1809 | # FIXME: isAlwaysKnown() can be expensive for file links; we should really do |
1818 | 1810 | # batch file existence checks for NS_FILE and NS_MEDIA |
1819 | | - if( $iw == '' && $nt->isAlwaysKnown() ) { |
| 1811 | + if ( $iw == '' && $nt->isAlwaysKnown() ) { |
1820 | 1812 | $this->mOutput->addLink( $nt ); |
1821 | 1813 | $s .= $this->makeKnownLinkHolder( $nt, $text, '', $trail, $prefix ); |
1822 | 1814 | } else { |
— | — | @@ -1893,7 +1885,7 @@ |
1894 | 1886 | * @return string the full name of the link |
1895 | 1887 | * @private |
1896 | 1888 | */ |
1897 | | - function maybeDoSubpageLink($target, &$text) { |
| 1889 | + function maybeDoSubpageLink( $target, &$text ) { |
1898 | 1890 | return Linker::normalizeSubpageLink( $this->mTitle, $target, $text ); |
1899 | 1891 | } |
1900 | 1892 | |
— | — | @@ -1910,42 +1902,57 @@ |
1911 | 1903 | $this->mLastSection = ''; |
1912 | 1904 | return $result; |
1913 | 1905 | } |
1914 | | - # getCommon() returns the length of the longest common substring |
1915 | | - # of both arguments, starting at the beginning of both. |
1916 | | - # |
1917 | | - /* private */ function getCommon( $st1, $st2 ) { |
| 1906 | + /** |
| 1907 | + * getCommon() returns the length of the longest common substring |
| 1908 | + * of both arguments, starting at the beginning of both. |
| 1909 | + * @private |
| 1910 | + */ |
| 1911 | + function getCommon( $st1, $st2 ) { |
1918 | 1912 | $fl = strlen( $st1 ); |
1919 | 1913 | $shorter = strlen( $st2 ); |
1920 | | - if ( $fl < $shorter ) { $shorter = $fl; } |
| 1914 | + if ( $fl < $shorter ) { |
| 1915 | + $shorter = $fl; |
| 1916 | + } |
1921 | 1917 | |
1922 | 1918 | for ( $i = 0; $i < $shorter; ++$i ) { |
1923 | | - if ( $st1{$i} != $st2{$i} ) { break; } |
| 1919 | + if ( $st1{$i} != $st2{$i} ) { |
| 1920 | + break; |
| 1921 | + } |
1924 | 1922 | } |
1925 | 1923 | return $i; |
1926 | 1924 | } |
1927 | | - # These next three functions open, continue, and close the list |
1928 | | - # element appropriate to the prefix character passed into them. |
1929 | | - # |
1930 | | - /* private */ function openList( $char ) { |
| 1925 | + /** |
| 1926 | + * These next three functions open, continue, and close the list |
| 1927 | + * element appropriate to the prefix character passed into them. |
| 1928 | + * @private |
| 1929 | + */ |
| 1930 | + function openList( $char ) { |
1931 | 1931 | $result = $this->closeParagraph(); |
1932 | 1932 | |
1933 | | - if ( '*' === $char ) { $result .= '<ul><li>'; } |
1934 | | - elseif ( '#' === $char ) { $result .= '<ol><li>'; } |
1935 | | - elseif ( ':' === $char ) { $result .= '<dl><dd>'; } |
1936 | | - elseif ( ';' === $char ) { |
| 1933 | + if ( '*' === $char ) { |
| 1934 | + $result .= '<ul><li>'; |
| 1935 | + } elseif ( '#' === $char ) { |
| 1936 | + $result .= '<ol><li>'; |
| 1937 | + } elseif ( ':' === $char ) { |
| 1938 | + $result .= '<dl><dd>'; |
| 1939 | + } elseif ( ';' === $char ) { |
1937 | 1940 | $result .= '<dl><dt>'; |
1938 | 1941 | $this->mDTopen = true; |
| 1942 | + } else { |
| 1943 | + $result = '<!-- ERR 1 -->'; |
1939 | 1944 | } |
1940 | | - else { $result = '<!-- ERR 1 -->'; } |
1941 | 1945 | |
1942 | 1946 | return $result; |
1943 | 1947 | } |
1944 | 1948 | |
1945 | 1949 | /* private */ function nextItem( $char ) { |
1946 | | - if ( '*' === $char || '#' === $char ) { return '</li><li>'; } |
1947 | | - elseif ( ':' === $char || ';' === $char ) { |
| 1950 | + if ( '*' === $char || '#' === $char ) { |
| 1951 | + return '</li><li>'; |
| 1952 | + } elseif ( ':' === $char || ';' === $char ) { |
1948 | 1953 | $close = '</dd>'; |
1949 | | - if ( $this->mDTopen ) { $close = '</dt>'; } |
| 1954 | + if ( $this->mDTopen ) { |
| 1955 | + $close = '</dt>'; |
| 1956 | + } |
1950 | 1957 | if ( ';' === $char ) { |
1951 | 1958 | $this->mDTopen = true; |
1952 | 1959 | return $close . '<dt>'; |
— | — | @@ -1958,17 +1965,20 @@ |
1959 | 1966 | } |
1960 | 1967 | |
1961 | 1968 | /* private */ function closeList( $char ) { |
1962 | | - if ( '*' === $char ) { $text = '</li></ul>'; } |
1963 | | - elseif ( '#' === $char ) { $text = '</li></ol>'; } |
1964 | | - elseif ( ':' === $char ) { |
| 1969 | + if ( '*' === $char ) { |
| 1970 | + $text = '</li></ul>'; |
| 1971 | + } elseif ( '#' === $char ) { |
| 1972 | + $text = '</li></ol>'; |
| 1973 | + } elseif ( ':' === $char ) { |
1965 | 1974 | if ( $this->mDTopen ) { |
1966 | 1975 | $this->mDTopen = false; |
1967 | 1976 | $text = '</dt></dl>'; |
1968 | 1977 | } else { |
1969 | 1978 | $text = '</dd></dl>'; |
1970 | 1979 | } |
| 1980 | + } else { |
| 1981 | + return '<!-- ERR 3 -->'; |
1971 | 1982 | } |
1972 | | - else { return '<!-- ERR 3 -->'; } |
1973 | 1983 | return $text."\n"; |
1974 | 1984 | } |
1975 | 1985 | /**#@-*/ |
— | — | @@ -1986,7 +1996,7 @@ |
1987 | 1997 | # Parsing through the text line by line. The main thing |
1988 | 1998 | # happening here is handling of block-level elements p, pre, |
1989 | 1999 | # and making lists from lines starting with * # : etc. |
1990 | | - # |
| 2000 | + # |
1991 | 2001 | $textLines = StringUtils::explode( "\n", $text ); |
1992 | 2002 | |
1993 | 2003 | $lastPrefix = $output = ''; |
— | — | @@ -2007,8 +2017,8 @@ |
2008 | 2018 | // : = dd |
2009 | 2019 | |
2010 | 2020 | $lastPrefixLength = strlen( $lastPrefix ); |
2011 | | - $preCloseMatch = preg_match('/<\\/pre/i', $oLine ); |
2012 | | - $preOpenMatch = preg_match('/<pre/i', $oLine ); |
| 2021 | + $preCloseMatch = preg_match( '/<\\/pre/i', $oLine ); |
| 2022 | + $preOpenMatch = preg_match( '/<pre/i', $oLine ); |
2013 | 2023 | // If not in a <pre> element, scan for and figure out what prefixes are there. |
2014 | 2024 | if ( !$this->mInPre ) { |
2015 | 2025 | # Multiple prefixes may abut each other for nested lists. |
— | — | @@ -2030,7 +2040,7 @@ |
2031 | 2041 | } |
2032 | 2042 | |
2033 | 2043 | # List generation |
2034 | | - if( $prefixLength && $lastPrefix === $prefix2 ) { |
| 2044 | + if ( $prefixLength && $lastPrefix === $prefix2 ) { |
2035 | 2045 | # Same as the last item, so no need to deal with nesting or opening stuff |
2036 | 2046 | $output .= $this->nextItem( substr( $prefix, -1 ) ); |
2037 | 2047 | $paragraphStack = false; |
— | — | @@ -2041,12 +2051,12 @@ |
2042 | 2052 | # So we check for : in the remainder text to split up the |
2043 | 2053 | # title and definition, without b0rking links. |
2044 | 2054 | $term = $t2 = ''; |
2045 | | - if ($this->findColonNoLinks($t, $term, $t2) !== false) { |
| 2055 | + if ( $this->findColonNoLinks( $t, $term, $t2 ) !== false ) { |
2046 | 2056 | $t = $t2; |
2047 | 2057 | $output .= $term . $this->nextItem( ':' ); |
2048 | 2058 | } |
2049 | 2059 | } |
2050 | | - } elseif( $prefixLength || $lastPrefixLength ) { |
| 2060 | + } elseif ( $prefixLength || $lastPrefixLength ) { |
2051 | 2061 | // We need to open or close prefixes, or both. |
2052 | 2062 | |
2053 | 2063 | # Either open or close a level... |
— | — | @@ -2054,7 +2064,7 @@ |
2055 | 2065 | $paragraphStack = false; |
2056 | 2066 | |
2057 | 2067 | // Close all the prefixes which aren't shared. |
2058 | | - while( $commonPrefixLength < $lastPrefixLength ) { |
| 2068 | + while ( $commonPrefixLength < $lastPrefixLength ) { |
2059 | 2069 | $output .= $this->closeList( $lastPrefix[$lastPrefixLength-1] ); |
2060 | 2070 | --$lastPrefixLength; |
2061 | 2071 | } |
— | — | @@ -2071,7 +2081,7 @@ |
2072 | 2082 | |
2073 | 2083 | if ( ';' === $char ) { |
2074 | 2084 | # FIXME: This is dupe of code above |
2075 | | - if ($this->findColonNoLinks($t, $term, $t2) !== false) { |
| 2085 | + if ( $this->findColonNoLinks( $t, $term, $t2 ) !== false ) { |
2076 | 2086 | $t = $t2; |
2077 | 2087 | $output .= $term . $this->nextItem( ':' ); |
2078 | 2088 | } |
— | — | @@ -2082,7 +2092,7 @@ |
2083 | 2093 | } |
2084 | 2094 | |
2085 | 2095 | // If we have no prefixes, go to paragraph mode. |
2086 | | - if( 0 == $prefixLength ) { |
| 2096 | + if ( 0 == $prefixLength ) { |
2087 | 2097 | wfProfileIn( __METHOD__."-paragraph" ); |
2088 | 2098 | # No prefix (not in list)--go to paragraph mode |
2089 | 2099 | // XXX: use a stack for nestable elements like span, table and div |
— | — | @@ -2102,10 +2112,10 @@ |
2103 | 2113 | } else { |
2104 | 2114 | $inBlockElem = true; |
2105 | 2115 | } |
2106 | | - } else if ( !$inBlockElem && !$this->mInPre ) { |
2107 | | - if ( ' ' == substr( $t, 0, 1 ) and ( $this->mLastSection === 'pre' or trim($t) != '' ) ) { |
| 2116 | + } elseif ( !$inBlockElem && !$this->mInPre ) { |
| 2117 | + if ( ' ' == substr( $t, 0, 1 ) and ( $this->mLastSection === 'pre' || trim( $t ) != '' ) ) { |
2108 | 2118 | // pre |
2109 | | - if ($this->mLastSection !== 'pre') { |
| 2119 | + if ( $this->mLastSection !== 'pre' ) { |
2110 | 2120 | $paragraphStack = false; |
2111 | 2121 | $output .= $this->closeParagraph().'<pre>'; |
2112 | 2122 | $this->mLastSection = 'pre'; |
— | — | @@ -2113,13 +2123,13 @@ |
2114 | 2124 | $t = substr( $t, 1 ); |
2115 | 2125 | } else { |
2116 | 2126 | // paragraph |
2117 | | - if ( trim($t) == '' ) { |
| 2127 | + if ( trim( $t ) == '' ) { |
2118 | 2128 | if ( $paragraphStack ) { |
2119 | 2129 | $output .= $paragraphStack.'<br />'; |
2120 | 2130 | $paragraphStack = false; |
2121 | 2131 | $this->mLastSection = 'p'; |
2122 | 2132 | } else { |
2123 | | - if ($this->mLastSection !== 'p' ) { |
| 2133 | + if ( $this->mLastSection !== 'p' ) { |
2124 | 2134 | $output .= $this->closeParagraph(); |
2125 | 2135 | $this->mLastSection = ''; |
2126 | 2136 | $paragraphStack = '<p>'; |
— | — | @@ -2132,7 +2142,7 @@ |
2133 | 2143 | $output .= $paragraphStack; |
2134 | 2144 | $paragraphStack = false; |
2135 | 2145 | $this->mLastSection = 'p'; |
2136 | | - } else if ($this->mLastSection !== 'p') { |
| 2146 | + } elseif ( $this->mLastSection !== 'p' ) { |
2137 | 2147 | $output .= $this->closeParagraph().'<p>'; |
2138 | 2148 | $this->mLastSection = 'p'; |
2139 | 2149 | } |
— | — | @@ -2142,10 +2152,10 @@ |
2143 | 2153 | wfProfileOut( __METHOD__."-paragraph" ); |
2144 | 2154 | } |
2145 | 2155 | // somewhere above we forget to get out of pre block (bug 785) |
2146 | | - if($preCloseMatch && $this->mInPre) { |
| 2156 | + if ( $preCloseMatch && $this->mInPre ) { |
2147 | 2157 | $this->mInPre = false; |
2148 | 2158 | } |
2149 | | - if ($paragraphStack === false) { |
| 2159 | + if ( $paragraphStack === false ) { |
2150 | 2160 | $output .= $t."\n"; |
2151 | 2161 | } |
2152 | 2162 | } |
— | — | @@ -2170,18 +2180,18 @@ |
2171 | 2181 | * @param string &$after set to everything after the ':' |
2172 | 2182 | * return string the position of the ':', or false if none found |
2173 | 2183 | */ |
2174 | | - function findColonNoLinks($str, &$before, &$after) { |
| 2184 | + function findColonNoLinks( $str, &$before, &$after ) { |
2175 | 2185 | wfProfileIn( __METHOD__ ); |
2176 | 2186 | |
2177 | 2187 | $pos = strpos( $str, ':' ); |
2178 | | - if( $pos === false ) { |
| 2188 | + if ( $pos === false ) { |
2179 | 2189 | // Nothing to find! |
2180 | 2190 | wfProfileOut( __METHOD__ ); |
2181 | 2191 | return false; |
2182 | 2192 | } |
2183 | 2193 | |
2184 | 2194 | $lt = strpos( $str, '<' ); |
2185 | | - if( $lt === false || $lt > $pos ) { |
| 2195 | + if ( $lt === false || $lt > $pos ) { |
2186 | 2196 | // Easy; no tag nesting to worry about |
2187 | 2197 | $before = substr( $str, 0, $pos ); |
2188 | 2198 | $after = substr( $str, $pos+1 ); |
— | — | @@ -2205,7 +2215,7 @@ |
2206 | 2216 | $state = self::COLON_STATE_TAGSTART; |
2207 | 2217 | break; |
2208 | 2218 | case ":": |
2209 | | - if( $stack == 0 ) { |
| 2219 | + if ( $stack == 0 ) { |
2210 | 2220 | // We found it! |
2211 | 2221 | $before = substr( $str, 0, $i ); |
2212 | 2222 | $after = substr( $str, $i + 1 ); |
— | — | @@ -2217,14 +2227,14 @@ |
2218 | 2228 | default: |
2219 | 2229 | // Skip ahead looking for something interesting |
2220 | 2230 | $colon = strpos( $str, ':', $i ); |
2221 | | - if( $colon === false ) { |
| 2231 | + if ( $colon === false ) { |
2222 | 2232 | // Nothing else interesting |
2223 | 2233 | wfProfileOut( __METHOD__ ); |
2224 | 2234 | return false; |
2225 | 2235 | } |
2226 | 2236 | $lt = strpos( $str, '<', $i ); |
2227 | | - if( $stack === 0 ) { |
2228 | | - if( $lt === false || $colon < $lt ) { |
| 2237 | + if ( $stack === 0 ) { |
| 2238 | + if ( $lt === false || $colon < $lt ) { |
2229 | 2239 | // We found it! |
2230 | 2240 | $before = substr( $str, 0, $colon ); |
2231 | 2241 | $after = substr( $str, $colon + 1 ); |
— | — | @@ -2232,7 +2242,7 @@ |
2233 | 2243 | return $i; |
2234 | 2244 | } |
2235 | 2245 | } |
2236 | | - if( $lt === false ) { |
| 2246 | + if ( $lt === false ) { |
2237 | 2247 | // Nothing else interesting to find; abort! |
2238 | 2248 | // We're nested, but there's no close tags left. Abort! |
2239 | 2249 | break 2; |
— | — | @@ -2275,9 +2285,9 @@ |
2276 | 2286 | break; |
2277 | 2287 | case 3: // self::COLON_STATE_CLOSETAG: |
2278 | 2288 | // In a </tag> |
2279 | | - if( $c === ">" ) { |
| 2289 | + if ( $c === ">" ) { |
2280 | 2290 | $stack--; |
2281 | | - if( $stack < 0 ) { |
| 2291 | + if ( $stack < 0 ) { |
2282 | 2292 | wfDebug( __METHOD__.": Invalid input; too many close tags\n" ); |
2283 | 2293 | wfProfileOut( __METHOD__ ); |
2284 | 2294 | return false; |
— | — | @@ -2286,7 +2296,7 @@ |
2287 | 2297 | } |
2288 | 2298 | break; |
2289 | 2299 | case self::COLON_STATE_TAGSLASH: |
2290 | | - if( $c === ">" ) { |
| 2300 | + if ( $c === ">" ) { |
2291 | 2301 | // Yes, a self-closed tag <blah/> |
2292 | 2302 | $state = self::COLON_STATE_TEXT; |
2293 | 2303 | } else { |
— | — | @@ -2295,19 +2305,19 @@ |
2296 | 2306 | } |
2297 | 2307 | break; |
2298 | 2308 | case 5: // self::COLON_STATE_COMMENT: |
2299 | | - if( $c === "-" ) { |
| 2309 | + if ( $c === "-" ) { |
2300 | 2310 | $state = self::COLON_STATE_COMMENTDASH; |
2301 | 2311 | } |
2302 | 2312 | break; |
2303 | 2313 | case self::COLON_STATE_COMMENTDASH: |
2304 | | - if( $c === "-" ) { |
| 2314 | + if ( $c === "-" ) { |
2305 | 2315 | $state = self::COLON_STATE_COMMENTDASHDASH; |
2306 | 2316 | } else { |
2307 | 2317 | $state = self::COLON_STATE_COMMENT; |
2308 | 2318 | } |
2309 | 2319 | break; |
2310 | 2320 | case self::COLON_STATE_COMMENTDASHDASH: |
2311 | | - if( $c === ">" ) { |
| 2321 | + if ( $c === ">" ) { |
2312 | 2322 | $state = self::COLON_STATE_TEXT; |
2313 | 2323 | } else { |
2314 | 2324 | $state = self::COLON_STATE_COMMENT; |
— | — | @@ -2317,7 +2327,7 @@ |
2318 | 2328 | throw new MWException( "State machine error in " . __METHOD__ ); |
2319 | 2329 | } |
2320 | 2330 | } |
2321 | | - if( $stack > 0 ) { |
| 2331 | + if ( $stack > 0 ) { |
2322 | 2332 | wfDebug( __METHOD__.": Invalid input; not enough close tags (stack $stack, state $state)\n" ); |
2323 | 2333 | return false; |
2324 | 2334 | } |
— | — | @@ -2436,7 +2446,7 @@ |
2437 | 2447 | $value = wfUrlEncode( str_replace( ' ', '_', $this->mTitle->getBaseText() ) ); |
2438 | 2448 | break; |
2439 | 2449 | case 'talkpagename': |
2440 | | - if( $this->mTitle->canTalk() ) { |
| 2450 | + if ( $this->mTitle->canTalk() ) { |
2441 | 2451 | $talkPage = $this->mTitle->getTalkPage(); |
2442 | 2452 | $value = wfEscapeWikiText( $talkPage->getPrefixedText() ); |
2443 | 2453 | } else { |
— | — | @@ -2444,7 +2454,7 @@ |
2445 | 2455 | } |
2446 | 2456 | break; |
2447 | 2457 | case 'talkpagenamee': |
2448 | | - if( $this->mTitle->canTalk() ) { |
| 2458 | + if ( $this->mTitle->canTalk() ) { |
2449 | 2459 | $talkPage = $this->mTitle->getTalkPage(); |
2450 | 2460 | $value = $talkPage->getPrefixedUrl(); |
2451 | 2461 | } else { |
— | — | @@ -2509,13 +2519,13 @@ |
2510 | 2520 | $value = $this->getRevisionUser(); |
2511 | 2521 | break; |
2512 | 2522 | case 'namespace': |
2513 | | - $value = str_replace('_',' ',$wgContLang->getNsText( $this->mTitle->getNamespace() ) ); |
| 2523 | + $value = str_replace( '_',' ',$wgContLang->getNsText( $this->mTitle->getNamespace() ) ); |
2514 | 2524 | break; |
2515 | 2525 | case 'namespacee': |
2516 | 2526 | $value = wfUrlencode( $wgContLang->getNsText( $this->mTitle->getNamespace() ) ); |
2517 | 2527 | break; |
2518 | 2528 | case 'talkspace': |
2519 | | - $value = $this->mTitle->canTalk() ? str_replace('_',' ',$this->mTitle->getTalkNsText()) : ''; |
| 2529 | + $value = $this->mTitle->canTalk() ? str_replace( '_',' ',$this->mTitle->getTalkNsText() ) : ''; |
2520 | 2530 | break; |
2521 | 2531 | case 'talkspacee': |
2522 | 2532 | $value = $this->mTitle->canTalk() ? wfUrlencode( $this->mTitle->getTalkNsText() ) : ''; |
— | — | @@ -2582,7 +2592,7 @@ |
2583 | 2593 | $value = $wgContLang->formatNum( SiteStats::pages() ); |
2584 | 2594 | break; |
2585 | 2595 | case 'numberofadmins': |
2586 | | - $value = $wgContLang->formatNum( SiteStats::numberingroup('sysop') ); |
| 2596 | + $value = $wgContLang->formatNum( SiteStats::numberingroup( 'sysop' ) ); |
2587 | 2597 | break; |
2588 | 2598 | case 'numberofedits': |
2589 | 2599 | $value = $wgContLang->formatNum( SiteStats::edits() ); |
— | — | @@ -2616,10 +2626,11 @@ |
2617 | 2627 | return $wgContLanguageCode; |
2618 | 2628 | default: |
2619 | 2629 | $ret = null; |
2620 | | - if ( wfRunHooks( 'ParserGetVariableValueSwitch', array( &$this, &$this->mVarCache, &$index, &$ret, &$frame ) ) ) |
| 2630 | + if ( wfRunHooks( 'ParserGetVariableValueSwitch', array( &$this, &$this->mVarCache, &$index, &$ret, &$frame ) ) ) { |
2621 | 2631 | return $ret; |
2622 | | - else |
| 2632 | + } else { |
2623 | 2633 | return null; |
| 2634 | + } |
2624 | 2635 | } |
2625 | 2636 | |
2626 | 2637 | if ( $index ) |
— | — | @@ -2665,7 +2676,7 @@ |
2666 | 2677 | * |
2667 | 2678 | * @private |
2668 | 2679 | */ |
2669 | | - function preprocessToDom ( $text, $flags = 0 ) { |
| 2680 | + function preprocessToDom( $text, $flags = 0 ) { |
2670 | 2681 | $dom = $this->getPreprocessor()->preprocessToObj( $text, $flags ); |
2671 | 2682 | return $dom; |
2672 | 2683 | } |
— | — | @@ -2714,7 +2725,7 @@ |
2715 | 2726 | $frame = $this->getPreprocessor()->newFrame(); |
2716 | 2727 | } elseif ( !( $frame instanceof PPFrame ) ) { |
2717 | 2728 | wfDebug( __METHOD__." called using plain parameters instead of a PPFrame instance. Creating custom frame.\n" ); |
2718 | | - $frame = $this->getPreprocessor()->newCustomFrame($frame); |
| 2729 | + $frame = $this->getPreprocessor()->newCustomFrame( $frame ); |
2719 | 2730 | } |
2720 | 2731 | |
2721 | 2732 | $dom = $this->preprocessToDom( $text ); |
— | — | @@ -2725,11 +2736,11 @@ |
2726 | 2737 | return $text; |
2727 | 2738 | } |
2728 | 2739 | |
2729 | | - /// Clean up argument array - refactored in 1.9 so parserfunctions can use it, too. |
| 2740 | + // Clean up argument array - refactored in 1.9 so parserfunctions can use it, too. |
2730 | 2741 | static function createAssocArgs( $args ) { |
2731 | 2742 | $assocArgs = array(); |
2732 | 2743 | $index = 1; |
2733 | | - foreach( $args as $arg ) { |
| 2744 | + foreach ( $args as $arg ) { |
2734 | 2745 | $eqpos = strpos( $arg, '=' ); |
2735 | 2746 | if ( $eqpos === false ) { |
2736 | 2747 | $assocArgs[$index++] = $arg; |
— | — | @@ -2753,14 +2764,20 @@ |
2754 | 2765 | * Will warn at most once the user per limitation type |
2755 | 2766 | * |
2756 | 2767 | * @param string $limitationType, should be one of: |
2757 | | - * 'expensive-parserfunction' (corresponding messages: 'expensive-parserfunction-warning', 'expensive-parserfunction-category') |
2758 | | - * 'post-expand-template-argument' (corresponding messages: 'post-expand-template-argument-warning', 'post-expand-template-argument-category') |
2759 | | - * 'post-expand-template-inclusion' (corresponding messages: 'post-expand-template-inclusion-warning', 'post-expand-template-inclusion-category') |
| 2768 | + * 'expensive-parserfunction' (corresponding messages: |
| 2769 | + * 'expensive-parserfunction-warning', |
| 2770 | + * 'expensive-parserfunction-category') |
| 2771 | + * 'post-expand-template-argument' (corresponding messages: |
| 2772 | + * 'post-expand-template-argument-warning', |
| 2773 | + * 'post-expand-template-argument-category') |
| 2774 | + * 'post-expand-template-inclusion' (corresponding messages: |
| 2775 | + * 'post-expand-template-inclusion-warning', |
| 2776 | + * 'post-expand-template-inclusion-category') |
2760 | 2777 | * @params int $current, $max When an explicit limit has been |
2761 | 2778 | * exceeded, provide the values (optional) |
2762 | 2779 | */ |
2763 | 2780 | function limitationWarn( $limitationType, $current=null, $max=null) { |
2764 | | - //does no harm if $current and $max are present but are unnecessary for the message |
| 2781 | + // does no harm if $current and $max are present but are unnecessary for the message |
2765 | 2782 | $warning = wfMsgExt( "$limitationType-warning", array( 'parsemag', 'escape' ), $current, $max ); |
2766 | 2783 | $this->mOutput->addWarning( $warning ); |
2767 | 2784 | $this->addTrackingCategory( "$limitationType-category" ); |
— | — | @@ -2804,7 +2821,7 @@ |
2805 | 2822 | $originalTitle = $part1; |
2806 | 2823 | |
2807 | 2824 | # $args is a list of argument nodes, starting from index 0, not including $part1 |
2808 | | - $args = (null == $piece['parts']) ? array() : $piece['parts']; |
| 2825 | + $args = ( null == $piece['parts'] ) ? array() : $piece['parts']; |
2809 | 2826 | wfProfileOut( __METHOD__.'-setup' ); |
2810 | 2827 | |
2811 | 2828 | # SUBST |
— | — | @@ -2840,8 +2857,9 @@ |
2841 | 2858 | $id = $this->mVariables->matchStartToEnd( $part1 ); |
2842 | 2859 | if ( $id !== false ) { |
2843 | 2860 | $text = $this->getVariableValue( $id, $frame ); |
2844 | | - if (MagicWord::getCacheTTL($id)>-1) |
| 2861 | + if ( MagicWord::getCacheTTL( $id ) > -1 ) { |
2845 | 2862 | $this->mOutput->mContainsOldMagic = true; |
| 2863 | + } |
2846 | 2864 | $found = true; |
2847 | 2865 | } |
2848 | 2866 | } |
— | — | @@ -2944,21 +2962,23 @@ |
2945 | 2963 | # Split the title into page and subpage |
2946 | 2964 | $subpage = ''; |
2947 | 2965 | $part1 = $this->maybeDoSubpageLink( $part1, $subpage ); |
2948 | | - if ($subpage !== '') { |
| 2966 | + if ( $subpage !== '' ) { |
2949 | 2967 | $ns = $this->mTitle->getNamespace(); |
2950 | 2968 | } |
2951 | 2969 | $title = Title::newFromText( $part1, $ns ); |
2952 | 2970 | if ( $title ) { |
2953 | 2971 | $titleText = $title->getPrefixedText(); |
2954 | 2972 | # Check for language variants if the template is not found |
2955 | | - if($wgContLang->hasVariants() && $title->getArticleID() == 0){ |
| 2973 | + if ( $wgContLang->hasVariants() && $title->getArticleID() == 0 ) { |
2956 | 2974 | $wgContLang->findVariantLink( $part1, $title, true ); |
2957 | 2975 | } |
2958 | 2976 | # Do recursion depth check |
2959 | 2977 | $limit = $this->mOptions->getMaxTemplateDepth(); |
2960 | 2978 | if ( $frame->depth >= $limit ) { |
2961 | 2979 | $found = true; |
2962 | | - $text = '<span class="error">' . wfMsgForContent( 'parser-template-recursion-depth-warning', $limit ) . '</span>'; |
| 2980 | + $text = '<span class="error">' |
| 2981 | + . wfMsgForContent( 'parser-template-recursion-depth-warning', $limit ) |
| 2982 | + . '</span>'; |
2963 | 2983 | } |
2964 | 2984 | } |
2965 | 2985 | } |
— | — | @@ -2967,15 +2987,18 @@ |
2968 | 2988 | if ( !$found && $title ) { |
2969 | 2989 | wfProfileIn( __METHOD__ . '-loadtpl' ); |
2970 | 2990 | if ( !$title->isExternal() ) { |
2971 | | - if ( $title->getNamespace() == NS_SPECIAL && $this->mOptions->getAllowSpecialInclusion() && $this->ot['html'] ) { |
| 2991 | + if ( $title->getNamespace() == NS_SPECIAL |
| 2992 | + && $this->mOptions->getAllowSpecialInclusion() |
| 2993 | + && $this->ot['html'] ) |
| 2994 | + { |
2972 | 2995 | $text = SpecialPage::capturePath( $title ); |
2973 | 2996 | if ( is_string( $text ) ) { |
2974 | 2997 | $found = true; |
2975 | 2998 | $isHTML = true; |
2976 | 2999 | $this->disableCache(); |
2977 | 3000 | } |
2978 | | - } else if ( $wgNonincludableNamespaces && in_array( $title->getNamespace(), $wgNonincludableNamespaces ) ) { |
2979 | | - $found = false; //access denied |
| 3001 | + } elseif ( $wgNonincludableNamespaces && in_array( $title->getNamespace(), $wgNonincludableNamespaces ) ) { |
| 3002 | + $found = false; // access denied |
2980 | 3003 | wfDebug( __METHOD__.": template inclusion denied for " . $title->getPrefixedDBkey() ); |
2981 | 3004 | } else { |
2982 | 3005 | list( $text, $title ) = $this->getTemplateDom( $title ); |
— | — | @@ -3052,15 +3075,16 @@ |
3053 | 3076 | # immediately preceding headings |
3054 | 3077 | if ( $isHTML ) { |
3055 | 3078 | $text = "\n\n" . $this->insertStripItem( $text ); |
3056 | | - } |
3057 | | - # Escape nowiki-style return values |
3058 | | - elseif ( $nowiki && ( $this->ot['html'] || $this->ot['pre'] ) ) { |
| 3079 | + } elseif ( $nowiki && ( $this->ot['html'] || $this->ot['pre'] ) ) { |
| 3080 | + # Escape nowiki-style return values |
3059 | 3081 | $text = wfEscapeWikiText( $text ); |
3060 | | - } |
3061 | | - # Bug 529: if the template begins with a table or block-level |
3062 | | - # element, it should be treated as beginning a new line. |
3063 | | - # This behaviour is somewhat controversial. |
3064 | | - elseif ( is_string( $text ) && !$piece['lineStart'] && preg_match('/^(?:{\\||:|;|#|\*)/', $text)) /*}*/{ |
| 3082 | + } elseif ( is_string( $text ) |
| 3083 | + && !$piece['lineStart'] |
| 3084 | + && preg_match( '/^(?:{\\||:|;|#|\*)/', $text ) ) |
| 3085 | + { |
| 3086 | + # Bug 529: if the template begins with a table or block-level |
| 3087 | + # element, it should be treated as beginning a new line. |
| 3088 | + # This behaviour is somewhat controversial. |
3065 | 3089 | $text = "\n" . $text; |
3066 | 3090 | } |
3067 | 3091 | |
— | — | @@ -3109,7 +3133,7 @@ |
3110 | 3134 | $dom = $this->preprocessToDom( $text, self::PTD_FOR_INCLUSION ); |
3111 | 3135 | $this->mTplDomCache[ $titleText ] = $dom; |
3112 | 3136 | |
3113 | | - if (! $title->equals($cacheTitle)) { |
| 3137 | + if ( !$title->equals( $cacheTitle ) ) { |
3114 | 3138 | $this->mTplRedirCache[$cacheTitle->getPrefixedDBkey()] = |
3115 | 3139 | array( $title->getNamespace(),$cdb = $title->getDBkey() ); |
3116 | 3140 | } |
— | — | @@ -3130,11 +3154,11 @@ |
3131 | 3155 | $this->mOutput->addTemplate( $dep['title'], $dep['page_id'], $dep['rev_id'] ); |
3132 | 3156 | } |
3133 | 3157 | } |
3134 | | - return array($text,$finalTitle); |
| 3158 | + return array( $text, $finalTitle ); |
3135 | 3159 | } |
3136 | 3160 | |
3137 | 3161 | function fetchTemplate( $title ) { |
3138 | | - $rv = $this->fetchTemplateAndTitle($title); |
| 3162 | + $rv = $this->fetchTemplateAndTitle( $title ); |
3139 | 3163 | return $rv[0]; |
3140 | 3164 | } |
3141 | 3165 | |
— | — | @@ -3153,7 +3177,7 @@ |
3154 | 3178 | $id = false; // Assume current |
3155 | 3179 | wfRunHooks( 'BeforeParserFetchTemplateAndtitle', array( $parser, &$title, &$skip, &$id ) ); |
3156 | 3180 | |
3157 | | - if( $skip ) { |
| 3181 | + if ( $skip ) { |
3158 | 3182 | $text = false; |
3159 | 3183 | $deps[] = array( |
3160 | 3184 | 'title' => $title, |
— | — | @@ -3164,7 +3188,7 @@ |
3165 | 3189 | $rev = $id ? Revision::newFromId( $id ) : Revision::newFromTitle( $title ); |
3166 | 3190 | $rev_id = $rev ? $rev->getId() : 0; |
3167 | 3191 | // If there is no current revision, there is no page |
3168 | | - if( $id === false && !$rev ) { |
| 3192 | + if ( $id === false && !$rev ) { |
3169 | 3193 | $linkCache = LinkCache::singleton(); |
3170 | 3194 | $linkCache->addBadLinkObj( $title ); |
3171 | 3195 | } |
— | — | @@ -3174,13 +3198,13 @@ |
3175 | 3199 | 'page_id' => $title->getArticleID(), |
3176 | 3200 | 'rev_id' => $rev_id ); |
3177 | 3201 | |
3178 | | - if( $rev ) { |
| 3202 | + if ( $rev ) { |
3179 | 3203 | $text = $rev->getText(); |
3180 | | - } elseif( $title->getNamespace() == NS_MEDIAWIKI ) { |
| 3204 | + } elseif ( $title->getNamespace() == NS_MEDIAWIKI ) { |
3181 | 3205 | global $wgContLang; |
3182 | 3206 | $message = $wgContLang->lcfirst( $title->getText() ); |
3183 | 3207 | $text = wfMsgForContentNoTrans( $message ); |
3184 | | - if( wfEmptyMsg( $message, $text ) ) { |
| 3208 | + if ( wfEmptyMsg( $message, $text ) ) { |
3185 | 3209 | $text = false; |
3186 | 3210 | break; |
3187 | 3211 | } |
— | — | @@ -3206,35 +3230,39 @@ |
3207 | 3231 | function interwikiTransclude( $title, $action ) { |
3208 | 3232 | global $wgEnableScaryTranscluding; |
3209 | 3233 | |
3210 | | - if (!$wgEnableScaryTranscluding) |
| 3234 | + if ( !$wgEnableScaryTranscluding ) { |
3211 | 3235 | return wfMsg('scarytranscludedisabled'); |
| 3236 | + } |
3212 | 3237 | |
3213 | 3238 | $url = $title->getFullUrl( "action=$action" ); |
3214 | 3239 | |
3215 | | - if (strlen($url) > 255) |
3216 | | - return wfMsg('scarytranscludetoolong'); |
3217 | | - return $this->fetchScaryTemplateMaybeFromCache($url); |
| 3240 | + if ( strlen( $url ) > 255 ) { |
| 3241 | + return wfMsg( 'scarytranscludetoolong' ); |
| 3242 | + } |
| 3243 | + return $this->fetchScaryTemplateMaybeFromCache( $url ); |
3218 | 3244 | } |
3219 | 3245 | |
3220 | | - function fetchScaryTemplateMaybeFromCache($url) { |
| 3246 | + function fetchScaryTemplateMaybeFromCache( $url ) { |
3221 | 3247 | global $wgTranscludeCacheExpiry; |
3222 | | - $dbr = wfGetDB(DB_SLAVE); |
| 3248 | + $dbr = wfGetDB( DB_SLAVE ); |
3223 | 3249 | $tsCond = $dbr->timestamp( time() - $wgTranscludeCacheExpiry ); |
3224 | | - $obj = $dbr->selectRow('transcache', array('tc_time', 'tc_contents'), |
3225 | | - array('tc_url' => $url, "tc_time >= " . $dbr->addQuotes( $tsCond ) ) ); |
3226 | | - if ($obj) { |
| 3250 | + $obj = $dbr->selectRow( 'transcache', array('tc_time', 'tc_contents' ), |
| 3251 | + array( 'tc_url' => $url, "tc_time >= " . $dbr->addQuotes( $tsCond ) ) ); |
| 3252 | + if ( $obj ) { |
3227 | 3253 | return $obj->tc_contents; |
3228 | 3254 | } |
3229 | 3255 | |
3230 | | - $text = Http::get($url); |
3231 | | - if (!$text) |
3232 | | - return wfMsg('scarytranscludefailed', $url); |
| 3256 | + $text = Http::get( $url ); |
| 3257 | + if ( !$text ) { |
| 3258 | + return wfMsg( 'scarytranscludefailed', $url ); |
| 3259 | + } |
3233 | 3260 | |
3234 | | - $dbw = wfGetDB(DB_MASTER); |
3235 | | - $dbw->replace('transcache', array('tc_url'), array( |
| 3261 | + $dbw = wfGetDB( DB_MASTER ); |
| 3262 | + $dbw->replace( 'transcache', array('tc_url'), array( |
3236 | 3263 | 'tc_url' => $url, |
3237 | 3264 | 'tc_time' => $dbw->timestamp( time() ), |
3238 | | - 'tc_contents' => $text)); |
| 3265 | + 'tc_contents' => $text) |
| 3266 | + ); |
3239 | 3267 | return $text; |
3240 | 3268 | } |
3241 | 3269 | |
— | — | @@ -3302,7 +3330,7 @@ |
3303 | 3331 | $name = $frame->expand( $params['name'] ); |
3304 | 3332 | $attrText = !isset( $params['attr'] ) ? null : $frame->expand( $params['attr'] ); |
3305 | 3333 | $content = !isset( $params['inner'] ) ? null : $frame->expand( $params['inner'] ); |
3306 | | - $marker = "{$this->mUniqPrefix}-$name-" . sprintf('%08X', $this->mMarkerIndex++) . self::MARKER_SUFFIX; |
| 3334 | + $marker = "{$this->mUniqPrefix}-$name-" . sprintf( '%08X', $this->mMarkerIndex++ ) . self::MARKER_SUFFIX; |
3307 | 3335 | |
3308 | 3336 | $isFunctionTag = isset( $this->mFunctionTagHooks[strtolower($name)] ) && |
3309 | 3337 | ( $this->ot['html'] || $this->ot['pre'] ); |
— | — | @@ -3318,20 +3346,20 @@ |
3319 | 3347 | $attributes = $attributes + $params['attributes']; |
3320 | 3348 | } |
3321 | 3349 | |
3322 | | - if( isset( $this->mTagHooks[$name] ) ) { |
| 3350 | + if ( isset( $this->mTagHooks[$name] ) ) { |
3323 | 3351 | # Workaround for PHP bug 35229 and similar |
3324 | 3352 | if ( !is_callable( $this->mTagHooks[$name] ) ) { |
3325 | 3353 | throw new MWException( "Tag hook for $name is not callable\n" ); |
3326 | 3354 | } |
3327 | 3355 | $output = call_user_func_array( $this->mTagHooks[$name], |
3328 | 3356 | array( $content, $attributes, $this, $frame ) ); |
3329 | | - } elseif( isset( $this->mFunctionTagHooks[$name] ) ) { |
| 3357 | + } elseif ( isset( $this->mFunctionTagHooks[$name] ) ) { |
3330 | 3358 | list( $callback, $flags ) = $this->mFunctionTagHooks[$name]; |
3331 | | - if( !is_callable( $callback ) ) |
| 3359 | + if ( !is_callable( $callback ) ) { |
3332 | 3360 | throw new MWException( "Tag hook for $name is not callable\n" ); |
| 3361 | + } |
3333 | 3362 | |
3334 | | - $output = call_user_func_array( $callback, |
3335 | | - array( &$this, $frame, $content, $attributes ) ); |
| 3363 | + $output = call_user_func_array( $callback, array( &$this, $frame, $content, $attributes ) ); |
3336 | 3364 | } else { |
3337 | 3365 | $output = '<span class="error">Invalid tag extension name: ' . |
3338 | 3366 | htmlspecialchars( $name ) . '</span>'; |
— | — | @@ -3362,7 +3390,7 @@ |
3363 | 3391 | } |
3364 | 3392 | } |
3365 | 3393 | |
3366 | | - if( $markerType === 'none' ) { |
| 3394 | + if ( $markerType === 'none' ) { |
3367 | 3395 | return $output; |
3368 | 3396 | } elseif ( $markerType === 'nowiki' ) { |
3369 | 3397 | $this->mStripState->nowiki->setPair( $marker, $output ); |
— | — | @@ -3398,7 +3426,7 @@ |
3399 | 3427 | function incrementExpensiveFunctionCount() { |
3400 | 3428 | global $wgExpensiveParserFunctionLimit; |
3401 | 3429 | $this->mExpensiveFunctionCount++; |
3402 | | - if($this->mExpensiveFunctionCount <= $wgExpensiveParserFunctionLimit) { |
| 3430 | + if ( $this->mExpensiveFunctionCount <= $wgExpensiveParserFunctionLimit ) { |
3403 | 3431 | return true; |
3404 | 3432 | } |
3405 | 3433 | return false; |
— | — | @@ -3413,7 +3441,7 @@ |
3414 | 3442 | |
3415 | 3443 | // The position of __TOC__ needs to be recorded |
3416 | 3444 | $mw = MagicWord::get( 'toc' ); |
3417 | | - if( $mw->match( $text ) ) { |
| 3445 | + if ( $mw->match( $text ) ) { |
3418 | 3446 | $this->mShowToc = true; |
3419 | 3447 | $this->mForceTocPosition = true; |
3420 | 3448 | |
— | — | @@ -3439,14 +3467,14 @@ |
3440 | 3468 | $this->addTrackingCategory( 'hidden-category-category' ); |
3441 | 3469 | } |
3442 | 3470 | # (bug 8068) Allow control over whether robots index a page. |
3443 | | - # |
| 3471 | + # |
3444 | 3472 | # FIXME (bug 14899): __INDEX__ always overrides __NOINDEX__ here! This |
3445 | 3473 | # is not desirable, the last one on the page should win. |
3446 | | - if( isset( $this->mDoubleUnderscores['noindex'] ) && $this->mTitle->canUseNoindex() ) { |
| 3474 | + if ( isset( $this->mDoubleUnderscores['noindex'] ) && $this->mTitle->canUseNoindex() ) { |
3447 | 3475 | $this->mOutput->setIndexPolicy( 'noindex' ); |
3448 | 3476 | $this->addTrackingCategory( 'noindex-category' ); |
3449 | 3477 | } |
3450 | | - if( isset( $this->mDoubleUnderscores['index'] ) && $this->mTitle->canUseNoindex() ){ |
| 3478 | + if ( isset( $this->mDoubleUnderscores['index'] ) && $this->mTitle->canUseNoindex() ) { |
3451 | 3479 | $this->mOutput->setIndexPolicy( 'index' ); |
3452 | 3480 | $this->addTrackingCategory( 'index-category' ); |
3453 | 3481 | } |
— | — | @@ -3461,11 +3489,13 @@ |
3462 | 3490 | * @param $msg String message key |
3463 | 3491 | * @return Bool whether the addition was successful |
3464 | 3492 | */ |
3465 | | - protected function addTrackingCategory( $msg ){ |
| 3493 | + protected function addTrackingCategory( $msg ) { |
3466 | 3494 | $cat = wfMsgForContent( $msg ); |
3467 | 3495 | |
3468 | 3496 | # Allow tracking categories to be disabled by setting them to "-" |
3469 | | - if( $cat === '-' ) return false; |
| 3497 | + if ( $cat === '-' ) { |
| 3498 | + return false; |
| 3499 | + } |
3470 | 3500 | |
3471 | 3501 | $containerCategory = Title::makeTitleSafe( NS_CATEGORY, $cat ); |
3472 | 3502 | if ( $containerCategory ) { |
— | — | @@ -3499,7 +3529,7 @@ |
3500 | 3530 | $showEditLink = $this->mOptions->getEditSection(); |
3501 | 3531 | |
3502 | 3532 | // Do not call quickUserCan unless necessary |
3503 | | - if( $showEditLink && !$this->mTitle->quickUserCan( 'edit' ) ) { |
| 3533 | + if ( $showEditLink && !$this->mTitle->quickUserCan( 'edit' ) ) { |
3504 | 3534 | $showEditLink = 0; |
3505 | 3535 | } |
3506 | 3536 | |
— | — | @@ -3516,7 +3546,7 @@ |
3517 | 3547 | # if there are fewer than 4 headlines in the article, do not show TOC |
3518 | 3548 | # unless it's been explicitly enabled. |
3519 | 3549 | $enoughToc = $this->mShowToc && |
3520 | | - (($numMatches >= 4) || $this->mForceTocPosition); |
| 3550 | + ( ( $numMatches >= 4 ) || $this->mForceTocPosition ); |
3521 | 3551 | |
3522 | 3552 | # Allow user to stipulate that a page should have a "new section" |
3523 | 3553 | # link added via __NEWSECTIONLINK__ |
— | — | @@ -3566,20 +3596,20 @@ |
3567 | 3597 | $byteOffset = 0; |
3568 | 3598 | $tocraw = array(); |
3569 | 3599 | |
3570 | | - foreach( $matches[3] as $headline ) { |
| 3600 | + foreach ( $matches[3] as $headline ) { |
3571 | 3601 | $isTemplate = false; |
3572 | 3602 | $titleText = false; |
3573 | 3603 | $sectionIndex = false; |
3574 | 3604 | $numbering = ''; |
3575 | 3605 | $markerMatches = array(); |
3576 | | - if (preg_match("/^$markerRegex/", $headline, $markerMatches)) { |
| 3606 | + if ( preg_match("/^$markerRegex/", $headline, $markerMatches ) ) { |
3577 | 3607 | $serial = $markerMatches[1]; |
3578 | 3608 | list( $titleText, $sectionIndex ) = $this->mHeadings[$serial]; |
3579 | | - $isTemplate = ($titleText != $baseTitleText); |
3580 | | - $headline = preg_replace("/^$markerRegex/", "", $headline); |
| 3609 | + $isTemplate = ( $titleText != $baseTitleText ); |
| 3610 | + $headline = preg_replace( "/^$markerRegex/", "", $headline ); |
3581 | 3611 | } |
3582 | 3612 | |
3583 | | - if( $toclevel ) { |
| 3613 | + if ( $toclevel ) { |
3584 | 3614 | $prevlevel = $level; |
3585 | 3615 | $prevtoclevel = $toclevel; |
3586 | 3616 | } |
— | — | @@ -3589,30 +3619,30 @@ |
3590 | 3620 | # Increase TOC level |
3591 | 3621 | $toclevel++; |
3592 | 3622 | $sublevelCount[$toclevel] = 0; |
3593 | | - if( $toclevel<$wgMaxTocLevel ) { |
| 3623 | + if ( $toclevel<$wgMaxTocLevel ) { |
3594 | 3624 | $prevtoclevel = $toclevel; |
3595 | 3625 | $toc .= $sk->tocIndent(); |
3596 | 3626 | $numVisible++; |
3597 | 3627 | } |
3598 | | - } |
3599 | | - elseif ( $level < $prevlevel && $toclevel > 1 ) { |
| 3628 | + } elseif ( $level < $prevlevel && $toclevel > 1 ) { |
3600 | 3629 | # Decrease TOC level, find level to jump to |
3601 | 3630 | |
3602 | | - for ($i = $toclevel; $i > 0; $i--) { |
| 3631 | + for ( $i = $toclevel; $i > 0; $i-- ) { |
3603 | 3632 | if ( $levelCount[$i] == $level ) { |
3604 | 3633 | # Found last matching level |
3605 | 3634 | $toclevel = $i; |
3606 | 3635 | break; |
3607 | | - } |
3608 | | - elseif ( $levelCount[$i] < $level ) { |
| 3636 | + } elseif ( $levelCount[$i] < $level ) { |
3609 | 3637 | # Found first matching level below current level |
3610 | 3638 | $toclevel = $i + 1; |
3611 | 3639 | break; |
3612 | 3640 | } |
3613 | 3641 | } |
3614 | | - if( $i == 0 ) $toclevel = 1; |
3615 | | - if( $toclevel<$wgMaxTocLevel ) { |
3616 | | - if($prevtoclevel < $wgMaxTocLevel) { |
| 3642 | + if ( $i == 0 ) { |
| 3643 | + $toclevel = 1; |
| 3644 | + } |
| 3645 | + if ( $toclevel<$wgMaxTocLevel ) { |
| 3646 | + if ( $prevtoclevel < $wgMaxTocLevel ) { |
3617 | 3647 | # Unindent only if the previous toc level was shown :p |
3618 | 3648 | $toc .= $sk->tocUnindent( $prevtoclevel - $toclevel ); |
3619 | 3649 | $prevtoclevel = $toclevel; |
— | — | @@ -3620,10 +3650,9 @@ |
3621 | 3651 | $toc .= $sk->tocLineEnd(); |
3622 | 3652 | } |
3623 | 3653 | } |
3624 | | - } |
3625 | | - else { |
| 3654 | + } else { |
3626 | 3655 | # No change in level, end TOC line |
3627 | | - if( $toclevel<$wgMaxTocLevel ) { |
| 3656 | + if ( $toclevel<$wgMaxTocLevel ) { |
3628 | 3657 | $toc .= $sk->tocLineEnd(); |
3629 | 3658 | } |
3630 | 3659 | } |
— | — | @@ -3634,8 +3663,8 @@ |
3635 | 3664 | @$sublevelCount[$toclevel]++; |
3636 | 3665 | $dot = 0; |
3637 | 3666 | for( $i = 1; $i <= $toclevel; $i++ ) { |
3638 | | - if( !empty( $sublevelCount[$i] ) ) { |
3639 | | - if( $dot ) { |
| 3667 | + if ( !empty( $sublevelCount[$i] ) ) { |
| 3668 | + if ( $dot ) { |
3640 | 3669 | $numbering .= '.'; |
3641 | 3670 | } |
3642 | 3671 | $numbering .= $wgContLang->formatNum( $sublevelCount[$i] ); |
— | — | @@ -3656,7 +3685,7 @@ |
3657 | 3686 | # Strip out HTML (other than plain <sup> and <sub>: bug 8393) |
3658 | 3687 | $tocline = preg_replace( |
3659 | 3688 | array( '#<(?!/?(sup|sub)).*?'.'>#', '#<(/?(sup|sub)).*?'.'>#' ), |
3660 | | - array( '', '<$1>'), |
| 3689 | + array( '', '<$1>' ), |
3661 | 3690 | $safeHeadline |
3662 | 3691 | ); |
3663 | 3692 | $tocline = trim( $tocline ); |
— | — | @@ -3672,7 +3701,7 @@ |
3673 | 3702 | if ( $wgHtml5 && $wgExperimentalHtmlIds ) { |
3674 | 3703 | # For reverse compatibility, provide an id that's |
3675 | 3704 | # HTML4-compatible, like we used to. |
3676 | | - # |
| 3705 | + # |
3677 | 3706 | # It may be worth noting, academically, that it's possible for |
3678 | 3707 | # the legacy anchor to conflict with a non-legacy headline |
3679 | 3708 | # anchor on the page. In this case likely the "correct" thing |
— | — | @@ -3717,7 +3746,7 @@ |
3718 | 3747 | } |
3719 | 3748 | |
3720 | 3749 | # Don't number the heading if it is the only one (looks silly) |
3721 | | - if( $doNumberHeadings && count( $matches[3] ) > 1) { |
| 3750 | + if ( $doNumberHeadings && count( $matches[3] ) > 1) { |
3722 | 3751 | # the two are different if the line contains a link |
3723 | 3752 | $headline = $numbering . ' ' . $headline; |
3724 | 3753 | } |
— | — | @@ -3731,9 +3760,9 @@ |
3732 | 3761 | if ( $legacyHeadline !== false && $refers[$legacyArrayKey] > 1 ) { |
3733 | 3762 | $legacyAnchor .= '_' . $refers[$legacyArrayKey]; |
3734 | 3763 | } |
3735 | | - if( $enoughToc && ( !isset($wgMaxTocLevel) || $toclevel<$wgMaxTocLevel ) ) { |
3736 | | - $toc .= $sk->tocLine($anchor, $tocline, |
3737 | | - $numbering, $toclevel, ($isTemplate ? false : $sectionIndex)); |
| 3764 | + if ( $enoughToc && ( !isset( $wgMaxTocLevel ) || $toclevel < $wgMaxTocLevel ) ) { |
| 3765 | + $toc .= $sk->tocLine( $anchor, $tocline, |
| 3766 | + $numbering, $toclevel, ( $isTemplate ? false : $sectionIndex ) ); |
3738 | 3767 | } |
3739 | 3768 | |
3740 | 3769 | # Add the section to the section tree |
— | — | @@ -3753,20 +3782,20 @@ |
3754 | 3783 | 'level' => $level, |
3755 | 3784 | 'line' => $tocline, |
3756 | 3785 | 'number' => $numbering, |
3757 | | - 'index' => ($isTemplate ? 'T-' : '' ) . $sectionIndex, |
| 3786 | + 'index' => ( $isTemplate ? 'T-' : '' ) . $sectionIndex, |
3758 | 3787 | 'fromtitle' => $titleText, |
3759 | 3788 | 'byteoffset' => ( $isTemplate ? null : $byteOffset ), |
3760 | 3789 | 'anchor' => $anchor, |
3761 | 3790 | ); |
3762 | 3791 | |
3763 | 3792 | # give headline the correct <h#> tag |
3764 | | - if( $showEditLink && $sectionIndex !== false ) { |
3765 | | - if( $isTemplate ) { |
| 3793 | + if ( $showEditLink && $sectionIndex !== false ) { |
| 3794 | + if ( $isTemplate ) { |
3766 | 3795 | # Put a T flag in the section identifier, to indicate to extractSections() |
3767 | 3796 | # that sections inside <includeonly> should be counted. |
3768 | | - $editlink = $sk->doEditSectionLink(Title::newFromText( $titleText ), "T-$sectionIndex"); |
| 3797 | + $editlink = $sk->doEditSectionLink( Title::newFromText( $titleText ), "T-$sectionIndex" ); |
3769 | 3798 | } else { |
3770 | | - $editlink = $sk->doEditSectionLink($this->mTitle, $sectionIndex, $headlineHint); |
| 3799 | + $editlink = $sk->doEditSectionLink( $this->mTitle, $sectionIndex, $headlineHint ); |
3771 | 3800 | } |
3772 | 3801 | } else { |
3773 | 3802 | $editlink = ''; |
— | — | @@ -3781,12 +3810,12 @@ |
3782 | 3811 | $this->setOutputType( $oldType ); |
3783 | 3812 | |
3784 | 3813 | # Never ever show TOC if no headers |
3785 | | - if( $numVisible < 1 ) { |
| 3814 | + if ( $numVisible < 1 ) { |
3786 | 3815 | $enoughToc = false; |
3787 | 3816 | } |
3788 | 3817 | |
3789 | | - if( $enoughToc ) { |
3790 | | - if( $prevtoclevel > 0 && $prevtoclevel < $wgMaxTocLevel ) { |
| 3818 | + if ( $enoughToc ) { |
| 3819 | + if ( $prevtoclevel > 0 && $prevtoclevel < $wgMaxTocLevel ) { |
3791 | 3820 | $toc .= $sk->tocUnindent( $prevtoclevel - 1 ); |
3792 | 3821 | } |
3793 | 3822 | $toc = $sk->tocList( $toc ); |
— | — | @@ -3802,8 +3831,8 @@ |
3803 | 3832 | $blocks = preg_split( '/<H[1-6].*?' . '>.*?<\/H[1-6]>/i', $text ); |
3804 | 3833 | $i = 0; |
3805 | 3834 | |
3806 | | - foreach( $blocks as $block ) { |
3807 | | - if( $showEditLink && $headlineCount > 0 && $i == 0 && $block !== "\n" ) { |
| 3835 | + foreach ( $blocks as $block ) { |
| 3836 | + if ( $showEditLink && $headlineCount > 0 && $i == 0 && $block !== "\n" ) { |
3808 | 3837 | # This is the [edit] link that appears for the top block of text when |
3809 | 3838 | # section editing is enabled |
3810 | 3839 | |
— | — | @@ -3812,17 +3841,17 @@ |
3813 | 3842 | # $full .= $sk->editSectionLink(0); |
3814 | 3843 | } |
3815 | 3844 | $full .= $block; |
3816 | | - if( $enoughToc && !$i && $isMain && !$this->mForceTocPosition ) { |
| 3845 | + if ( $enoughToc && !$i && $isMain && !$this->mForceTocPosition ) { |
3817 | 3846 | # Top anchor now in skin |
3818 | 3847 | $full = $full.$toc; |
3819 | 3848 | } |
3820 | 3849 | |
3821 | | - if( !empty( $head[$i] ) ) { |
| 3850 | + if ( !empty( $head[$i] ) ) { |
3822 | 3851 | $full .= $head[$i]; |
3823 | 3852 | } |
3824 | 3853 | $i++; |
3825 | 3854 | } |
3826 | | - if( $this->mForceTocPosition ) { |
| 3855 | + if ( $this->mForceTocPosition ) { |
3827 | 3856 | return str_replace( '<!--MWTOC-->', $toc, $full ); |
3828 | 3857 | } else { |
3829 | 3858 | return $full; |
— | — | @@ -3852,11 +3881,12 @@ |
3853 | 3882 | $titletext = $title->getPrefixedDBkey(); |
3854 | 3883 | foreach ( $tree1 as $s ) { |
3855 | 3884 | if ( $targetLevel !== false ) { |
3856 | | - if ( $s['level'] <= $targetLevel ) |
| 3885 | + if ( $s['level'] <= $targetLevel ) { |
3857 | 3886 | // We've skipped enough |
3858 | 3887 | $targetLevel = false; |
3859 | | - else |
| 3888 | + } else { |
3860 | 3889 | continue; |
| 3890 | + } |
3861 | 3891 | } |
3862 | 3892 | if ( $s['index'] != $section || |
3863 | 3893 | $s['fromtitle'] != $titletext ) { |
— | — | @@ -3866,8 +3896,9 @@ |
3867 | 3897 | // Rewrite index, byteoffset and number |
3868 | 3898 | if ( $s['fromtitle'] == $titletext ) { |
3869 | 3899 | $s['index'] = $nextIndex++; |
3870 | | - if ( $merged ) |
| 3900 | + if ( $merged ) { |
3871 | 3901 | $s['byteoffset'] += $len2; |
| 3902 | + } |
3872 | 3903 | } |
3873 | 3904 | $s['number'] = implode( '.', array_map( |
3874 | 3905 | array( $wgContLang, 'formatnum' ), |
— | — | @@ -3908,15 +3939,17 @@ |
3909 | 3940 | * @param $lastLevel int Level of previous TOC entry |
3910 | 3941 | */ |
3911 | 3942 | private static function incrementNumbering( &$number, $level, $lastLevel ) { |
3912 | | - if ( $level > $lastLevel ) |
| 3943 | + if ( $level > $lastLevel ) { |
3913 | 3944 | $number[$level - 1] = 1; |
3914 | | - else if ( $level < $lastLevel ) { |
| 3945 | + } elseif ( $level < $lastLevel ) { |
3915 | 3946 | foreach ( $number as $key => $unused ) |
3916 | | - if ( $key >= $level ) |
| 3947 | + if ( $key >= $level ) { |
3917 | 3948 | unset( $number[$key] ); |
| 3949 | + } |
3918 | 3950 | $number[$level - 1]++; |
3919 | | - } else |
| 3951 | + } else { |
3920 | 3952 | $number[$level - 1]++; |
| 3953 | + } |
3921 | 3954 | } |
3922 | 3955 | |
3923 | 3956 | /** |
— | — | @@ -3956,13 +3989,11 @@ |
3957 | 3990 | function pstPass2( $text, $user ) { |
3958 | 3991 | global $wgContLang, $wgLocaltimezone; |
3959 | 3992 | |
3960 | | - /* Note: This is the timestamp saved as hardcoded wikitext to |
3961 | | - * the database, we use $wgContLang here in order to give |
3962 | | - * everyone the same signature and use the default one rather |
3963 | | - * than the one selected in each user's preferences. |
3964 | | - * |
3965 | | - * (see also bug 12815) |
3966 | | - */ |
| 3993 | + # Note: This is the timestamp saved as hardcoded wikitext to |
| 3994 | + # the database, we use $wgContLang here in order to give |
| 3995 | + # everyone the same signature and use the default one rather |
| 3996 | + # than the one selected in each user's preferences. |
| 3997 | + # (see also bug 12815) |
3967 | 3998 | $ts = $this->mOptions->getTimestamp(); |
3968 | 3999 | if ( isset( $wgLocaltimezone ) ) { |
3969 | 4000 | $tz = $wgLocaltimezone; |
— | — | @@ -3976,13 +4007,14 @@ |
3977 | 4008 | $ts = date( 'YmdHis', $unixts ); |
3978 | 4009 | $tzMsg = date( 'T', $unixts ); # might vary on DST changeover! |
3979 | 4010 | |
3980 | | - /* Allow translation of timezones trough wiki. date() can return |
3981 | | - * whatever crap the system uses, localised or not, so we cannot |
3982 | | - * ship premade translations. |
3983 | | - */ |
| 4011 | + # Allow translation of timezones trough wiki. date() can return |
| 4012 | + # whatever crap the system uses, localised or not, so we cannot |
| 4013 | + # ship premade translations. |
3984 | 4014 | $key = 'timezone-' . strtolower( trim( $tzMsg ) ); |
3985 | 4015 | $value = wfMsgForContent( $key ); |
3986 | | - if ( !wfEmptyMsg( $key, $value ) ) $tzMsg = $value; |
| 4016 | + if ( !wfEmptyMsg( $key, $value ) ) { |
| 4017 | + $tzMsg = $value; |
| 4018 | + } |
3987 | 4019 | |
3988 | 4020 | date_default_timezone_set( $oldtz ); |
3989 | 4021 | |
— | — | @@ -4001,7 +4033,6 @@ |
4002 | 4034 | ) ); |
4003 | 4035 | |
4004 | 4036 | # Context links: [[|name]] and [[name (context)|]] |
4005 | | - # |
4006 | 4037 | global $wgLegalTitleChars; |
4007 | 4038 | $tc = "[$wgLegalTitleChars]"; |
4008 | 4039 | $nc = '[ _0-9A-Za-z\x80-\xff-]'; # Namespaces can use non-ascii! |
— | — | @@ -4051,17 +4082,18 @@ |
4052 | 4083 | if ( $nickname === false ) |
4053 | 4084 | $nickname = $user->getOption( 'nickname' ); |
4054 | 4085 | |
4055 | | - if ( is_null( $fancySig ) ) |
| 4086 | + if ( is_null( $fancySig ) ) { |
4056 | 4087 | $fancySig = $user->getBoolOption( 'fancysig' ); |
| 4088 | + } |
4057 | 4089 | |
4058 | 4090 | $nickname = $nickname == null ? $username : $nickname; |
4059 | 4091 | |
4060 | | - if( mb_strlen( $nickname ) > $wgMaxSigChars ) { |
| 4092 | + if ( mb_strlen( $nickname ) > $wgMaxSigChars ) { |
4061 | 4093 | $nickname = $username; |
4062 | 4094 | wfDebug( __METHOD__ . ": $username has overlong signature.\n" ); |
4063 | | - } elseif( $fancySig !== false ) { |
| 4095 | + } elseif ( $fancySig !== false ) { |
4064 | 4096 | # Sig. might contain markup; validate this |
4065 | | - if( $this->validateSig( $nickname ) !== false ) { |
| 4097 | + if ( $this->validateSig( $nickname ) !== false ) { |
4066 | 4098 | # Validated; clean up (if needed) and return it |
4067 | 4099 | return $this->cleanSig( $nickname, true ); |
4068 | 4100 | } else { |
— | — | @@ -4179,11 +4211,11 @@ |
4180 | 4212 | } |
4181 | 4213 | $executing = true; |
4182 | 4214 | |
4183 | | - wfProfileIn(__METHOD__); |
| 4215 | + wfProfileIn( __METHOD__ ); |
4184 | 4216 | $text = $this->preprocess( $text, $wgTitle, $options ); |
4185 | 4217 | |
4186 | 4218 | $executing = false; |
4187 | | - wfProfileOut(__METHOD__); |
| 4219 | + wfProfileOut( __METHOD__ ); |
4188 | 4220 | return $text; |
4189 | 4221 | } |
4190 | 4222 | |
— | — | @@ -4206,7 +4238,7 @@ |
4207 | 4239 | $tag = strtolower( $tag ); |
4208 | 4240 | $oldVal = isset( $this->mTagHooks[$tag] ) ? $this->mTagHooks[$tag] : null; |
4209 | 4241 | $this->mTagHooks[$tag] = $callback; |
4210 | | - if( !in_array( $tag, $this->mStripList ) ) { |
| 4242 | + if ( !in_array( $tag, $this->mStripList ) ) { |
4211 | 4243 | $this->mStripList[] = $tag; |
4212 | 4244 | } |
4213 | 4245 | |
— | — | @@ -4281,7 +4313,7 @@ |
4282 | 4314 | |
4283 | 4315 | # Add to function cache |
4284 | 4316 | $mw = MagicWord::get( $id ); |
4285 | | - if( !$mw ) |
| 4317 | + if ( !$mw ) |
4286 | 4318 | throw new MWException( __METHOD__.'() expecting a magic word identifier.' ); |
4287 | 4319 | |
4288 | 4320 | $synonyms = $mw->getSynonyms(); |
— | — | @@ -4325,7 +4357,7 @@ |
4326 | 4358 | $this->mFunctionTagHooks[$tag] : null; |
4327 | 4359 | $this->mFunctionTagHooks[$tag] = array( $callback, $flags ); |
4328 | 4360 | |
4329 | | - if( !in_array( $tag, $this->mStripList ) ) { |
| 4361 | + if ( !in_array( $tag, $this->mStripList ) ) { |
4330 | 4362 | $this->mStripList[] = $tag; |
4331 | 4363 | } |
4332 | 4364 | |
— | — | @@ -4372,24 +4404,24 @@ |
4373 | 4405 | $ig->useSkin( $this->mOptions->getSkin() ); |
4374 | 4406 | $ig->mRevisionId = $this->mRevisionId; |
4375 | 4407 | |
4376 | | - if( isset( $params['showfilename'] ) ) { |
| 4408 | + if ( isset( $params['showfilename'] ) ) { |
4377 | 4409 | $ig->setShowFilename( true ); |
4378 | 4410 | } else { |
4379 | 4411 | $ig->setShowFilename( false ); |
4380 | 4412 | } |
4381 | | - if( isset( $params['caption'] ) ) { |
| 4413 | + if ( isset( $params['caption'] ) ) { |
4382 | 4414 | $caption = $params['caption']; |
4383 | 4415 | $caption = htmlspecialchars( $caption ); |
4384 | 4416 | $caption = $this->replaceInternalLinks( $caption ); |
4385 | 4417 | $ig->setCaptionHtml( $caption ); |
4386 | 4418 | } |
4387 | | - if( isset( $params['perrow'] ) ) { |
| 4419 | + if ( isset( $params['perrow'] ) ) { |
4388 | 4420 | $ig->setPerRow( $params['perrow'] ); |
4389 | 4421 | } |
4390 | | - if( isset( $params['widths'] ) ) { |
| 4422 | + if ( isset( $params['widths'] ) ) { |
4391 | 4423 | $ig->setWidths( $params['widths'] ); |
4392 | 4424 | } |
4393 | | - if( isset( $params['heights'] ) ) { |
| 4425 | + if ( isset( $params['heights'] ) ) { |
4394 | 4426 | $ig->setHeights( $params['heights'] ); |
4395 | 4427 | } |
4396 | 4428 | |
— | — | @@ -4406,11 +4438,12 @@ |
4407 | 4439 | continue; |
4408 | 4440 | } |
4409 | 4441 | |
4410 | | - if ( strpos( $matches[0], '%' ) !== false ) |
| 4442 | + if ( strpos( $matches[0], '%' ) !== false ) { |
4411 | 4443 | $matches[1] = urldecode( $matches[1] ); |
| 4444 | + } |
4412 | 4445 | $tp = Title::newFromText( $matches[1]/*, NS_FILE*/ ); |
4413 | 4446 | $nt =& $tp; |
4414 | | - if( is_null( $nt ) ) { |
| 4447 | + if ( is_null( $nt ) ) { |
4415 | 4448 | # Bogus title. Ignore these so we don't bomb out later. |
4416 | 4449 | continue; |
4417 | 4450 | } |
— | — | @@ -4527,15 +4560,15 @@ |
4528 | 4561 | $caption = ''; |
4529 | 4562 | $params = array( 'frame' => array(), 'handler' => array(), |
4530 | 4563 | 'horizAlign' => array(), 'vertAlign' => array() ); |
4531 | | - foreach( $parts as $part ) { |
| 4564 | + foreach ( $parts as $part ) { |
4532 | 4565 | $part = trim( $part ); |
4533 | 4566 | list( $magicName, $value ) = $mwArray->matchVariableStartToEnd( $part ); |
4534 | 4567 | $validated = false; |
4535 | | - if( isset( $paramMap[$magicName] ) ) { |
| 4568 | + if ( isset( $paramMap[$magicName] ) ) { |
4536 | 4569 | list( $type, $paramName ) = $paramMap[$magicName]; |
4537 | 4570 | |
4538 | 4571 | // Special case; width and height come in one variable together |
4539 | | - if( $type === 'handler' && $paramName === 'width' ) { |
| 4572 | + if ( $type === 'handler' && $paramName === 'width' ) { |
4540 | 4573 | $m = array(); |
4541 | 4574 | # (bug 13500) In both cases (width/height and width only), |
4542 | 4575 | # permit trailing "px" for backward compatibility. |
— | — | @@ -4631,13 +4664,13 @@ |
4632 | 4665 | # came to also set the caption, ordinary text after the image -- which |
4633 | 4666 | # makes no sense, because that just repeats the text multiple times in |
4634 | 4667 | # screen readers. It *also* came to set the title attribute. |
4635 | | - # |
| 4668 | + # |
4636 | 4669 | # Now that we have an alt attribute, we should not set the alt text to |
4637 | 4670 | # equal the caption: that's worse than useless, it just repeats the |
4638 | 4671 | # text. This is the framed/thumbnail case. If there's no caption, we |
4639 | 4672 | # use the unnamed parameter for alt text as well, just for the time be- |
4640 | 4673 | # ing, if the unnamed param is set and the alt param is not. |
4641 | | - # |
| 4674 | + # |
4642 | 4675 | # For the future, we need to figure out if we want to tweak this more, |
4643 | 4676 | # e.g., introducing a title= parameter for the title; ignoring the un- |
4644 | 4677 | # named parameter entirely for images without a caption; adding an ex- |
— | — | @@ -4734,7 +4767,9 @@ |
4735 | 4768 | /**#@+ |
4736 | 4769 | * Accessor |
4737 | 4770 | */ |
4738 | | - function getTags() { return array_merge( array_keys($this->mTransparentTagHooks), array_keys( $this->mTagHooks ) ); } |
| 4771 | + function getTags() { |
| 4772 | + return array_merge( array_keys( $this->mTransparentTagHooks ), array_keys( $this->mTagHooks ) ); |
| 4773 | + } |
4739 | 4774 | /**#@-*/ |
4740 | 4775 | |
4741 | 4776 | |
— | — | @@ -4838,7 +4873,7 @@ |
4839 | 4874 | // Add two newlines on -- trailing whitespace in $newText is conventionally |
4840 | 4875 | // stripped by the editor, so we need both newlines to restore the paragraph gap |
4841 | 4876 | // Only add trailing whitespace if there is newText |
4842 | | - if($newText != "") { |
| 4877 | + if ( $newText != "" ) { |
4843 | 4878 | $outText .= $newText . "\n\n"; |
4844 | 4879 | } |
4845 | 4880 | |
— | — | @@ -4896,7 +4931,7 @@ |
4897 | 4932 | |
4898 | 4933 | // The cryptic '' timezone parameter tells to use the site-default |
4899 | 4934 | // timezone offset instead of the user settings. |
4900 | | - // |
| 4935 | + // |
4901 | 4936 | // Since this value will be saved into the parser cache, served |
4902 | 4937 | // to other users, and potentially even used inside links and such, |
4903 | 4938 | // it needs to be consistent for all visitors. |
— | — | @@ -4913,7 +4948,7 @@ |
4914 | 4949 | function getRevisionUser() { |
4915 | 4950 | // if this template is subst: the revision id will be blank, |
4916 | 4951 | // so just use the current user's name |
4917 | | - if( $this->mRevisionId ) { |
| 4952 | + if ( $this->mRevisionId ) { |
4918 | 4953 | $revision = Revision::newFromId( $this->mRevisionId ); |
4919 | 4954 | $revuser = $revision->getUserText(); |
4920 | 4955 | } else { |
— | — | @@ -4940,10 +4975,11 @@ |
4941 | 4976 | */ |
4942 | 4977 | public function getDefaultSort() { |
4943 | 4978 | global $wgCategoryPrefixedDefaultSortkey; |
4944 | | - if( $this->mDefaultSort !== false ) { |
| 4979 | + if ( $this->mDefaultSort !== false ) { |
4945 | 4980 | return $this->mDefaultSort; |
4946 | | - } elseif ($this->mTitle->getNamespace() == NS_CATEGORY || |
4947 | | - !$wgCategoryPrefixedDefaultSortkey) { |
| 4981 | + } elseif ( $this->mTitle->getNamespace() == NS_CATEGORY || |
| 4982 | + !$wgCategoryPrefixedDefaultSortkey ) |
| 4983 | + { |
4948 | 4984 | return $this->mTitle->getText(); |
4949 | 4985 | } else { |
4950 | 4986 | return $this->mTitle->getPrefixedText(); |
— | — | @@ -4999,16 +5035,16 @@ |
5000 | 5036 | */ |
5001 | 5037 | public function stripSectionName( $text ) { |
5002 | 5038 | # Strip internal link markup |
5003 | | - $text = preg_replace('/\[\[:?([^[|]+)\|([^[]+)\]\]/','$2',$text); |
5004 | | - $text = preg_replace('/\[\[:?([^[]+)\|?\]\]/','$1',$text); |
| 5039 | + $text = preg_replace( '/\[\[:?([^[|]+)\|([^[]+)\]\]/', '$2', $text ); |
| 5040 | + $text = preg_replace( '/\[\[:?([^[]+)\|?\]\]/', '$1', $text ); |
5005 | 5041 | |
5006 | 5042 | # Strip external link markup (FIXME: Not Tolerant to blank link text |
5007 | 5043 | # I.E. [http://www.mediawiki.org] will render as [1] or something depending |
5008 | 5044 | # on how many empty links there are on the page - need to figure that out. |
5009 | | - $text = preg_replace('/\[(?:' . wfUrlProtocols() . ')([^ ]+?) ([^[]+)\]/','$2',$text); |
| 5045 | + $text = preg_replace( '/\[(?:' . wfUrlProtocols() . ')([^ ]+?) ([^[]+)\]/', '$2', $text ); |
5010 | 5046 | |
5011 | 5047 | # Parse wikitext quotes (italics & bold) |
5012 | | - $text = $this->doQuotes($text); |
| 5048 | + $text = $this->doQuotes( $text ); |
5013 | 5049 | |
5014 | 5050 | # Strip HTML tags |
5015 | 5051 | $text = StringUtils::delimiterReplace( '<', '>', '', $text ); |
— | — | @@ -5024,7 +5060,7 @@ |
5025 | 5061 | */ |
5026 | 5062 | function testSrvus( $text, $title, $options, $outputType = self::OT_HTML ) { |
5027 | 5063 | $this->clearState(); |
5028 | | - if ( ! ( $title instanceof Title ) ) { |
| 5064 | + if ( !$title instanceof Title ) { |
5029 | 5065 | $title = Title::newFromText( $title ); |
5030 | 5066 | } |
5031 | 5067 | $this->mTitle = $title; |
— | — | @@ -5038,14 +5074,14 @@ |
5039 | 5075 | |
5040 | 5076 | function testPst( $text, $title, $options ) { |
5041 | 5077 | global $wgUser; |
5042 | | - if ( ! ( $title instanceof Title ) ) { |
| 5078 | + if ( !$title instanceof Title ) { |
5043 | 5079 | $title = Title::newFromText( $title ); |
5044 | 5080 | } |
5045 | 5081 | return $this->preSaveTransform( $text, $title, $wgUser, $options ); |
5046 | 5082 | } |
5047 | 5083 | |
5048 | 5084 | function testPreprocess( $text, $title, $options ) { |
5049 | | - if ( ! ( $title instanceof Title ) ) { |
| 5085 | + if ( !$title instanceof Title ) { |
5050 | 5086 | $title = Title::newFromText( $title ); |
5051 | 5087 | } |
5052 | 5088 | return $this->testSrvus( $text, $title, $options, self::OT_PREPROCESS ); |
— | — | @@ -5083,7 +5119,9 @@ |
5084 | 5120 | // data in an array. |
5085 | 5121 | $stripState = new StripState; |
5086 | 5122 | $pos = 0; |
5087 | | - while( ( $start_pos = strpos( $text, $this->mUniqPrefix, $pos ) ) && ( $end_pos = strpos( $text, self::MARKER_SUFFIX, $pos ) ) ) { |
| 5123 | + while ( ( $start_pos = strpos( $text, $this->mUniqPrefix, $pos ) ) |
| 5124 | + && ( $end_pos = strpos( $text, self::MARKER_SUFFIX, $pos ) ) ) |
| 5125 | + { |
5088 | 5126 | $end_pos += strlen( self::MARKER_SUFFIX ); |
5089 | 5127 | $marker = substr( $text, $start_pos, $end_pos-$start_pos ); |
5090 | 5128 | |
— | — | @@ -5108,11 +5146,11 @@ |
5109 | 5147 | $pos = 0; |
5110 | 5148 | |
5111 | 5149 | // Internal links |
5112 | | - while( ( $start_pos = strpos( $text, '<!--LINK ', $pos ) ) ) { |
| 5150 | + while ( ( $start_pos = strpos( $text, '<!--LINK ', $pos ) ) ) { |
5113 | 5151 | list( $ns, $trail ) = explode( ':', substr( $text, $start_pos + strlen( '<!--LINK ' ) ), 2 ); |
5114 | 5152 | |
5115 | | - $ns = trim($ns); |
5116 | | - if (empty( $links['internal'][$ns] )) { |
| 5153 | + $ns = trim( $ns ); |
| 5154 | + if ( empty( $links['internal'][$ns] ) ) { |
5117 | 5155 | $links['internal'][$ns] = array(); |
5118 | 5156 | } |
5119 | 5157 | |
— | — | @@ -5124,7 +5162,7 @@ |
5125 | 5163 | $pos = 0; |
5126 | 5164 | |
5127 | 5165 | // Interwiki links |
5128 | | - while( ( $start_pos = strpos( $text, '<!--IWLINK ', $pos ) ) ) { |
| 5166 | + while ( ( $start_pos = strpos( $text, '<!--IWLINK ', $pos ) ) ) { |
5129 | 5167 | $data = substr( $text, $start_pos ); |
5130 | 5168 | $key = trim( substr( $data, 0, strpos( $data, '-->' ) ) ); |
5131 | 5169 | $links['interwiki'][] = $this->mLinkHolders->interwiki[$key]; |
— | — | @@ -5137,8 +5175,9 @@ |
5138 | 5176 | } |
5139 | 5177 | |
5140 | 5178 | function unserialiseHalfParsedText( $data, $intPrefix = null /* Unique identifying prefix */ ) { |
5141 | | - if (!$intPrefix) |
| 5179 | + if ( !$intPrefix ) { |
5142 | 5180 | $intPrefix = $this->getRandomString(); |
| 5181 | + } |
5143 | 5182 | |
5144 | 5183 | // First, extract the strip state. |
5145 | 5184 | $stripState = $data['stripstate']; |
— | — | @@ -5150,8 +5189,8 @@ |
5151 | 5190 | $links = $data['linkholder']; |
5152 | 5191 | |
5153 | 5192 | // Internal... |
5154 | | - foreach( $links['internal'] as $ns => $nsLinks ) { |
5155 | | - foreach( $nsLinks as $key => $entry ) { |
| 5193 | + foreach ( $links['internal'] as $ns => $nsLinks ) { |
| 5194 | + foreach ( $nsLinks as $key => $entry ) { |
5156 | 5195 | $newKey = $intPrefix . '-' . $key; |
5157 | 5196 | $this->mLinkHolders->internals[$ns][$newKey] = $entry; |
5158 | 5197 | |
— | — | @@ -5160,7 +5199,7 @@ |
5161 | 5200 | } |
5162 | 5201 | |
5163 | 5202 | // Interwiki... |
5164 | | - foreach( $links['interwiki'] as $key => $entry ) { |
| 5203 | + foreach ( $links['interwiki'] as $key => $entry ) { |
5165 | 5204 | $newKey = "$intPrefix-$key"; |
5166 | 5205 | $this->mLinkHolders->interwikis[$newKey] = $entry; |
5167 | 5206 | |