r61515 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61514‎ | r61515 | r61516 >
Date:11:57, 26 January 2010
Author:platonides
Status:reverted
Tags:
Comment:
Cosmetic changes from r61052 comments:
else if -> elseif
Space after #
Prefer !== to !=
Modified paths:
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/parser/Parser.php
@@ -213,7 +213,7 @@
214214 * Must not consist of all title characters, or else it will change
215215 * the behaviour of <nowiki> in a link.
216216 */
217 - #$this->mUniqPrefix = "\x07UNIQ" . Parser::getRandomString();
 217+ # $this->mUniqPrefix = "\x07UNIQ" . Parser::getRandomString();
218218 # Changed to \x7f to allow XML double-parsing -- TS
219219 $this->mUniqPrefix = "\x7fUNIQ" . self::getRandomString();
220220
@@ -338,7 +338,7 @@
339339 '/(.) (?=\\?|:|;|!|%|\\302\\273)/' => '\\1&nbsp;\\2',
340340 # french spaces, Guillemet-right
341341 '/(\\302\\253) /' => '\\1&nbsp;',
342 - '/&nbsp;(!\s*important)/' => ' \\1', #Beware of CSS magic word !important, bug #11874.
 342+ '/&nbsp;(!\s*important)/' => ' \\1', # Beware of CSS magic word !important, bug #11874.
