50 parent::__construct(
'BotPasswords',
'editmyprivateinfo' );
51 $this->logger = LoggerFactory::getInstance(
'authentication' );
58 return $this->
getConfig()->get(
'EnableBotPasswords' );
74 if ( strlen(
$par ) === 0 ) {
76 } elseif ( strlen(
$par ) > BotPassword::APPID_MAXLENGTH ) {
77 throw new ErrorPageError(
'botpasswords',
'botpasswords-bad-appid',
78 [ htmlspecialchars(
$par ) ] );
81 parent::execute(
$par );
85 parent::checkExecutePermissions(
$user );
87 if ( !$this->
getConfig()->
get(
'EnableBotPasswords' ) ) {
88 throw new ErrorPageError(
'botpasswords',
'botpasswords-disabled' );
91 $this->userId = CentralIdLookup::factory()->centralIdFromLocalUser( $this->
getUser() );
92 if ( !$this->userId ) {
93 throw new ErrorPageError(
'botpasswords',
'botpasswords-no-central-id' );
100 if ( $this->par !==
null ) {
101 $this->botPassword = BotPassword::newFromCentralId( $this->userId, $this->par );
102 if ( !$this->botPassword ) {
103 $this->botPassword = BotPassword::newUnsaved( [
104 'centralId' => $this->userId,
105 'appId' => $this->par,
109 $sep = BotPassword::getSeparator();
112 'label-message' =>
'username',
116 if ( $this->botPassword->isSaved() ) {
117 $fields[
'resetPassword'] = [
119 'label-message' =>
'botpasswords-label-resetpassword',
121 if ( $this->botPassword->isInvalid() ) {
122 $fields[
'resetPassword'][
'default'] =
true;
128 $fields[
'grants'] = [
129 'type' =>
'checkmatrix',
130 'label-message' =>
'botpasswords-label-grants',
131 'help-message' =>
'botpasswords-help-grants',
133 $this->
msg(
'botpasswords-label-grants-column' )->escaped() =>
'grant'
135 'rows' => array_combine(
136 array_map(
'MWGrants::getGrantsLink', $showGrants ),
139 'default' => array_map(
143 $this->botPassword->getGrants()
145 'tooltips' => array_combine(
146 array_map(
'MWGrants::getGrantsLink', $showGrants ),
148 function ( $rights )
use (
$lang ) {
149 return $lang->semicolonList( array_map(
'User::getRightDescription', $rights ) );
154 'force-options-on' => array_map(
162 $fields[
'restrictions'] = [
163 'class' => HTMLRestrictionsField::class,
165 'default' => $this->botPassword->getRestrictions(),
170 $passwordFactory = MediaWikiServices::getInstance()->getPasswordFactory();
175 [
'bp_app_id',
'bp_password' ],
176 [
'bp_user' => $this->userId ],
179 foreach (
$res as $row ) {
181 $password = $passwordFactory->newFromCiphertext( $row->bp_password );
185 $passwordInvalid =
true;
192 if ( $passwordInvalid ) {
193 $text .= $this->
msg(
'word-separator' )->escaped()
194 . $this->
msg(
'botpasswords-label-needsreset' )->parse();
198 'section' =>
'existing',
206 'section' =>
'createnew',
207 'type' =>
'textwithbutton',
208 'label-message' =>
'botpasswords-label-appid',
209 'buttondefault' => $this->
msg(
'botpasswords-label-create' )->text(),
210 'buttonflags' => [
'progressive',
'primary' ],
212 'size' => BotPassword::APPID_MAXLENGTH,
213 'maxlength' => BotPassword::APPID_MAXLENGTH,
214 'validation-callback' =>
function ( $v ) {
216 return $v !==
'' && strlen( $v ) <= BotPassword::APPID_MAXLENGTH;
231 $form->
setId(
'mw-botpasswords-form' );
233 $form->
addPreText( $this->
msg(
'botpasswords-summary' )->parseAsBlock() );
236 if ( $this->par !==
null ) {
237 if ( $this->botPassword->isSaved() ) {
242 'label-message' =>
'botpasswords-label-update',
243 'flags' => [
'primary',
'progressive' ],
248 'label-message' =>
'botpasswords-label-delete',
249 'flags' => [
'destructive' ],
256 'label-message' =>
'botpasswords-label-create',
257 'flags' => [
'primary',
'progressive' ],
264 'label-message' =>
'botpasswords-label-cancel'
270 $op = $this->
getRequest()->getVal(
'op',
'' );
278 $this->operation =
'insert';
279 return $this->
save( $data );
282 $this->operation =
'update';
283 return $this->
save( $data );
286 $this->operation =
'delete';
287 $bp = BotPassword::newFromCentralId( $this->userId, $this->par );
291 "Bot password {op} for {user}@{app_id}",
293 'app_id' => $this->par,
295 'centralId' => $this->userId,
301 return Status::newGood();
312 $bp = BotPassword::newUnsaved( [
313 'centralId' => $this->userId,
314 'appId' => $this->par,
315 'restrictions' =>
$data[
'restrictions'],
316 'grants' => array_merge(
318 preg_replace(
'/^grant-/',
'',
$data[
'grants'] )
322 if ( $this->operation ===
'insert' || !empty(
$data[
'resetPassword'] ) ) {
323 $this->password = BotPassword::generatePassword( $this->
getConfig() );
324 $passwordFactory = MediaWikiServices::getInstance()->getPasswordFactory();
325 $password = $passwordFactory->newFromPlaintext( $this->password );
330 if ( $bp->save( $this->operation,
$password ) ) {
332 "Bot password {op} for {user}@{app_id}",
334 'op' => $this->operation,
336 'app_id' => $this->par,
337 'centralId' => $this->userId,
338 'restrictions' =>
$data[
'restrictions'],
339 'grants' => $bp->getGrants(),
340 'client_ip' => $this->getRequest()->getIP()
343 return Status::newGood();
346 return Status::newFatal(
"botpasswords-{$this->operation}-failed", $this->par );
354 switch ( $this->operation ) {
356 $out->setPageTitle( $this->
msg(
'botpasswords-created-title' )->
text() );
357 $out->addWikiMsg(
'botpasswords-created-body', $this->par,
$username );
361 $out->setPageTitle( $this->
msg(
'botpasswords-updated-title' )->
text() );
362 $out->addWikiMsg(
'botpasswords-updated-body', $this->par,
$username );
366 $out->setPageTitle( $this->
msg(
'botpasswords-deleted-title' )->
text() );
367 $out->addWikiMsg(
'botpasswords-deleted-body', $this->par,
$username );
368 $this->password =
null;
372 if ( $this->password !==
null ) {
373 $sep = BotPassword::getSeparator();
375 'botpasswords-newpassword',
376 htmlspecialchars(
$username . $sep . $this->par ),
377 htmlspecialchars( $this->password ),
379 htmlspecialchars( $this->par . $sep . $this->password )
381 $this->password =
null;
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
This list may contain false positives That usually means there is additional text with links below the first Each row contains links to the first and second as well as the first line of the second redirect text
Utility class for bot passwords.
An error page which can definitely be safely rendered using the OutputPage.
Special page which uses an HTMLForm to handle processing.
string null $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.
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.
Psr Log LoggerInterface $logger
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
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
$data
Utility to generate mapping file used in mw.Title (phpCharToUpper.json)
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password 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
return true to allow those checks to and false if checking is done & $user
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
if(!isset( $args[0])) $lang