Go to the documentation of this file.
50 parent::__construct(
'BotPasswords',
'editmyprivateinfo' );
51 $this->logger = LoggerFactory::getInstance(
'authentication' );
58 return $this->
getConfig()->get(
'EnableBotPasswords' );
75 if ( strlen(
$par ) === 0 ) {
78 throw new ErrorPageError(
'botpasswords',
'botpasswords-bad-appid',
79 [ htmlspecialchars(
$par ) ] );
82 parent::execute(
$par );
86 parent::checkExecutePermissions( $user );
88 if ( !$this->
getConfig()->
get(
'EnableBotPasswords' ) ) {
89 throw new ErrorPageError(
'botpasswords',
'botpasswords-disabled' );
93 if ( !$this->userId ) {
94 throw new ErrorPageError(
'botpasswords',
'botpasswords-no-central-id' );
101 if ( $this->par !==
null ) {
103 if ( !$this->botPassword ) {
105 'centralId' => $this->userId,
106 'appId' => $this->par,
113 'label-message' =>
'username',
117 if ( $this->botPassword->isSaved() ) {
118 $fields[
'resetPassword'] = [
120 'label-message' =>
'botpasswords-label-resetpassword',
122 if ( $this->botPassword->isInvalid() ) {
123 $fields[
'resetPassword'][
'default'] =
true;
129 $fields[
'grants'] = [
130 'type' =>
'checkmatrix',
131 'label-message' =>
'botpasswords-label-grants',
132 'help-message' =>
'botpasswords-help-grants',
134 $this->
msg(
'botpasswords-label-grants-column' )->escaped() =>
'grant'
136 'rows' => array_combine(
137 array_map(
'MWGrants::getGrantsLink', $showGrants ),
140 'default' => array_map(
144 $this->botPassword->getGrants()
146 'tooltips' => array_combine(
147 array_map(
'MWGrants::getGrantsLink', $showGrants ),
149 function ( $rights ) use (
$lang ) {
150 return $lang->semicolonList( array_map(
'User::getRightDescription', $rights ) );
155 'force-options-on' => array_map(
163 $fields[
'restrictions'] = [
164 'class' => HTMLRestrictionsField::class,
166 'default' => $this->botPassword->getRestrictions(),
171 $passwordFactory = MediaWikiServices::getInstance()->getPasswordFactory();
176 [
'bp_app_id',
'bp_password' ],
177 [
'bp_user' => $this->userId ],
180 foreach (
$res as $row ) {
182 $password = $passwordFactory->newFromCiphertext( $row->bp_password );
186 $passwordInvalid =
true;
193 if ( $passwordInvalid ) {
194 $text .= $this->
msg(
'word-separator' )->escaped()
195 . $this->
msg(
'botpasswords-label-needsreset' )->parse();
199 'section' =>
'existing',
207 'section' =>
'createnew',
208 'type' =>
'textwithbutton',
209 'label-message' =>
'botpasswords-label-appid',
210 'buttondefault' => $this->
msg(
'botpasswords-label-create' )->text(),
211 'buttonflags' => [
'progressive',
'primary' ],
215 'validation-callback' =>
function ( $v ) {
232 $form->
setId(
'mw-botpasswords-form' );
234 $form->
addPreText( $this->
msg(
'botpasswords-summary' )->parseAsBlock() );
237 if ( $this->par !==
null ) {
238 if ( $this->botPassword->isSaved() ) {
243 'label-message' =>
'botpasswords-label-update',
244 'flags' => [
'primary',
'progressive' ],
249 'label-message' =>
'botpasswords-label-delete',
250 'flags' => [
'destructive' ],
257 'label-message' =>
'botpasswords-label-create',
258 'flags' => [
'primary',
'progressive' ],
265 'label-message' =>
'botpasswords-label-cancel'
271 $op = $this->
getRequest()->getVal(
'op',
'' );
279 $this->operation =
'insert';
280 return $this->
save( $data );
283 $this->operation =
'update';
284 return $this->
save( $data );
287 $this->operation =
'delete';
292 "Bot password {op} for {user}@{app_id}",
294 'app_id' => $this->par,
296 'centralId' => $this->userId,
312 private function save( array $data ) {
314 'centralId' => $this->userId,
315 'appId' => $this->par,
316 'restrictions' => $data[
'restrictions'],
317 'grants' => array_merge(
321 preg_replace(
'/^grant-/',
'', $data[
'grants'] )
325 if ( $this->operation ===
'insert' || !empty( $data[
'resetPassword'] ) ) {
327 $passwordFactory = MediaWikiServices::getInstance()->getPasswordFactory();
328 $password = $passwordFactory->newFromPlaintext( $this->password );
333 if ( $bp->save( $this->operation,
$password ) ) {
335 "Bot password {op} for {user}@{app_id}",
337 'op' => $this->operation,
339 'app_id' => $this->par,
340 'centralId' => $this->userId,
341 'restrictions' => $data[
'restrictions'],
342 'grants' => $bp->getGrants(),
349 return Status::newFatal(
"botpasswords-{$this->operation}-failed", $this->par );
356 $username = $this->
getUser()->getName();
357 switch ( $this->operation ) {
359 $out->setPageTitle( $this->
msg(
'botpasswords-created-title' )->text() );
360 $out->addWikiMsg(
'botpasswords-created-body', $this->par, $username );
364 $out->setPageTitle( $this->
msg(
'botpasswords-updated-title' )->text() );
365 $out->addWikiMsg(
'botpasswords-updated-body', $this->par, $username );
369 $out->setPageTitle( $this->
msg(
'botpasswords-deleted-title' )->text() );
370 $out->addWikiMsg(
'botpasswords-deleted-body', $this->par, $username );
371 $this->password =
null;
375 if ( $this->password !==
null ) {
378 'botpasswords-newpassword',
379 htmlspecialchars( $username . $sep . $this->par ),
380 htmlspecialchars( $this->password ),
381 htmlspecialchars( $username ),
382 htmlspecialchars( $this->par . $sep . $this->password )
384 $this->password =
null;
getPageTitle( $subpage=false)
Get a self-referential title object.
Let users manage bot passwords.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
static newFatal( $message,... $parameters)
Factory function for fatal errors.
getOutput()
Get the OutputPage being used for this instance.
if(!isset( $args[0])) $lang
checkExecutePermissions(User $user)
Called from execute() to check if the given user can perform this action.
Utility class for bot passwords.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
static getSeparator()
Get the separator for combined user name + app ID.
static generatePassword( $config)
Returns a (raw, unhashed) random password string.
Show an error when any operation involving passwords fails to run.
Special page which uses an HTMLForm to handle processing.
getFormFields()
Get an HTMLForm descriptor array.
Represents an invalid password hash.
static getDB( $db)
Get a database connection for the bot passwords database.
getLanguage()
Shortcut to get user's language.
getName()
Get the name of this Special Page.
static getHiddenGrants()
Get the list of grants that are hidden and should always be granted.
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
getConfig()
Shortcut to get main config object.
static newUnsaved(array $data, $flags=self::READ_NORMAL)
Create an unsaved BotPassword.
onSuccess()
Do something exciting on successful processing of the form, most likely to show a confirmation messag...
getUser()
Shortcut to get the User executing this instance.
Psr Log LoggerInterface $logger
static getValidGrants()
List all known grants.
getDisplayFormat()
Get display format for the form.
alterForm(HTMLForm $form)
Play with the HTMLForm if you need to more substantially.
string null $par
The sub-page of the special page.
requireLogin( $reasonMsg='exception-nologin-text', $titleMsg='exception-nologin')
If the user is not logged in, throws UserNotLoggedIn error.
string $password
New password set, for communication between onSubmit() and onSuccess()
static newGood( $value=null)
Factory function for good results.
getRequest()
Get the WebRequest being used for this instance.
static newFromCentralId( $centralId, $appId, $flags=self::READ_NORMAL)
Load a BotPassword from the database.
int $userId
Central user ID.
static getRightsByGrant()
Map all grants to corresponding user rights.
onSubmit(array $data)
Process the form on POST submission.
MediaWiki Linker LinkRenderer null $linkRenderer
string $operation
Operation being performed: create, update, delete.
An error page which can definitely be safely rendered using the OutputPage.
static factory( $providerId=null)
Fetch a CentralIdLookup.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
execute( $par)
Main execution point.
BotPassword null $botPassword
Bot password being edited, if any.
getLoginSecurityLevel()
Tells if the special page does something security-sensitive and needs extra defense against a stolen ...