From 9ceb44a598751550a0e14349562aa931b24b58c6 Mon Sep 17 00:00:00 2001 From: Sam Reed Date: Sun, 16 Oct 2011 03:27:12 +0000 Subject: [PATCH] Fixup some assignments in conditionals Add/normalise some more return statements --- includes/EditPage.php | 1 + includes/Exception.php | 3 +- includes/Linker.php | 3 +- includes/OutputPage.php | 7 ++- includes/Sanitizer.php | 60 ++++++++++--------- includes/Title.php | 2 +- includes/installer/Ibm_db2Installer.php | 7 ++- includes/objectcache/DBABagOStuff.php | 4 +- includes/search/SearchUpdate.php | 2 +- includes/specials/SpecialSearch.php | 10 +++- languages/Language.php | 2 +- maintenance/benchmarks/benchmarkHooks.php | 2 +- maintenance/storage/checkStorage.php | 3 + .../includes/search/SearchEngineTest.php | 4 +- .../includes/upload/UploadFromUrlTest.php | 5 +- 15 files changed, 69 insertions(+), 46 deletions(-) diff --git a/includes/EditPage.php b/includes/EditPage.php index b34184f20d..7ac9c90d98 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -2938,6 +2938,7 @@ HTML $wgOut->permissionRequired( 'upload' ); return false; } + return false; } /** diff --git a/includes/Exception.php b/includes/Exception.php index c5abad0bee..b1e788f86c 100644 --- a/includes/Exception.php +++ b/includes/Exception.php @@ -70,8 +70,9 @@ class MWException extends Exception { $result = null; } - if ( is_string( $result ) ) + if ( is_string( $result ) ) { return $result; + } } } diff --git a/includes/Linker.php b/includes/Linker.php index 8c867bb2ef..4c16a9ad15 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -1823,9 +1823,8 @@ class Linker { return Linker::revDeleteLink( $query, $rev->isDeleted( File::DELETED_RESTRICTED ), $canHide ); } - } else { - return ''; } + return ''; } /** diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 0dc7b0cc41..d84b9f00a1 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -1201,12 +1201,12 @@ class OutputPage extends ContextSource { public function addHTML( $text ) { $this->mBodytext .= $text; } - + /** * Shortcut for adding an Html::element via addHTML. - * + * * @since 1.19 - * + * * @param $element string * @param $attribs array * @param $contents string @@ -1730,6 +1730,7 @@ class OutputPage extends ContextSource { } elseif ( $this->mPreventClickjacking && $wgEditPageFrameOptions ) { return $wgEditPageFrameOptions; } + return false; } /** diff --git a/includes/Sanitizer.php b/includes/Sanitizer.php index 8272ea4e72..13ba8c1a07 100644 --- a/includes/Sanitizer.php +++ b/includes/Sanitizer.php @@ -33,7 +33,7 @@ class Sanitizer { * Regular expression to match various types of character references in * Sanitizer::normalizeCharReferences and Sanitizer::decodeCharReferences */ - const CHAR_REFS_REGEX = + const CHAR_REFS_REGEX = '/&([A-Za-z0-9\x80-\xff]+); |&\#([0-9]+); |&\#[xX]([0-9A-Fa-f]+); @@ -335,7 +335,7 @@ class Sanitizer { $attribFirst = '[:A-Z_a-z0-9]'; $attrib = '[:A-Z_a-z-.0-9]'; $space = '[\x09\x0a\x0d\x20]'; - self::$attribsRegex = + self::$attribsRegex = "/(?:^|$space)({$attribFirst}{$attrib}*) ($space*=$space* (?: @@ -465,8 +465,14 @@ class Sanitizer { if ( $t != $ot ) { # No match. Push the optional elements back again $badtag = true; - while ( $ot = @array_pop( $optstack ) ) { + wfSuppressWarnings(); + $ot = array_pop( $optstack ); + wfRestoreWarnings(); + while ( $ot ) { array_push( $tagstack, $ot ); + wfSuppressWarnings(); + $ot = array_pop( $optstack ); + wfRestoreWarnings(); } } } else { @@ -608,7 +614,7 @@ class Sanitizer { * This does not validate properties, so you should ensure that you call * validateTagAttributes AFTER this to ensure that the resulting style rule * this may add is safe. - * + * * - Converts most presentational attributes like align into inline css * * @param $attribs Array @@ -617,19 +623,19 @@ class Sanitizer { */ static function fixDeprecatedAttributes( $attribs, $element ) { global $wgHtml5, $wgCleanupPresentationalAttributes; - + // presentational attributes were removed from html5, we can leave them // in when html5 is turned off if ( !$wgHtml5 || !$wgCleanupPresentationalAttributes ) { return $attribs; } - + $table = array( 'table' ); $cells = array( 'td', 'th' ); $colls = array( 'col', 'colgroup' ); $tblocks = array( 'tbody', 'tfoot', 'thead' ); $h = array( 'h1', 'h2', 'h3', 'h4', 'h5', 'h6' ); - + $presentationalAttribs = array( 'align' => array( 'text-align', array_merge( array( 'caption', 'hr', 'div', 'p', 'tr' ), $table, $cells, $colls, $tblocks, $h ) ), 'clear' => array( 'clear', array( 'br' ) ), @@ -640,7 +646,7 @@ class Sanitizer { 'valign' => array( 'vertical-align', array_merge( $cells, $colls, $tblocks ) ), 'width' => array( 'width', array_merge( array( 'hr', 'pre' ), $table, $cells, $colls ) ), ); - + // Ensure that any upper case or mixed case attributes are converted to lowercase foreach ( $attribs as $attribute => $value ) { if ( $attribute !== strtolower( $attribute ) && array_key_exists( strtolower( $attribute ), $presentationalAttribs ) ) { @@ -648,45 +654,45 @@ class Sanitizer { unset( $attribs[$attribute] ); } } - + $style = ""; foreach ( $presentationalAttribs as $attribute => $info ) { list( $property, $elements ) = $info; - + // Skip if this attribute is not relevant to this element if ( !in_array( $element, $elements ) ) { continue; } - + // Skip if the attribute is not used if ( !array_key_exists( $attribute, $attribs ) ) { continue; } - + $value = $attribs[$attribute]; - + // For nowrap the value should be nowrap instead of whatever text is in the value if ( $attribute === 'nowrap' ) { $value = 'nowrap'; } - + // clear="all" is clear: both; in css if ( $attribute === 'clear' && strtolower( $value ) === 'all' ) { $value = 'both'; } - + // Size based properties should have px applied to them if they have no unit if ( in_array( $attribute, array( 'height', 'width', 'size' ) ) ) { if ( preg_match( '/^[\d.]+$/', $value ) ) { $value = "{$value}px"; } } - + $style .= " $property: $value;"; - + unset( $attribs[$attribute] ); } - + if ( $style ) { // Prepend our style rules so that they can be overridden by user css if ( isset($attribs['style']) ) { @@ -694,7 +700,7 @@ class Sanitizer { } $attribs['style'] = trim($style); } - + return $attribs; } @@ -766,7 +772,7 @@ class Sanitizer { } //RDFa and microdata properties allow URLs, URIs and/or CURIs. check them for sanity - if ( $attribute === 'rel' || $attribute === 'rev' || + if ( $attribute === 'rel' || $attribute === 'rev' || $attribute === 'about' || $attribute === 'property' || $attribute === 'resource' || #RDFa $attribute === 'datatype' || $attribute === 'typeof' || #RDFa $attribute === 'itemid' || $attribute === 'itemprop' || $attribute === 'itemref' || #HTML5 microdata @@ -774,7 +780,7 @@ class Sanitizer { //Paranoia. Allow "simple" values but suppress javascript if ( preg_match( self::EVIL_URI_PATTERN, $value ) ) { - continue; + continue; } } @@ -839,7 +845,7 @@ class Sanitizer { * returned string may contain character references given certain * clever input strings. These character references must * be escaped before the return value is embedded in HTML. - * + * * @param $value String * @return String */ @@ -861,7 +867,7 @@ class Sanitizer { $space = '[\\x20\\t\\r\\n\\f]'; $nl = '(?:\\n|\\r\\n|\\r|\\f)'; $backslash = '\\\\'; - $decodeRegex = "/ $backslash + $decodeRegex = "/ $backslash (?: ($nl) | # 1. Line continuation ([0-9A-Fa-f]{1,6})$space? | # 2. character number @@ -871,7 +877,7 @@ class Sanitizer { } $value = preg_replace_callback( $decodeRegex, array( __CLASS__, 'cssDecodeCallback' ), $value ); - + // Remove any comments; IE gets token splitting wrong // This must be done AFTER decoding character references and // escape sequences, because those steps can introduce comments @@ -1446,7 +1452,7 @@ class Sanitizer { if ( $wgAllowRdfaAttributes ) { #RDFa attributes as specified in section 9 of http://www.w3.org/TR/2008/REC-rdfa-syntax-20081014 $common = array_merge( $common, array( - 'about', 'property', 'resource', 'datatype', 'typeof', + 'about', 'property', 'resource', 'datatype', 'typeof', ) ); } @@ -1563,7 +1569,7 @@ class Sanitizer { 'th' => array_merge( $common, $tablecell, $tablealign ), # 12.2 # NOTE: is not allowed directly, but the attrib whitelist is used from the Parser object - 'a' => array_merge( $common, array( 'href', 'rel', 'rev' ) ), # rel/rev esp. for RDFa + 'a' => array_merge( $common, array( 'href', 'rel', 'rev' ) ), # rel/rev esp. for RDFa # 13.2 # Not usually allowed, but may be used for extension-style hooks @@ -1654,7 +1660,7 @@ class Sanitizer { $url = Sanitizer::decodeCharReferences( $url ); # Escape any control characters introduced by the above step - $url = preg_replace_callback( '/[\][<>"\\x00-\\x20\\x7F\|]/', + $url = preg_replace_callback( '/[\][<>"\\x00-\\x20\\x7F\|]/', array( __CLASS__, 'cleanUrlCallback' ), $url ); # Validate hostname portion diff --git a/includes/Title.php b/includes/Title.php index 84a88e3b0d..858f931db0 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -2552,7 +2552,7 @@ class Title { */ public function invalidateCache() { if ( wfReadOnly() ) { - return; + return false; } $dbw = wfGetDB( DB_MASTER ); $success = $dbw->update( diff --git a/includes/installer/Ibm_db2Installer.php b/includes/installer/Ibm_db2Installer.php index 78e607fb1e..46ddeef844 100644 --- a/includes/installer/Ibm_db2Installer.php +++ b/includes/installer/Ibm_db2Installer.php @@ -216,12 +216,13 @@ class Ibm_db2Installer extends DatabaseInstaller { $result = $this->db->query( 'SELECT PAGESIZE FROM SYSCAT.TABLESPACES' ); if( $result == false ) { $status->fatal( 'config-connection-error', '' ); - } - else { - while ( $row = $this->db->fetchRow( $result ) ) { + } else { + $row = $this->db->fetchRow( $result ); + while ( $row ) { if( $row[0] >= 32768 ) { return $status; } + $row = $this->db->fetchRow( $result ); } $status->fatal( 'config-ibm_db2-low-db-pagesize', '' ); } diff --git a/includes/objectcache/DBABagOStuff.php b/includes/objectcache/DBABagOStuff.php index 783cd22b38..1ecc0deca8 100644 --- a/includes/objectcache/DBABagOStuff.php +++ b/includes/objectcache/DBABagOStuff.php @@ -184,8 +184,10 @@ class DBABagOStuff extends BagOStuff { $result[] = $k1; - while ( $key = dba_nextkey( $reader ) ) { + $key = dba_nextkey( $reader ); + while ( $key ) { $result[] = $key; + $key = dba_nextkey( $reader ) } return $result; diff --git a/includes/search/SearchUpdate.php b/includes/search/SearchUpdate.php index 30e6a13ed8..613e659730 100644 --- a/includes/search/SearchUpdate.php +++ b/includes/search/SearchUpdate.php @@ -37,7 +37,7 @@ class SearchUpdate implements DeferrableUpdate { global $wgContLang, $wgDisableSearchUpdate; if( $wgDisableSearchUpdate || !$this->mId ) { - return false; + return; } wfProfileIn( __METHOD__ ); diff --git a/includes/specials/SpecialSearch.php b/includes/specials/SpecialSearch.php index 6853ccd04b..bdd7681a35 100644 --- a/includes/specials/SpecialSearch.php +++ b/includes/specials/SpecialSearch.php @@ -35,7 +35,7 @@ class SpecialSearch extends SpecialPage { * string when applicable. Extensions can add new profiles with hooks * with custom search options just for that profile. * null|string - */ + */ protected $profile; /// Search engine @@ -497,8 +497,10 @@ class SpecialSearch extends SpecialPage { $out .= "\n\n"; } $out .= "\n"; @@ -717,9 +719,11 @@ class SpecialSearch extends SpecialPage { } $prev = null; - while( $result = $matches->next() ) { + $result = $matches->next(); + while( $result ) { $out .= $this->showInterwikiHit( $result, $prev, $terms, $query, $customCaptions ); $prev = $result->getInterwikiPrefix(); + $result = $matches->next(); } // TODO: should support paging in a non-confusing way (not sure how though, maybe via ajax).. $out .= "\n"; diff --git a/languages/Language.php b/languages/Language.php index 6059e28c11..7a98df502b 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -3685,7 +3685,7 @@ class Language { $format['noabbrevs'] ? 'hours' : 'hours-abbrev' )->inLanguage( $this ); $daysMsg = wfMessage( $format['noabbrevs'] ? 'days' : 'days-abbrev' )->inLanguage( $this ); - + if ( round( $seconds * 10 ) < 100 ) { $s = $this->formatNum( sprintf( "%.1f", round( $seconds * 10 ) / 10 ) ); $s = $secondsMsg->params( $s )->text(); diff --git a/maintenance/benchmarks/benchmarkHooks.php b/maintenance/benchmarks/benchmarkHooks.php index 90e5908b87..ec11c2f8bd 100644 --- a/maintenance/benchmarks/benchmarkHooks.php +++ b/maintenance/benchmarks/benchmarkHooks.php @@ -49,7 +49,7 @@ class BenchmarkHooks extends Benchmarker { $wgHooks['Test'][] = array( $this, 'test' ); } $time = $this->benchHooks(); - $this->output( 'Loaded (ten) hook: ' . $time . "\n" ); + $this->output( 'Loaded (one hundred) hook: ' . $time . "\n" ); $this->output( "\n" ); } diff --git a/maintenance/storage/checkStorage.php b/maintenance/storage/checkStorage.php index 7bd0371cc6..bc47f9587a 100644 --- a/maintenance/storage/checkStorage.php +++ b/maintenance/storage/checkStorage.php @@ -99,6 +99,9 @@ class CheckStorage { $res = $dbr->select( 'text', array( 'old_id', 'old_flags' ), 'old_id IN (' . implode( ',', $this->oldIdMap ) . ')', __METHOD__ ); foreach ( $res as $row ) { + /** + * @var $flags int + */ $flags = $row->old_flags; $id = $row->old_id; diff --git a/tests/phpunit/includes/search/SearchEngineTest.php b/tests/phpunit/includes/search/SearchEngineTest.php index 1a0fcd311b..2cbb900789 100644 --- a/tests/phpunit/includes/search/SearchEngineTest.php +++ b/tests/phpunit/includes/search/SearchEngineTest.php @@ -64,8 +64,10 @@ class SearchEngineTest extends MediaWikiTestCase { $this->assertTrue( is_object( $results ) ); $matches = array(); - while ( $row = $results->next() ) { + $row = $results->next(); + while ( $row ) { $matches[] = $row->getTitle()->getPrefixedText(); + $row = $results->next(); } $results->free(); # Search is not guaranteed to return results in a certain order; diff --git a/tests/phpunit/includes/upload/UploadFromUrlTest.php b/tests/phpunit/includes/upload/UploadFromUrlTest.php index 4722d40846..164beee088 100644 --- a/tests/phpunit/includes/upload/UploadFromUrlTest.php +++ b/tests/phpunit/includes/upload/UploadFromUrlTest.php @@ -36,7 +36,10 @@ class UploadFromUrlTest extends ApiTestCase { * Ensure that the job queue is empty before continuing */ public function testClearQueue() { - while ( $job = Job::pop() ) { } + $job = Job::pop(); + while ( $job ) { + $job = Job::pop(); + } $this->assertFalse( $job ); } -- 2.20.1