namespace MediaWiki\Preferences;
-use Config;
use DateTime;
use DateTimeZone;
use Exception;
use MediaWiki\Config\ServiceOptions;
use MediaWiki\Linker\LinkRenderer;
use MediaWiki\MediaWikiServices;
+use MediaWiki\Permissions\PermissionManager;
use MessageLocalizer;
use MWException;
use MWTimestamp;
/** @var NamespaceInfo */
protected $nsInfo;
+ /** @var PermissionManager */
+ protected $permissionManager;
+
/**
* TODO Make this a const when we drop HHVM support (T192166)
*
/**
* Do not call this directly. Get it from MediaWikiServices.
*
- * @param ServiceOptions|Config $options Config accepted for backwards compatibility
+ * @param ServiceOptions $options
* @param Language $contLang
* @param AuthManager $authManager
* @param LinkRenderer $linkRenderer
- * @param NamespaceInfo|null $nsInfo
+ * @param NamespaceInfo $nsInfo
+ * @param PermissionManager $permissionManager
*/
public function __construct(
- $options,
+ ServiceOptions $options,
Language $contLang,
AuthManager $authManager,
LinkRenderer $linkRenderer,
- NamespaceInfo $nsInfo = null
+ NamespaceInfo $nsInfo,
+ PermissionManager $permissionManager
) {
- if ( $options instanceof Config ) {
- wfDeprecated( __METHOD__ . ' with Config parameter', '1.34' );
- $options = new ServiceOptions( self::$constructorOptions, $options );
- }
-
$options->assertRequiredOptions( self::$constructorOptions );
- if ( !$nsInfo ) {
- wfDeprecated( __METHOD__ . ' with no NamespaceInfo argument', '1.34' );
- $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
- }
$this->options = $options;
$this->contLang = $contLang;
$this->authManager = $authManager;
$this->linkRenderer = $linkRenderer;
$this->nsInfo = $nsInfo;
+ $this->permissionManager = $permissionManager;
$this->logger = new NullLogger();
}
# # Make sure that form fields have their parent set. See T43337.
$dummyForm = new HTMLForm( [], $context );
- $disable = !$user->isAllowed( 'editmyoptions' );
+ $disable = !$this->permissionManager->userHasRight( $user, 'editmyoptions' );
$defaultOptions = User::getDefaultOptions();
$userOptions = $user->getOptions();
];
}
- $canViewPrivateInfo = $user->isAllowed( 'viewmyprivateinfo' );
- $canEditPrivateInfo = $user->isAllowed( 'editmyprivateinfo' );
+ $canViewPrivateInfo = $this->permissionManager->userHasRight( $user, 'viewmyprivateinfo' );
+ $canEditPrivateInfo = $this->permissionManager->userHasRight( $user, 'editmyprivateinfo' );
// Actually changeable stuff
$defaultPreferences['realname'] = [
];
}
- if ( $this->options->get( 'EnableUserEmail' ) && $user->isAllowed( 'sendemail' ) ) {
+ if ( $this->options->get( 'EnableUserEmail' ) &&
+ $this->permissionManager->userHasRight( $user, 'sendemail' )
+ ) {
$defaultPreferences['disablemail'] = [
'id' => 'wpAllowEmail',
'type' => 'toggle',
'label-message' => 'tog-numberheadings',
];
- if ( $user->isAllowed( 'rollback' ) ) {
+ if ( $this->permissionManager->userHasRight( $user, 'rollback' ) ) {
$defaultPreferences['showrollbackconfirmation'] = [
'type' => 'toggle',
'section' => 'rendering/advancedrendering',
];
}
- if ( $user->isAllowed( 'minoredit' ) ) {
+ if ( $this->permissionManager->userHasRight( $user, 'minoredit' ) ) {
$defaultPreferences['minordefault'] = [
'type' => 'toggle',
'section' => 'editing/editor',
$watchlistdaysMax = ceil( $this->options->get( 'RCMaxAge' ) / ( 3600 * 24 ) );
# # Watchlist #####################################
- if ( $user->isAllowed( 'editmywatchlist' ) ) {
+ if ( $this->permissionManager->userHasRight( $user, 'editmywatchlist' ) ) {
$editWatchlistLinks = '';
$editWatchlistModes = [
'edit' => [ 'subpage' => false, 'flags' => [] ],
];
// Kinda hacky
- if ( $user->isAllowed( 'createpage' ) || $user->isAllowed( 'createtalk' ) ) {
+ if ( $this->permissionManager->userHasAnyRight( $user, 'createpage', 'createtalk' ) ) {
$watchTypes['read'] = 'watchcreations';
}
- if ( $user->isAllowed( 'rollback' ) ) {
+ if ( $this->permissionManager->userHasRight( $user, 'rollback' ) ) {
$watchTypes['rollback'] = 'watchrollback';
}
- if ( $user->isAllowed( 'upload' ) ) {
+ if ( $this->permissionManager->userHasRight( $user, 'upload' ) ) {
$watchTypes['upload'] = 'watchuploads';
}
foreach ( $watchTypes as $action => $pref ) {
- if ( $user->isAllowed( $action ) ) {
+ if ( $this->permissionManager->userHasRight( $user, $action ) ) {
// Messages:
// tog-watchdefault, tog-watchmoves, tog-watchdeletion, tog-watchcreations, tog-watchuploads
// tog-watchrollback
}
/**
- * @var HTMLForm $htmlForm
+ * @var PreferencesFormOOUI $htmlForm
*/
$htmlForm = new $formClass( $formDescriptor, $context, 'prefs' );
] ) );
$htmlForm->setModifiedUser( $user );
+ $htmlForm->setOptionsEditable( $this->permissionManager
+ ->userHasRight( $user, 'editmyoptions' ) );
+ $htmlForm->setPrivateInfoEditable( $this->permissionManager
+ ->userHasRight( $user, 'editmyprivateinfo' ) );
$htmlForm->setId( 'mw-prefs-form' );
$htmlForm->setAutocomplete( 'off' );
$htmlForm->setSubmitText( $context->msg( 'saveprefs' )->text() );
$htmlForm->setSubmitTooltip( 'preferences-save' );
$htmlForm->setSubmitID( 'prefcontrol' );
$htmlForm->setSubmitCallback(
- function ( array $formData, HTMLForm $form ) use ( $formDescriptor ) {
+ function ( array $formData, PreferencesFormOOUI $form ) use ( $formDescriptor ) {
return $this->submitForm( $formData, $form, $formDescriptor );
}
);
$hiddenPrefs = $this->options->get( 'HiddenPrefs' );
$result = true;
- if ( !$user->isAllowedAny( 'editmyprivateinfo', 'editmyoptions' ) ) {
+ if ( !$this->permissionManager
+ ->userHasAnyRight( $user, 'editmyprivateinfo', 'editmyoptions' )
+ ) {
return Status::newFatal( 'mypreferencesprotected' );
}
// (not really "private", but still shouldn't be edited without permission)
if ( !in_array( 'realname', $hiddenPrefs )
- && $user->isAllowed( 'editmyprivateinfo' )
+ && $this->permissionManager->userHasRight( $user, 'editmyprivateinfo' )
&& array_key_exists( 'realname', $formData )
) {
$realName = $formData['realname'];
$user->setRealName( $realName );
}
- if ( $user->isAllowed( 'editmyoptions' ) ) {
+ if ( $this->permissionManager->userHasRight( $user, 'editmyoptions' ) ) {
$oldUserOptions = $user->getOptions();
foreach ( $this->getSaveBlacklist() as $b ) {