bug 25517 Assignment in conditions should be avoided/ http://www.mediawiki.org/wiki...
authorSam Reed <reedy@users.mediawiki.org>
Mon, 1 Nov 2010 00:07:17 +0000 (00:07 +0000)
committerSam Reed <reedy@users.mediawiki.org>
Mon, 1 Nov 2010 00:07:17 +0000 (00:07 +0000)
26 files changed:
includes/Article.php
includes/ChangeTags.php
includes/EditPage.php
includes/Exception.php
includes/Metadata.php
includes/SkinTemplate.php
includes/Title.php
includes/Wiki.php
includes/db/DatabaseMssql.php
includes/diff/DifferenceEngine.php
includes/filerepo/File.php
includes/filerepo/ForeignAPIRepo.php
includes/normal/UtfNormal.php
includes/resourceloader/ResourceLoaderWikiModule.php
includes/specials/SpecialAllpages.php
includes/specials/SpecialExport.php
includes/specials/SpecialNewimages.php
includes/specials/SpecialRecentchangeslinked.php
includes/specials/SpecialVersion.php
maintenance/checkSyntax.php
maintenance/findhooks.php
maintenance/importImages.inc
maintenance/namespaceDupes.php
maintenance/rebuildrecentchanges.php
skins/Standard.php
skins/Vector.php

index c2ac338..53abef0 100644 (file)
@@ -984,15 +984,18 @@ class Article {
                                                wfDebug( __METHOD__ . ": showing CSS/JS source\n" );
                                                $this->showCssOrJsPage();
                                                $outputDone = true;
-                                       } else if ( $rt = Title::newFromRedirectArray( $text ) ) {
-                                               wfDebug( __METHOD__ . ": showing redirect=no page\n" );
-                                               # Viewing a redirect page (e.g. with parameter redirect=no)
-                                               # Don't append the subtitle if this was an old revision
-                                               $wgOut->addHTML( $this->viewRedirect( $rt, !$wasRedirected && $this->isCurrent() ) );
-                                               # Parse just to get categories, displaytitle, etc.
-                                               $this->mParserOutput = $wgParser->parse( $text, $this->mTitle, $parserOptions );
-                                               $wgOut->addParserOutputNoText( $this->mParserOutput );
-                                               $outputDone = true;
+                                       } else {
+                                               $rt = Title::newFromRedirectArray( $text );
+                                               if ( $rt ) {
+                                                       wfDebug( __METHOD__ . ": showing redirect=no page\n" );
+                                                       # Viewing a redirect page (e.g. with parameter redirect=no)
+                                                       # Don't append the subtitle if this was an old revision
+                                                       $wgOut->addHTML( $this->viewRedirect( $rt, !$wasRedirected && $this->isCurrent() ) );
+                                                       # Parse just to get categories, displaytitle, etc.
+                                                       $this->mParserOutput = $wgParser->parse( $text, $this->mTitle, $parserOptions );
+                                                       $wgOut->addParserOutputNoText( $this->mParserOutput );
+                                                       $outputDone = true;
+                                               }
                                        }
                                        break;
                                case 4:
