61 $this->centralId = (int)$row->bp_user;
62 $this->appId = $row->bp_app_id;
63 $this->token = $row->bp_token;
73 public static function getDB( $db ) {
74 global $wgBotPasswordsCluster, $wgBotPasswordsDatabase;
76 $lb = $wgBotPasswordsCluster
78 :
wfGetLB( $wgBotPasswordsDatabase );
79 return $lb->getConnectionRef( $db, [], $wgBotPasswordsDatabase );
104 global $wgEnableBotPasswords;
106 if ( !$wgEnableBotPasswords ) {
111 $db = self::getDB( $index );
112 $row = $db->selectRow(
114 [
'bp_user',
'bp_app_id',
'bp_token',
'bp_restrictions',
'bp_grants' ],
119 return $row ?
new self( $row,
true,
$flags ) : null;
137 'bp_app_id' => isset( $data[
'appId'] ) ? trim( $data[
'appId'] ) :
'',
138 'bp_token' =>
'**unsaved**',
139 'bp_restrictions' => isset( $data[
'restrictions'] )
140 ? $data[
'restrictions']
142 'bp_grants' => isset( $data[
'grants'] ) ? $data[
'grants'] : [],
146 $row->bp_app_id ===
'' || strlen( $row->bp_app_id ) > self::APPID_MAXLENGTH ||
148 !is_array( $row->bp_grants )
153 $row->bp_restrictions = $row->bp_restrictions->toJson();
156 if ( isset( $data[
'user'] ) ) {
157 if ( !$data[
'user'] instanceof
User ) {
163 } elseif ( isset( $data[
'username'] ) ) {
167 } elseif ( isset( $data[
'centralId'] ) ) {
168 $row->bp_user = $data[
'centralId'];
170 if ( !$row->bp_user ) {
174 return new self( $row,
false,
$flags );
230 global $wgUserrightsInterwikiDelimiter;
231 return $wgUserrightsInterwikiDelimiter;
240 $db = self::getDB( $index );
241 $password = $db->selectField(
244 [
'bp_user' => $this->centralId,
'bp_app_id' => $this->appId ],
248 if ( $password ===
false ) {
252 $passwordFactory = new \PasswordFactory();
255 return $passwordFactory->newFromCiphertext( $password );
274 'bp_restrictions' => $this->restrictions->toJson(),
278 if ( $password !== null ) {
279 $fields[
'bp_password'] = $password->toString();
280 } elseif ( $operation ===
'insert' ) {
285 switch ( $operation ) {
287 $dbw->insert(
'bot_passwords', $fields + $conds, __METHOD__, [
'IGNORE' ] );
291 $dbw->update(
'bot_passwords', $fields, $conds, __METHOD__ );
297 $ok = (bool)$dbw->affectedRows();
299 $this->token = $dbw->selectField(
'bot_passwords',
'bp_token', $conds, __METHOD__ );
309 public function delete() {
315 $dbw->delete(
'bot_passwords', $conds, __METHOD__ );
316 $ok = (bool)$dbw->affectedRows();
318 $this->token =
'**unsaved**';
342 global $wgEnableBotPasswords;
344 if ( !$wgEnableBotPasswords ) {
355 return (
bool)$dbw->affectedRows();
376 global $wgEnableBotPasswords;
378 if ( !$wgEnableBotPasswords ) {
388 return (
bool)$dbw->affectedRows();
398 max( 32, $config->get(
'MinimalPasswordLength' ) ) );
415 if ( strlen( $password ) >= 32 && strpos(
$username, $sep ) !==
false ) {
417 if ( preg_match(
'/^[0-9a-w]{32,}$/', $password ) ) {
420 } elseif ( strlen( $password ) > 32 && strpos( $password, $sep ) !==
false ) {
421 $segments = explode( $sep, $password );
422 $password = array_pop( $segments );
423 $appId = implode( $sep, $segments );
424 if ( preg_match(
'/^[0-9a-w]{32,}$/', $password ) ) {
439 global $wgEnableBotPasswords;
441 if ( !$wgEnableBotPasswords ) {
452 $sep = self::getSeparator();
453 if ( strpos(
$username, $sep ) ===
false ) {
471 $status = $bp->getRestrictions()->check( $request );
477 if ( !$bp->getPassword()->equals( $password ) ) {
static newFromName($name, $validate= 'valid')
Static factory method for creation from username.
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 etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
static getSeparator()
Get the separator for combined user name + app ID.
the array() calling protocol came about after MediaWiki 1.4rc1.
static getDB($db)
Get a database connection for the bot passwords database.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
static newFatal($message)
Factory function for fatal errors.
getUserCentralId()
Get the central user ID.
const TOKEN_LENGTH
int Number of characters in user_token field.
static removeAllPasswordsForCentralId($centralId)
Remove all passwords for a user, by central ID.
static generateRandomPasswordString($minLength=10)
Generate a random string suitable for a password.
static invalidateAllPasswordsForCentralId($centralId)
Invalidate all passwords for a user, by central ID.
when a variable name is used in a it is silently declared as a new local masking the global
globals will be eliminated from MediaWiki replaced by an application object which would be passed to constructors Whether that would be an convenient solution remains to be but certainly PHP makes such object oriented programming models easier than they were in previous versions For the time being MediaWiki programmers will have to work in an environment with some global context At the time of globals were initialised on startup by MediaWiki of these were configuration which are documented in DefaultSettings php There is no comprehensive documentation for the remaining however some of the most important ones are listed below They are typically initialised either in index php or in Setup php For a description of the see design txt $wgTitle Title object created from the request URL $wgOut OutputPage object for HTTP response $wgUser User object for the user associated with the current request $wgLang Language object selected by user preferences $wgContLang Language object associated with the wiki being viewed $wgParser Parser object Parser extensions register their hooks here $wgRequest WebRequest object
static newUnsaved(array $data, $flags=self::READ_NORMAL)
Create an unsaved BotPassword.
isSaved()
Indicate whether this is known to be saved.
static newFromCentralId($centralId, $appId, $flags=self::READ_NORMAL)
Load a BotPassword from the database.
static removeAllPasswordsForUser($username)
Remove all passwords for a user, by name.
getAppId()
Get the app ID.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
save($operation, Password $password=null)
Save the BotPassword to the database.
wfGetLB($wiki=false)
Get a load balancer object.
static getMain()
Static methods.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context $options
static invalidateAllPasswordsForUser($username)
Invalidate all passwords for a user, by name.
getPassword()
Get the password.
A class to check request restrictions expressed as a JSON object.
static factory($providerId=null)
Fetch a CentralIdLookup.
static newGood($value=null)
Factory function for good results.
static getDBOptions($bitfield)
Get an appropriate DB index, options, and fallback DB index for a query.
static newFromJson($json)
static newInvalidPassword()
Create an InvalidPassword.
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
static newFromUser(User $user, $appId, $flags=self::READ_NORMAL)
Load a BotPassword from the database.
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
this hook is for auditing only or null if authentication failed before getting that far $username
wfGetLBFactory()
Get the load balancer factory object.
error also a ContextSource you ll probably need to make sure the header is varied on $request
Show an error when any operation involving passwords fails to run.
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
static generatePassword($config)
Returns a (raw, unhashed) random password string.
static generateHex($chars, $forceStrong=false)
Generate a run of (ideally) cryptographically random data and return it in hexadecimal string format...
static canonicalizeLoginData($username, $password)
There are two ways to login with a bot password: "username@appId", "password" and "username"...
Interface for database access objects.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
__construct($row, $isSaved, $flags=self::READ_NORMAL)
getGrants()
Get the grants.
static login($username, $password, WebRequest $request)
Try to log the user in.
MWRestrictions $restrictions
getRestrictions()
Get the restrictions.
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 in any and then calling but I prefer the flexibility This should also do the output encoding The system allocates a global one in $wgOut Title Represents the title of an and does all the work of translating among various forms such as plain database etc For and for historical it also represents a few features of articles that don t involve their such as access rights See also title txt Article Encapsulates access to the page table of the database The object represents a an and maintains state such as flags
Allows to change the fields on the form that will be generated $name