From: Bartosz Dziewoński Date: Sun, 16 Nov 2014 19:18:00 +0000 (+0100) Subject: Standardize indentation of multiline 'if'/'elseif' conditions X-Git-Tag: 1.31.0-rc.0~13276 X-Git-Url: https://git.cyclocoop.org/%242?a=commitdiff_plain;h=3e85dfb8ad7b12c479b5cbe1fe40fbb5f5e537ac;p=lhc%2Fweb%2Fwiklou.git Standardize indentation of multiline 'if'/'elseif' conditions Always indent the continuation one level deeper, and always place the closing parenthesis on the next line, per coding conventions. https://www.mediawiki.org/wiki/Manual:Coding_conventions#Indenting_and_alignment https://www.mediawiki.org/wiki/Manual:Coding_conventions#Line_continuation Regexp used: (\t+)(if|while|\} elseif|foreach).+(? $option ) { if ( !preg_match( '/^[0-9]+|language$/', $arrayKey ) ) { - # An unknown index, neither numeric nor "language" + // An unknown index, neither numeric nor "language" wfWarn( "wfMsgExt called with incorrect parameter key $arrayKey", 1, E_USER_WARNING ); - } elseif ( preg_match( '/^[0-9]+$/', $arrayKey ) && !in_array( $option, - array( 'parse', 'parseinline', 'escape', 'escapenoentities', - 'replaceafter', 'parsemag', 'content' ) ) ) { - # A numeric index with unknown value + } elseif ( preg_match( '/^[0-9]+$/', $arrayKey ) && !in_array( $option, $validOptions ) ) { + // A numeric index with unknown value wfWarn( "wfMsgExt called with incorrect parameter $option", 1, E_USER_WARNING ); } } diff --git a/includes/Html.php b/includes/Html.php index fa868e373e..b3437d3930 100644 --- a/includes/Html.php +++ b/includes/Html.php @@ -267,8 +267,7 @@ class Html { // In text/html, initial and tags can be omitted under // pretty much any sane circumstances, if they have no attributes. See: // - if ( !$wgWellFormedXml && !$attribs - && in_array( $element, array( 'html', 'head' ) ) ) { + if ( !$wgWellFormedXml && !$attribs && in_array( $element, array( 'html', 'head' ) ) ) { return ''; } @@ -301,8 +300,7 @@ class Html { 'tel', 'color', ); - if ( isset( $attribs['type'] ) - && !in_array( $attribs['type'], $validTypes ) ) { + if ( isset( $attribs['type'] ) && !in_array( $attribs['type'], $validTypes ) ) { unset( $attribs['type'] ); } } @@ -396,8 +394,9 @@ class Html { } // Simple checks using $attribDefaults - if ( isset( $attribDefaults[$element][$lcattrib] ) && - $attribDefaults[$element][$lcattrib] == $value ) { + if ( isset( $attribDefaults[$element][$lcattrib] ) + && $attribDefaults[$element][$lcattrib] == $value + ) { unset( $attribs[$attrib] ); } @@ -407,8 +406,9 @@ class Html { } // More subtle checks - if ( $element === 'link' && isset( $attribs['type'] ) - && strval( $attribs['type'] ) == 'text/css' ) { + if ( $element === 'link' + && isset( $attribs['type'] ) && strval( $attribs['type'] ) == 'text/css' + ) { unset( $attribs['type'] ); } if ( $element === 'input' ) { @@ -507,8 +507,7 @@ class Html { // For boolean attributes, support array( 'foo' ) instead of // requiring array( 'foo' => 'meaningless' ). - if ( is_int( $key ) - && in_array( strtolower( $value ), self::$boolAttribs ) ) { + if ( is_int( $key ) && in_array( strtolower( $value ), self::$boolAttribs ) ) { $key = $value; } @@ -587,14 +586,13 @@ class Html { // marks omitted, but not all. (Although a literal " is not // permitted, we don't check for that, since it will be escaped // anyway.) - # + // See also research done on further characters that need to be // escaped: http://code.google.com/p/html5lib/issues/detail?id=93 $badChars = "\\x00- '=<>`/\x{00a0}\x{1680}\x{180e}\x{180F}\x{2000}\x{2001}" . "\x{2002}\x{2003}\x{2004}\x{2005}\x{2006}\x{2007}\x{2008}\x{2009}" . "\x{200A}\x{2028}\x{2029}\x{202F}\x{205F}\x{3000}"; - if ( $wgWellFormedXml || $value === '' - || preg_match( "![$badChars]!u", $value ) ) { + if ( $wgWellFormedXml || $value === '' || preg_match( "![$badChars]!u", $value ) ) { $quote = '"'; } else { $quote = ''; diff --git a/includes/Linker.php b/includes/Linker.php index 0e9ef2b03a..1b0803c762 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -209,8 +209,9 @@ class Linker { $dummy = new DummyLinker; // dummy linker instance for bc on the hooks $ret = null; - if ( !wfRunHooks( 'LinkBegin', array( $dummy, $target, &$html, - &$customAttribs, &$query, &$options, &$ret ) ) ) { + if ( !wfRunHooks( 'LinkBegin', + array( $dummy, $target, &$html, &$customAttribs, &$query, &$options, &$ret ) ) + ) { wfProfileOut( __METHOD__ ); return $ret; } diff --git a/includes/Sanitizer.php b/includes/Sanitizer.php index bca2f67e91..16546430b9 100644 --- a/includes/Sanitizer.php +++ b/includes/Sanitizer.php @@ -510,15 +510,12 @@ class Sanitizer { $newparams = ''; } else { # Keep track for later - if ( isset( $tabletags[$t] ) && - !in_array( 'table', $tagstack ) ) { + if ( isset( $tabletags[$t] ) && !in_array( 'table', $tagstack ) ) { $badtag = true; - } elseif ( in_array( $t, $tagstack ) && - !isset( $htmlnest[$t] ) ) { + } elseif ( in_array( $t, $tagstack ) && !isset( $htmlnest[$t] ) ) { $badtag = true; # Is it a self closed htmlpair ? (bug 5487) - } elseif ( $brace == '/>' && - isset( $htmlpairs[$t] ) ) { + } elseif ( $brace == '/>' && isset( $htmlpairs[$t] ) ) { $badtag = true; } elseif ( isset( $htmlsingleonly[$t] ) ) { # Hack to force empty tag for unclosable elements @@ -530,8 +527,7 @@ class Sanitizer { # the tag stack so that we can match end tags # instead of marking them as bad. array_push( $tagstack, $t ); - } elseif ( isset( $tabletags[$t] ) - && in_array( $t, $tagstack ) ) { + } elseif ( isset( $tabletags[$t] ) && in_array( $t, $tagstack ) ) { // New table tag but forgot to close the previous one $text .= ""; } else { @@ -1120,14 +1116,14 @@ class Sanitizer { $id = preg_replace( '/[ \t\n\r\f_\'"&#%]+/', '_', $id ); $id = trim( $id, '_' ); if ( $id === '' ) { - # Must have been all whitespace to start with. + // Must have been all whitespace to start with. return '_'; } else { return $id; } } - # HTML4-style escaping + // HTML4-style escaping static $replace = array( '%3A' => ':', '%' => '.' @@ -1136,8 +1132,7 @@ class Sanitizer { $id = urlencode( strtr( $id, ' ', '_' ) ); $id = str_replace( array_keys( $replace ), array_values( $replace ), $id ); - if ( !preg_match( '/^[a-zA-Z]/', $id ) - && !in_array( 'noninitial', $options ) ) { + if ( !preg_match( '/^[a-zA-Z]/', $id ) && !in_array( 'noninitial', $options ) ) { // Initial character must be a letter! $id = "x$id"; } @@ -1368,8 +1363,7 @@ class Sanitizer { static function normalizeEntity( $name ) { if ( isset( self::$htmlEntityAliases[$name] ) ) { return '&' . self::$htmlEntityAliases[$name] . ';'; - } elseif ( in_array( $name, - array( 'lt', 'gt', 'amp', 'quot' ) ) ) { + } elseif ( in_array( $name, array( 'lt', 'gt', 'amp', 'quot' ) ) ) { return "&$name;"; } elseif ( isset( self::$htmlEntities[$name] ) ) { return '&#' . self::$htmlEntities[$name] . ';'; diff --git a/includes/User.php b/includes/User.php index 90d33fb434..8fcdab26cf 100644 --- a/includes/User.php +++ b/includes/User.php @@ -641,10 +641,11 @@ class User implements IDBAccessObject { global $wgContLang, $wgMaxNameChars; if ( $name == '' - || User::isIP( $name ) - || strpos( $name, '/' ) !== false - || strlen( $name ) > $wgMaxNameChars - || $name != $wgContLang->ucfirst( $name ) ) { + || User::isIP( $name ) + || strpos( $name, '/' ) !== false + || strlen( $name ) > $wgMaxNameChars + || $name != $wgContLang->ucfirst( $name ) + ) { wfDebugLog( 'username', __METHOD__ . ": '$name' invalid due to empty, IP, slash, length, or lowercase" ); return false; @@ -4511,6 +4512,7 @@ class User implements IDBAccessObject { // Same thing for remove if ( empty( $wgRemoveGroups[$group] ) ) { + // Do nothing } elseif ( $wgRemoveGroups[$group] === true ) { $groups['remove'] = self::getAllGroups(); } elseif ( is_array( $wgRemoveGroups[$group] ) ) { @@ -4536,6 +4538,7 @@ class User implements IDBAccessObject { // Now figure out what groups the user can add to him/herself if ( empty( $wgGroupsAddToSelf[$group] ) ) { + // Do nothing } elseif ( $wgGroupsAddToSelf[$group] === true ) { // No idea WHY this would be used, but it's there $groups['add-self'] = User::getAllGroups(); @@ -4544,6 +4547,7 @@ class User implements IDBAccessObject { } if ( empty( $wgGroupsRemoveFromSelf[$group] ) ) { + // Do nothing } elseif ( $wgGroupsRemoveFromSelf[$group] === true ) { $groups['remove-self'] = User::getAllGroups(); } elseif ( is_array( $wgGroupsRemoveFromSelf[$group] ) ) { diff --git a/includes/htmlform/HTMLIntField.php b/includes/htmlform/HTMLIntField.php index 28876e2cf9..d0ee13b4f6 100644 --- a/includes/htmlform/HTMLIntField.php +++ b/includes/htmlform/HTMLIntField.php @@ -17,8 +17,7 @@ class HTMLIntField extends HTMLFloatField { # phone numbers when you know that they are integers (the HTML5 type=tel # input does not require its value to be numeric). If you want a tidier # value to, eg, save in the DB, clean it up with intval(). - if ( !preg_match( '/^((\+|\-)?\d+)?$/', trim( $value ) ) - ) { + if ( !preg_match( '/^((\+|\-)?\d+)?$/', trim( $value ) ) ) { return $this->msg( 'htmlform-int-invalid' )->parseAsBlock(); } diff --git a/includes/htmlform/HTMLSelectAndOtherField.php b/includes/htmlform/HTMLSelectAndOtherField.php index 1175bd3b51..a1c0c95748 100644 --- a/includes/htmlform/HTMLSelectAndOtherField.php +++ b/includes/htmlform/HTMLSelectAndOtherField.php @@ -13,6 +13,7 @@ class HTMLSelectAndOtherField extends HTMLSelectField { function __construct( $params ) { if ( array_key_exists( 'other', $params ) ) { + // Do nothing } elseif ( array_key_exists( 'other-message', $params ) ) { $params['other'] = wfMessage( $params['other-message'] )->plain(); } else { @@ -22,7 +23,7 @@ class HTMLSelectAndOtherField extends HTMLSelectField { parent::__construct( $params ); if ( $this->getOptions() === null ) { - # Sulk + // Sulk throw new MWException( 'HTMLSelectAndOtherField called without any options' ); } if ( !in_array( 'other', $this->mOptions, true ) ) { diff --git a/includes/installer/WebInstallerPage.php b/includes/installer/WebInstallerPage.php index b2b0a69124..d507303595 100644 --- a/includes/installer/WebInstallerPage.php +++ b/includes/installer/WebInstallerPage.php @@ -1287,8 +1287,7 @@ class WebInstallerOptions extends WebInstallerPage { $retVal = true; - if ( !array_key_exists( $this->getVar( '_RightsProfile' ), $this->parent->rightsProfiles ) - ) { + if ( !array_key_exists( $this->getVar( '_RightsProfile' ), $this->parent->rightsProfiles ) ) { reset( $this->parent->rightsProfiles ); $this->setVar( '_RightsProfile', key( $this->parent->rightsProfiles ) ); }