-
-/**
- * B/C class to try handling login/signup template modifications even though login/signup does not
- * actually happen through a template anymore. Just collects extra field definitions and allows
- * some other class to do decide what to do with threm..
- * TODO find the right place for adding extra fields and kill this
- */
-class FakeAuthTemplate extends BaseTemplate {
- public function execute() {
- throw new LogicException( 'not used' );
- }
-
- /**
- * Extensions (AntiSpoof and TitleBlacklist) call this in response to
- * UserCreateForm hook to add checkboxes to the create account form.
- * @param string $name
- * @param string $value
- * @param string $type
- * @param string $msg
- * @param string|bool $helptext
- */
- public function addInputItem( $name, $value, $type, $msg, $helptext = false ) {
- // use the same indexes as UserCreateForm just in case someone adds an item manually
- $this->data['extrainput'][] = [
- 'name' => $name,
- 'value' => $value,
- 'type' => $type,
- 'msg' => $msg,
- 'helptext' => $helptext,
- ];
- }
-
- /**
- * Turns addInputItem-style field definitions into HTMLForm field definitions.
- * @return array
- */
- public function getExtraInputDefinitions() {
- $definitions = [];
-
- foreach ( $this->get( 'extrainput', [] ) as $field ) {
- $definition = [
- 'type' => $field['type'] === 'checkbox' ? 'check' : $field['type'],
- 'name' => $field['name'],
- 'value' => $field['value'],
- 'id' => $field['name'],
- ];
- if ( $field['msg'] ) {
- $definition['label-message'] = $this->getMsg( $field['msg'] );
- }
- if ( $field['helptext'] ) {
- $definition['help'] = $this->msgWiki( $field['helptext'] );
- }
-
- // the array key doesn't matter much when name is defined explicitly but
- // let's try and follow HTMLForm conventions
- $name = preg_replace( '/^wp(?=[A-Z])/', '', $field['name'] );
- $definitions[$name] = $definition;
- }
-
- if ( $this->haveData( 'extrafields' ) ) {
- $definitions['extrafields'] = [
- 'type' => 'info',
- 'raw' => true,
- 'default' => $this->get( 'extrafields' ),
- ];
- }
-
- return $definitions;
- }
-}
-
-/**
- * LoginForm as a special page has been replaced by SpecialUserLogin and SpecialCreateAccount,
- * but some extensions called its public methods directly, so the class is retained as a
- * B/C wrapper. Anything that used it before should use AuthManager instead.
- */
-class LoginForm extends SpecialPage {
- const SUCCESS = 0;
- const NO_NAME = 1;
- const ILLEGAL = 2;
- const WRONG_PLUGIN_PASS = 3;
- const NOT_EXISTS = 4;
- const WRONG_PASS = 5;
- const EMPTY_PASS = 6;
- const RESET_PASS = 7;
- const ABORTED = 8;
- const CREATE_BLOCKED = 9;
- const THROTTLED = 10;
- const USER_BLOCKED = 11;
- const NEED_TOKEN = 12;
- const WRONG_TOKEN = 13;
- const USER_MIGRATED = 14;
-
- public static $statusCodes = [
- self::SUCCESS => 'success',
- self::NO_NAME => 'no_name',
- self::ILLEGAL => 'illegal',
- self::WRONG_PLUGIN_PASS => 'wrong_plugin_pass',
- self::NOT_EXISTS => 'not_exists',
- self::WRONG_PASS => 'wrong_pass',
- self::EMPTY_PASS => 'empty_pass',
- self::RESET_PASS => 'reset_pass',
- self::ABORTED => 'aborted',
- self::CREATE_BLOCKED => 'create_blocked',
- self::THROTTLED => 'throttled',
- self::USER_BLOCKED => 'user_blocked',
- self::NEED_TOKEN => 'need_token',
- self::WRONG_TOKEN => 'wrong_token',
- self::USER_MIGRATED => 'user_migrated',
- ];
-
- /**
- * @param WebRequest|null $request
- */
- public function __construct( $request = null ) {
- wfDeprecated( 'LoginForm', '1.27' );
- parent::__construct();
- }
-
- /**
- * @deprecated since 1.27 - call LoginHelper::getValidErrorMessages instead.
- * @return array
- */
- public static function getValidErrorMessages() {
- return LoginHelper::getValidErrorMessages();
- }
-
- /**
- * @deprecated since 1.27 - don't use LoginForm, use AuthManager instead
- * @param string $username
- * @return array|false
- */
- public static function incrementLoginThrottle( $username ) {
- wfDeprecated( __METHOD__, "1.27" );
- global $wgRequest;
- $username = User::getCanonicalName( $username, 'usable' ) ?: $username;
- $throttler = new Throttler();
- return $throttler->increase( $username, $wgRequest->getIP(), __METHOD__ );
- }
-
- /**
- * @deprecated since 1.27 - don't use LoginForm, use AuthManager instead
- * @param string $username
- * @return bool|int
- */
- public static function incLoginThrottle( $username ) {
- wfDeprecated( __METHOD__, "1.27" );
- $res = self::incrementLoginThrottle( $username );
- return is_array( $res ) ? true : 0;
- }
-
- /**
- * @deprecated since 1.27 - don't use LoginForm, use AuthManager instead
- * @param string $username
- * @return void
- */
- public static function clearLoginThrottle( $username ) {
- wfDeprecated( __METHOD__, "1.27" );
- global $wgRequest;
- $username = User::getCanonicalName( $username, 'usable' ) ?: $username;
- $throttler = new Throttler();
- return $throttler->clear( $username, $wgRequest->getIP() );
- }
-
- /**
- * @deprecated since 1.27 - don't use LoginForm, use AuthManager instead
- */
- public static function getLoginToken() {
- wfDeprecated( __METHOD__, '1.27' );
- global $wgRequest;
- return $wgRequest->getSession()->getToken( '', 'login' )->toString();
- }
-
- /**
- * @deprecated since 1.27 - don't use LoginForm, use AuthManager instead
- */
- public static function setLoginToken() {
- wfDeprecated( __METHOD__, '1.27' );
- }
-
- /**
- * @deprecated since 1.27 - don't use LoginForm, use AuthManager instead
- */
- public static function clearLoginToken() {
- wfDeprecated( __METHOD__, '1.27' );
- global $wgRequest;
- $wgRequest->getSession()->resetToken( 'login' );
- }
-
- /**
- * @deprecated since 1.27 - don't use LoginForm, use AuthManager instead
- * @return string
- */
- public static function getCreateaccountToken() {
- wfDeprecated( __METHOD__, '1.27' );
- global $wgRequest;
- return $wgRequest->getSession()->getToken( '', 'createaccount' )->toString();
- }
-
- /**
- * @deprecated since 1.27 - don't use LoginForm, use AuthManager instead
- */
- public static function setCreateaccountToken() {
- wfDeprecated( __METHOD__, '1.27' );
- }
-
- /**
- * @deprecated since 1.27 - don't use LoginForm, use AuthManager instead
- */
- public static function clearCreateaccountToken() {
- wfDeprecated( __METHOD__, '1.27' );
- global $wgRequest;
- $wgRequest->getSession()->resetToken( 'createaccount' );
- }
-}