r39615 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r39614‎ | r39615 | r39616 >
Date:20:52, 18 August 2008
Author:aaron
Status:old
Tags:
Comment:
Use more simple strict comparisons
Modified paths:
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/parser/Parser.php
@@ -541,7 +541,7 @@
542542 $text = $inside;
543543 $tail = null;
544544 } else {
545 - if( $element == '!--' ) {
 545+ if( $element === '!--' ) {
546546 $end = '/(-->)/';
547547 } else {
548548 $end = "/(<\\/$element\\s*>)/i";
@@ -786,7 +786,7 @@
787787 // Don't do any of the following
788788 $out .= $outLine."\n";
789789 continue;
790 - } else if ( substr ( $line , 0 , 2 ) == '|}' ) {
 790+ } else if ( substr ( $line , 0 , 2 ) === '|}' ) {
791791 // We are ending a table
792792 $line = '</table>' . substr ( $line , 2 );
793793 $last_tag = array_pop ( $last_tag_history );
@@ -804,7 +804,7 @@
805805 }
806806 array_pop ( $tr_attributes );
807807 $outLine = $line . str_repeat( '</dd></dl>' , $indent_level );
808 - } else if ( substr ( $line , 0 , 2 ) == '|-' ) {
 808+ } else if ( substr ( $line , 0 , 2 ) === '|-' ) {
809809 // Now we have a table row
810810 $line = preg_replace( '#^\|-+#', '', $line );
811811
@@ -832,16 +832,16 @@
833833 array_push ( $td_history , false );
834834 array_push ( $last_tag_history , '' );
835835 }
836 - else if ( $first_character == '|' || $first_character == '!' || substr ( $line , 0 , 2 ) == '|+' ) {
 836+ else if ( $first_character === '|' || $first_character === '!' || substr ( $line , 0 , 2 ) === '|+' ) {
837837 // This might be cell elements, td, th or captions
838 - if ( substr ( $line , 0 , 2 ) == '|+' ) {
 838+ if ( substr ( $line , 0 , 2 ) === '|+' ) {
839839 $first_character = '+';
840840 $line = substr ( $line , 1 );
841841 }
842842
843843 $line = substr ( $line , 1 );
844844
845 - if ( $first_character == '!' ) {
 845+ if ( $first_character === '!' ) {
846846 $line = str_replace ( '!!' , '||' , $line );
847847 }
848848
@@ -857,7 +857,7 @@
858858 foreach ( $cells as $cell )
859859 {
860860 $previous = '';
861 - if ( $first_character != '+' )
 861+ if ( $first_character !== '+' )
862862 {
863863 $tr_after = array_pop ( $tr_attributes );
864864 if ( !array_pop ( $tr_history ) ) {
@@ -875,11 +875,11 @@
876876 $previous = "</{$last_tag}>{$previous}";
877877 }
878878
879 - if ( $first_character == '|' ) {
 879+ if ( $first_character === '|' ) {
880880 $last_tag = 'td';
881 - } else if ( $first_character == '!' ) {
 881+ } else if ( $first_character === '!' ) {
882882 $last_tag = 'th';
883 - } else if ( $first_character == '+' ) {
 883+ } else if ( $first_character === '+' ) {
884884 $last_tag = 'caption';
885885 } else {
886886 $last_tag = '';
@@ -926,12 +926,12 @@
927927 }
928928
929929 // Remove trailing line-ending (b/c)
930 - if ( substr( $out, -1 ) == "\n" ) {
 930+ if ( substr( $out, -1 ) === "\n" ) {
931931 $out = substr( $out, 0, -1 );
932932 }
933933
934934 // special case: don't return empty table
935 - if( $out == "<table>\n<tr><td></td></tr>\n</table>" ) {
 935+ if( $out === "<table>\n<tr><td></td></tr>\n</table>" ) {
936936 $out = '';
937937 }
938938
@@ -1013,10 +1013,10 @@
10141014 }
10151015
10161016 function magicLinkCallback( $m ) {
1017 - if ( substr( $m[0], 0, 1 ) == '<' ) {
 1017+ if ( substr( $m[0], 0, 1 ) === '<' ) {
10181018 # Skip HTML element
10191019 return $m[0];
1020 - } elseif ( substr( $m[0], 0, 4 ) == 'ISBN' ) {
 1020+ } elseif ( substr( $m[0], 0, 4 ) === 'ISBN' ) {
10211021 $isbn = $m[2];
10221022 $num = strtr( $isbn, array(
10231023 '-' => '',
@@ -1028,11 +1028,11 @@
10291029 $titleObj->escapeLocalUrl() .
10301030 "\" class=\"internal\">ISBN $isbn</a>";
10311031 } else {
1032 - if ( substr( $m[0], 0, 3 ) == 'RFC' ) {
 1032+ if ( substr( $m[0], 0, 3 ) === 'RFC' ) {
10331033 $keyword = 'RFC';
10341034 $urlmsg = 'rfcurl';
10351035 $id = $m[1];
1036 - } elseif ( substr( $m[0], 0, 4 ) == 'PMID' ) {
 1036+ } elseif ( substr( $m[0], 0, 4 ) === 'PMID' ) {
10371037 $keyword = 'PMID';
10381038 $urlmsg = 'pubmedurl';
10391039 $id = $m[1];
@@ -1140,9 +1140,9 @@
11411141 {
11421142 $x1 = substr ($arr[$i-1], -1);
11431143 $x2 = substr ($arr[$i-1], -2, 1);
1144 - if ($x1 == ' ') {
 1144+ if ($x1 === ' ') {
11451145 if ($firstspace == -1) $firstspace = $i;
1146 - } else if ($x2 == ' ') {
 1146+ } else if ($x2 === ' ') {
11471147 if ($firstsingleletterword == -1) $firstsingleletterword = $i;
11481148 } else {
11491149 if ($firstmultiletterword == -1) $firstmultiletterword = $i;
@@ -1182,7 +1182,7 @@
11831183 {
11841184 if (($i % 2) == 0)
11851185 {
1186 - if ($state == 'both')
 1186+ if ($state === 'both')
11871187 $buffer .= $r;
11881188 else
11891189 $output .= $r;
@@ -1191,41 +1191,41 @@
11921192 {
11931193 if (strlen ($r) == 2)
11941194 {
1195 - if ($state == 'i')
 1195+ if ($state === 'i')
11961196 { $output .= '</i>'; $state = ''; }
1197 - else if ($state == 'bi')
 1197+ else if ($state === 'bi')
11981198 { $output .= '</i>'; $state = 'b'; }
1199 - else if ($state == 'ib')
 1199+ else if ($state === 'ib')
12001200 { $output .= '</b></i><b>'; $state = 'b'; }
1201 - else if ($state == 'both')
 1201+ else if ($state === 'both')
12021202 { $output .= '<b><i>'.$buffer.'</i>'; $state = 'b'; }
12031203 else # $state can be 'b' or ''
12041204 { $output .= '<i>'; $state .= 'i'; }
12051205 }
12061206 else if (strlen ($r) == 3)
12071207 {
1208 - if ($state == 'b')
 1208+ if ($state === 'b')
12091209 { $output .= '</b>'; $state = ''; }
1210 - else if ($state == 'bi')
 1210+ else if ($state === 'bi')
12111211 { $output .= '</i></b><i>'; $state = 'i'; }
1212 - else if ($state == 'ib')
 1212+ else if ($state === 'ib')
12131213 { $output .= '</b>'; $state = 'i'; }
1214 - else if ($state == 'both')
 1214+ else if ($state === 'both')
12151215 { $output .= '<i><b>'.$buffer.'</b>'; $state = 'i'; }
12161216 else # $state can be 'i' or ''
12171217 { $output .= '<b>'; $state .= 'b'; }
12181218 }
12191219 else if (strlen ($r) == 5)
12201220 {
1221 - if ($state == 'b')
 1221+ if ($state === 'b')
12221222 { $output .= '</b><i>'; $state = 'i'; }
1223 - else if ($state == 'i')
 1223+ else if ($state === 'i')
12241224 { $output .= '</i><b>'; $state = 'b'; }
1225 - else if ($state == 'bi')
 1225+ else if ($state === 'bi')
12261226 { $output .= '</i></b>'; $state = ''; }
1227 - else if ($state == 'ib')
 1227+ else if ($state === 'ib')
12281228 { $output .= '</b></i>'; $state = ''; }
1229 - else if ($state == 'both')
 1229+ else if ($state === 'both')
12301230 { $output .= '<i><b>'.$buffer.'</b></i>'; $state = ''; }
12311231 else # ($state == '')
12321232 { $buffer = ''; $state = 'both'; }
@@ -1234,14 +1234,14 @@
12351235 $i++;
12361236 }
12371237 # Now close all remaining tags. Notice that the order is important.
1238 - if ($state == 'b' || $state == 'ib')
 1238+ if ($state === 'b' || $state === 'ib')
12391239 $output .= '</b>';
1240 - if ($state == 'i' || $state == 'bi' || $state == 'ib')
 1240+ if ($state === 'i' || $state === 'bi' || $state === 'ib')
12411241 $output .= '</i>';
1242 - if ($state == 'bi')
 1242+ if ($state === 'bi')
12431243 $output .= '</b>';
12441244 # There might be lonely ''''', so make sure we have a buffer
1245 - if ($state == 'both' && $buffer)
 1245+ if ($state === 'both' && $buffer)
12461246 $output .= '<b><i>'.$buffer.'</i></b>';
12471247 return $output;
12481248 }
@@ -1291,7 +1291,7 @@
12921292 $dtrail = '';
12931293
12941294 # Set linktype for CSS - if URL==text, link is essentially free
1295 - $linktype = ($text == $url) ? 'free' : 'text';
 1295+ $linktype = ($text === $url) ? 'free' : 'text';
12961296
12971297 # No link text, e.g. [http://domain.tld/some.link]
12981298 if ( $text == '' ) {
@@ -1631,7 +1631,7 @@
16321632 $link = $m[1];
16331633 }
16341634
1635 - $noforce = (substr($m[1], 0, 1) != ':');
 1635+ $noforce = (substr($m[1], 0, 1) !== ':');
16361636 if (!$noforce) {
16371637 # Strip off leading ':'
16381638 $link = substr($link, 1);
@@ -1892,7 +1892,7 @@
18931893 # bug 7425
18941894 $target = trim( $target );
18951895 # Look at the first character
1896 - if( $target != '' && $target{0} == '/' ) {
 1896+ if( $target != '' && $target{0} === '/' ) {
18971897 # / at end means we don't want the slash to be shown
18981898 $m = array();
18991899 $trailingSlashes = preg_match_all( '%(/+)$%', $target, $m );
@@ -1919,7 +1919,7 @@
19201920 if( count( $exploded ) > $dotdotcount ) { # not allowed to go below top level page
19211921 $ret = implode( '/', array_slice( $exploded, 0, -$dotdotcount ) );
19221922 # / at the end means don't show full path
1923 - if( substr( $nodotdot, -1, 1 ) == '/' ) {
 1923+ if( substr( $nodotdot, -1, 1 ) === '/' ) {
19241924 $nodotdot = substr( $nodotdot, 0, -1 );
19251925 if( '' === $text ) {
19261926 $text = $nodotdot . $suffix;
@@ -1971,10 +1971,10 @@
19721972 /* private */ function openList( $char ) {
19731973 $result = $this->closeParagraph();
19741974
1975 - if ( '*' == $char ) { $result .= '<ul><li>'; }
1976 - else if ( '#' == $char ) { $result .= '<ol><li>'; }
1977 - else if ( ':' == $char ) { $result .= '<dl><dd>'; }
1978 - else if ( ';' == $char ) {
 1975+ if ( '*' === $char ) { $result .= '<ul><li>'; }
 1976+ else if ( '#' === $char ) { $result .= '<ol><li>'; }
 1977+ else if ( ':' === $char ) { $result .= '<dl><dd>'; }
 1978+ else if ( ';' === $char ) {
19791979 $result .= '<dl><dt>';
19801980 $this->mDTopen = true;
19811981 }
@@ -1984,11 +1984,11 @@
19851985 }
19861986
19871987 /* private */ function nextItem( $char ) {
1988 - if ( '*' == $char || '#' == $char ) { return '</li><li>'; }
1989 - else if ( ':' == $char || ';' == $char ) {
 1988+ if ( '*' === $char || '#' === $char ) { return '</li><li>'; }
 1989+ else if ( ':' === $char || ';' === $char ) {
19901990 $close = '</dd>';
19911991 if ( $this->mDTopen ) { $close = '</dt>'; }
1992 - if ( ';' == $char ) {
 1992+ if ( ';' === $char ) {
19931993 $this->mDTopen = true;
19941994 return $close . '<dt>';
19951995 } else {
@@ -2000,9 +2000,9 @@
20012001 }
20022002
20032003 /* private */ function closeList( $char ) {
2004 - if ( '*' == $char ) { $text = '</li></ul>'; }
2005 - else if ( '#' == $char ) { $text = '</li></ol>'; }
2006 - else if ( ':' == $char ) {
 2004+ if ( '*' === $char ) { $text = '</li></ul>'; }
 2005+ else if ( '#' === $char ) { $text = '</li></ol>'; }
 2006+ else if ( ':' === $char ) {
20072007 if ( $this->mDTopen ) {
20082008 $this->mDTopen = false;
20092009 $text = '</dt></dl>';
@@ -2068,7 +2068,7 @@
20692069 $output .= $this->nextItem( substr( $prefix, -1 ) );
20702070 $paragraphStack = false;
20712071
2072 - if ( substr( $prefix, -1 ) == ';') {
 2072+ if ( substr( $prefix, -1 ) === ';') {
20732073 # The one nasty exception: definition lists work like this:
20742074 # ; title : definition text
20752075 # So we check for : in the remainder text to split up the
@@ -2095,7 +2095,7 @@
20962096 $char = substr( $prefix, $commonPrefixLength, 1 );
20972097 $output .= $this->openList( $char );
20982098
2099 - if ( ';' == $char ) {
 2099+ if ( ';' === $char ) {
21002100 # FIXME: This is dupe of code above
21012101 if ($this->findColonNoLinks($t, $term, $t2) !== false) {
21022102 $t = $t2;
@@ -2127,9 +2127,9 @@
21282128 $inBlockElem = true;
21292129 }
21302130 } else if ( !$inBlockElem && !$this->mInPre ) {
2131 - if ( ' ' == $t{0} and ( $this->mLastSection == 'pre' or trim($t) != '' ) ) {
 2131+ if ( ' ' == $t{0} and ( $this->mLastSection === 'pre' or trim($t) != '' ) ) {
21322132 // pre
2133 - if ($this->mLastSection != 'pre') {
 2133+ if ($this->mLastSection !== 'pre') {
21342134 $paragraphStack = false;
21352135 $output .= $this->closeParagraph().'<pre>';
21362136 $this->mLastSection = 'pre';
@@ -2143,7 +2143,7 @@
21442144 $paragraphStack = false;
21452145 $this->mLastSection = 'p';
21462146 } else {
2147 - if ($this->mLastSection != 'p' ) {
 2147+ if ($this->mLastSection !== 'p' ) {
21482148 $output .= $this->closeParagraph();
21492149 $this->mLastSection = '';
21502150 $paragraphStack = '<p>';
@@ -2156,7 +2156,7 @@
21572157 $output .= $paragraphStack;
21582158 $paragraphStack = false;
21592159 $this->mLastSection = 'p';
2160 - } else if ($this->mLastSection != 'p') {
 2160+ } else if ($this->mLastSection !== 'p') {
21612161 $output .= $this->closeParagraph().'<p>';
21622162 $this->mLastSection = 'p';
21632163 }
@@ -2299,7 +2299,7 @@
23002300 break;
23012301 case 3: // self::COLON_STATE_CLOSETAG:
23022302 // In a </tag>
2303 - if( $c == ">" ) {
 2303+ if( $c === ">" ) {
23042304 $stack--;
23052305 if( $stack < 0 ) {
23062306 wfDebug( __METHOD__.": Invalid input; too many close tags\n" );
@@ -2310,7 +2310,7 @@
23112311 }
23122312 break;
23132313 case self::COLON_STATE_TAGSLASH:
2314 - if( $c == ">" ) {
 2314+ if( $c === ">" ) {
23152315 // Yes, a self-closed tag <blah/>
23162316 $state = self::COLON_STATE_TEXT;
23172317 } else {
@@ -2319,19 +2319,19 @@
23202320 }
23212321 break;
23222322 case 5: // self::COLON_STATE_COMMENT:
2323 - if( $c == "-" ) {
 2323+ if( $c === "-" ) {
23242324 $state = self::COLON_STATE_COMMENTDASH;
23252325 }
23262326 break;
23272327 case self::COLON_STATE_COMMENTDASH:
2328 - if( $c == "-" ) {
 2328+ if( $c === "-" ) {
23292329 $state = self::COLON_STATE_COMMENTDASHDASH;
23302330 } else {
23312331 $state = self::COLON_STATE_COMMENT;
23322332 }
23332333 break;
23342334 case self::COLON_STATE_COMMENTDASHDASH:
2335 - if( $c == ">" ) {
 2335+ if( $c === ">" ) {
23362336 $state = self::COLON_STATE_TEXT;
23372337 } else {
23382338 $state = self::COLON_STATE_COMMENT;
@@ -3291,7 +3291,7 @@
32923292 }
32933293 }
32943294
3295 - if ( $name == 'html' || $name == 'nowiki' ) {
 3295+ if ( $name === 'html' || $name === 'nowiki' ) {
32963296 $this->mStripState->nowiki->setPair( $marker, $output );
32973297 } else {
32983298 $this->mStripState->general->setPair( $marker, $output );
@@ -3623,7 +3623,7 @@
36243624 $i = 0;
36253625
36263626 foreach( $blocks as $block ) {
3627 - if( $showEditLink && $headlineCount > 0 && $i == 0 && $block != "\n" ) {
 3627+ if( $showEditLink && $headlineCount > 0 && $i == 0 && $block !== "\n" ) {
36283628 # This is the [edit] link that appears for the top block of text when
36293629 # section editing is enabled
36303630
@@ -4003,7 +4003,7 @@
40044004 $syn = '#' . $syn;
40054005 }
40064006 # Remove trailing colon
4007 - if ( substr( $syn, -1, 1 ) == ':' ) {
 4007+ if ( substr( $syn, -1, 1 ) === ':' ) {
40084008 $syn = substr( $syn, 0, -1 );
40094009 }
40104010 $this->mFunctionSynonyms[$sensitive][$syn] = $id;
@@ -4224,7 +4224,7 @@
42254225 list( $type, $paramName ) = $paramMap[$magicName];
42264226
42274227 // Special case; width and height come in one variable together
4228 - if( $type == 'handler' && $paramName == 'width' ) {
 4228+ if( $type === 'handler' && $paramName === 'width' ) {
42294229 $m = array();
42304230 # (bug 13500) In both cases (width/height and width only),
42314231 # permit trailing "px" for backward compatibility.
@@ -4247,7 +4247,7 @@
42484248 }
42494249 } // else no validation -- bug 13436
42504250 } else {
4251 - if ( $type == 'handler' ) {
 4251+ if ( $type === 'handler' ) {
42524252 # Validate handler parameter
42534253 $validated = $handler->validateParam( $paramName, $value );
42544254 } else {
@@ -4392,7 +4392,7 @@
43934393 $sectionParts = explode( '-', $section );
43944394 $sectionIndex = array_pop( $sectionParts );
43954395 foreach ( $sectionParts as $part ) {
4396 - if ( $part == 'T' ) {
 4396+ if ( $part === 'T' ) {
43974397 $flags |= self::PTD_FOR_INCLUSION;
43984398 }
43994399 }
@@ -4409,14 +4409,14 @@
44104410 $targetLevel = 1000;
44114411 } else {
44124412 while ( $node ) {
4413 - if ( $node->getName() == 'h' ) {
 4413+ if ( $node->getName() === 'h' ) {
44144414 $bits = $node->splitHeading();
44154415 if ( $bits['i'] == $sectionIndex ) {
44164416 $targetLevel = $bits['level'];
44174417 break;
44184418 }
44194419 }
4420 - if ( $mode == 'replace' ) {
 4420+ if ( $mode === 'replace' ) {
44214421 $outText .= $frame->expand( $node, PPFrame::RECOVER_ORIG );
44224422 }
44234423 $node = $node->getNextSibling();
@@ -4425,7 +4425,7 @@
44264426
44274427 if ( !$node ) {
44284428 // Not found
4429 - if ( $mode == 'get' ) {
 4429+ if ( $mode === 'get' ) {
44304430 return $newText;
44314431 } else {
44324432 return $text;
@@ -4434,21 +4434,21 @@
44354435
44364436 // Find the end of the section, including nested sections
44374437 do {
4438 - if ( $node->getName() == 'h' ) {
 4438+ if ( $node->getName() === 'h' ) {
44394439 $bits = $node->splitHeading();
44404440 $curLevel = $bits['level'];
44414441 if ( $bits['i'] != $sectionIndex && $curLevel <= $targetLevel ) {
44424442 break;
44434443 }
44444444 }
4445 - if ( $mode == 'get' ) {
 4445+ if ( $mode === 'get' ) {
44464446 $outText .= $frame->expand( $node, PPFrame::RECOVER_ORIG );
44474447 }
44484448 $node = $node->getNextSibling();
44494449 } while ( $node );
44504450
44514451 // Write out the remainder (in replace mode only)
4452 - if ( $mode == 'replace' ) {
 4452+ if ( $mode === 'replace' ) {
44534453 // Output the replacement text
44544454 // Add two newlines on -- trailing whitespace in $newText is conventionally
44554455 // stripped by the editor, so we need both newlines to restore the paragraph gap
@@ -4713,7 +4713,7 @@
47144714 var $output = '';
47154715
47164716 function replace( $matches ) {
4717 - if ( substr( $matches[1], -1 ) == "\n" ) {
 4717+ if ( substr( $matches[1], -1 ) === "\n" ) {
47184718 $this->output .= substr( $matches[1], 0, -1 );
47194719 } else {
47204720 $this->output .= $matches[1];

Status & tagging log