* ResourceLoaderContext::getConfig and ResourceLoaderContext::getLogger have
been deprecated. Inside ResourceLoaderModule subclasses, use the local methods
instead. Elsewhere, use the methods from the ResourceLoader class.
+* The Profiler::setTemplated and Profiler::getTemplated methods have been
+ deprecated. Use Profiler::setAllowOutput and Profiler::getAllowOutput
+ instead.
* The Preprocessor_DOM implementation has been deprecated. It will be
removed in a future release. Use the Preprocessor_Hash implementation
instead.
* See LockManager::__construct() for more details.
* Additional parameters are specific to the lock manager class used.
* These settings should be global to all wikis.
- *
- * When using DBLockManager, the 'dbsByBucket' map can reference 'localDBMaster' as
- * a peer database in each bucket. This will result in an extra connection to the domain
- * that the LockManager services, which must also be a valid wiki ID.
*/
$wgLockManagers = [];
* Check permissions on special pages & namespaces
*
* @param string $action The action to check
- * @param User $user User to check
+ * @param UserIdentity $user User to check
* @param array $errors List of current errors
* @param string $rigor One of PermissionManager::RIGOR_ constants
* - RIGOR_QUICK : does cheap permission checks from replica DBs (usable for GUI creation)
*/
private function checkSpecialsAndNSPermissions(
$action,
- User $user,
+ UserIdentity $user,
$errors,
$rigor,
$short,
}
# Check $wgNamespaceProtection for restricted namespaces
- if ( $title->isNamespaceProtected( $user ) ) {
+ if ( $this->isNamespaceProtected( $title->getNamespace(), $user ) ) {
$ns = $title->getNamespace() == NS_MAIN ?
wfMessage( 'nstab-main' )->text() : $title->getNsText();
$errors[] = $title->getNamespace() == NS_MEDIAWIKI ?
return $this->allRights;
}
+ /**
+ * Determines if $user is unable to edit pages in namespace because it has been protected.
+ * @param $index
+ * @param UserIdentity $user
+ * @return bool
+ */
+ private function isNamespaceProtected( $index, UserIdentity $user ) {
+ $namespaceProtection = $this->options->get( 'NamespaceProtection' );
+ if ( isset( $namespaceProtection[$index] ) ) {
+ return !$this->userHasAllRights( $user, ...(array)$namespaceProtection[$index] );
+ }
+ return false;
+ }
+
/**
* Determine which restriction levels it makes sense to use in a namespace,
* optionally filtered by a user's rights.
* Determines if $user is unable to edit this page because it has been protected
* by $wgNamespaceProtection.
*
+ * @deprecated since 1.34 Don't use this function in new code.
* @param User $user User object to check permissions
* @return bool
*/
// Lazy-load the actual lock manager instance
if ( !isset( $this->managers[$name]['instance'] ) ) {
$class = $this->managers[$name]['class'];
+ '@phan-var string $class';
$config = $this->managers[$name]['config'];
- if ( $class === DBLockManager::class ) {
- $lb = $this->lbFactory->getMainLB( $config['domain'] );
- $config['dbServers']['localDBMaster'] = $lb->getLazyConnectionRef(
- DB_MASTER,
- [],
- $config['domain'],
- $lb::CONN_TRX_AUTOCOMMIT
- );
- $config['srvCache'] = ObjectCache::getLocalServerInstance( 'hash' );
- }
$config['logger'] = LoggerFactory::getInstance( 'LockManager' );
- // XXX Looks like phan is right, we are trying to instantiate an abstract class and it
- // throws. Did this ever work? Presumably we need to detect the right subclass? Or
- // should we just get rid of this? It looks like it never worked since it was first
- // introduced by 0cf832a3394 in 2016, so if no one's complained until now, clearly it
- // can't be very useful?
- // @phan-suppress-next-line PhanTypeInstantiateAbstract
$this->managers[$name]['instance'] = new $class( $config );
}
}
/**
- * @param string|bool $domain Domain (usually wiki ID). false for the default (normally the
- * current wiki's domain).
+ * @param string|null|false $domain Domain (usually wiki ID). false for the default (normally
+ * the current wiki's domain).
* @return LockManagerGroup
*/
public function getLockManagerGroup( $domain = false ) : LockManagerGroup {
- if ( $domain === false ) {
+ if ( $domain === false || $domain === null ) {
$domain = $this->defaultDomain;
}
* * Only contains entity definitions (e.g. No <!ATLIST )
* * Entity definitions are not "system" entities
* * Entity definitions are not "parameter" (i.e. %) entities
- * * Entity definitions do not reference other entites except &
+ * * Entity definitions do not reference other entities except &
* and quotes. Entity aliases (where the entity contains only
* another entity are allowed)
* * Entity references aren't overly long (>255 bytes).
abstract class Profiler {
/** @var string|bool Profiler ID for bucketing data */
protected $profileID = false;
- /** @var bool Whether MediaWiki is in a SkinTemplate output context */
- protected $templated = false;
/** @var array All of the params passed from $wgProfiler */
protected $params = [];
/** @var IContextSource Current request context */
protected $context = null;
/** @var TransactionProfiler */
protected $trxProfiler;
+ /** @var bool */
+ private $allowOutput = false;
+
/** @var Profiler */
private static $instance = null;
}
/**
- * Get the content type sent out to the client.
- * Used for profilers that output instead of store data.
- * @return string
+ * Get the Content-Type for deciding how to format appended profile output.
+ *
+ * Disabled by default. Enable via setAllowOutput().
+ *
+ * @see ProfilerOutputText
* @since 1.25
+ * @return string|null Returns null if disabled or no Content-Type found.
*/
public function getContentType() {
- foreach ( headers_list() as $header ) {
- if ( preg_match( '#^content-type: (\w+/\w+);?#i', $header, $m ) ) {
- return $m[1];
+ if ( $this->allowOutput ) {
+ foreach ( headers_list() as $header ) {
+ if ( preg_match( '#^content-type: (\w+/\w+);?#i', $header, $m ) ) {
+ return $m[1];
+ }
}
}
return null;
/**
* Mark this call as templated or not
*
+ * @deprecated since 1.34 Use setAllowOutput() instead.
* @param bool $t
*/
public function setTemplated( $t ) {
- $this->templated = $t;
+ // wfDeprecated( __METHOD__, '1.34' );
+ $this->allowOutput = ( $t === true );
}
/**
* Was this call as templated or not
*
+ * @deprecated since 1.34 Use getAllowOutput() instead.
* @return bool
*/
public function getTemplated() {
- return $this->templated;
+ // wfDeprecated( __METHOD__, '1.34' );
+ return $this->getAllowOutput();
+ }
+
+ /**
+ * Enable appending profiles to standard output.
+ *
+ * @since 1.34
+ */
+ public function setAllowOutput() {
+ $this->allowOutput = true;
+ }
+
+ /**
+ * Whether appending profiles is allowed.
+ *
+ * @since 1.34
+ * @return bool
+ */
+ public function getAllowOutput() {
+ return $this->allowOutput;
}
/**
}
/**
- * Remove newlines, carriage returns and decode html entites
+ * Remove newlines, carriage returns and decode html entities
* @param string $text
* @return string
*/
-- see https://www.iana.org/assignments/media-types/
img_minor_mime varbinary(100) NOT NULL default "unknown",
- -- Description field as entered by the uploader.
+ -- Foreign key to comment table, which contains the description field as entered by the uploader.
-- This is displayed in image upload history and logs.
img_description_id bigint unsigned NOT NULL,
* @covers MediaWiki\Permissions\PermissionManager::checkSpecialsAndNSPermissions
*/
public function testSpecialsAndNSPermissions() {
- global $wgNamespaceProtection;
$this->setUser( $this->userName );
$this->setTitle( NS_SPECIAL );
MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'bogus', $this->user, $this->title ) );
- $wgNamespaceProtection[NS_USER] = [ 'bogus' ];
+ $this->mergeMwGlobalArrayValue( 'wgNamespaceProtection', [
+ NS_USER => [ 'bogus' ]
+ ] );
+ $this->resetServices();
+ $this->overrideUserPermissions( $this->user, '' );
$this->setTitle( NS_USER );
- $this->overrideUserPermissions( $this->user, '' );
$this->assertEquals( [ [ 'badaccess-group0' ],
[ 'namespaceprotected', 'User', 'bogus' ] ],
MediaWikiServices::getInstance()->getPermissionManager()
MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'bogus', $this->user, $this->title ) );
- $wgNamespaceProtection = null;
-
+ $this->setMwGlobals( 'wgNamespaceProtection', null );
+ $this->resetServices();
$this->overrideUserPermissions( $this->user, 'bogus' );
+
$this->assertEquals( [],
MediaWikiServices::getInstance()->getPermissionManager()
->getPermissionErrors( 'bogus', $this->user, $this->title ) );
* @covers \MediaWiki\Permissions\PermissionManager::checkSpecialsAndNSPermissions
*/
public function testSpecialsAndNSPermissions() {
- global $wgNamespaceProtection;
$this->setUser( $this->userName );
$this->setTitle( NS_SPECIAL );
$this->assertEquals( [ [ 'badaccess-group0' ] ],
$this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
- $wgNamespaceProtection[NS_USER] = [ 'bogus' ];
-
+ $this->mergeMwGlobalArrayValue( 'wgNamespaceProtection', [
+ NS_USER => [ 'bogus' ]
+ ] );
+ $this->resetServices();
$this->setTitle( NS_USER );
$this->overrideUserPermissions( $this->user );
$this->assertEquals( [ [ 'badaccess-group0' ],
$this->assertEquals( [ [ 'protectedinterface', 'bogus' ] ],
$this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
- $wgNamespaceProtection = null;
-
+ $this->setMwGlobals( 'wgNamespaceProtection', null );
+ $this->resetServices();
$this->overrideUserPermissions( $this->user, 'bogus' );
$this->assertEquals( [],
$this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
LockManagerGroup::destroySingletons();
$this->assertSame(
- null,
+ WikiMap::getCurrentWikiDbDomain()->getId(),
LockManagerGroup::singleton( null )->config( 'a' )['domain']
);
}