Index: trunk/phase3/includes/parser/Parser.php |
— | — | @@ -98,7 +98,7 @@ |
99 | 99 | # Cleared with clearState(): |
100 | 100 | var $mOutput, $mAutonumber, $mDTopen, $mStripState; |
101 | 101 | var $mIncludeCount, $mArgStack, $mLastSection, $mInPre; |
102 | | - var $mLinkHolders, $mLinkID; |
| 102 | + var $mInterwikiLinkHolders, $mLinkHolders; |
103 | 103 | var $mIncludeSizes, $mPPNodeCount, $mDefaultSort; |
104 | 104 | var $mTplExpandCache; // empty-frame expansion cache |
105 | 105 | var $mTplRedirCache, $mTplDomCache, $mHeadings, $mDoubleUnderscores; |
— | — | @@ -179,8 +179,17 @@ |
180 | 180 | $this->mStripState = new StripState; |
181 | 181 | $this->mArgStack = false; |
182 | 182 | $this->mInPre = false; |
183 | | - $this->mLinkHolders = new LinkHolderArray( $this ); |
184 | | - $this->mLinkID = 0; |
| 183 | + $this->mInterwikiLinkHolders = array( |
| 184 | + 'texts' => array(), |
| 185 | + 'titles' => array() |
| 186 | + ); |
| 187 | + $this->mLinkHolders = array( |
| 188 | + 'namespaces' => array(), |
| 189 | + 'dbkeys' => array(), |
| 190 | + 'queries' => array(), |
| 191 | + 'texts' => array(), |
| 192 | + 'titles' => array() |
| 193 | + ); |
185 | 194 | $this->mRevisionTimestamp = $this->mRevisionId = null; |
186 | 195 | |
187 | 196 | /** |
— | — | @@ -195,7 +204,7 @@ |
196 | 205 | */ |
197 | 206 | #$this->mUniqPrefix = "\x07UNIQ" . Parser::getRandomString(); |
198 | 207 | # Changed to \x7f to allow XML double-parsing -- TS |
199 | | - $this->mUniqPrefix = "\x7fUNIQ" . self::getRandomString(); |
| 208 | + $this->mUniqPrefix = "\x7fUNIQ" . Parser::getRandomString(); |
200 | 209 | |
201 | 210 | |
202 | 211 | # Clear these on every parse, bug 4549 |
— | — | @@ -285,7 +294,7 @@ |
286 | 295 | */ |
287 | 296 | |
288 | 297 | global $wgUseTidy, $wgAlwaysUseTidy, $wgContLang; |
289 | | - $fname = __METHOD__.'-' . wfGetCaller(); |
| 298 | + $fname = 'Parser::parse-' . wfGetCaller(); |
290 | 299 | wfProfileIn( __METHOD__ ); |
291 | 300 | wfProfileIn( $fname ); |
292 | 301 | |
— | — | @@ -319,6 +328,7 @@ |
320 | 329 | ); |
321 | 330 | $text = preg_replace( array_keys($fixtags), array_values($fixtags), $text ); |
322 | 331 | |
| 332 | + # only once and last |
323 | 333 | $text = $this->doBlockLevels( $text, $linestart ); |
324 | 334 | |
325 | 335 | $this->replaceLinkHolders( $text ); |
— | — | @@ -338,7 +348,7 @@ |
339 | 349 | $uniq_prefix = $this->mUniqPrefix; |
340 | 350 | $matches = array(); |
341 | 351 | $elements = array_keys( $this->mTransparentTagHooks ); |
342 | | - $text = self::extractTagsAndParams( $elements, $text, $matches, $uniq_prefix ); |
| 352 | + $text = Parser::extractTagsAndParams( $elements, $text, $matches, $uniq_prefix ); |
343 | 353 | |
344 | 354 | foreach( $matches as $marker => $data ) { |
345 | 355 | list( $element, $content, $params, $tag ) = $data; |
— | — | @@ -356,7 +366,7 @@ |
357 | 367 | $text = Sanitizer::normalizeCharReferences( $text ); |
358 | 368 | |
359 | 369 | if (($wgUseTidy and $this->mOptions->mTidy) or $wgAlwaysUseTidy) { |
360 | | - $text = self::tidy($text); |
| 370 | + $text = Parser::tidy($text); |
361 | 371 | } else { |
362 | 372 | # attempt to sanitize at least some nesting problems |
363 | 373 | # (bug #2702 and quite a few others) |
— | — | @@ -461,8 +471,6 @@ |
462 | 472 | function &getTitle() { return $this->mTitle; } |
463 | 473 | function getOptions() { return $this->mOptions; } |
464 | 474 | function getRevisionId() { return $this->mRevisionId; } |
465 | | - function getOutput() { return $this->mOutput; } |
466 | | - function nextLinkID() { return $this->mLinkID++; } |
467 | 475 | |
468 | 476 | function getFunctionLang() { |
469 | 477 | global $wgLang, $wgContLang; |
— | — | @@ -504,7 +512,7 @@ |
505 | 513 | * @public |
506 | 514 | * @static |
507 | 515 | */ |
508 | | - static function extractTagsAndParams($elements, $text, &$matches, $uniq_prefix = ''){ |
| 516 | + function extractTagsAndParams($elements, $text, &$matches, $uniq_prefix = ''){ |
509 | 517 | static $n = 1; |
510 | 518 | $stripped = ''; |
511 | 519 | $matches = array(); |
— | — | @@ -541,7 +549,7 @@ |
542 | 550 | $text = $inside; |
543 | 551 | $tail = null; |
544 | 552 | } else { |
545 | | - if( $element === '!--' ) { |
| 553 | + if( $element == '!--' ) { |
546 | 554 | $end = '/(-->)/'; |
547 | 555 | } else { |
548 | 556 | $end = "/(<\\/$element\\s*>)/i"; |
— | — | @@ -644,15 +652,15 @@ |
645 | 653 | * @public |
646 | 654 | * @static |
647 | 655 | */ |
648 | | - static function tidy( $text ) { |
| 656 | + function tidy( $text ) { |
649 | 657 | global $wgTidyInternal; |
650 | 658 | $wrappedtext = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"'. |
651 | 659 | ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>'. |
652 | 660 | '<head><title>test</title></head><body>'.$text.'</body></html>'; |
653 | 661 | if( $wgTidyInternal ) { |
654 | | - $correctedtext = self::internalTidy( $wrappedtext ); |
| 662 | + $correctedtext = Parser::internalTidy( $wrappedtext ); |
655 | 663 | } else { |
656 | | - $correctedtext = self::externalTidy( $wrappedtext ); |
| 664 | + $correctedtext = Parser::externalTidy( $wrappedtext ); |
657 | 665 | } |
658 | 666 | if( is_null( $correctedtext ) ) { |
659 | 667 | wfDebug( "Tidy error detected!\n" ); |
— | — | @@ -667,9 +675,10 @@ |
668 | 676 | * @private |
669 | 677 | * @static |
670 | 678 | */ |
671 | | - static function externalTidy( $text ) { |
| 679 | + function externalTidy( $text ) { |
672 | 680 | global $wgTidyConf, $wgTidyBin, $wgTidyOpts; |
673 | | - wfProfileIn( __METHOD__ ); |
| 681 | + $fname = 'Parser::externalTidy'; |
| 682 | + wfProfileIn( $fname ); |
674 | 683 | |
675 | 684 | $cleansource = ''; |
676 | 685 | $opts = ' -utf8'; |
— | — | @@ -698,7 +707,7 @@ |
699 | 708 | } |
700 | 709 | } |
701 | 710 | |
702 | | - wfProfileOut( __METHOD__ ); |
| 711 | + wfProfileOut( $fname ); |
703 | 712 | |
704 | 713 | if( $cleansource == '' && $text != '') { |
705 | 714 | // Some kind of error happened, so we couldn't get the corrected text. |
— | — | @@ -718,9 +727,10 @@ |
719 | 728 | * @private |
720 | 729 | * @static |
721 | 730 | */ |
722 | | - static function internalTidy( $text ) { |
| 731 | + function internalTidy( $text ) { |
723 | 732 | global $wgTidyConf, $IP, $wgDebugTidy; |
724 | | - wfProfileIn( __METHOD__ ); |
| 733 | + $fname = 'Parser::internalTidy'; |
| 734 | + wfProfileIn( $fname ); |
725 | 735 | |
726 | 736 | $tidy = new tidy; |
727 | 737 | $tidy->parseString( $text, $wgTidyConf, 'utf8' ); |
— | — | @@ -738,7 +748,7 @@ |
739 | 749 | "\n-->"; |
740 | 750 | } |
741 | 751 | |
742 | | - wfProfileOut( __METHOD__ ); |
| 752 | + wfProfileOut( $fname ); |
743 | 753 | return $cleansource; |
744 | 754 | } |
745 | 755 | |
— | — | @@ -748,35 +758,34 @@ |
749 | 759 | * @private |
750 | 760 | */ |
751 | 761 | function doTableStuff ( $text ) { |
752 | | - wfProfileIn( __METHOD__ ); |
| 762 | + $fname = 'Parser::doTableStuff'; |
| 763 | + wfProfileIn( $fname ); |
753 | 764 | |
754 | | - $lines = StringUtils::explode( "\n", $text ); |
755 | | - $out = ''; |
| 765 | + $lines = explode ( "\n" , $text ); |
756 | 766 | $td_history = array (); // Is currently a td tag open? |
757 | 767 | $last_tag_history = array (); // Save history of last lag activated (td, th or caption) |
758 | 768 | $tr_history = array (); // Is currently a tr tag open? |
759 | 769 | $tr_attributes = array (); // history of tr attributes |
760 | 770 | $has_opened_tr = array(); // Did this table open a <tr> element? |
761 | 771 | $indent_level = 0; // indent level of the table |
| 772 | + foreach ( $lines as $key => $line ) |
| 773 | + { |
| 774 | + $line = trim ( $line ); |
762 | 775 | |
763 | | - foreach ( $lines as $outLine ) { |
764 | | - $line = trim( $outLine ); |
765 | | - |
766 | 776 | if( $line == '' ) { // empty line, go to next line |
767 | | - $out .= "\n"; |
768 | 777 | continue; |
769 | 778 | } |
770 | | - $first_character = $line[0]; |
| 779 | + $first_character = $line{0}; |
771 | 780 | $matches = array(); |
772 | 781 | |
773 | | - if ( preg_match( '/^(:*)\{\|(.*)$/', $line , $matches ) ) { |
| 782 | + if ( preg_match( '/^(:*)\{\|(.*)$/' , $line , $matches ) ) { |
774 | 783 | // First check if we are starting a new table |
775 | 784 | $indent_level = strlen( $matches[1] ); |
776 | 785 | |
777 | 786 | $attributes = $this->mStripState->unstripBoth( $matches[2] ); |
778 | 787 | $attributes = Sanitizer::fixTagAttributes ( $attributes , 'table' ); |
779 | 788 | |
780 | | - $outLine = str_repeat( '<dl><dd>' , $indent_level ) . "<table{$attributes}>"; |
| 789 | + $lines[$key] = str_repeat( '<dl><dd>' , $indent_level ) . "<table{$attributes}>"; |
781 | 790 | array_push ( $td_history , false ); |
782 | 791 | array_push ( $last_tag_history , '' ); |
783 | 792 | array_push ( $tr_history , false ); |
— | — | @@ -784,9 +793,8 @@ |
785 | 794 | array_push ( $has_opened_tr , false ); |
786 | 795 | } else if ( count ( $td_history ) == 0 ) { |
787 | 796 | // Don't do any of the following |
788 | | - $out .= $outLine."\n"; |
789 | 797 | continue; |
790 | | - } else if ( substr ( $line , 0 , 2 ) === '|}' ) { |
| 798 | + } else if ( substr ( $line , 0 , 2 ) == '|}' ) { |
791 | 799 | // We are ending a table |
792 | 800 | $line = '</table>' . substr ( $line , 2 ); |
793 | 801 | $last_tag = array_pop ( $last_tag_history ); |
— | — | @@ -803,8 +811,8 @@ |
804 | 812 | $line = "</{$last_tag}>{$line}"; |
805 | 813 | } |
806 | 814 | array_pop ( $tr_attributes ); |
807 | | - $outLine = $line . str_repeat( '</dd></dl>' , $indent_level ); |
808 | | - } else if ( substr ( $line , 0 , 2 ) === '|-' ) { |
| 815 | + $lines[$key] = $line . str_repeat( '</dd></dl>' , $indent_level ); |
| 816 | + } else if ( substr ( $line , 0 , 2 ) == '|-' ) { |
809 | 817 | // Now we have a table row |
810 | 818 | $line = preg_replace( '#^\|-+#', '', $line ); |
811 | 819 | |
— | — | @@ -827,21 +835,21 @@ |
828 | 836 | $line = "</{$last_tag}>{$line}"; |
829 | 837 | } |
830 | 838 | |
831 | | - $outLine = $line; |
| 839 | + $lines[$key] = $line; |
832 | 840 | array_push ( $tr_history , false ); |
833 | 841 | array_push ( $td_history , false ); |
834 | 842 | array_push ( $last_tag_history , '' ); |
835 | 843 | } |
836 | | - else if ( $first_character === '|' || $first_character === '!' || substr ( $line , 0 , 2 ) === '|+' ) { |
| 844 | + else if ( $first_character == '|' || $first_character == '!' || substr ( $line , 0 , 2 ) == '|+' ) { |
837 | 845 | // This might be cell elements, td, th or captions |
838 | | - if ( substr ( $line , 0 , 2 ) === '|+' ) { |
| 846 | + if ( substr ( $line , 0 , 2 ) == '|+' ) { |
839 | 847 | $first_character = '+'; |
840 | 848 | $line = substr ( $line , 1 ); |
841 | 849 | } |
842 | 850 | |
843 | 851 | $line = substr ( $line , 1 ); |
844 | 852 | |
845 | | - if ( $first_character === '!' ) { |
| 853 | + if ( $first_character == '!' ) { |
846 | 854 | $line = str_replace ( '!!' , '||' , $line ); |
847 | 855 | } |
848 | 856 | |
— | — | @@ -851,13 +859,13 @@ |
852 | 860 | // attribute values containing literal "||". |
853 | 861 | $cells = StringUtils::explodeMarkup( '||' , $line ); |
854 | 862 | |
855 | | - $outLine = ''; |
| 863 | + $lines[$key] = ''; |
856 | 864 | |
857 | 865 | // Loop through each table cell |
858 | 866 | foreach ( $cells as $cell ) |
859 | 867 | { |
860 | 868 | $previous = ''; |
861 | | - if ( $first_character !== '+' ) |
| 869 | + if ( $first_character != '+' ) |
862 | 870 | { |
863 | 871 | $tr_after = array_pop ( $tr_attributes ); |
864 | 872 | if ( !array_pop ( $tr_history ) ) { |
— | — | @@ -875,11 +883,11 @@ |
876 | 884 | $previous = "</{$last_tag}>{$previous}"; |
877 | 885 | } |
878 | 886 | |
879 | | - if ( $first_character === '|' ) { |
| 887 | + if ( $first_character == '|' ) { |
880 | 888 | $last_tag = 'td'; |
881 | | - } else if ( $first_character === '!' ) { |
| 889 | + } else if ( $first_character == '!' ) { |
882 | 890 | $last_tag = 'th'; |
883 | | - } else if ( $first_character === '+' ) { |
| 891 | + } else if ( $first_character == '+' ) { |
884 | 892 | $last_tag = 'caption'; |
885 | 893 | } else { |
886 | 894 | $last_tag = ''; |
— | — | @@ -902,42 +910,38 @@ |
903 | 911 | $cell = "{$previous}<{$last_tag}{$attributes}>{$cell_data[1]}"; |
904 | 912 | } |
905 | 913 | |
906 | | - $outLine .= $cell; |
| 914 | + $lines[$key] .= $cell; |
907 | 915 | array_push ( $td_history , true ); |
908 | 916 | } |
909 | 917 | } |
910 | | - $out .= $outLine . "\n"; |
911 | 918 | } |
912 | 919 | |
913 | 920 | // Closing open td, tr && table |
914 | 921 | while ( count ( $td_history ) > 0 ) |
915 | 922 | { |
916 | 923 | if ( array_pop ( $td_history ) ) { |
917 | | - $out .= "</td>\n"; |
| 924 | + $lines[] = '</td>' ; |
918 | 925 | } |
919 | 926 | if ( array_pop ( $tr_history ) ) { |
920 | | - $out .= "</tr>\n"; |
| 927 | + $lines[] = '</tr>' ; |
921 | 928 | } |
922 | 929 | if ( !array_pop ( $has_opened_tr ) ) { |
923 | | - $out .= "<tr><td></td></tr>\n" ; |
| 930 | + $lines[] = "<tr><td></td></tr>" ; |
924 | 931 | } |
925 | 932 | |
926 | | - $out .= "</table>\n"; |
| 933 | + $lines[] = '</table>' ; |
927 | 934 | } |
928 | 935 | |
929 | | - // Remove trailing line-ending (b/c) |
930 | | - if ( substr( $out, -1 ) === "\n" ) { |
931 | | - $out = substr( $out, 0, -1 ); |
932 | | - } |
| 936 | + $output = implode ( "\n" , $lines ) ; |
933 | 937 | |
934 | 938 | // special case: don't return empty table |
935 | | - if( $out === "<table>\n<tr><td></td></tr>\n</table>" ) { |
936 | | - $out = ''; |
| 939 | + if( $output == "<table>\n<tr><td></td></tr>\n</table>" ) { |
| 940 | + $output = ''; |
937 | 941 | } |
938 | 942 | |
939 | | - wfProfileOut( __METHOD__ ); |
| 943 | + wfProfileOut( $fname ); |
940 | 944 | |
941 | | - return $out; |
| 945 | + return $output; |
942 | 946 | } |
943 | 947 | |
944 | 948 | /** |
— | — | @@ -948,11 +952,12 @@ |
949 | 953 | */ |
950 | 954 | function internalParse( $text ) { |
951 | 955 | $isMain = true; |
952 | | - wfProfileIn( __METHOD__ ); |
| 956 | + $fname = 'Parser::internalParse'; |
| 957 | + wfProfileIn( $fname ); |
953 | 958 | |
954 | 959 | # Hook to suspend the parser in this state |
955 | 960 | if ( !wfRunHooks( 'ParserBeforeInternalParse', array( &$this, &$text, &$this->mStripState ) ) ) { |
956 | | - wfProfileOut( __METHOD__ ); |
| 961 | + wfProfileOut( $fname ); |
957 | 962 | return $text ; |
958 | 963 | } |
959 | 964 | |
— | — | @@ -985,7 +990,7 @@ |
986 | 991 | $text = $this->doMagicLinks( $text ); |
987 | 992 | $text = $this->formatHeadings( $text, $isMain ); |
988 | 993 | |
989 | | - wfProfileOut( __METHOD__ ); |
| 994 | + wfProfileOut( $fname ); |
990 | 995 | return $text; |
991 | 996 | } |
992 | 997 | |
— | — | @@ -1013,10 +1018,10 @@ |
1014 | 1019 | } |
1015 | 1020 | |
1016 | 1021 | function magicLinkCallback( $m ) { |
1017 | | - if ( substr( $m[0], 0, 1 ) === '<' ) { |
| 1022 | + if ( substr( $m[0], 0, 1 ) == '<' ) { |
1018 | 1023 | # Skip HTML element |
1019 | 1024 | return $m[0]; |
1020 | | - } elseif ( substr( $m[0], 0, 4 ) === 'ISBN' ) { |
| 1025 | + } elseif ( substr( $m[0], 0, 4 ) == 'ISBN' ) { |
1021 | 1026 | $isbn = $m[2]; |
1022 | 1027 | $num = strtr( $isbn, array( |
1023 | 1028 | '-' => '', |
— | — | @@ -1028,11 +1033,11 @@ |
1029 | 1034 | $titleObj->escapeLocalUrl() . |
1030 | 1035 | "\" class=\"internal\">ISBN $isbn</a>"; |
1031 | 1036 | } else { |
1032 | | - if ( substr( $m[0], 0, 3 ) === 'RFC' ) { |
| 1037 | + if ( substr( $m[0], 0, 3 ) == 'RFC' ) { |
1033 | 1038 | $keyword = 'RFC'; |
1034 | 1039 | $urlmsg = 'rfcurl'; |
1035 | 1040 | $id = $m[1]; |
1036 | | - } elseif ( substr( $m[0], 0, 4 ) === 'PMID' ) { |
| 1041 | + } elseif ( substr( $m[0], 0, 4 ) == 'PMID' ) { |
1037 | 1042 | $keyword = 'PMID'; |
1038 | 1043 | $urlmsg = 'pubmedurl'; |
1039 | 1044 | $id = $m[1]; |
— | — | @@ -1054,14 +1059,15 @@ |
1055 | 1060 | * |
1056 | 1061 | * @private |
1057 | 1062 | */ |
1058 | | - static function doHeadings( $text ) { |
1059 | | - wfProfileIn( __METHOD__ ); |
| 1063 | + function doHeadings( $text ) { |
| 1064 | + $fname = 'Parser::doHeadings'; |
| 1065 | + wfProfileIn( $fname ); |
1060 | 1066 | for ( $i = 6; $i >= 1; --$i ) { |
1061 | 1067 | $h = str_repeat( '=', $i ); |
1062 | 1068 | $text = preg_replace( "/^$h(.+)$h\\s*$/m", |
1063 | 1069 | "<h$i>\\1</h$i>", $text ); |
1064 | 1070 | } |
1065 | | - wfProfileOut( __METHOD__ ); |
| 1071 | + wfProfileOut( $fname ); |
1066 | 1072 | return $text; |
1067 | 1073 | } |
1068 | 1074 | |
— | — | @@ -1070,22 +1076,23 @@ |
1071 | 1077 | * @private |
1072 | 1078 | * @return string the altered text |
1073 | 1079 | */ |
1074 | | - static function doAllQuotes( $text ) { |
1075 | | - wfProfileIn( __METHOD__ ); |
| 1080 | + function doAllQuotes( $text ) { |
| 1081 | + $fname = 'Parser::doAllQuotes'; |
| 1082 | + wfProfileIn( $fname ); |
1076 | 1083 | $outtext = ''; |
1077 | | - $lines = StringUtils::explode( "\n", $text ); |
| 1084 | + $lines = explode( "\n", $text ); |
1078 | 1085 | foreach ( $lines as $line ) { |
1079 | | - $outtext .= self::doQuotes( $line ) . "\n"; |
| 1086 | + $outtext .= $this->doQuotes ( $line ) . "\n"; |
1080 | 1087 | } |
1081 | 1088 | $outtext = substr($outtext, 0,-1); |
1082 | | - wfProfileOut( __METHOD__ ); |
| 1089 | + wfProfileOut( $fname ); |
1083 | 1090 | return $outtext; |
1084 | 1091 | } |
1085 | 1092 | |
1086 | 1093 | /** |
1087 | 1094 | * Helper function for doAllQuotes() |
1088 | 1095 | */ |
1089 | | - public static function doQuotes( $text ) { |
| 1096 | + public function doQuotes( $text ) { |
1090 | 1097 | $arr = preg_split( "/(''+)/", $text, -1, PREG_SPLIT_DELIM_CAPTURE ); |
1091 | 1098 | if ( count( $arr ) == 1 ) |
1092 | 1099 | return $text; |
— | — | @@ -1140,9 +1147,9 @@ |
1141 | 1148 | { |
1142 | 1149 | $x1 = substr ($arr[$i-1], -1); |
1143 | 1150 | $x2 = substr ($arr[$i-1], -2, 1); |
1144 | | - if ($x1 === ' ') { |
| 1151 | + if ($x1 == ' ') { |
1145 | 1152 | if ($firstspace == -1) $firstspace = $i; |
1146 | | - } else if ($x2 === ' ') { |
| 1153 | + } else if ($x2 == ' ') { |
1147 | 1154 | if ($firstsingleletterword == -1) $firstsingleletterword = $i; |
1148 | 1155 | } else { |
1149 | 1156 | if ($firstmultiletterword == -1) $firstmultiletterword = $i; |
— | — | @@ -1182,7 +1189,7 @@ |
1183 | 1190 | { |
1184 | 1191 | if (($i % 2) == 0) |
1185 | 1192 | { |
1186 | | - if ($state === 'both') |
| 1193 | + if ($state == 'both') |
1187 | 1194 | $buffer .= $r; |
1188 | 1195 | else |
1189 | 1196 | $output .= $r; |
— | — | @@ -1191,41 +1198,41 @@ |
1192 | 1199 | { |
1193 | 1200 | if (strlen ($r) == 2) |
1194 | 1201 | { |
1195 | | - if ($state === 'i') |
| 1202 | + if ($state == 'i') |
1196 | 1203 | { $output .= '</i>'; $state = ''; } |
1197 | | - else if ($state === 'bi') |
| 1204 | + else if ($state == 'bi') |
1198 | 1205 | { $output .= '</i>'; $state = 'b'; } |
1199 | | - else if ($state === 'ib') |
| 1206 | + else if ($state == 'ib') |
1200 | 1207 | { $output .= '</b></i><b>'; $state = 'b'; } |
1201 | | - else if ($state === 'both') |
| 1208 | + else if ($state == 'both') |
1202 | 1209 | { $output .= '<b><i>'.$buffer.'</i>'; $state = 'b'; } |
1203 | 1210 | else # $state can be 'b' or '' |
1204 | 1211 | { $output .= '<i>'; $state .= 'i'; } |
1205 | 1212 | } |
1206 | 1213 | else if (strlen ($r) == 3) |
1207 | 1214 | { |
1208 | | - if ($state === 'b') |
| 1215 | + if ($state == 'b') |
1209 | 1216 | { $output .= '</b>'; $state = ''; } |
1210 | | - else if ($state === 'bi') |
| 1217 | + else if ($state == 'bi') |
1211 | 1218 | { $output .= '</i></b><i>'; $state = 'i'; } |
1212 | | - else if ($state === 'ib') |
| 1219 | + else if ($state == 'ib') |
1213 | 1220 | { $output .= '</b>'; $state = 'i'; } |
1214 | | - else if ($state === 'both') |
| 1221 | + else if ($state == 'both') |
1215 | 1222 | { $output .= '<i><b>'.$buffer.'</b>'; $state = 'i'; } |
1216 | 1223 | else # $state can be 'i' or '' |
1217 | 1224 | { $output .= '<b>'; $state .= 'b'; } |
1218 | 1225 | } |
1219 | 1226 | else if (strlen ($r) == 5) |
1220 | 1227 | { |
1221 | | - if ($state === 'b') |
| 1228 | + if ($state == 'b') |
1222 | 1229 | { $output .= '</b><i>'; $state = 'i'; } |
1223 | | - else if ($state === 'i') |
| 1230 | + else if ($state == 'i') |
1224 | 1231 | { $output .= '</i><b>'; $state = 'b'; } |
1225 | | - else if ($state === 'bi') |
| 1232 | + else if ($state == 'bi') |
1226 | 1233 | { $output .= '</i></b>'; $state = ''; } |
1227 | | - else if ($state === 'ib') |
| 1234 | + else if ($state == 'ib') |
1228 | 1235 | { $output .= '</b></i>'; $state = ''; } |
1229 | | - else if ($state === 'both') |
| 1236 | + else if ($state == 'both') |
1230 | 1237 | { $output .= '<i><b>'.$buffer.'</b></i>'; $state = ''; } |
1231 | 1238 | else # ($state == '') |
1232 | 1239 | { $buffer = ''; $state = 'both'; } |
— | — | @@ -1234,14 +1241,14 @@ |
1235 | 1242 | $i++; |
1236 | 1243 | } |
1237 | 1244 | # Now close all remaining tags. Notice that the order is important. |
1238 | | - if ($state === 'b' || $state === 'ib') |
| 1245 | + if ($state == 'b' || $state == 'ib') |
1239 | 1246 | $output .= '</b>'; |
1240 | | - if ($state === 'i' || $state === 'bi' || $state === 'ib') |
| 1247 | + if ($state == 'i' || $state == 'bi' || $state == 'ib') |
1241 | 1248 | $output .= '</i>'; |
1242 | | - if ($state === 'bi') |
| 1249 | + if ($state == 'bi') |
1243 | 1250 | $output .= '</b>'; |
1244 | 1251 | # There might be lonely ''''', so make sure we have a buffer |
1245 | | - if ($state === 'both' && $buffer) |
| 1252 | + if ($state == 'both' && $buffer) |
1246 | 1253 | $output .= '<b><i>'.$buffer.'</i></b>'; |
1247 | 1254 | return $output; |
1248 | 1255 | } |
— | — | @@ -1257,7 +1264,8 @@ |
1258 | 1265 | */ |
1259 | 1266 | function replaceExternalLinks( $text ) { |
1260 | 1267 | global $wgContLang; |
1261 | | - wfProfileIn( __METHOD__ ); |
| 1268 | + $fname = 'Parser::replaceExternalLinks'; |
| 1269 | + wfProfileIn( $fname ); |
1262 | 1270 | |
1263 | 1271 | $sk = $this->mOptions->getSkin(); |
1264 | 1272 | |
— | — | @@ -1291,7 +1299,7 @@ |
1292 | 1300 | $dtrail = ''; |
1293 | 1301 | |
1294 | 1302 | # Set linktype for CSS - if URL==text, link is essentially free |
1295 | | - $linktype = ($text === $url) ? 'free' : 'text'; |
| 1303 | + $linktype = ($text == $url) ? 'free' : 'text'; |
1296 | 1304 | |
1297 | 1305 | # No link text, e.g. [http://domain.tld/some.link] |
1298 | 1306 | if ( $text == '' ) { |
— | — | @@ -1327,11 +1335,11 @@ |
1328 | 1336 | # Register link in the output object. |
1329 | 1337 | # Replace unnecessary URL escape codes with the referenced character |
1330 | 1338 | # This prevents spammers from hiding links from the filters |
1331 | | - $pasteurized = self::replaceUnusualEscapes( $url ); |
| 1339 | + $pasteurized = Parser::replaceUnusualEscapes( $url ); |
1332 | 1340 | $this->mOutput->addExternalLink( $pasteurized ); |
1333 | 1341 | } |
1334 | 1342 | |
1335 | | - wfProfileOut( __METHOD__ ); |
| 1343 | + wfProfileOut( $fname ); |
1336 | 1344 | return $s; |
1337 | 1345 | } |
1338 | 1346 | |
— | — | @@ -1341,7 +1349,8 @@ |
1342 | 1350 | */ |
1343 | 1351 | function replaceFreeExternalLinks( $text ) { |
1344 | 1352 | global $wgContLang; |
1345 | | - wfProfileIn( __METHOD__ ); |
| 1353 | + $fname = 'Parser::replaceFreeExternalLinks'; |
| 1354 | + wfProfileIn( $fname ); |
1346 | 1355 | |
1347 | 1356 | $bits = preg_split( '/(\b(?:' . wfUrlProtocols() . '))/S', $text, -1, PREG_SPLIT_DELIM_CAPTURE ); |
1348 | 1357 | $s = array_shift( $bits ); |
— | — | @@ -1403,7 +1412,7 @@ |
1404 | 1413 | $text = $sk->makeExternalLink( $url, $wgContLang->markNoConversion($url), true, 'free', $this->mTitle->getNamespace() ); |
1405 | 1414 | # Register it in the output object... |
1406 | 1415 | # Replace unnecessary URL escape codes with their equivalent characters |
1407 | | - $pasteurized = self::replaceUnusualEscapes( $url ); |
| 1416 | + $pasteurized = Parser::replaceUnusualEscapes( $url ); |
1408 | 1417 | $this->mOutput->addExternalLink( $pasteurized ); |
1409 | 1418 | } |
1410 | 1419 | $s .= $text . $trail; |
— | — | @@ -1411,7 +1420,7 @@ |
1412 | 1421 | $s .= $protocol . $remainder; |
1413 | 1422 | } |
1414 | 1423 | } |
1415 | | - wfProfileOut( __METHOD__ ); |
| 1424 | + wfProfileOut( $fname ); |
1416 | 1425 | return $s; |
1417 | 1426 | } |
1418 | 1427 | |
— | — | @@ -1427,7 +1436,7 @@ |
1428 | 1437 | */ |
1429 | 1438 | static function replaceUnusualEscapes( $url ) { |
1430 | 1439 | return preg_replace_callback( '/%[0-9A-Fa-f]{2}/', |
1431 | | - array( __CLASS__, 'replaceUnusualEscapesCallback' ), $url ); |
| 1440 | + array( 'Parser', 'replaceUnusualEscapesCallback' ), $url ); |
1432 | 1441 | } |
1433 | 1442 | |
1434 | 1443 | /** |
— | — | @@ -1471,48 +1480,35 @@ |
1472 | 1481 | |
1473 | 1482 | /** |
1474 | 1483 | * Process [[ ]] wikilinks |
1475 | | - * @return processed text |
1476 | 1484 | * |
1477 | 1485 | * @private |
1478 | 1486 | */ |
1479 | 1487 | function replaceInternalLinks( $s ) { |
1480 | | - $this->mLinkHolders->merge( $this->replaceInternalLinks2( $s ) ); |
1481 | | - return $s; |
1482 | | - } |
1483 | | - |
1484 | | - /** |
1485 | | - * Process [[ ]] wikilinks |
1486 | | - * @return LinkHolderArray |
1487 | | - * |
1488 | | - * @private |
1489 | | - */ |
1490 | | - function replaceInternalLinks2( &$s ) { |
1491 | 1488 | global $wgContLang; |
| 1489 | + static $fname = 'Parser::replaceInternalLinks' ; |
1492 | 1490 | |
1493 | | - wfProfileIn( __METHOD__ ); |
| 1491 | + wfProfileIn( $fname ); |
1494 | 1492 | |
1495 | | - wfProfileIn( __METHOD__.'-setup' ); |
1496 | | - static $tc = FALSE, $e1, $e1_img; |
| 1493 | + wfProfileIn( $fname.'-setup' ); |
| 1494 | + static $tc = FALSE; |
1497 | 1495 | # the % is needed to support urlencoded titles as well |
1498 | | - if ( !$tc ) { |
1499 | | - $tc = Title::legalChars() . '#%'; |
1500 | | - # Match a link having the form [[namespace:link|alternate]]trail |
1501 | | - $e1 = "/^([{$tc}]+)(?:\\|(.+?))?]](.*)\$/sD"; |
1502 | | - # Match cases where there is no "]]", which might still be images |
1503 | | - $e1_img = "/^([{$tc}]+)\\|(.*)\$/sD"; |
1504 | | - } |
| 1496 | + if ( !$tc ) { $tc = Title::legalChars() . '#%'; } |
1505 | 1497 | |
1506 | 1498 | $sk = $this->mOptions->getSkin(); |
1507 | | - $holders = new LinkHolderArray( $this ); |
1508 | 1499 | |
1509 | 1500 | #split the entire text string on occurences of [[ |
1510 | | - $a = StringUtils::explode( '[[', ' ' . $s ); |
| 1501 | + $a = explode( '[[', ' ' . $s ); |
1511 | 1502 | #get the first element (all text up to first [[), and remove the space we added |
1512 | | - $s = $a->current(); |
1513 | | - $a->next(); |
1514 | | - $line = $a->current(); # Workaround for broken ArrayIterator::next() that returns "void" |
| 1503 | + $s = array_shift( $a ); |
1515 | 1504 | $s = substr( $s, 1 ); |
1516 | 1505 | |
| 1506 | + # Match a link having the form [[namespace:link|alternate]]trail |
| 1507 | + static $e1 = FALSE; |
| 1508 | + if ( !$e1 ) { $e1 = "/^([{$tc}]+)(?:\\|(.+?))?]](.*)\$/sD"; } |
| 1509 | + # Match cases where there is no "]]", which might still be images |
| 1510 | + static $e1_img = FALSE; |
| 1511 | + if ( !$e1_img ) { $e1_img = "/^([{$tc}]+)\\|(.*)\$/sD"; } |
| 1512 | + |
1517 | 1513 | $useLinkPrefixExtension = $wgContLang->linkPrefixExtension(); |
1518 | 1514 | $e2 = null; |
1519 | 1515 | if ( $useLinkPrefixExtension ) { |
— | — | @@ -1522,8 +1518,8 @@ |
1523 | 1519 | } |
1524 | 1520 | |
1525 | 1521 | if( is_null( $this->mTitle ) ) { |
1526 | | - wfProfileOut( __METHOD__.'-setup' ); |
1527 | | - wfProfileOut( __METHOD__ ); |
| 1522 | + wfProfileOut( $fname ); |
| 1523 | + wfProfileOut( $fname.'-setup' ); |
1528 | 1524 | throw new MWException( __METHOD__.": \$this->mTitle is null\n" ); |
1529 | 1525 | } |
1530 | 1526 | $nottalk = !$this->mTitle->isTalkPage(); |
— | — | @@ -1545,20 +1541,13 @@ |
1546 | 1542 | $selflink = array($this->mTitle->getPrefixedText()); |
1547 | 1543 | } |
1548 | 1544 | $useSubpages = $this->areSubpagesAllowed(); |
1549 | | - wfProfileOut( __METHOD__.'-setup' ); |
| 1545 | + wfProfileOut( $fname.'-setup' ); |
1550 | 1546 | |
1551 | 1547 | # Loop for each link |
1552 | | - for ( ; $line !== false && $line !== null ; $a->next(), $line = $a->current() ) { |
1553 | | - # Check for excessive memory usage |
1554 | | - if ( $holders->isBig() ) { |
1555 | | - # Too big |
1556 | | - # Do the existence check, replace the link holders and clear the array |
1557 | | - $holders->replace( $s ); |
1558 | | - $holders->clear(); |
1559 | | - } |
1560 | | - |
| 1548 | + for ($k = 0; isset( $a[$k] ); $k++) { |
| 1549 | + $line = $a[$k]; |
1561 | 1550 | if ( $useLinkPrefixExtension ) { |
1562 | | - wfProfileIn( __METHOD__.'-prefixhandling' ); |
| 1551 | + wfProfileIn( $fname.'-prefixhandling' ); |
1563 | 1552 | if ( preg_match( $e2, $s, $m ) ) { |
1564 | 1553 | $prefix = $m[2]; |
1565 | 1554 | $s = $m[1]; |
— | — | @@ -1570,12 +1559,12 @@ |
1571 | 1560 | $prefix = $first_prefix; |
1572 | 1561 | $first_prefix = false; |
1573 | 1562 | } |
1574 | | - wfProfileOut( __METHOD__.'-prefixhandling' ); |
| 1563 | + wfProfileOut( $fname.'-prefixhandling' ); |
1575 | 1564 | } |
1576 | 1565 | |
1577 | 1566 | $might_be_img = false; |
1578 | 1567 | |
1579 | | - wfProfileIn( __METHOD__."-e1" ); |
| 1568 | + wfProfileIn( "$fname-e1" ); |
1580 | 1569 | if ( preg_match( $e1, $line, $m ) ) { # page with normal text or alt |
1581 | 1570 | $text = $m[2]; |
1582 | 1571 | # If we get a ] at the beginning of $m[3] that means we have a link that's something like: |
— | — | @@ -1609,18 +1598,18 @@ |
1610 | 1599 | $trail = ""; |
1611 | 1600 | } else { # Invalid form; output directly |
1612 | 1601 | $s .= $prefix . '[[' . $line ; |
1613 | | - wfProfileOut( __METHOD__."-e1" ); |
| 1602 | + wfProfileOut( "$fname-e1" ); |
1614 | 1603 | continue; |
1615 | 1604 | } |
1616 | | - wfProfileOut( __METHOD__."-e1" ); |
1617 | | - wfProfileIn( __METHOD__."-misc" ); |
| 1605 | + wfProfileOut( "$fname-e1" ); |
| 1606 | + wfProfileIn( "$fname-misc" ); |
1618 | 1607 | |
1619 | 1608 | # Don't allow internal links to pages containing |
1620 | 1609 | # PROTO: where PROTO is a valid URL protocol; these |
1621 | 1610 | # should be external links. |
1622 | 1611 | if (preg_match('/^\b(?:' . wfUrlProtocols() . ')/', $m[1])) { |
1623 | 1612 | $s .= $prefix . '[[' . $line ; |
1624 | | - wfProfileOut( __METHOD__."-misc" ); |
| 1613 | + wfProfileOut( "$fname-misc" ); |
1625 | 1614 | continue; |
1626 | 1615 | } |
1627 | 1616 | |
— | — | @@ -1631,36 +1620,33 @@ |
1632 | 1621 | $link = $m[1]; |
1633 | 1622 | } |
1634 | 1623 | |
1635 | | - $noforce = (substr($m[1], 0, 1) !== ':'); |
| 1624 | + $noforce = (substr($m[1], 0, 1) != ':'); |
1636 | 1625 | if (!$noforce) { |
1637 | 1626 | # Strip off leading ':' |
1638 | 1627 | $link = substr($link, 1); |
1639 | 1628 | } |
1640 | 1629 | |
1641 | | - wfProfileOut( __METHOD__."-misc" ); |
1642 | | - wfProfileIn( __METHOD__."-title" ); |
| 1630 | + wfProfileOut( "$fname-misc" ); |
| 1631 | + wfProfileIn( "$fname-title" ); |
1643 | 1632 | $nt = Title::newFromText( $this->mStripState->unstripNoWiki($link) ); |
1644 | 1633 | if( !$nt ) { |
1645 | 1634 | $s .= $prefix . '[[' . $line; |
1646 | | - wfProfileOut( __METHOD__."-title" ); |
| 1635 | + wfProfileOut( "$fname-title" ); |
1647 | 1636 | continue; |
1648 | 1637 | } |
1649 | 1638 | |
1650 | 1639 | $ns = $nt->getNamespace(); |
1651 | 1640 | $iw = $nt->getInterWiki(); |
1652 | | - wfProfileOut( __METHOD__."-title" ); |
| 1641 | + wfProfileOut( "$fname-title" ); |
1653 | 1642 | |
1654 | 1643 | if ($might_be_img) { # if this is actually an invalid link |
1655 | | - wfProfileIn( __METHOD__."-might_be_img" ); |
| 1644 | + wfProfileIn( "$fname-might_be_img" ); |
1656 | 1645 | if ($ns == NS_IMAGE && $noforce) { #but might be an image |
1657 | 1646 | $found = false; |
1658 | | - while ( true ) { |
| 1647 | + while (isset ($a[$k+1]) ) { |
1659 | 1648 | #look at the next 'line' to see if we can close it there |
1660 | | - $a->next(); |
1661 | | - $next_line = $a->current(); |
1662 | | - if ( $next_line === false || $next_line === null ) { |
1663 | | - break; |
1664 | | - } |
| 1649 | + $spliced = array_splice( $a, $k + 1, 1 ); |
| 1650 | + $next_line = array_shift( $spliced ); |
1665 | 1651 | $m = explode( ']]', $next_line, 3 ); |
1666 | 1652 | if ( count( $m ) == 3 ) { |
1667 | 1653 | # the first ]] closes the inner link, the second the image |
— | — | @@ -1680,19 +1666,19 @@ |
1681 | 1667 | if ( !$found ) { |
1682 | 1668 | # we couldn't find the end of this imageLink, so output it raw |
1683 | 1669 | #but don't ignore what might be perfectly normal links in the text we've examined |
1684 | | - $holders->merge( $this->replaceInternalLinks2( $text ) ); |
| 1670 | + $text = $this->replaceInternalLinks($text); |
1685 | 1671 | $s .= "{$prefix}[[$link|$text"; |
1686 | 1672 | # note: no $trail, because without an end, there *is* no trail |
1687 | | - wfProfileOut( __METHOD__."-might_be_img" ); |
| 1673 | + wfProfileOut( "$fname-might_be_img" ); |
1688 | 1674 | continue; |
1689 | 1675 | } |
1690 | 1676 | } else { #it's not an image, so output it raw |
1691 | 1677 | $s .= "{$prefix}[[$link|$text"; |
1692 | 1678 | # note: no $trail, because without an end, there *is* no trail |
1693 | | - wfProfileOut( __METHOD__."-might_be_img" ); |
| 1679 | + wfProfileOut( "$fname-might_be_img" ); |
1694 | 1680 | continue; |
1695 | 1681 | } |
1696 | | - wfProfileOut( __METHOD__."-might_be_img" ); |
| 1682 | + wfProfileOut( "$fname-might_be_img" ); |
1697 | 1683 | } |
1698 | 1684 | |
1699 | 1685 | $wasblank = ( '' == $text ); |
— | — | @@ -1702,36 +1688,41 @@ |
1703 | 1689 | if( $noforce ) { |
1704 | 1690 | |
1705 | 1691 | # Interwikis |
1706 | | - wfProfileIn( __METHOD__."-interwiki" ); |
| 1692 | + wfProfileIn( "$fname-interwiki" ); |
1707 | 1693 | if( $iw && $this->mOptions->getInterwikiMagic() && $nottalk && $wgContLang->getLanguageName( $iw ) ) { |
1708 | 1694 | $this->mOutput->addLanguageLink( $nt->getFullText() ); |
1709 | 1695 | $s = rtrim($s . $prefix); |
1710 | 1696 | $s .= trim($trail, "\n") == '' ? '': $prefix . $trail; |
1711 | | - wfProfileOut( __METHOD__."-interwiki" ); |
| 1697 | + wfProfileOut( "$fname-interwiki" ); |
1712 | 1698 | continue; |
1713 | 1699 | } |
1714 | | - wfProfileOut( __METHOD__."-interwiki" ); |
| 1700 | + wfProfileOut( "$fname-interwiki" ); |
1715 | 1701 | |
1716 | 1702 | if ( $ns == NS_IMAGE ) { |
1717 | | - wfProfileIn( __METHOD__."-image" ); |
| 1703 | + wfProfileIn( "$fname-image" ); |
1718 | 1704 | if ( !wfIsBadImage( $nt->getDBkey(), $this->mTitle ) ) { |
1719 | 1705 | # recursively parse links inside the image caption |
1720 | 1706 | # actually, this will parse them in any other parameters, too, |
1721 | 1707 | # but it might be hard to fix that, and it doesn't matter ATM |
1722 | 1708 | $text = $this->replaceExternalLinks($text); |
1723 | | - $holders->merge( $this->replaceInternalLinks2( $text ) ); |
| 1709 | + $text = $this->replaceInternalLinks($text); |
1724 | 1710 | |
1725 | 1711 | # cloak any absolute URLs inside the image markup, so replaceExternalLinks() won't touch them |
1726 | | - $s .= $prefix . $this->armorLinks( $this->makeImage( $nt, $text, $holders ) ) . $trail; |
| 1712 | + $s .= $prefix . $this->armorLinks( $this->makeImage( $nt, $text ) ) . $trail; |
| 1713 | + $this->mOutput->addImage( $nt->getDBkey() ); |
| 1714 | + |
| 1715 | + wfProfileOut( "$fname-image" ); |
| 1716 | + continue; |
| 1717 | + } else { |
| 1718 | + # We still need to record the image's presence on the page |
| 1719 | + $this->mOutput->addImage( $nt->getDBkey() ); |
1727 | 1720 | } |
1728 | | - $this->mOutput->addImage( $nt->getDBkey() ); |
1729 | | - wfProfileOut( __METHOD__."-image" ); |
1730 | | - continue; |
| 1721 | + wfProfileOut( "$fname-image" ); |
1731 | 1722 | |
1732 | 1723 | } |
1733 | 1724 | |
1734 | 1725 | if ( $ns == NS_CATEGORY ) { |
1735 | | - wfProfileIn( __METHOD__."-category" ); |
| 1726 | + wfProfileIn( "$fname-category" ); |
1736 | 1727 | $s = rtrim($s . "\n"); # bug 87 |
1737 | 1728 | |
1738 | 1729 | if ( $wasblank ) { |
— | — | @@ -1750,7 +1741,7 @@ |
1751 | 1742 | */ |
1752 | 1743 | $s .= trim($prefix . $trail, "\n") == '' ? '': $prefix . $trail; |
1753 | 1744 | |
1754 | | - wfProfileOut( __METHOD__."-category" ); |
| 1745 | + wfProfileOut( "$fname-category" ); |
1755 | 1746 | continue; |
1756 | 1747 | } |
1757 | 1748 | } |
— | — | @@ -1781,7 +1772,7 @@ |
1782 | 1773 | if( SpecialPage::exists( $nt->getDBkey() ) ) { |
1783 | 1774 | $s .= $this->makeKnownLinkHolder( $nt, $text, '', $trail, $prefix ); |
1784 | 1775 | } else { |
1785 | | - $s .= $holders->makeHolder( $nt, $text, '', $trail, $prefix ); |
| 1776 | + $s .= $this->makeLinkHolder( $nt, $text, '', $trail, $prefix ); |
1786 | 1777 | } |
1787 | 1778 | continue; |
1788 | 1779 | } elseif( $ns == NS_IMAGE ) { |
— | — | @@ -1795,10 +1786,10 @@ |
1796 | 1787 | continue; |
1797 | 1788 | } |
1798 | 1789 | } |
1799 | | - $s .= $holders->makeHolder( $nt, $text, '', $trail, $prefix ); |
| 1790 | + $s .= $this->makeLinkHolder( $nt, $text, '', $trail, $prefix ); |
1800 | 1791 | } |
1801 | | - wfProfileOut( __METHOD__ ); |
1802 | | - return $holders; |
| 1792 | + wfProfileOut( $fname ); |
| 1793 | + return $s; |
1803 | 1794 | } |
1804 | 1795 | |
1805 | 1796 | /** |
— | — | @@ -1807,10 +1798,32 @@ |
1808 | 1799 | * parsing of interwiki links, and secondly to allow all existence checks and |
1809 | 1800 | * article length checks (for stub links) to be bundled into a single query. |
1810 | 1801 | * |
1811 | | - * @deprecated |
1812 | 1802 | */ |
1813 | 1803 | function makeLinkHolder( &$nt, $text = '', $query = '', $trail = '', $prefix = '' ) { |
1814 | | - return $this->mLinkHolders->makeHolder( $nt, $text, $query, $trail, $prefix ); |
| 1804 | + wfProfileIn( __METHOD__ ); |
| 1805 | + if ( ! is_object($nt) ) { |
| 1806 | + # Fail gracefully |
| 1807 | + $retVal = "<!-- ERROR -->{$prefix}{$text}{$trail}"; |
| 1808 | + } else { |
| 1809 | + # Separate the link trail from the rest of the link |
| 1810 | + list( $inside, $trail ) = Linker::splitTrail( $trail ); |
| 1811 | + |
| 1812 | + if ( $nt->isExternal() ) { |
| 1813 | + $nr = array_push( $this->mInterwikiLinkHolders['texts'], $prefix.$text.$inside ); |
| 1814 | + $this->mInterwikiLinkHolders['titles'][] = $nt; |
| 1815 | + $retVal = '<!--IWLINK '. ($nr-1) ."-->{$trail}"; |
| 1816 | + } else { |
| 1817 | + $nr = array_push( $this->mLinkHolders['namespaces'], $nt->getNamespace() ); |
| 1818 | + $this->mLinkHolders['dbkeys'][] = $nt->getDBkey(); |
| 1819 | + $this->mLinkHolders['queries'][] = $query; |
| 1820 | + $this->mLinkHolders['texts'][] = $prefix.$text.$inside; |
| 1821 | + $this->mLinkHolders['titles'][] = $nt; |
| 1822 | + |
| 1823 | + $retVal = '<!--LINK '. ($nr-1) ."-->{$trail}"; |
| 1824 | + } |
| 1825 | + } |
| 1826 | + wfProfileOut( __METHOD__ ); |
| 1827 | + return $retVal; |
1815 | 1828 | } |
1816 | 1829 | |
1817 | 1830 | /** |
— | — | @@ -1876,7 +1889,8 @@ |
1877 | 1890 | # ../ -- convert to CurrentPage, from CurrentPage/CurrentSubPage |
1878 | 1891 | # ../Foobar -- convert to CurrentPage/Foobar, from CurrentPage/CurrentSubPage |
1879 | 1892 | |
1880 | | - wfProfileIn( __METHOD__ ); |
| 1893 | + $fname = 'Parser::maybeDoSubpageLink'; |
| 1894 | + wfProfileIn( $fname ); |
1881 | 1895 | $ret = $target; # default return value is no change |
1882 | 1896 | |
1883 | 1897 | # Some namespaces don't allow subpages, |
— | — | @@ -1892,7 +1906,7 @@ |
1893 | 1907 | # bug 7425 |
1894 | 1908 | $target = trim( $target ); |
1895 | 1909 | # Look at the first character |
1896 | | - if( $target != '' && $target{0} === '/' ) { |
| 1910 | + if( $target != '' && $target{0} == '/' ) { |
1897 | 1911 | # / at end means we don't want the slash to be shown |
1898 | 1912 | $m = array(); |
1899 | 1913 | $trailingSlashes = preg_match_all( '%(/+)$%', $target, $m ); |
— | — | @@ -1919,7 +1933,7 @@ |
1920 | 1934 | if( count( $exploded ) > $dotdotcount ) { # not allowed to go below top level page |
1921 | 1935 | $ret = implode( '/', array_slice( $exploded, 0, -$dotdotcount ) ); |
1922 | 1936 | # / at the end means don't show full path |
1923 | | - if( substr( $nodotdot, -1, 1 ) === '/' ) { |
| 1937 | + if( substr( $nodotdot, -1, 1 ) == '/' ) { |
1924 | 1938 | $nodotdot = substr( $nodotdot, 0, -1 ); |
1925 | 1939 | if( '' === $text ) { |
1926 | 1940 | $text = $nodotdot . $suffix; |
— | — | @@ -1935,7 +1949,7 @@ |
1936 | 1950 | } |
1937 | 1951 | } |
1938 | 1952 | |
1939 | | - wfProfileOut( __METHOD__ ); |
| 1953 | + wfProfileOut( $fname ); |
1940 | 1954 | return $ret; |
1941 | 1955 | } |
1942 | 1956 | |
— | — | @@ -1955,7 +1969,7 @@ |
1956 | 1970 | # getCommon() returns the length of the longest common substring |
1957 | 1971 | # of both arguments, starting at the beginning of both. |
1958 | 1972 | # |
1959 | | - /* private */ static function getCommon( $st1, $st2 ) { |
| 1973 | + /* private */ function getCommon( $st1, $st2 ) { |
1960 | 1974 | $fl = strlen( $st1 ); |
1961 | 1975 | $shorter = strlen( $st2 ); |
1962 | 1976 | if ( $fl < $shorter ) { $shorter = $fl; } |
— | — | @@ -1971,10 +1985,10 @@ |
1972 | 1986 | /* private */ function openList( $char ) { |
1973 | 1987 | $result = $this->closeParagraph(); |
1974 | 1988 | |
1975 | | - if ( '*' === $char ) { $result .= '<ul><li>'; } |
1976 | | - else if ( '#' === $char ) { $result .= '<ol><li>'; } |
1977 | | - else if ( ':' === $char ) { $result .= '<dl><dd>'; } |
1978 | | - else if ( ';' === $char ) { |
| 1989 | + if ( '*' == $char ) { $result .= '<ul><li>'; } |
| 1990 | + else if ( '#' == $char ) { $result .= '<ol><li>'; } |
| 1991 | + else if ( ':' == $char ) { $result .= '<dl><dd>'; } |
| 1992 | + else if ( ';' == $char ) { |
1979 | 1993 | $result .= '<dl><dt>'; |
1980 | 1994 | $this->mDTopen = true; |
1981 | 1995 | } |
— | — | @@ -1984,11 +1998,11 @@ |
1985 | 1999 | } |
1986 | 2000 | |
1987 | 2001 | /* private */ function nextItem( $char ) { |
1988 | | - if ( '*' === $char || '#' === $char ) { return '</li><li>'; } |
1989 | | - else if ( ':' === $char || ';' === $char ) { |
| 2002 | + if ( '*' == $char || '#' == $char ) { return '</li><li>'; } |
| 2003 | + else if ( ':' == $char || ';' == $char ) { |
1990 | 2004 | $close = '</dd>'; |
1991 | 2005 | if ( $this->mDTopen ) { $close = '</dt>'; } |
1992 | | - if ( ';' === $char ) { |
| 2006 | + if ( ';' == $char ) { |
1993 | 2007 | $this->mDTopen = true; |
1994 | 2008 | return $close . '<dt>'; |
1995 | 2009 | } else { |
— | — | @@ -2000,9 +2014,9 @@ |
2001 | 2015 | } |
2002 | 2016 | |
2003 | 2017 | /* private */ function closeList( $char ) { |
2004 | | - if ( '*' === $char ) { $text = '</li></ul>'; } |
2005 | | - else if ( '#' === $char ) { $text = '</li></ol>'; } |
2006 | | - else if ( ':' === $char ) { |
| 2018 | + if ( '*' == $char ) { $text = '</li></ul>'; } |
| 2019 | + else if ( '#' == $char ) { $text = '</li></ol>'; } |
| 2020 | + else if ( ':' == $char ) { |
2007 | 2021 | if ( $this->mDTopen ) { |
2008 | 2022 | $this->mDTopen = false; |
2009 | 2023 | $text = '</dt></dl>'; |
— | — | @@ -2022,53 +2036,50 @@ |
2023 | 2037 | * @return string the lists rendered as HTML |
2024 | 2038 | */ |
2025 | 2039 | function doBlockLevels( $text, $linestart ) { |
2026 | | - wfProfileIn( __METHOD__ ); |
| 2040 | + $fname = 'Parser::doBlockLevels'; |
| 2041 | + wfProfileIn( $fname ); |
2027 | 2042 | |
2028 | 2043 | # Parsing through the text line by line. The main thing |
2029 | 2044 | # happening here is handling of block-level elements p, pre, |
2030 | 2045 | # and making lists from lines starting with * # : etc. |
2031 | 2046 | # |
2032 | | - $textLines = StringUtils::explode( "\n", $text ); |
| 2047 | + $textLines = explode( "\n", $text ); |
2033 | 2048 | |
2034 | 2049 | $lastPrefix = $output = ''; |
2035 | 2050 | $this->mDTopen = $inBlockElem = false; |
2036 | 2051 | $prefixLength = 0; |
2037 | 2052 | $paragraphStack = false; |
2038 | 2053 | |
| 2054 | + if ( !$linestart ) { |
| 2055 | + $output .= array_shift( $textLines ); |
| 2056 | + } |
2039 | 2057 | foreach ( $textLines as $oLine ) { |
2040 | | - # Fix up $linestart |
2041 | | - if ( !$linestart ) { |
2042 | | - $output .= $oLine; |
2043 | | - $linestart = true; |
2044 | | - continue; |
2045 | | - } |
2046 | | - |
2047 | 2058 | $lastPrefixLength = strlen( $lastPrefix ); |
2048 | 2059 | $preCloseMatch = preg_match('/<\\/pre/i', $oLine ); |
2049 | 2060 | $preOpenMatch = preg_match('/<pre/i', $oLine ); |
2050 | 2061 | if ( !$this->mInPre ) { |
2051 | 2062 | # Multiple prefixes may abut each other for nested lists. |
2052 | 2063 | $prefixLength = strspn( $oLine, '*#:;' ); |
2053 | | - $prefix = substr( $oLine, 0, $prefixLength ); |
| 2064 | + $pref = substr( $oLine, 0, $prefixLength ); |
2054 | 2065 | |
2055 | 2066 | # eh? |
2056 | | - $prefix2 = str_replace( ';', ':', $prefix ); |
| 2067 | + $pref2 = str_replace( ';', ':', $pref ); |
2057 | 2068 | $t = substr( $oLine, $prefixLength ); |
2058 | | - $this->mInPre = (bool)$preOpenMatch; |
| 2069 | + $this->mInPre = !empty($preOpenMatch); |
2059 | 2070 | } else { |
2060 | 2071 | # Don't interpret any other prefixes in preformatted text |
2061 | 2072 | $prefixLength = 0; |
2062 | | - $prefix = $prefix2 = ''; |
| 2073 | + $pref = $pref2 = ''; |
2063 | 2074 | $t = $oLine; |
2064 | 2075 | } |
2065 | 2076 | |
2066 | 2077 | # List generation |
2067 | | - if( $prefixLength && $lastPrefix === $prefix2 ) { |
| 2078 | + if( $prefixLength && 0 == strcmp( $lastPrefix, $pref2 ) ) { |
2068 | 2079 | # Same as the last item, so no need to deal with nesting or opening stuff |
2069 | | - $output .= $this->nextItem( substr( $prefix, -1 ) ); |
| 2080 | + $output .= $this->nextItem( substr( $pref, -1 ) ); |
2070 | 2081 | $paragraphStack = false; |
2071 | 2082 | |
2072 | | - if ( substr( $prefix, -1 ) === ';') { |
| 2083 | + if ( substr( $pref, -1 ) == ';') { |
2073 | 2084 | # The one nasty exception: definition lists work like this: |
2074 | 2085 | # ; title : definition text |
2075 | 2086 | # So we check for : in the remainder text to split up the |
— | — | @@ -2081,21 +2092,21 @@ |
2082 | 2093 | } |
2083 | 2094 | } elseif( $prefixLength || $lastPrefixLength ) { |
2084 | 2095 | # Either open or close a level... |
2085 | | - $commonPrefixLength = $this->getCommon( $prefix, $lastPrefix ); |
| 2096 | + $commonPrefixLength = $this->getCommon( $pref, $lastPrefix ); |
2086 | 2097 | $paragraphStack = false; |
2087 | 2098 | |
2088 | 2099 | while( $commonPrefixLength < $lastPrefixLength ) { |
2089 | | - $output .= $this->closeList( $lastPrefix[$lastPrefixLength-1] ); |
| 2100 | + $output .= $this->closeList( $lastPrefix{$lastPrefixLength-1} ); |
2090 | 2101 | --$lastPrefixLength; |
2091 | 2102 | } |
2092 | 2103 | if ( $prefixLength <= $commonPrefixLength && $commonPrefixLength > 0 ) { |
2093 | | - $output .= $this->nextItem( $prefix[$commonPrefixLength-1] ); |
| 2104 | + $output .= $this->nextItem( $pref{$commonPrefixLength-1} ); |
2094 | 2105 | } |
2095 | 2106 | while ( $prefixLength > $commonPrefixLength ) { |
2096 | | - $char = substr( $prefix, $commonPrefixLength, 1 ); |
| 2107 | + $char = substr( $pref, $commonPrefixLength, 1 ); |
2097 | 2108 | $output .= $this->openList( $char ); |
2098 | 2109 | |
2099 | | - if ( ';' === $char ) { |
| 2110 | + if ( ';' == $char ) { |
2100 | 2111 | # FIXME: This is dupe of code above |
2101 | 2112 | if ($this->findColonNoLinks($t, $term, $t2) !== false) { |
2102 | 2113 | $t = $t2; |
— | — | @@ -2104,10 +2115,10 @@ |
2105 | 2116 | } |
2106 | 2117 | ++$commonPrefixLength; |
2107 | 2118 | } |
2108 | | - $lastPrefix = $prefix2; |
| 2119 | + $lastPrefix = $pref2; |
2109 | 2120 | } |
2110 | 2121 | if( 0 == $prefixLength ) { |
2111 | | - wfProfileIn( __METHOD__."-paragraph" ); |
| 2122 | + wfProfileIn( "$fname-paragraph" ); |
2112 | 2123 | # No prefix (not in list)--go to paragraph mode |
2113 | 2124 | // XXX: use a stack for nestable elements like span, table and div |
2114 | 2125 | $openmatch = preg_match('/(?:<table|<blockquote|<h1|<h2|<h3|<h4|<h5|<h6|<pre|<tr|<p|<ul|<ol|<li|<\\/tr|<\\/td|<\\/th)/iS', $t ); |
— | — | @@ -2127,9 +2138,9 @@ |
2128 | 2139 | $inBlockElem = true; |
2129 | 2140 | } |
2130 | 2141 | } else if ( !$inBlockElem && !$this->mInPre ) { |
2131 | | - if ( ' ' == $t{0} and ( $this->mLastSection === 'pre' or trim($t) != '' ) ) { |
| 2142 | + if ( ' ' == $t{0} and ( $this->mLastSection == 'pre' or trim($t) != '' ) ) { |
2132 | 2143 | // pre |
2133 | | - if ($this->mLastSection !== 'pre') { |
| 2144 | + if ($this->mLastSection != 'pre') { |
2134 | 2145 | $paragraphStack = false; |
2135 | 2146 | $output .= $this->closeParagraph().'<pre>'; |
2136 | 2147 | $this->mLastSection = 'pre'; |
— | — | @@ -2143,7 +2154,7 @@ |
2144 | 2155 | $paragraphStack = false; |
2145 | 2156 | $this->mLastSection = 'p'; |
2146 | 2157 | } else { |
2147 | | - if ($this->mLastSection !== 'p' ) { |
| 2158 | + if ($this->mLastSection != 'p' ) { |
2148 | 2159 | $output .= $this->closeParagraph(); |
2149 | 2160 | $this->mLastSection = ''; |
2150 | 2161 | $paragraphStack = '<p>'; |
— | — | @@ -2156,14 +2167,14 @@ |
2157 | 2168 | $output .= $paragraphStack; |
2158 | 2169 | $paragraphStack = false; |
2159 | 2170 | $this->mLastSection = 'p'; |
2160 | | - } else if ($this->mLastSection !== 'p') { |
| 2171 | + } else if ($this->mLastSection != 'p') { |
2161 | 2172 | $output .= $this->closeParagraph().'<p>'; |
2162 | 2173 | $this->mLastSection = 'p'; |
2163 | 2174 | } |
2164 | 2175 | } |
2165 | 2176 | } |
2166 | 2177 | } |
2167 | | - wfProfileOut( __METHOD__."-paragraph" ); |
| 2178 | + wfProfileOut( "$fname-paragraph" ); |
2168 | 2179 | } |
2169 | 2180 | // somewhere above we forget to get out of pre block (bug 785) |
2170 | 2181 | if($preCloseMatch && $this->mInPre) { |
— | — | @@ -2174,7 +2185,7 @@ |
2175 | 2186 | } |
2176 | 2187 | } |
2177 | 2188 | while ( $prefixLength ) { |
2178 | | - $output .= $this->closeList( $prefix2[$prefixLength-1] ); |
| 2189 | + $output .= $this->closeList( $pref2{$prefixLength-1} ); |
2179 | 2190 | --$prefixLength; |
2180 | 2191 | } |
2181 | 2192 | if ( '' != $this->mLastSection ) { |
— | — | @@ -2182,7 +2193,7 @@ |
2183 | 2194 | $this->mLastSection = ''; |
2184 | 2195 | } |
2185 | 2196 | |
2186 | | - wfProfileOut( __METHOD__ ); |
| 2197 | + wfProfileOut( $fname ); |
2187 | 2198 | return $output; |
2188 | 2199 | } |
2189 | 2200 | |
— | — | @@ -2194,13 +2205,14 @@ |
2195 | 2206 | * @param string &$after set to everything after the ':' |
2196 | 2207 | * return string the position of the ':', or false if none found |
2197 | 2208 | */ |
2198 | | - static function findColonNoLinks($str, &$before, &$after) { |
2199 | | - wfProfileIn( __METHOD__ ); |
| 2209 | + function findColonNoLinks($str, &$before, &$after) { |
| 2210 | + $fname = 'Parser::findColonNoLinks'; |
| 2211 | + wfProfileIn( $fname ); |
2200 | 2212 | |
2201 | 2213 | $pos = strpos( $str, ':' ); |
2202 | 2214 | if( $pos === false ) { |
2203 | 2215 | // Nothing to find! |
2204 | | - wfProfileOut( __METHOD__ ); |
| 2216 | + wfProfileOut( $fname ); |
2205 | 2217 | return false; |
2206 | 2218 | } |
2207 | 2219 | |
— | — | @@ -2209,7 +2221,7 @@ |
2210 | 2222 | // Easy; no tag nesting to worry about |
2211 | 2223 | $before = substr( $str, 0, $pos ); |
2212 | 2224 | $after = substr( $str, $pos+1 ); |
2213 | | - wfProfileOut( __METHOD__ ); |
| 2225 | + wfProfileOut( $fname ); |
2214 | 2226 | return $pos; |
2215 | 2227 | } |
2216 | 2228 | |
— | — | @@ -2233,7 +2245,7 @@ |
2234 | 2246 | // We found it! |
2235 | 2247 | $before = substr( $str, 0, $i ); |
2236 | 2248 | $after = substr( $str, $i + 1 ); |
2237 | | - wfProfileOut( __METHOD__ ); |
| 2249 | + wfProfileOut( $fname ); |
2238 | 2250 | return $i; |
2239 | 2251 | } |
2240 | 2252 | // Embedded in a tag; don't break it. |
— | — | @@ -2243,7 +2255,7 @@ |
2244 | 2256 | $colon = strpos( $str, ':', $i ); |
2245 | 2257 | if( $colon === false ) { |
2246 | 2258 | // Nothing else interesting |
2247 | | - wfProfileOut( __METHOD__ ); |
| 2259 | + wfProfileOut( $fname ); |
2248 | 2260 | return false; |
2249 | 2261 | } |
2250 | 2262 | $lt = strpos( $str, '<', $i ); |
— | — | @@ -2252,7 +2264,7 @@ |
2253 | 2265 | // We found it! |
2254 | 2266 | $before = substr( $str, 0, $colon ); |
2255 | 2267 | $after = substr( $str, $colon + 1 ); |
2256 | | - wfProfileOut( __METHOD__ ); |
| 2268 | + wfProfileOut( $fname ); |
2257 | 2269 | return $i; |
2258 | 2270 | } |
2259 | 2271 | } |
— | — | @@ -2299,18 +2311,18 @@ |
2300 | 2312 | break; |
2301 | 2313 | case 3: // self::COLON_STATE_CLOSETAG: |
2302 | 2314 | // In a </tag> |
2303 | | - if( $c === ">" ) { |
| 2315 | + if( $c == ">" ) { |
2304 | 2316 | $stack--; |
2305 | 2317 | if( $stack < 0 ) { |
2306 | | - wfDebug( __METHOD__.": Invalid input; too many close tags\n" ); |
2307 | | - wfProfileOut( __METHOD__ ); |
| 2318 | + wfDebug( "Invalid input in $fname; too many close tags\n" ); |
| 2319 | + wfProfileOut( $fname ); |
2308 | 2320 | return false; |
2309 | 2321 | } |
2310 | 2322 | $state = self::COLON_STATE_TEXT; |
2311 | 2323 | } |
2312 | 2324 | break; |
2313 | 2325 | case self::COLON_STATE_TAGSLASH: |
2314 | | - if( $c === ">" ) { |
| 2326 | + if( $c == ">" ) { |
2315 | 2327 | // Yes, a self-closed tag <blah/> |
2316 | 2328 | $state = self::COLON_STATE_TEXT; |
2317 | 2329 | } else { |
— | — | @@ -2319,33 +2331,33 @@ |
2320 | 2332 | } |
2321 | 2333 | break; |
2322 | 2334 | case 5: // self::COLON_STATE_COMMENT: |
2323 | | - if( $c === "-" ) { |
| 2335 | + if( $c == "-" ) { |
2324 | 2336 | $state = self::COLON_STATE_COMMENTDASH; |
2325 | 2337 | } |
2326 | 2338 | break; |
2327 | 2339 | case self::COLON_STATE_COMMENTDASH: |
2328 | | - if( $c === "-" ) { |
| 2340 | + if( $c == "-" ) { |
2329 | 2341 | $state = self::COLON_STATE_COMMENTDASHDASH; |
2330 | 2342 | } else { |
2331 | 2343 | $state = self::COLON_STATE_COMMENT; |
2332 | 2344 | } |
2333 | 2345 | break; |
2334 | 2346 | case self::COLON_STATE_COMMENTDASHDASH: |
2335 | | - if( $c === ">" ) { |
| 2347 | + if( $c == ">" ) { |
2336 | 2348 | $state = self::COLON_STATE_TEXT; |
2337 | 2349 | } else { |
2338 | 2350 | $state = self::COLON_STATE_COMMENT; |
2339 | 2351 | } |
2340 | 2352 | break; |
2341 | 2353 | default: |
2342 | | - throw new MWException( "State machine error in " . __METHOD__ ); |
| 2354 | + throw new MWException( "State machine error in $fname" ); |
2343 | 2355 | } |
2344 | 2356 | } |
2345 | 2357 | if( $stack > 0 ) { |
2346 | | - wfDebug( __METHOD__.": Invalid input; not enough close tags (stack $stack, state $state)\n" ); |
| 2358 | + wfDebug( "Invalid input in $fname; not enough close tags (stack $stack, state $state)\n" ); |
2347 | 2359 | return false; |
2348 | 2360 | } |
2349 | | - wfProfileOut( __METHOD__ ); |
| 2361 | + wfProfileOut( $fname ); |
2350 | 2362 | return false; |
2351 | 2363 | } |
2352 | 2364 | |
— | — | @@ -2575,11 +2587,12 @@ |
2576 | 2588 | * @private |
2577 | 2589 | */ |
2578 | 2590 | function initialiseVariables() { |
2579 | | - wfProfileIn( __METHOD__ ); |
| 2591 | + $fname = 'Parser::initialiseVariables'; |
| 2592 | + wfProfileIn( $fname ); |
2580 | 2593 | $variableIDs = MagicWord::getVariableIDs(); |
2581 | 2594 | |
2582 | 2595 | $this->mVariables = new MagicWordArray( $variableIDs ); |
2583 | | - wfProfileOut( __METHOD__ ); |
| 2596 | + wfProfileOut( $fname ); |
2584 | 2597 | } |
2585 | 2598 | |
2586 | 2599 | /** |
— | — | @@ -2648,7 +2661,8 @@ |
2649 | 2662 | return $text; |
2650 | 2663 | } |
2651 | 2664 | |
2652 | | - wfProfileIn( __METHOD__ ); |
| 2665 | + $fname = __METHOD__; |
| 2666 | + wfProfileIn( $fname ); |
2653 | 2667 | |
2654 | 2668 | if ( $frame === false ) { |
2655 | 2669 | $frame = $this->getPreprocessor()->newFrame(); |
— | — | @@ -2661,7 +2675,7 @@ |
2662 | 2676 | $flags = $argsOnly ? PPFrame::NO_TEMPLATES : 0; |
2663 | 2677 | $text = $frame->expand( $dom, $flags ); |
2664 | 2678 | |
2665 | | - wfProfileOut( __METHOD__ ); |
| 2679 | + wfProfileOut( $fname ); |
2666 | 2680 | return $text; |
2667 | 2681 | } |
2668 | 2682 | |
— | — | @@ -2724,7 +2738,8 @@ |
2725 | 2739 | */ |
2726 | 2740 | function braceSubstitution( $piece, $frame ) { |
2727 | 2741 | global $wgContLang, $wgLang, $wgAllowDisplayTitle, $wgNonincludableNamespaces; |
2728 | | - wfProfileIn( __METHOD__ ); |
| 2742 | + $fname = __METHOD__; |
| 2743 | + wfProfileIn( $fname ); |
2729 | 2744 | wfProfileIn( __METHOD__.'-setup' ); |
2730 | 2745 | |
2731 | 2746 | # Flags |
— | — | @@ -2911,7 +2926,7 @@ |
2912 | 2927 | } |
2913 | 2928 | } else if ( $wgNonincludableNamespaces && in_array( $title->getNamespace(), $wgNonincludableNamespaces ) ) { |
2914 | 2929 | $found = false; //access denied |
2915 | | - wfDebug( __METHOD__.": template inclusion denied for " . $title->getPrefixedDBkey() ); |
| 2930 | + wfDebug( "$fname: template inclusion denied for " . $title->getPrefixedDBkey() ); |
2916 | 2931 | } else { |
2917 | 2932 | list( $text, $title ) = $this->getTemplateDom( $title ); |
2918 | 2933 | if ( $text !== false ) { |
— | — | @@ -2945,7 +2960,7 @@ |
2946 | 2961 | # Recover the source wikitext and return it |
2947 | 2962 | if ( !$found ) { |
2948 | 2963 | $text = $frame->virtualBracketedImplode( '{{', '|', '}}', $titleWithSpaces, $args ); |
2949 | | - wfProfileOut( __METHOD__ ); |
| 2964 | + wfProfileOut( $fname ); |
2950 | 2965 | return array( 'object' => $text ); |
2951 | 2966 | } |
2952 | 2967 | |
— | — | @@ -3004,7 +3019,7 @@ |
3005 | 3020 | $ret = array( 'text' => $text ); |
3006 | 3021 | } |
3007 | 3022 | |
3008 | | - wfProfileOut( __METHOD__ ); |
| 3023 | + wfProfileOut( $fname ); |
3009 | 3024 | return $ret; |
3010 | 3025 | } |
3011 | 3026 | |
— | — | @@ -3143,7 +3158,7 @@ |
3144 | 3159 | return $this->fetchScaryTemplateMaybeFromCache($url); |
3145 | 3160 | } |
3146 | 3161 | |
3147 | | - static function fetchScaryTemplateMaybeFromCache($url) { |
| 3162 | + function fetchScaryTemplateMaybeFromCache($url) { |
3148 | 3163 | global $wgTranscludeCacheExpiry; |
3149 | 3164 | $dbr = wfGetDB(DB_SLAVE); |
3150 | 3165 | $obj = $dbr->selectRow('transcache', array('tc_time', 'tc_contents'), |
— | — | @@ -3291,7 +3306,7 @@ |
3292 | 3307 | } |
3293 | 3308 | } |
3294 | 3309 | |
3295 | | - if ( $name === 'html' || $name === 'nowiki' ) { |
| 3310 | + if ( $name == 'html' || $name == 'nowiki' ) { |
3296 | 3311 | $this->mStripState->nowiki->setPair( $marker, $output ); |
3297 | 3312 | } else { |
3298 | 3313 | $this->mStripState->general->setPair( $marker, $output ); |
— | — | @@ -3547,7 +3562,12 @@ |
3548 | 3563 | # <!--LINK number--> |
3549 | 3564 | # turns into |
3550 | 3565 | # link text with suffix |
3551 | | - $safeHeadline = $this->replaceLinkHoldersText( $safeHeadline ); |
| 3566 | + $safeHeadline = preg_replace( '/<!--LINK ([0-9]*)-->/e', |
| 3567 | + "\$this->mLinkHolders['texts'][\$1]", |
| 3568 | + $safeHeadline ); |
| 3569 | + $safeHeadline = preg_replace( '/<!--IWLINK ([0-9]*)-->/e', |
| 3570 | + "\$this->mInterwikiLinkHolders['texts'][\$1]", |
| 3571 | + $safeHeadline ); |
3552 | 3572 | |
3553 | 3573 | # Strip out HTML (other than plain <sup> and <sub>: bug 8393) |
3554 | 3574 | $tocline = preg_replace( |
— | — | @@ -3623,7 +3643,7 @@ |
3624 | 3644 | $i = 0; |
3625 | 3645 | |
3626 | 3646 | foreach( $blocks as $block ) { |
3627 | | - if( $showEditLink && $headlineCount > 0 && $i == 0 && $block !== "\n" ) { |
| 3647 | + if( $showEditLink && $headlineCount > 0 && $i == 0 && $block != "\n" ) { |
3628 | 3648 | # This is the [edit] link that appears for the top block of text when |
3629 | 3649 | # section editing is enabled |
3630 | 3650 | |
— | — | @@ -3775,7 +3795,7 @@ |
3776 | 3796 | } else { |
3777 | 3797 | # Failed to validate; fall back to the default |
3778 | 3798 | $nickname = $username; |
3779 | | - wfDebug( __METHOD__.": $username has bad XML tags in signature.\n" ); |
| 3799 | + wfDebug( "Parser::getUserSig: $username has bad XML tags in signature.\n" ); |
3780 | 3800 | } |
3781 | 3801 | } |
3782 | 3802 | |
— | — | @@ -3798,7 +3818,7 @@ |
3799 | 3819 | * @param string $text |
3800 | 3820 | * @return mixed An expanded string, or false if invalid. |
3801 | 3821 | */ |
3802 | | - static function validateSig( $text ) { |
| 3822 | + function validateSig( $text ) { |
3803 | 3823 | return( wfIsWellFormedXmlFragment( $text ) ? $text : false ); |
3804 | 3824 | } |
3805 | 3825 | |
— | — | @@ -3850,7 +3870,7 @@ |
3851 | 3871 | * @param string $text |
3852 | 3872 | * @return string Signature text with /~{3,5}/ removed |
3853 | 3873 | */ |
3854 | | - static function cleanSigInSig( $text ) { |
| 3874 | + function cleanSigInSig( $text ) { |
3855 | 3875 | $text = preg_replace( '/~{3,5}/', '', $text ); |
3856 | 3876 | return $text; |
3857 | 3877 | } |
— | — | @@ -3881,17 +3901,19 @@ |
3882 | 3902 | global $wgTitle; |
3883 | 3903 | static $executing = false; |
3884 | 3904 | |
| 3905 | + $fname = "Parser::transformMsg"; |
| 3906 | + |
3885 | 3907 | # Guard against infinite recursion |
3886 | 3908 | if ( $executing ) { |
3887 | 3909 | return $text; |
3888 | 3910 | } |
3889 | 3911 | $executing = true; |
3890 | 3912 | |
3891 | | - wfProfileIn(__METHOD__); |
| 3913 | + wfProfileIn($fname); |
3892 | 3914 | $text = $this->preprocess( $text, $wgTitle, $options ); |
3893 | 3915 | |
3894 | 3916 | $executing = false; |
3895 | | - wfProfileOut(__METHOD__); |
| 3917 | + wfProfileOut($fname); |
3896 | 3918 | return $text; |
3897 | 3919 | } |
3898 | 3920 | |
— | — | @@ -3988,7 +4010,7 @@ |
3989 | 4011 | # Add to function cache |
3990 | 4012 | $mw = MagicWord::get( $id ); |
3991 | 4013 | if( !$mw ) |
3992 | | - throw new MWException( __METHOD__.'() expecting a magic word identifier.' ); |
| 4014 | + throw new MWException( 'Parser::setFunctionHook() expecting a magic word identifier.' ); |
3993 | 4015 | |
3994 | 4016 | $synonyms = $mw->getSynonyms(); |
3995 | 4017 | $sensitive = intval( $mw->isCaseSensitive() ); |
— | — | @@ -4003,7 +4025,7 @@ |
4004 | 4026 | $syn = '#' . $syn; |
4005 | 4027 | } |
4006 | 4028 | # Remove trailing colon |
4007 | | - if ( substr( $syn, -1, 1 ) === ':' ) { |
| 4029 | + if ( substr( $syn, -1, 1 ) == ':' ) { |
4008 | 4030 | $syn = substr( $syn, 0, -1 ); |
4009 | 4031 | } |
4010 | 4032 | $this->mFunctionSynonyms[$sensitive][$syn] = $id; |
— | — | @@ -4024,9 +4046,266 @@ |
4025 | 4047 | * Replace <!--LINK--> link placeholders with actual links, in the buffer |
4026 | 4048 | * Placeholders created in Skin::makeLinkObj() |
4027 | 4049 | * Returns an array of link CSS classes, indexed by PDBK. |
| 4050 | + * $options is a bit field, RLH_FOR_UPDATE to select for update |
4028 | 4051 | */ |
4029 | 4052 | function replaceLinkHolders( &$text, $options = 0 ) { |
4030 | | - return $this->mLinkHolders->replace( $text ); |
| 4053 | + global $wgUser; |
| 4054 | + global $wgContLang; |
| 4055 | + |
| 4056 | + $fname = 'Parser::replaceLinkHolders'; |
| 4057 | + wfProfileIn( $fname ); |
| 4058 | + |
| 4059 | + $pdbks = array(); |
| 4060 | + $colours = array(); |
| 4061 | + $linkcolour_ids = array(); |
| 4062 | + $sk = $this->mOptions->getSkin(); |
| 4063 | + $linkCache = LinkCache::singleton(); |
| 4064 | + |
| 4065 | + if ( !empty( $this->mLinkHolders['namespaces'] ) ) { |
| 4066 | + wfProfileIn( $fname.'-check' ); |
| 4067 | + $dbr = wfGetDB( DB_SLAVE ); |
| 4068 | + $page = $dbr->tableName( 'page' ); |
| 4069 | + $threshold = $wgUser->getOption('stubthreshold'); |
| 4070 | + |
| 4071 | + # Sort by namespace |
| 4072 | + asort( $this->mLinkHolders['namespaces'] ); |
| 4073 | + |
| 4074 | + # Generate query |
| 4075 | + $query = false; |
| 4076 | + $current = null; |
| 4077 | + foreach ( $this->mLinkHolders['namespaces'] as $key => $ns ) { |
| 4078 | + # Make title object |
| 4079 | + $title = $this->mLinkHolders['titles'][$key]; |
| 4080 | + |
| 4081 | + # Skip invalid entries. |
| 4082 | + # Result will be ugly, but prevents crash. |
| 4083 | + if ( is_null( $title ) ) { |
| 4084 | + continue; |
| 4085 | + } |
| 4086 | + $pdbk = $pdbks[$key] = $title->getPrefixedDBkey(); |
| 4087 | + |
| 4088 | + # Check if it's a static known link, e.g. interwiki |
| 4089 | + if ( $title->isAlwaysKnown() ) { |
| 4090 | + $colours[$pdbk] = ''; |
| 4091 | + } elseif ( ( $id = $linkCache->getGoodLinkID( $pdbk ) ) != 0 ) { |
| 4092 | + $colours[$pdbk] = ''; |
| 4093 | + $this->mOutput->addLink( $title, $id ); |
| 4094 | + } elseif ( $linkCache->isBadLink( $pdbk ) ) { |
| 4095 | + $colours[$pdbk] = 'new'; |
| 4096 | + } elseif ( $title->getNamespace() == NS_SPECIAL && !SpecialPage::exists( $pdbk ) ) { |
| 4097 | + $colours[$pdbk] = 'new'; |
| 4098 | + } else { |
| 4099 | + # Not in the link cache, add it to the query |
| 4100 | + if ( !isset( $current ) ) { |
| 4101 | + $current = $ns; |
| 4102 | + $query = "SELECT page_id, page_namespace, page_title, page_is_redirect, page_len"; |
| 4103 | + $query .= " FROM $page WHERE (page_namespace=$ns AND page_title IN("; |
| 4104 | + } elseif ( $current != $ns ) { |
| 4105 | + $current = $ns; |
| 4106 | + $query .= ")) OR (page_namespace=$ns AND page_title IN("; |
| 4107 | + } else { |
| 4108 | + $query .= ', '; |
| 4109 | + } |
| 4110 | + |
| 4111 | + $query .= $dbr->addQuotes( $this->mLinkHolders['dbkeys'][$key] ); |
| 4112 | + } |
| 4113 | + } |
| 4114 | + if ( $query ) { |
| 4115 | + $query .= '))'; |
| 4116 | + if ( $options & RLH_FOR_UPDATE ) { |
| 4117 | + $query .= ' FOR UPDATE'; |
| 4118 | + } |
| 4119 | + |
| 4120 | + $res = $dbr->query( $query, $fname ); |
| 4121 | + |
| 4122 | + # Fetch data and form into an associative array |
| 4123 | + # non-existent = broken |
| 4124 | + while ( $s = $dbr->fetchObject($res) ) { |
| 4125 | + $title = Title::makeTitle( $s->page_namespace, $s->page_title ); |
| 4126 | + $pdbk = $title->getPrefixedDBkey(); |
| 4127 | + $linkCache->addGoodLinkObj( $s->page_id, $title, $s->page_len, $s->page_is_redirect ); |
| 4128 | + $this->mOutput->addLink( $title, $s->page_id ); |
| 4129 | + $colours[$pdbk] = $sk->getLinkColour( $title, $threshold ); |
| 4130 | + //add id to the extension todolist |
| 4131 | + $linkcolour_ids[$s->page_id] = $pdbk; |
| 4132 | + } |
| 4133 | + //pass an array of page_ids to an extension |
| 4134 | + wfRunHooks( 'GetLinkColours', array( $linkcolour_ids, &$colours ) ); |
| 4135 | + } |
| 4136 | + wfProfileOut( $fname.'-check' ); |
| 4137 | + |
| 4138 | + # Do a second query for different language variants of links and categories |
| 4139 | + if($wgContLang->hasVariants()){ |
| 4140 | + $linkBatch = new LinkBatch(); |
| 4141 | + $variantMap = array(); // maps $pdbkey_Variant => $keys (of link holders) |
| 4142 | + $categoryMap = array(); // maps $category_variant => $category (dbkeys) |
| 4143 | + $varCategories = array(); // category replacements oldDBkey => newDBkey |
| 4144 | + |
| 4145 | + $categories = $this->mOutput->getCategoryLinks(); |
| 4146 | + |
| 4147 | + // Add variants of links to link batch |
| 4148 | + foreach ( $this->mLinkHolders['namespaces'] as $key => $ns ) { |
| 4149 | + $title = $this->mLinkHolders['titles'][$key]; |
| 4150 | + if ( is_null( $title ) ) |
| 4151 | + continue; |
| 4152 | + |
| 4153 | + $pdbk = $title->getPrefixedDBkey(); |
| 4154 | + $titleText = $title->getText(); |
| 4155 | + |
| 4156 | + // generate all variants of the link title text |
| 4157 | + $allTextVariants = $wgContLang->convertLinkToAllVariants($titleText); |
| 4158 | + |
| 4159 | + // if link was not found (in first query), add all variants to query |
| 4160 | + if ( !isset($colours[$pdbk]) ){ |
| 4161 | + foreach($allTextVariants as $textVariant){ |
| 4162 | + if($textVariant != $titleText){ |
| 4163 | + $variantTitle = Title::makeTitle( $ns, $textVariant ); |
| 4164 | + if(is_null($variantTitle)) continue; |
| 4165 | + $linkBatch->addObj( $variantTitle ); |
| 4166 | + $variantMap[$variantTitle->getPrefixedDBkey()][] = $key; |
| 4167 | + } |
| 4168 | + } |
| 4169 | + } |
| 4170 | + } |
| 4171 | + |
| 4172 | + // process categories, check if a category exists in some variant |
| 4173 | + foreach( $categories as $category ){ |
| 4174 | + $variants = $wgContLang->convertLinkToAllVariants($category); |
| 4175 | + foreach($variants as $variant){ |
| 4176 | + if($variant != $category){ |
| 4177 | + $variantTitle = Title::newFromDBkey( Title::makeName(NS_CATEGORY,$variant) ); |
| 4178 | + if(is_null($variantTitle)) continue; |
| 4179 | + $linkBatch->addObj( $variantTitle ); |
| 4180 | + $categoryMap[$variant] = $category; |
| 4181 | + } |
| 4182 | + } |
| 4183 | + } |
| 4184 | + |
| 4185 | + |
| 4186 | + if(!$linkBatch->isEmpty()){ |
| 4187 | + // construct query |
| 4188 | + $titleClause = $linkBatch->constructSet('page', $dbr); |
| 4189 | + |
| 4190 | + $variantQuery = "SELECT page_id, page_namespace, page_title, page_is_redirect, page_len"; |
| 4191 | + |
| 4192 | + $variantQuery .= " FROM $page WHERE $titleClause"; |
| 4193 | + if ( $options & RLH_FOR_UPDATE ) { |
| 4194 | + $variantQuery .= ' FOR UPDATE'; |
| 4195 | + } |
| 4196 | + |
| 4197 | + $varRes = $dbr->query( $variantQuery, $fname ); |
| 4198 | + |
| 4199 | + // for each found variants, figure out link holders and replace |
| 4200 | + while ( $s = $dbr->fetchObject($varRes) ) { |
| 4201 | + |
| 4202 | + $variantTitle = Title::makeTitle( $s->page_namespace, $s->page_title ); |
| 4203 | + $varPdbk = $variantTitle->getPrefixedDBkey(); |
| 4204 | + $vardbk = $variantTitle->getDBkey(); |
| 4205 | + |
| 4206 | + $holderKeys = array(); |
| 4207 | + if(isset($variantMap[$varPdbk])){ |
| 4208 | + $holderKeys = $variantMap[$varPdbk]; |
| 4209 | + $linkCache->addGoodLinkObj( $s->page_id, $variantTitle, $s->page_len, $s->page_is_redirect ); |
| 4210 | + $this->mOutput->addLink( $variantTitle, $s->page_id ); |
| 4211 | + } |
| 4212 | + |
| 4213 | + // loop over link holders |
| 4214 | + foreach($holderKeys as $key){ |
| 4215 | + $title = $this->mLinkHolders['titles'][$key]; |
| 4216 | + if ( is_null( $title ) ) continue; |
| 4217 | + |
| 4218 | + $pdbk = $title->getPrefixedDBkey(); |
| 4219 | + |
| 4220 | + if(!isset($colours[$pdbk])){ |
| 4221 | + // found link in some of the variants, replace the link holder data |
| 4222 | + $this->mLinkHolders['titles'][$key] = $variantTitle; |
| 4223 | + $this->mLinkHolders['dbkeys'][$key] = $variantTitle->getDBkey(); |
| 4224 | + |
| 4225 | + // set pdbk and colour |
| 4226 | + $pdbks[$key] = $varPdbk; |
| 4227 | + $colours[$varPdbk] = $sk->getLinkColour( $variantTitle, $threshold ); |
| 4228 | + $linkcolour_ids[$s->page_id] = $pdbk; |
| 4229 | + } |
| 4230 | + wfRunHooks( 'GetLinkColours', array( $linkcolour_ids, &$colours ) ); |
| 4231 | + } |
| 4232 | + |
| 4233 | + // check if the object is a variant of a category |
| 4234 | + if(isset($categoryMap[$vardbk])){ |
| 4235 | + $oldkey = $categoryMap[$vardbk]; |
| 4236 | + if($oldkey != $vardbk) |
| 4237 | + $varCategories[$oldkey]=$vardbk; |
| 4238 | + } |
| 4239 | + } |
| 4240 | + |
| 4241 | + // rebuild the categories in original order (if there are replacements) |
| 4242 | + if(count($varCategories)>0){ |
| 4243 | + $newCats = array(); |
| 4244 | + $originalCats = $this->mOutput->getCategories(); |
| 4245 | + foreach($originalCats as $cat => $sortkey){ |
| 4246 | + // make the replacement |
| 4247 | + if( array_key_exists($cat,$varCategories) ) |
| 4248 | + $newCats[$varCategories[$cat]] = $sortkey; |
| 4249 | + else $newCats[$cat] = $sortkey; |
| 4250 | + } |
| 4251 | + $this->mOutput->setCategoryLinks($newCats); |
| 4252 | + } |
| 4253 | + } |
| 4254 | + } |
| 4255 | + |
| 4256 | + # Construct search and replace arrays |
| 4257 | + wfProfileIn( $fname.'-construct' ); |
| 4258 | + $replacePairs = array(); |
| 4259 | + foreach ( $this->mLinkHolders['namespaces'] as $key => $ns ) { |
| 4260 | + $pdbk = $pdbks[$key]; |
| 4261 | + $searchkey = "<!--LINK $key-->"; |
| 4262 | + $title = $this->mLinkHolders['titles'][$key]; |
| 4263 | + if ( !isset( $colours[$pdbk] ) || $colours[$pdbk] == 'new' ) { |
| 4264 | + $linkCache->addBadLinkObj( $title ); |
| 4265 | + $colours[$pdbk] = 'new'; |
| 4266 | + $this->mOutput->addLink( $title, 0 ); |
| 4267 | + $replacePairs[$searchkey] = $sk->makeBrokenLinkObj( $title, |
| 4268 | + $this->mLinkHolders['texts'][$key], |
| 4269 | + $this->mLinkHolders['queries'][$key] ); |
| 4270 | + } else { |
| 4271 | + $replacePairs[$searchkey] = $sk->makeColouredLinkObj( $title, $colours[$pdbk], |
| 4272 | + $this->mLinkHolders['texts'][$key], |
| 4273 | + $this->mLinkHolders['queries'][$key] ); |
| 4274 | + } |
| 4275 | + } |
| 4276 | + $replacer = new HashtableReplacer( $replacePairs, 1 ); |
| 4277 | + wfProfileOut( $fname.'-construct' ); |
| 4278 | + |
| 4279 | + # Do the thing |
| 4280 | + wfProfileIn( $fname.'-replace' ); |
| 4281 | + $text = preg_replace_callback( |
| 4282 | + '/(<!--LINK .*?-->)/', |
| 4283 | + $replacer->cb(), |
| 4284 | + $text); |
| 4285 | + |
| 4286 | + wfProfileOut( $fname.'-replace' ); |
| 4287 | + } |
| 4288 | + |
| 4289 | + # Now process interwiki link holders |
| 4290 | + # This is quite a bit simpler than internal links |
| 4291 | + if ( !empty( $this->mInterwikiLinkHolders['texts'] ) ) { |
| 4292 | + wfProfileIn( $fname.'-interwiki' ); |
| 4293 | + # Make interwiki link HTML |
| 4294 | + $replacePairs = array(); |
| 4295 | + foreach( $this->mInterwikiLinkHolders['texts'] as $key => $link ) { |
| 4296 | + $title = $this->mInterwikiLinkHolders['titles'][$key]; |
| 4297 | + $replacePairs[$key] = $sk->link( $title, $link ); |
| 4298 | + } |
| 4299 | + $replacer = new HashtableReplacer( $replacePairs, 1 ); |
| 4300 | + |
| 4301 | + $text = preg_replace_callback( |
| 4302 | + '/<!--IWLINK (.*?)-->/', |
| 4303 | + $replacer->cb(), |
| 4304 | + $text ); |
| 4305 | + wfProfileOut( $fname.'-interwiki' ); |
| 4306 | + } |
| 4307 | + |
| 4308 | + wfProfileOut( $fname ); |
| 4309 | + return $colours; |
4031 | 4310 | } |
4032 | 4311 | |
4033 | 4312 | /** |
— | — | @@ -4036,13 +4315,42 @@ |
4037 | 4316 | * @return string |
4038 | 4317 | */ |
4039 | 4318 | function replaceLinkHoldersText( $text ) { |
4040 | | - return $this->mLinkHolders->replaceText( $text ); |
| 4319 | + $fname = 'Parser::replaceLinkHoldersText'; |
| 4320 | + wfProfileIn( $fname ); |
| 4321 | + |
| 4322 | + $text = preg_replace_callback( |
| 4323 | + '/<!--(LINK|IWLINK) (.*?)-->/', |
| 4324 | + array( &$this, 'replaceLinkHoldersTextCallback' ), |
| 4325 | + $text ); |
| 4326 | + |
| 4327 | + wfProfileOut( $fname ); |
| 4328 | + return $text; |
4041 | 4329 | } |
4042 | 4330 | |
4043 | 4331 | /** |
| 4332 | + * @param array $matches |
| 4333 | + * @return string |
| 4334 | + * @private |
| 4335 | + */ |
| 4336 | + function replaceLinkHoldersTextCallback( $matches ) { |
| 4337 | + $type = $matches[1]; |
| 4338 | + $key = $matches[2]; |
| 4339 | + if( $type == 'LINK' ) { |
| 4340 | + if( isset( $this->mLinkHolders['texts'][$key] ) ) { |
| 4341 | + return $this->mLinkHolders['texts'][$key]; |
| 4342 | + } |
| 4343 | + } elseif( $type == 'IWLINK' ) { |
| 4344 | + if( isset( $this->mInterwikiLinkHolders['texts'][$key] ) ) { |
| 4345 | + return $this->mInterwikiLinkHolders['texts'][$key]; |
| 4346 | + } |
| 4347 | + } |
| 4348 | + return $matches[0]; |
| 4349 | + } |
| 4350 | + |
| 4351 | + /** |
4044 | 4352 | * Tag hook handler for 'pre'. |
4045 | 4353 | */ |
4046 | | - static function renderPreTag( $text, $attribs ) { |
| 4354 | + function renderPreTag( $text, $attribs ) { |
4047 | 4355 | // Backwards-compatibility hack |
4048 | 4356 | $content = StringUtils::delimiterReplace( '<nowiki>', '</nowiki>', '$1', $text, 'i' ); |
4049 | 4357 | |
— | — | @@ -4090,7 +4398,7 @@ |
4091 | 4399 | |
4092 | 4400 | wfRunHooks( 'BeforeParserrenderImageGallery', array( &$this, &$ig ) ); |
4093 | 4401 | |
4094 | | - $lines = StringUtils::explode( "\n", $text ); |
| 4402 | + $lines = explode( "\n", $text ); |
4095 | 4403 | foreach ( $lines as $line ) { |
4096 | 4404 | # match lines like these: |
4097 | 4405 | # Image:someimage.jpg|This is some image |
— | — | @@ -4103,7 +4411,7 @@ |
4104 | 4412 | |
4105 | 4413 | if ( strpos( $matches[0], '%' ) !== false ) |
4106 | 4414 | $matches[1] = urldecode( $matches[1] ); |
4107 | | - $tp = Title::newFromText( $matches[1], NS_IMAGE ); |
| 4415 | + $tp = Title::newFromText( $matches[1] ); |
4108 | 4416 | $nt =& $tp; |
4109 | 4417 | if( is_null( $nt ) ) { |
4110 | 4418 | # Bogus title. Ignore these so we don't bomb out later. |
— | — | @@ -4169,11 +4477,8 @@ |
4170 | 4478 | |
4171 | 4479 | /** |
4172 | 4480 | * Parse image options text and use it to make an image |
4173 | | - * @param Title $title |
4174 | | - * @param string $options |
4175 | | - * @param LinkHolderArray $holders |
4176 | 4481 | */ |
4177 | | - function makeImage( $title, $options, $holders = false ) { |
| 4482 | + function makeImage( $title, $options ) { |
4178 | 4483 | # Check if the options text is of the form "options|alt text" |
4179 | 4484 | # Options are: |
4180 | 4485 | # * thumbnail make a thumbnail with enlarge-icon and caption, alignment depends on lang |
— | — | @@ -4196,7 +4501,7 @@ |
4197 | 4502 | # * bottom |
4198 | 4503 | # * text-bottom |
4199 | 4504 | |
4200 | | - $parts = StringUtils::explode( "|", $options ); |
| 4505 | + $parts = array_map( 'trim', explode( '|', $options) ); |
4201 | 4506 | $sk = $this->mOptions->getSkin(); |
4202 | 4507 | |
4203 | 4508 | # Give extensions a chance to select the file revision for us |
— | — | @@ -4224,7 +4529,7 @@ |
4225 | 4530 | list( $type, $paramName ) = $paramMap[$magicName]; |
4226 | 4531 | |
4227 | 4532 | // Special case; width and height come in one variable together |
4228 | | - if( $type === 'handler' && $paramName === 'width' ) { |
| 4533 | + if( $type == 'handler' && $paramName == 'width' ) { |
4229 | 4534 | $m = array(); |
4230 | 4535 | # (bug 13500) In both cases (width/height and width only), |
4231 | 4536 | # permit trailing "px" for backward compatibility. |
— | — | @@ -4247,7 +4552,7 @@ |
4248 | 4553 | } |
4249 | 4554 | } // else no validation -- bug 13436 |
4250 | 4555 | } else { |
4251 | | - if ( $type === 'handler' ) { |
| 4556 | + if ( $type == 'handler' ) { |
4252 | 4557 | # Validate handler parameter |
4253 | 4558 | $validated = $handler->validateParam( $paramName, $value ); |
4254 | 4559 | } else { |
— | — | @@ -4283,13 +4588,7 @@ |
4284 | 4589 | } |
4285 | 4590 | |
4286 | 4591 | # Strip bad stuff out of the alt text |
4287 | | - # We can't just use replaceLinkHoldersText() here, because if this function |
4288 | | - # is called from replaceInternalLinks2(), mLinkHolders won't be up to date. |
4289 | | - if ( $holders ) { |
4290 | | - $alt = $holders->replaceText( $caption ); |
4291 | | - } else { |
4292 | | - $alt = $this->replaceLinkHoldersText( $caption ); |
4293 | | - } |
| 4592 | + $alt = $this->replaceLinkHoldersText( $caption ); |
4294 | 4593 | |
4295 | 4594 | # make sure there are no placeholders in thumbnail attributes |
4296 | 4595 | # that are later expanded to html- so expand them now and |
— | — | @@ -4392,7 +4691,7 @@ |
4393 | 4692 | $sectionParts = explode( '-', $section ); |
4394 | 4693 | $sectionIndex = array_pop( $sectionParts ); |
4395 | 4694 | foreach ( $sectionParts as $part ) { |
4396 | | - if ( $part === 'T' ) { |
| 4695 | + if ( $part == 'T' ) { |
4397 | 4696 | $flags |= self::PTD_FOR_INCLUSION; |
4398 | 4697 | } |
4399 | 4698 | } |
— | — | @@ -4409,14 +4708,14 @@ |
4410 | 4709 | $targetLevel = 1000; |
4411 | 4710 | } else { |
4412 | 4711 | while ( $node ) { |
4413 | | - if ( $node->getName() === 'h' ) { |
| 4712 | + if ( $node->getName() == 'h' ) { |
4414 | 4713 | $bits = $node->splitHeading(); |
4415 | 4714 | if ( $bits['i'] == $sectionIndex ) { |
4416 | 4715 | $targetLevel = $bits['level']; |
4417 | 4716 | break; |
4418 | 4717 | } |
4419 | 4718 | } |
4420 | | - if ( $mode === 'replace' ) { |
| 4719 | + if ( $mode == 'replace' ) { |
4421 | 4720 | $outText .= $frame->expand( $node, PPFrame::RECOVER_ORIG ); |
4422 | 4721 | } |
4423 | 4722 | $node = $node->getNextSibling(); |
— | — | @@ -4425,7 +4724,7 @@ |
4426 | 4725 | |
4427 | 4726 | if ( !$node ) { |
4428 | 4727 | // Not found |
4429 | | - if ( $mode === 'get' ) { |
| 4728 | + if ( $mode == 'get' ) { |
4430 | 4729 | return $newText; |
4431 | 4730 | } else { |
4432 | 4731 | return $text; |
— | — | @@ -4434,21 +4733,21 @@ |
4435 | 4734 | |
4436 | 4735 | // Find the end of the section, including nested sections |
4437 | 4736 | do { |
4438 | | - if ( $node->getName() === 'h' ) { |
| 4737 | + if ( $node->getName() == 'h' ) { |
4439 | 4738 | $bits = $node->splitHeading(); |
4440 | 4739 | $curLevel = $bits['level']; |
4441 | 4740 | if ( $bits['i'] != $sectionIndex && $curLevel <= $targetLevel ) { |
4442 | 4741 | break; |
4443 | 4742 | } |
4444 | 4743 | } |
4445 | | - if ( $mode === 'get' ) { |
| 4744 | + if ( $mode == 'get' ) { |
4446 | 4745 | $outText .= $frame->expand( $node, PPFrame::RECOVER_ORIG ); |
4447 | 4746 | } |
4448 | 4747 | $node = $node->getNextSibling(); |
4449 | 4748 | } while ( $node ); |
4450 | 4749 | |
4451 | 4750 | // Write out the remainder (in replace mode only) |
4452 | | - if ( $mode === 'replace' ) { |
| 4751 | + if ( $mode == 'replace' ) { |
4453 | 4752 | // Output the replacement text |
4454 | 4753 | // Add two newlines on -- trailing whitespace in $newText is conventionally |
4455 | 4754 | // stripped by the editor, so we need both newlines to restore the paragraph gap |
— | — | @@ -4678,7 +4977,7 @@ |
4679 | 4978 | do { |
4680 | 4979 | $oldText = $text; |
4681 | 4980 | $text = $this->general->replace( $text ); |
4682 | | - } while ( $text !== $oldText ); |
| 4981 | + } while ( $text != $oldText ); |
4683 | 4982 | wfProfileOut( __METHOD__ ); |
4684 | 4983 | return $text; |
4685 | 4984 | } |
— | — | @@ -4688,7 +4987,7 @@ |
4689 | 4988 | do { |
4690 | 4989 | $oldText = $text; |
4691 | 4990 | $text = $this->nowiki->replace( $text ); |
4692 | | - } while ( $text !== $oldText ); |
| 4991 | + } while ( $text != $oldText ); |
4693 | 4992 | wfProfileOut( __METHOD__ ); |
4694 | 4993 | return $text; |
4695 | 4994 | } |
— | — | @@ -4699,7 +4998,7 @@ |
4700 | 4999 | $oldText = $text; |
4701 | 5000 | $text = $this->general->replace( $text ); |
4702 | 5001 | $text = $this->nowiki->replace( $text ); |
4703 | | - } while ( $text !== $oldText ); |
| 5002 | + } while ( $text != $oldText ); |
4704 | 5003 | wfProfileOut( __METHOD__ ); |
4705 | 5004 | return $text; |
4706 | 5005 | } |
— | — | @@ -4713,7 +5012,7 @@ |
4714 | 5013 | var $output = ''; |
4715 | 5014 | |
4716 | 5015 | function replace( $matches ) { |
4717 | | - if ( substr( $matches[1], -1 ) === "\n" ) { |
| 5016 | + if ( substr( $matches[1], -1 ) == "\n" ) { |
4718 | 5017 | $this->output .= substr( $matches[1], 0, -1 ); |
4719 | 5018 | } else { |
4720 | 5019 | $this->output .= $matches[1]; |