* $wgPopularPasswordFile — The location of the default popular passwords file
has been moved to be in line with other non-PHP files used by libraries and
classes.
+* $wgEnableImageWhitelist is now disabled by default, as it opens up a hole for
+ potential privacy leaks by administrators. You can check
+ "MediaWiki:External image whitelist" on your wiki to see whether the feature
+ was ever used, and whether it needs to be re-enabled.
==== Removed configuration ====
* $wgEnableAPI and $wgEnableWriteAPI – These settings, deprecated in 1.31,
=== Configuration changes in 1.33 ===
==== New configuration ====
+* $wgEnablePartialBlocks – This enables the Partial Blocks feature, which gives
+ accounts with block permissions the ability to block users, IPs, and IP ranges
+ from editing specific pages, while allowing them to edit the rest of the wiki.
* …
==== Changed configuration ====
*
* Set this to true to enable the on-wiki whitelist (MediaWiki:External image whitelist)
* Or false to disable it
+ *
+ * @since 1.14
*/
-$wgEnableImageWhitelist = true;
+$wgEnableImageWhitelist = false;
/**
* A different approach to the above: simply allow the "<img>" tag to be used.
private $config;
/**
- * @var String Cache what action this request is
+ * @var string Cache what action this request is
*/
private $action;
* @return CryptRand
*/
public function getCryptRand() {
+ wfDeprecated( __METHOD__, '1.32' );
return $this->getService( 'CryptRand' );
}
* or else addWikiTextAsContent() if $interface is false.
*/
public function addWikiText( $text, $linestart = true, $interface = true ) {
+ wfDeprecated( __METHOD__, '1.32' );
$title = $this->getTitle();
if ( !$title ) {
throw new MWException( 'Title is null' );
) {
global $wgParser;
+ if ( !$tidy ) {
+ wfDeprecated( 'disabling tidy', '1.32' );
+ }
+
$popts = $this->parserOptions();
$oldTidy = $popts->setTidy( $tidy );
$popts->setInterfaceMessage( (bool)$interface );
* Helper function to setup the PHP implementation of OOUI to use in this request.
*
* @since 1.26
- * @param String $skinName The Skin name to determine the correct OOUI theme
- * @param String $dir Language direction
+ * @param string $skinName The Skin name to determine the correct OOUI theme
+ * @param string $dir Language direction
*/
public static function setupOOUI( $skinName = 'default', $dir = 'ltr' ) {
$themes = ResourceLoaderOOUIModule::getSkinThemeMap();
* This mimicks the behavior of EditPage in formatting a summary
*
* @param Title $title of the page being parsed
- * @param Array $params the API parameters of the request
+ * @param array $params The API parameters of the request
* @return Content|bool
*/
private function formatSummary( $title, $params ) {
$this->limit = 1;
}
}
- if ( isset( $params['section'] ) ) {
- $this->section = $params['section'];
- } else {
- $this->section = false;
- }
+ $this->section = $params['section'] ?? false;
}
$userMax = $this->parseContent ? 1 : ( $smallLimit ? ApiBase::LIMIT_SML1 : ApiBase::LIMIT_BIG1 );
$this->dieStatus( $this->errorArrayToStatus( $retval, $user ) );
}
- $watch = 'preferences';
- if ( isset( $params['watchlist'] ) ) {
- $watch = $params['watchlist'];
- }
+ $watch = $params['watchlist'] ?? 'preferences';
// Watch pages
$this->setWatch( $watch, $titleObj, 'watchrollback' );
}
public function getDomain() {
- if ( isset( $this->domain ) ) {
- return $this->domain;
- } else {
- return 'invaliddomain';
- }
+ return $this->domain ?? 'invaliddomain';
}
public function validDomain( $domain ) {
/**
* Returns check key for the backlinks cache for a particular title
*
- * @return String
+ * @return string
*/
private function makeCheckKey() {
return $this->wanCache->makeKey(
function __construct( $conf = [] ) {
global $wgCacheDirectory;
- if ( isset( $conf['directory'] ) ) {
- $this->directory = $conf['directory'];
- } else {
- $this->directory = $wgCacheDirectory;
- }
+ $this->directory = $conf['directory'] ?? $wgCacheDirectory;
}
public function get( $code, $key ) {
public function __construct( $conf = [] ) {
global $wgCacheDirectory;
- if ( isset( $conf['directory'] ) ) {
- $this->directory = $conf['directory'];
- } else {
- $this->directory = $wgCacheDirectory;
- }
+ $this->directory = $conf['directory'] ?? $wgCacheDirectory;
}
public function startWrite( $code ) {
$this->showHide = $filterDefinition['showHide'];
}
- if ( isset( $filterDefinition['isReplacedInStructuredUi'] ) ) {
- $this->isReplacedInStructuredUi = $filterDefinition['isReplacedInStructuredUi'];
- } else {
- $this->isReplacedInStructuredUi = false;
- }
+ $this->isReplacedInStructuredUi = $filterDefinition['isReplacedInStructuredUi'] ?? false;
if ( isset( $filterDefinition['default'] ) ) {
$this->setDefault( $filterDefinition['default'] );
$this->queryCallable = $filterDefinition['queryCallable'];
}
- if ( isset( $filterDefinition['activeValue'] ) ) {
- $this->activeValue = $filterDefinition['activeValue'];
- } else {
- $this->activeValue = true;
- }
+ $this->activeValue = $filterDefinition['activeValue'] ?? true;
}
/**
}
$this->type = $groupDefinition['type'];
- if ( isset( $groupDefinition['priority'] ) ) {
- $this->priority = $groupDefinition['priority'];
- } else {
- $this->priority = self::DEFAULT_PRIORITY;
- }
+ $this->priority = $groupDefinition['priority'] ?? self::DEFAULT_PRIORITY;
$this->isFullCoverage = $groupDefinition['isFullCoverage'];
foreach ( $tagsToAdd as $tag ) {
$changeTagMapping[$tag] = $changeTagDefStore->acquireId( $tag );
}
-
- $dbw->update(
- 'change_tag_def',
- [ 'ctd_count = ctd_count + 1' ],
- [ 'ctd_name' => $tagsToAdd ],
- __METHOD__
- );
+ // T207881: update the counts at the end of the transaction
+ $dbw->onTransactionPreCommitOrIdle( function () use ( $dbw, $tagsToAdd ) {
+ $dbw->update(
+ 'change_tag_def',
+ [ 'ctd_count = ctd_count + 1' ],
+ [ 'ctd_name' => $tagsToAdd ],
+ __METHOD__
+ );
+ } );
}
$tagsRows = [];
);
$dbw->delete( 'change_tag', $conds, __METHOD__ );
if ( $dbw->affectedRows() && $wgChangeTagsSchemaMigrationStage > MIGRATION_OLD ) {
- $dbw->update(
- 'change_tag_def',
- [ 'ctd_count = ctd_count - 1' ],
- [ 'ctd_name' => $tag ],
- __METHOD__
- );
-
- $dbw->delete(
- 'change_tag_def',
- [ 'ctd_name' => $tag, 'ctd_count' => 0, 'ctd_user_defined' => 0 ],
- __METHOD__
- );
+ // T207881: update the counts at the end of the transaction
+ $dbw->onTransactionPreCommitOrIdle( function () use ( $dbw, $tag ) {
+ $dbw->update(
+ 'change_tag_def',
+ [ 'ctd_count = ctd_count - 1' ],
+ [ 'ctd_name' => $tag ],
+ __METHOD__
+ );
+
+ $dbw->delete(
+ 'change_tag_def',
+ [ 'ctd_name' => $tag, 'ctd_count' => 0, 'ctd_user_defined' => 0 ],
+ __METHOD__
+ );
+ } );
}
}
}
* @param array $records List of records to append
*/
protected function addMessages( $channel, array $records ) {
- if ( isset( $this->options['alias'][$channel] ) ) {
- $topic = $this->options['alias'][$channel];
- } else {
- $topic = "monolog_$channel";
- }
+ $topic = $this->options['alias'][$channel] ?? "monolog_$channel";
$partition = $this->getRandomPartition( $topic );
if ( $partition !== null ) {
$this->produce->setMessages( $topic, $partition, $records );
/**
* Combines the passed element with a button.
- * @param String $element Element to combine the button with.
- * @return String
+ * @param string $element Element to combine the button with.
+ * @return string
*/
public function getElement( $element ) {
return $element . "\u{00A0}" . $this->getInputHTML( '' );
}
public function getDefault() {
- if ( isset( $this->mDefault ) ) {
- return $this->mDefault;
- } else {
- return [];
- }
+ return $this->mDefault ?? [];
}
public function filterDataForSubmit( $data ) {
$this->url = wfExpandUrl( $url, PROTO_HTTP );
$this->parsedUrl = wfParseUrl( $this->url );
- if ( isset( $options['logger'] ) ) {
- $this->logger = $options['logger'];
- } else {
- $this->logger = new NullLogger();
- }
+ $this->logger = $options['logger'] ?? new NullLogger();
if ( !$this->parsedUrl || !Http::isValidURI( $this->url ) ) {
$this->status = StatusValue::newFatal( 'http-invalid-url', $url );
$revision->setText( $text );
}
- if ( isset( $revisionInfo['timestamp'] ) ) {
- $revision->setTimestamp( $revisionInfo['timestamp'] );
- } else {
- $revision->setTimestamp( wfTimestampNow() );
- }
+ $revision->setTimestamp( $revisionInfo['timestamp'] ?? wfTimestampNow() );
if ( isset( $revisionInfo['comment'] ) ) {
$revision->setComment( $revisionInfo['comment'] );
// This will automatically add "AutoloadClasses" to $wgAutoloadClasses
$data = $registry->readFromQueue( $queue );
- $hooks = [];
- if ( isset( $data['globals']['wgHooks']['LoadExtensionSchemaUpdates'] ) ) {
- $hooks = $data['globals']['wgHooks']['LoadExtensionSchemaUpdates'];
- }
+ $hooks = $data['globals']['wgHooks']['LoadExtensionSchemaUpdates'] ?? [];
if ( $vars && isset( $vars['wgHooks']['LoadExtensionSchemaUpdates'] ) ) {
$hooks = array_merge_recursive( $hooks, $vars['wgHooks']['LoadExtensionSchemaUpdates'] );
}
* @return mixed
*/
public function getVar( $name, $default = null ) {
- if ( !isset( $this->settings[$name] ) ) {
- return $default;
- } else {
- return $this->settings[$name];
- }
+ return $this->settings[$name] ?? $default;
}
/**
$data = $registry->readFromQueue( $queue );
$wgAutoloadClasses += $data['autoload'];
- $hooksWeWant = isset( $wgHooks['LoadExtensionSchemaUpdates'] ) ?
- /** @suppress PhanUndeclaredVariable $wgHooks is set by DefaultSettings */
- $wgHooks['LoadExtensionSchemaUpdates'] : [];
+ /** @suppress PhanUndeclaredVariable $wgHooks is set by DefaultSettings */
+ $hooksWeWant = $wgHooks['LoadExtensionSchemaUpdates'] ?? [];
if ( isset( $data['globals']['wgHooks']['LoadExtensionSchemaUpdates'] ) ) {
$hooksWeWant = array_merge_recursive(
$existingSchema = false;
$this->parent->showMessage( 'config-unknown-collation' );
}
- if ( isset( $row->Engine ) ) {
- $existingEngine = $row->Engine;
- } else {
- $existingEngine = $row->Type;
- }
+ $existingEngine = $row->Engine ?? $row->Type;
}
} else {
$existingSchema = false;
return $this->session;
}
- if ( isset( $session['happyPages'] ) ) {
- $this->happyPages = $session['happyPages'];
- } else {
- $this->happyPages = [];
- }
+ $this->happyPages = $session['happyPages'] ?? [];
- if ( isset( $session['skippedPages'] ) ) {
- $this->skippedPages = $session['skippedPages'];
- } else {
- $this->skippedPages = [];
- }
+ $this->skippedPages = $session['skippedPages'] ?? [];
$lowestUnhappy = $this->getLowestUnhappy();
* @return array
*/
public function getSession( $name, $default = null ) {
- if ( !isset( $this->session[$name] ) ) {
- return $default;
- } else {
- return $this->session[$name];
- }
+ return $this->session[$name] ?? $default;
}
/**
if ( !isset( $params['labelAttribs'] ) ) {
$params['labelAttribs'] = [];
}
- if ( isset( $params['rawtext'] ) ) {
- $labelText = $params['rawtext'];
- } else {
- $labelText = $this->parse( wfMessage( $params['label'] )->text() );
- }
+ $labelText = $params['rawtext'] ?? $this->parse( wfMessage( $params['label'] )->text() );
return "<div class=\"config-input-check\">\n" .
$params['help'] .
public function getRadioSet( $params ) {
$items = $this->getRadioElements( $params );
- if ( !isset( $params['label'] ) ) {
- $label = '';
- } else {
- $label = $params['label'];
- }
+ $label = $params['label'] ?? '';
if ( !isset( $params['controlName'] ) ) {
$params['controlName'] = 'config_' . $params['var'];
return $status;
}
- if ( isset( $vars['wgDBadminuser'] ) ) {
- $this->setVar( '_InstallUser', $vars['wgDBadminuser'] );
- } else {
- $this->setVar( '_InstallUser', $vars['wgDBuser'] );
- }
- if ( isset( $vars['wgDBadminpassword'] ) ) {
- $this->setVar( '_InstallPassword', $vars['wgDBadminpassword'] );
- } else {
- $this->setVar( '_InstallPassword', $vars['wgDBpassword'] );
- }
+ $this->setVar( '_InstallUser', $vars['wgDBadminuser'] ?? $vars['wgDBuser'] );
+ $this->setVar( '_InstallPassword', $vars['wgDBadminpassword'] ?? $vars['wgDBpassword'] );
// Test the database connection
$status = $installer->getConnection();
// config-license-cc-0, config-license-pd, config-license-gfdl, config-license-none,
// config-license-cc-choose
$entry = $this->parent->licenses[$code];
- if ( isset( $entry['text'] ) ) {
- $this->setVar( 'wgRightsText', $entry['text'] );
- } else {
- $this->setVar( 'wgRightsText', wfMessage( 'config-license-' . $code )->text() );
- }
+ $this->setVar( 'wgRightsText',
+ $entry['text'] ?? wfMessage( 'config-license-' . $code )->text() );
$this->setVar( 'wgRightsUrl', $entry['url'] );
$this->setVar( 'wgRightsIcon', $entry['icon'] );
} else {
global $wgJobTypeConf;
$conf = [ 'wiki' => $this->wiki, 'type' => $type ];
- if ( isset( $wgJobTypeConf[$type] ) ) {
- $conf = $conf + $wgJobTypeConf[$type];
- } else {
- $conf = $conf + $wgJobTypeConf['default'];
- }
+ $conf += $wgJobTypeConf[$type] ?? $wgJobTypeConf['default'];
$conf['aggregator'] = JobQueueAggregator::singleton();
if ( !isset( $conf['readOnlyReason'] ) ) {
$conf['readOnlyReason'] = $this->readOnlyReason;
public static function getMimeType( $file ) {
// Infer the MIME-type from the file extension
$ext = strtolower( pathinfo( $file, PATHINFO_EXTENSION ) );
- if ( isset( self::$mimeTypes[$ext] ) ) {
- return self::$mimeTypes[$ext];
- }
-
- return mime_content_type( realpath( $file ) );
+ return self::$mimeTypes[$ext] ?? mime_content_type( realpath( $file ) );
}
/**
$this->expires = strtotime( $attr['expires'] );
}
- if ( isset( $attr['path'] ) ) {
- $this->path = $attr['path'];
- } else {
- $this->path = '/';
- }
+ $this->path = $attr['path'] ?? '/';
if ( isset( $attr['domain'] ) ) {
if ( self::validateCookieDomain( $attr['domain'] ) ) {
* @return string
*/
protected function initialRandomState() {
+ wfDeprecated( __METHOD__, '1.32' );
return '';
}
* @author Tim Starling
*/
protected function driftHash( $data ) {
+ wfDeprecated( __METHOD__, '1.32' );
return '';
}
* @return string A new weak random state
*/
protected function randomState() {
+ wfDeprecated( __METHOD__, '1.32' );
return '';
}
* @return bool Always true
*/
public function wasStrong() {
+ wfDeprecated( __METHOD__, '1.32' );
return true;
}
* @return string Raw binary random data
*/
public function generate( $bytes ) {
+ wfDeprecated( __METHOD__, '1.32' );
$bytes = floor( $bytes );
return random_bytes( $bytes );
}
* @return string Hexadecimal random data
*/
public function generateHex( $chars ) {
+ wfDeprecated( __METHOD__, '1.32' );
return MWCryptRand::generateHex( $chars );
}
}
* Returns minified JavaScript code.
*
* @param string $s JavaScript code to minify
- * @return String Minified code
+ * @return string Minified code
*/
public static function minify( $s ) {
// First we declare a few tables that contain our parsing rules
$xml = new XmlTypeCheck( $file );
if ( $xml->wellFormed ) {
$xmlTypes = $this->xmlTypes;
- if ( isset( $xmlTypes[$xml->getRootElement()] ) ) {
- return $xmlTypes[$xml->getRootElement()];
- } else {
- return 'application/xml';
- }
+ return $xmlTypes[$xml->getRootElement()] ?? 'application/xml';
}
/**
* @param array $params
*/
public function __construct( array $params = [] ) {
- if ( isset( $params['logger'] ) ) {
- $this->setLogger( $params['logger'] );
- } else {
- $this->setLogger( new NullLogger() );
- }
+ $this->setLogger( $params['logger'] ?? new NullLogger() );
if ( isset( $params['keyspace'] ) ) {
$this->keyspace = $params['keyspace'];
$this->serverTagMap[is_int( $key ) ? $server : $key] = $server;
}
- if ( isset( $params['automaticFailover'] ) ) {
- $this->automaticFailover = $params['automaticFailover'];
- } else {
- $this->automaticFailover = true;
- }
+ $this->automaticFailover = $params['automaticFailover'] ?? true;
$this->attrMap[self::ATTR_SYNCWRITES] = self::QOS_SYNCWRITES_NONE;
}
*/
public function getServerVersion() {
$server_info = sqlsrv_server_info( $this->conn );
- $version = 'Error';
- if ( isset( $server_info['SQLServerVersion'] ) ) {
- $version = $server_info['SQLServerVersion'];
- }
+ $version = $server_info['SQLServerVersion'] ?? 'Error';
return $version;
}
return $this->lastSection;
}
list( $dbName, ) = $this->getDBNameAndPrefix( $domain );
- if ( isset( $this->sectionsByDB[$dbName] ) ) {
- $section = $this->sectionsByDB[$dbName];
- } else {
- $section = 'DEFAULT';
- }
+ $section = $this->sectionsByDB[$dbName] ?? 'DEFAULT';
$this->lastSection = $section;
$this->lastDomain = $domain;
public function newMainLB( $domain = false ) {
list( $dbName, ) = $this->getDBNameAndPrefix( $domain );
$section = $this->getSectionForDomain( $domain );
- if ( isset( $this->groupLoadsByDB[$dbName] ) ) {
- $groupLoads = $this->groupLoadsByDB[$dbName];
- } else {
- $groupLoads = [];
- }
+ $groupLoads = $this->groupLoadsByDB[$dbName] ?? [];
if ( isset( $this->groupLoadsBySection[$section] ) ) {
$groupLoads = array_merge_recursive(
if ( isset( $groupLoadsByServer[$serverName] ) ) {
$serverInfo['groupLoads'] = $groupLoadsByServer[$serverName];
}
- if ( isset( $this->hostsByName[$serverName] ) ) {
- $serverInfo['host'] = $this->hostsByName[$serverName];
- } else {
- $serverInfo['host'] = $serverName;
- }
+ $serverInfo['host'] = $this->hostsByName[$serverName] ?? $serverName;
$serverInfo['hostName'] = $serverName;
$serverInfo['load'] = $load;
$serverInfo += [ 'flags' => IDatabase::DBO_DEFAULT ];
$this->maxLag = $params['maxLag'];
}
- if ( isset( $params['loadMonitor'] ) ) {
- $this->loadMonitorConfig = $params['loadMonitor'];
- } else {
- $this->loadMonitorConfig = [ 'class' => 'LoadMonitorNull' ];
- }
+ $this->loadMonitorConfig = $params['loadMonitor'] ?? [ 'class' => 'LoadMonitorNull' ];
$this->loadMonitorConfig += [ 'lagWarnThreshold' => $this->maxLag ];
foreach ( $params['servers'] as $i => $server ) {
}
}
- if ( isset( $params['srvCache'] ) ) {
- $this->srvCache = $params['srvCache'];
- } else {
- $this->srvCache = new EmptyBagOStuff();
- }
- if ( isset( $params['wanCache'] ) ) {
- $this->wanCache = $params['wanCache'];
- } else {
- $this->wanCache = WANObjectCache::newEmpty();
- }
+ $this->srvCache = $params['srvCache'] ?? new EmptyBagOStuff();
+ $this->wanCache = $params['wanCache'] ?? WANObjectCache::newEmpty();
$this->profiler = $params['profiler'] ?? null;
- if ( isset( $params['trxProfiler'] ) ) {
- $this->trxProfiler = $params['trxProfiler'];
- } else {
- $this->trxProfiler = new TransactionProfiler();
- }
+ $this->trxProfiler = $params['trxProfiler'] ?? new TransactionProfiler();
$this->errorLogger = $params['errorLogger'] ?? function ( Exception $e ) {
trigger_error( get_class( $e ) . ': ' . $e->getMessage(), E_USER_WARNING );
}
public function getServerName( $i ) {
- if ( isset( $this->servers[$i]['hostName'] ) ) {
- $name = $this->servers[$i]['hostName'];
- } elseif ( isset( $this->servers[$i]['host'] ) ) {
- $name = $this->servers[$i]['host'];
- } else {
- $name = '';
- }
+ $name = $this->servers[$i]['hostName'] ?? $this->servers[$i]['host'] ?? '';
return ( $name != '' ) ? $name : 'localhost';
}
public function getServerInfo( $i ) {
- if ( isset( $this->servers[$i] ) ) {
- return $this->servers[$i];
- } else {
- return false;
- }
+ return $this->servers[$i] ?? false;
}
public function getServerType( $i ) {
global $wgLogActionsHandlers;
$fulltype = $entry->getFullType();
$wildcard = $entry->getType() . '/*';
- $handler = '';
-
- if ( isset( $wgLogActionsHandlers[$fulltype] ) ) {
- $handler = $wgLogActionsHandlers[$fulltype];
- } elseif ( isset( $wgLogActionsHandlers[$wildcard] ) ) {
- $handler = $wgLogActionsHandlers[$wildcard];
- }
+ $handler = $wgLogActionsHandlers[$fulltype] ?? $wgLogActionsHandlers[$wildcard] ?? '';
if ( $handler !== '' && is_string( $handler ) && class_exists( $handler ) ) {
return new $handler( $entry );
global $wgLogNames;
// BC
- if ( isset( $wgLogNames[$this->type] ) ) {
- $key = $wgLogNames[$this->type];
- } else {
- $key = 'log-name-' . $this->type;
- }
+ $key = $wgLogNames[$this->type] ?? 'log-name-' . $this->type;
return wfMessage( $key );
}
public function getDescription() {
global $wgLogHeaders;
// BC
- if ( isset( $wgLogHeaders[$this->type] ) ) {
- $key = $wgLogHeaders[$this->type];
- } else {
- $key = 'log-description-' . $this->type;
- }
+ $key = $wgLogHeaders[$this->type] ?? 'log-description-' . $this->type;
return wfMessage( $key );
}
*/
public function getRestriction() {
global $wgLogRestrictions;
- if ( isset( $wgLogRestrictions[$this->type] ) ) {
- $restriction = $wgLogRestrictions[$this->type];
- } else {
- // '' always returns true with $user->isAllowed()
- $restriction = '';
- }
-
- return $restriction;
+ // '' always returns true with $user->isAllowed()
+ return $wgLogRestrictions[$this->type] ?? '';
}
/**
case '2#055':
// Date created (not date digitized).
// Maps to exif DateTimeOriginal
- if ( isset( $parsed['2#060'] ) ) {
- $time = $parsed['2#060'];
- } else {
- $time = [];
- }
+ $time = $parsed['2#060'] ?? [];
$timestamp = self::timeHelper( $val, $time, $c );
if ( $timestamp ) {
$data['DateTimeOriginal'] = $timestamp;
case '2#062':
// Date converted to digital representation.
// Maps to exif DateTimeDigitized
- if ( isset( $parsed['2#063'] ) ) {
- $time = $parsed['2#063'];
- } else {
- $time = [];
- }
+ $time = $parsed['2#063'] ?? [];
$timestamp = self::timeHelper( $val, $time, $c );
if ( $timestamp ) {
$data['DateTimeDigitized'] = $timestamp;
case '2#030':
// Date released.
- if ( isset( $parsed['2#035'] ) ) {
- $time = $parsed['2#035'];
- } else {
- $time = [];
- }
+ $time = $parsed['2#035'] ?? [];
$timestamp = self::timeHelper( $val, $time, $c );
if ( $timestamp ) {
$data['DateTimeReleased'] = $timestamp;
case '2#037':
// Date expires.
- if ( isset( $parsed['2#038'] ) ) {
- $time = $parsed['2#038'];
- } else {
- $time = [];
- }
+ $time = $parsed['2#038'] ?? [];
$timestamp = self::timeHelper( $val, $time, $c );
if ( $timestamp ) {
$data['DateTimeExpires'] = $timestamp;
/**
* Converts a dimensions array about a potentially multipage document from an
* exhaustive list of ordered page numbers to a list of page ranges
- * @param Array $pagesByDimensions
- * @return String
+ * @param array $pagesByDimensions
+ * @return string
* @since 1.30
*/
public static function getPageRangesByDimensions( $pagesByDimensions ) {
* @throws InvalidArgumentException
*/
public static function newFromParams( $params ) {
- if ( isset( $params['loggroup'] ) ) {
- $params['logger'] = LoggerFactory::getInstance( $params['loggroup'] );
- } else {
- $params['logger'] = LoggerFactory::getInstance( 'objectcache' );
- }
+ $params['logger'] = LoggerFactory::getInstance( $params['loggroup'] ?? 'objectcache' );
if ( !isset( $params['keyspace'] ) ) {
$params['keyspace'] = self::getDefaultKeyspace();
}
}
}
$params['cache'] = self::newFromParams( $params['store'] );
- if ( isset( $params['loggroup'] ) ) {
- $params['logger'] = LoggerFactory::getInstance( $params['loggroup'] );
- } else {
- $params['logger'] = LoggerFactory::getInstance( 'objectcache' );
- }
+ $params['logger'] = LoggerFactory::getInstance( $params['loggroup'] ?? 'objectcache' );
if ( !$wgCommandLineMode ) {
// Send the statsd data post-send on HTTP requests; avoid in CLI mode (T181385)
$params['stats'] = $services->getStatsdDataFactory();
*/
private function replace( $matches ) {
# Extract information from $matches
- $linked = true;
- if ( isset( $this->mLinked ) ) {
- $linked = $this->mLinked;
- }
+ $linked = $this->mLinked ?? true;
$bits = [];
$key = $this->keys[$this->mSource];
* or null if no value was set for this key.
*/
public function getExtensionData( $key ) {
- if ( isset( $this->mExtensionData[$key] ) ) {
- return $this->mExtensionData[$key];
- }
-
- return null;
+ return $this->mExtensionData[$key] ?? null;
}
private static function getTimes( $clock = null ) {
* @return string|bool
*/
public function getArgument( $index ) {
- if ( !isset( $this->args[$index] ) ) {
- return false;
- }
- return $this->args[$index];
+ return $this->args[$index] ?? false;
}
public function getArguments() {
* @return string|bool
*/
public function getArgument( $index ) {
- if ( !isset( $this->args[$index] ) ) {
- return false;
- }
- return $this->args[$index];
+ return $this->args[$index] ?? false;
}
public function getArguments() {
continue;
}
- if ( isset( $userGroupMemberships[$ueg] ) ) {
- $groupStringOrObject = $userGroupMemberships[$ueg];
- } else {
- $groupStringOrObject = $ueg;
- }
+ $groupStringOrObject = $userGroupMemberships[$ueg] ?? $ueg;
$userG = UserGroupMembership::getLink( $groupStringOrObject, $context, 'html' );
$userM = UserGroupMembership::getLink( $groupStringOrObject, $context, 'html',
* @param string $dir
*/
protected function extractConfig2( array $info, $dir ) {
- if ( isset( $info['config_prefix'] ) ) {
- $prefix = $info['config_prefix'];
- } else {
- $prefix = 'wg';
- }
+ $prefix = $info['config_prefix'] ?? 'wg';
if ( isset( $info['config'] ) ) {
foreach ( $info['config'] as $key => $data ) {
$value = $data['value'];
$object->setConfig( $this->getConfig() );
$object->setLogger( $this->logger );
} else {
- if ( !isset( $info['class'] ) ) {
- $class = ResourceLoaderFileModule::class;
- } else {
- $class = $info['class'];
- }
+ $class = $info['class'] ?? ResourceLoaderFileModule::class;
/** @var ResourceLoaderModule $object */
$object = new $class( $info );
$object->setConfig( $this->getConfig() );
* - new XmlJsCode( '{}' )
* - new stdClass() // (object) []
*
- * @param Array $array
+ * @param array $array
*/
private static function trimArray( array &$array ) {
$i = count( $array );
* @return mixed the feature value or null if unset
*/
public function getFeatureData( $feature ) {
- if ( isset( $this->features[$feature] ) ) {
- return $this->features[$feature];
- }
- return null;
+ return $this->features[$feature] ?? null;
}
/**
// Give site config file a chance to run the script in a wrapper.
// The caller may likely want to call wfBasename() on $script.
Hooks::run( 'wfShellWikiCmd', [ &$script, &$parameters, &$options ] );
- $cmd = isset( $options['php'] ) ? [ $options['php'] ] : [ $wgPhpCli ];
+ $cmd = [ $options['php'] ?? $wgPhpCli ];
if ( isset( $options['wrapper'] ) ) {
$cmd[] = $options['wrapper'];
}
* @return Site|null
*/
public function getSite( $globalId, $source = 'cache' ) {
- if ( isset( $this->sites[$globalId] ) ) {
- return $this->sites[$globalId];
- } else {
- return null;
- }
+ return $this->sites[$globalId] ?? null;
}
/**
* @return string
*/
function makeLink( $key, $item, $options = [] ) {
- if ( isset( $item['text'] ) ) {
- $text = $item['text'];
- } else {
- $text = wfMessage( $item['msg'] ?? $key )->text();
- }
+ $text = $item['text'] ?? wfMessage( $item['msg'] ?? $key )->text();
$html = htmlspecialchars( $text );
* @return Title
*/
public function getRelevantTitle() {
- if ( isset( $this->mRelevantTitle ) ) {
- return $this->mRelevantTitle;
- }
- return $this->getTitle();
+ return $this->mRelevantTitle ?? $this->getTitle();
}
/**
/**
* Fetch the change tags list for the front end
*
- * @return Array Tag data
+ * @return array Tag data
*/
protected function getChangeTagList() {
$cache = ObjectCache::getMainWANInstance();
$caseFoldedAlias = $this->contLang->caseFold( $bits[0] );
$caseFoldedAlias = str_replace( ' ', '_', $caseFoldedAlias );
$aliases = $this->getAliasList();
- if ( isset( $aliases[$caseFoldedAlias] ) ) {
- $name = $aliases[$caseFoldedAlias];
- } else {
+ if ( !isset( $aliases[$caseFoldedAlias] ) ) {
return [ null, null ];
}
-
- if ( !isset( $bits[1] ) ) { // T4087
- $par = null;
- } else {
- $par = $bits[1];
- }
+ $name = $aliases[$caseFoldedAlias];
+ $par = $bits[1] ?? null; // T4087
return [ $name, $par ];
}
// @todo FIXME: Redirects broken due to this call
$bits = explode( '/', $title->getDBkey(), 2 );
$name = $bits[0];
- if ( !isset( $bits[1] ) ) { // T4087
- $par = null;
- } else {
- $par = $bits[1];
- }
+ $par = $bits[1] ?? null; // T4087
$page = $this->getPage( $name );
if ( !$page ) {
}
/**
- * @return String
+ * @return string
*/
protected function getGroupName() {
return 'redirects';
*
* It's important that img_media_type come first, otherwise the
* tables will be fragmented.
- * @return Array Fields to sort by
+ * @return array Fields to sort by
*/
function getOrderFields() {
return [ 'img_media_type', 'count(*)', 'img_major_mime', 'img_minor_mime' ];
/**
* @param float $decimal A decimal percentage (ie for 12.3%, this would be 0.123)
- * @return String The percentage formatted so that 3 significant digits are shown.
+ * @return string The percentage formatted so that 3 significant digits are shown.
*/
protected function makePercentPretty( $decimal ) {
$decimal *= 100;
/**
* Get (not output) the header row for the table
*
- * @return String the header row of the able
+ * @return string The header row of the table
*/
protected function getTableHeaderRow() {
$headers = [ 'mimetype', 'extensions', 'count', 'totalbytes' ];
* @param UserGroupMembership[] $usergroups Associative array of (group name as string =>
* UserGroupMembership object) for groups the user belongs to
* @param User $user
- * @return Array with 2 elements: the XHTML table element with checkxboes, and
+ * @return array Array with 2 elements: the XHTML table element with checkxboes, and
* whether any groups are changeable
*/
private function groupCheckboxes( $usergroups, $user ) {
$label = Html::rawElement( 'label', [ 'for' => $id ], $this->mLabel );
if ( !empty( $this->mParams['radio'] ) ) {
- if ( isset( $this->mParams['radio-id'] ) ) {
- $radioId = $this->mParams['radio-id'];
- } else {
+ $radioId = $this->mParams['radio-id'] ??
// Old way. For the benefit of extensions that do not define
// the 'radio-id' key.
- $radioId = 'wpSourceType' . $this->mParams['upload-type'];
- }
+ 'wpSourceType' . $this->mParams['upload-type'];
$attribs = [
'name' => 'wpSourceType',
self::WINDOWS_NONASCII_FILENAME => 'windows-nonascii-filename',
self::FILENAME_TOO_LONG => 'filename-toolong',
];
- if ( isset( $code_to_status[$error] ) ) {
- return $code_to_status[$error];
- }
-
- return 'unknown-error';
+ return $code_to_status[$error] ?? 'unknown-error';
}
/**
*/
public static function getDefaultOption( $opt ) {
$defOpts = self::getDefaultOptions();
- if ( isset( $defOpts[$opt] ) ) {
- return $defOpts[$opt];
- } else {
- return null;
- }
+ return $defOpts[$opt] ?? null;
}
/**
* @return CryptRand
*/
protected static function singleton() {
+ wfDeprecated( __METHOD__, '1.32' );
return MediaWikiServices::getInstance()->getCryptRand();
}
* @return bool Always true
*/
public static function wasStrong() {
+ wfDeprecated( __METHOD__, '1.32' );
return true;
}
* @return string Raw binary random data
*/
public static function generate( $bytes ) {
+ wfDeprecated( __METHOD__, '1.32' );
return random_bytes( floor( $bytes ) );
}
# NOTE: $gis[2] contains a code for the image type. This is no longer used.
$info['width'] = $gis[0];
$info['height'] = $gis[1];
- if ( isset( $gis['bits'] ) ) {
- $info['bits'] = $gis['bits'];
- } else {
- $info['bits'] = 0;
- }
+ $info['bits'] = $gis['bits'] ?? 0;
return $info;
}
$interwiki = $this->iwLookup->fetch( $iwPrefix );
$parsed = wfParseUrl( wfExpandUrl( $interwiki ? $interwiki->getURL() : '/' ) );
- if ( isset( $this->customCaptions[$iwPrefix] ) ) {
- $caption = $this->customCaptions[$iwPrefix];
- } else {
- $caption = $this->specialSearch->msg( 'search-interwiki-default', $parsed['host'] )->escaped();
- }
+ $caption = $this->customCaptions[$iwPrefix] ??
+ $this->specialSearch->msg( 'search-interwiki-default', $parsed['host'] )->escaped();
$searchLink = Html::rawElement( 'em', null,
Html::rawElement( 'a', [ 'href' => $href, 'target' => '_blank' ], $caption )
*/
/**
- * Parser for rules of language conversion , parse rules in -{ }- tag.
+ * Parser for rules of language conversion, parse rules in -{ }- tag.
* @ingroup Language
* @author fdcn <fdcn64@gmail.com>, PhiLiP <philip.npc@gmail.com>
*/
public $mConverter; // LanguageConverter object
public $mRuleDisplay = '';
public $mRuleTitle = false;
- public $mRules = '';// string : the text of the rules
+ public $mRules = ''; // string : the text of the rules
public $mRulesAction = 'none';
public $mFlags = [];
public $mVariantFlags = [];
public $mConvTable = [];
- public $mBidtable = [];// array of the translation in each variant
- public $mUnidtable = [];// array of the translation in each variant
+ public $mBidtable = []; // array of the translation in each variant
+ public $mUnidtable = []; // array of the translation in each variant
/**
* @param string $text The text between -{ and }-
* @group MediaWiki
*/
class MediaWikiServicesTest extends MediaWikiTestCase {
+ private $deprecatedServices = [ 'CryptRand' ];
/**
* @return Config
$getterCases[$name] = [
'get' . $service,
$class,
+ in_array( $service, $this->deprecatedServices )
];
}
/**
* @dataProvider provideGetters
*/
- public function testGetters( $getter, $type ) {
+ public function testGetters( $getter, $type, $isDeprecated = false ) {
+ if ( $isDeprecated ) {
+ $this->hideDeprecated( MediaWikiServices::class . "::$getter" );
+ }
+
// Test against the default instance, since the dummy will not know the default services.
$services = MediaWikiServices::getInstance();
$service = $services->$getter();
$op = $this->newInstance();
$this->assertSame( '', $op->getHTML() );
+ $this->hideDeprecated( 'OutputPage::addWikiText' );
$this->hideDeprecated( 'OutputPage::addWikiTextTitle' );
$this->hideDeprecated( 'OutputPage::addWikiTextWithTitle' );
$this->hideDeprecated( 'OutputPage::addWikiTextTidy' );
$this->hideDeprecated( 'OutputPage::addWikiTextTitleTidy' );
+ $this->hideDeprecated( 'disabling tidy' );
+
if ( in_array(
$method,
[ 'addWikiTextWithTitle', 'addWikiTextTitleTidy', 'addWikiTextTitle' ]
* @covers OutputPage::addWikiText
*/
public function testAddWikiTextNoTitle() {
+ $this->hideDeprecated( 'OutputPage::addWikiText' );
$this->setExpectedException( MWException::class, 'Title is null' );
$op = $this->newInstance( [], null, 'notitle' );