343343 );
344344 $text = preg_replace( array_keys($fixtags), array_values($fixtags), $text );
345345
@@ -556,7 +556,7 @@
557557 $taglist = implode( '|', $elements );
558558 $start = "/<($taglist)(\\s+[^>]*?|\\s*?)(\/?" . ">)|<(!--)/i";
559559
560 - while ( $text != '' ) {
 560+ while ( $text !== '' ) {
561561 $p = preg_split( $start, $text, 2, PREG_SPLIT_DELIM_CAPTURE );
562562 $stripped .= $p[0];
563563 if( count( $p ) < 5 ) {
@@ -723,11 +723,11 @@
724724 array_push( $tr_history , false );
725725 array_push( $tr_attributes , '' );
726726 array_push( $has_opened_tr , false );
727 - } else if ( count ( $td_history ) == 0 ) {
 727+ } elseif ( count ( $td_history ) == 0 ) {
728728 // Don't do any of the following
729729 $out .= $outLine."\n";
730730 continue;
731 - } else if ( substr ( $line , 0 , 2 ) === '|}' ) {
 731+ } elseif ( substr ( $line , 0 , 2 ) === '|}' ) {
732732 // We are ending a table
733733 $line = '</table>' . substr ( $line , 2 );
734734 $last_tag = array_pop ( $last_tag_history );
@@ -745,7 +745,7 @@
746746 }
747747 array_pop ( $tr_attributes );
748748 $outLine = $line . str_repeat( '</dd></dl>' , $indent_level );
749 - } else if ( substr ( $line , 0 , 2 ) === '|-' ) {
 749+ } elseif ( substr ( $line , 0 , 2 ) === '|-' ) {
750750 // Now we have a table row
751751 $line = preg_replace( '#^\|-+#', '', $line );
752752
@@ -773,7 +773,7 @@
774774 array_push ( $td_history , false );
775775 array_push ( $last_tag_history , '' );
776776 }
777 - else if ( $first_character === '|' || $first_character === '!' || substr ( $line , 0 , 2 ) === '|+' ) {
 777+ elseif ( $first_character === '|' || $first_character === '!' || substr ( $line , 0 , 2 ) === '|+' ) {
778778 // This might be cell elements, td, th or captions
779779 if ( substr ( $line , 0 , 2 ) === '|+' ) {
780780 $first_character = '+';
@@ -818,9 +818,9 @@
819819
820820 if ( $first_character === '|' ) {
821821 $last_tag = 'td';
822 - } else if ( $first_character === '!' ) {
 822+ } elseif ( $first_character === '!' ) {
823823 $last_tag = 'th';
824 - } else if ( $first_character === '+' ) {
 824+ } elseif ( $first_character === '+' ) {
825825 $last_tag = 'caption';
826826 } else {
827827 $last_tag = '';
@@ -835,7 +835,7 @@
836836 // be mistaken as delimiting cell parameters
837837 if ( strpos( $cell_data[0], '[[' ) !== false ) {
838838 $cell = "{$previous}<{$last_tag}>{$cell}";
839 - } else if ( count ( $cell_data ) == 1 )
 839+ } elseif ( count ( $cell_data ) == 1 )
840840 $cell = "{$previous}<{$last_tag}>{$cell_data[0]}";
841841 else {
842842 $attributes = $this->mStripState->unstripBoth( $cell_data[0] );
@@ -1136,7 +1136,7 @@
11371137 }
11381138 # If there are more than 6 apostrophes in a row, assume they're all
11391139 # text except for the last 6.
1140 - else if ( strlen( $arr[$i] ) > 6 )
 1140+ elseif ( strlen( $arr[$i] ) > 6 )
11411141 {
11421142 $arr[$i-1] .= str_repeat( "'", strlen( $arr[$i] ) - 6 );
11431143 $arr[$i] = "''''''";
@@ -1144,9 +1144,9 @@
11451145 # Count the number of occurrences of bold and italics mark-ups.
11461146 # We are not counting sequences of five apostrophes.
11471147 if ( strlen( $arr[$i] ) == 2 ) { $numitalics++; }
1148 - else if ( strlen( $arr[$i] ) == 3 ) { $numbold++; }
1149 - else if ( strlen( $arr[$i] ) == 5 ) { $numitalics++; $numbold++; }
1150 - else if ( strlen( $arr[$i] ) == 6 ) { $numbold+=2; }
 1148+ elseif ( strlen( $arr[$i] ) == 3 ) { $numbold++; }
 1149+ elseif ( strlen( $arr[$i] ) == 5 ) { $numitalics++; $numbold++; }
 1150+ elseif ( strlen( $arr[$i] ) == 6 ) { $numbold+=2; }
11511151 }
11521152 $i++;
11531153 }
@@ -1159,25 +1159,25 @@
11601160 {
11611161 $i = 0;
11621162
1163 - #These are indexes to the /next/ array entry than the
1164 - #one holding the text matching the condition.
 1163+ # These are indexes to the /next/ array entry than the
 1164+ # one holding the text matching the condition.
11651165 $firstsingleletterword = -1;
11661166 $firstmultiletterword = -1;
11671167 $firstspace = -1;
11681168
11691169 foreach ( $arr as $r )
11701170 {
1171 - #Filter the "'''". Separators are on odd positions.
1172 - #$arr[0] will be an empty string if needed.
 1171+ # Filter the "'''". Separators are on odd positions.
 1172+ # $arr[0] will be an empty string if needed.
11731173 if ( ( $i % 2 == 1 ) and ( strlen( $r ) == 3 ) )
11741174 {
11751175 $x1 = substr ($arr[$i-1], -1);
11761176 $x2 = substr ($arr[$i-1], -2, 1);
11771177 if ($x1 === ' ') {
11781178 if ($firstspace == -1) $firstspace = $i;
1179 - } else if ($x2 === ' ') {
 1179+ } elseif ($x2 === ' ') {
11801180 if ($firstsingleletterword == -1) $firstsingleletterword = $i;
1181 - } else if ($arr[$i-1] != "") {
 1181+ } elseif ($arr[$i-1] !== "") {
11821182 if ($firstmultiletterword == -1) $firstmultiletterword = $i;
11831183 }
11841184 }
@@ -1191,7 +1191,7 @@
11921192 $arr [ $firstsingleletterword-1 ] .= "'";
11931193 }
11941194 # If not, but there's a multi-letter word, use that one.
1195 - else if ($firstmultiletterword > -1)
 1195+ elseif ($firstmultiletterword > -1)
11961196 {
11971197 $arr [ $firstmultiletterword ] = "''";
11981198 $arr [ $firstmultiletterword-1 ] .= "'";
@@ -1199,7 +1199,7 @@
12001200 # ... otherwise use the first one that has neither.
12011201 # (notice that it is possible for all three to be -1 if, for example,
12021202 # there is only one pentuple-apostrophe in the line)
1203 - else if ($firstspace > -1)
 1203+ elseif ($firstspace > -1)
12041204 {
12051205 $arr [ $firstspace ] = "''";
12061206 $arr [ $firstspace-1 ] .= "'";
@@ -1207,9 +1207,9 @@
12081208 }
12091209
12101210 # Now let's actually convert our apostrophic mush to HTML!
1211 - $output = ''; #Processed text
1212 - $buffer = ''; #Content if $state is 'both'
1213 - $state = ''; #Flags with the order of open tags: '|b|i|bi|ib|both'
 1211+ $output = ''; # Processed text
 1212+ $buffer = ''; # Content if $state is 'both'
 1213+ $state = ''; # Flags with the order of open tags: '|b|i|bi|ib|both'
12141214 $i = 0;
12151215 foreach ($arr as $r)
12161216 {
@@ -1226,54 +1226,54 @@
12271227 {
12281228 if ($state === 'i')
12291229 { $output .= '</i>'; $state = ''; }
1230 - else if ($state === 'bi')
 1230+ elseif ($state === 'bi')
12311231 { $output .= '</i>'; $state = 'b'; }
1232 - else if ($state === 'ib')
 1232+ elseif ($state === 'ib')
12331233 { $output .= '</b></i><b>'; $state = 'b'; }
1234 - else if ($state === 'both')
 1234+ elseif ($state === 'both')
12351235 { $output .= '<b><i>'.$buffer.'</i>'; $state = 'b'; }
12361236 else # $state can be 'b' or ''
12371237 { $output .= '<i>'; $state .= 'i'; }
12381238 }
1239 - else if (strlen ($r) == 3)
 1239+ elseif (strlen ($r) == 3)
12401240 {
12411241 if ($state === 'b')
12421242 { $output .= '</b>'; $state = ''; }
1243 - else if ($state === 'bi')
 1243+ elseif ($state === 'bi')
12441244 { $output .= '</i></b><i>'; $state = 'i'; }
1245 - else if ($state === 'ib')
 1245+ elseif ($state === 'ib')
12461246 { $output .= '</b>'; $state = 'i'; }
1247 - else if ($state === 'both')
 1247+ elseif ($state === 'both')
12481248 { $output .= '<i><b>'.$buffer.'</b>'; $state = 'i'; }
12491249 else # $state can be 'i' or ''
12501250 { $output .= '<b>'; $state .= 'b'; }
12511251 }
1252 - else if (strlen ($r) == 5)
 1252+ elseif (strlen ($r) == 5)
12531253 {
12541254 if ($state === 'b')
12551255 { $output .= '</b><i>'; $state = 'i'; }
1256 - else if ($state === 'i')
 1256+ elseif ($state === 'i')
12571257 { $output .= '</i><b>'; $state = 'b'; }
1258 - else if ($state === 'bi')
 1258+ elseif ($state === 'bi')
12591259 { $output .= '</i></b>'; $state = ''; }
1260 - else if ($state === 'ib')
 1260+ elseif ($state === 'ib')
12611261 { $output .= '</b></i>'; $state = ''; }
1262 - else if ($state === 'both')
 1262+ elseif ($state === 'both')
12631263 { $output .= '<i><b>'.$buffer.'</b></i>'; $state = ''; }
12641264 else # ($state == '')
12651265 { $buffer = ''; $state = 'both'; }
12661266 }
1267 - else if (strlen ($r) == 6)
 1267+ elseif (strlen ($r) == 6)
12681268 {
12691269 if ($state === 'b')
12701270 { $output .= '</b><b>'; $state = 'b'; }
1271 - else if ($state === 'i')
 1271+ elseif ($state === 'i')
12721272 { $output .= '\'</i><b>'; $state = 'b'; }
1273 - else if ($state === 'bi')
 1273+ elseif ($state === 'bi')
12741274 { $output .= '\'</i></b>'; $state = ''; }
1275 - else if ($state === 'ib')
 1275+ elseif ($state === 'ib')
12761276 { $output .= '\'</b></i>'; $state = ''; }
1277 - else if ($state === 'both')
 1277+ elseif ($state === 'both')
12781278 { $output .= '<i><b>'.$buffer.'</b><b>'; $state = 'ib'; }
12791279 else # ($state == '')
12801280 { $buffer = ''; $state = ''; }
@@ -1536,9 +1536,9 @@
15371537 $sk = $this->mOptions->getSkin();
15381538 $holders = new LinkHolderArray( $this );
15391539
1540 - #split the entire text string on occurences of [[
 1540+ # split the entire text string on occurences of [[
15411541 $a = StringUtils::explode( '[[', ' ' . $s );
1542 - #get the first element (all text up to first [[), and remove the space we added
 1542+ # get the first element (all text up to first [[), and remove the space we added
15431543 $s = $a->current();
15441544 $a->next();
15451545 $line = $a->current(); # Workaround for broken ArrayIterator::next() that returns "void"
@@ -1683,10 +1683,10 @@
16841684
16851685 if ( $might_be_img ) { # if this is actually an invalid link
16861686 wfProfileIn( __METHOD__."-might_be_img" );
1687 - if ( $ns == NS_FILE && $noforce ) { #but might be an image
 1687+ if ( $ns == NS_FILE && $noforce ) { # but might be an image
16881688 $found = false;
16891689 while ( true ) {
1690 - #look at the next 'line' to see if we can close it there
 1690+ # look at the next 'line' to see if we can close it there
16911691 $a->next();
16921692 $next_line = $a->current();
16931693 if ( $next_line === false || $next_line === null ) {
@@ -1700,24 +1700,24 @@
17011701 $trail = $m[2];
17021702 break;
17031703 } elseif ( count( $m ) == 2 ) {
1704 - #if there's exactly one ]] that's fine, we'll keep looking
 1704+ # if there's exactly one ]] that's fine, we'll keep looking
17051705 $text .= "[[{$m[0]}]]{$m[1]}";
17061706 } else {
1707 - #if $next_line is invalid too, we need look no further
 1707+ # if $next_line is invalid too, we need look no further
17081708 $text .= '[[' . $next_line;
17091709 break;
17101710 }
17111711 }
17121712 if ( !$found ) {
17131713 # we couldn't find the end of this imageLink, so output it raw
1714 - #but don't ignore what might be perfectly normal links in the text we've examined
 1714+ # but don't ignore what might be perfectly normal links in the text we've examined
17151715 $holders->merge( $this->replaceInternalLinks2( $text ) );
17161716 $s .= "{$prefix}[[$link|$text";
17171717 # note: no $trail, because without an end, there *is* no trail
17181718 wfProfileOut( __METHOD__."-might_be_img" );
17191719 continue;
17201720 }
1721 - } else { #it's not an image, so output it raw
 1721+ } else { # it's not an image, so output it raw
17221722 $s .= "{$prefix}[[$link|$text";
17231723 # note: no $trail, because without an end, there *is* no trail
17241724 wfProfileOut( __METHOD__."-might_be_img" );
@@ -1794,7 +1794,7 @@
17951795 }
17961796
17971797 # Self-link checking
1798 - if( $nt->getFragment() === '' && $ns != NS_SPECIAL ) {
 1798+ if( $nt->getFragment() === '' && $ns !== NS_SPECIAL ) {
17991799 if( in_array( $nt->getPrefixedText(), $selflink, true ) ) {
18001800 $s .= $prefix . $sk->makeSelfLinkObj( $nt, $text, '', $trail );
18011801 continue;
@@ -1914,7 +1914,7 @@
19151915 */
19161916 /* private */ function closeParagraph() {
19171917 $result = '';
1918 - if ( $this->mLastSection != '' ) {
 1918+ if ( $this->mLastSection !== '' ) {
19191919 $result = '</' . $this->mLastSection . ">\n";
19201920 }
19211921 $this->mInPre = false;
@@ -1930,7 +1930,7 @@
19311931 if ( $fl < $shorter ) { $shorter = $fl; }
19321932
19331933 for ( $i = 0; $i < $shorter; ++$i ) {
1934 - if ( $st1{$i} != $st2{$i} ) { break; }
 1934+ if ( $st1{$i} !== $st2{$i} ) { break; }
19351935 }
19361936 return $i;
19371937 }
@@ -2103,7 +2103,7 @@
21042104 '<td|<th|<\\/?div|<hr|<\\/pre|<\\/p|'.$this->mUniqPrefix.'-pre|<\\/li|<\\/ul|<\\/ol|<\\/?center)/iS', $t );
21052105 if ( $openmatch or $closematch ) {
21062106 $paragraphStack = false;
2107 - # TODO bug 5718: paragraph closed
 2107+ # TODO bug 5718: paragraph closed
21082108 $output .= $this->closeParagraph();
21092109 if ( $preOpenMatch and !$preCloseMatch ) {
21102110 $this->mInPre = true;
@@ -2113,8 +2113,8 @@
21142114 } else {
21152115 $inBlockElem = true;
21162116 }
2117 - } else if ( !$inBlockElem && !$this->mInPre ) {
2118 - if ( ' ' == substr( $t, 0, 1 ) and ( $this->mLastSection === 'pre' or trim($t) != '' ) ) {
 2117+ } elseif ( !$inBlockElem && !$this->mInPre ) {
 2118+ if ( ' ' == substr( $t, 0, 1 ) and ( $this->mLastSection === 'pre' or trim($t) !== '' ) ) {
21192119 // pre
21202120 if ($this->mLastSection !== 'pre') {
21212121 $paragraphStack = false;
@@ -2143,7 +2143,7 @@
21442144 $output .= $paragraphStack;
21452145 $paragraphStack = false;
21462146 $this->mLastSection = 'p';
2147 - } else if ($this->mLastSection !== 'p') {
 2147+ } elseif ($this->mLastSection !== 'p') {
21482148 $output .= $this->closeParagraph().'<p>';
21492149 $this->mLastSection = 'p';
21502150 }
@@ -2164,7 +2164,7 @@
21652165 $output .= $this->closeList( $prefix2[$prefixLength-1] );
21662166 --$prefixLength;
21672167 }
2168 - if ( $this->mLastSection != '' ) {
 2168+ if ( $this->mLastSection !== '' ) {
21692169 $output .= '</' . $this->mLastSection . '>';
21702170 $this->mLastSection = '';
21712171 }
@@ -2970,7 +2970,7 @@
29712971 $isHTML = true;
29722972 $this->disableCache();
29732973 }
2974 - } else if ( $wgNonincludableNamespaces && in_array( $title->getNamespace(), $wgNonincludableNamespaces ) ) {
 2974+ } elseif ( $wgNonincludableNamespaces && in_array( $title->getNamespace(), $wgNonincludableNamespaces ) ) {
29752975 $found = false; //access denied
29762976 wfDebug( __METHOD__.": template inclusion denied for " . $title->getPrefixedDBkey() );
29772977 } else {
@@ -3583,7 +3583,7 @@
35843584 if (preg_match("/^$markerRegex/", $headline, $markerMatches)) {
35853585 $serial = $markerMatches[1];
35863586 list( $titleText, $sectionIndex ) = $this->mHeadings[$serial];
3587 - $isTemplate = ($titleText != $baseTitleText);
 3587+ $isTemplate = ($titleText !== $baseTitleText);
35883588 $headline = preg_replace("/^$markerRegex/", "", $headline);
35893589 }
35903590
@@ -3699,7 +3699,7 @@
37003700 if ( $legacyHeadline == $safeHeadline ) {
37013701 # No reason to have both (in fact, we can't)
37023702 $legacyHeadline = false;
3703 - } elseif ( $legacyHeadline != Sanitizer::escapeId(
 3703+ } elseif ( $legacyHeadline !== Sanitizer::escapeId(
37043704 $legacyHeadline, 'xml' ) ) {
37053705 # The legacy id is invalid XML. We used to allow this, but
37063706 # there's no reason to do so anymore. Backward
@@ -3873,8 +3873,8 @@
38743874 else
38753875 continue;
38763876 }
3877 - if ( $s['index'] != $section ||
3878 - $s['fromtitle'] != $titletext ) {
 3877+ if ( $s['index'] !== $section ||
 3878+ $s['fromtitle'] !== $titletext ) {
38793879 self::incrementNumbering( $numbering,
38803880 $s['toclevel'], $lastLevel );
38813881
@@ -3925,7 +3925,7 @@
39263926 private static function incrementNumbering( &$number, $level, $lastLevel ) {
39273927 if ( $level > $lastLevel )
39283928 $number[$level - 1] = 1;
3929 - else if ( $level < $lastLevel ) {
 3929+ elseif ( $level < $lastLevel ) {
39303930 foreach ( $number as $key => $unused )
39313931 if ( $key >= $level )
39323932 unset( $number[$key] );
@@ -4035,7 +4035,7 @@
40364036 $m = array();
40374037 if ( preg_match( "/^($nc+:|)$tc+?( \\($tc+\\))$/", $t, $m ) ) {
40384038 $text = preg_replace( $p2, "[[$m[1]\\1$m[2]|\\1]]", $text );
4039 - } elseif ( preg_match( "/^($nc+:|)$tc+?(, $tc+|)$/", $t, $m ) && "$m[1]$m[2]" != '' ) {
 4039+ } elseif ( preg_match( "/^($nc+:|)$tc+?(, $tc+|)$/", $t, $m ) && "$m[1]$m[2]" !== '' ) {
40404040 $text = preg_replace( $p2, "[[$m[1]\\1$m[2]|\\1]]", $text );
40414041 } else {
40424042 # if there's no context, don't bother duplicating the title
@@ -4874,7 +4874,7 @@
48754875 if ( $node->getName() === 'h' ) {
48764876 $bits = $node->splitHeading();
48774877 $curLevel = $bits['level'];
4878 - if ( $bits['i'] != $sectionIndex && $curLevel <= $targetLevel ) {
 4878+ if ( $bits['i'] !== $sectionIndex && $curLevel <= $targetLevel ) {
48794879 break;
48804880 }
48814881 }
@@ -4890,7 +4890,7 @@
48914891 // Add two newlines on -- trailing whitespace in $newText is conventionally
48924892 // stripped by the editor, so we need both newlines to restore the paragraph gap
48934893 // Only add trailing whitespace if there is newText
4894 - if($newText != "") {
 4894+ if($newText !== "") {
48954895 $outText .= $newText . "\n\n";
48964896 }
48974897

Follow-up revisions

RevisionCommit summaryAuthorDate
r61551Revert r61528, r61527, r61526, r61525, r61519, r61515, r61053, r61052 (Parser...tstarling02:41, 27 January 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r61052* (bug 18765) Increased consistency of bold-italic markup for unbalanced quotes....platonides16:18, 14 January 2010

Status & tagging log