Merge "PHP: Use short ternary operator (?:) where possible"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Mon, 11 Jun 2018 23:06:59 +0000 (23:06 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 11 Jun 2018 23:06:59 +0000 (23:06 +0000)
22 files changed:
includes/AjaxResponse.php
includes/EditPage.php
includes/MediaWiki.php
includes/OutputPage.php
includes/Setup.php
includes/cache/GenderCache.php
includes/changetags/ChangeTags.php
includes/filerepo/RepoGroup.php
includes/libs/jsminplus.php
includes/libs/lockmanager/DBLockManager.php
includes/libs/mime/IEContentAnalyzer.php
includes/parser/Parser.php
includes/specials/SpecialEmailuser.php
includes/specials/SpecialMIMEsearch.php
includes/specials/SpecialPageLanguage.php
includes/specials/SpecialVersion.php
includes/specials/pagers/AllMessagesTablePager.php
includes/upload/UploadBase.php
maintenance/storage/checkStorage.php
profileinfo.php
tests/parser/DjVuSupport.php
tests/phpunit/includes/Storage/RevisionStoreTest.php

index 3e42c08..0c11505 100644 (file)
@@ -242,7 +242,7 @@ class AjaxResponse {
                        # this breaks strtotime().
                        $modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
                        $modsinceTime = strtotime( $modsince );
-                       $ismodsince = wfTimestamp( TS_MW, $modsinceTime ? $modsinceTime : 1 );
+                       $ismodsince = wfTimestamp( TS_MW, $modsinceTime ?: 1 );
                        wfDebug( "$fname: -- client send If-Modified-Since: $modsince", 'private' );
                        wfDebug( "$fname: --  we might send Last-Modified : $lastmod", 'private' );
 
index 22c29d6..581a28f 100644 (file)
@@ -2812,7 +2812,7 @@ ERROR;
                        $this->autoSumm = md5( '' );
                }
 
-               $autosumm = $this->autoSumm ? $this->autoSumm : md5( $this->summary );
+               $autosumm = $this->autoSumm ?: md5( $this->summary );
                $out->addHTML( Html::hidden( 'wpAutoSummary', $autosumm ) );
 
                $out->addHTML( Html::hidden( 'oldid', $this->oldid ) );
index 7978727..72b1090 100644 (file)
@@ -104,7 +104,7 @@ class MediaWiki {
                if ( $ret === null || !$ret->isSpecialPage() ) {
                        // We can have urls with just ?diff=,?oldid= or even just ?diff=
                        $oldid = $request->getInt( 'oldid' );
-                       $oldid = $oldid ? $oldid : $request->getInt( 'diff' );
+                       $oldid = $oldid ?: $request->getInt( 'diff' );
                        // Allow oldid to override a changed or missing title
                        if ( $oldid ) {
                                $rev = Revision::newFromId( $oldid );
@@ -426,7 +426,7 @@ class MediaWiki {
                        // If $target is set, then a hook wanted to redirect.
                        if ( !$ignoreRedirect && ( $target || $page->isRedirect() ) ) {
                                // Is the target already set by an extension?
-                               $target = $target ? $target : $page->followRedirect();
+                               $target = $target ?: $page->followRedirect();
                                if ( is_string( $target ) ) {
                                        if ( !$this->config->get( 'DisableHardRedirects' ) ) {
                                                // we'll need to redirect
index 6700cdb..50cc991 100644 (file)
@@ -3111,13 +3111,13 @@ class OutputPage extends ContextSource {
 
                // Pre-process information
                $separatorTransTable = $lang->separatorTransformTable();
-               $separatorTransTable = $separatorTransTable ? $separatorTransTable : [];
+               $separatorTransTable = $separatorTransTable ?: [];
                $compactSeparatorTransTable = [
                        implode( "\t", array_keys( $separatorTransTable ) ),
                        implode( "\t", $separatorTransTable ),
                ];
                $digitTransTable = $lang->digitTransformTable();
-               $digitTransTable = $digitTransTable ? $digitTransTable : [];
+               $digitTransTable = $digitTransTable ?: [];
                $compactDigitTransTable = [
                        implode( "\t", array_keys( $digitTransTable ) ),
                        implode( "\t", $digitTransTable ),
index e2fab45..41d5945 100644 (file)
@@ -825,7 +825,7 @@ $wgInitialSessionId = null;
 if ( !defined( 'MW_NO_SESSION' ) && !$wgCommandLineMode ) {
        // If session.auto_start is there, we can't touch session name
        if ( $wgPHPSessionHandling !== 'disable' && !wfIniGetBool( 'session.auto_start' ) ) {
-               session_name( $wgSessionName ? $wgSessionName : $wgCookiePrefix . '_session' );
+               session_name( $wgSessionName ?: $wgCookiePrefix . '_session' );
        }
 
        // Create the SessionManager singleton and set up our session handler,
index 1ec39a5..7228814 100644 (file)
@@ -171,7 +171,7 @@ class GenderCache {
                $res = $dbr->select( $table, $fields, $conds, $comment, [], $joins );
 
                foreach ( $res as $row ) {
-                       $this->cache[$row->user_name] = $row->up_value ? $row->up_value : $default;
+                       $this->cache[$row->user_name] = $row->up_value ?: $default;
                }
        }
 
index 09d1b81..d019f41 100644 (file)
@@ -466,7 +466,7 @@ class ChangeTags {
                // $prevTags can be out of date on replica DBs, especially when addTags is called consecutively,
                // causing loss of tags added recently in tag_summary table.
                $prevTags = $dbw->selectField( 'tag_summary', 'ts_tags', $tsConds, __METHOD__ );
-               $prevTags = $prevTags ? $prevTags : '';
+               $prevTags = $prevTags ?: '';
                $prevTags = array_filter( explode( ',', $prevTags ) );
 
                // add tags
index 7dd8b25..89287af 100644 (file)
@@ -163,7 +163,7 @@ class RepoGroup {
                        }
                }
 
-               $image = $image ? $image : false; // type sanity
+               $image = $image ?: false; // type sanity
                # Cache file existence or non-existence
                if ( $useCache && ( !$image || $image->isCacheable() ) ) {
                        $this->cache->set( $dbkey, $time, $image );
index e3c2d75..08e9d69 100644 (file)
@@ -909,7 +909,7 @@ class JSParser
                                }
                                else
                                {
-                                       $n->setup = $n2 ? $n2 : null;
+                                       $n->setup = $n2 ?: null;
                                        $this->t->mustMatch(OP_SEMICOLON);
                                        $n->condition = $this->t->peek() == OP_SEMICOLON ? null : $this->Expression($x);
                                        $this->t->mustMatch(OP_SEMICOLON);
@@ -1656,7 +1656,7 @@ class JSNode
        {
                if ($token = $t->currentToken())
                {
-                       $this->type = $type ? $type : $token->type;
+                       $this->type = $type ?: $token->type;
                        $this->value = $token->value;
                        $this->lineno = $token->lineno;
                        $this->start = $token->start;
@@ -1752,7 +1752,7 @@ class JSTokenizer
        public function init($source, $filename = '', $lineno = 1)
        {
                $this->source = $source;
-               $this->filename = $filename ? $filename : '[inline]';
+               $this->filename = $filename ?: '[inline]';
                $this->lineno = $lineno;
 
                $this->cursor = 0;
index 564616d..aec9f25 100644 (file)
@@ -82,7 +82,7 @@ abstract class DBLockManager extends QuorumLockManager {
                        $this->lockExpiry = $config['lockExpiry'];
                } else {
                        $met = ini_get( 'max_execution_time' );
-                       $this->lockExpiry = $met ? $met : 60; // use some sane amount if 0
+                       $this->lockExpiry = $met ?: 60; // use some sane amount if 0
                }
                $this->safeDelay = ( $this->lockExpiry <= 0 )
                        ? 60 // pick a safe-ish number to match DB timeout default
index e9fb11f..802ed2d 100644 (file)
@@ -500,13 +500,13 @@ class IEContentAnalyzer {
                        < ( $counters['ctrl'] + $counters['high'] ) * 16
                ) {
                        $kindOfBinary = true;
-                       $type = $binaryType ? $binaryType : $textType;
+                       $type = $binaryType ?: $textType;
                        if ( $type === false ) {
                                $type = 'application/octet-stream';
                        }
                } else {
                        $kindOfBinary = false;
-                       $type = $textType ? $textType : $binaryType;
+                       $type = $textType ?: $binaryType;
                        if ( $type === false ) {
                                $type = 'text/plain';
                        }
index 15ed93c..28e7450 100644 (file)
@@ -2641,7 +2641,7 @@ class Parser {
                                        $this->mOutput->setFlag( 'vary-revision' );
                                        wfDebug( __METHOD__ . ": {{PAGEID}} used in a new page, setting vary-revision...\n" );
                                }
-                               $value = $pageid ? $pageid : null;
+                               $value = $pageid ?: null;
                                break;
                        case 'revisionid':
                                # Let the edit saving system know we should parse the page
index f322ac4..0e93194 100644 (file)
@@ -204,7 +204,7 @@ class SpecialEmailUser extends UnlistedSpecialPage {
                $nu = User::newFromName( $target );
                $error = self::validateTarget( $nu, $sender );
 
-               return $error ? $error : $nu;
+               return $error ?: $nu;
        }
 
        /**
index a54d72d..f43ed9b 100644 (file)
@@ -160,7 +160,7 @@ class MIMEsearchPage extends QueryPage {
        }
 
        public function execute( $par ) {
-               $this->mime = $par ? $par : $this->getRequest()->getText( 'mime' );
+               $this->mime = $par ?: $this->getRequest()->getText( 'mime' );
                $this->mime = trim( $this->mime );
                list( $this->major, $this->minor ) = File::splitMime( $this->mime );
 
index e3485ff..3741272 100644 (file)
@@ -224,8 +224,8 @@ class SpecialPageLanguage extends FormSpecialPage {
                }
 
                // Hardcoded [def] if the language is set to null
-               $logOld = $oldLanguage ? $oldLanguage : $defLang . '[def]';
-               $logNew = $newLanguage ? $newLanguage : $defLang . '[def]';
+               $logOld = $oldLanguage ?: $defLang . '[def]';
+               $logNew = $newLanguage ?: $defLang . '[def]';
 
                // Writing new page language to database
                $dbw->update(
index 911c9a6..35c5689 100644 (file)
@@ -1134,7 +1134,7 @@ class SpecialVersion extends SpecialPage {
         */
        public function getEntryPointInfo() {
                global $wgArticlePath, $wgScriptPath;
-               $scriptPath = $wgScriptPath ? $wgScriptPath : "/";
+               $scriptPath = $wgScriptPath ?: "/";
                $entryPoints = [
                        'version-entrypoints-articlepath' => $wgArticlePath,
                        'version-entrypoints-scriptpath' => $scriptPath,
index e6a0f0b..35c9931 100644 (file)
@@ -58,7 +58,7 @@ class AllMessagesTablePager extends TablePager {
 
                $this->talk = $this->msg( 'talkpagelinktext' )->escaped();
 
-               $this->lang = ( $langObj ? $langObj : $wgContLang );
+               $this->lang = $langObj ?: $wgContLang;
                $this->langcode = $this->lang->getCode();
                $this->foreign = !$this->lang->equals( $wgContLang );
 
index 5352d95..87b96ac 100644 (file)
@@ -160,7 +160,7 @@ abstract class UploadBase {
         * @return null|UploadBase
         */
        public static function createFromRequest( &$request, $type = null ) {
-               $type = $type ? $type : $request->getVal( 'wpSourceType', 'File' );
+               $type = $type ?: $request->getVal( 'wpSourceType', 'File' );
 
                if ( !$type ) {
                        return null;
index bd0556a..0ec24af 100644 (file)
@@ -502,7 +502,7 @@ class CheckStorage {
        function importRevision( &$revision, &$importer ) {
                $id = $revision->getID();
                $content = $revision->getContent( Revision::RAW );
-               $id = $id ? $id : '';
+               $id = $id ?: '';
 
                if ( $content === null ) {
                        echo "Revision $id is broken, we have no content available\n";
index 9ebd57b..8bd37dd 100644 (file)
@@ -396,8 +396,8 @@ if ( isset( $_REQUEST['filter'] ) ) {
                return htmlspecialchars(
                        '?' .
                                wfArrayToCgi( [
-                                       'filter' => $_filter ? $_filter : $filter,
-                                       'sort' => $_sort ? $_sort : $sort,
+                                       'filter' => $_filter ?: $filter,
+                                       'sort' => $_sort ?: $sort,
                                        'expand' => implode( ',', array_keys( $_expand ) )
                                ] )
                );
index 73d4a47..eede54e 100644 (file)
@@ -31,10 +31,10 @@ class DjVuSupport {
        public function __construct() {
                global $wgDjvuRenderer, $wgDjvuDump, $wgDjvuToXML, $wgFileExtensions, $wgDjvuTxt;
 
-               $wgDjvuRenderer = $wgDjvuRenderer ? $wgDjvuRenderer : '/usr/bin/ddjvu';
-               $wgDjvuDump = $wgDjvuDump ? $wgDjvuDump : '/usr/bin/djvudump';
-               $wgDjvuToXML = $wgDjvuToXML ? $wgDjvuToXML : '/usr/bin/djvutoxml';
-               $wgDjvuTxt = $wgDjvuTxt ? $wgDjvuTxt : '/usr/bin/djvutxt';
+               $wgDjvuRenderer = $wgDjvuRenderer ?: '/usr/bin/ddjvu';
+               $wgDjvuDump = $wgDjvuDump ?: '/usr/bin/djvudump';
+               $wgDjvuToXML = $wgDjvuToXML ?: '/usr/bin/djvutoxml';
+               $wgDjvuTxt = $wgDjvuTxt ?: '/usr/bin/djvutxt';
 
                if ( !in_array( 'djvu', $wgFileExtensions ) ) {
                        $wgFileExtensions[] = 'djvu';
index 3749f29..61d0512 100644 (file)
@@ -29,9 +29,9 @@ class RevisionStoreTest extends MediaWikiTestCase {
                $WANObjectCache = null
        ) {
                return new RevisionStore(
-                       $loadBalancer ? $loadBalancer : $this->getMockLoadBalancer(),
-                       $blobStore ? $blobStore : $this->getMockSqlBlobStore(),
-                       $WANObjectCache ? $WANObjectCache : $this->getHashWANObjectCache(),
+                       $loadBalancer ?: $this->getMockLoadBalancer(),
+                       $blobStore ?: $this->getMockSqlBlobStore(),
+                       $WANObjectCache ?: $this->getHashWANObjectCache(),
                        MediaWikiServices::getInstance()->getCommentStore(),
                        MediaWikiServices::getInstance()->getActorMigration()
                );