Standardize indentation of multiline 'if'/'elseif' conditions
authorBartosz Dziewoński <matma.rex@gmail.com>
Sun, 16 Nov 2014 19:18:00 +0000 (20:18 +0100)
committerUmherirrender <umherirrender_de.wp@web.de>
Mon, 17 Nov 2014 15:33:34 +0000 (15:33 +0000)
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).+(?<![;}])\n\1\S

Also:
* Change to just one line if line length stays under 100 characters.
* Add "// Do nothing" comment in empty 'if' bodies.
* Change '#' comments to '//' comments near affected code.

Change-Id: I4f62658fddb5a0ed18bbf9b2231cd794683d6402

includes/GlobalFunctions.php
includes/Html.php
includes/Linker.php
includes/Sanitizer.php
includes/User.php
includes/htmlform/HTMLIntField.php
includes/htmlform/HTMLSelectAndOtherField.php
includes/installer/WebInstallerPage.php

index 81f767d..b499904 100644 (file)
@@ -1620,15 +1620,15 @@ function wfMsgExt( $key, $options ) {
        array_shift( $args );
        array_shift( $args );
        $options = (array)$options;
+       $validOptions = array( 'parse', 'parseinline', 'escape', 'escapenoentities', 'replaceafter',
+               'parsemag', 'content' );
 
        foreach ( $options as $arrayKey => $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 );
                }
        }
index fa868e3..b3437d3 100644 (file)
@@ -267,8 +267,7 @@ class Html {
                // In text/html, initial <html> and <head> tags can be omitted under
                // pretty much any sane circumstances, if they have no attributes.  See:
                // <http://www.whatwg.org/html/syntax.html#optional-tags>
-               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 = '';
index 0e9ef2b..1b0803c 100644 (file)
@@ -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;
                }
index bca2f67..1654643 100644 (file)
@@ -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 .= "</$t>";
                                                } 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] . ';';
index 90d33fb..8fcdab2 100644 (file)
@@ -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] ) ) {
index 28876e2..d0ee13b 100644 (file)
@@ -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();
                }
 
index 1175bd3..a1c0c95 100644 (file)
@@ -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 ) ) {
index b2b0a69..d507303 100644 (file)
@@ -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 ) );
                }