wiki.techinc.nl/includes/Preferences.php

274 lines
7.8 KiB
PHP
Raw Normal View History

<?php
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
*/
Use AuthManager on special pages Rewrite authentication-related special pages to use AuthManager. All the changes mentioned below only take effect when $wgDisableAuthManager is false. LoginForm is rewritten to use HTMLForm and split into UserLogin and CreateAccount; ChangePassword and PasswordReset are rewritten; ChangeEmail and Preferences are updated. Four new special pages are added to handle the new capabilities of AuthManager (linked accounts, secondary authentication providers): LinkAccounts, UnlinkAccounts, ChangeCredentials, RemoveCredentials. The old form-based hooks (ChangePasswordForm, UserCreateForm, UserLoginForm) are deprecated. A new, more generic hook is available to alter the forms (AuthChangeFormFields); form changes that involve new fields should be done via $wgAuthManagerConfig. UserLoginComplete is limited to web-based login; for more generic functionality UserLoggedIn can be used instead. Hooks that assume password-based login (PrefsPasswordAudit, AbortChangePassword) are removed; the first functionality is replaced by ChangeAuthenticationDataAudit, the second is handled by AuthManager. LoginPasswordResetMessage is removed, the functionality can be recreated via authentication providers. There are several smaller backwards incompatible changes: * Adding fields to the login/signup forms by manipulating the template via the extraInput/extrafields parameters is not supported anymore. Depending on the authn configuration the login/signup process might be multistep and it would be complicated to ensure that extensions can access the data at the right moment. Instead, you can create an AuthenticationProvider which can define its own fields and process them when the authentication is over. (There is B/C support for a transitional period that works with the default login form, but might break with configurations that require multiple steps or redirects.) * Removed cookie redirect check. This was added in 2003 in 9ead07fe9 for the benefit of bots, but with MediaWiki having an API these days there is little reason to keep it. Same for the wpSkipCookieCheck flag (added in 2008 in 29c73e8265). * Instead of embedding a password field on sensitive special pages such as ChangeEmail, such pages rely on AuthManager for elevated security (which typically involves requiring the user to log in again unless their last login was more than a few minutes ago). Accordingly, wgRequirePasswordforEmailChange is removed. * Special:ChangePassword requires login now. * Special:ResetPassword now sends a separate email to each user when called with a shared email address. * the Reason field had a message with 'prefsectiontip' class which was sorta broken but used in extensions for formatting. HTMLForm does not support that, so this commit turns it into a help message which will break formatting. See https://gerrit.wikimedia.org/r/#/c/231884 Bug: T110277 Change-Id: I8b52ec8ddf494f23941807638f149f15b5e46b0c Depends-On: If4e0dfb6ee6674f0dace80a01850e2d0cbbdb47a
2015-09-22 22:50:04 +00:00
use MediaWiki\Auth\AuthManager;
use MediaWiki\MediaWikiServices;
use MediaWiki\Preferences\DefaultPreferencesFactory;
/**
* This class has been replaced by the PreferencesFactory service.
2009-08-23 20:09:59 +00:00
*
* @deprecated since 1.31 use the PreferencesFactory service instead.
2009-08-23 20:09:59 +00:00
*/
class Preferences {
2009-06-21 14:16:11 +00:00
/**
* A shim to maintain backwards-compatibility of this class, basically replicating the
* default behaviour of the PreferencesFactory service but not permitting overriding.
* @return DefaultPreferencesFactory
*/
protected static function getDefaultPreferencesFactory() {
$services = MediaWikiServices::getInstance();
$authManager = AuthManager::singleton();
$linkRenderer = $services->getLinkRenderer();
$config = $services->getMainConfig();
$preferencesFactory = new DefaultPreferencesFactory(
$config, $services->getContentLanguage(), $authManager,
$linkRenderer
);
return $preferencesFactory;
}
/**
* @throws MWException
* @param User $user
* @param IContextSource $context
* @return array|null
*/
public static function getPreferences( $user, IContextSource $context ) {
wfDeprecated( __METHOD__, '1.31' );
$preferencesFactory = self::getDefaultPreferencesFactory();
return $preferencesFactory->getFormDescriptor( $user, $context );
}
/**
* Loads existing values for a given array of preferences
* @throws MWException
* @param User $user
* @param IContextSource $context
* @param array &$defaultPreferences Array to load values for
* @return array|null
*/
public static function loadPreferenceValues( $user, $context, &$defaultPreferences ) {
throw new Exception( __METHOD__ . '() is deprecated and does nothing' );
}
2009-06-21 14:16:11 +00:00
/**
* Pull option from a user account. Handles stuff like array-type preferences.
*
* @param string $name
* @param array $info
* @param User $user
* @return array|string
*/
public static function getOptionFromUser( $name, $info, $user ) {
throw new Exception( __METHOD__ . '() is deprecated and does nothing' );
}
2009-06-21 14:16:11 +00:00
/**
* @param User $user
* @param IContextSource $context
* @param array &$defaultPreferences
* @return void
*/
public static function profilePreferences(
$user, IContextSource $context, &$defaultPreferences
) {
wfDeprecated( __METHOD__, '1.31' );
$defaultPreferences = self::getPreferences( $user, $context );
}
2009-06-21 14:16:11 +00:00
/**
* @param User $user
* @param IContextSource $context
* @param array &$defaultPreferences
* @return void
*/
public static function skinPreferences( $user, IContextSource $context, &$defaultPreferences ) {
wfDeprecated( __METHOD__, '1.31' );
$defaultPreferences = self::getPreferences( $user, $context );
}
2009-06-21 14:16:11 +00:00
2011-05-28 16:32:09 +00:00
/**
* @param User $user
* @param IContextSource $context
* @param array &$defaultPreferences
2011-05-28 16:32:09 +00:00
*/
public static function filesPreferences(
$user, IContextSource $context, &$defaultPreferences
) {
wfDeprecated( __METHOD__, '1.31' );
$defaultPreferences = self::getPreferences( $user, $context );
}
2009-06-21 14:16:11 +00:00
/**
* @param User $user
* @param IContextSource $context
* @param array &$defaultPreferences
* @return void
*/
public static function datetimePreferences(
$user, IContextSource $context, &$defaultPreferences
) {
wfDeprecated( __METHOD__, '1.31' );
$defaultPreferences = self::getPreferences( $user, $context );
}
2009-06-21 14:16:11 +00:00
2011-05-28 16:32:09 +00:00
/**
* @param User $user
* @param IContextSource $context
* @param array &$defaultPreferences
2011-05-28 16:32:09 +00:00
*/
public static function renderingPreferences(
$user, IContextSource $context, &$defaultPreferences
) {
wfDeprecated( __METHOD__, '1.31' );
$defaultPreferences = self::getPreferences( $user, $context );
}
2009-06-21 14:16:11 +00:00
2011-05-28 16:32:09 +00:00
/**
* @param User $user
* @param IContextSource $context
* @param array &$defaultPreferences
2011-05-28 16:32:09 +00:00
*/
public static function editingPreferences(
$user, IContextSource $context, &$defaultPreferences
) {
wfDeprecated( __METHOD__, '1.31' );
$defaultPreferences = self::getPreferences( $user, $context );
}
2009-06-21 14:16:11 +00:00
2011-05-28 16:32:09 +00:00
/**
* @param User $user
* @param IContextSource $context
* @param array &$defaultPreferences
2011-05-28 16:32:09 +00:00
*/
public static function rcPreferences( $user, IContextSource $context, &$defaultPreferences ) {
wfDeprecated( __METHOD__, '1.31' );
$defaultPreferences = self::getPreferences( $user, $context );
}
2009-06-21 14:16:11 +00:00
/**
* @param User $user
* @param IContextSource $context
* @param array &$defaultPreferences
*/
public static function watchlistPreferences(
$user, IContextSource $context, &$defaultPreferences
) {
wfDeprecated( __METHOD__, '1.31' );
$defaultPreferences = self::getPreferences( $user, $context );
}
2009-06-21 14:16:11 +00:00
2011-05-28 16:32:09 +00:00
/**
* @param User $user
* @param IContextSource $context
* @param array &$defaultPreferences
2011-05-28 16:32:09 +00:00
*/
public static function searchPreferences(
$user, IContextSource $context, &$defaultPreferences
) {
wfDeprecated( __METHOD__, '1.31' );
$defaultPreferences = self::getPreferences( $user, $context );
}
2009-06-21 14:16:11 +00:00
2011-05-28 16:32:09 +00:00
/**
* Dummy, kept for backwards-compatibility.
* @param User $user
* @param IContextSource $context
* @param array &$defaultPreferences
2011-05-28 16:32:09 +00:00
*/
public static function miscPreferences( $user, IContextSource $context, &$defaultPreferences ) {
wfDeprecated( __METHOD__, '1.31' );
}
2009-06-21 14:16:11 +00:00
/**
* @param User $user
* @param IContextSource $context
* @return array Text/links to display as key; $skinkey as value
*/
public static function generateSkinOptions( $user, IContextSource $context ) {
wfDeprecated( __METHOD__, '1.31' );
return self::getPreferences( $user, $context );
}
2009-06-21 14:16:11 +00:00
2011-05-28 16:32:09 +00:00
/**
* @param IContextSource $context
2011-05-28 16:32:09 +00:00
* @return array
*/
static function getDateOptions( IContextSource $context ) {
throw new Exception( __METHOD__ . '() is deprecated and does nothing' );
}
2009-06-21 14:16:11 +00:00
2011-05-28 16:32:09 +00:00
/**
* @param IContextSource $context
2011-05-28 16:32:09 +00:00
* @return array
*/
public static function getImageSizes( IContextSource $context ) {
throw new Exception( __METHOD__ . '() is deprecated and does nothing' );
}
2009-06-21 14:16:11 +00:00
2011-05-28 16:32:09 +00:00
/**
* @param IContextSource $context
2011-05-28 16:32:09 +00:00
* @return array
*/
public static function getThumbSizes( IContextSource $context ) {
throw new Exception( __METHOD__ . '() is deprecated and does nothing' );
}
2009-06-21 14:16:11 +00:00
2011-05-28 16:32:09 +00:00
/**
* @param string $signature
* @param array $alldata
* @param HTMLForm $form
2011-05-28 16:32:09 +00:00
* @return bool|string
*/
public static function validateSignature( $signature, $alldata, $form ) {
throw new Exception( __METHOD__ . '() is deprecated and does nothing' );
}
2009-06-21 14:16:11 +00:00
2011-05-28 16:32:09 +00:00
/**
* @param string $signature
* @param array $alldata
* @param HTMLForm $form
2011-05-29 14:01:47 +00:00
* @return string
2011-05-28 16:32:09 +00:00
*/
public static function cleanSignature( $signature, $alldata, $form ) {
throw new Exception( __METHOD__ . '() is deprecated and does nothing now' );
}
2009-06-21 14:16:11 +00:00
2011-05-28 16:32:09 +00:00
/**
* @param User $user
* @param IContextSource $context
* @param string $formClass
* @param array $remove Array of items to remove
* @return PreferencesFormLegacy|HTMLForm
2011-05-28 16:32:09 +00:00
*/
public static function getFormObject(
$user,
IContextSource $context,
$formClass = PreferencesFormLegacy::class,
array $remove = []
) {
wfDeprecated( __METHOD__, '1.31' );
$preferencesFactory = self::getDefaultPreferencesFactory();
return $preferencesFactory->getForm( $user, $context, $formClass, $remove );
}
}