Merge "Simplify PHP by using ?? and ?:"
This commit is contained in:
commit
ef97002179
32 changed files with 43 additions and 76 deletions
|
|
@ -1641,7 +1641,7 @@ class Block {
|
|||
$reason,
|
||||
$context->getRequest()->getIP(),
|
||||
$this->getByName(),
|
||||
$systemBlockType !== null ? $systemBlockType : $this->getId(),
|
||||
$systemBlockType ?? $this->getId(),
|
||||
$lang->formatExpiry( $this->mExpiry ),
|
||||
(string)$intended,
|
||||
$lang->userTimeAndDate( $this->mTimestamp, $context->getUser() ),
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@ class CommentStore {
|
|||
* @return string
|
||||
*/
|
||||
private function getKey( $methodKey = null ) {
|
||||
$key = $this->key !== null ? $this->key : $methodKey;
|
||||
$key = $this->key ?? $methodKey;
|
||||
if ( $key === null ) {
|
||||
// @codeCoverageIgnoreStart
|
||||
throw new InvalidArgumentException( '$key should not be null' );
|
||||
|
|
|
|||
|
|
@ -3352,7 +3352,7 @@ ERROR;
|
|||
}
|
||||
|
||||
$this->showTextbox(
|
||||
$textoverride !== null ? $textoverride : $this->textbox1,
|
||||
$textoverride ?? $this->textbox1,
|
||||
'wpTextbox1',
|
||||
$attribs
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1128,7 +1128,7 @@ class RevisionStore
|
|||
if ( !property_exists( $row, 'old_flags' ) ) {
|
||||
throw new InvalidArgumentException( 'old_flags was not set in $row' );
|
||||
}
|
||||
$blobFlags = ( $row->old_flags === null ) ? '' : $row->old_flags;
|
||||
$blobFlags = $row->old_flags ?? '';
|
||||
}
|
||||
|
||||
$mainSlotRow->slot_revision_id = intval( $row->rev_id );
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class WikiReference {
|
|||
public function __construct( $canonicalServer, $path, $server = null ) {
|
||||
$this->mCanonicalServer = $canonicalServer;
|
||||
$this->mPath = $path;
|
||||
$this->mServer = $server === null ? $canonicalServer : $server;
|
||||
$this->mServer = $server ?? $canonicalServer;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -218,21 +218,15 @@ class InfoAction extends FormlessAction {
|
|||
|
||||
$pageCounts = $this->pageCounts( $this->page );
|
||||
|
||||
$pageProperties = [];
|
||||
$props = PageProps::getInstance()->getAllProperties( $title );
|
||||
if ( isset( $props[$id] ) ) {
|
||||
$pageProperties = $props[$id];
|
||||
}
|
||||
$pageProperties = $props[$id] ?? [];
|
||||
|
||||
// Basic information
|
||||
$pageInfo = [];
|
||||
$pageInfo['header-basic'] = [];
|
||||
|
||||
// Display title
|
||||
$displayTitle = $title->getPrefixedText();
|
||||
if ( isset( $pageProperties['displaytitle'] ) ) {
|
||||
$displayTitle = $pageProperties['displaytitle'];
|
||||
}
|
||||
$displayTitle = $pageProperties['displaytitle'] ?? $title->getPrefixedText();
|
||||
|
||||
$pageInfo['header-basic'][] = [
|
||||
$this->msg( 'pageinfo-display-title' ), $displayTitle
|
||||
|
|
@ -254,10 +248,7 @@ class InfoAction extends FormlessAction {
|
|||
}
|
||||
|
||||
// Default sort key
|
||||
$sortKey = $title->getCategorySortkey();
|
||||
if ( isset( $pageProperties['defaultsort'] ) ) {
|
||||
$sortKey = $pageProperties['defaultsort'];
|
||||
}
|
||||
$sortKey = $pageProperties['defaultsort'] ?? $title->getCategorySortkey();
|
||||
|
||||
$sortKey = htmlspecialchars( $sortKey );
|
||||
$pageInfo['header-basic'][] = [ $this->msg( 'pageinfo-default-sort' ), $sortKey ];
|
||||
|
|
|
|||
|
|
@ -149,11 +149,7 @@ class ApiQueryAllDeletedRevisions extends ApiQueryRevisionsBase {
|
|||
$miser_ns = null;
|
||||
|
||||
if ( $mode == 'all' ) {
|
||||
if ( $params['namespace'] !== null ) {
|
||||
$namespaces = $params['namespace'];
|
||||
} else {
|
||||
$namespaces = MWNamespace::getValidNamespaces();
|
||||
}
|
||||
$namespaces = $params['namespace'] ?? MWNamespace::getValidNamespaces();
|
||||
$this->addWhereFld( 'ar_namespace', $namespaces );
|
||||
|
||||
// For from/to/prefix, we have to consider the potential
|
||||
|
|
|
|||
|
|
@ -129,15 +129,15 @@ class ApiQueryAllImages extends ApiQueryGeneratorBase {
|
|||
if ( !is_null( $params['continue'] ) ) {
|
||||
$cont = explode( '|', $params['continue'] );
|
||||
$this->dieContinueUsageIf( count( $cont ) != 1 );
|
||||
$op = ( $ascendingOrder ? '>' : '<' );
|
||||
$op = $ascendingOrder ? '>' : '<';
|
||||
$continueFrom = $db->addQuotes( $cont[0] );
|
||||
$this->addWhere( "img_name $op= $continueFrom" );
|
||||
}
|
||||
|
||||
// Image filters
|
||||
$from = ( $params['from'] === null ? null : $this->titlePartToKey( $params['from'], NS_FILE ) );
|
||||
$to = ( $params['to'] === null ? null : $this->titlePartToKey( $params['to'], NS_FILE ) );
|
||||
$this->addWhereRange( 'img_name', ( $ascendingOrder ? 'newer' : 'older' ), $from, $to );
|
||||
$from = $params['from'] === null ? null : $this->titlePartToKey( $params['from'], NS_FILE );
|
||||
$to = $params['to'] === null ? null : $this->titlePartToKey( $params['to'], NS_FILE );
|
||||
$this->addWhereRange( 'img_name', $ascendingOrder ? 'newer' : 'older', $from, $to );
|
||||
|
||||
if ( isset( $params['prefix'] ) ) {
|
||||
$this->addWhere( 'img_name' . $db->buildLike(
|
||||
|
|
@ -210,7 +210,7 @@ class ApiQueryAllImages extends ApiQueryGeneratorBase {
|
|||
'ug_expiry IS NULL OR ug_expiry >= ' . $db->addQuotes( $db->timestamp() )
|
||||
]
|
||||
] ] );
|
||||
$groupCond = ( $params['filterbots'] == 'nobots' ? 'NULL' : 'NOT NULL' );
|
||||
$groupCond = $params['filterbots'] == 'nobots' ? 'NULL' : 'NOT NULL';
|
||||
$this->addWhere( "ug_group IS $groupCond" );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -150,10 +150,10 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase {
|
|||
}
|
||||
|
||||
// 'continue' always overrides 'from'
|
||||
$from = ( $continue || $params['from'] === null ? null :
|
||||
$this->titlePartToKey( $params['from'], $namespace ) );
|
||||
$to = ( $params['to'] === null ? null :
|
||||
$this->titlePartToKey( $params['to'], $namespace ) );
|
||||
$from = $continue || $params['from'] === null ? null :
|
||||
$this->titlePartToKey( $params['from'], $namespace );
|
||||
$to = $params['to'] === null ? null :
|
||||
$this->titlePartToKey( $params['to'], $namespace );
|
||||
$this->addWhereRange( $pfx . $fieldTitle, 'newer', $from, $to );
|
||||
|
||||
if ( isset( $params['prefix'] ) ) {
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ class ApiQueryContributors extends ApiQueryBase {
|
|||
// some other module used up all the space. Just set a dummy
|
||||
// continue and hope it works next time.
|
||||
$this->setContinueEnumParameter( 'continue',
|
||||
$params['continue'] !== null ? $params['continue'] : '0|0'
|
||||
$params['continue'] ?? '0|0'
|
||||
);
|
||||
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ class ApiQueryImageInfo extends ApiQueryBase {
|
|||
if ( count( $pageIds[NS_FILE] ) == 1 ) {
|
||||
// See the 'the user is screwed' comment below
|
||||
$this->setContinueEnumParameter( 'start',
|
||||
$start !== null ? $start : wfTimestamp( TS_ISO_8601, $img->getTimestamp() )
|
||||
$start ?? wfTimestamp( TS_ISO_8601, $img->getTimestamp() )
|
||||
);
|
||||
} else {
|
||||
$this->setContinueEnumParameter( 'continue',
|
||||
|
|
@ -152,7 +152,7 @@ class ApiQueryImageInfo extends ApiQueryBase {
|
|||
// thing again. When the violating queries have been
|
||||
// out-continued, the result will get through
|
||||
$this->setContinueEnumParameter( 'start',
|
||||
$start !== null ? $start : wfTimestamp( TS_ISO_8601, $img->getTimestamp() )
|
||||
$start ?? wfTimestamp( TS_ISO_8601, $img->getTimestamp() )
|
||||
);
|
||||
} else {
|
||||
$this->setContinueEnumParameter( 'continue',
|
||||
|
|
|
|||
|
|
@ -321,7 +321,7 @@ class ApiQueryLogEvents extends ApiQueryBase {
|
|||
}
|
||||
if ( LogEventsList::userCan( $row, LogPage::DELETED_USER, $user ) ) {
|
||||
if ( $this->fld_user ) {
|
||||
$vals['user'] = $row->user_name === null ? $row->log_user_text : $row->user_name;
|
||||
$vals['user'] = $row->user_name ?? $row->log_user_text;
|
||||
}
|
||||
if ( $this->fld_userid ) {
|
||||
$vals['userid'] = intval( $row->log_user );
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ class ApiSetPageLanguage extends ApiBase {
|
|||
$this,
|
||||
$titleObj,
|
||||
$params['lang'],
|
||||
$params['reason'] === null ? '' : $params['reason'],
|
||||
$params['reason'] ?? '',
|
||||
$params['tags'] ?: []
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ class CloneDatabase {
|
|||
$this->db = $db;
|
||||
$this->tablesToClone = $tablesToClone;
|
||||
$this->newTablePrefix = $newTablePrefix;
|
||||
$this->oldTablePrefix = $oldTablePrefix !== null ? $oldTablePrefix : $this->db->tablePrefix();
|
||||
$this->oldTablePrefix = $oldTablePrefix ?? $this->db->tablePrefix();
|
||||
$this->dropCurrentTables = $dropCurrentTables;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -968,11 +968,7 @@ abstract class HTMLFormField {
|
|||
}
|
||||
|
||||
public function getDefault() {
|
||||
if ( isset( $this->mDefault ) ) {
|
||||
return $this->mDefault;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return $this->mDefault ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ abstract class FileOp {
|
|||
if ( FileBackend::isStoragePath( $path ) ) {
|
||||
$res = FileBackend::normalizeStoragePath( $path );
|
||||
|
||||
return ( $res !== null ) ? $res : $path;
|
||||
return $res ?? $path;
|
||||
}
|
||||
|
||||
return $path;
|
||||
|
|
|
|||
|
|
@ -821,7 +821,7 @@ class ManualLogEntry extends LogEntryBase {
|
|||
}
|
||||
|
||||
public function getTimestamp() {
|
||||
$ts = $this->timestamp !== null ? $this->timestamp : wfTimestampNow();
|
||||
$ts = $this->timestamp ?? wfTimestampNow();
|
||||
|
||||
return wfTimestamp( TS_MW, $ts );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -971,11 +971,7 @@ class FormatMetadata extends ContextSource {
|
|||
|
||||
case 'LanguageCode':
|
||||
$lang = Language::fetchLanguageName( strtolower( $val ), $this->getLanguage()->getCode() );
|
||||
if ( $lang ) {
|
||||
$val = htmlspecialchars( $lang );
|
||||
} else {
|
||||
$val = htmlspecialchars( $val );
|
||||
}
|
||||
$val = htmlspecialchars( $lang ?: $val );
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
|
|||
|
|
@ -205,7 +205,7 @@ class SearchResultSet implements Countable, IteratorAggregate {
|
|||
$it = $this->bcIterator();
|
||||
$searchResult = $it->current();
|
||||
$it->next();
|
||||
return $searchResult === null ? false : $searchResult;
|
||||
return $searchResult ?? false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -338,11 +338,7 @@ class SearchResultSet implements Countable, IteratorAggregate {
|
|||
return;
|
||||
}
|
||||
$result->setExtensionData( function () use ( $id ) {
|
||||
if ( isset( $this->extraData[$id] ) ) {
|
||||
return $this->extraData[$id];
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
return $this->extraData[$id] ?? [];
|
||||
} );
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -198,7 +198,7 @@ class DBSiteStore implements SiteStore {
|
|||
'site_type' => $site->getType(),
|
||||
'site_group' => $site->getGroup(),
|
||||
'site_source' => $site->getSource(),
|
||||
'site_language' => $site->getLanguageCode() === null ? '' : $site->getLanguageCode(),
|
||||
'site_language' => $site->getLanguageCode() ?? '',
|
||||
'site_protocol' => $site->getProtocol(),
|
||||
'site_domain' => strrev( $site->getDomain() ) . '.',
|
||||
'site_data' => serialize( $site->getExtraData() ),
|
||||
|
|
|
|||
|
|
@ -865,7 +865,7 @@ abstract class QueryPage extends SpecialPage {
|
|||
|
||||
$batch = new LinkBatch;
|
||||
foreach ( $res as $row ) {
|
||||
$batch->add( $ns !== null ? $ns : $row->namespace, $row->title );
|
||||
$batch->add( $ns ?? $row->namespace, $row->title );
|
||||
}
|
||||
$batch->execute();
|
||||
|
||||
|
|
|
|||
|
|
@ -50,11 +50,7 @@ class SpecialContributions extends IncludableSpecialPage {
|
|||
$this->opts = [];
|
||||
$request = $this->getRequest();
|
||||
|
||||
if ( $par !== null ) {
|
||||
$target = $par;
|
||||
} else {
|
||||
$target = $request->getVal( 'target' );
|
||||
}
|
||||
$target = $par ?? $request->getVal( 'target' );
|
||||
|
||||
if ( $request->getVal( 'contribs' ) == 'newbie' || $par === 'newbies' ) {
|
||||
$target = 'newbies';
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ class FileDuplicateSearchPage extends QueryPage {
|
|||
$this->setHeaders();
|
||||
$this->outputHeader();
|
||||
|
||||
$this->filename = $par !== null ? $par : $this->getRequest()->getText( 'filename' );
|
||||
$this->filename = $par ?? $this->getRequest()->getText( 'filename' );
|
||||
$this->file = null;
|
||||
$this->hash = '';
|
||||
$title = Title::newFromText( $this->filename, NS_FILE );
|
||||
|
|
|
|||
|
|
@ -163,7 +163,7 @@ class SpecialPageLanguage extends FormSpecialPage {
|
|||
$this->getContext(),
|
||||
$title,
|
||||
$newLanguage,
|
||||
$data['reason'] === null ? '' : $data['reason']
|
||||
$data['reason'] ?? ''
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -259,7 +259,7 @@ class SpecialSearch extends SpecialPage {
|
|||
return null;
|
||||
}
|
||||
|
||||
return $url === null ? $title->getFullUrlForRedirect() : $url;
|
||||
return $url ?? $title->getFullUrlForRedirect();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -87,11 +87,7 @@ class UserrightsPage extends SpecialPage {
|
|||
|
||||
$out->addModules( [ 'mediawiki.special.userrights' ] );
|
||||
|
||||
if ( $par !== null ) {
|
||||
$this->mTarget = $par;
|
||||
} else {
|
||||
$this->mTarget = $request->getVal( 'user' );
|
||||
}
|
||||
$this->mTarget = $par ?? $request->getVal( 'user' );
|
||||
|
||||
if ( is_string( $this->mTarget ) ) {
|
||||
$this->mTarget = trim( $this->mTarget );
|
||||
|
|
|
|||
|
|
@ -235,7 +235,7 @@ class ProtectedPagesPager extends TablePager {
|
|||
$this->getUser()
|
||||
) ) {
|
||||
$value = CommentStore::getStore()->getComment( 'log_comment', $row )->text;
|
||||
$formatted = Linker::formatComment( $value !== null ? $value : '' );
|
||||
$formatted = Linker::formatComment( $value ?? '' );
|
||||
} else {
|
||||
$formatted = $this->msg( 'rev-deleted-comment' )->escaped();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ class UpdateSpecialPages extends Maintenance {
|
|||
if ( $queryPage->isExpensive() ) {
|
||||
$t1 = microtime( true );
|
||||
# Do the query
|
||||
$num = $queryPage->recache( $limit === null ? $wgQueryCacheLimit : $limit );
|
||||
$num = $queryPage->recache( $limit ?? $wgQueryCacheLimit );
|
||||
$t2 = microtime( true );
|
||||
if ( $num === false ) {
|
||||
$this->output( "FAILED: database error\n" );
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@ class ResourceLoaderTestModule extends ResourceLoaderModule {
|
|||
}
|
||||
|
||||
public function shouldEmbedModule( ResourceLoaderContext $context ) {
|
||||
return $this->shouldEmbed !== null ? $this->shouldEmbed : parent::shouldEmbedModule( $context );
|
||||
return $this->shouldEmbed ?? parent::shouldEmbedModule( $context );
|
||||
}
|
||||
|
||||
public function enableModuleContentVersion() {
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ class DerivedPageDataUpdaterTest extends MediaWikiTestCase {
|
|||
$comment = CommentStoreComment::newUnsavedComment( $summary );
|
||||
|
||||
if ( !$content instanceof Content ) {
|
||||
$content = new WikitextContent( $content === null ? $summary : $content );
|
||||
$content = new WikitextContent( $content ?? $summary );
|
||||
}
|
||||
|
||||
$this->getDerivedPageDataUpdater( $page ); // flush cached instance before.
|
||||
|
|
|
|||
|
|
@ -235,7 +235,7 @@ class PageUpdaterTest extends MediaWikiTestCase {
|
|||
$comment = CommentStoreComment::newUnsavedComment( $summary );
|
||||
|
||||
if ( !$content instanceof Content ) {
|
||||
$content = new TextContent( $content === null ? $summary : $content );
|
||||
$content = new TextContent( $content ?? $summary );
|
||||
}
|
||||
|
||||
$updater = $page->newPageUpdater( $user );
|
||||
|
|
|
|||
|
|
@ -519,7 +519,7 @@ class CookieSessionProviderTest extends MediaWikiTestCase {
|
|||
|
||||
$normalExpiry = $config->get( 'CookieExpiration' );
|
||||
$extendedExpiry = $config->get( 'ExtendedLoginCookieExpiration' );
|
||||
$extendedExpiry = (int)( $extendedExpiry === null ? 0 : $extendedExpiry );
|
||||
$extendedExpiry = (int)( $extendedExpiry ?? 0 );
|
||||
$expect = [
|
||||
'MySessionName' => [
|
||||
'value' => (string)$sessionId,
|
||||
|
|
|
|||
Loading…
Reference in a new issue