r64407 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r64406‎ | r64407 | r64408 >
Date:21:20, 30 March 2010
Author:happy-melon
Status:resolved (Comments)
Tags:
Comment:
Overhaul code format to coding conventions.
Modified paths:
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/parser/Parser.php
@@ -45,8 +45,7 @@
4646 *
4747 * @ingroup Parser
4848 */
49 -class Parser
50 -{
 49+class Parser {
5150 /**
5251 * Update this version number when the ParserOutput format
5352 * changes in an incompatible way, so the parser cache
@@ -93,10 +92,10 @@
9493 * @private
9594 */
9695 # Persistent:
97 - var $mTagHooks, $mTransparentTagHooks, $mFunctionHooks, $mFunctionSynonyms, $mVariables,
98 - $mSubstWords, $mImageParams, $mImageParamsMagicArray, $mStripList, $mMarkerIndex,
99 - $mPreprocessor, $mExtLinkBracketedRegex, $mUrlProtocols, $mDefaultStripList,
100 - $mVarCache, $mConf, $mFunctionTagHooks;
 96+ var $mTagHooks, $mTransparentTagHooks, $mFunctionHooks, $mFunctionSynonyms, $mVariables;
 97+ var $mSubstWords, $mImageParams, $mImageParamsMagicArray, $mStripList, $mMarkerIndex;
 98+ var $mPreprocessor, $mExtLinkBracketedRegex, $mUrlProtocols, $mDefaultStripList;
 99+ var $mVarCache, $mConf, $mFunctionTagHooks;
101100
102101
103102 # Cleared with clearState():
@@ -110,13 +109,13 @@
111110
112111 # Temporary
113112 # These are variables reset at least once per parse regardless of $clearState
114 - var $mOptions, // ParserOptions object
115 - $mTitle, // Title context, used for self-link rendering and similar things
116 - $mOutputType, // Output type, one of the OT_xxx constants
117 - $ot, // Shortcut alias, see setOutputType()
118 - $mRevisionId, // ID to display in {{REVISIONID}} tags
119 - $mRevisionTimestamp, // The timestamp of the specified revision ID
120 - $mRevIdForTs; // The revision ID which was used to fetch the timestamp
 113+ var $mOptions; // ParserOptions object
 114+ var $mTitle; // Title context, used for self-link rendering and similar things
 115+ var $mOutputType; // Output type, one of the OT_xxx constants
 116+ var $ot; // Shortcut alias, see setOutputType()
 117+ var $mRevisionId; // ID to display in {{REVISIONID}} tags
 118+ var $mRevisionTimestamp; // The timestamp of the specified revision ID
 119+ var $mRevIdForTs; // The revision ID which was used to fetch the timestamp
121120
122121 /**#@-*/
123122
@@ -216,7 +215,7 @@
217216 * Must not consist of all title characters, or else it will change
218217 * the behaviour of <nowiki> in a link.
219218 */
220 - #$this->mUniqPrefix = "\x07UNIQ" . Parser::getRandomString();
 219+ # $this->mUniqPrefix = "\x07UNIQ" . Parser::getRandomString();
221220 # Changed to \x7f to allow XML double-parsing -- TS
222221 $this->mUniqPrefix = "\x7fUNIQ" . self::getRandomString();
223222
@@ -279,14 +278,14 @@
280279 * @public
281280 */
282281 function uniqPrefix() {
283 - if( !isset( $this->mUniqPrefix ) ) {
 282+ if ( !isset( $this->mUniqPrefix ) ) {
284283 // @todo Fixme: this is probably *horribly wrong*
285284 // LanguageConverter seems to want $wgParser's uniqPrefix, however
286285 // if this is called for a parser cache hit, the parser may not
287286 // have ever been initialized in the first place.
288287 // Not really sure what the heck is supposed to be going on here.
289288 return '';
290 - //throw new MWException( "Accessing uninitialized mUniqPrefix" );
 289+ // throw new MWException( "Accessing uninitialized mUniqPrefix" );
291290 }
292291 return $this->mUniqPrefix;
293292 }
@@ -323,7 +322,7 @@
324323
325324 $oldRevisionId = $this->mRevisionId;
326325 $oldRevisionTimestamp = $this->mRevisionTimestamp;
327 - if( $revid !== null ) {
 326+ if ( $revid !== null ) {
328327 $this->mRevisionId = $revid;
329328 $this->mRevisionTimestamp = null;
330329 }
@@ -342,9 +341,9 @@
343342 '/(.) (?=\\?|:|;|!|%|\\302\\273)/' => '\\1&nbsp;\\2',
344343 # french spaces, Guillemet-right
345344 '/(\\302\\253) /' => '\\1&nbsp;',
346 - '/&nbsp;(!\s*important)/' => ' \\1', #Beware of CSS magic word !important, bug #11874.
 345+ '/&nbsp;(!\s*important)/' => ' \\1', # Beware of CSS magic word !important, bug #11874.
347346 );
348 - $text = preg_replace( array_keys($fixtags), array_values($fixtags), $text );
 347+ $text = preg_replace( array_keys( $fixtags ), array_values( $fixtags ), $text );
349348
350349 $text = $this->doBlockLevels( $text, $linestart );
351350
@@ -379,12 +378,11 @@
380379 $elements = array_keys( $this->mTransparentTagHooks );
381380 $text = self::extractTagsAndParams( $elements, $text, $matches, $uniq_prefix );
382381
383 - foreach( $matches as $marker => $data ) {
 382+ foreach ( $matches as $marker => $data ) {
384383 list( $element, $content, $params, $tag ) = $data;
385384 $tagName = strtolower( $element );
386 - if( isset( $this->mTransparentTagHooks[$tagName] ) ) {
387 - $output = call_user_func_array( $this->mTransparentTagHooks[$tagName],
388 - array( $content, $params, $this ) );
 385+ if ( isset( $this->mTransparentTagHooks[$tagName] ) ) {
 386+ $output = call_user_func_array( $this->mTransparentTagHooks[$tagName], array( $content, $params, $this ) );
389387 } else {
390388 $output = $tag;
391389 }
@@ -481,7 +479,7 @@
482480 $this->setOutputType( self::OT_PREPROCESS );
483481 $this->mOptions = $options;
484482 $this->setTitle( $title );
485 - if( $revid !== null ) {
 483+ if ( $revid !== null ) {
486484 $this->mRevisionId = $revid;
487485 }
488486 wfRunHooks( 'ParserBeforeStrip', array( &$this, &$text, &$this->mStripState ) );
@@ -517,7 +515,7 @@
518516 * @static
519517 */
520518 function getRandomString() {
521 - return dechex(mt_rand(0, 0x7fffffff)) . dechex(mt_rand(0, 0x7fffffff));
 519+ return dechex( mt_rand( 0, 0x7fffffff ) ) . dechex( mt_rand( 0, 0x7fffffff ) );
522520 }
523521
524522 function &getTitle() { return $this->mTitle; }
@@ -566,7 +564,7 @@
567565 * @public
568566 * @static
569567 */
570 - function extractTagsAndParams($elements, $text, &$matches, $uniq_prefix = ''){
 568+ function extractTagsAndParams( $elements, $text, &$matches, $uniq_prefix = '' ) {
571569 static $n = 1;
572570 $stripped = '';
573571 $matches = array();
@@ -577,10 +575,10 @@
578576 while ( $text != '' ) {
579577 $p = preg_split( $start, $text, 2, PREG_SPLIT_DELIM_CAPTURE );
580578 $stripped .= $p[0];
581 - if( count( $p ) < 5 ) {
 579+ if ( count( $p ) < 5 ) {
582580 break;
583581 }
584 - if( count( $p ) > 5 ) {
 582+ if ( count( $p ) > 5 ) {
585583 // comment
586584 $element = $p[4];
587585 $attributes = '';
@@ -594,7 +592,7 @@
595593 $inside = $p[4];
596594 }
597595
598 - $marker = "$uniq_prefix-$element-" . sprintf('%08X', $n++) . self::MARKER_SUFFIX;
 596+ $marker = "$uniq_prefix-$element-" . sprintf( '%08X', $n++ ) . self::MARKER_SUFFIX;
599597 $stripped .= $marker;
600598
601599 if ( $close === '/>' ) {
@@ -603,14 +601,14 @@
604602 $text = $inside;
605603 $tail = null;
606604 } else {
607 - if( $element === '!--' ) {
 605+ if ( $element === '!--' ) {
608606 $end = '/(-->)/';
609607 } else {
610608 $end = "/(<\\/$element\\s*>)/i";
611609 }
612610 $q = preg_split( $end, $inside, 2, PREG_SPLIT_DELIM_CAPTURE );
613611 $content = $q[0];
614 - if( count( $q ) < 3 ) {
 612+ if ( count( $q ) < 3 ) {
615613 # No end tag -- let it run out to the end of the text.
616614 $tail = '';
617615 $text = '';
@@ -638,7 +636,7 @@
639637 /**
640638 * @deprecated use replaceVariables
641639 */
642 - function strip( $text, $state, $stripcomments = false , $dontstrip = array () ) {
 640+ function strip( $text, $state, $stripcomments = false , $dontstrip = array() ) {
643641 return $text;
644642 }
645643
@@ -698,22 +696,22 @@
699697 *
700698 * @private
701699 */
702 - function doTableStuff ( $text ) {
 700+ function doTableStuff( $text ) {
703701 wfProfileIn( __METHOD__ );
704702
705703 $lines = StringUtils::explode( "\n", $text );
706704 $out = '';
707 - $td_history = array (); // Is currently a td tag open?
708 - $last_tag_history = array (); // Save history of last lag activated (td, th or caption)
709 - $tr_history = array (); // Is currently a tr tag open?
710 - $tr_attributes = array (); // history of tr attributes
 705+ $td_history = array(); // Is currently a td tag open?
 706+ $last_tag_history = array(); // Save history of last lag activated (td, th or caption)
 707+ $tr_history = array(); // Is currently a tr tag open?
 708+ $tr_attributes = array(); // history of tr attributes
711709 $has_opened_tr = array(); // Did this table open a <tr> element?
712710 $indent_level = 0; // indent level of the table
713711
714712 foreach ( $lines as $outLine ) {
715713 $line = trim( $outLine );
716714
717 - if( $line == '' ) { // empty line, go to next line
 715+ if ( $line == '' ) { // empty line, go to next line
718716 $out .= $outLine."\n";
719717 continue;
720718 }
@@ -725,7 +723,7 @@
726724 $indent_level = strlen( $matches[1] );
727725
728726 $attributes = $this->mStripState->unstripBoth( $matches[2] );
729 - $attributes = Sanitizer::fixTagAttributes ( $attributes , 'table' );
 727+ $attributes = Sanitizer::fixTagAttributes( $attributes , 'table' );
730728
731729 $outLine = str_repeat( '<dl><dd>' , $indent_level ) . "<table{$attributes}>";
732730 array_push( $td_history , false );
@@ -733,29 +731,29 @@
734732 array_push( $tr_history , false );
735733 array_push( $tr_attributes , '' );
736734 array_push( $has_opened_tr , false );
737 - } else if ( count ( $td_history ) == 0 ) {
 735+ } elseif ( count( $td_history ) == 0 ) {
738736 // Don't do any of the following
739737 $out .= $outLine."\n";
740738 continue;
741 - } else if ( substr ( $line , 0 , 2 ) === '|}' ) {
 739+ } elseif ( substr( $line , 0 , 2 ) === '|}' ) {
742740 // We are ending a table
743 - $line = '</table>' . substr ( $line , 2 );
744 - $last_tag = array_pop ( $last_tag_history );
 741+ $line = '</table>' . substr( $line , 2 );
 742+ $last_tag = array_pop( $last_tag_history );
745743
746 - if ( !array_pop ( $has_opened_tr ) ) {
 744+ if ( !array_pop( $has_opened_tr ) ) {
747745 $line = "<tr><td></td></tr>{$line}";
748746 }
749747
750 - if ( array_pop ( $tr_history ) ) {
 748+ if ( array_pop( $tr_history ) ) {
751749 $line = "</tr>{$line}";
752750 }
753751
754 - if ( array_pop ( $td_history ) ) {
 752+ if ( array_pop( $td_history ) ) {
755753 $line = "</{$last_tag}>{$line}";
756754 }
757 - array_pop ( $tr_attributes );
 755+ array_pop( $tr_attributes );
758756 $outLine = $line . str_repeat( '</dd></dl>' , $indent_level );
759 - } else if ( substr ( $line , 0 , 2 ) === '|-' ) {
 757+ } elseif ( substr( $line , 0 , 2 ) === '|-' ) {
760758 // Now we have a table row
761759 $line = preg_replace( '#^\|-+#', '', $line );
762760
@@ -766,34 +764,33 @@
767765 array_push( $tr_attributes, $attributes );
768766
769767 $line = '';
770 - $last_tag = array_pop ( $last_tag_history );
771 - array_pop ( $has_opened_tr );
772 - array_push ( $has_opened_tr , true );
 768+ $last_tag = array_pop( $last_tag_history );
 769+ array_pop( $has_opened_tr );
 770+ array_push( $has_opened_tr , true );
773771
774 - if ( array_pop ( $tr_history ) ) {
 772+ if ( array_pop( $tr_history ) ) {
775773 $line = '</tr>';
776774 }
777775
778 - if ( array_pop ( $td_history ) ) {
 776+ if ( array_pop( $td_history ) ) {
779777 $line = "</{$last_tag}>{$line}";
780778 }
781779
782780 $outLine = $line;
783 - array_push ( $tr_history , false );
784 - array_push ( $td_history , false );
785 - array_push ( $last_tag_history , '' );
786 - }
787 - else if ( $first_character === '|' || $first_character === '!' || substr ( $line , 0 , 2 ) === '|+' ) {
 781+ array_push( $tr_history , false );
 782+ array_push( $td_history , false );
 783+ array_push( $last_tag_history , '' );
 784+ } elseif ( $first_character === '|' || $first_character === '!' || substr( $line , 0 , 2 ) === '|+' ) {
788785 // This might be cell elements, td, th or captions
789 - if ( substr ( $line , 0 , 2 ) === '|+' ) {
 786+ if ( substr( $line , 0 , 2 ) === '|+' ) {
790787 $first_character = '+';
791 - $line = substr ( $line , 1 );
 788+ $line = substr( $line , 1 );
792789 }
793790
794 - $line = substr ( $line , 1 );
 791+ $line = substr( $line , 1 );
795792
796793 if ( $first_character === '!' ) {
797 - $line = str_replace ( '!!' , '||' , $line );
 794+ $line = str_replace( '!!' , '||' , $line );
798795 }
799796
800797 // Split up multiple cells on the same line.
@@ -805,71 +802,68 @@
806803 $outLine = '';
807804
808805 // Loop through each table cell
809 - foreach ( $cells as $cell )
810 - {
 806+ foreach ( $cells as $cell ) {
811807 $previous = '';
812 - if ( $first_character !== '+' )
813 - {
814 - $tr_after = array_pop ( $tr_attributes );
815 - if ( !array_pop ( $tr_history ) ) {
 808+ if ( $first_character !== '+' ) {
 809+ $tr_after = array_pop( $tr_attributes );
 810+ if ( !array_pop( $tr_history ) ) {
816811 $previous = "<tr{$tr_after}>\n";
817812 }
818 - array_push ( $tr_history , true );
819 - array_push ( $tr_attributes , '' );
820 - array_pop ( $has_opened_tr );
821 - array_push ( $has_opened_tr , true );
 813+ array_push( $tr_history , true );
 814+ array_push( $tr_attributes , '' );
 815+ array_pop( $has_opened_tr );
 816+ array_push( $has_opened_tr , true );
822817 }
823818
824 - $last_tag = array_pop ( $last_tag_history );
 819+ $last_tag = array_pop( $last_tag_history );
825820
826 - if ( array_pop ( $td_history ) ) {
 821+ if ( array_pop( $td_history ) ) {
827822 $previous = "</{$last_tag}>{$previous}";
828823 }
829824
830825 if ( $first_character === '|' ) {
831826 $last_tag = 'td';
832 - } else if ( $first_character === '!' ) {
 827+ } elseif ( $first_character === '!' ) {
833828 $last_tag = 'th';
834 - } else if ( $first_character === '+' ) {
 829+ } elseif ( $first_character === '+' ) {
835830 $last_tag = 'caption';
836831 } else {
837832 $last_tag = '';
838833 }
839834
840 - array_push ( $last_tag_history , $last_tag );
 835+ array_push( $last_tag_history , $last_tag );
841836
842837 // A cell could contain both parameters and data
843 - $cell_data = explode ( '|' , $cell , 2 );
 838+ $cell_data = explode( '|' , $cell , 2 );
844839
845840 // Bug 553: Note that a '|' inside an invalid link should not
846841 // be mistaken as delimiting cell parameters
847842 if ( strpos( $cell_data[0], '[[' ) !== false ) {
848843 $cell = "{$previous}<{$last_tag}>{$cell}";
849 - } else if ( count ( $cell_data ) == 1 )
 844+ } elseif ( count( $cell_data ) == 1 ) {
850845 $cell = "{$previous}<{$last_tag}>{$cell_data[0]}";
851 - else {
 846+ } else {
852847 $attributes = $this->mStripState->unstripBoth( $cell_data[0] );
853848 $attributes = Sanitizer::fixTagAttributes( $attributes , $last_tag );
854849 $cell = "{$previous}<{$last_tag}{$attributes}>{$cell_data[1]}";
855850 }
856851
857852 $outLine .= $cell;
858 - array_push ( $td_history , true );
 853+ array_push( $td_history , true );
859854 }
860855 }
861856 $out .= $outLine . "\n";
862857 }
863858
864859 // Closing open td, tr && table
865 - while ( count ( $td_history ) > 0 )
866 - {
867 - if ( array_pop ( $td_history ) ) {
 860+ while ( count( $td_history ) > 0 ) {
 861+ if ( array_pop( $td_history ) ) {
868862 $out .= "</td>\n";
869863 }
870 - if ( array_pop ( $tr_history ) ) {
 864+ if ( array_pop( $tr_history ) ) {
871865 $out .= "</tr>\n";
872866 }
873 - if ( !array_pop ( $has_opened_tr ) ) {
 867+ if ( !array_pop( $has_opened_tr ) ) {
874868 $out .= "<tr><td></td></tr>\n" ;
875869 }
876870
@@ -882,7 +876,7 @@
883877 }
884878
885879 // special case: don't return empty table
886 - if( $out === "<table>\n<tr><td></td></tr>\n</table>" ) {
 880+ if ( $out === "<table>\n<tr><td></td></tr>\n</table>" ) {
887881 $out = '';
888882 }
889883
@@ -909,18 +903,18 @@
910904 }
911905
912906 // if $frame is provided, then use $frame for replacing any variables
913 - if ($frame) {
 907+ if ( $frame ) {
914908 // use frame depth to infer how include/noinclude tags should be handled
915909 // depth=0 means this is the top-level document; otherwise it's an included document
916 - if( !$frame->depth )
 910+ if ( !$frame->depth ) {
917911 $flag = 0;
918 - else
 912+ } else {
919913 $flag = Parser::PTD_FOR_INCLUSION;
920914 $dom = $this->preprocessToDom( $text, $flag );
921915 $text = $frame->expand( $dom );
922 - }
923 - // if $frame is not provided, then use old-style replaceVariables
924 - else {
 916+ }
 917+ } else {
 918+ // if $frame is not provided, then use old-style replaceVariables
925919 $text = $this->replaceVariables( $text );
926920 }
927921
@@ -938,7 +932,7 @@
939933 $text = $this->doDoubleUnderscore( $text );
940934
941935 $text = $this->doHeadings( $text );
942 - if( $this->mOptions->getUseDynamicDates() ) {
 936+ if ( $this->mOptions->getUseDynamicDates() ) {
943937 $df = DateFormatter::getInstance();
944938 $text = $df->reformat( $this->mOptions->getDateFormat(), $text );
945939 }
@@ -948,7 +942,7 @@
949943
950944 # replaceInternalLinks may sometimes leave behind
951945 # absolute URLs, which have to be masked to hide them from replaceExternalLinks
952 - $text = str_replace($this->mUniqPrefix.'NOPARSE', '', $text);
 946+ $text = str_replace( $this->mUniqPrefix.'NOPARSE', '', $text );
953947
954948 $text = $this->doMagicLinks( $text );
955949 $text = $this->formatHeadings( $text, $origText, $isMain );
@@ -1009,7 +1003,7 @@
10101004 $id = $m[4];
10111005 } else {
10121006 throw new MWException( __METHOD__.': unrecognised match type "' .
1013 - substr($m[0], 0, 20 ) . '"' );
 1007+ substr( $m[0], 0, 20 ) . '"' );
10141008 }
10151009 $url = wfMsg( $urlmsg, $id);
10161010 $sk = $this->mOptions->getSkin();
@@ -1048,9 +1042,9 @@
10491043 # removeHTMLtags()) should not be included in
10501044 # URLs, per RFC 2396.
10511045 $m2 = array();
1052 - if (preg_match('/&(lt|gt);/', $url, $m2, PREG_OFFSET_CAPTURE)) {
1053 - $trail = substr($url, $m2[0][1]) . $trail;
1054 - $url = substr($url, 0, $m2[0][1]);
 1046+ if ( preg_match( '/&(lt|gt);/', $url, $m2, PREG_OFFSET_CAPTURE ) ) {
 1047+ $trail = substr( $url, $m2[0][1] ) . $trail;
 1048+ $url = substr( $url, 0, $m2[0][1] );
10551049 }
10561050
10571051 # Move trailing punctuation to $trail
@@ -1112,7 +1106,7 @@
11131107 foreach ( $lines as $line ) {
11141108 $outtext .= $this->doQuotes( $line ) . "\n";
11151109 }
1116 - $outtext = substr($outtext, 0,-1);
 1110+ $outtext = substr( $outtext, 0,-1 );
11171111 wfProfileOut( __METHOD__ );
11181112 return $outtext;
11191113 }
@@ -1122,39 +1116,38 @@
11231117 */
11241118 public function doQuotes( $text ) {
11251119 $arr = preg_split( "/(''+)/", $text, -1, PREG_SPLIT_DELIM_CAPTURE );
1126 - if ( count( $arr ) == 1 )
 1120+ if ( count( $arr ) == 1 ) {
11271121 return $text;
1128 - else
1129 - {
 1122+ } else {
11301123 # First, do some preliminary work. This may shift some apostrophes from
11311124 # being mark-up to being text. It also counts the number of occurrences
11321125 # of bold and italics mark-ups.
11331126 $i = 0;
11341127 $numbold = 0;
11351128 $numitalics = 0;
1136 - foreach ( $arr as $r )
1137 - {
1138 - if ( ( $i % 2 ) == 1 )
1139 - {
 1129+ foreach ( $arr as $r ) {
 1130+ if ( ( $i % 2 ) == 1 ) {
11401131 # If there are ever four apostrophes, assume the first is supposed to
11411132 # be text, and the remaining three constitute mark-up for bold text.
1142 - if ( strlen( $arr[$i] ) == 4 )
1143 - {
 1133+ if ( strlen( $arr[$i] ) == 4 ) {
11441134 $arr[$i-1] .= "'";
11451135 $arr[$i] = "'''";
1146 - }
1147 - # If there are more than 5 apostrophes in a row, assume they're all
1148 - # text except for the last 5.
1149 - else if ( strlen( $arr[$i] ) > 5 )
1150 - {
 1136+ } elseif ( strlen( $arr[$i] ) > 5 ) {
 1137+ # If there are more than 5 apostrophes in a row, assume they're all
 1138+ # text except for the last 5.
11511139 $arr[$i-1] .= str_repeat( "'", strlen( $arr[$i] ) - 5 );
11521140 $arr[$i] = "'''''";
11531141 }
11541142 # Count the number of occurrences of bold and italics mark-ups.
11551143 # We are not counting sequences of five apostrophes.
1156 - if ( strlen( $arr[$i] ) == 2 ) { $numitalics++; }
1157 - else if ( strlen( $arr[$i] ) == 3 ) { $numbold++; }
1158 - else if ( strlen( $arr[$i] ) == 5 ) { $numitalics++; $numbold++; }
 1144+ if ( strlen( $arr[$i] ) == 2 ) {
 1145+ $numitalics++;
 1146+ } elseif ( strlen( $arr[$i] ) == 3 ) {
 1147+ $numbold++;
 1148+ } elseif ( strlen( $arr[$i] ) == 5 ) {
 1149+ $numitalics++;
 1150+ $numbold++;
 1151+ }
11591152 }
11601153 $i++;
11611154 }
@@ -1163,49 +1156,47 @@
11641157 # that one of the bold ones was meant to be an apostrophe followed
11651158 # by italics. Which one we cannot know for certain, but it is more
11661159 # likely to be one that has a single-letter word before it.
1167 - if ( ( $numbold % 2 == 1 ) && ( $numitalics % 2 == 1 ) )
1168 - {
 1160+ if ( ( $numbold % 2 == 1 ) && ( $numitalics % 2 == 1 ) ) {
11691161 $i = 0;
11701162 $firstsingleletterword = -1;
11711163 $firstmultiletterword = -1;
11721164 $firstspace = -1;
1173 - foreach ( $arr as $r )
1174 - {
1175 - if ( ( $i % 2 == 1 ) and ( strlen( $r ) == 3 ) )
1176 - {
1177 - $x1 = substr ($arr[$i-1], -1);
1178 - $x2 = substr ($arr[$i-1], -2, 1);
1179 - if ($x1 === ' ') {
1180 - if ($firstspace == -1) $firstspace = $i;
1181 - } else if ($x2 === ' ') {
1182 - if ($firstsingleletterword == -1) $firstsingleletterword = $i;
 1165+ foreach ( $arr as $r ) {
 1166+ if ( ( $i % 2 == 1 ) and ( strlen( $r ) == 3 ) ) {
 1167+ $x1 = substr( $arr[$i-1], -1 );
 1168+ $x2 = substr( $arr[$i-1], -2, 1 );
 1169+ if ( $x1 === ' ' ) {
 1170+ if ( $firstspace == -1 ) {
 1171+ $firstspace = $i;
 1172+ }
 1173+ } elseif ( $x2 === ' ') {
 1174+ if ( $firstsingleletterword == -1 ) {
 1175+ $firstsingleletterword = $i;
 1176+ }
11831177 } else {
1184 - if ($firstmultiletterword == -1) $firstmultiletterword = $i;
 1178+ if ( $firstmultiletterword == -1 ) {
 1179+ $firstmultiletterword = $i;
 1180+ }
11851181 }
11861182 }
11871183 $i++;
11881184 }
11891185
11901186 # If there is a single-letter word, use it!
1191 - if ($firstsingleletterword > -1)
1192 - {
1193 - $arr [ $firstsingleletterword ] = "''";
1194 - $arr [ $firstsingleletterword-1 ] .= "'";
 1187+ if ( $firstsingleletterword > -1 ) {
 1188+ $arr[$firstsingleletterword] = "''";
 1189+ $arr[$firstsingleletterword-1] .= "'";
 1190+ } elseif ( $firstmultiletterword > -1 ) {
 1191+ # If not, but there's a multi-letter word, use that one.
 1192+ $arr[$firstmultiletterword] = "''";
 1193+ $arr[$firstmultiletterword-1] .= "'";
 1194+ } elseif ( $firstspace > -1 ) {
 1195+ # ... otherwise use the first one that has neither.
 1196+ # (notice that it is possible for all three to be -1 if, for example,
 1197+ # there is only one pentuple-apostrophe in the line)
 1198+ $arr[$firstspace] = "''";
 1199+ $arr[$firstspace-1] .= "'";
11951200 }
1196 - # If not, but there's a multi-letter word, use that one.
1197 - else if ($firstmultiletterword > -1)
1198 - {
1199 - $arr [ $firstmultiletterword ] = "''";
1200 - $arr [ $firstmultiletterword-1 ] .= "'";
1201 - }
1202 - # ... otherwise use the first one that has neither.
1203 - # (notice that it is possible for all three to be -1 if, for example,
1204 - # there is only one pentuple-apostrophe in the line)
1205 - else if ($firstspace > -1)
1206 - {
1207 - $arr [ $firstspace ] = "''";
1208 - $arr [ $firstspace-1 ] .= "'";
1209 - }
12101201 }
12111202
12121203 # Now let's actually convert our apostrophic mush to HTML!
@@ -1213,71 +1204,70 @@
12141205 $buffer = '';
12151206 $state = '';
12161207 $i = 0;
1217 - foreach ($arr as $r)
1218 - {
1219 - if (($i % 2) == 0)
1220 - {
1221 - if ($state === 'both')
 1208+ foreach ( $arr as $r ) {
 1209+ if ( ( $i % 2 ) == 0 ) {
 1210+ if ( $state === 'both' ) {
12221211 $buffer .= $r;
1223 - else
 1212+ } else {
12241213 $output .= $r;
1225 - }
1226 - else
1227 - {
1228 - if (strlen ($r) == 2)
1229 - {
1230 - if ($state === 'i')
1231 - { $output .= '</i>'; $state = ''; }
1232 - else if ($state === 'bi')
1233 - { $output .= '</i>'; $state = 'b'; }
1234 - else if ($state === 'ib')
1235 - { $output .= '</b></i><b>'; $state = 'b'; }
1236 - else if ($state === 'both')
1237 - { $output .= '<b><i>'.$buffer.'</i>'; $state = 'b'; }
1238 - else # $state can be 'b' or ''
1239 - { $output .= '<i>'; $state .= 'i'; }
12401214 }
1241 - else if (strlen ($r) == 3)
1242 - {
1243 - if ($state === 'b')
1244 - { $output .= '</b>'; $state = ''; }
1245 - else if ($state === 'bi')
1246 - { $output .= '</i></b><i>'; $state = 'i'; }
1247 - else if ($state === 'ib')
1248 - { $output .= '</b>'; $state = 'i'; }
1249 - else if ($state === 'both')
1250 - { $output .= '<i><b>'.$buffer.'</b>'; $state = 'i'; }
1251 - else # $state can be 'i' or ''
1252 - { $output .= '<b>'; $state .= 'b'; }
 1215+ } else {
 1216+ if ( strlen( $r ) == 2 ) {
 1217+ if ( $state === 'i' ) {
 1218+ $output .= '</i>'; $state = '';
 1219+ } elseif ( $state === 'bi' ) {
 1220+ $output .= '</i>'; $state = 'b';
 1221+ } elseif ( $state === 'ib' ) {
 1222+ $output .= '</b></i><b>'; $state = 'b';
 1223+ } elseif ( $state === 'both' ) {
 1224+ $output .= '<b><i>'.$buffer.'</i>'; $state = 'b';
 1225+ } else { # $state can be 'b' or ''
 1226+ $output .= '<i>'; $state .= 'i';
 1227+ }
 1228+ } elseif ( strlen( $r ) == 3 ) {
 1229+ if ( $state === 'b' ) {
 1230+ $output .= '</b>'; $state = '';
 1231+ } elseif ( $state === 'bi' ) {
 1232+ $output .= '</i></b><i>'; $state = 'i';
 1233+ } elseif ( $state === 'ib' ) {
 1234+ $output .= '</b>'; $state = 'i';
 1235+ } elseif ( $state === 'both' ) {
 1236+ $output .= '<i><b>'.$buffer.'</b>'; $state = 'i';
 1237+ } else { # $state can be 'i' or ''
 1238+ $output .= '<b>'; $state .= 'b';
 1239+ }
 1240+ } elseif ( strlen( $r ) == 5 ) {
 1241+ if ( $state === 'b' ) {
 1242+ $output .= '</b><i>'; $state = 'i';
 1243+ } elseif ( $state === 'i' ) {
 1244+ $output .= '</i><b>'; $state = 'b';
 1245+ } elseif ( $state === 'bi' ) {
 1246+ $output .= '</i></b>'; $state = '';
 1247+ } elseif ( $state === 'ib' ) {
 1248+ $output .= '</b></i>'; $state = '';
 1249+ } elseif ( $state === 'both' ) {
 1250+ $output .= '<i><b>'.$buffer.'</b></i>'; $state = '';
 1251+ } else { # ($state == '')
 1252+ $buffer = ''; $state = 'both';
 1253+ }
12531254 }
1254 - else if (strlen ($r) == 5)
1255 - {
1256 - if ($state === 'b')
1257 - { $output .= '</b><i>'; $state = 'i'; }
1258 - else if ($state === 'i')
1259 - { $output .= '</i><b>'; $state = 'b'; }
1260 - else if ($state === 'bi')
1261 - { $output .= '</i></b>'; $state = ''; }
1262 - else if ($state === 'ib')
1263 - { $output .= '</b></i>'; $state = ''; }
1264 - else if ($state === 'both')
1265 - { $output .= '<i><b>'.$buffer.'</b></i>'; $state = ''; }
1266 - else # ($state == '')
1267 - { $buffer = ''; $state = 'both'; }
1268 - }
12691255 }
12701256 $i++;
12711257 }
12721258 # Now close all remaining tags. Notice that the order is important.
1273 - if ($state === 'b' || $state === 'ib')
 1259+ if ( $state === 'b' || $state === 'ib' ) {
12741260 $output .= '</b>';
1275 - if ($state === 'i' || $state === 'bi' || $state === 'ib')
 1261+ }
 1262+ if ( $state === 'i' || $state === 'bi' || $state === 'ib' ) {
12761263 $output .= '</i>';
1277 - if ($state === 'bi')
 1264+ }
 1265+ if ( $state === 'bi' ) {
12781266 $output .= '</b>';
 1267+ }
12791268 # There might be lonely ''''', so make sure we have a buffer
1280 - if ($state === 'both' && $buffer)
 1269+ if ( $state === 'both' && $buffer ) {
12811270 $output .= '<b><i>'.$buffer.'</i></b>';
 1271+ }
12821272 return $output;
12831273 }
12841274 }
@@ -1310,9 +1300,9 @@
13111301 # removeHTMLtags()) should not be included in
13121302 # URLs, per RFC 2396.
13131303 $m2 = array();
1314 - if (preg_match('/&(lt|gt);/', $url, $m2, PREG_OFFSET_CAPTURE)) {
1315 - $text = substr($url, $m2[0][1]) . ' ' . $text;
1316 - $url = substr($url, 0, $m2[0][1]);
 1304+ if ( preg_match( '/&(lt|gt);/', $url, $m2, PREG_OFFSET_CAPTURE ) ) {
 1305+ $text = substr( $url, $m2[0][1] ) . ' ' . $text;
 1306+ $url = substr( $url, 0, $m2[0][1] );
13171307 }
13181308
13191309 # If the link text is an image URL, replace it with an <img> tag
@@ -1325,12 +1315,12 @@
13261316 $dtrail = '';
13271317
13281318 # Set linktype for CSS - if URL==text, link is essentially free
1329 - $linktype = ($text === $url) ? 'free' : 'text';
 1319+ $linktype = ( $text === $url ) ? 'free' : 'text';
13301320
13311321 # No link text, e.g. [http://domain.tld/some.link]
13321322 if ( $text == '' ) {
13331323 # Autonumber if allowed. See bug #5918
1334 - if ( strpos( wfUrlProtocols(), substr($protocol, 0, strpos($protocol, ':')) ) !== false ) {
 1324+ if ( strpos( wfUrlProtocols(), substr( $protocol, 0, strpos( $protocol, ':' ) ) ) !== false ) {
13351325 $langObj = $this->getFunctionLang();
13361326 $text = '[' . $langObj->formatNum( ++$this->mAutonumber ) . ']';
13371327 $linktype = 'autonumber';
@@ -1345,7 +1335,7 @@
13461336 list( $dtrail, $trail ) = Linker::splitTrail( $trail );
13471337 }
13481338
1349 - $text = $wgContLang->markNoConversion($text);
 1339+ $text = $wgContLang->markNoConversion( $text );
13501340
13511341 $url = Sanitizer::cleanUrl( $url );
13521342
@@ -1381,7 +1371,7 @@
13821372 $attribs = array();
13831373 global $wgNoFollowLinks, $wgNoFollowNsExceptions;
13841374 $ns = $this->mTitle->getNamespace();
1385 - if( $wgNoFollowLinks && !in_array($ns, $wgNoFollowNsExceptions) ) {
 1375+ if ( $wgNoFollowLinks && !in_array( $ns, $wgNoFollowNsExceptions ) ) {
13861376 $attribs['rel'] = 'nofollow';
13871377
13881378 global $wgNoFollowDomainExceptions;
@@ -1389,8 +1379,7 @@
13901380 $bits = wfParseUrl( $url );
13911381 if ( is_array( $bits ) && isset( $bits['host'] ) ) {
13921382 foreach ( $wgNoFollowDomainExceptions as $domain ) {
1393 - if( substr( $bits['host'], -strlen( $domain ) )
1394 - == $domain ) {
 1383+ if ( substr( $bits['host'], -strlen( $domain ) ) == $domain ) {
13951384 unset( $attribs['rel'] );
13961385 break;
13971386 }
@@ -1447,19 +1436,19 @@
14481437 function maybeMakeExternalImage( $url ) {
14491438 $sk = $this->mOptions->getSkin();
14501439 $imagesfrom = $this->mOptions->getAllowExternalImagesFrom();
1451 - $imagesexception = !empty($imagesfrom);
 1440+ $imagesexception = !empty( $imagesfrom );
14521441 $text = false;
14531442 # $imagesfrom could be either a single string or an array of strings, parse out the latter
1454 - if( $imagesexception && is_array( $imagesfrom ) ) {
 1443+ if ( $imagesexception && is_array( $imagesfrom ) ) {
14551444 $imagematch = false;
1456 - foreach( $imagesfrom as $match ) {
1457 - if( strpos( $url, $match ) === 0 ) {
 1445+ foreach ( $imagesfrom as $match ) {
 1446+ if ( strpos( $url, $match ) === 0 ) {
14581447 $imagematch = true;
14591448 break;
14601449 }
14611450 }
1462 - } elseif( $imagesexception ) {
1463 - $imagematch = (strpos( $url, $imagesfrom ) === 0);
 1451+ } elseif ( $imagesexception ) {
 1452+ $imagematch = ( strpos( $url, $imagesfrom ) === 0 );
14641453 } else {
14651454 $imagematch = false;
14661455 }
@@ -1470,14 +1459,15 @@
14711460 $text = $sk->makeExternalImage( $url );
14721461 }
14731462 }
1474 - if( !$text && $this->mOptions->getEnableImageWhitelist()
 1463+ if ( !$text && $this->mOptions->getEnableImageWhitelist()
14751464 && preg_match( self::EXT_IMAGE_REGEX, $url ) ) {
14761465 $whitelist = explode( "\n", wfMsgForContent( 'external_image_whitelist' ) );
1477 - foreach( $whitelist as $entry ) {
 1466+ foreach ( $whitelist as $entry ) {
14781467 # Sanitize the regex fragment, make it case-insensitive, ignore blank entries/comments
1479 - if( strpos( $entry, '#' ) === 0 || $entry === '' )
 1468+ if ( strpos( $entry, '#' ) === 0 || $entry === '' ) {
14801469 continue;
1481 - if( preg_match( '/' . str_replace( '/', '\\/', $entry ) . '/i', $url ) ) {
 1470+ }
 1471+ if ( preg_match( '/' . str_replace( '/', '\\/', $entry ) . '/i', $url ) ) {
14821472 # Image matches a whitelist entry
14831473 $text = $sk->makeExternalImage( $url );
14841474 break;
@@ -1523,9 +1513,9 @@
15241514 $sk = $this->mOptions->getSkin();
15251515 $holders = new LinkHolderArray( $this );
15261516
1527 - #split the entire text string on occurences of [[
 1517+ # split the entire text string on occurences of [[
15281518 $a = StringUtils::explode( '[[', ' ' . $s );
1529 - #get the first element (all text up to first [[), and remove the space we added
 1519+ # get the first element (all text up to first [[), and remove the space we added
15301520 $s = $a->current();
15311521 $a->next();
15321522 $line = $a->current(); # Workaround for broken ArrayIterator::next() that returns "void"
@@ -1539,7 +1529,7 @@
15401530 $e2 = wfMsgForContent( 'linkprefix' );
15411531 }
15421532
1543 - if( is_null( $this->mTitle ) ) {
 1533+ if ( is_null( $this->mTitle ) ) {
15441534 wfProfileOut( __METHOD__.'-setup' );
15451535 wfProfileOut( __METHOD__ );
15461536 throw new MWException( __METHOD__.": \$this->mTitle is null\n" );
@@ -1557,10 +1547,10 @@
15581548 $prefix = '';
15591549 }
15601550
1561 - if($wgContLang->hasVariants()) {
1562 - $selflink = $wgContLang->convertLinkToAllVariants($this->mTitle->getPrefixedText());
 1551+ if ( $wgContLang->hasVariants() ) {
 1552+ $selflink = $wgContLang->convertLinkToAllVariants( $this->mTitle->getPrefixedText() );
15631553 } else {
1564 - $selflink = array($this->mTitle->getPrefixedText());
 1554+ $selflink = array( $this->mTitle->getPrefixedText() );
15651555 }
15661556 $useSubpages = $this->areSubpagesAllowed();
15671557 wfProfileOut( __METHOD__.'-setup' );
@@ -1584,7 +1574,7 @@
15851575 $prefix='';
15861576 }
15871577 # first link
1588 - if($first_prefix) {
 1578+ if ( $first_prefix ) {
15891579 $prefix = $first_prefix;
15901580 $first_prefix = false;
15911581 }
@@ -1600,29 +1590,29 @@
16011591 # [[Image:Foo.jpg|[http://example.com desc]]] <- having three ] in a row fucks up,
16021592 # the real problem is with the $e1 regex
16031593 # See bug 1300.
1604 - #
 1594+ #
16051595 # Still some problems for cases where the ] is meant to be outside punctuation,
16061596 # and no image is in sight. See bug 2095.
1607 - #
1608 - if( $text !== '' &&
 1597+ #
 1598+ if ( $text !== '' &&
16091599 substr( $m[3], 0, 1 ) === ']' &&
1610 - strpos($text, '[') !== false
 1600+ strpos( $text, '[' ) !== false
16111601 )
16121602 {
16131603 $text .= ']'; # so that replaceExternalLinks($text) works later
16141604 $m[3] = substr( $m[3], 1 );
16151605 }
16161606 # fix up urlencoded title texts
1617 - if( strpos( $m[1], '%' ) !== false ) {
 1607+ if ( strpos( $m[1], '%' ) !== false ) {
16181608 # Should anchors '#' also be rejected?
1619 - $m[1] = str_replace( array('<', '>'), array('&lt;', '&gt;'), urldecode($m[1]) );
 1609+ $m[1] = str_replace( array('<', '>'), array('&lt;', '&gt;'), urldecode( $m[1] ) );
16201610 }
16211611 $trail = $m[3];
1622 - } elseif( preg_match($e1_img, $line, $m) ) { # Invalid, but might be an image with a link in its caption
 1612+ } elseif ( preg_match( $e1_img, $line, $m ) ) { # Invalid, but might be an image with a link in its caption
16231613 $might_be_img = true;
16241614 $text = $m[2];
16251615 if ( strpos( $m[1], '%' ) !== false ) {
1626 - $m[1] = urldecode($m[1]);
 1616+ $m[1] = urldecode( $m[1] );
16271617 }
16281618 $trail = "";
16291619 } else { # Invalid form; output directly
@@ -1649,8 +1639,8 @@
16501640 $link = $m[1];
16511641 }
16521642
1653 - $noforce = (substr( $m[1], 0, 1 ) !== ':');
1654 - if (!$noforce) {
 1643+ $noforce = ( substr( $m[1], 0, 1 ) !== ':' );
 1644+ if ( !$noforce ) {
16551645 # Strip off leading ':'
16561646 $link = substr( $link, 1 );
16571647 }
@@ -1670,10 +1660,10 @@
16711661
16721662 if ( $might_be_img ) { # if this is actually an invalid link
16731663 wfProfileIn( __METHOD__."-might_be_img" );
1674 - if ( $ns == NS_FILE && $noforce ) { #but might be an image
 1664+ if ( $ns == NS_FILE && $noforce ) { # but might be an image
16751665 $found = false;
16761666 while ( true ) {
1677 - #look at the next 'line' to see if we can close it there
 1667+ # look at the next 'line' to see if we can close it there
16781668 $a->next();
16791669 $next_line = $a->current();
16801670 if ( $next_line === false || $next_line === null ) {
@@ -1687,24 +1677,24 @@
16881678 $trail = $m[2];
16891679 break;
16901680 } elseif ( count( $m ) == 2 ) {
1691 - #if there's exactly one ]] that's fine, we'll keep looking
 1681+ # if there's exactly one ]] that's fine, we'll keep looking
16921682 $text .= "[[{$m[0]}]]{$m[1]}";
16931683 } else {
1694 - #if $next_line is invalid too, we need look no further
 1684+ # if $next_line is invalid too, we need look no further
16951685 $text .= '[[' . $next_line;
16961686 break;
16971687 }
16981688 }
16991689 if ( !$found ) {
17001690 # we couldn't find the end of this imageLink, so output it raw
1701 - #but don't ignore what might be perfectly normal links in the text we've examined
 1691+ # but don't ignore what might be perfectly normal links in the text we've examined
17021692 $holders->merge( $this->replaceInternalLinks2( $text ) );
17031693 $s .= "{$prefix}[[$link|$text";
17041694 # note: no $trail, because without an end, there *is* no trail
17051695 wfProfileOut( __METHOD__."-might_be_img" );
17061696 continue;
17071697 }
1708 - } else { #it's not an image, so output it raw
 1698+ } else { # it's not an image, so output it raw
17091699 $s .= "{$prefix}[[$link|$text";
17101700 # note: no $trail, because without an end, there *is* no trail
17111701 wfProfileOut( __METHOD__."-might_be_img" );
@@ -1714,7 +1704,9 @@
17151705 }
17161706
17171707 $wasblank = ( $text == '' );
1718 - if ( $wasblank ) $text = $link;
 1708+ if ( $wasblank ) {
 1709+ $text = $link;
 1710+ }
17191711
17201712 # Link not escaped by : , create the various objects
17211713 if ( $noforce ) {
@@ -1723,8 +1715,8 @@
17241716 wfProfileIn( __METHOD__."-interwiki" );
17251717 if ( $iw && $this->mOptions->getInterwikiMagic() && $nottalk && $wgContLang->getLanguageName( $iw ) ) {
17261718 $this->mOutput->addLanguageLink( $nt->getFullText() );
1727 - $s = rtrim($s . $prefix);
1728 - $s .= trim($trail, "\n") == '' ? '': $prefix . $trail;
 1719+ $s = rtrim( $s . $prefix );
 1720+ $s .= trim( $trail, "\n" ) == '' ? '': $prefix . $trail;
17291721 wfProfileOut( __METHOD__."-interwiki" );
17301722 continue;
17311723 }
@@ -1743,7 +1735,7 @@
17441736 # recursively parse links inside the image caption
17451737 # actually, this will parse them in any other parameters, too,
17461738 # but it might be hard to fix that, and it doesn't matter ATM
1747 - $text = $this->replaceExternalLinks($text);
 1739+ $text = $this->replaceExternalLinks( $text );
17481740 $holders->merge( $this->replaceInternalLinks2( $text ) );
17491741 }
17501742 # cloak any absolute URLs inside the image markup, so replaceExternalLinks() won't touch them
@@ -1759,7 +1751,7 @@
17601752
17611753 if ( $ns == NS_CATEGORY ) {
17621754 wfProfileIn( __METHOD__."-category" );
1763 - $s = rtrim($s . "\n"); # bug 87
 1755+ $s = rtrim( $s . "\n" ); # bug 87
17641756
17651757 if ( $wasblank ) {
17661758 $sortkey = $this->getDefaultSort();
@@ -1775,7 +1767,7 @@
17761768 * Strip the whitespace Category links produce, see bug 87
17771769 * @todo We might want to use trim($tmp, "\n") here.
17781770 */
1779 - $s .= trim($prefix . $trail, "\n") == '' ? '': $prefix . $trail;
 1771+ $s .= trim( $prefix . $trail, "\n" ) == '' ? '': $prefix . $trail;
17801772
17811773 wfProfileOut( __METHOD__."-category" );
17821774 continue;
@@ -1783,8 +1775,8 @@
17841776 }
17851777
17861778 # Self-link checking
1787 - if( $nt->getFragment() === '' && $ns != NS_SPECIAL ) {
1788 - if( in_array( $nt->getPrefixedText(), $selflink, true ) ) {
 1779+ if ( $nt->getFragment() === '' && $ns != NS_SPECIAL ) {
 1780+ if ( in_array( $nt->getPrefixedText(), $selflink, true ) ) {
17891781 $s .= $prefix . $sk->makeSelfLinkObj( $nt, $text, '', $trail );
17901782 continue;
17911783 }
@@ -1792,7 +1784,7 @@
17931785
17941786 # NS_MEDIA is a pseudo-namespace for linking directly to a file
17951787 # FIXME: Should do batch file existence checks, see comment below
1796 - if( $ns == NS_MEDIA ) {
 1788+ if ( $ns == NS_MEDIA ) {
17971789 wfProfileIn( __METHOD__."-media" );
17981790 # Give extensions a chance to select the file revision for us
17991791 $skip = $time = false;
@@ -1812,10 +1804,10 @@
18131805 wfProfileIn( __METHOD__."-always_known" );
18141806 # Some titles, such as valid special pages or files in foreign repos, should
18151807 # be shown as bluelinks even though they're not included in the page table
1816 - #
 1808+ #
18171809 # FIXME: isAlwaysKnown() can be expensive for file links; we should really do
18181810 # batch file existence checks for NS_FILE and NS_MEDIA
1819 - if( $iw == '' && $nt->isAlwaysKnown() ) {
 1811+ if ( $iw == '' && $nt->isAlwaysKnown() ) {
18201812 $this->mOutput->addLink( $nt );
18211813 $s .= $this->makeKnownLinkHolder( $nt, $text, '', $trail, $prefix );
18221814 } else {
@@ -1893,7 +1885,7 @@
18941886 * @return string the full name of the link
18951887 * @private
18961888 */
1897 - function maybeDoSubpageLink($target, &$text) {
 1889+ function maybeDoSubpageLink( $target, &$text ) {
18981890 return Linker::normalizeSubpageLink( $this->mTitle, $target, $text );
18991891 }
19001892
@@ -1910,42 +1902,57 @@
19111903 $this->mLastSection = '';
19121904 return $result;
19131905 }
1914 - # getCommon() returns the length of the longest common substring
1915 - # of both arguments, starting at the beginning of both.
1916 - #
1917 - /* private */ function getCommon( $st1, $st2 ) {
 1906+ /**
 1907+ * getCommon() returns the length of the longest common substring
 1908+ * of both arguments, starting at the beginning of both.
 1909+ * @private
 1910+ */
 1911+ function getCommon( $st1, $st2 ) {
19181912 $fl = strlen( $st1 );
19191913 $shorter = strlen( $st2 );
1920 - if ( $fl < $shorter ) { $shorter = $fl; }
 1914+ if ( $fl < $shorter ) {
 1915+ $shorter = $fl;
 1916+ }
19211917
19221918 for ( $i = 0; $i < $shorter; ++$i ) {
1923 - if ( $st1{$i} != $st2{$i} ) { break; }
 1919+ if ( $st1{$i} != $st2{$i} ) {
 1920+ break;
 1921+ }
19241922 }
19251923 return $i;
19261924 }
1927 - # These next three functions open, continue, and close the list
1928 - # element appropriate to the prefix character passed into them.
1929 - #
1930 - /* private */ function openList( $char ) {
 1925+ /**
 1926+ * These next three functions open, continue, and close the list
 1927+ * element appropriate to the prefix character passed into them.
 1928+ * @private
 1929+ */
 1930+ function openList( $char ) {
19311931 $result = $this->closeParagraph();
19321932
1933 - if ( '*' === $char ) { $result .= '<ul><li>'; }
1934 - elseif ( '#' === $char ) { $result .= '<ol><li>'; }
1935 - elseif ( ':' === $char ) { $result .= '<dl><dd>'; }
1936 - elseif ( ';' === $char ) {
 1933+ if ( '*' === $char ) {
 1934+ $result .= '<ul><li>';
 1935+ } elseif ( '#' === $char ) {
 1936+ $result .= '<ol><li>';
 1937+ } elseif ( ':' === $char ) {
 1938+ $result .= '<dl><dd>';
 1939+ } elseif ( ';' === $char ) {
19371940 $result .= '<dl><dt>';
19381941 $this->mDTopen = true;
 1942+ } else {
 1943+ $result = '<!-- ERR 1 -->';
19391944 }
1940 - else { $result = '<!-- ERR 1 -->'; }
19411945
19421946 return $result;
19431947 }
19441948
19451949 /* private */ function nextItem( $char ) {
1946 - if ( '*' === $char || '#' === $char ) { return '</li><li>'; }
1947 - elseif ( ':' === $char || ';' === $char ) {
 1950+ if ( '*' === $char || '#' === $char ) {
 1951+ return '</li><li>';
 1952+ } elseif ( ':' === $char || ';' === $char ) {
19481953 $close = '</dd>';
1949 - if ( $this->mDTopen ) { $close = '</dt>'; }
 1954+ if ( $this->mDTopen ) {
 1955+ $close = '</dt>';
 1956+ }
19501957 if ( ';' === $char ) {
19511958 $this->mDTopen = true;
19521959 return $close . '<dt>';
@@ -1958,17 +1965,20 @@
19591966 }
19601967
19611968 /* private */ function closeList( $char ) {
1962 - if ( '*' === $char ) { $text = '</li></ul>'; }
1963 - elseif ( '#' === $char ) { $text = '</li></ol>'; }
1964 - elseif ( ':' === $char ) {
 1969+ if ( '*' === $char ) {
 1970+ $text = '</li></ul>';
 1971+ } elseif ( '#' === $char ) {
 1972+ $text = '</li></ol>';
 1973+ } elseif ( ':' === $char ) {
19651974 if ( $this->mDTopen ) {
19661975 $this->mDTopen = false;
19671976 $text = '</dt></dl>';
19681977 } else {
19691978 $text = '</dd></dl>';
19701979 }
 1980+ } else {
 1981+ return '<!-- ERR 3 -->';
19711982 }
1972 - else { return '<!-- ERR 3 -->'; }
19731983 return $text."\n";
19741984 }
19751985 /**#@-*/
@@ -1986,7 +1996,7 @@
19871997 # Parsing through the text line by line. The main thing
19881998 # happening here is handling of block-level elements p, pre,
19891999 # and making lists from lines starting with * # : etc.
1990 - #
 2000+ #
19912001 $textLines = StringUtils::explode( "\n", $text );
19922002
19932003 $lastPrefix = $output = '';
@@ -2007,8 +2017,8 @@
20082018 // : = dd
20092019
20102020 $lastPrefixLength = strlen( $lastPrefix );
2011 - $preCloseMatch = preg_match('/<\\/pre/i', $oLine );
2012 - $preOpenMatch = preg_match('/<pre/i', $oLine );
 2021+ $preCloseMatch = preg_match( '/<\\/pre/i', $oLine );
 2022+ $preOpenMatch = preg_match( '/<pre/i', $oLine );
20132023 // If not in a <pre> element, scan for and figure out what prefixes are there.
20142024 if ( !$this->mInPre ) {
20152025 # Multiple prefixes may abut each other for nested lists.
@@ -2030,7 +2040,7 @@
20312041 }
20322042
20332043 # List generation
2034 - if( $prefixLength && $lastPrefix === $prefix2 ) {
 2044+ if ( $prefixLength && $lastPrefix === $prefix2 ) {
20352045 # Same as the last item, so no need to deal with nesting or opening stuff
20362046 $output .= $this->nextItem( substr( $prefix, -1 ) );
20372047 $paragraphStack = false;
@@ -2041,12 +2051,12 @@
20422052 # So we check for : in the remainder text to split up the
20432053 # title and definition, without b0rking links.
20442054 $term = $t2 = '';
2045 - if ($this->findColonNoLinks($t, $term, $t2) !== false) {
 2055+ if ( $this->findColonNoLinks( $t, $term, $t2 ) !== false ) {
20462056 $t = $t2;
20472057 $output .= $term . $this->nextItem( ':' );
20482058 }
20492059 }
2050 - } elseif( $prefixLength || $lastPrefixLength ) {
 2060+ } elseif ( $prefixLength || $lastPrefixLength ) {
20512061 // We need to open or close prefixes, or both.
20522062
20532063 # Either open or close a level...
@@ -2054,7 +2064,7 @@
20552065 $paragraphStack = false;
20562066
20572067 // Close all the prefixes which aren't shared.
2058 - while( $commonPrefixLength < $lastPrefixLength ) {
 2068+ while ( $commonPrefixLength < $lastPrefixLength ) {
20592069 $output .= $this->closeList( $lastPrefix[$lastPrefixLength-1] );
20602070 --$lastPrefixLength;
20612071 }
@@ -2071,7 +2081,7 @@
20722082
20732083 if ( ';' === $char ) {
20742084 # FIXME: This is dupe of code above
2075 - if ($this->findColonNoLinks($t, $term, $t2) !== false) {
 2085+ if ( $this->findColonNoLinks( $t, $term, $t2 ) !== false ) {
20762086 $t = $t2;
20772087 $output .= $term . $this->nextItem( ':' );
20782088 }
@@ -2082,7 +2092,7 @@
20832093 }
20842094
20852095 // If we have no prefixes, go to paragraph mode.
2086 - if( 0 == $prefixLength ) {
 2096+ if ( 0 == $prefixLength ) {
20872097 wfProfileIn( __METHOD__."-paragraph" );
20882098 # No prefix (not in list)--go to paragraph mode
20892099 // XXX: use a stack for nestable elements like span, table and div
@@ -2102,10 +2112,10 @@
21032113 } else {
21042114 $inBlockElem = true;
21052115 }
2106 - } else if ( !$inBlockElem && !$this->mInPre ) {
2107 - if ( ' ' == substr( $t, 0, 1 ) and ( $this->mLastSection === 'pre' or trim($t) != '' ) ) {
 2116+ } elseif ( !$inBlockElem && !$this->mInPre ) {
 2117+ if ( ' ' == substr( $t, 0, 1 ) and ( $this->mLastSection === 'pre' || trim( $t ) != '' ) ) {
21082118 // pre
2109 - if ($this->mLastSection !== 'pre') {
 2119+ if ( $this->mLastSection !== 'pre' ) {
21102120 $paragraphStack = false;
21112121 $output .= $this->closeParagraph().'<pre>';
21122122 $this->mLastSection = 'pre';
@@ -2113,13 +2123,13 @@
21142124 $t = substr( $t, 1 );
21152125 } else {
21162126 // paragraph
2117 - if ( trim($t) == '' ) {
 2127+ if ( trim( $t ) == '' ) {
21182128 if ( $paragraphStack ) {
21192129 $output .= $paragraphStack.'<br />';
21202130 $paragraphStack = false;
21212131 $this->mLastSection = 'p';
21222132 } else {
2123 - if ($this->mLastSection !== 'p' ) {
 2133+ if ( $this->mLastSection !== 'p' ) {
21242134 $output .= $this->closeParagraph();
21252135 $this->mLastSection = '';
21262136 $paragraphStack = '<p>';
@@ -2132,7 +2142,7 @@
21332143 $output .= $paragraphStack;
21342144 $paragraphStack = false;
21352145 $this->mLastSection = 'p';
2136 - } else if ($this->mLastSection !== 'p') {
 2146+ } elseif ( $this->mLastSection !== 'p' ) {
21372147 $output .= $this->closeParagraph().'<p>';
21382148 $this->mLastSection = 'p';
21392149 }
@@ -2142,10 +2152,10 @@
21432153 wfProfileOut( __METHOD__."-paragraph" );
21442154 }
21452155 // somewhere above we forget to get out of pre block (bug 785)
2146 - if($preCloseMatch && $this->mInPre) {
 2156+ if ( $preCloseMatch && $this->mInPre ) {
21472157 $this->mInPre = false;
21482158 }
2149 - if ($paragraphStack === false) {
 2159+ if ( $paragraphStack === false ) {
21502160 $output .= $t."\n";
21512161 }
21522162 }
@@ -2170,18 +2180,18 @@
21712181 * @param string &$after set to everything after the ':'
21722182 * return string the position of the ':', or false if none found
21732183 */
2174 - function findColonNoLinks($str, &$before, &$after) {
 2184+ function findColonNoLinks( $str, &$before, &$after ) {
21752185 wfProfileIn( __METHOD__ );
21762186
21772187 $pos = strpos( $str, ':' );
2178 - if( $pos === false ) {
 2188+ if ( $pos === false ) {
21792189 // Nothing to find!
21802190 wfProfileOut( __METHOD__ );
21812191 return false;
21822192 }
21832193
21842194 $lt = strpos( $str, '<' );
2185 - if( $lt === false || $lt > $pos ) {
 2195+ if ( $lt === false || $lt > $pos ) {
21862196 // Easy; no tag nesting to worry about
21872197 $before = substr( $str, 0, $pos );
21882198 $after = substr( $str, $pos+1 );
@@ -2205,7 +2215,7 @@
22062216 $state = self::COLON_STATE_TAGSTART;
22072217 break;
22082218 case ":":
2209 - if( $stack == 0 ) {
 2219+ if ( $stack == 0 ) {
22102220 // We found it!
22112221 $before = substr( $str, 0, $i );
22122222 $after = substr( $str, $i + 1 );
@@ -2217,14 +2227,14 @@
22182228 default:
22192229 // Skip ahead looking for something interesting
22202230 $colon = strpos( $str, ':', $i );
2221 - if( $colon === false ) {
 2231+ if ( $colon === false ) {
22222232 // Nothing else interesting
22232233 wfProfileOut( __METHOD__ );
22242234 return false;
22252235 }
22262236 $lt = strpos( $str, '<', $i );
2227 - if( $stack === 0 ) {
2228 - if( $lt === false || $colon < $lt ) {
 2237+ if ( $stack === 0 ) {
 2238+ if ( $lt === false || $colon < $lt ) {
22292239 // We found it!
22302240 $before = substr( $str, 0, $colon );
22312241 $after = substr( $str, $colon + 1 );
@@ -2232,7 +2242,7 @@
22332243 return $i;
22342244 }
22352245 }
2236 - if( $lt === false ) {
 2246+ if ( $lt === false ) {
22372247 // Nothing else interesting to find; abort!
22382248 // We're nested, but there's no close tags left. Abort!
22392249 break 2;
@@ -2275,9 +2285,9 @@
22762286 break;
22772287 case 3: // self::COLON_STATE_CLOSETAG:
22782288 // In a </tag>
2279 - if( $c === ">" ) {
 2289+ if ( $c === ">" ) {
22802290 $stack--;
2281 - if( $stack < 0 ) {
 2291+ if ( $stack < 0 ) {
22822292 wfDebug( __METHOD__.": Invalid input; too many close tags\n" );
22832293 wfProfileOut( __METHOD__ );
22842294 return false;
@@ -2286,7 +2296,7 @@
22872297 }
22882298 break;
22892299 case self::COLON_STATE_TAGSLASH:
2290 - if( $c === ">" ) {
 2300+ if ( $c === ">" ) {
22912301 // Yes, a self-closed tag <blah/>
22922302 $state = self::COLON_STATE_TEXT;
22932303 } else {
@@ -2295,19 +2305,19 @@
22962306 }
22972307 break;
22982308 case 5: // self::COLON_STATE_COMMENT:
2299 - if( $c === "-" ) {
 2309+ if ( $c === "-" ) {
23002310 $state = self::COLON_STATE_COMMENTDASH;
23012311 }
23022312 break;
23032313 case self::COLON_STATE_COMMENTDASH:
2304 - if( $c === "-" ) {
 2314+ if ( $c === "-" ) {
23052315 $state = self::COLON_STATE_COMMENTDASHDASH;
23062316 } else {
23072317 $state = self::COLON_STATE_COMMENT;
23082318 }
23092319 break;
23102320 case self::COLON_STATE_COMMENTDASHDASH:
2311 - if( $c === ">" ) {
 2321+ if ( $c === ">" ) {
23122322 $state = self::COLON_STATE_TEXT;
23132323 } else {
23142324 $state = self::COLON_STATE_COMMENT;
@@ -2317,7 +2327,7 @@
23182328 throw new MWException( "State machine error in " . __METHOD__ );
23192329 }
23202330 }
2321 - if( $stack > 0 ) {
 2331+ if ( $stack > 0 ) {
23222332 wfDebug( __METHOD__.": Invalid input; not enough close tags (stack $stack, state $state)\n" );
23232333 return false;
23242334 }
@@ -2436,7 +2446,7 @@
24372447 $value = wfUrlEncode( str_replace( ' ', '_', $this->mTitle->getBaseText() ) );
24382448 break;
24392449 case 'talkpagename':
2440 - if( $this->mTitle->canTalk() ) {
 2450+ if ( $this->mTitle->canTalk() ) {
24412451 $talkPage = $this->mTitle->getTalkPage();
24422452 $value = wfEscapeWikiText( $talkPage->getPrefixedText() );
24432453 } else {
@@ -2444,7 +2454,7 @@
24452455 }
24462456 break;
24472457 case 'talkpagenamee':
2448 - if( $this->mTitle->canTalk() ) {
 2458+ if ( $this->mTitle->canTalk() ) {
24492459 $talkPage = $this->mTitle->getTalkPage();
24502460 $value = $talkPage->getPrefixedUrl();
24512461 } else {
@@ -2509,13 +2519,13 @@
25102520 $value = $this->getRevisionUser();
25112521 break;
25122522 case 'namespace':
2513 - $value = str_replace('_',' ',$wgContLang->getNsText( $this->mTitle->getNamespace() ) );
 2523+ $value = str_replace( '_',' ',$wgContLang->getNsText( $this->mTitle->getNamespace() ) );
25142524 break;
25152525 case 'namespacee':
25162526 $value = wfUrlencode( $wgContLang->getNsText( $this->mTitle->getNamespace() ) );
25172527 break;
25182528 case 'talkspace':
2519 - $value = $this->mTitle->canTalk() ? str_replace('_',' ',$this->mTitle->getTalkNsText()) : '';
 2529+ $value = $this->mTitle->canTalk() ? str_replace( '_',' ',$this->mTitle->getTalkNsText() ) : '';
25202530 break;
25212531 case 'talkspacee':
25222532 $value = $this->mTitle->canTalk() ? wfUrlencode( $this->mTitle->getTalkNsText() ) : '';
@@ -2582,7 +2592,7 @@
25832593 $value = $wgContLang->formatNum( SiteStats::pages() );
25842594 break;
25852595 case 'numberofadmins':
2586 - $value = $wgContLang->formatNum( SiteStats::numberingroup('sysop') );
 2596+ $value = $wgContLang->formatNum( SiteStats::numberingroup( 'sysop' ) );
25872597 break;
25882598 case 'numberofedits':
25892599 $value = $wgContLang->formatNum( SiteStats::edits() );
@@ -2616,10 +2626,11 @@
26172627 return $wgContLanguageCode;
26182628 default:
26192629 $ret = null;
2620 - if ( wfRunHooks( 'ParserGetVariableValueSwitch', array( &$this, &$this->mVarCache, &$index, &$ret, &$frame ) ) )
 2630+ if ( wfRunHooks( 'ParserGetVariableValueSwitch', array( &$this, &$this->mVarCache, &$index, &$ret, &$frame ) ) ) {
26212631 return $ret;
2622 - else
 2632+ } else {
26232633 return null;
 2634+ }
26242635 }
26252636
26262637 if ( $index )
@@ -2665,7 +2676,7 @@
26662677 *
26672678 * @private
26682679 */
2669 - function preprocessToDom ( $text, $flags = 0 ) {
 2680+ function preprocessToDom( $text, $flags = 0 ) {
26702681 $dom = $this->getPreprocessor()->preprocessToObj( $text, $flags );
26712682 return $dom;
26722683 }
@@ -2714,7 +2725,7 @@
27152726 $frame = $this->getPreprocessor()->newFrame();
27162727 } elseif ( !( $frame instanceof PPFrame ) ) {
27172728 wfDebug( __METHOD__." called using plain parameters instead of a PPFrame instance. Creating custom frame.\n" );
2718 - $frame = $this->getPreprocessor()->newCustomFrame($frame);
 2729+ $frame = $this->getPreprocessor()->newCustomFrame( $frame );
27192730 }
27202731
27212732 $dom = $this->preprocessToDom( $text );
@@ -2725,11 +2736,11 @@
27262737 return $text;
27272738 }
27282739
2729 - /// Clean up argument array - refactored in 1.9 so parserfunctions can use it, too.
 2740+ // Clean up argument array - refactored in 1.9 so parserfunctions can use it, too.
27302741 static function createAssocArgs( $args ) {
27312742 $assocArgs = array();
27322743 $index = 1;
2733 - foreach( $args as $arg ) {
 2744+ foreach ( $args as $arg ) {
27342745 $eqpos = strpos( $arg, '=' );
27352746 if ( $eqpos === false ) {
27362747 $assocArgs[$index++] = $arg;
@@ -2753,14 +2764,20 @@
27542765 * Will warn at most once the user per limitation type
27552766 *
27562767 * @param string $limitationType, should be one of:
2757 - * 'expensive-parserfunction' (corresponding messages: 'expensive-parserfunction-warning', 'expensive-parserfunction-category')
2758 - * 'post-expand-template-argument' (corresponding messages: 'post-expand-template-argument-warning', 'post-expand-template-argument-category')
2759 - * 'post-expand-template-inclusion' (corresponding messages: 'post-expand-template-inclusion-warning', 'post-expand-template-inclusion-category')
 2768+ * 'expensive-parserfunction' (corresponding messages:
 2769+ * 'expensive-parserfunction-warning',
 2770+ * 'expensive-parserfunction-category')
 2771+ * 'post-expand-template-argument' (corresponding messages:
 2772+ * 'post-expand-template-argument-warning',
 2773+ * 'post-expand-template-argument-category')
 2774+ * 'post-expand-template-inclusion' (corresponding messages:
 2775+ * 'post-expand-template-inclusion-warning',
 2776+ * 'post-expand-template-inclusion-category')
27602777 * @params int $current, $max When an explicit limit has been
27612778 * exceeded, provide the values (optional)
27622779 */
27632780 function limitationWarn( $limitationType, $current=null, $max=null) {
2764 - //does no harm if $current and $max are present but are unnecessary for the message
 2781+ // does no harm if $current and $max are present but are unnecessary for the message
27652782 $warning = wfMsgExt( "$limitationType-warning", array( 'parsemag', 'escape' ), $current, $max );
27662783 $this->mOutput->addWarning( $warning );
27672784 $this->addTrackingCategory( "$limitationType-category" );
@@ -2804,7 +2821,7 @@
28052822 $originalTitle = $part1;
28062823
28072824 # $args is a list of argument nodes, starting from index 0, not including $part1
2808 - $args = (null == $piece['parts']) ? array() : $piece['parts'];
 2825+ $args = ( null == $piece['parts'] ) ? array() : $piece['parts'];
28092826 wfProfileOut( __METHOD__.'-setup' );
28102827
28112828 # SUBST
@@ -2840,8 +2857,9 @@
28412858 $id = $this->mVariables->matchStartToEnd( $part1 );
28422859 if ( $id !== false ) {
28432860 $text = $this->getVariableValue( $id, $frame );
2844 - if (MagicWord::getCacheTTL($id)>-1)
 2861+ if ( MagicWord::getCacheTTL( $id ) > -1 ) {
28452862 $this->mOutput->mContainsOldMagic = true;
 2863+ }
28462864 $found = true;
28472865 }
28482866 }
@@ -2944,21 +2962,23 @@
29452963 # Split the title into page and subpage
29462964 $subpage = '';
29472965 $part1 = $this->maybeDoSubpageLink( $part1, $subpage );
2948 - if ($subpage !== '') {
 2966+ if ( $subpage !== '' ) {
29492967 $ns = $this->mTitle->getNamespace();
29502968 }
29512969 $title = Title::newFromText( $part1, $ns );
29522970 if ( $title ) {
29532971 $titleText = $title->getPrefixedText();
29542972 # Check for language variants if the template is not found
2955 - if($wgContLang->hasVariants() && $title->getArticleID() == 0){
 2973+ if ( $wgContLang->hasVariants() && $title->getArticleID() == 0 ) {
29562974 $wgContLang->findVariantLink( $part1, $title, true );
29572975 }
29582976 # Do recursion depth check
29592977 $limit = $this->mOptions->getMaxTemplateDepth();
29602978 if ( $frame->depth >= $limit ) {
29612979 $found = true;
2962 - $text = '<span class="error">' . wfMsgForContent( 'parser-template-recursion-depth-warning', $limit ) . '</span>';
 2980+ $text = '<span class="error">'
 2981+ . wfMsgForContent( 'parser-template-recursion-depth-warning', $limit )
 2982+ . '</span>';
29632983 }
29642984 }
29652985 }
@@ -2967,15 +2987,18 @@
29682988 if ( !$found && $title ) {
29692989 wfProfileIn( __METHOD__ . '-loadtpl' );
29702990 if ( !$title->isExternal() ) {
2971 - if ( $title->getNamespace() == NS_SPECIAL && $this->mOptions->getAllowSpecialInclusion() && $this->ot['html'] ) {
 2991+ if ( $title->getNamespace() == NS_SPECIAL
 2992+ && $this->mOptions->getAllowSpecialInclusion()
 2993+ && $this->ot['html'] )
 2994+ {
29722995 $text = SpecialPage::capturePath( $title );
29732996 if ( is_string( $text ) ) {
29742997 $found = true;
29752998 $isHTML = true;
29762999 $this->disableCache();
29773000 }
2978 - } else if ( $wgNonincludableNamespaces && in_array( $title->getNamespace(), $wgNonincludableNamespaces ) ) {
2979 - $found = false; //access denied
 3001+ } elseif ( $wgNonincludableNamespaces && in_array( $title->getNamespace(), $wgNonincludableNamespaces ) ) {
 3002+ $found = false; // access denied
29803003 wfDebug( __METHOD__.": template inclusion denied for " . $title->getPrefixedDBkey() );
29813004 } else {
29823005 list( $text, $title ) = $this->getTemplateDom( $title );
@@ -3052,15 +3075,16 @@
30533076 # immediately preceding headings
30543077 if ( $isHTML ) {
30553078 $text = "\n\n" . $this->insertStripItem( $text );
3056 - }
3057 - # Escape nowiki-style return values
3058 - elseif ( $nowiki && ( $this->ot['html'] || $this->ot['pre'] ) ) {
 3079+ } elseif ( $nowiki && ( $this->ot['html'] || $this->ot['pre'] ) ) {
 3080+ # Escape nowiki-style return values
30593081 $text = wfEscapeWikiText( $text );
3060 - }
3061 - # Bug 529: if the template begins with a table or block-level
3062 - # element, it should be treated as beginning a new line.
3063 - # This behaviour is somewhat controversial.
3064 - elseif ( is_string( $text ) && !$piece['lineStart'] && preg_match('/^(?:{\\||:|;|#|\*)/', $text)) /*}*/{
 3082+ } elseif ( is_string( $text )
 3083+ && !$piece['lineStart']
 3084+ && preg_match( '/^(?:{\\||:|;|#|\*)/', $text ) )
 3085+ {
 3086+ # Bug 529: if the template begins with a table or block-level
 3087+ # element, it should be treated as beginning a new line.
 3088+ # This behaviour is somewhat controversial.
30653089 $text = "\n" . $text;
30663090 }
30673091
@@ -3109,7 +3133,7 @@
31103134 $dom = $this->preprocessToDom( $text, self::PTD_FOR_INCLUSION );
31113135 $this->mTplDomCache[ $titleText ] = $dom;
31123136
3113 - if (! $title->equals($cacheTitle)) {
 3137+ if ( !$title->equals( $cacheTitle ) ) {
31143138 $this->mTplRedirCache[$cacheTitle->getPrefixedDBkey()] =
31153139 array( $title->getNamespace(),$cdb = $title->getDBkey() );
31163140 }
@@ -3130,11 +3154,11 @@
31313155 $this->mOutput->addTemplate( $dep['title'], $dep['page_id'], $dep['rev_id'] );
31323156 }
31333157 }
3134 - return array($text,$finalTitle);
 3158+ return array( $text, $finalTitle );
31353159 }
31363160
31373161 function fetchTemplate( $title ) {
3138 - $rv = $this->fetchTemplateAndTitle($title);
 3162+ $rv = $this->fetchTemplateAndTitle( $title );
31393163 return $rv[0];
31403164 }
31413165
@@ -3153,7 +3177,7 @@
31543178 $id = false; // Assume current
31553179 wfRunHooks( 'BeforeParserFetchTemplateAndtitle', array( $parser, &$title, &$skip, &$id ) );
31563180
3157 - if( $skip ) {
 3181+ if ( $skip ) {
31583182 $text = false;
31593183 $deps[] = array(
31603184 'title' => $title,
@@ -3164,7 +3188,7 @@
31653189 $rev = $id ? Revision::newFromId( $id ) : Revision::newFromTitle( $title );
31663190 $rev_id = $rev ? $rev->getId() : 0;
31673191 // If there is no current revision, there is no page
3168 - if( $id === false && !$rev ) {
 3192+ if ( $id === false && !$rev ) {
31693193 $linkCache = LinkCache::singleton();
31703194 $linkCache->addBadLinkObj( $title );
31713195 }
@@ -3174,13 +3198,13 @@
31753199 'page_id' => $title->getArticleID(),
31763200 'rev_id' => $rev_id );
31773201
3178 - if( $rev ) {
 3202+ if ( $rev ) {
31793203 $text = $rev->getText();
3180 - } elseif( $title->getNamespace() == NS_MEDIAWIKI ) {
 3204+ } elseif ( $title->getNamespace() == NS_MEDIAWIKI ) {
31813205 global $wgContLang;
31823206 $message = $wgContLang->lcfirst( $title->getText() );
31833207 $text = wfMsgForContentNoTrans( $message );
3184 - if( wfEmptyMsg( $message, $text ) ) {
 3208+ if ( wfEmptyMsg( $message, $text ) ) {
31853209 $text = false;
31863210 break;
31873211 }
@@ -3206,35 +3230,39 @@
32073231 function interwikiTransclude( $title, $action ) {
32083232 global $wgEnableScaryTranscluding;
32093233
3210 - if (!$wgEnableScaryTranscluding)
 3234+ if ( !$wgEnableScaryTranscluding ) {
32113235 return wfMsg('scarytranscludedisabled');
 3236+ }
32123237
32133238 $url = $title->getFullUrl( "action=$action" );
32143239
3215 - if (strlen($url) > 255)
3216 - return wfMsg('scarytranscludetoolong');
3217 - return $this->fetchScaryTemplateMaybeFromCache($url);
 3240+ if ( strlen( $url ) > 255 ) {
 3241+ return wfMsg( 'scarytranscludetoolong' );
 3242+ }
 3243+ return $this->fetchScaryTemplateMaybeFromCache( $url );
32183244 }
32193245
3220 - function fetchScaryTemplateMaybeFromCache($url) {
 3246+ function fetchScaryTemplateMaybeFromCache( $url ) {
32213247 global $wgTranscludeCacheExpiry;
3222 - $dbr = wfGetDB(DB_SLAVE);
 3248+ $dbr = wfGetDB( DB_SLAVE );
32233249 $tsCond = $dbr->timestamp( time() - $wgTranscludeCacheExpiry );
3224 - $obj = $dbr->selectRow('transcache', array('tc_time', 'tc_contents'),
3225 - array('tc_url' => $url, "tc_time >= " . $dbr->addQuotes( $tsCond ) ) );
3226 - if ($obj) {
 3250+ $obj = $dbr->selectRow( 'transcache', array('tc_time', 'tc_contents' ),
 3251+ array( 'tc_url' => $url, "tc_time >= " . $dbr->addQuotes( $tsCond ) ) );
 3252+ if ( $obj ) {
32273253 return $obj->tc_contents;
32283254 }
32293255
3230 - $text = Http::get($url);
3231 - if (!$text)
3232 - return wfMsg('scarytranscludefailed', $url);
 3256+ $text = Http::get( $url );
 3257+ if ( !$text ) {
 3258+ return wfMsg( 'scarytranscludefailed', $url );
 3259+ }
32333260
3234 - $dbw = wfGetDB(DB_MASTER);
3235 - $dbw->replace('transcache', array('tc_url'), array(
 3261+ $dbw = wfGetDB( DB_MASTER );
 3262+ $dbw->replace( 'transcache', array('tc_url'), array(
32363263 'tc_url' => $url,
32373264 'tc_time' => $dbw->timestamp( time() ),
3238 - 'tc_contents' => $text));
 3265+ 'tc_contents' => $text)
 3266+ );
32393267 return $text;
32403268 }
32413269
@@ -3302,7 +3330,7 @@
33033331 $name = $frame->expand( $params['name'] );
33043332 $attrText = !isset( $params['attr'] ) ? null : $frame->expand( $params['attr'] );
33053333 $content = !isset( $params['inner'] ) ? null : $frame->expand( $params['inner'] );
3306 - $marker = "{$this->mUniqPrefix}-$name-" . sprintf('%08X', $this->mMarkerIndex++) . self::MARKER_SUFFIX;
 3334+ $marker = "{$this->mUniqPrefix}-$name-" . sprintf( '%08X', $this->mMarkerIndex++ ) . self::MARKER_SUFFIX;
33073335
33083336 $isFunctionTag = isset( $this->mFunctionTagHooks[strtolower($name)] ) &&
33093337 ( $this->ot['html'] || $this->ot['pre'] );
@@ -3318,20 +3346,20 @@
33193347 $attributes = $attributes + $params['attributes'];
33203348 }
33213349
3322 - if( isset( $this->mTagHooks[$name] ) ) {
 3350+ if ( isset( $this->mTagHooks[$name] ) ) {
33233351 # Workaround for PHP bug 35229 and similar
33243352 if ( !is_callable( $this->mTagHooks[$name] ) ) {
33253353 throw new MWException( "Tag hook for $name is not callable\n" );
33263354 }
33273355 $output = call_user_func_array( $this->mTagHooks[$name],
33283356 array( $content, $attributes, $this, $frame ) );
3329 - } elseif( isset( $this->mFunctionTagHooks[$name] ) ) {
 3357+ } elseif ( isset( $this->mFunctionTagHooks[$name] ) ) {
33303358 list( $callback, $flags ) = $this->mFunctionTagHooks[$name];
3331 - if( !is_callable( $callback ) )
 3359+ if ( !is_callable( $callback ) ) {
33323360 throw new MWException( "Tag hook for $name is not callable\n" );
 3361+ }
33333362
3334 - $output = call_user_func_array( $callback,
3335 - array( &$this, $frame, $content, $attributes ) );
 3363+ $output = call_user_func_array( $callback, array( &$this, $frame, $content, $attributes ) );
33363364 } else {
33373365 $output = '<span class="error">Invalid tag extension name: ' .
33383366 htmlspecialchars( $name ) . '</span>';
@@ -3362,7 +3390,7 @@
33633391 }
33643392 }
33653393
3366 - if( $markerType === 'none' ) {
 3394+ if ( $markerType === 'none' ) {
33673395 return $output;
33683396 } elseif ( $markerType === 'nowiki' ) {
33693397 $this->mStripState->nowiki->setPair( $marker, $output );
@@ -3398,7 +3426,7 @@
33993427 function incrementExpensiveFunctionCount() {
34003428 global $wgExpensiveParserFunctionLimit;
34013429 $this->mExpensiveFunctionCount++;
3402 - if($this->mExpensiveFunctionCount <= $wgExpensiveParserFunctionLimit) {
 3430+ if ( $this->mExpensiveFunctionCount <= $wgExpensiveParserFunctionLimit ) {
34033431 return true;
34043432 }
34053433 return false;
@@ -3413,7 +3441,7 @@
34143442
34153443 // The position of __TOC__ needs to be recorded
34163444 $mw = MagicWord::get( 'toc' );
3417 - if( $mw->match( $text ) ) {
 3445+ if ( $mw->match( $text ) ) {
34183446 $this->mShowToc = true;
34193447 $this->mForceTocPosition = true;
34203448
@@ -3439,14 +3467,14 @@
34403468 $this->addTrackingCategory( 'hidden-category-category' );
34413469 }
34423470 # (bug 8068) Allow control over whether robots index a page.
3443 - #
 3471+ #
34443472 # FIXME (bug 14899): __INDEX__ always overrides __NOINDEX__ here! This
34453473 # is not desirable, the last one on the page should win.
3446 - if( isset( $this->mDoubleUnderscores['noindex'] ) && $this->mTitle->canUseNoindex() ) {
 3474+ if ( isset( $this->mDoubleUnderscores['noindex'] ) && $this->mTitle->canUseNoindex() ) {
34473475 $this->mOutput->setIndexPolicy( 'noindex' );
34483476 $this->addTrackingCategory( 'noindex-category' );
34493477 }
3450 - if( isset( $this->mDoubleUnderscores['index'] ) && $this->mTitle->canUseNoindex() ){
 3478+ if ( isset( $this->mDoubleUnderscores['index'] ) && $this->mTitle->canUseNoindex() ) {
34513479 $this->mOutput->setIndexPolicy( 'index' );
34523480 $this->addTrackingCategory( 'index-category' );
34533481 }
@@ -3461,11 +3489,13 @@
34623490 * @param $msg String message key
34633491 * @return Bool whether the addition was successful
34643492 */
3465 - protected function addTrackingCategory( $msg ){
 3493+ protected function addTrackingCategory( $msg ) {
34663494 $cat = wfMsgForContent( $msg );
34673495
34683496 # Allow tracking categories to be disabled by setting them to "-"
3469 - if( $cat === '-' ) return false;
 3497+ if ( $cat === '-' ) {
 3498+ return false;
 3499+ }
34703500
34713501 $containerCategory = Title::makeTitleSafe( NS_CATEGORY, $cat );
34723502 if ( $containerCategory ) {
@@ -3499,7 +3529,7 @@
35003530 $showEditLink = $this->mOptions->getEditSection();
35013531
35023532 // Do not call quickUserCan unless necessary
3503 - if( $showEditLink && !$this->mTitle->quickUserCan( 'edit' ) ) {
 3533+ if ( $showEditLink && !$this->mTitle->quickUserCan( 'edit' ) ) {
35043534 $showEditLink = 0;
35053535 }
35063536
@@ -3516,7 +3546,7 @@
35173547 # if there are fewer than 4 headlines in the article, do not show TOC
35183548 # unless it's been explicitly enabled.
35193549 $enoughToc = $this->mShowToc &&
3520 - (($numMatches >= 4) || $this->mForceTocPosition);
 3550+ ( ( $numMatches >= 4 ) || $this->mForceTocPosition );
35213551
35223552 # Allow user to stipulate that a page should have a "new section"
35233553 # link added via __NEWSECTIONLINK__
@@ -3566,20 +3596,20 @@
35673597 $byteOffset = 0;
35683598 $tocraw = array();
35693599
3570 - foreach( $matches[3] as $headline ) {
 3600+ foreach ( $matches[3] as $headline ) {
35713601 $isTemplate = false;
35723602 $titleText = false;
35733603 $sectionIndex = false;
35743604 $numbering = '';
35753605 $markerMatches = array();
3576 - if (preg_match("/^$markerRegex/", $headline, $markerMatches)) {
 3606+ if ( preg_match("/^$markerRegex/", $headline, $markerMatches ) ) {
35773607 $serial = $markerMatches[1];
35783608 list( $titleText, $sectionIndex ) = $this->mHeadings[$serial];
3579 - $isTemplate = ($titleText != $baseTitleText);
3580 - $headline = preg_replace("/^$markerRegex/", "", $headline);
 3609+ $isTemplate = ( $titleText != $baseTitleText );
 3610+ $headline = preg_replace( "/^$markerRegex/", "", $headline );
35813611 }
35823612
3583 - if( $toclevel ) {
 3613+ if ( $toclevel ) {
35843614 $prevlevel = $level;
35853615 $prevtoclevel = $toclevel;
35863616 }
@@ -3589,30 +3619,30 @@
35903620 # Increase TOC level
35913621 $toclevel++;
35923622 $sublevelCount[$toclevel] = 0;
3593 - if( $toclevel<$wgMaxTocLevel ) {
 3623+ if ( $toclevel<$wgMaxTocLevel ) {
35943624 $prevtoclevel = $toclevel;
35953625 $toc .= $sk->tocIndent();
35963626 $numVisible++;
35973627 }
3598 - }
3599 - elseif ( $level < $prevlevel && $toclevel > 1 ) {
 3628+ } elseif ( $level < $prevlevel && $toclevel > 1 ) {
36003629 # Decrease TOC level, find level to jump to
36013630
3602 - for ($i = $toclevel; $i > 0; $i--) {
 3631+ for ( $i = $toclevel; $i > 0; $i-- ) {
36033632 if ( $levelCount[$i] == $level ) {
36043633 # Found last matching level
36053634 $toclevel = $i;
36063635 break;
3607 - }
3608 - elseif ( $levelCount[$i] < $level ) {
 3636+ } elseif ( $levelCount[$i] < $level ) {
36093637 # Found first matching level below current level
36103638 $toclevel = $i + 1;
36113639 break;
36123640 }
36133641 }
3614 - if( $i == 0 ) $toclevel = 1;
3615 - if( $toclevel<$wgMaxTocLevel ) {
3616 - if($prevtoclevel < $wgMaxTocLevel) {
 3642+ if ( $i == 0 ) {
 3643+ $toclevel = 1;
 3644+ }
 3645+ if ( $toclevel<$wgMaxTocLevel ) {
 3646+ if ( $prevtoclevel < $wgMaxTocLevel ) {
36173647 # Unindent only if the previous toc level was shown :p
36183648 $toc .= $sk->tocUnindent( $prevtoclevel - $toclevel );
36193649 $prevtoclevel = $toclevel;
@@ -3620,10 +3650,9 @@
36213651 $toc .= $sk->tocLineEnd();
36223652 }
36233653 }
3624 - }
3625 - else {
 3654+ } else {
36263655 # No change in level, end TOC line
3627 - if( $toclevel<$wgMaxTocLevel ) {
 3656+ if ( $toclevel<$wgMaxTocLevel ) {
36283657 $toc .= $sk->tocLineEnd();
36293658 }
36303659 }
@@ -3634,8 +3663,8 @@
36353664 @$sublevelCount[$toclevel]++;
36363665 $dot = 0;
36373666 for( $i = 1; $i <= $toclevel; $i++ ) {
3638 - if( !empty( $sublevelCount[$i] ) ) {
3639 - if( $dot ) {
 3667+ if ( !empty( $sublevelCount[$i] ) ) {
 3668+ if ( $dot ) {
36403669 $numbering .= '.';
36413670 }
36423671 $numbering .= $wgContLang->formatNum( $sublevelCount[$i] );
@@ -3656,7 +3685,7 @@
36573686 # Strip out HTML (other than plain <sup> and <sub>: bug 8393)
36583687 $tocline = preg_replace(
36593688 array( '#<(?!/?(sup|sub)).*?'.'>#', '#<(/?(sup|sub)).*?'.'>#' ),
3660 - array( '', '<$1>'),
 3689+ array( '', '<$1>' ),
36613690 $safeHeadline
36623691 );
36633692 $tocline = trim( $tocline );
@@ -3672,7 +3701,7 @@
36733702 if ( $wgHtml5 && $wgExperimentalHtmlIds ) {
36743703 # For reverse compatibility, provide an id that's
36753704 # HTML4-compatible, like we used to.
3676 - #
 3705+ #
36773706 # It may be worth noting, academically, that it's possible for
36783707 # the legacy anchor to conflict with a non-legacy headline
36793708 # anchor on the page. In this case likely the "correct" thing
@@ -3717,7 +3746,7 @@
37183747 }
37193748
37203749 # Don't number the heading if it is the only one (looks silly)
3721 - if( $doNumberHeadings && count( $matches[3] ) > 1) {
 3750+ if ( $doNumberHeadings && count( $matches[3] ) > 1) {
37223751 # the two are different if the line contains a link
37233752 $headline = $numbering . ' ' . $headline;
37243753 }
@@ -3731,9 +3760,9 @@
37323761 if ( $legacyHeadline !== false && $refers[$legacyArrayKey] > 1 ) {
37333762 $legacyAnchor .= '_' . $refers[$legacyArrayKey];
37343763 }
3735 - if( $enoughToc && ( !isset($wgMaxTocLevel) || $toclevel<$wgMaxTocLevel ) ) {
3736 - $toc .= $sk->tocLine($anchor, $tocline,
3737 - $numbering, $toclevel, ($isTemplate ? false : $sectionIndex));
 3764+ if ( $enoughToc && ( !isset( $wgMaxTocLevel ) || $toclevel < $wgMaxTocLevel ) ) {
 3765+ $toc .= $sk->tocLine( $anchor, $tocline,
 3766+ $numbering, $toclevel, ( $isTemplate ? false : $sectionIndex ) );
37383767 }
37393768
37403769 # Add the section to the section tree
@@ -3753,20 +3782,20 @@
37543783 'level' => $level,
37553784 'line' => $tocline,
37563785 'number' => $numbering,
3757 - 'index' => ($isTemplate ? 'T-' : '' ) . $sectionIndex,
 3786+ 'index' => ( $isTemplate ? 'T-' : '' ) . $sectionIndex,
37583787 'fromtitle' => $titleText,
37593788 'byteoffset' => ( $isTemplate ? null : $byteOffset ),
37603789 'anchor' => $anchor,
37613790 );
37623791
37633792 # give headline the correct <h#> tag
3764 - if( $showEditLink && $sectionIndex !== false ) {
3765 - if( $isTemplate ) {
 3793+ if ( $showEditLink && $sectionIndex !== false ) {
 3794+ if ( $isTemplate ) {
37663795 # Put a T flag in the section identifier, to indicate to extractSections()
37673796 # that sections inside <includeonly> should be counted.
3768 - $editlink = $sk->doEditSectionLink(Title::newFromText( $titleText ), "T-$sectionIndex");
 3797+ $editlink = $sk->doEditSectionLink( Title::newFromText( $titleText ), "T-$sectionIndex" );
37693798 } else {
3770 - $editlink = $sk->doEditSectionLink($this->mTitle, $sectionIndex, $headlineHint);
 3799+ $editlink = $sk->doEditSectionLink( $this->mTitle, $sectionIndex, $headlineHint );
37713800 }
37723801 } else {
37733802 $editlink = '';
@@ -3781,12 +3810,12 @@
37823811 $this->setOutputType( $oldType );
37833812
37843813 # Never ever show TOC if no headers
3785 - if( $numVisible < 1 ) {
 3814+ if ( $numVisible < 1 ) {
37863815 $enoughToc = false;
37873816 }
37883817
3789 - if( $enoughToc ) {
3790 - if( $prevtoclevel > 0 && $prevtoclevel < $wgMaxTocLevel ) {
 3818+ if ( $enoughToc ) {
 3819+ if ( $prevtoclevel > 0 && $prevtoclevel < $wgMaxTocLevel ) {
37913820 $toc .= $sk->tocUnindent( $prevtoclevel - 1 );
37923821 }
37933822 $toc = $sk->tocList( $toc );
@@ -3802,8 +3831,8 @@
38033832 $blocks = preg_split( '/<H[1-6].*?' . '>.*?<\/H[1-6]>/i', $text );
38043833 $i = 0;
38053834
3806 - foreach( $blocks as $block ) {
3807 - if( $showEditLink && $headlineCount > 0 && $i == 0 && $block !== "\n" ) {
 3835+ foreach ( $blocks as $block ) {
 3836+ if ( $showEditLink && $headlineCount > 0 && $i == 0 && $block !== "\n" ) {
38083837 # This is the [edit] link that appears for the top block of text when
38093838 # section editing is enabled
38103839
@@ -3812,17 +3841,17 @@
38133842 # $full .= $sk->editSectionLink(0);
38143843 }
38153844 $full .= $block;
3816 - if( $enoughToc && !$i && $isMain && !$this->mForceTocPosition ) {
 3845+ if ( $enoughToc && !$i && $isMain && !$this->mForceTocPosition ) {
38173846 # Top anchor now in skin
38183847 $full = $full.$toc;
38193848 }
38203849
3821 - if( !empty( $head[$i] ) ) {
 3850+ if ( !empty( $head[$i] ) ) {
38223851 $full .= $head[$i];
38233852 }
38243853 $i++;
38253854 }
3826 - if( $this->mForceTocPosition ) {
 3855+ if ( $this->mForceTocPosition ) {
38273856 return str_replace( '<!--MWTOC-->', $toc, $full );
38283857 } else {
38293858 return $full;
@@ -3852,11 +3881,12 @@
38533882 $titletext = $title->getPrefixedDBkey();
38543883 foreach ( $tree1 as $s ) {
38553884 if ( $targetLevel !== false ) {
3856 - if ( $s['level'] <= $targetLevel )
 3885+ if ( $s['level'] <= $targetLevel ) {
38573886 // We've skipped enough
38583887 $targetLevel = false;
3859 - else
 3888+ } else {
38603889 continue;
 3890+ }
38613891 }
38623892 if ( $s['index'] != $section ||
38633893 $s['fromtitle'] != $titletext ) {
@@ -3866,8 +3896,9 @@
38673897 // Rewrite index, byteoffset and number
38683898 if ( $s['fromtitle'] == $titletext ) {
38693899 $s['index'] = $nextIndex++;
3870 - if ( $merged )
 3900+ if ( $merged ) {
38713901 $s['byteoffset'] += $len2;
 3902+ }
38723903 }
38733904 $s['number'] = implode( '.', array_map(
38743905 array( $wgContLang, 'formatnum' ),
@@ -3908,15 +3939,17 @@
39093940 * @param $lastLevel int Level of previous TOC entry
39103941 */
39113942 private static function incrementNumbering( &$number, $level, $lastLevel ) {
3912 - if ( $level > $lastLevel )
 3943+ if ( $level > $lastLevel ) {
39133944 $number[$level - 1] = 1;
3914 - else if ( $level < $lastLevel ) {
 3945+ } elseif ( $level < $lastLevel ) {
39153946 foreach ( $number as $key => $unused )
3916 - if ( $key >= $level )
 3947+ if ( $key >= $level ) {
39173948 unset( $number[$key] );
 3949+ }
39183950 $number[$level - 1]++;
3919 - } else
 3951+ } else {
39203952 $number[$level - 1]++;
 3953+ }
39213954 }
39223955
39233956 /**
@@ -3956,13 +3989,11 @@
39573990 function pstPass2( $text, $user ) {
39583991 global $wgContLang, $wgLocaltimezone;
39593992
3960 - /* Note: This is the timestamp saved as hardcoded wikitext to
3961 - * the database, we use $wgContLang here in order to give
3962 - * everyone the same signature and use the default one rather
3963 - * than the one selected in each user's preferences.
3964 - *
3965 - * (see also bug 12815)
3966 - */
 3993+ # Note: This is the timestamp saved as hardcoded wikitext to
 3994+ # the database, we use $wgContLang here in order to give
 3995+ # everyone the same signature and use the default one rather
 3996+ # than the one selected in each user's preferences.
 3997+ # (see also bug 12815)
39673998 $ts = $this->mOptions->getTimestamp();
39683999 if ( isset( $wgLocaltimezone ) ) {
39694000 $tz = $wgLocaltimezone;
@@ -3976,13 +4007,14 @@
39774008 $ts = date( 'YmdHis', $unixts );
39784009 $tzMsg = date( 'T', $unixts ); # might vary on DST changeover!
39794010
3980 - /* Allow translation of timezones trough wiki. date() can return
3981 - * whatever crap the system uses, localised or not, so we cannot
3982 - * ship premade translations.
3983 - */
 4011+ # Allow translation of timezones trough wiki. date() can return
 4012+ # whatever crap the system uses, localised or not, so we cannot
 4013+ # ship premade translations.
39844014 $key = 'timezone-' . strtolower( trim( $tzMsg ) );
39854015 $value = wfMsgForContent( $key );
3986 - if ( !wfEmptyMsg( $key, $value ) ) $tzMsg = $value;
 4016+ if ( !wfEmptyMsg( $key, $value ) ) {
 4017+ $tzMsg = $value;
 4018+ }
39874019
39884020 date_default_timezone_set( $oldtz );
39894021
@@ -4001,7 +4033,6 @@
40024034 ) );
40034035
40044036 # Context links: [[|name]] and [[name (context)|]]
4005 - #
40064037 global $wgLegalTitleChars;
40074038 $tc = "[$wgLegalTitleChars]";
40084039 $nc = '[ _0-9A-Za-z\x80-\xff-]'; # Namespaces can use non-ascii!
@@ -4051,17 +4082,18 @@
40524083 if ( $nickname === false )
40534084 $nickname = $user->getOption( 'nickname' );
40544085
4055 - if ( is_null( $fancySig ) )
 4086+ if ( is_null( $fancySig ) ) {
40564087 $fancySig = $user->getBoolOption( 'fancysig' );
 4088+ }
40574089
40584090 $nickname = $nickname == null ? $username : $nickname;
40594091
4060 - if( mb_strlen( $nickname ) > $wgMaxSigChars ) {
 4092+ if ( mb_strlen( $nickname ) > $wgMaxSigChars ) {
40614093 $nickname = $username;
40624094 wfDebug( __METHOD__ . ": $username has overlong signature.\n" );
4063 - } elseif( $fancySig !== false ) {
 4095+ } elseif ( $fancySig !== false ) {
40644096 # Sig. might contain markup; validate this
4065 - if( $this->validateSig( $nickname ) !== false ) {
 4097+ if ( $this->validateSig( $nickname ) !== false ) {
40664098 # Validated; clean up (if needed) and return it
40674099 return $this->cleanSig( $nickname, true );
40684100 } else {
@@ -4179,11 +4211,11 @@
41804212 }
41814213 $executing = true;
41824214
4183 - wfProfileIn(__METHOD__);
 4215+ wfProfileIn( __METHOD__ );
41844216 $text = $this->preprocess( $text, $wgTitle, $options );
41854217
41864218 $executing = false;
4187 - wfProfileOut(__METHOD__);
 4219+ wfProfileOut( __METHOD__ );
41884220 return $text;
41894221 }
41904222
@@ -4206,7 +4238,7 @@
42074239 $tag = strtolower( $tag );
42084240 $oldVal = isset( $this->mTagHooks[$tag] ) ? $this->mTagHooks[$tag] : null;
42094241 $this->mTagHooks[$tag] = $callback;
4210 - if( !in_array( $tag, $this->mStripList ) ) {
 4242+ if ( !in_array( $tag, $this->mStripList ) ) {
42114243 $this->mStripList[] = $tag;
42124244 }
42134245
@@ -4281,7 +4313,7 @@
42824314
42834315 # Add to function cache
42844316 $mw = MagicWord::get( $id );
4285 - if( !$mw )
 4317+ if ( !$mw )
42864318 throw new MWException( __METHOD__.'() expecting a magic word identifier.' );
42874319
42884320 $synonyms = $mw->getSynonyms();
@@ -4325,7 +4357,7 @@
43264358 $this->mFunctionTagHooks[$tag] : null;
43274359 $this->mFunctionTagHooks[$tag] = array( $callback, $flags );
43284360
4329 - if( !in_array( $tag, $this->mStripList ) ) {
 4361+ if ( !in_array( $tag, $this->mStripList ) ) {
43304362 $this->mStripList[] = $tag;
43314363 }
43324364
@@ -4372,24 +4404,24 @@
43734405 $ig->useSkin( $this->mOptions->getSkin() );
43744406 $ig->mRevisionId = $this->mRevisionId;
43754407
4376 - if( isset( $params['showfilename'] ) ) {
 4408+ if ( isset( $params['showfilename'] ) ) {
43774409 $ig->setShowFilename( true );
43784410 } else {
43794411 $ig->setShowFilename( false );
43804412 }
4381 - if( isset( $params['caption'] ) ) {
 4413+ if ( isset( $params['caption'] ) ) {
43824414 $caption = $params['caption'];
43834415 $caption = htmlspecialchars( $caption );
43844416 $caption = $this->replaceInternalLinks( $caption );
43854417 $ig->setCaptionHtml( $caption );
43864418 }
4387 - if( isset( $params['perrow'] ) ) {
 4419+ if ( isset( $params['perrow'] ) ) {
43884420 $ig->setPerRow( $params['perrow'] );
43894421 }
4390 - if( isset( $params['widths'] ) ) {
 4422+ if ( isset( $params['widths'] ) ) {
43914423 $ig->setWidths( $params['widths'] );
43924424 }
4393 - if( isset( $params['heights'] ) ) {
 4425+ if ( isset( $params['heights'] ) ) {
43944426 $ig->setHeights( $params['heights'] );
43954427 }
43964428
@@ -4406,11 +4438,12 @@
44074439 continue;
44084440 }
44094441
4410 - if ( strpos( $matches[0], '%' ) !== false )
 4442+ if ( strpos( $matches[0], '%' ) !== false ) {
44114443 $matches[1] = urldecode( $matches[1] );
 4444+ }
44124445 $tp = Title::newFromText( $matches[1]/*, NS_FILE*/ );
44134446 $nt =& $tp;
4414 - if( is_null( $nt ) ) {
 4447+ if ( is_null( $nt ) ) {
44154448 # Bogus title. Ignore these so we don't bomb out later.
44164449 continue;
44174450 }
@@ -4527,15 +4560,15 @@
45284561 $caption = '';
45294562 $params = array( 'frame' => array(), 'handler' => array(),
45304563 'horizAlign' => array(), 'vertAlign' => array() );
4531 - foreach( $parts as $part ) {
 4564+ foreach ( $parts as $part ) {
45324565 $part = trim( $part );
45334566 list( $magicName, $value ) = $mwArray->matchVariableStartToEnd( $part );
45344567 $validated = false;
4535 - if( isset( $paramMap[$magicName] ) ) {
 4568+ if ( isset( $paramMap[$magicName] ) ) {
45364569 list( $type, $paramName ) = $paramMap[$magicName];
45374570
45384571 // Special case; width and height come in one variable together
4539 - if( $type === 'handler' && $paramName === 'width' ) {
 4572+ if ( $type === 'handler' && $paramName === 'width' ) {
45404573 $m = array();
45414574 # (bug 13500) In both cases (width/height and width only),
45424575 # permit trailing "px" for backward compatibility.
@@ -4631,13 +4664,13 @@
46324665 # came to also set the caption, ordinary text after the image -- which
46334666 # makes no sense, because that just repeats the text multiple times in
46344667 # screen readers. It *also* came to set the title attribute.
4635 - #
 4668+ #
46364669 # Now that we have an alt attribute, we should not set the alt text to
46374670 # equal the caption: that's worse than useless, it just repeats the
46384671 # text. This is the framed/thumbnail case. If there's no caption, we
46394672 # use the unnamed parameter for alt text as well, just for the time be-
46404673 # ing, if the unnamed param is set and the alt param is not.
4641 - #
 4674+ #
46424675 # For the future, we need to figure out if we want to tweak this more,
46434676 # e.g., introducing a title= parameter for the title; ignoring the un-
46444677 # named parameter entirely for images without a caption; adding an ex-
@@ -4734,7 +4767,9 @@
47354768 /**#@+
47364769 * Accessor
47374770 */
4738 - function getTags() { return array_merge( array_keys($this->mTransparentTagHooks), array_keys( $this->mTagHooks ) ); }
 4771+ function getTags() {
 4772+ return array_merge( array_keys( $this->mTransparentTagHooks ), array_keys( $this->mTagHooks ) );
 4773+ }
47394774 /**#@-*/
47404775
47414776
@@ -4838,7 +4873,7 @@
48394874 // Add two newlines on -- trailing whitespace in $newText is conventionally
48404875 // stripped by the editor, so we need both newlines to restore the paragraph gap
48414876 // Only add trailing whitespace if there is newText
4842 - if($newText != "") {
 4877+ if ( $newText != "" ) {
48434878 $outText .= $newText . "\n\n";
48444879 }
48454880
@@ -4896,7 +4931,7 @@
48974932
48984933 // The cryptic '' timezone parameter tells to use the site-default
48994934 // timezone offset instead of the user settings.
4900 - //
 4935+ //
49014936 // Since this value will be saved into the parser cache, served
49024937 // to other users, and potentially even used inside links and such,
49034938 // it needs to be consistent for all visitors.
@@ -4913,7 +4948,7 @@
49144949 function getRevisionUser() {
49154950 // if this template is subst: the revision id will be blank,
49164951 // so just use the current user's name
4917 - if( $this->mRevisionId ) {
 4952+ if ( $this->mRevisionId ) {
49184953 $revision = Revision::newFromId( $this->mRevisionId );
49194954 $revuser = $revision->getUserText();
49204955 } else {
@@ -4940,10 +4975,11 @@
49414976 */
49424977 public function getDefaultSort() {
49434978 global $wgCategoryPrefixedDefaultSortkey;
4944 - if( $this->mDefaultSort !== false ) {
 4979+ if ( $this->mDefaultSort !== false ) {
49454980 return $this->mDefaultSort;
4946 - } elseif ($this->mTitle->getNamespace() == NS_CATEGORY ||
4947 - !$wgCategoryPrefixedDefaultSortkey) {
 4981+ } elseif ( $this->mTitle->getNamespace() == NS_CATEGORY ||
 4982+ !$wgCategoryPrefixedDefaultSortkey )
 4983+ {
49484984 return $this->mTitle->getText();
49494985 } else {
49504986 return $this->mTitle->getPrefixedText();
@@ -4999,16 +5035,16 @@
50005036 */
50015037 public function stripSectionName( $text ) {
50025038 # Strip internal link markup
5003 - $text = preg_replace('/\[\[:?([^[|]+)\|([^[]+)\]\]/','$2',$text);
5004 - $text = preg_replace('/\[\[:?([^[]+)\|?\]\]/','$1',$text);
 5039+ $text = preg_replace( '/\[\[:?([^[|]+)\|([^[]+)\]\]/', '$2', $text );
 5040+ $text = preg_replace( '/\[\[:?([^[]+)\|?\]\]/', '$1', $text );
50055041
50065042 # Strip external link markup (FIXME: Not Tolerant to blank link text
50075043 # I.E. [http://www.mediawiki.org] will render as [1] or something depending
50085044 # on how many empty links there are on the page - need to figure that out.
5009 - $text = preg_replace('/\[(?:' . wfUrlProtocols() . ')([^ ]+?) ([^[]+)\]/','$2',$text);
 5045+ $text = preg_replace( '/\[(?:' . wfUrlProtocols() . ')([^ ]+?) ([^[]+)\]/', '$2', $text );
50105046
50115047 # Parse wikitext quotes (italics & bold)
5012 - $text = $this->doQuotes($text);
 5048+ $text = $this->doQuotes( $text );
50135049
50145050 # Strip HTML tags
50155051 $text = StringUtils::delimiterReplace( '<', '>', '', $text );
@@ -5024,7 +5060,7 @@
50255061 */
50265062 function testSrvus( $text, $title, $options, $outputType = self::OT_HTML ) {
50275063 $this->clearState();
5028 - if ( ! ( $title instanceof Title ) ) {
 5064+ if ( !$title instanceof Title ) {
50295065 $title = Title::newFromText( $title );
50305066 }
50315067 $this->mTitle = $title;
@@ -5038,14 +5074,14 @@
50395075
50405076 function testPst( $text, $title, $options ) {
50415077 global $wgUser;
5042 - if ( ! ( $title instanceof Title ) ) {
 5078+ if ( !$title instanceof Title ) {
50435079 $title = Title::newFromText( $title );
50445080 }
50455081 return $this->preSaveTransform( $text, $title, $wgUser, $options );
50465082 }
50475083
50485084 function testPreprocess( $text, $title, $options ) {
5049 - if ( ! ( $title instanceof Title ) ) {
 5085+ if ( !$title instanceof Title ) {
50505086 $title = Title::newFromText( $title );
50515087 }
50525088 return $this->testSrvus( $text, $title, $options, self::OT_PREPROCESS );
@@ -5083,7 +5119,9 @@
50845120 // data in an array.
50855121 $stripState = new StripState;
50865122 $pos = 0;
5087 - while( ( $start_pos = strpos( $text, $this->mUniqPrefix, $pos ) ) && ( $end_pos = strpos( $text, self::MARKER_SUFFIX, $pos ) ) ) {
 5123+ while ( ( $start_pos = strpos( $text, $this->mUniqPrefix, $pos ) )
 5124+ && ( $end_pos = strpos( $text, self::MARKER_SUFFIX, $pos ) ) )
 5125+ {
50885126 $end_pos += strlen( self::MARKER_SUFFIX );
50895127 $marker = substr( $text, $start_pos, $end_pos-$start_pos );
50905128
@@ -5108,11 +5146,11 @@
51095147 $pos = 0;
51105148
51115149 // Internal links
5112 - while( ( $start_pos = strpos( $text, '<!--LINK ', $pos ) ) ) {
 5150+ while ( ( $start_pos = strpos( $text, '<!--LINK ', $pos ) ) ) {
51135151 list( $ns, $trail ) = explode( ':', substr( $text, $start_pos + strlen( '<!--LINK ' ) ), 2 );
51145152
5115 - $ns = trim($ns);
5116 - if (empty( $links['internal'][$ns] )) {
 5153+ $ns = trim( $ns );
 5154+ if ( empty( $links['internal'][$ns] ) ) {
51175155 $links['internal'][$ns] = array();
51185156 }
51195157
@@ -5124,7 +5162,7 @@
51255163 $pos = 0;
51265164
51275165 // Interwiki links
5128 - while( ( $start_pos = strpos( $text, '<!--IWLINK ', $pos ) ) ) {
 5166+ while ( ( $start_pos = strpos( $text, '<!--IWLINK ', $pos ) ) ) {
51295167 $data = substr( $text, $start_pos );
51305168 $key = trim( substr( $data, 0, strpos( $data, '-->' ) ) );
51315169 $links['interwiki'][] = $this->mLinkHolders->interwiki[$key];
@@ -5137,8 +5175,9 @@
51385176 }
51395177
51405178 function unserialiseHalfParsedText( $data, $intPrefix = null /* Unique identifying prefix */ ) {
5141 - if (!$intPrefix)
 5179+ if ( !$intPrefix ) {
51425180 $intPrefix = $this->getRandomString();
 5181+ }
51435182
51445183 // First, extract the strip state.
51455184 $stripState = $data['stripstate'];
@@ -5150,8 +5189,8 @@
51515190 $links = $data['linkholder'];
51525191
51535192 // Internal...
5154 - foreach( $links['internal'] as $ns => $nsLinks ) {
5155 - foreach( $nsLinks as $key => $entry ) {
 5193+ foreach ( $links['internal'] as $ns => $nsLinks ) {
 5194+ foreach ( $nsLinks as $key => $entry ) {
51565195 $newKey = $intPrefix . '-' . $key;
51575196 $this->mLinkHolders->internals[$ns][$newKey] = $entry;
51585197
@@ -5160,7 +5199,7 @@
51615200 }
51625201
51635202 // Interwiki...
5164 - foreach( $links['interwiki'] as $key => $entry ) {
 5203+ foreach ( $links['interwiki'] as $key => $entry ) {
51655204 $newKey = "$intPrefix-$key";
51665205 $this->mLinkHolders->interwikis[$newKey] = $entry;
51675206

Follow-up revisions

RevisionCommit summaryAuthorDate
r64886Follow-up to r64407 - a perfect example of why we encourage using braces for ...happy-melon16:44, 10 April 2010

Comments

#Comment by Platonides (talk | contribs)   14:13, 10 April 2010

This breaks poem, interpreting wiki text which is into <poem> tags. See its parser tests.

#Comment by Happy-melon (talk | contribs)   15:45, 21 June 2010

This was fixed in r64886.

Status & tagging log