index 4d433d4..4a1ad80 100644 (file)
@@ -180,8 +180,8 @@ class ChangeTags {
                // Caching...
                global $wgMemc;
                $key = wfMemcKey( 'valid-tags' );
-
-               if ( $tags = $wgMemc->get( $key ) ) {
+               $tags = $wgMemc->get( $key );
+               if ( $tags ) {
                        return $tags;
                }
 
index 386dc80..2150656 100644 (file)
@@ -1867,38 +1867,40 @@ HTML
                        $parserOptions->setTidy( true );
                        $parserOutput = $wgParser->parse( $previewtext, $this->mTitle, $parserOptions );
                        $previewHTML = $parserOutput->mText;
-               } elseif ( $rt = Title::newFromRedirectArray( $this->textbox1 ) ) {
-                       $previewHTML = $this->mArticle->viewRedirect( $rt, false );
                } else {
-                       $toparse = $this->textbox1;
+                       $rt = Title::newFromRedirectArray( $this->textbox1 );
+                       if ( $rt ) {
+                               $previewHTML = $this->mArticle->viewRedirect( $rt, false );
+                       } else {
+                               $toparse = $this->textbox1;
 
-                       # If we're adding a comment, we need to show the
-                       # summary as the headline
-                       if ( $this->section == "new" && $this->summary != "" ) {
-                               $toparse = "== {$this->summary} ==\n\n" . $toparse;
-                       }
+                               # If we're adding a comment, we need to show the
+                               # summary as the headline
+                               if ( $this->section == "new" && $this->summary != "" ) {
+                                       $toparse = "== {$this->summary} ==\n\n" . $toparse;
+                               }
 
-                       wfRunHooks( 'EditPageGetPreviewText', array( $this, &$toparse ) );
-
-                       // Parse mediawiki messages with correct target language
-                       if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
-                               list( /* $unused */, $lang ) = $wgMessageCache->figureMessage( $this->mTitle->getText() );
-                               $obj = wfGetLangObj( $lang );
-                               $parserOptions->setTargetLanguage( $obj );
-                       }
+                               wfRunHooks( 'EditPageGetPreviewText', array( $this, &$toparse ) );
 
+                               // Parse mediawiki messages with correct target language
+                               if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
+                                       list( /* $unused */, $lang ) = $wgMessageCache->figureMessage( $this->mTitle->getText() );
+                                       $obj = wfGetLangObj( $lang );
+                                       $parserOptions->setTargetLanguage( $obj );
+                               }
 
-                       $parserOptions->setTidy( true );
-                       $parserOptions->enableLimitReport();
-                       $parserOutput = $wgParser->parse( $this->mArticle->preSaveTransform( $toparse ),
+                               $parserOptions->setTidy( true );
+                               $parserOptions->enableLimitReport();
+                               $parserOutput = $wgParser->parse( $this->mArticle->preSaveTransform( $toparse ),
                                        $this->mTitle, $parserOptions );
 
-                       $previewHTML = $parserOutput->getText();
-                       $this->mParserOutput = $parserOutput;
-                       $wgOut->addParserOutputNoText( $parserOutput );
+                               $previewHTML = $parserOutput->getText();
+                               $this->mParserOutput = $parserOutput;
+                               $wgOut->addParserOutputNoText( $parserOutput );
 
-                       if ( count( $parserOutput->getWarnings() ) ) {
-                               $note .= "\n\n" . implode( "\n\n", $parserOutput->getWarnings() );
+                               if ( count( $parserOutput->getWarnings() ) ) {
+                                       $note .= "\n\n" . implode( "\n\n", $parserOutput->getWarnings() );
+                               }
                        }
                }
 
index a5e86cd..ac336bf 100644 (file)
@@ -179,7 +179,8 @@ class MWException extends Exception {
                        $wgOut->redirect( '' );
                        $wgOut->clearHTML();
 
-                       if ( $hookResult = $this->runHooks( get_class( $this ) ) ) {
+                       $hookResult = $this->runHooks( get_class( $this ) );
+                       if ( $hookResult ) {
                                $wgOut->addHTML( $hookResult );
                        } else {
                                $wgOut->addHTML( $this->getHTML() );
@@ -187,7 +188,8 @@ class MWException extends Exception {
 
                        $wgOut->output();
                } else {
-                       if ( $hookResult = $this->runHooks( get_class( $this ) . "Raw" ) ) {
+                       $hookResult = $this->runHooks( get_class( $this ) . "Raw" );
+                       if ( $hookResult ) {
                                die( $hookResult );
                        }
 
index 508afb6..aff103f 100644 (file)
@@ -119,11 +119,14 @@ abstract class RdfMetaData {
        protected function person($name, User $user ){
                if( $user->isAnon() ){
                        $this->element( $name, wfMsgExt( 'anonymous', array( 'parsemag' ), 1 ) );
-               } else if( $real = $user->getRealName() ) {
-                       $this->element( $name, $real );
                } else {
-                       $userName = $user->getName();
-                       $this->pageOrString( $name, $user->getUserPage(), wfMsgExt( 'siteuser', 'parsemag', $userName, $userName ) );
+                       $real = $user->getRealName();
+                       if( $real ) {
+                               $this->element( $name, $real );
+                       } else {
+                               $userName = $user->getName();
+                               $this->pageOrString( $name, $user->getUserPage(), wfMsgExt( 'siteuser', 'parsemag', $userName, $userName ) );
+                       }
                }
        }
 
index b2cfd0c..360918f 100644 (file)
@@ -793,7 +793,8 @@ class SkinTemplate extends Skin {
                        } else {
                                //article doesn't exist or is deleted
                                if( $wgUser->isAllowed( 'deletedhistory' ) && $wgUser->isAllowed( 'deletedtext' ) ) {
-                                       if( $n = $this->mTitle->isDeleted() ) {
+                                       $n = $this->mTitle->isDeleted();
+                                       if( $n ) {
                                                $undelTitle = SpecialPage::getTitleFor( 'Undelete' );
                                                $content_actions['undelete'] = array(
                                                        'class' => false,
index cec0067..02bf964 100644 (file)
@@ -2794,7 +2794,8 @@ class Title {
                $retVal = array();
                if ( $db->numRows( $res ) ) {
                        foreach ( $res as $row ) {
-                               if ( $titleObj = Title::makeTitle( $row->page_namespace, $row->page_title ) ) {
+                               $titleObj = Title::makeTitle( $row->page_namespace, $row->page_title )
+                               if ( $titleObj ) {
                                        $linkCache->addGoodLinkObj( $row->page_id, $titleObj, $row->page_len, $row->page_is_redirect, $row->page_latest );
                                        $retVal[] = $titleObj;
                                }
index aaced48..c31a6ab 100644 (file)
@@ -108,8 +108,8 @@ class MediaWiki {
                if( $wgRequest->getVal( 'printable' ) === 'yes' ) {
                        $wgOut->setPrintable();
                }
-
-               if( $curid = $wgRequest->getInt( 'curid' ) ) {
+               $curid = $wgRequest->getInt( 'curid' );
+               if( $curid ) {
                        // URLs like this are generated by RC, because rc_title isn't always accurate
                        $ret = Title::newFromID( $curid );
                } elseif( $title == '' && $action != 'delete' ) {
@@ -191,7 +191,8 @@ class MediaWiki {
 
                // Interwiki redirects
                } else if( $title->getInterwiki() != '' ) {
-                       if( $rdfrom = $request->getVal( 'rdfrom' ) ) {
+                       $rdfrom = $request->getVal( 'rdfrom' );
+                       if( $rdfrom ) {
                                $url = $title->getFullURL( 'rdfrom=' . urlencode( $rdfrom ) );
                        } else {
                                $query = $request->getValues();
index 9c9bbd1..0087e74 100644 (file)
@@ -780,7 +780,8 @@ class DatabaseMssql extends DatabaseBase {
                        print( "Error in fieldInfo query: " . $this->getErrors() );
                        return false;
                }
-               if ( $meta = $this->fetchRow( $res ) ) {
+               $meta = $this->fetchRow( $res );
+               if ( $meta ) {
                        return new MssqlField( $meta );
                }
                return false;
index 512f3fb..f46705c 100644 (file)
@@ -308,8 +308,9 @@ class _DiffEngine {
                        $x1 = $xoff + (int)(($numer + ($xlim-$xoff)*$chunk) / $nchunks);
                        for ( ; $x < $x1; $x++) {
                                $line = $flip ? $this->yv[$x] : $this->xv[$x];
-                               if (empty($ymatches[$line]))
-                               continue;
+                               if (empty($ymatches[$line])) {
+                                       continue;
+                               }
                                $matches = $ymatches[$line];
                                reset($matches);
                                while ( list( $junk, $y ) = each( $matches ) ) {
index 063fb16..28929b7 100644 (file)
@@ -906,7 +906,8 @@ abstract class File {
                $retVal = array();
                if ( $db->numRows( $res ) ) {
                        foreach ( $res as $row ) {
-                               if ( $titleObj = Title::newFromRow( $row ) ) {
+                               $titleObj = Title::newFromRow( $row )
+                               if ( $titleObj ) {
                                        $linkCache->addGoodLinkObj( $row->page_id, $titleObj, $row->page_len, $row->page_is_redirect, $row->page_latest );
                                        $retVal[] = $titleObj;
                                }
index c75d15e..f6b21ee 100644 (file)
@@ -201,7 +201,8 @@ class ForeignAPIRepo extends FileRepo {
                }
 
                $key = $this->getLocalCacheKey( 'ForeignAPIRepo', 'ThumbUrl', $name );
-               if ( $thumbUrl = $wgMemc->get($key) ) {
+               $thumbUrl = $wgMemc->get($key);
+               if ( $thumbUrl ) {
                        wfDebug("Got thumb from local cache. $thumbUrl \n");
                        return $thumbUrl;
                }
index 1d94d72..8390d08 100644 (file)
@@ -308,7 +308,8 @@ class UtfNormal {
                        $len = $chunk + 1; # Counting down is faster. I'm *so* sorry.
 
                        for( $i = -1; --$len; ) {
-                               if( $remaining = $tailBytes[$c = $str{++$i}] ) {
+                               $remaining = $tailBytes[$c = $str{++$i}]
+                               if( $remaining ) {
                                        # UTF-8 head byte!
                                        $sequence = $head = $c;
                                        do {
index f0e4231..a395cf0 100644 (file)
@@ -45,7 +45,8 @@ abstract class ResourceLoaderWikiModule extends ResourceLoaderModule {
                if ( $ns === NS_MEDIAWIKI ) {
                        return wfEmptyMsg( $page ) ? '' : wfMsgExt( $page, 'content' );
                }
-               if ( $title = Title::newFromText( $page, $ns ) ) {
+               $title = Title::newFromText( $page, $ns );
+               if ( $title ) {
                        if ( $title->isValidCssJsSubpage() && $revision = Revision::newFromTitle( $title ) ) {
                                return $revision->getRawText();
                        }
@@ -59,7 +60,8 @@ abstract class ResourceLoaderWikiModule extends ResourceLoaderModule {
                $scripts = '';
                foreach ( $this->getPages( $context ) as $page => $options ) {
                        if ( $options['type'] === 'script' ) {
-                               if ( $script = $this->getContent( $page, $options['ns'] ) ) {
+                               $script = $this->getContent( $page, $options['ns'] );
+                               if ( $script ) {
                                        $ns = MWNamespace::getCanonicalName( $options['ns'] );
                                        $scripts .= "/*$ns:$page */\n$script\n";
                                }
@@ -74,7 +76,8 @@ abstract class ResourceLoaderWikiModule extends ResourceLoaderModule {
                foreach ( $this->getPages( $context ) as $page => $options ) {
                        if ( $options['type'] === 'style' ) {
                                $media = isset( $options['media'] ) ? $options['media'] : 'all';
-                               if ( $style = $this->getContent( $page, $options['ns'] ) ) {
+                               $style = $this->getContent( $page, $options['ns'] );
+                               if ( $style ) {
                                        if ( !isset( $styles[$media] ) ) {
                                                $styles[$media] = '';
                                        }
index e0fbe02..487d44d 100644 (file)
@@ -188,7 +188,8 @@ class SpecialAllpages extends IncludableSpecialPage {
                                        array ('LIMIT' => 2, 'OFFSET' => $maxPerSubpage - 1, 'ORDER BY' => 'page_title ASC')
                                );
 
-                               if( $s = $dbr->fetchObject( $res ) ) {
+                               $s = $dbr->fetchObject( $res );
+                               if( $s ) {
                                        array_push( $lines, $s->page_title );
                                } else {
                                        // Final chunk, but ended prematurely. Go back and find the end.
@@ -198,7 +199,8 @@ class SpecialAllpages extends IncludableSpecialPage {
                                        array_push( $lines, $endTitle );
                                        $done = true;
                                }
-                               if( $s = $res->fetchObject() ) {
+                               $s = $res->fetchObject();
+                               if( $s ) {
                                        array_push( $lines, $s->page_title );
                                        $lastTitle = $s->page_title;
                                } else {
index 5f56bef..eaed239 100644 (file)
@@ -229,8 +229,8 @@ class SpecialExport extends SpecialPage {
                if( $this->templates ) {
                        $pageSet = $this->getTemplates( $inputPages, $pageSet );
                }
-
-               if( $linkDepth = $this->pageLinkDepth ) {
+               $linkDepth = $this->pageLinkDepth;
+               if( $linkDepth ) {
                        $pageSet = $this->getPageLinks( $inputPages, $pageSet, $linkDepth );
                }
 
index 5962215..cecd7df 100644 (file)
@@ -74,8 +74,8 @@ function wfSpecialNewimages( $par, $specialPage ) {
 
        # Hardcode this for now.
        $limit = 48;
-
-       if ( $parval = intval( $par ) ) {
+       $parval = intval( $par );
+       if ( $parval ) {
                if ( $parval <= $limit && $parval > 0 ) {
                        $limit = $parval;
                }
@@ -92,10 +92,12 @@ function wfSpecialNewimages( $par, $specialPage ) {
        }
 
        $invertSort = false;
-       if( $until = $wgRequest->getVal( 'until' ) ) {
+       $until = $wgRequest->getVal( 'until' );
+       if( $until ) {
                $where[] = "img_timestamp < '" . $dbr->timestamp( $until ) . "'";
        }
-       if( $from = $wgRequest->getVal( 'from' ) ) {
+       $from = $wgRequest->getVal( 'from' );
+       if( $from ) {
                $where[] = "img_timestamp >= '" . $dbr->timestamp( $from ) . "'";
                $invertSort = true;
        }
index b929a79..db0f554 100644 (file)
@@ -99,7 +99,8 @@ class SpecialRecentchangeslinked extends SpecialRecentChanges {
                $query_options = array();
 
                // left join with watchlist table to highlight watched rows
-               if( $uid = $wgUser->getId() ) {
+               $uid = $wgUser->getId();
+               if( $uid ) {
                        $tables[] = 'watchlist';
                        $select[] = 'wl_user';
                        $join_conds['watchlist'] = array( 'LEFT JOIN', "wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace" );
index 700d10f..a62c248 100644 (file)
@@ -293,7 +293,10 @@ class SpecialVersion extends SpecialPage {
                        $out .= '<tr><td colspan="4">' . $this->listToText( $wgExtensionFunctions ) . "</td></tr>\n";
                }
 
-               if ( $cnt = count( $tags = $wgParser->getTags() ) ) {
+               $tags = $wgParser->getTags();
+               $cnt = count( $tags );
+
+               if ( $cnt ) {
                        for ( $i = 0; $i < $cnt; ++$i ) {
                                $tags[$i] = "&lt;{$tags[$i]}&gt;";
                        }
index c0966ae..53e4209 100644 (file)
@@ -105,7 +105,8 @@ class CheckSyntax extends Maintenance {
                        if ( !$f ) {
                                $this->error( "Can't open file $file\n", true );
                        }
-                       while ( $path = trim( fgets( $f ) ) ) {
+                       $path = trim( fgets( $f ) );
+                       while ( $path ) {
                                $this->addPath( $path );
                        }
                        fclose( $f );
@@ -113,6 +114,7 @@ class CheckSyntax extends Maintenance {
                } elseif ( $this->hasOption( 'modified' ) ) {
                        $this->output( "Retrieving list from Subversion... " );
                        $parentDir = wfEscapeShellArg( dirname( __FILE__ ) . '/..' );
+                       $retval = null;
                        $output = wfShellExec( "svn status --ignore-externals $parentDir", $retval );
                        if ( $retval ) {
                                $this->error( "Error retrieving list from Subversion!\n", true );
index cca1b70..431f50d 100644 (file)
@@ -145,7 +145,8 @@ class FindHooks extends Maintenance {
         */
        private function getHooksFromPath( $path ) {
                $hooks = array();
-               if ( $dh = opendir( $path ) ) {
+               $dh = opendir( $path );
+               if ( $dh ) {
                        while ( ( $file = readdir( $dh ) ) !== false ) {
                                if ( filetype( $path . $file ) == 'file' ) {
                                        $hooks = array_merge( $hooks, $this->getHooksFromFile( $path . $file ) );
@@ -180,7 +181,8 @@ class FindHooks extends Maintenance {
         */
        private function getBadHooksFromPath( $path ) {
                $hooks = array();
-               if ( $dh = opendir( $path ) ) {
+               $dh = opendir( $path );
+               if ( $dh ) {
                        while ( ( $file = readdir( $dh ) ) !== false ) {
                                # We don't want to read this file as it contains bad calls to wfRunHooks()
                                if ( filetype( $path . $file ) == 'file' && !$path . $file == __FILE__ ) {
index 29a7fbc..e0001f9 100644 (file)
@@ -18,7 +18,8 @@
  */
 function findFiles( $dir, $exts ) {
        if ( is_dir( $dir ) ) {
-               if ( $dhl = opendir( $dir ) ) {
+               $dhl = opendir( $dir );
+               if ( $dhl ) {
                        $files = array();
                        while ( ( $file = readdir( $dhl ) ) !== false ) {
                                if ( is_file( $dir . '/' . $file ) ) {
index 13dfd9f..ce12f61 100644 (file)
@@ -263,11 +263,12 @@ class NamespaceConflictChecker extends Maintenance {
                                $row->title .= $suffix;
                                $this->output( "...  *** new title {$row->title}\n" );
                                $title = Title::makeTitleSafe( $row->namespace, $row->title );
-                               if ( ! $title ) {
+                               if ( !$title ) {
                                        $this->output( "... !!! invalid title\n" );
                                        return false;
                                }
-                               if ( $id = $title->getArticleId() ) {
+                               $id = $title->getArticleId();
+                               if ( $id ) {
                                        $this->output( "...  *** page exists with ID $id ***\n" );
                                } else {
                                        break;
index 2b96645..357718b 100644 (file)
@@ -119,7 +119,8 @@ class RebuildRecentchanges extends Maintenance {
                                        "AND rev_timestamp<'{$emit}' ORDER BY rev_timestamp DESC";
                                $sql2 = $dbw->limitResult( $sql2, 1, false );
                                $res2 = $dbw->query( $sql2 );
-                               if ( $row = $dbw->fetchObject( $res2 ) ) {
+                               $row = $dbw->fetchObject( $res2 );
+                               if ( $row ) {
                                        $lastOldId = intval( $row->rev_id );
                                        # Grab the last text size if available
                                        $lastSize = !is_null( $row->rev_len ) ? intval( $row->rev_len ) : 'NULL';
index f9309fa..e9920dc 100644 (file)
@@ -186,7 +186,8 @@ class SkinStandard extends Skin {
                                        }
 
                                        $link = $this->mTitle->getText();
-                                       if( $nstext = $wgContLang->getNsText( $tns ) ) { # add namespace if necessary
+                                       $nstext = $wgContLang->getNsText( $tns );
+                                       if( $nstext ) { # add namespace if necessary
                                                $link = $nstext . ':' . $link;
                                        }
 
index 679d244..479d06d 100644 (file)
@@ -226,7 +226,8 @@ class SkinVector extends SkinTemplate {
                                        $wgUser->isAllowed( 'deletedhistory' ) &&
                                        $wgUser->isAllowed( 'undelete' )
                                ) {
-                                       if( $n = $this->mTitle->isDeleted() ) {
+                                       $n = $this->mTitle->isDeleted();
+                                       if( $n ) {
                                                $undelTitle = SpecialPage::getTitleFor( 'Undelete' );
                                                $links['actions']['undelete'] = array(
                                                        'class' => false,