Index: trunk/phase3/includes/parser/Parser.php |
— | — | @@ -17,17 +17,17 @@ |
18 | 18 | * <pre> |
19 | 19 | * There are five main entry points into the Parser class: |
20 | 20 | * parse() |
21 | | - * produces HTML output |
| 21 | + * produces HTML output |
22 | 22 | * preSaveTransform(). |
23 | | - * produces altered wiki markup. |
| 23 | + * produces altered wiki markup. |
24 | 24 | * preprocess() |
25 | | - * removes HTML comments and expands templates |
| 25 | + * removes HTML comments and expands templates |
26 | 26 | * cleanSig() |
27 | | - * Cleans a signature before saving it to preferences |
| 27 | + * Cleans a signature before saving it to preferences |
28 | 28 | * extractSections() |
29 | | - * Extracts sections from an article for section editing |
| 29 | + * Extracts sections from an article for section editing |
30 | 30 | * getPreloadText() |
31 | | - * Removes <noinclude> sections, and <includeonly> tags. |
| 31 | + * Removes <noinclude> sections, and <includeonly> tags. |
32 | 32 | * |
33 | 33 | * Globals used: |
34 | 34 | * objects: $wgLang, $wgContLang |
— | — | @@ -64,7 +64,7 @@ |
65 | 65 | const EXT_IMAGE_REGEX = '/^(http:\/\/|https:\/\/)([^][<>"\\x00-\\x20\\x7F]+) |
66 | 66 | \\/([A-Za-z0-9_.,~%\\-+&;#*?!=()@\\x80-\\xFF]+)\\.((?i)gif|png|jpg|jpeg)$/Sx'; |
67 | 67 | |
68 | | - // State constants for the definition list colon extraction |
| 68 | + # State constants for the definition list colon extraction |
69 | 69 | const COLON_STATE_TEXT = 0; |
70 | 70 | const COLON_STATE_TAG = 1; |
71 | 71 | const COLON_STATE_TAGSTART = 2; |
— | — | @@ -74,23 +74,20 @@ |
75 | 75 | const COLON_STATE_COMMENTDASH = 6; |
76 | 76 | const COLON_STATE_COMMENTDASHDASH = 7; |
77 | 77 | |
78 | | - // Flags for preprocessToDom |
| 78 | + # Flags for preprocessToDom |
79 | 79 | const PTD_FOR_INCLUSION = 1; |
80 | 80 | |
81 | | - // Allowed values for $this->mOutputType |
82 | | - // Parameter to startExternalParse(). |
83 | | - const OT_HTML = 1; // like parse() |
84 | | - const OT_WIKI = 2; // like preSaveTransform() |
85 | | - const OT_PREPROCESS = 3; // like preprocess() |
| 81 | + # Allowed values for $this->mOutputType |
| 82 | + # Parameter to startExternalParse(). |
| 83 | + const OT_HTML = 1; # like parse() |
| 84 | + const OT_WIKI = 2; # like preSaveTransform() |
| 85 | + const OT_PREPROCESS = 3; # like preprocess() |
86 | 86 | const OT_MSG = 3; |
87 | | - const OT_PLAIN = 4; // like extractSections() - portions of the original are returned unchanged. |
| 87 | + const OT_PLAIN = 4; # like extractSections() - portions of the original are returned unchanged. |
88 | 88 | |
89 | | - // Marker Suffix needs to be accessible staticly. |
| 89 | + # Marker Suffix needs to be accessible staticly. |
90 | 90 | const MARKER_SUFFIX = "-QINU\x7f"; |
91 | 91 | |
92 | | - /**#@+ |
93 | | - * @private |
94 | | - */ |
95 | 92 | # Persistent: |
96 | 93 | var $mTagHooks, $mTransparentTagHooks, $mFunctionHooks, $mFunctionSynonyms, $mVariables; |
97 | 94 | var $mSubstWords, $mImageParams, $mImageParamsMagicArray, $mStripList, $mMarkerIndex; |
— | — | @@ -103,22 +100,20 @@ |
104 | 101 | var $mIncludeCount, $mArgStack, $mLastSection, $mInPre; |
105 | 102 | var $mLinkHolders, $mLinkID; |
106 | 103 | var $mIncludeSizes, $mPPNodeCount, $mDefaultSort; |
107 | | - var $mTplExpandCache; // empty-frame expansion cache |
| 104 | + var $mTplExpandCache; # empty-frame expansion cache |
108 | 105 | var $mTplRedirCache, $mTplDomCache, $mHeadings, $mDoubleUnderscores; |
109 | | - var $mExpensiveFunctionCount; // number of expensive parser function calls |
| 106 | + var $mExpensiveFunctionCount; # number of expensive parser function calls |
110 | 107 | |
111 | 108 | # Temporary |
112 | 109 | # These are variables reset at least once per parse regardless of $clearState |
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 |
| 110 | + var $mOptions; # ParserOptions object |
| 111 | + var $mTitle; # Title context, used for self-link rendering and similar things |
| 112 | + var $mOutputType; # Output type, one of the OT_xxx constants |
| 113 | + var $ot; # Shortcut alias, see setOutputType() |
| 114 | + var $mRevisionId; # ID to display in {{REVISIONID}} tags |
| 115 | + var $mRevisionTimestamp; # The timestamp of the specified revision ID |
| 116 | + var $mRevIdForTs; # The revision ID which was used to fetch the timestamp |
120 | 117 | |
121 | | - /**#@-*/ |
122 | | - |
123 | 118 | /** |
124 | 119 | * Constructor |
125 | 120 | * |
— | — | @@ -139,7 +134,7 @@ |
140 | 135 | if ( isset( $conf['preprocessorClass'] ) ) { |
141 | 136 | $this->mPreprocessorClass = $conf['preprocessorClass']; |
142 | 137 | } elseif ( extension_loaded( 'domxml' ) ) { |
143 | | - // PECL extension that conflicts with the core DOM extension (bug 13770) |
| 138 | + # PECL extension that conflicts with the core DOM extension (bug 13770) |
144 | 139 | wfDebug( "Warning: you have the obsolete domxml extension for PHP. Please remove it!\n" ); |
145 | 140 | $this->mPreprocessorClass = 'Preprocessor_Hash'; |
146 | 141 | } elseif ( extension_loaded( 'dom' ) ) { |
— | — | @@ -246,7 +241,7 @@ |
247 | 242 | |
248 | 243 | function setOutputType( $ot ) { |
249 | 244 | $this->mOutputType = $ot; |
250 | | - // Shortcut alias |
| 245 | + # Shortcut alias |
251 | 246 | $this->ot = array( |
252 | 247 | 'html' => $ot == self::OT_HTML, |
253 | 248 | 'wiki' => $ot == self::OT_WIKI, |
— | — | @@ -279,13 +274,13 @@ |
280 | 275 | */ |
281 | 276 | function uniqPrefix() { |
282 | 277 | if ( !isset( $this->mUniqPrefix ) ) { |
283 | | - // @todo Fixme: this is probably *horribly wrong* |
284 | | - // LanguageConverter seems to want $wgParser's uniqPrefix, however |
285 | | - // if this is called for a parser cache hit, the parser may not |
286 | | - // have ever been initialized in the first place. |
287 | | - // Not really sure what the heck is supposed to be going on here. |
| 278 | + # @todo Fixme: this is probably *horribly wrong* |
| 279 | + # LanguageConverter seems to want $wgParser's uniqPrefix, however |
| 280 | + # if this is called for a parser cache hit, the parser may not |
| 281 | + # have ever been initialized in the first place. |
| 282 | + # Not really sure what the heck is supposed to be going on here. |
288 | 283 | return ''; |
289 | | - // throw new MWException( "Accessing uninitialized mUniqPrefix" ); |
| 284 | + # throw new MWException( "Accessing uninitialized mUniqPrefix" ); |
290 | 285 | } |
291 | 286 | return $this->mUniqPrefix; |
292 | 287 | } |
— | — | @@ -318,7 +313,7 @@ |
319 | 314 | } |
320 | 315 | |
321 | 316 | $this->mOptions = $options; |
322 | | - $this->setTitle( $title ); // Page title has to be set for the pre-processor |
| 317 | + $this->setTitle( $title ); # Page title has to be set for the pre-processor |
323 | 318 | |
324 | 319 | $oldRevisionId = $this->mRevisionId; |
325 | 320 | $oldRevisionTimestamp = $this->mRevisionTimestamp; |
— | — | @@ -349,9 +344,9 @@ |
350 | 345 | |
351 | 346 | $this->replaceLinkHolders( $text ); |
352 | 347 | |
353 | | - // The position of the convert() call should not be changed. it |
354 | | - // assumes that the links are all replaced and the only thing left |
355 | | - // is the <nowiki> mark. |
| 348 | + # The position of the convert() call should not be changed. it |
| 349 | + # assumes that the links are all replaced and the only thing left |
| 350 | + # is the <nowiki> mark. |
356 | 351 | if ( !( $wgDisableLangConversion |
357 | 352 | || isset( $this->mDoubleUnderscores['nocontentconvert'] ) |
358 | 353 | || $this->mTitle->isTalkPage() |
— | — | @@ -359,10 +354,10 @@ |
360 | 355 | $text = $wgContLang->convert( $text ); |
361 | 356 | } |
362 | 357 | |
363 | | - // A title may have been set in a conversion rule. |
364 | | - // Note that if a user tries to set a title in a conversion |
365 | | - // rule but content conversion was not done, then the parser |
366 | | - // won't pick it up. This is probably expected behavior. |
| 358 | + # A title may have been set in a conversion rule. |
| 359 | + # Note that if a user tries to set a title in a conversion |
| 360 | + # rule but content conversion was not done, then the parser |
| 361 | + # won't pick it up. This is probably expected behavior. |
367 | 362 | if ( $wgContLang->getConvRuleTitle() ) { |
368 | 363 | $this->mOutput->setTitleText( $wgContLang->getConvRuleTitle() ); |
369 | 364 | } |
— | — | @@ -497,7 +492,7 @@ |
498 | 493 | * comments, templates, arguments, tags hooks and parser functions are untouched. |
499 | 494 | */ |
500 | 495 | public function getPreloadText( $text, $title, $options ) { |
501 | | - // Parser (re)initialisation |
| 496 | + # Parser (re)initialisation |
502 | 497 | $this->clearState(); |
503 | 498 | $this->setOutputType( self::OT_PLAIN ); |
504 | 499 | $this->mOptions = $options; |
— | — | @@ -579,13 +574,13 @@ |
580 | 575 | break; |
581 | 576 | } |
582 | 577 | if ( count( $p ) > 5 ) { |
583 | | - // comment |
| 578 | + # comment |
584 | 579 | $element = $p[4]; |
585 | 580 | $attributes = ''; |
586 | 581 | $close = ''; |
587 | 582 | $inside = $p[5]; |
588 | 583 | } else { |
589 | | - // tag |
| 584 | + # tag |
590 | 585 | $element = $p[1]; |
591 | 586 | $attributes = $p[2]; |
592 | 587 | $close = $p[3]; |
— | — | @@ -596,7 +591,7 @@ |
597 | 592 | $stripped .= $marker; |
598 | 593 | |
599 | 594 | if ( $close === '/>' ) { |
600 | | - // Empty element tag, <tag /> |
| 595 | + # Empty element tag, <tag /> |
601 | 596 | $content = null; |
602 | 597 | $text = $inside; |
603 | 598 | $tail = null; |
— | — | @@ -701,17 +696,17 @@ |
702 | 697 | |
703 | 698 | $lines = StringUtils::explode( "\n", $text ); |
704 | 699 | $out = ''; |
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 |
709 | | - $has_opened_tr = array(); // Did this table open a <tr> element? |
710 | | - $indent_level = 0; // indent level of the table |
| 700 | + $td_history = array(); # Is currently a td tag open? |
| 701 | + $last_tag_history = array(); # Save history of last lag activated (td, th or caption) |
| 702 | + $tr_history = array(); # Is currently a tr tag open? |
| 703 | + $tr_attributes = array(); # history of tr attributes |
| 704 | + $has_opened_tr = array(); # Did this table open a <tr> element? |
| 705 | + $indent_level = 0; # indent level of the table |
711 | 706 | |
712 | 707 | foreach ( $lines as $outLine ) { |
713 | 708 | $line = trim( $outLine ); |
714 | 709 | |
715 | | - if ( $line == '' ) { // empty line, go to next line |
| 710 | + if ( $line == '' ) { # empty line, go to next line |
716 | 711 | $out .= $outLine."\n"; |
717 | 712 | continue; |
718 | 713 | } |
— | — | @@ -719,7 +714,7 @@ |
720 | 715 | $matches = array(); |
721 | 716 | |
722 | 717 | if ( preg_match( '/^(:*)\{\|(.*)$/', $line , $matches ) ) { |
723 | | - // First check if we are starting a new table |
| 718 | + # First check if we are starting a new table |
724 | 719 | $indent_level = strlen( $matches[1] ); |
725 | 720 | |
726 | 721 | $attributes = $this->mStripState->unstripBoth( $matches[2] ); |
— | — | @@ -732,11 +727,11 @@ |
733 | 728 | array_push( $tr_attributes , '' ); |
734 | 729 | array_push( $has_opened_tr , false ); |
735 | 730 | } elseif ( count( $td_history ) == 0 ) { |
736 | | - // Don't do any of the following |
| 731 | + # Don't do any of the following |
737 | 732 | $out .= $outLine."\n"; |
738 | 733 | continue; |
739 | 734 | } elseif ( substr( $line , 0 , 2 ) === '|}' ) { |
740 | | - // We are ending a table |
| 735 | + # We are ending a table |
741 | 736 | $line = '</table>' . substr( $line , 2 ); |
742 | 737 | $last_tag = array_pop( $last_tag_history ); |
743 | 738 | |
— | — | @@ -754,10 +749,10 @@ |
755 | 750 | array_pop( $tr_attributes ); |
756 | 751 | $outLine = $line . str_repeat( '</dd></dl>' , $indent_level ); |
757 | 752 | } elseif ( substr( $line , 0 , 2 ) === '|-' ) { |
758 | | - // Now we have a table row |
| 753 | + # Now we have a table row |
759 | 754 | $line = preg_replace( '#^\|-+#', '', $line ); |
760 | 755 | |
761 | | - // Whats after the tag is now only attributes |
| 756 | + # Whats after the tag is now only attributes |
762 | 757 | $attributes = $this->mStripState->unstripBoth( $line ); |
763 | 758 | $attributes = Sanitizer::fixTagAttributes( $attributes, 'tr' ); |
764 | 759 | array_pop( $tr_attributes ); |
— | — | @@ -781,7 +776,7 @@ |
782 | 777 | array_push( $td_history , false ); |
783 | 778 | array_push( $last_tag_history , '' ); |
784 | 779 | } elseif ( $first_character === '|' || $first_character === '!' || substr( $line , 0 , 2 ) === '|+' ) { |
785 | | - // This might be cell elements, td, th or captions |
| 780 | + # This might be cell elements, td, th or captions |
786 | 781 | if ( substr( $line , 0 , 2 ) === '|+' ) { |
787 | 782 | $first_character = '+'; |
788 | 783 | $line = substr( $line , 1 ); |
— | — | @@ -793,15 +788,15 @@ |
794 | 789 | $line = str_replace( '!!' , '||' , $line ); |
795 | 790 | } |
796 | 791 | |
797 | | - // Split up multiple cells on the same line. |
798 | | - // FIXME : This can result in improper nesting of tags processed |
799 | | - // by earlier parser steps, but should avoid splitting up eg |
800 | | - // attribute values containing literal "||". |
| 792 | + # Split up multiple cells on the same line. |
| 793 | + # FIXME : This can result in improper nesting of tags processed |
| 794 | + # by earlier parser steps, but should avoid splitting up eg |
| 795 | + # attribute values containing literal "||". |
801 | 796 | $cells = StringUtils::explodeMarkup( '||' , $line ); |
802 | 797 | |
803 | 798 | $outLine = ''; |
804 | 799 | |
805 | | - // Loop through each table cell |
| 800 | + # Loop through each table cell |
806 | 801 | foreach ( $cells as $cell ) { |
807 | 802 | $previous = ''; |
808 | 803 | if ( $first_character !== '+' ) { |
— | — | @@ -833,11 +828,11 @@ |
834 | 829 | |
835 | 830 | array_push( $last_tag_history , $last_tag ); |
836 | 831 | |
837 | | - // A cell could contain both parameters and data |
| 832 | + # A cell could contain both parameters and data |
838 | 833 | $cell_data = explode( '|' , $cell , 2 ); |
839 | 834 | |
840 | | - // Bug 553: Note that a '|' inside an invalid link should not |
841 | | - // be mistaken as delimiting cell parameters |
| 835 | + # Bug 553: Note that a '|' inside an invalid link should not |
| 836 | + # be mistaken as delimiting cell parameters |
842 | 837 | if ( strpos( $cell_data[0], '[[' ) !== false ) { |
843 | 838 | $cell = "{$previous}<{$last_tag}>{$cell}"; |
844 | 839 | } elseif ( count( $cell_data ) == 1 ) { |
— | — | @@ -855,7 +850,7 @@ |
856 | 851 | $out .= $outLine . "\n"; |
857 | 852 | } |
858 | 853 | |
859 | | - // Closing open td, tr && table |
| 854 | + # Closing open td, tr && table |
860 | 855 | while ( count( $td_history ) > 0 ) { |
861 | 856 | if ( array_pop( $td_history ) ) { |
862 | 857 | $out .= "</td>\n"; |
— | — | @@ -870,12 +865,12 @@ |
871 | 866 | $out .= "</table>\n"; |
872 | 867 | } |
873 | 868 | |
874 | | - // Remove trailing line-ending (b/c) |
| 869 | + # Remove trailing line-ending (b/c) |
875 | 870 | if ( substr( $out, -1 ) === "\n" ) { |
876 | 871 | $out = substr( $out, 0, -1 ); |
877 | 872 | } |
878 | 873 | |
879 | | - // special case: don't return empty table |
| 874 | + # special case: don't return empty table |
880 | 875 | if ( $out === "<table>\n<tr><td></td></tr>\n</table>" ) { |
881 | 876 | $out = ''; |
882 | 877 | } |
— | — | @@ -902,10 +897,10 @@ |
903 | 898 | return $text ; |
904 | 899 | } |
905 | 900 | |
906 | | - // if $frame is provided, then use $frame for replacing any variables |
| 901 | + # if $frame is provided, then use $frame for replacing any variables |
907 | 902 | if ( $frame ) { |
908 | | - // use frame depth to infer how include/noinclude tags should be handled |
909 | | - // depth=0 means this is the top-level document; otherwise it's an included document |
| 903 | + # use frame depth to infer how include/noinclude tags should be handled |
| 904 | + # depth=0 means this is the top-level document; otherwise it's an included document |
910 | 905 | if ( !$frame->depth ) { |
911 | 906 | $flag = 0; |
912 | 907 | } else { |
— | — | @@ -914,17 +909,17 @@ |
915 | 910 | $text = $frame->expand( $dom ); |
916 | 911 | } |
917 | 912 | } else { |
918 | | - // if $frame is not provided, then use old-style replaceVariables |
| 913 | + # if $frame is not provided, then use old-style replaceVariables |
919 | 914 | $text = $this->replaceVariables( $text ); |
920 | 915 | } |
921 | 916 | |
922 | 917 | $text = Sanitizer::removeHTMLtags( $text, array( &$this, 'attributeStripCallback' ), false, array_keys( $this->mTransparentTagHooks ) ); |
923 | 918 | wfRunHooks( 'InternalParseBeforeLinks', array( &$this, &$text, &$this->mStripState ) ); |
924 | 919 | |
925 | | - // Tables need to come after variable replacement for things to work |
926 | | - // properly; putting them before other transformations should keep |
927 | | - // exciting things like link expansions from showing up in surprising |
928 | | - // places. |
| 920 | + # Tables need to come after variable replacement for things to work |
| 921 | + # properly; putting them before other transformations should keep |
| 922 | + # exciting things like link expansions from showing up in surprising |
| 923 | + # places. |
929 | 924 | $text = $this->doTableStuff( $text ); |
930 | 925 | |
931 | 926 | $text = preg_replace( '/(^|\n)-----*/', '\\1<hr />', $text ); |
— | — | @@ -1418,12 +1413,12 @@ |
1419 | 1414 | private static function replaceUnusualEscapesCallback( $matches ) { |
1420 | 1415 | $char = urldecode( $matches[0] ); |
1421 | 1416 | $ord = ord( $char ); |
1422 | | - // Is it an unsafe or HTTP reserved character according to RFC 1738? |
| 1417 | + # Is it an unsafe or HTTP reserved character according to RFC 1738? |
1423 | 1418 | if ( $ord > 32 && $ord < 127 && strpos( '<>"#{}|\^~[]`;/?', $char ) === false ) { |
1424 | | - // No, shouldn't be escaped |
| 1419 | + # No, shouldn't be escaped |
1425 | 1420 | return $char; |
1426 | 1421 | } else { |
1427 | | - // Yes, leave it escaped |
| 1422 | + # Yes, leave it escaped |
1428 | 1423 | return $matches[0]; |
1429 | 1424 | } |
1430 | 1425 | } |
— | — | @@ -1849,7 +1844,7 @@ |
1850 | 1845 | function makeKnownLinkHolder( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) { |
1851 | 1846 | list( $inside, $trail ) = Linker::splitTrail( $trail ); |
1852 | 1847 | $sk = $this->mOptions->getSkin(); |
1853 | | - // FIXME: use link() instead of deprecated makeKnownLinkObj() |
| 1848 | + # FIXME: use link() instead of deprecated makeKnownLinkObj() |
1854 | 1849 | $link = $sk->makeKnownLinkObj( $nt, $text, $query, $inside, $prefix ); |
1855 | 1850 | return $this->armorLinks( $link ) . $trail; |
1856 | 1851 | } |
— | — | @@ -1893,7 +1888,7 @@ |
1894 | 1889 | * Used by doBlockLevels() |
1895 | 1890 | * @private |
1896 | 1891 | */ |
1897 | | - /* private */ function closeParagraph() { |
| 1892 | + function closeParagraph() { |
1898 | 1893 | $result = ''; |
1899 | 1894 | if ( $this->mLastSection != '' ) { |
1900 | 1895 | $result = '</' . $this->mLastSection . ">\n"; |
— | — | @@ -1945,7 +1940,12 @@ |
1946 | 1941 | return $result; |
1947 | 1942 | } |
1948 | 1943 | |
1949 | | - /* private */ function nextItem( $char ) { |
| 1944 | + /** |
| 1945 | + * TODO: document |
| 1946 | + * @param $char String |
| 1947 | + * @private |
| 1948 | + */ |
| 1949 | + function nextItem( $char ) { |
1950 | 1950 | if ( '*' === $char || '#' === $char ) { |
1951 | 1951 | return '</li><li>'; |
1952 | 1952 | } elseif ( ':' === $char || ';' === $char ) { |
— | — | @@ -1964,7 +1964,12 @@ |
1965 | 1965 | return '<!-- ERR 2 -->'; |
1966 | 1966 | } |
1967 | 1967 | |
1968 | | - /* private */ function closeList( $char ) { |
| 1968 | + /** |
| 1969 | + * TODO: document |
| 1970 | + * @param $char String |
| 1971 | + * @private |
| 1972 | + */ |
| 1973 | + function closeList( $char ) { |
1969 | 1974 | if ( '*' === $char ) { |
1970 | 1975 | $text = '</li></ul>'; |
1971 | 1976 | } elseif ( '#' === $char ) { |
— | — | @@ -2011,24 +2016,24 @@ |
2012 | 2017 | $linestart = true; |
2013 | 2018 | continue; |
2014 | 2019 | } |
2015 | | - // * = ul |
2016 | | - // # = ol |
2017 | | - // ; = dt |
2018 | | - // : = dd |
| 2020 | + # * = ul |
| 2021 | + # # = ol |
| 2022 | + # ; = dt |
| 2023 | + # : = dd |
2019 | 2024 | |
2020 | 2025 | $lastPrefixLength = strlen( $lastPrefix ); |
2021 | 2026 | $preCloseMatch = preg_match( '/<\\/pre/i', $oLine ); |
2022 | 2027 | $preOpenMatch = preg_match( '/<pre/i', $oLine ); |
2023 | | - // If not in a <pre> element, scan for and figure out what prefixes are there. |
| 2028 | + # If not in a <pre> element, scan for and figure out what prefixes are there. |
2024 | 2029 | if ( !$this->mInPre ) { |
2025 | 2030 | # Multiple prefixes may abut each other for nested lists. |
2026 | 2031 | $prefixLength = strspn( $oLine, '*#:;' ); |
2027 | 2032 | $prefix = substr( $oLine, 0, $prefixLength ); |
2028 | 2033 | |
2029 | 2034 | # eh? |
2030 | | - // ; and : are both from definition-lists, so they're equivalent |
2031 | | - // for the purposes of determining whether or not we need to open/close |
2032 | | - // elements. |
| 2035 | + # ; and : are both from definition-lists, so they're equivalent |
| 2036 | + # for the purposes of determining whether or not we need to open/close |
| 2037 | + # elements. |
2033 | 2038 | $prefix2 = str_replace( ';', ':', $prefix ); |
2034 | 2039 | $t = substr( $oLine, $prefixLength ); |
2035 | 2040 | $this->mInPre = (bool)$preOpenMatch; |
— | — | @@ -2057,24 +2062,24 @@ |
2058 | 2063 | } |
2059 | 2064 | } |
2060 | 2065 | } elseif ( $prefixLength || $lastPrefixLength ) { |
2061 | | - // We need to open or close prefixes, or both. |
| 2066 | + # We need to open or close prefixes, or both. |
2062 | 2067 | |
2063 | 2068 | # Either open or close a level... |
2064 | 2069 | $commonPrefixLength = $this->getCommon( $prefix, $lastPrefix ); |
2065 | 2070 | $paragraphStack = false; |
2066 | 2071 | |
2067 | | - // Close all the prefixes which aren't shared. |
| 2072 | + # Close all the prefixes which aren't shared. |
2068 | 2073 | while ( $commonPrefixLength < $lastPrefixLength ) { |
2069 | 2074 | $output .= $this->closeList( $lastPrefix[$lastPrefixLength-1] ); |
2070 | 2075 | --$lastPrefixLength; |
2071 | 2076 | } |
2072 | 2077 | |
2073 | | - // Continue the current prefix if appropriate. |
| 2078 | + # Continue the current prefix if appropriate. |
2074 | 2079 | if ( $prefixLength <= $commonPrefixLength && $commonPrefixLength > 0 ) { |
2075 | 2080 | $output .= $this->nextItem( $prefix[$commonPrefixLength-1] ); |
2076 | 2081 | } |
2077 | 2082 | |
2078 | | - // Open prefixes where appropriate. |
| 2083 | + # Open prefixes where appropriate. |
2079 | 2084 | while ( $prefixLength > $commonPrefixLength ) { |
2080 | 2085 | $char = substr( $prefix, $commonPrefixLength, 1 ); |
2081 | 2086 | $output .= $this->openList( $char ); |
— | — | @@ -2091,11 +2096,11 @@ |
2092 | 2097 | $lastPrefix = $prefix2; |
2093 | 2098 | } |
2094 | 2099 | |
2095 | | - // If we have no prefixes, go to paragraph mode. |
| 2100 | + # If we have no prefixes, go to paragraph mode. |
2096 | 2101 | if ( 0 == $prefixLength ) { |
2097 | 2102 | wfProfileIn( __METHOD__."-paragraph" ); |
2098 | 2103 | # No prefix (not in list)--go to paragraph mode |
2099 | | - // XXX: use a stack for nestable elements like span, table and div |
| 2104 | + # XXX: use a stack for nestable elements like span, table and div |
2100 | 2105 | $openmatch = preg_match('/(?:<table|<blockquote|<h1|<h2|<h3|<h4|<h5|<h6|<pre|<tr|<p|<ul|<ol|<li|<\\/tr|<\\/td|<\\/th)/iS', $t ); |
2101 | 2106 | $closematch = preg_match( |
2102 | 2107 | '/(?:<\\/table|<\\/blockquote|<\\/h1|<\\/h2|<\\/h3|<\\/h4|<\\/h5|<\\/h6|'. |
— | — | @@ -2114,7 +2119,7 @@ |
2115 | 2120 | } |
2116 | 2121 | } elseif ( !$inBlockElem && !$this->mInPre ) { |
2117 | 2122 | if ( ' ' == substr( $t, 0, 1 ) and ( $this->mLastSection === 'pre' || trim( $t ) != '' ) ) { |
2118 | | - // pre |
| 2123 | + # pre |
2119 | 2124 | if ( $this->mLastSection !== 'pre' ) { |
2120 | 2125 | $paragraphStack = false; |
2121 | 2126 | $output .= $this->closeParagraph().'<pre>'; |
— | — | @@ -2122,7 +2127,7 @@ |
2123 | 2128 | } |
2124 | 2129 | $t = substr( $t, 1 ); |
2125 | 2130 | } else { |
2126 | | - // paragraph |
| 2131 | + # paragraph |
2127 | 2132 | if ( trim( $t ) == '' ) { |
2128 | 2133 | if ( $paragraphStack ) { |
2129 | 2134 | $output .= $paragraphStack.'<br />'; |
— | — | @@ -2151,7 +2156,7 @@ |
2152 | 2157 | } |
2153 | 2158 | wfProfileOut( __METHOD__."-paragraph" ); |
2154 | 2159 | } |
2155 | | - // somewhere above we forget to get out of pre block (bug 785) |
| 2160 | + # somewhere above we forget to get out of pre block (bug 785) |
2156 | 2161 | if ( $preCloseMatch && $this->mInPre ) { |
2157 | 2162 | $this->mInPre = false; |
2158 | 2163 | } |
— | — | @@ -2185,21 +2190,21 @@ |
2186 | 2191 | |
2187 | 2192 | $pos = strpos( $str, ':' ); |
2188 | 2193 | if ( $pos === false ) { |
2189 | | - // Nothing to find! |
| 2194 | + # Nothing to find! |
2190 | 2195 | wfProfileOut( __METHOD__ ); |
2191 | 2196 | return false; |
2192 | 2197 | } |
2193 | 2198 | |
2194 | 2199 | $lt = strpos( $str, '<' ); |
2195 | 2200 | if ( $lt === false || $lt > $pos ) { |
2196 | | - // Easy; no tag nesting to worry about |
| 2201 | + # Easy; no tag nesting to worry about |
2197 | 2202 | $before = substr( $str, 0, $pos ); |
2198 | 2203 | $after = substr( $str, $pos+1 ); |
2199 | 2204 | wfProfileOut( __METHOD__ ); |
2200 | 2205 | return $pos; |
2201 | 2206 | } |
2202 | 2207 | |
2203 | | - // Ugly state machine to walk through avoiding tags. |
| 2208 | + # Ugly state machine to walk through avoiding tags. |
2204 | 2209 | $state = self::COLON_STATE_TEXT; |
2205 | 2210 | $stack = 0; |
2206 | 2211 | $len = strlen( $str ); |
— | — | @@ -2207,35 +2212,35 @@ |
2208 | 2213 | $c = $str{$i}; |
2209 | 2214 | |
2210 | 2215 | switch( $state ) { |
2211 | | - // (Using the number is a performance hack for common cases) |
2212 | | - case 0: // self::COLON_STATE_TEXT: |
| 2216 | + # (Using the number is a performance hack for common cases) |
| 2217 | + case 0: # self::COLON_STATE_TEXT: |
2213 | 2218 | switch( $c ) { |
2214 | 2219 | case "<": |
2215 | | - // Could be either a <start> tag or an </end> tag |
| 2220 | + # Could be either a <start> tag or an </end> tag |
2216 | 2221 | $state = self::COLON_STATE_TAGSTART; |
2217 | 2222 | break; |
2218 | 2223 | case ":": |
2219 | 2224 | if ( $stack == 0 ) { |
2220 | | - // We found it! |
| 2225 | + # We found it! |
2221 | 2226 | $before = substr( $str, 0, $i ); |
2222 | 2227 | $after = substr( $str, $i + 1 ); |
2223 | 2228 | wfProfileOut( __METHOD__ ); |
2224 | 2229 | return $i; |
2225 | 2230 | } |
2226 | | - // Embedded in a tag; don't break it. |
| 2231 | + # Embedded in a tag; don't break it. |
2227 | 2232 | break; |
2228 | 2233 | default: |
2229 | | - // Skip ahead looking for something interesting |
| 2234 | + # Skip ahead looking for something interesting |
2230 | 2235 | $colon = strpos( $str, ':', $i ); |
2231 | 2236 | if ( $colon === false ) { |
2232 | | - // Nothing else interesting |
| 2237 | + # Nothing else interesting |
2233 | 2238 | wfProfileOut( __METHOD__ ); |
2234 | 2239 | return false; |
2235 | 2240 | } |
2236 | 2241 | $lt = strpos( $str, '<', $i ); |
2237 | 2242 | if ( $stack === 0 ) { |
2238 | 2243 | if ( $lt === false || $colon < $lt ) { |
2239 | | - // We found it! |
| 2244 | + # We found it! |
2240 | 2245 | $before = substr( $str, 0, $colon ); |
2241 | 2246 | $after = substr( $str, $colon + 1 ); |
2242 | 2247 | wfProfileOut( __METHOD__ ); |
— | — | @@ -2243,31 +2248,31 @@ |
2244 | 2249 | } |
2245 | 2250 | } |
2246 | 2251 | if ( $lt === false ) { |
2247 | | - // Nothing else interesting to find; abort! |
2248 | | - // We're nested, but there's no close tags left. Abort! |
| 2252 | + # Nothing else interesting to find; abort! |
| 2253 | + # We're nested, but there's no close tags left. Abort! |
2249 | 2254 | break 2; |
2250 | 2255 | } |
2251 | | - // Skip ahead to next tag start |
| 2256 | + # Skip ahead to next tag start |
2252 | 2257 | $i = $lt; |
2253 | 2258 | $state = self::COLON_STATE_TAGSTART; |
2254 | 2259 | } |
2255 | 2260 | break; |
2256 | | - case 1: // self::COLON_STATE_TAG: |
2257 | | - // In a <tag> |
| 2261 | + case 1: # self::COLON_STATE_TAG: |
| 2262 | + # In a <tag> |
2258 | 2263 | switch( $c ) { |
2259 | 2264 | case ">": |
2260 | 2265 | $stack++; |
2261 | 2266 | $state = self::COLON_STATE_TEXT; |
2262 | 2267 | break; |
2263 | 2268 | case "/": |
2264 | | - // Slash may be followed by >? |
| 2269 | + # Slash may be followed by >? |
2265 | 2270 | $state = self::COLON_STATE_TAGSLASH; |
2266 | 2271 | break; |
2267 | 2272 | default: |
2268 | | - // ignore |
| 2273 | + # ignore |
2269 | 2274 | } |
2270 | 2275 | break; |
2271 | | - case 2: // self::COLON_STATE_TAGSTART: |
| 2276 | + case 2: # self::COLON_STATE_TAGSTART: |
2272 | 2277 | switch( $c ) { |
2273 | 2278 | case "/": |
2274 | 2279 | $state = self::COLON_STATE_CLOSETAG; |
— | — | @@ -2276,15 +2281,15 @@ |
2277 | 2282 | $state = self::COLON_STATE_COMMENT; |
2278 | 2283 | break; |
2279 | 2284 | case ">": |
2280 | | - // Illegal early close? This shouldn't happen D: |
| 2285 | + # Illegal early close? This shouldn't happen D: |
2281 | 2286 | $state = self::COLON_STATE_TEXT; |
2282 | 2287 | break; |
2283 | 2288 | default: |
2284 | 2289 | $state = self::COLON_STATE_TAG; |
2285 | 2290 | } |
2286 | 2291 | break; |
2287 | | - case 3: // self::COLON_STATE_CLOSETAG: |
2288 | | - // In a </tag> |
| 2292 | + case 3: # self::COLON_STATE_CLOSETAG: |
| 2293 | + # In a </tag> |
2289 | 2294 | if ( $c === ">" ) { |
2290 | 2295 | $stack--; |
2291 | 2296 | if ( $stack < 0 ) { |
— | — | @@ -2297,14 +2302,14 @@ |
2298 | 2303 | break; |
2299 | 2304 | case self::COLON_STATE_TAGSLASH: |
2300 | 2305 | if ( $c === ">" ) { |
2301 | | - // Yes, a self-closed tag <blah/> |
| 2306 | + # Yes, a self-closed tag <blah/> |
2302 | 2307 | $state = self::COLON_STATE_TEXT; |
2303 | 2308 | } else { |
2304 | | - // Probably we're jumping the gun, and this is an attribute |
| 2309 | + # Probably we're jumping the gun, and this is an attribute |
2305 | 2310 | $state = self::COLON_STATE_TAG; |
2306 | 2311 | } |
2307 | 2312 | break; |
2308 | | - case 5: // self::COLON_STATE_COMMENT: |
| 2313 | + case 5: # self::COLON_STATE_COMMENT: |
2309 | 2314 | if ( $c === "-" ) { |
2310 | 2315 | $state = self::COLON_STATE_COMMENTDASH; |
2311 | 2316 | } |
— | — | @@ -2470,50 +2475,50 @@ |
2471 | 2476 | $value = $subjPage->getPrefixedUrl(); |
2472 | 2477 | break; |
2473 | 2478 | case 'revisionid': |
2474 | | - // Let the edit saving system know we should parse the page |
2475 | | - // *after* a revision ID has been assigned. |
| 2479 | + # Let the edit saving system know we should parse the page |
| 2480 | + # *after* a revision ID has been assigned. |
2476 | 2481 | $this->mOutput->setFlag( 'vary-revision' ); |
2477 | 2482 | wfDebug( __METHOD__ . ": {{REVISIONID}} used, setting vary-revision...\n" ); |
2478 | 2483 | $value = $this->mRevisionId; |
2479 | 2484 | break; |
2480 | 2485 | case 'revisionday': |
2481 | | - // Let the edit saving system know we should parse the page |
2482 | | - // *after* a revision ID has been assigned. This is for null edits. |
| 2486 | + # Let the edit saving system know we should parse the page |
| 2487 | + # *after* a revision ID has been assigned. This is for null edits. |
2483 | 2488 | $this->mOutput->setFlag( 'vary-revision' ); |
2484 | 2489 | wfDebug( __METHOD__ . ": {{REVISIONDAY}} used, setting vary-revision...\n" ); |
2485 | 2490 | $value = intval( substr( $this->getRevisionTimestamp(), 6, 2 ) ); |
2486 | 2491 | break; |
2487 | 2492 | case 'revisionday2': |
2488 | | - // Let the edit saving system know we should parse the page |
2489 | | - // *after* a revision ID has been assigned. This is for null edits. |
| 2493 | + # Let the edit saving system know we should parse the page |
| 2494 | + # *after* a revision ID has been assigned. This is for null edits. |
2490 | 2495 | $this->mOutput->setFlag( 'vary-revision' ); |
2491 | 2496 | wfDebug( __METHOD__ . ": {{REVISIONDAY2}} used, setting vary-revision...\n" ); |
2492 | 2497 | $value = substr( $this->getRevisionTimestamp(), 6, 2 ); |
2493 | 2498 | break; |
2494 | 2499 | case 'revisionmonth': |
2495 | | - // Let the edit saving system know we should parse the page |
2496 | | - // *after* a revision ID has been assigned. This is for null edits. |
| 2500 | + # Let the edit saving system know we should parse the page |
| 2501 | + # *after* a revision ID has been assigned. This is for null edits. |
2497 | 2502 | $this->mOutput->setFlag( 'vary-revision' ); |
2498 | 2503 | wfDebug( __METHOD__ . ": {{REVISIONMONTH}} used, setting vary-revision...\n" ); |
2499 | 2504 | $value = intval( substr( $this->getRevisionTimestamp(), 4, 2 ) ); |
2500 | 2505 | break; |
2501 | 2506 | case 'revisionyear': |
2502 | | - // Let the edit saving system know we should parse the page |
2503 | | - // *after* a revision ID has been assigned. This is for null edits. |
| 2507 | + # Let the edit saving system know we should parse the page |
| 2508 | + # *after* a revision ID has been assigned. This is for null edits. |
2504 | 2509 | $this->mOutput->setFlag( 'vary-revision' ); |
2505 | 2510 | wfDebug( __METHOD__ . ": {{REVISIONYEAR}} used, setting vary-revision...\n" ); |
2506 | 2511 | $value = substr( $this->getRevisionTimestamp(), 0, 4 ); |
2507 | 2512 | break; |
2508 | 2513 | case 'revisiontimestamp': |
2509 | | - // Let the edit saving system know we should parse the page |
2510 | | - // *after* a revision ID has been assigned. This is for null edits. |
| 2514 | + # Let the edit saving system know we should parse the page |
| 2515 | + # *after* a revision ID has been assigned. This is for null edits. |
2511 | 2516 | $this->mOutput->setFlag( 'vary-revision' ); |
2512 | 2517 | wfDebug( __METHOD__ . ": {{REVISIONTIMESTAMP}} used, setting vary-revision...\n" ); |
2513 | 2518 | $value = $this->getRevisionTimestamp(); |
2514 | 2519 | break; |
2515 | 2520 | case 'revisionuser': |
2516 | | - // Let the edit saving system know we should parse the page |
2517 | | - // *after* a revision ID has been assigned. This is for null edits. |
| 2521 | + # Let the edit saving system know we should parse the page |
| 2522 | + # *after* a revision ID has been assigned. This is for null edits. |
2518 | 2523 | $this->mOutput->setFlag( 'vary-revision' ); |
2519 | 2524 | wfDebug( __METHOD__ . ": {{REVISIONUSER}} used, setting vary-revision...\n" ); |
2520 | 2525 | $value = $this->getRevisionUser(); |
— | — | @@ -2549,8 +2554,8 @@ |
2550 | 2555 | $value = $wgContLang->formatNum( gmdate( 'H', $ts ), true ); |
2551 | 2556 | break; |
2552 | 2557 | case 'currentweek': |
2553 | | - // @bug 4594 PHP5 has it zero padded, PHP4 does not, cast to |
2554 | | - // int to remove the padding |
| 2558 | + # @bug 4594 PHP5 has it zero padded, PHP4 does not, cast to |
| 2559 | + # int to remove the padding |
2555 | 2560 | $value = $wgContLang->formatNum( (int)gmdate( 'W', $ts ) ); |
2556 | 2561 | break; |
2557 | 2562 | case 'currentdow': |
— | — | @@ -2569,8 +2574,8 @@ |
2570 | 2575 | $value = $wgContLang->formatNum( $localHour, true ); |
2571 | 2576 | break; |
2572 | 2577 | case 'localweek': |
2573 | | - // @bug 4594 PHP5 has it zero padded, PHP4 does not, cast to |
2574 | | - // int to remove the padding |
| 2578 | + # @bug 4594 PHP5 has it zero padded, PHP4 does not, cast to |
| 2579 | + # int to remove the padding |
2575 | 2580 | $value = $wgContLang->formatNum( (int)$localWeek ); |
2576 | 2581 | break; |
2577 | 2582 | case 'localdow': |
— | — | @@ -2681,7 +2686,7 @@ |
2682 | 2687 | return $dom; |
2683 | 2688 | } |
2684 | 2689 | |
2685 | | - /* |
| 2690 | + /** |
2686 | 2691 | * Return a three-element array: leading whitespace, string contents, trailing whitespace |
2687 | 2692 | */ |
2688 | 2693 | public static function splitWhitespace( $s ) { |
— | — | @@ -2736,7 +2741,7 @@ |
2737 | 2742 | return $text; |
2738 | 2743 | } |
2739 | 2744 | |
2740 | | - // Clean up argument array - refactored in 1.9 so parserfunctions can use it, too. |
| 2745 | + # Clean up argument array - refactored in 1.9 so parserfunctions can use it, too. |
2741 | 2746 | static function createAssocArgs( $args ) { |
2742 | 2747 | $assocArgs = array(); |
2743 | 2748 | $index = 1; |
— | — | @@ -2777,7 +2782,7 @@ |
2778 | 2783 | * exceeded, provide the values (optional) |
2779 | 2784 | */ |
2780 | 2785 | function limitationWarn( $limitationType, $current=null, $max=null) { |
2781 | | - // does no harm if $current and $max are present but are unnecessary for the message |
| 2786 | + # does no harm if $current and $max are present but are unnecessary for the message |
2782 | 2787 | $warning = wfMsgExt( "$limitationType-warning", array( 'parsemag', 'escape' ), $current, $max ); |
2783 | 2788 | $this->mOutput->addWarning( $warning ); |
2784 | 2789 | $this->addTrackingCategory( "$limitationType-category" ); |
— | — | @@ -2940,8 +2945,8 @@ |
2941 | 2946 | unset( $result[0] ); |
2942 | 2947 | } |
2943 | 2948 | |
2944 | | - // Extract flags into the local scope |
2945 | | - // This allows callers to set flags such as nowiki, found, etc. |
| 2949 | + # Extract flags into the local scope |
| 2950 | + # This allows callers to set flags such as nowiki, found, etc. |
2946 | 2951 | extract( $result ); |
2947 | 2952 | } else { |
2948 | 2953 | $text = $result; |
— | — | @@ -2998,7 +3003,7 @@ |
2999 | 3004 | $this->disableCache(); |
3000 | 3005 | } |
3001 | 3006 | } elseif ( $wgNonincludableNamespaces && in_array( $title->getNamespace(), $wgNonincludableNamespaces ) ) { |
3002 | | - $found = false; // access denied |
| 3007 | + $found = false; # access denied |
3003 | 3008 | wfDebug( __METHOD__.": template inclusion denied for " . $title->getPrefixedDBkey() ); |
3004 | 3009 | } else { |
3005 | 3010 | list( $text, $title ) = $this->getTemplateDom( $title ); |
— | — | @@ -3014,13 +3019,13 @@ |
3015 | 3020 | $found = true; |
3016 | 3021 | } |
3017 | 3022 | } elseif ( $title->isTrans() ) { |
3018 | | - // Interwiki transclusion |
| 3023 | + # Interwiki transclusion |
3019 | 3024 | if ( $this->ot['html'] && !$forceRawInterwiki ) { |
3020 | 3025 | $text = $this->interwikiTransclude( $title, 'render' ); |
3021 | 3026 | $isHTML = true; |
3022 | 3027 | } else { |
3023 | 3028 | $text = $this->interwikiTransclude( $title, 'raw' ); |
3024 | | - // Preprocess it like a template |
| 3029 | + # Preprocess it like a template |
3025 | 3030 | $text = $this->preprocessToDom( $text, self::PTD_FOR_INCLUSION ); |
3026 | 3031 | $isChildObj = true; |
3027 | 3032 | } |
— | — | @@ -3122,7 +3127,7 @@ |
3123 | 3128 | return array( $this->mTplDomCache[$titleText], $title ); |
3124 | 3129 | } |
3125 | 3130 | |
3126 | | - // Cache miss, go to the database |
| 3131 | + # Cache miss, go to the database |
3127 | 3132 | list( $text, $title ) = $this->fetchTemplateAndTitle( $title ); |
3128 | 3133 | |
3129 | 3134 | if ( $text === false ) { |
— | — | @@ -3171,10 +3176,10 @@ |
3172 | 3177 | $finalTitle = $title; |
3173 | 3178 | $deps = array(); |
3174 | 3179 | |
3175 | | - // Loop to fetch the article, with up to 1 redirect |
| 3180 | + # Loop to fetch the article, with up to 1 redirect |
3176 | 3181 | for ( $i = 0; $i < 2 && is_object( $title ); $i++ ) { |
3177 | 3182 | # Give extensions a chance to select the revision instead |
3178 | | - $id = false; // Assume current |
| 3183 | + $id = false; # Assume current |
3179 | 3184 | wfRunHooks( 'BeforeParserFetchTemplateAndtitle', array( $parser, &$title, &$skip, &$id ) ); |
3180 | 3185 | |
3181 | 3186 | if ( $skip ) { |
— | — | @@ -3187,7 +3192,7 @@ |
3188 | 3193 | } |
3189 | 3194 | $rev = $id ? Revision::newFromId( $id ) : Revision::newFromTitle( $title ); |
3190 | 3195 | $rev_id = $rev ? $rev->getId() : 0; |
3191 | | - // If there is no current revision, there is no page |
| 3196 | + # If there is no current revision, there is no page |
3192 | 3197 | if ( $id === false && !$rev ) { |
3193 | 3198 | $linkCache = LinkCache::singleton(); |
3194 | 3199 | $linkCache->addBadLinkObj( $title ); |
— | — | @@ -3214,7 +3219,7 @@ |
3215 | 3220 | if ( $text === false ) { |
3216 | 3221 | break; |
3217 | 3222 | } |
3218 | | - // Redirect? |
| 3223 | + # Redirect? |
3219 | 3224 | $finalTitle = $title; |
3220 | 3225 | $title = Title::newFromRedirect( $text ); |
3221 | 3226 | } |
— | — | @@ -3366,7 +3371,7 @@ |
3367 | 3372 | } |
3368 | 3373 | |
3369 | 3374 | if ( is_array( $output ) ) { |
3370 | | - // Extract flags to local scope (to override $markerType) |
| 3375 | + # Extract flags to local scope (to override $markerType) |
3371 | 3376 | $flags = $output; |
3372 | 3377 | $output = $flags[0]; |
3373 | 3378 | unset( $flags[0] ); |
— | — | @@ -3439,20 +3444,20 @@ |
3440 | 3445 | function doDoubleUnderscore( $text ) { |
3441 | 3446 | wfProfileIn( __METHOD__ ); |
3442 | 3447 | |
3443 | | - // The position of __TOC__ needs to be recorded |
| 3448 | + # The position of __TOC__ needs to be recorded |
3444 | 3449 | $mw = MagicWord::get( 'toc' ); |
3445 | 3450 | if ( $mw->match( $text ) ) { |
3446 | 3451 | $this->mShowToc = true; |
3447 | 3452 | $this->mForceTocPosition = true; |
3448 | 3453 | |
3449 | | - // Set a placeholder. At the end we'll fill it in with the TOC. |
| 3454 | + # Set a placeholder. At the end we'll fill it in with the TOC. |
3450 | 3455 | $text = $mw->replace( '<!--MWTOC-->', $text, 1 ); |
3451 | 3456 | |
3452 | | - // Only keep the first one. |
| 3457 | + # Only keep the first one. |
3453 | 3458 | $text = $mw->replace( '', $text ); |
3454 | 3459 | } |
3455 | 3460 | |
3456 | | - // Now match and remove the rest of them |
| 3461 | + # Now match and remove the rest of them |
3457 | 3462 | $mwa = MagicWord::getDoubleUnderscoreArray(); |
3458 | 3463 | $this->mDoubleUnderscores = $mwa->matchAndRemove( $text ); |
3459 | 3464 | |
— | — | @@ -3528,7 +3533,7 @@ |
3529 | 3534 | $doNumberHeadings = $this->mOptions->getNumberHeadings(); |
3530 | 3535 | $showEditLink = $this->mOptions->getEditSection(); |
3531 | 3536 | |
3532 | | - // Do not call quickUserCan unless necessary |
| 3537 | + # Do not call quickUserCan unless necessary |
3533 | 3538 | if ( $showEditLink && !$this->mTitle->quickUserCan( 'edit' ) ) { |
3534 | 3539 | $showEditLink = 0; |
3535 | 3540 | } |
— | — | @@ -3882,7 +3887,7 @@ |
3883 | 3888 | foreach ( $tree1 as $s ) { |
3884 | 3889 | if ( $targetLevel !== false ) { |
3885 | 3890 | if ( $s['level'] <= $targetLevel ) { |
3886 | | - // We've skipped enough |
| 3891 | + # We've skipped enough |
3887 | 3892 | $targetLevel = false; |
3888 | 3893 | } else { |
3889 | 3894 | continue; |
— | — | @@ -3893,7 +3898,7 @@ |
3894 | 3899 | self::incrementNumbering( $numbering, |
3895 | 3900 | $s['toclevel'], $lastLevel ); |
3896 | 3901 | |
3897 | | - // Rewrite index, byteoffset and number |
| 3902 | + # Rewrite index, byteoffset and number |
3898 | 3903 | if ( $s['fromtitle'] == $titletext ) { |
3899 | 3904 | $s['index'] = $nextIndex++; |
3900 | 3905 | if ( $merged ) { |
— | — | @@ -3906,11 +3911,11 @@ |
3907 | 3912 | $lastLevel = $s['toclevel']; |
3908 | 3913 | $newTree[] = $s; |
3909 | 3914 | } else { |
3910 | | - // We're at $section |
3911 | | - // Insert sections from $tree2 here |
| 3915 | + # We're at $section |
| 3916 | + # Insert sections from $tree2 here |
3912 | 3917 | foreach ( $tree2 as $s2 ) { |
3913 | | - // Rewrite the fields in $s2 |
3914 | | - // before inserting it |
| 3918 | + # Rewrite the fields in $s2 |
| 3919 | + # before inserting it |
3915 | 3920 | $s2['toclevel'] += $s['toclevel'] - 1; |
3916 | 3921 | $s2['level'] += $s['level'] - 1; |
3917 | 3922 | $s2['index'] = $nextIndex++; |
— | — | @@ -3924,7 +3929,7 @@ |
3925 | 3930 | $lastLevel = $s2['toclevel']; |
3926 | 3931 | $newTree[] = $s2; |
3927 | 3932 | } |
3928 | | - // Skip all descendants of $section in $tree1 |
| 3933 | + # Skip all descendants of $section in $tree1 |
3929 | 3934 | $targetLevel = $s['level']; |
3930 | 3935 | $merged = true; |
3931 | 3936 | } |
— | — | @@ -4078,7 +4083,7 @@ |
4079 | 4084 | |
4080 | 4085 | $username = $user->getName(); |
4081 | 4086 | |
4082 | | - // If not given, retrieve from the user object. |
| 4087 | + # If not given, retrieve from the user object. |
4083 | 4088 | if ( $nickname === false ) |
4084 | 4089 | $nickname = $user->getOption( 'nickname' ); |
4085 | 4090 | |
— | — | @@ -4103,7 +4108,7 @@ |
4104 | 4109 | } |
4105 | 4110 | } |
4106 | 4111 | |
4107 | | - // Make sure nickname doesnt get a sig in a sig |
| 4112 | + # Make sure nickname doesnt get a sig in a sig |
4108 | 4113 | $nickname = $this->cleanSigInSig( $nickname ); |
4109 | 4114 | |
4110 | 4115 | # If we're still here, make it a link to the user page |
— | — | @@ -4441,7 +4446,7 @@ |
4442 | 4447 | if ( strpos( $matches[0], '%' ) !== false ) { |
4443 | 4448 | $matches[1] = urldecode( $matches[1] ); |
4444 | 4449 | } |
4445 | | - $tp = Title::newFromText( $matches[1]/*, NS_FILE*/ ); |
| 4450 | + $tp = Title::newFromText( $matches[1] ); |
4446 | 4451 | $nt =& $tp; |
4447 | 4452 | if ( is_null( $nt ) ) { |
4448 | 4453 | # Bogus title. Ignore these so we don't bomb out later. |
— | — | @@ -4472,7 +4477,7 @@ |
4473 | 4478 | $handlerClass = ''; |
4474 | 4479 | } |
4475 | 4480 | if ( !isset( $this->mImageParams[$handlerClass] ) ) { |
4476 | | - // Initialise static lists |
| 4481 | + # Initialise static lists |
4477 | 4482 | static $internalParamNames = array( |
4478 | 4483 | 'horizAlign' => array( 'left', 'right', 'center', 'none' ), |
4479 | 4484 | 'vertAlign' => array( 'baseline', 'sub', 'super', 'top', 'text-top', 'middle', |
— | — | @@ -4491,7 +4496,7 @@ |
4492 | 4497 | } |
4493 | 4498 | } |
4494 | 4499 | |
4495 | | - // Add handler params |
| 4500 | + # Add handler params |
4496 | 4501 | $paramMap = $internalParamMap; |
4497 | 4502 | if ( $handler ) { |
4498 | 4503 | $handlerParamMap = $handler->getParamMap(); |
— | — | @@ -4567,7 +4572,7 @@ |
4568 | 4573 | if ( isset( $paramMap[$magicName] ) ) { |
4569 | 4574 | list( $type, $paramName ) = $paramMap[$magicName]; |
4570 | 4575 | |
4571 | | - // Special case; width and height come in one variable together |
| 4576 | + # Special case; width and height come in one variable together |
4572 | 4577 | if ( $type === 'handler' && $paramName === 'width' ) { |
4573 | 4578 | $m = array(); |
4574 | 4579 | # (bug 13500) In both cases (width/height and width only), |
— | — | @@ -4589,7 +4594,7 @@ |
4590 | 4595 | $params[$type]['width'] = $width; |
4591 | 4596 | $validated = true; |
4592 | 4597 | } |
4593 | | - } // else no validation -- bug 13436 |
| 4598 | + } # else no validation -- bug 13436 |
4594 | 4599 | } else { |
4595 | 4600 | if ( $type === 'handler' ) { |
4596 | 4601 | # Validate handler parameter |
— | — | @@ -4599,9 +4604,9 @@ |
4600 | 4605 | switch( $paramName ) { |
4601 | 4606 | case 'manualthumb': |
4602 | 4607 | case 'alt': |
4603 | | - // @todo Fixme: possibly check validity here for |
4604 | | - // manualthumb? downstream behavior seems odd with |
4605 | | - // missing manual thumbs. |
| 4608 | + # @todo Fixme: possibly check validity here for |
| 4609 | + # manualthumb? downstream behavior seems odd with |
| 4610 | + # missing manual thumbs. |
4606 | 4611 | $validated = true; |
4607 | 4612 | $value = $this->stripAltText( $value, $holders ); |
4608 | 4613 | break; |
— | — | @@ -4629,7 +4634,7 @@ |
4630 | 4635 | } |
4631 | 4636 | break; |
4632 | 4637 | default: |
4633 | | - // Most other things appear to be empty or numeric... |
| 4638 | + # Most other things appear to be empty or numeric... |
4634 | 4639 | $validated = ( $value === false || is_numeric( trim( $value ) ) ); |
4635 | 4640 | } |
4636 | 4641 | } |
— | — | @@ -4801,13 +4806,13 @@ |
4802 | 4807 | private function extractSections( $text, $section, $mode, $newText='' ) { |
4803 | 4808 | global $wgTitle; |
4804 | 4809 | $this->clearState(); |
4805 | | - $this->setTitle( $wgTitle ); // not generally used but removes an ugly failure mode |
| 4810 | + $this->setTitle( $wgTitle ); # not generally used but removes an ugly failure mode |
4806 | 4811 | $this->mOptions = new ParserOptions; |
4807 | 4812 | $this->setOutputType( self::OT_PLAIN ); |
4808 | 4813 | $outText = ''; |
4809 | 4814 | $frame = $this->getPreprocessor()->newFrame(); |
4810 | 4815 | |
4811 | | - // Process section extraction flags |
| 4816 | + # Process section extraction flags |
4812 | 4817 | $flags = 0; |
4813 | 4818 | $sectionParts = explode( '-', $section ); |
4814 | 4819 | $sectionIndex = array_pop( $sectionParts ); |
— | — | @@ -4816,16 +4821,16 @@ |
4817 | 4822 | $flags |= self::PTD_FOR_INCLUSION; |
4818 | 4823 | } |
4819 | 4824 | } |
4820 | | - // Preprocess the text |
| 4825 | + # Preprocess the text |
4821 | 4826 | $root = $this->preprocessToDom( $text, $flags ); |
4822 | 4827 | |
4823 | | - // <h> nodes indicate section breaks |
4824 | | - // They can only occur at the top level, so we can find them by iterating the root's children |
| 4828 | + # <h> nodes indicate section breaks |
| 4829 | + # They can only occur at the top level, so we can find them by iterating the root's children |
4825 | 4830 | $node = $root->getFirstChild(); |
4826 | 4831 | |
4827 | | - // Find the target section |
| 4832 | + # Find the target section |
4828 | 4833 | if ( $sectionIndex == 0 ) { |
4829 | | - // Section zero doesn't nest, level=big |
| 4834 | + # Section zero doesn't nest, level=big |
4830 | 4835 | $targetLevel = 1000; |
4831 | 4836 | } else { |
4832 | 4837 | while ( $node ) { |
— | — | @@ -4844,7 +4849,7 @@ |
4845 | 4850 | } |
4846 | 4851 | |
4847 | 4852 | if ( !$node ) { |
4848 | | - // Not found |
| 4853 | + # Not found |
4849 | 4854 | if ( $mode === 'get' ) { |
4850 | 4855 | return $newText; |
4851 | 4856 | } else { |
— | — | @@ -4852,7 +4857,7 @@ |
4853 | 4858 | } |
4854 | 4859 | } |
4855 | 4860 | |
4856 | | - // Find the end of the section, including nested sections |
| 4861 | + # Find the end of the section, including nested sections |
4857 | 4862 | do { |
4858 | 4863 | if ( $node->getName() === 'h' ) { |
4859 | 4864 | $bits = $node->splitHeading(); |
— | — | @@ -4867,12 +4872,12 @@ |
4868 | 4873 | $node = $node->getNextSibling(); |
4869 | 4874 | } while ( $node ); |
4870 | 4875 | |
4871 | | - // Write out the remainder (in replace mode only) |
| 4876 | + # Write out the remainder (in replace mode only) |
4872 | 4877 | if ( $mode === 'replace' ) { |
4873 | | - // Output the replacement text |
4874 | | - // Add two newlines on -- trailing whitespace in $newText is conventionally |
4875 | | - // stripped by the editor, so we need both newlines to restore the paragraph gap |
4876 | | - // Only add trailing whitespace if there is newText |
| 4878 | + # Output the replacement text |
| 4879 | + # Add two newlines on -- trailing whitespace in $newText is conventionally |
| 4880 | + # stripped by the editor, so we need both newlines to restore the paragraph gap |
| 4881 | + # Only add trailing whitespace if there is newText |
4877 | 4882 | if ( $newText != "" ) { |
4878 | 4883 | $outText .= $newText . "\n\n"; |
4879 | 4884 | } |
— | — | @@ -4884,7 +4889,7 @@ |
4885 | 4890 | } |
4886 | 4891 | |
4887 | 4892 | if ( is_string( $outText ) ) { |
4888 | | - // Re-insert stripped tags |
| 4893 | + # Re-insert stripped tags |
4889 | 4894 | $outText = rtrim( $this->mStripState->unstripBoth( $outText ) ); |
4890 | 4895 | } |
4891 | 4896 | |
— | — | @@ -4923,18 +4928,18 @@ |
4924 | 4929 | $timestamp = $dbr->selectField( 'revision', 'rev_timestamp', |
4925 | 4930 | array( 'rev_id' => $this->mRevisionId ), __METHOD__ ); |
4926 | 4931 | |
4927 | | - // Normalize timestamp to internal MW format for timezone processing. |
4928 | | - // This has the added side-effect of replacing a null value with |
4929 | | - // the current time, which gives us more sensible behavior for |
4930 | | - // previews. |
| 4932 | + # Normalize timestamp to internal MW format for timezone processing. |
| 4933 | + # This has the added side-effect of replacing a null value with |
| 4934 | + # the current time, which gives us more sensible behavior for |
| 4935 | + # previews. |
4931 | 4936 | $timestamp = wfTimestamp( TS_MW, $timestamp ); |
4932 | 4937 | |
4933 | | - // The cryptic '' timezone parameter tells to use the site-default |
4934 | | - // timezone offset instead of the user settings. |
4935 | | - // |
4936 | | - // Since this value will be saved into the parser cache, served |
4937 | | - // to other users, and potentially even used inside links and such, |
4938 | | - // it needs to be consistent for all visitors. |
| 4938 | + # The cryptic '' timezone parameter tells to use the site-default |
| 4939 | + # timezone offset instead of the user settings. |
| 4940 | + # |
| 4941 | + # Since this value will be saved into the parser cache, served |
| 4942 | + # to other users, and potentially even used inside links and such, |
| 4943 | + # it needs to be consistent for all visitors. |
4939 | 4944 | $this->mRevisionTimestamp = $wgContLang->userAdjust( $timestamp, '' ); |
4940 | 4945 | |
4941 | 4946 | wfProfileOut( __METHOD__ ); |
— | — | @@ -4946,8 +4951,8 @@ |
4947 | 4952 | * Get the name of the user that edited the last revision |
4948 | 4953 | */ |
4949 | 4954 | function getRevisionUser() { |
4950 | | - // if this template is subst: the revision id will be blank, |
4951 | | - // so just use the current user's name |
| 4955 | + # if this template is subst: the revision id will be blank, |
| 4956 | + # so just use the current user's name |
4952 | 4957 | if ( $this->mRevisionId ) { |
4953 | 4958 | $revision = Revision::newFromId( $this->mRevisionId ); |
4954 | 4959 | $revuser = $revision->getUserText(); |
— | — | @@ -5115,8 +5120,8 @@ |
5116 | 5121 | $data = array(); |
5117 | 5122 | $data['text'] = $text; |
5118 | 5123 | |
5119 | | - // First, find all strip markers, and store their |
5120 | | - // data in an array. |
| 5124 | + # First, find all strip markers, and store their |
| 5125 | + # data in an array. |
5121 | 5126 | $stripState = new StripState; |
5122 | 5127 | $pos = 0; |
5123 | 5128 | while ( ( $start_pos = strpos( $text, $this->mUniqPrefix, $pos ) ) |
— | — | @@ -5140,12 +5145,12 @@ |
5141 | 5146 | } |
5142 | 5147 | $data['stripstate'] = $stripState; |
5143 | 5148 | |
5144 | | - // Now, find all of our links, and store THEIR |
5145 | | - // data in an array! :) |
| 5149 | + # Now, find all of our links, and store THEIR |
| 5150 | + # data in an array! :) |
5146 | 5151 | $links = array( 'internal' => array(), 'interwiki' => array() ); |
5147 | 5152 | $pos = 0; |
5148 | 5153 | |
5149 | | - // Internal links |
| 5154 | + # Internal links |
5150 | 5155 | while ( ( $start_pos = strpos( $text, '<!--LINK ', $pos ) ) ) { |
5151 | 5156 | list( $ns, $trail ) = explode( ':', substr( $text, $start_pos + strlen( '<!--LINK ' ) ), 2 ); |
5152 | 5157 | |
— | — | @@ -5161,7 +5166,7 @@ |
5162 | 5167 | |
5163 | 5168 | $pos = 0; |
5164 | 5169 | |
5165 | | - // Interwiki links |
| 5170 | + # Interwiki links |
5166 | 5171 | while ( ( $start_pos = strpos( $text, '<!--IWLINK ', $pos ) ) ) { |
5167 | 5172 | $data = substr( $text, $start_pos ); |
5168 | 5173 | $key = trim( substr( $data, 0, strpos( $data, '-->' ) ) ); |
— | — | @@ -5174,21 +5179,27 @@ |
5175 | 5180 | return $data; |
5176 | 5181 | } |
5177 | 5182 | |
5178 | | - function unserialiseHalfParsedText( $data, $intPrefix = null /* Unique identifying prefix */ ) { |
| 5183 | + /** |
| 5184 | + * TODO: document |
| 5185 | + * @param $data Array |
| 5186 | + * @param $intPrefix String unique identifying prefix |
| 5187 | + * @return String |
| 5188 | + */ |
| 5189 | + function unserialiseHalfParsedText( $data, $intPrefix = null ) { |
5179 | 5190 | if ( !$intPrefix ) { |
5180 | 5191 | $intPrefix = $this->getRandomString(); |
5181 | 5192 | } |
5182 | 5193 | |
5183 | | - // First, extract the strip state. |
| 5194 | + # First, extract the strip state. |
5184 | 5195 | $stripState = $data['stripstate']; |
5185 | 5196 | $this->mStripState->general->merge( $stripState->general ); |
5186 | 5197 | $this->mStripState->nowiki->merge( $stripState->nowiki ); |
5187 | 5198 | |
5188 | | - // Now, extract the text, and renumber links |
| 5199 | + # Now, extract the text, and renumber links |
5189 | 5200 | $text = $data['text']; |
5190 | 5201 | $links = $data['linkholder']; |
5191 | 5202 | |
5192 | | - // Internal... |
| 5203 | + # Internal... |
5193 | 5204 | foreach ( $links['internal'] as $ns => $nsLinks ) { |
5194 | 5205 | foreach ( $nsLinks as $key => $entry ) { |
5195 | 5206 | $newKey = $intPrefix . '-' . $key; |
— | — | @@ -5198,7 +5209,7 @@ |
5199 | 5210 | } |
5200 | 5211 | } |
5201 | 5212 | |
5202 | | - // Interwiki... |
| 5213 | + # Interwiki... |
5203 | 5214 | foreach ( $links['interwiki'] as $key => $entry ) { |
5204 | 5215 | $newKey = "$intPrefix-$key"; |
5205 | 5216 | $this->mLinkHolders->interwikis[$newKey] = $entry; |
— | — | @@ -5206,7 +5217,7 @@ |
5207 | 5218 | $text = str_replace( "<!--IWLINK $key-->", "<!--IWLINK $newKey-->", $text ); |
5208 | 5219 | } |
5209 | 5220 | |
5210 | | - // Should be good to go. |
| 5221 | + # Should be good to go. |
5211 | 5222 | return $text; |
5212 | 5223 | } |
5213 | 5224 | } |