Go to the documentation of this file.
62 $this->centralId = (int)$row->bp_user;
63 $this->appId = $row->bp_app_id;
64 $this->token = $row->bp_token;
74 public static function getDB( $db ) {
75 global $wgBotPasswordsCluster, $wgBotPasswordsDatabase;
77 $lb = $wgBotPasswordsCluster
79 :
wfGetLB( $wgBotPasswordsDatabase );
80 return $lb->getConnectionRef( $db, [], $wgBotPasswordsDatabase );
105 global $wgEnableBotPasswords;
107 if ( !$wgEnableBotPasswords ) {
113 $row = $db->selectRow(
115 [
'bp_user',
'bp_app_id',
'bp_token',
'bp_restrictions',
'bp_grants' ],
120 return $row ?
new self( $row,
true,
$flags ) :
null;
138 'bp_app_id' => isset( $data[
'appId'] ) ? trim( $data[
'appId'] ) :
'',
139 'bp_token' =>
'**unsaved**',
140 'bp_restrictions' => isset( $data[
'restrictions'] )
141 ? $data[
'restrictions']
143 'bp_grants' => isset( $data[
'grants'] ) ? $data[
'grants'] : [],
147 $row->bp_app_id ===
'' || strlen( $row->bp_app_id ) > self::APPID_MAXLENGTH ||
149 !is_array( $row->bp_grants )
154 $row->bp_restrictions = $row->bp_restrictions->toJson();
157 if ( isset( $data[
'user'] ) ) {
158 if ( !$data[
'user'] instanceof
User ) {
164 } elseif ( isset( $data[
'username'] ) ) {
168 } elseif ( isset( $data[
'centralId'] ) ) {
169 $row->bp_user = $data[
'centralId'];
171 if ( !$row->bp_user ) {
175 return new self( $row,
false,
$flags );
231 global $wgUserrightsInterwikiDelimiter;
232 return $wgUserrightsInterwikiDelimiter;
242 $password = $db->selectField(
245 [
'bp_user' => $this->centralId,
'bp_app_id' => $this->appId ],
249 if ( $password ===
false ) {
253 $passwordFactory = new \PasswordFactory();
256 return $passwordFactory->newFromCiphertext( $password );
275 'bp_restrictions' => $this->restrictions->toJson(),
279 if ( $password !==
null ) {
280 $fields[
'bp_password'] = $password->toString();
281 } elseif ( $operation ===
'insert' ) {
286 switch ( $operation ) {
288 $dbw->insert(
'bot_passwords', $fields + $conds, __METHOD__, [
'IGNORE' ] );
292 $dbw->update(
'bot_passwords', $fields, $conds, __METHOD__ );
298 $ok = (bool)$dbw->affectedRows();
300 $this->token = $dbw->selectField(
'bot_passwords',
'bp_token', $conds, __METHOD__ );
310 public function delete() {
316 $dbw->delete(
'bot_passwords', $conds, __METHOD__ );
317 $ok = (bool)$dbw->affectedRows();
319 $this->token =
'**unsaved**';
343 global $wgEnableBotPasswords;
345 if ( !$wgEnableBotPasswords ) {
356 return (
bool)$dbw->affectedRows();
377 global $wgEnableBotPasswords;
379 if ( !$wgEnableBotPasswords ) {
389 return (
bool)$dbw->affectedRows();
399 max( 32, $config->get(
'MinimalPasswordLength' ) ) );
416 if ( strlen( $password ) >= 32 && strpos(
$username, $sep ) !==
false ) {
418 if ( preg_match(
'/^[0-9a-w]{32,}$/', $password ) ) {
421 } elseif ( strlen( $password ) > 32 && strpos( $password, $sep ) !==
false ) {
422 $segments = explode( $sep, $password );
423 $password = array_pop( $segments );
424 $appId = implode( $sep, $segments );
425 if ( preg_match(
'/^[0-9a-w]{32,}$/', $password ) ) {
440 global $wgEnableBotPasswords;
442 if ( !$wgEnableBotPasswords ) {
454 if ( strpos(
$username, $sep ) ===
false ) {
478 if ( !$bp->getPassword()->equals( $password ) ) {
A class to check request restrictions expressed as a JSON object.
getRestrictions()
Get the restrictions.
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
error also a ContextSource you ll probably need to make sure the header is varied on $request
getUserCentralId()
Get the central user ID.
static canonicalizeLoginData( $username, $password)
There are two ways to login with a bot password: "username@appId", "password" and "username",...
wfGetLB( $wiki=false)
Get a load balancer object.
Utility class for bot passwords.
static getSeparator()
Get the separator for combined user name + app ID.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup 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
static generatePassword( $config)
Returns a (raw, unhashed) random password string.
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
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 account $user
static newFatal( $message)
Factory function for fatal errors.
Show an error when any operation involving passwords fails to run.
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
getAppId()
Get the app ID.
static generateRandomPasswordString( $minLength=10)
Generate a random string suitable for a password.
static generateHex( $chars, $forceStrong=false)
Generate a run of (ideally) cryptographically random data and return it in hexadecimal string format.
static getDBOptions( $bitfield)
Get an appropriate DB index, options, and fallback DB index for a query.
Allows to change the fields on the form that will be generated $name
static getDB( $db)
Get a database connection for the bot passwords database.
static invalidateAllPasswordsForCentralId( $centralId)
Invalidate all passwords for a user, by central ID.
Interface for database access objects.
__construct( $row, $isSaved, $flags=self::READ_NORMAL)
save( $operation, Password $password=null)
Save the BotPassword to 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
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
isSaved()
Indicate whether this is known to be saved.
static newUnsaved(array $data, $flags=self::READ_NORMAL)
Create an unsaved BotPassword.
const TOKEN_LENGTH
@const int Number of characters in user_token field.
when a variable name is used in a it is silently declared as a new masking the global
static newFromUser(User $user, $appId, $flags=self::READ_NORMAL)
Load a BotPassword from the database.
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
getPassword()
Get the password.
static newGood( $value=null)
Factory function for good results.
static invalidateAllPasswordsForUser( $username)
Invalidate all passwords for a user, by name.
static getMain()
Static methods.
wfGetLBFactory()
Get the load balancer factory object.
static newFromCentralId( $centralId, $appId, $flags=self::READ_NORMAL)
Load a BotPassword from the database.
static login( $username, $password, WebRequest $request)
Try to log the user in.
The WebRequest class encapsulates getting at data passed in the URL or via a POSTed form stripping il...
getGrants()
Get the grants.
static newInvalidPassword()
Create an InvalidPassword.
static newFromJson( $json)
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
static removeAllPasswordsForUser( $username)
Remove all passwords for a user, by name.
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
Represents a password hash for use in authentication.
static factory( $providerId=null)
Fetch a CentralIdLookup.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
this hook is for auditing only or null if authentication failed before getting that far $username
Advanced database interface for IDatabase handles that include maintenance methods.
static removeAllPasswordsForCentralId( $centralId)
Remove all passwords for a user, by central ID.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup 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
MWRestrictions $restrictions
the array() calling protocol came about after MediaWiki 1.4rc1.