44 parent::__construct(
'BotPasswords',
'editmyprivateinfo' );
51 return $this->
getConfig()->get(
'EnableBotPasswords' );
67 if ( strlen(
$par ) === 0 ) {
69 } elseif ( strlen(
$par ) > BotPassword::APPID_MAXLENGTH ) {
70 throw new ErrorPageError(
'botpasswords',
'botpasswords-bad-appid',
71 [ htmlspecialchars(
$par ) ] );
74 parent::execute(
$par );
78 parent::checkExecutePermissions( $user );
80 if ( !$this->
getConfig()->
get(
'EnableBotPasswords' ) ) {
81 throw new ErrorPageError(
'botpasswords',
'botpasswords-disabled' );
85 if ( !$this->userId ) {
86 throw new ErrorPageError(
'botpasswords',
'botpasswords-no-central-id' );
93 if ( $this->par !==
null ) {
94 $this->botPassword = BotPassword::newFromCentralId( $this->userId, $this->par );
95 if ( !$this->botPassword ) {
96 $this->botPassword = BotPassword::newUnsaved( [
97 'centralId' => $this->userId,
98 'appId' => $this->par,
102 $sep = BotPassword::getSeparator();
105 'label-message' =>
'username',
109 if ( $this->botPassword->isSaved() ) {
110 $fields[
'resetPassword'] = [
112 'label-message' =>
'botpasswords-label-resetpassword',
114 if ( $this->botPassword->isInvalid() ) {
115 $fields[
'resetPassword'][
'default'] =
true;
121 $fields[
'grants'] = [
122 'type' =>
'checkmatrix',
123 'label-message' =>
'botpasswords-label-grants',
124 'help-message' =>
'botpasswords-help-grants',
126 $this->
msg(
'botpasswords-label-grants-column' )->escaped() =>
'grant'
128 'rows' => array_combine(
129 array_map(
'MWGrants::getGrantsLink', $showGrants ),
132 'default' => array_map(
136 $this->botPassword->getGrants()
138 'tooltips' => array_combine(
139 array_map(
'MWGrants::getGrantsLink', $showGrants ),
141 function ( $rights ) use (
$lang ) {
142 return $lang->semicolonList( array_map(
'User::getRightDescription', $rights ) );
147 'force-options-on' => array_map(
155 $fields[
'restrictions'] = [
156 'class' =>
'HTMLRestrictionsField',
158 'default' => $this->botPassword->getRestrictions(),
164 $passwordFactory->init( $this->
getConfig() );
169 [
'bp_app_id',
'bp_password' ],
170 [
'bp_user' => $this->userId ],
173 foreach (
$res as $row ) {
175 $password = $passwordFactory->newFromCiphertext( $row->bp_password );
179 $passwordInvalid =
true;
186 if ( $passwordInvalid ) {
187 $text .= $this->
msg(
'word-separator' )->escaped()
188 . $this->
msg(
'botpasswords-label-needsreset' )->parse();
192 'section' =>
'existing',
200 'section' =>
'createnew',
201 'type' =>
'textwithbutton',
202 'label-message' =>
'botpasswords-label-appid',
203 'buttondefault' => $this->
msg(
'botpasswords-label-create' )->text(),
204 'buttonflags' => [
'progressive',
'primary' ],
206 'size' => BotPassword::APPID_MAXLENGTH,
207 'maxlength' => BotPassword::APPID_MAXLENGTH,
208 'validation-callback' =>
function ( $v ) {
210 return $v !==
'' && strlen( $v ) <= BotPassword::APPID_MAXLENGTH;
225 $form->setId(
'mw-botpasswords-form' );
226 $form->setTableId(
'mw-botpasswords-table' );
227 $form->addPreText( $this->
msg(
'botpasswords-summary' )->parseAsBlock() );
228 $form->suppressDefaultSubmit();
230 if ( $this->par !==
null ) {
231 if ( $this->botPassword->isSaved() ) {
232 $form->setWrapperLegendMsg(
'botpasswords-editexisting' );
236 'label-message' =>
'botpasswords-label-update',
237 'flags' => [
'primary',
'progressive' ],
242 'label-message' =>
'botpasswords-label-delete',
243 'flags' => [
'destructive' ],
246 $form->setWrapperLegendMsg(
'botpasswords-createnew' );
250 'label-message' =>
'botpasswords-label-create',
251 'flags' => [
'primary',
'progressive' ],
258 'label-message' =>
'botpasswords-label-cancel'
264 $op = $this->
getRequest()->getVal(
'op',
'' );
272 $this->operation =
'insert';
273 return $this->
save( $data );
276 $this->operation =
'update';
277 return $this->
save( $data );
280 $this->operation =
'delete';
281 $bp = BotPassword::newFromCentralId( $this->userId, $this->par );
285 return Status::newGood();
295 private function save( array $data ) {
296 $bp = BotPassword::newUnsaved( [
297 'centralId' => $this->userId,
298 'appId' => $this->par,
299 'restrictions' => $data[
'restrictions'],
300 'grants' => array_merge(
302 preg_replace(
'/^grant-/',
'', $data[
'grants'] )
306 if ( $this->operation ===
'insert' || !empty( $data[
'resetPassword'] ) ) {
307 $this->password = BotPassword::generatePassword( $this->
getConfig() );
310 $password = $passwordFactory->newFromPlaintext( $this->password );
315 if ( $bp->save( $this->operation,
$password ) ) {
316 return Status::newGood();
319 return Status::newFatal(
"botpasswords-{$this->operation}-failed", $this->par );
327 switch ( $this->operation ) {
329 $out->setPageTitle( $this->
msg(
'botpasswords-created-title' )->
text() );
330 $out->addWikiMsg(
'botpasswords-created-body', $this->par,
$username );
334 $out->setPageTitle( $this->
msg(
'botpasswords-updated-title' )->
text() );
335 $out->addWikiMsg(
'botpasswords-updated-body', $this->par,
$username );
339 $out->setPageTitle( $this->
msg(
'botpasswords-deleted-title' )->
text() );
340 $out->addWikiMsg(
'botpasswords-deleted-body', $this->par,
$username );
341 $this->password =
null;
345 if ( $this->password !==
null ) {
346 $sep = BotPassword::getSeparator();
348 'botpasswords-newpassword',
349 htmlspecialchars(
$username . $sep . $this->par ),
350 htmlspecialchars( $this->password ),
352 htmlspecialchars( $this->par . $sep . $this->password )
354 $this->password =
null;
Utility class for bot passwords.
static factory( $providerId=null)
Fetch a CentralIdLookup.
An error page which can definitely be safely rendered using the OutputPage.
Special page which uses an HTMLForm to handle processing.
string $par
The sub-page of the special page.
Represents an invalid password hash.
static getHiddenGrants()
Get the list of grants that are hidden and should always be granted.
static getRightsByGrant()
Map all grants to corresponding user rights.
static getValidGrants()
List all known grants.
Show an error when any operation involving passwords fails to run.
Factory class for creating and checking Password objects.
static getMain()
Static methods.
Let users manage bot passwords.
string $password
New password set, for communication between onSubmit() and onSuccess()
BotPassword null $botPassword
Bot password being edited, if any.
onSuccess()
Do something exciting on successful processing of the form, most likely to show a confirmation messag...
alterForm(HTMLForm $form)
Play with the HTMLForm if you need to more substantially.
execute( $par)
Main execution point.
getFormFields()
Get an HTMLForm descriptor array.
onSubmit(array $data)
Process the form on POST submission.
checkExecutePermissions(User $user)
Called from execute() to check if the given user can perform this action.
getDisplayFormat()
Get display format for the form.
getLoginSecurityLevel()
Tells if the special page does something security-sensitive and needs extra defense against a stolen ...
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
int $userId
Central user ID.
string $operation
Operation being performed: create, update, delete.
getName()
Get the name of this Special Page.
getOutput()
Get the OutputPage being used for this instance.
requireLogin( $reasonMsg='exception-nologin-text', $titleMsg='exception-nologin')
If the user is not logged in, throws UserNotLoggedIn error.
getUser()
Shortcut to get the User executing this instance.
msg( $key)
Wrapper around wfMessage that sets the current context.
getConfig()
Shortcut to get main config object.
getRequest()
Get the WebRequest being used for this instance.
getPageTitle( $subpage=false)
Get a self-referential title object.
getLanguage()
Shortcut to get user's language.
MediaWiki Linker LinkRenderer null $linkRenderer
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a save
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
this hook is for auditing only or null if authentication failed before getting that far $username
if(!isset( $args[0])) $lang