Links generated by the API are now aware of the user's preferred language and will show documents in that language if available. To test, log in to mediawiki.org and set your language preference to 'es', then on an MediaWiki installation with this patch view the generated expanded API help at `api.php?action=help&recursivesubmodules=1&modules=main`. Each link to documentation on mediawiki.org should take you to its translated /es subpage, if one exists. Bug: T104518 Change-Id: I339a1f3ae1bce9d759cf251899d57c32b1def91e
81 lines
2 KiB
PHP
81 lines
2 KiB
PHP
<?php
|
|
|
|
use MediaWiki\Auth\AuthManager;
|
|
|
|
/**
|
|
* @ingroup API
|
|
*/
|
|
class ApiValidatePassword extends ApiBase {
|
|
|
|
public function execute() {
|
|
$params = $this->extractRequestParams();
|
|
|
|
// For sanity
|
|
$this->requirePostedParameters( [ 'password' ] );
|
|
|
|
if ( $params['user'] !== null ) {
|
|
$user = User::newFromName( $params['user'], 'creatable' );
|
|
if ( !$user ) {
|
|
$encParamName = $this->encodeParamName( 'user' );
|
|
$this->dieWithError(
|
|
[ 'apierror-baduser', $encParamName, wfEscapeWikiText( $params['user'] ) ],
|
|
"baduser_{$encParamName}"
|
|
);
|
|
}
|
|
|
|
if ( !$user->isAnon() || AuthManager::singleton()->userExists( $user->getName() ) ) {
|
|
$this->dieWithError( 'userexists' );
|
|
}
|
|
|
|
$user->setEmail( (string)$params['email'] );
|
|
$user->setRealName( (string)$params['realname'] );
|
|
} else {
|
|
$user = $this->getUser();
|
|
}
|
|
|
|
$validity = $user->checkPasswordValidity( $params['password'] );
|
|
$r['validity'] = $validity->isGood() ? 'Good' : ( $validity->isOK() ? 'Change' : 'Invalid' );
|
|
$messages = array_merge(
|
|
$this->getErrorFormatter()->arrayFromStatus( $validity, 'error' ),
|
|
$this->getErrorFormatter()->arrayFromStatus( $validity, 'warning' )
|
|
);
|
|
if ( $messages ) {
|
|
$r['validitymessages'] = $messages;
|
|
}
|
|
|
|
Hooks::run( 'ApiValidatePassword', [ $this, &$r ] );
|
|
|
|
$this->getResult()->addValue( null, $this->getModuleName(), $r );
|
|
}
|
|
|
|
public function mustBePosted() {
|
|
return true;
|
|
}
|
|
|
|
public function getAllowedParams() {
|
|
return [
|
|
'password' => [
|
|
ApiBase::PARAM_TYPE => 'password',
|
|
ApiBase::PARAM_REQUIRED => true
|
|
],
|
|
'user' => [
|
|
ApiBase::PARAM_TYPE => 'user',
|
|
],
|
|
'email' => null,
|
|
'realname' => null,
|
|
];
|
|
}
|
|
|
|
protected function getExamplesMessages() {
|
|
return [
|
|
'action=validatepassword&password=foobar'
|
|
=> 'apihelp-validatepassword-example-1',
|
|
'action=validatepassword&password=querty&user=Example'
|
|
=> 'apihelp-validatepassword-example-2',
|
|
];
|
|
}
|
|
|
|
public function getHelpUrls() {
|
|
return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Validatepassword';
|
|
}
|
|
}
|