Make use of ??= in more places

New feature from PHP 7.4

Change-Id: Ifa7a9bc7b2ec415ad7ecb23f4c1776f51f58fd6b
This commit is contained in:
DannyS712 2022-12-16 23:48:27 +00:00
parent a8de3d6338
commit c1db64b808
66 changed files with 119 additions and 306 deletions

View file

@ -447,9 +447,7 @@ class CommentStore {
if ( ( $this->stage & SCHEMA_COMPAT_WRITE_NEW ) && !$comment->id ) {
$dbData = $comment->data;
if ( !$comment->message instanceof RawMessage ) {
if ( $dbData === null ) {
$dbData = [ '_null' => true ];
}
$dbData ??= [ '_null' => true ];
$dbData['_message'] = self::encodeMessage( $comment->message );
}
if ( $dbData !== null ) {

View file

@ -548,10 +548,7 @@ class ContentSecurityPolicy {
if ( !self::isNonceRequired( $this->mwConfig ) ) {
return false;
}
if ( $this->nonce === null ) {
$rand = random_bytes( 15 );
$this->nonce = base64_encode( $rand );
}
$this->nonce ??= base64_encode( random_bytes( 15 ) );
return $this->nonce;
}

View file

@ -1041,9 +1041,7 @@ function wfDebugBacktrace( $limit = 0 ) {
function wfBacktrace( $raw = null ) {
global $wgCommandLineMode;
if ( $raw === null ) {
$raw = $wgCommandLineMode;
}
$raw ??= $wgCommandLineMode;
if ( $raw ) {
$frameFormat = "%s line %s calls %s()\n";

View file

@ -374,9 +374,7 @@ class MediaWikiServices extends ServiceContainer {
self::failIfResetNotAllowed( __METHOD__ );
if ( $bootstrapConfig === null ) {
$bootstrapConfig = self::$instance->getBootstrapConfig();
}
$bootstrapConfig ??= self::$instance->getBootstrapConfig();
$oldInstance = self::$instance;

View file

@ -1968,9 +1968,7 @@ class OutputPage extends ContextSource {
public function addWikiTextAsInterface(
$text, $linestart = true, PageReference $title = null
) {
if ( $title === null ) {
$title = $this->getTitle();
}
$title ??= $this->getTitle();
if ( !$title ) {
throw new MWException( 'Title is null' );
}
@ -2018,9 +2016,7 @@ class OutputPage extends ContextSource {
public function addWikiTextAsContent(
$text, $linestart = true, PageReference $title = null
) {
if ( $title === null ) {
$title = $this->getTitle();
}
$title ??= $this->getTitle();
if ( !$title ) {
throw new MWException( 'Title is null' );
}
@ -3182,13 +3178,9 @@ class OutputPage extends ContextSource {
* @param string|null $returntoquery Query string for the return to link
*/
public function returnToMain( $unused = null, $returnto = null, $returntoquery = null ) {
if ( $returnto == null ) {
$returnto = $this->getRequest()->getText( 'returnto' );
}
$returnto ??= $this->getRequest()->getText( 'returnto' );
if ( $returntoquery == null ) {
$returntoquery = $this->getRequest()->getText( 'returntoquery' );
}
$returntoquery ??= $this->getRequest()->getText( 'returntoquery' );
if ( $returnto === '' ) {
$returnto = Title::newMainPage();

View file

@ -1930,10 +1930,8 @@ MESSAGE;
}
);
$stats->increment( $incKey );
if ( $result === null ) {
// Cached failure
$result = $data;
}
// Use $data on cache failure
$result ??= $data;
return $result;
}

View file

@ -33,9 +33,7 @@ class ConditionalHeaderUtil {
} else {
$this->lastModified = (int)ConvertibleTimestamp::convert( TS_UNIX, $lastModified );
}
if ( $hasRepresentation === null ) {
$hasRepresentation = $eTag !== null;
}
$hasRepresentation ??= ( $eTag !== null );
$this->hasRepresentation = $hasRepresentation;
}

View file

@ -92,9 +92,7 @@ class RequestFromGlobals extends RequestBase {
}
public function getUploadedFiles() {
if ( $this->uploadedFiles === null ) {
$this->uploadedFiles = ServerRequest::normalizeFiles( $_FILES );
}
$this->uploadedFiles ??= ServerRequest::normalizeFiles( $_FILES );
return $this->uploadedFiles;
}

View file

@ -351,9 +351,7 @@ class MutableRevisionRecord extends RevisionRecord {
*/
public function getSize() {
// If not known, re-calculate and remember. Will be reset when slots change.
if ( $this->mSize === null ) {
$this->mSize = $this->mSlots->computeSize();
}
$this->mSize ??= $this->mSlots->computeSize();
return $this->mSize;
}
@ -367,9 +365,7 @@ class MutableRevisionRecord extends RevisionRecord {
*/
public function getSha1() {
// If not known, re-calculate and remember. Will be reset when slots change.
if ( $this->mSha1 === null ) {
$this->mSha1 = $this->mSlots->computeSha1();
}
$this->mSha1 ??= $this->mSlots->computeSha1();
return $this->mSha1;
}

View file

@ -118,9 +118,7 @@ class RevisionArchiveRecord extends RevisionRecord {
public function getSize() {
// If length is null, calculate and remember it (potentially SLOW!).
// This is for compatibility with old database rows that don't have the field set.
if ( $this->mSize === null ) {
$this->mSize = $this->mSlots->computeSize();
}
$this->mSize ??= $this->mSlots->computeSize();
return $this->mSize;
}
@ -132,9 +130,7 @@ class RevisionArchiveRecord extends RevisionRecord {
public function getSha1() {
// If hash is null, calculate it and remember (potentially SLOW!)
// This is for compatibility with old database rows that don't have the field set.
if ( $this->mSha1 === null ) {
$this->mSha1 = $this->mSlots->computeSha1();
}
$this->mSha1 ??= $this->mSlots->computeSha1();
return $this->mSha1;
}

View file

@ -152,9 +152,7 @@ class RevisionStoreRecord extends RevisionRecord {
public function getSize() {
// If length is null, calculate and remember it (potentially SLOW!).
// This is for compatibility with old database rows that don't have the field set.
if ( $this->mSize === null ) {
$this->mSize = $this->mSlots->computeSize();
}
$this->mSize ??= $this->mSlots->computeSize();
return $this->mSize;
}
@ -166,9 +164,7 @@ class RevisionStoreRecord extends RevisionRecord {
public function getSha1() {
// If hash is null, calculate it and remember (potentially SLOW!)
// This is for compatibility with old database rows that don't have the field set.
if ( $this->mSha1 === null ) {
$this->mSha1 = $this->mSlots->computeSha1();
}
$this->mSha1 ??= $this->mSlots->computeSha1();
return $this->mSha1;
}

View file

@ -490,9 +490,7 @@ class SiteConfiguration {
protected function mergeParams( $wiki, $site, array $params, array $wikiTags ) {
$ret = $this->getWikiParams( $wiki );
if ( $ret['suffix'] === null ) {
$ret['suffix'] = $site;
}
$ret['suffix'] ??= $site;
// Make tags based on the db suffix (e.g. wiki family) automatically
// available for use in wgConf. The user does not have to maintain

View file

@ -264,9 +264,7 @@ class WebRequest {
* @return string
*/
public static function detectServer( $assumeProxiesUseDefaultProtocolPorts = null ) {
if ( $assumeProxiesUseDefaultProtocolPorts === null ) {
$assumeProxiesUseDefaultProtocolPorts = $GLOBALS['wgAssumeProxiesUseDefaultProtocolPorts'];
}
$assumeProxiesUseDefaultProtocolPorts ??= $GLOBALS['wgAssumeProxiesUseDefaultProtocolPorts'];
$proto = self::detectProtocol();
$stdPort = $proto === 'https' ? 443 : 80;
@ -372,9 +370,7 @@ class WebRequest {
* @return string
*/
public function getProtocol() {
if ( $this->protocol === null ) {
$this->protocol = self::detectProtocol();
}
$this->protocol ??= self::detectProtocol();
return $this->protocol;
}
@ -795,9 +791,7 @@ class WebRequest {
*/
public function getRawInput() {
static $input = null;
if ( $input === null ) {
$input = file_get_contents( 'php://input' );
}
$input ??= file_get_contents( 'php://input' );
return $input;
}

View file

@ -632,10 +632,8 @@ class InfoAction extends FormlessAction {
switch ( count( $protections ) ) {
case 0:
$message = $this->getNamespaceProtectionMessage( $title );
if ( $message === null ) {
// Allow all users
$message = $this->msg( 'protect-default' )->escaped();
}
// Allow all users by default
$message ??= $this->msg( 'protect-default' )->escaped();
break;
case 1:

View file

@ -496,9 +496,7 @@ class ApiEditPage extends ApiBase {
$baseContentModel = $baseContent ? $baseContent->getModel() : null;
}
if ( $baseContentModel === null ) {
$baseContentModel = $pageObj->getContentModel();
}
$baseContentModel ??= $pageObj->getContentModel();
// However, allow the content models to possibly differ if we are intentionally
// changing them or we are doing an undo edit that is reverting content model change.

View file

@ -250,10 +250,8 @@ class ApiFeedWatchlist extends ApiBase {
}
private function getWatchlistModule() {
if ( $this->watchlistModule === null ) {
$this->watchlistModule = $this->getMain()->getModuleManager()->getModule( 'query' )
->getModuleManager()->getModule( 'watchlist' );
}
$this->watchlistModule ??= $this->getMain()->getModuleManager()->getModule( 'query' )
->getModuleManager()->getModule( 'watchlist' );
return $this->watchlistModule;
}

View file

@ -167,9 +167,7 @@ class ApiImageRotate extends ApiBase {
* @return ApiPageSet
*/
private function getPageSet() {
if ( $this->mPageSet === null ) {
$this->mPageSet = new ApiPageSet( $this, 0, NS_FILE );
}
$this->mPageSet ??= new ApiPageSet( $this, 0, NS_FILE );
return $this->mPageSet;
}

View file

@ -1853,10 +1853,8 @@ class ApiMain extends ApiBase {
// See if custom printer is used
$this->mPrinter = $module->getCustomPrinter();
if ( $this->mPrinter === null ) {
// Create an appropriate printer
$this->mPrinter = $this->createPrinterByName( $params['format'] );
}
// Create an appropriate printer if not set
$this->mPrinter ??= $this->createPrinterByName( $params['format'] );
if ( $request->getProtocol() === 'http' &&
(

View file

@ -150,9 +150,7 @@ class ApiPurge extends ApiBase {
* @return ApiPageSet
*/
private function getPageSet() {
if ( $this->mPageSet === null ) {
$this->mPageSet = new ApiPageSet( $this );
}
$this->mPageSet ??= new ApiPageSet( $this );
return $this->mPageSet;
}

View file

@ -165,9 +165,7 @@ class ApiQueryBacklinksprop extends ApiQueryGeneratorBase {
$theTitle = null;
foreach ( $map as $nsTitles ) {
$key = array_key_first( $nsTitles );
if ( $theTitle === null ) {
$theTitle = $key;
}
$theTitle ??= $key;
if ( count( $nsTitles ) > 1 || $key !== $theTitle ) {
$sortby[$bl_title] = 'string';
break;

View file

@ -115,9 +115,7 @@ abstract class ApiQueryBase extends ApiBase {
* @return IDatabase
*/
protected function getDB() {
if ( $this->mDb === null ) {
$this->mDb = $this->getQuery()->getDB();
}
$this->mDb ??= $this->getQuery()->getDB();
return $this->mDb;
}
@ -171,9 +169,7 @@ abstract class ApiQueryBase extends ApiBase {
* @return SelectQueryBuilder
*/
protected function getQueryBuilder() {
if ( $this->queryBuilder === null ) {
$this->queryBuilder = $this->getDB()->newSelectQueryBuilder();
}
$this->queryBuilder ??= $this->getDB()->newSelectQueryBuilder();
return $this->queryBuilder;
}
@ -497,9 +493,8 @@ abstract class ApiQueryBase extends ApiBase {
* @return bool Whether the element fit in the result
*/
protected function addPageSubItem( $pageId, $item, $elemname = null ) {
if ( $elemname === null ) {
$elemname = $this->getModulePrefix();
}
$elemname ??= $this->getModulePrefix();
$result = $this->getResult();
$fit = $result->addValue( [ 'query', 'pages', $pageId,
$this->getModuleName() ], null, $item );

View file

@ -75,9 +75,7 @@ class ApiQueryExtLinksUsage extends ApiQueryGeneratorBase {
$orderBy = [];
if ( $query !== null && $query !== '' ) {
if ( $protocol === null ) {
$protocol = 'http://';
}
$protocol ??= 'http://';
// Normalize query to match the normalization applied for the externallinks table
$query = Parser::normalizeLinkUrl( $protocol . $query );

View file

@ -62,9 +62,7 @@ class ApiQueryExternalLinks extends ApiQueryBase {
}
if ( $query !== null && $query !== '' ) {
if ( $protocol === null ) {
$protocol = 'http://';
}
$protocol ??= 'http://';
// Normalize query to match the normalization applied for the externallinks table
$query = Parser::normalizeLinkUrl( $protocol . $query );

View file

@ -242,9 +242,7 @@ abstract class ApiQueryRevisionsBase extends ApiQueryGeneratorBase {
$this->parseContent = $params['parse'];
if ( $this->parseContent ) {
// Must manually initialize unset limit
if ( $this->limit === null ) {
$this->limit = 1;
}
$this->limit ??= 1;
}
$this->section = $params['section'] ?? false;
}

View file

@ -1198,9 +1198,7 @@ class ApiResult implements ApiSerializable {
*/
public static function formatExpiry( $expiry, $infinity = 'infinity' ) {
static $dbInfinity;
if ( $dbInfinity === null ) {
$dbInfinity = wfGetDB( DB_REPLICA )->getInfinity();
}
$dbInfinity ??= wfGetDB( DB_REPLICA )->getInfinity();
if ( $expiry === '' || $expiry === null || $expiry === false ||
wfIsInfinity( $expiry ) || $expiry === $dbInfinity

View file

@ -230,9 +230,7 @@ class ApiSetNotificationTimestamp extends ApiBase {
* @return ApiPageSet
*/
private function getPageSet() {
if ( $this->mPageSet === null ) {
$this->mPageSet = new ApiPageSet( $this );
}
$this->mPageSet ??= new ApiPageSet( $this );
return $this->mPageSet;
}

View file

@ -836,9 +836,7 @@ class ApiUpload extends ApiBase {
*/
protected function performUpload( $warnings ) {
// Use comment as initial page text by default
if ( $this->mParams['text'] === null ) {
$this->mParams['text'] = $this->mParams['comment'];
}
$this->mParams['text'] ??= $this->mParams['comment'];
/** @var LocalFile $file */
$file = $this->mUpload->getLocalFile();

View file

@ -161,9 +161,7 @@ class ApiWatch extends ApiBase {
* @return ApiPageSet
*/
private function getPageSet() {
if ( $this->mPageSet === null ) {
$this->mPageSet = new ApiPageSet( $this );
}
$this->mPageSet ??= new ApiPageSet( $this );
return $this->mPageSet;
}

View file

@ -38,12 +38,8 @@ trait ApiWatchlistTrait {
}
// This trait is used outside of core and therefor fallback to global state - T263904
$services = MediaWikiServices::getInstance();
if ( $this->watchlistManager === null ) {
$this->watchlistManager = $services->getWatchlistManager();
}
if ( $this->userOptionsLookup === null ) {
$this->userOptionsLookup = $services->getUserOptionsLookup();
}
$this->watchlistManager ??= $services->getWatchlistManager();
$this->userOptionsLookup ??= $services->getUserOptionsLookup();
}
/**

View file

@ -94,9 +94,7 @@ trait SearchApi {
$alternatives = $this->searchEngineConfig->getSearchTypes();
if ( count( $alternatives ) > 1 ) {
if ( $alternatives[0] === null ) {
$alternatives[0] = self::$BACKEND_NULL_PARAM;
}
$alternatives[0] ??= self::$BACKEND_NULL_PARAM;
$params['backend'] = [
ParamValidator::PARAM_DEFAULT => $this->searchEngineConfig->getSearchType(),
ParamValidator::PARAM_TYPE => $alternatives,

View file

@ -2333,9 +2333,7 @@ class AuthManager implements LoggerAwareInterface {
if ( !$req->action || $forceAction ) {
$req->action = $action;
}
if ( $req->username === null ) {
$req->username = $username;
}
$req->username ??= $username;
}
}

View file

@ -53,9 +53,7 @@ class CheckBlocksSecondaryAuthenticationProvider extends AbstractSecondaryAuthen
/** @inheritDoc */
protected function postInitSetup() {
if ( $this->blockDisablesLogin === null ) {
$this->blockDisablesLogin = $this->config->get( MainConfigNames::BlockDisablesLogin );
}
$this->blockDisablesLogin ??= $this->config->get( MainConfigNames::BlockDisablesLogin );
}
/** @inheritDoc */

View file

@ -34,10 +34,8 @@ class EmailNotificationSecondaryAuthenticationProvider
}
protected function postInitSetup() {
if ( $this->sendConfirmationEmail === null ) {
$this->sendConfirmationEmail = $this->config->get( MainConfigNames::EnableEmail )
$this->sendConfirmationEmail ??= $this->config->get( MainConfigNames::EnableEmail )
&& $this->config->get( MainConfigNames::EmailAuthentication );
}
}
public function getAuthenticationRequests( $action, array $options ) {

View file

@ -94,20 +94,12 @@ class TemporaryPasswordPrimaryAuthenticationProvider
}
protected function postInitSetup() {
if ( $this->emailEnabled === null ) {
$this->emailEnabled = $this->config->get( MainConfigNames::EnableEmail );
}
if ( $this->newPasswordExpiry === null ) {
$this->newPasswordExpiry = $this->config->get( MainConfigNames::NewPasswordExpiry );
}
if ( $this->passwordReminderResendTime === null ) {
$this->passwordReminderResendTime =
$this->config->get( MainConfigNames::PasswordReminderResendTime );
}
if ( $this->allowRequiringEmail === null ) {
$this->allowRequiringEmail =
$this->config->get( MainConfigNames::AllowRequiringEmailForResets );
}
$this->emailEnabled ??= $this->config->get( MainConfigNames::EnableEmail );
$this->newPasswordExpiry ??= $this->config->get( MainConfigNames::NewPasswordExpiry );
$this->passwordReminderResendTime ??=
$this->config->get( MainConfigNames::PasswordReminderResendTime );
$this->allowRequiringEmail ??=
$this->config->get( MainConfigNames::AllowRequiringEmailForResets );
}
protected function getPasswordResetData( $username, $data ) {

View file

@ -71,9 +71,7 @@ class PageRestriction extends AbstractRestriction {
// If the title does not exist, set to false to prevent multiple database
// queries.
if ( $this->title === null ) {
$this->title = false;
}
$this->title ??= false;
}
return $this->title;

View file

@ -169,9 +169,7 @@ class BacklinkCache {
* @return IDatabase
*/
protected function getDB() {
if ( $this->db === null ) {
$this->db = wfGetDB( DB_REPLICA );
}
$this->db ??= wfGetDB( DB_REPLICA );
return $this->db;
}

View file

@ -106,9 +106,7 @@ abstract class FileCacheBase {
* @return bool
*/
public function isCached() {
if ( $this->mCached === null ) {
$this->mCached = is_file( $this->cachePath() );
}
$this->mCached ??= is_file( $this->cachePath() );
return $this->mCached;
}

View file

@ -61,9 +61,7 @@ class GenderCache {
* @return string
*/
protected function getDefault() {
if ( $this->default === null ) {
$this->default = $this->userOptionsLookup->getDefaultOption( 'gender' );
}
$this->default ??= $this->userOptionsLookup->getDefaultOption( 'gender' );
return $this->default;
}

View file

@ -260,9 +260,7 @@ class LinkBatch {
// For each returned entry, add it to the list of good links, and remove it from $remaining
if ( $this->pageIdentities === null ) {
$this->pageIdentities = [];
}
$this->pageIdentities ??= [];
$ids = [];
$remaining = $this->data;

View file

@ -188,12 +188,10 @@ class CategoryMembershipChange {
$revisionStore = MediaWikiServices::getInstance()->getRevisionStore();
$correspondingRc = $revisionStore->getRecentChange( $this->revision );
if ( $correspondingRc === null ) {
$correspondingRc = $revisionStore->getRecentChange(
$this->revision,
RevisionStore::READ_LATEST
);
}
$correspondingRc ??= $revisionStore->getRecentChange(
$this->revision,
RevisionStore::READ_LATEST
);
if ( $correspondingRc !== null ) {
$bot = $correspondingRc->getAttribute( 'rc_bot' ) ?: 0;
$ip = $correspondingRc->getAttribute( 'rc_ip' ) ?: '';

View file

@ -757,9 +757,7 @@ class EnhancedChangesList extends ChangesList {
} elseif ( $query !== null ) {
wfDeprecated( __METHOD__ . ' with $query parameter', '1.36' );
}
if ( $useParentheses === null ) {
$useParentheses = true;
}
$useParentheses ??= true;
$pageTitle = $rc->getTitle();
if ( $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE ) {
// For categorizations we must swap the category title with the page title!

View file

@ -42,9 +42,7 @@ class JsonContent extends TextContent {
* @return Status
*/
public function getData() {
if ( $this->jsonParse === null ) {
$this->jsonParse = FormatJson::parse( $this->getText() );
}
$this->jsonParse ??= FormatJson::parse( $this->getText() );
return $this->jsonParse;
}

View file

@ -212,11 +212,9 @@ class DerivativeContext extends ContextSource implements MutableContext {
return $this->getContext()->getActionName();
}
if ( $this->action === null ) {
$this->action = MediaWikiServices::getInstance()
->getActionFactory()
->getActionName( $this );
}
$this->action ??= MediaWikiServices::getInstance()
->getActionFactory()
->getActionName( $this );
return $this->action;
}

View file

@ -121,11 +121,9 @@ class RequestContext implements IContextSource, MutableContext {
* @return Config
*/
public function getConfig() {
if ( $this->config === null ) {
// @todo In the future, we could move this to WebStart.php so
// the Config object is ready for when initialization happens
$this->config = MediaWikiServices::getInstance()->getMainConfig();
}
// @todo In the future, we could move this to WebStart.php so
// the Config object is ready for when initialization happens
$this->config ??= MediaWikiServices::getInstance()->getMainConfig();
return $this->config;
}
@ -158,11 +156,9 @@ class RequestContext implements IContextSource, MutableContext {
* @return Timing
*/
public function getTiming() {
if ( $this->timing === null ) {
$this->timing = new Timing( [
'logger' => LoggerFactory::getInstance( 'Timing' )
] );
}
$this->timing ??= new Timing( [
'logger' => LoggerFactory::getInstance( 'Timing' )
] );
return $this->timing;
}
@ -289,11 +285,9 @@ class RequestContext implements IContextSource, MutableContext {
//
// This value is frequently needed in OutputPage and in various
// Skin-related methods and classes.
if ( $this->action === null ) {
$this->action = MediaWikiServices::getInstance()
->getActionFactory()
->getActionName( $this );
}
$this->action ??= MediaWikiServices::getInstance()
->getActionFactory()
->getActionName( $this );
return $this->action;
}
@ -324,9 +318,7 @@ class RequestContext implements IContextSource, MutableContext {
* @return OutputPage
*/
public function getOutput() {
if ( $this->output === null ) {
$this->output = new OutputPage( $this );
}
$this->output ??= new OutputPage( $this );
return $this->output;
}
@ -551,9 +543,7 @@ class RequestContext implements IContextSource, MutableContext {
* @return RequestContext
*/
public static function getMain(): RequestContext {
if ( self::$instance === null ) {
self::$instance = new self;
}
self::$instance ??= new self;
return self::$instance;
}

View file

@ -445,10 +445,8 @@ class DifferenceEngine extends ContextSource {
* @return Language
*/
public function getDiffLang() {
if ( $this->mDiffLang === null ) {
# Default language in which the diff text is written.
$this->mDiffLang = $this->getTitle()->getPageLanguage();
}
# Default language in which the diff text is written.
$this->mDiffLang ??= $this->getTitle()->getPageLanguage();
return $this->mDiffLang;
}

View file

@ -1723,10 +1723,8 @@ class LocalFile extends File {
// updated and we must therefore update the DB too.
$oldver = $status->value;
if ( $uploader === null ) {
// Uploader argument is optional, fall back to the context authority
$uploader = RequestContext::getMain()->getAuthority();
}
// Uploader argument is optional, fall back to the context authority
$uploader ??= RequestContext::getMain()->getAuthority();
$uploadStatus = $this->recordUpload3(
$oldver,

View file

@ -464,11 +464,9 @@ class WikiRevision implements ImportableUploadRevision, ImportableOldRevision {
* @throws MWUnknownContentModelException
*/
public function getContentHandler() {
if ( $this->contentHandler === null ) {
$this->contentHandler = MediaWikiServices::getInstance()
->getContentHandlerFactory()
->getContentHandler( $this->getModel() );
}
$this->contentHandler ??= MediaWikiServices::getInstance()
->getContentHandlerFactory()
->getContentHandler( $this->getModel() );
return $this->contentHandler;
}
@ -505,9 +503,7 @@ class WikiRevision implements ImportableUploadRevision, ImportableOldRevision {
* @return string
*/
public function getModel() {
if ( $this->model === null ) {
$this->model = $this->getTitle()->getContentModel();
}
$this->model ??= $this->getTitle()->getContentModel();
return $this->model;
}
@ -518,9 +514,7 @@ class WikiRevision implements ImportableUploadRevision, ImportableOldRevision {
* @return string
*/
public function getFormat() {
if ( $this->format === null ) {
$this->format = $this->getContentHandler()->getDefaultFormat();
}
$this->format ??= $this->getContentHandler()->getDefaultFormat();
return $this->format;
}

View file

@ -698,9 +698,7 @@ abstract class DatabaseUpdater {
* @return bool False if patch is skipped.
*/
protected function applyPatch( $path, $isFullPath = false, $msg = null ) {
if ( $msg === null ) {
$msg = "Applying $path patch";
}
$msg ??= "Applying $path patch";
if ( $this->skipSchema ) {
$this->output( "...skipping schema change ($msg).\n" );

View file

@ -3152,11 +3152,8 @@ class Language {
*/
public function getSpecialPageAliases() {
// Cache aliases because it may be slow to load them
if ( $this->mExtendedSpecialPageAliases === null ) {
// Initialise array
$this->mExtendedSpecialPageAliases =
$this->localisationCache->getItem( $this->mCode, 'specialPageAliases' );
}
$this->mExtendedSpecialPageAliases ??=
$this->localisationCache->getItem( $this->mCode, 'specialPageAliases' );
return $this->mExtendedSpecialPageAliases;
}
@ -4384,9 +4381,7 @@ class Language {
* @return string
*/
public function getHtmlCode() {
if ( $this->mHtmlCode === null ) {
$this->mHtmlCode = LanguageCode::bcp47( $this->getCode() );
}
$this->mHtmlCode ??= LanguageCode::bcp47( $this->getCode() );
return $this->mHtmlCode;
}
@ -4570,9 +4565,7 @@ class Language {
*/
public function formatExpiry( $expiry, $format = true, $infinity = 'infinity', $user = null ) {
static $dbInfinity;
if ( $dbInfinity === null ) {
$dbInfinity = wfGetDB( DB_REPLICA )->getInfinity();
}
$dbInfinity ??= wfGetDB( DB_REPLICA )->getInfinity();
if ( $expiry == '' || $expiry === 'infinity' || $expiry == $dbInfinity ) {
return $format === true

View file

@ -986,16 +986,10 @@ class LocalisationCache {
unset( $page );
# If there were no plural rules, return an empty array
if ( $allData['pluralRules'] === null ) {
$allData['pluralRules'] = [];
}
if ( $allData['compiledPluralRules'] === null ) {
$allData['compiledPluralRules'] = [];
}
$allData['pluralRules'] ??= [];
$allData['compiledPluralRules'] ??= [];
# If there were no plural rule types, return an empty array
if ( $allData['pluralRuleTypes'] === null ) {
$allData['pluralRuleTypes'] = [];
}
$allData['pluralRuleTypes'] ??= [];
# Set the list keys
$allData['list'] = [];

View file

@ -1471,9 +1471,7 @@ class MessageCache implements LoggerAwareInterface {
*/
public function updateMessageOverride( LinkTarget $linkTarget, Content $content = null ) {
$msgText = $this->getMessageTextFromContent( $content );
if ( $msgText === null ) {
$msgText = false; // treat as not existing
}
$msgText ??= false; // treat null as not existing
$this->replace( $linkTarget->getDBkey(), $msgText );

View file

@ -69,9 +69,7 @@ class RawMessage extends Message {
*/
public function fetchMessage() {
// Just in case the message is unset somewhere.
if ( $this->message === null ) {
$this->message = $this->key;
}
$this->message ??= $this->key;
return $this->message;
}

View file

@ -147,9 +147,7 @@ abstract class GenericArrayObject extends ArrayObject {
);
}
if ( $index === null ) {
$index = $this->getNewOffset();
}
$index ??= $this->getNewOffset();
if ( $this->preSetElement( $index, $value ) ) {
parent::offsetSet( $index, $value );

View file

@ -153,9 +153,7 @@ class WRStatsReader {
* @return float|int
*/
private function now() {
if ( $this->now === null ) {
$this->now = microtime( true );
}
$this->now ??= microtime( true );
return $this->now;
}

View file

@ -97,9 +97,7 @@ class WRStatsWriter {
* @return float|int
*/
private function now() {
if ( $this->now === null ) {
$this->now = microtime( true );
}
$this->now ??= microtime( true );
return $this->now;
}

View file

@ -360,14 +360,12 @@ abstract class FileOp {
$status = StatusValue::newGood();
// Record the size of source file/string
$this->sourceSize = $this->getSourceSize(); // FS file or data string
if ( $this->sourceSize === null ) { // file in storage?
$this->sourceSize = $this->fileSize( $this->params['src'], $predicates );
}
// file in storage?
$this->sourceSize ??= $this->fileSize( $this->params['src'], $predicates );
// Record the hash of source file/string
$this->sourceSha1 = $this->getSourceSha1Base36(); // FS file or data string
if ( $this->sourceSha1 === null ) { // file in storage?
$this->sourceSha1 = $this->fileSha1( $this->params['src'], $predicates );
}
// file in storage?
$this->sourceSha1 ??= $this->fileSha1( $this->params['src'], $predicates );
// Record the existence of destination file
$this->destExists = $this->fileExists( $this->params['dst'], $predicates );
// Check if an incompatible file exists at the destination

View file

@ -127,9 +127,7 @@ class MultiHttpClient implements LoggerAwareInterface {
$this->$key = $options[$key];
}
}
if ( $this->logger === null ) {
$this->logger = new NullLogger;
}
$this->logger ??= new NullLogger;
}
/**

View file

@ -1101,9 +1101,7 @@ class MimeAnalyzer implements LoggerAwareInterface {
* @return IEContentAnalyzer
*/
protected function getIEContentAnalyzer(): IEContentAnalyzer {
if ( $this->IEAnalyzer === null ) {
$this->IEAnalyzer = new IEContentAnalyzer;
}
$this->IEAnalyzer ??= new IEContentAnalyzer;
return $this->IEAnalyzer;
}
}

View file

@ -882,9 +882,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
if ( !$sqls ) {
return [];
}
if ( $summarySql === null ) {
$summarySql = reset( $sqls );
}
$summarySql ??= reset( $sqls );
// Make sure that this caller is allowed to issue these query statements
foreach ( $sqls as $sql ) {
$this->assertQueryIsCurrentlyAllowed( $sql, $fname );

View file

@ -199,9 +199,7 @@ class DatabaseDomain {
* @return string
*/
public function getId(): string {
if ( $this->equivalentString === null ) {
$this->equivalentString = $this->convertToString();
}
$this->equivalentString ??= $this->convertToString();
return $this->equivalentString;
}

View file

@ -137,9 +137,7 @@ abstract class ResultWrapper implements IResultWrapper {
#[\ReturnTypeWillChange]
public function current() {
if ( $this->currentRow === null ) {
$this->currentRow = $this->fetchObject();
}
$this->currentRow ??= $this->fetchObject();
return $this->currentRow;
}
@ -158,9 +156,7 @@ abstract class ResultWrapper implements IResultWrapper {
}
public function getFieldNames() {
if ( $this->fieldNames === null ) {
$this->fieldNames = $this->doGetFieldNames();
}
$this->fieldNames ??= $this->doGetFieldNames();
return $this->fieldNames;
}
}

View file

@ -87,9 +87,7 @@ class LBFactorySimple extends LBFactory {
}
public function getMainLB( $domain = false ): ILoadBalancer {
if ( $this->mainLB === null ) {
$this->mainLB = $this->newMainLB( $domain );
}
$this->mainLB ??= $this->newMainLB( $domain );
return $this->mainLB;
}

View file

@ -204,9 +204,7 @@ class LinkRenderer {
'href' => $url,
] + $this->mergeAttribs( $attribs, $extraAttribs );
if ( $text === null ) {
$text = $this->getLinkText( $target );
}
$text ??= $this->getLinkText( $target );
return $this->buildAElement( $target, $text, $attribs, true );
}
@ -293,9 +291,7 @@ class LinkRenderer {
'href' => $url,
] + $this->mergeAttribs( $attribs, $extraAttribs );
if ( $text === null ) {
$text = $this->getLinkText( $target );
}
$text ??= $this->getLinkText( $target );
return $this->buildAElement( $target, $text, $attribs, false );
}

View file

@ -1825,9 +1825,7 @@ class Linker {
IContextSource $context = null,
$options = [ 'verify' ]
) {
if ( $context === null ) {
$context = RequestContext::getMain();
}
$context ??= RequestContext::getMain();
$editCount = false;
if ( in_array( 'verify', $options, true ) ) {
@ -1959,9 +1957,7 @@ class Linker {
// To config which pages are affected by miser mode
$disableRollbackEditCountSpecialPage = [ 'Recentchanges', 'Watchlist' ];
if ( $context === null ) {
$context = RequestContext::getMain();
}
$context ??= RequestContext::getMain();
$title = $revRecord->getPageAsLinkTarget();
$revUser = $revRecord->getUser();

View file

@ -54,9 +54,7 @@ class LegacyLogFormatter extends LogFormatter {
private $revert = null;
public function getComment() {
if ( $this->comment === null ) {
$this->comment = parent::getComment();
}
$this->comment ??= parent::getComment();
// Make sure we execute the LogLine hook so that we immediately return
// the correct value.

View file

@ -285,9 +285,7 @@ class ManualLogEntry extends LogEntryBase implements Taggable {
public function insert( IDatabase $dbw = null ) {
$dbw = $dbw ?: wfGetDB( DB_PRIMARY );
if ( $this->timestamp === null ) {
$this->timestamp = wfTimestampNow();
}
$this->timestamp ??= wfTimestampNow();
$actorId = MediaWikiServices::getInstance()->getActorStore()
->acquireActorId( $this->getPerformerIdentity(), $dbw );