51 'BotPasswordsCluster',
52 'BotPasswordsDatabase',
87 if ( $this->options->get(
'BotPasswordsCluster' ) ) {
88 $loadBalancer = $this->lbFactory->getExternalLB(
89 $this->options->get(
'BotPasswordsCluster' )
92 $loadBalancer = $this->lbFactory->getMainLB(
93 $this->options->get(
'BotPasswordsDatabase' )
96 return $loadBalancer->getConnectionRef(
99 $this->options->get(
'BotPasswordsDatabase' )
113 int $flags = self::READ_NORMAL
115 if ( !$this->options->get(
'EnableBotPasswords' ) ) {
119 $centralId = $this->centralIdLookup->centralIdFromLocalUser(
124 return $centralId ? $this->getByCentralId( $centralId, $appId, $flags ) : null;
137 int $flags = self::READ_NORMAL
139 if ( !$this->options->get(
'EnableBotPasswords' ) ) {
143 list( $index, $options ) = DBAccessObjectUtils::getDBOptions( $flags );
144 $db = $this->getDatabase( $index );
145 $row = $db->selectRow(
147 [
'bp_user',
'bp_app_id',
'bp_token',
'bp_restrictions',
'bp_grants' ],
148 [
'bp_user' => $centralId,
'bp_app_id' => $appId ],
152 return $row ?
new BotPassword( $row,
true, $flags ) : null;
169 int $flags = self::READ_NORMAL
171 if ( isset( $data[
'user'] ) && ( !$data[
'user'] instanceof
UserIdentity ) ) {
177 'bp_app_id' => isset( $data[
'appId'] ) ? trim( $data[
'appId'] ) :
'',
178 'bp_token' =>
'**unsaved**',
179 'bp_restrictions' => $data[
'restrictions'] ??
MWRestrictions::newDefault(),
180 'bp_grants' => $data[
'grants'] ?? [],
184 $row->bp_app_id ===
'' ||
185 strlen( $row->bp_app_id ) > BotPassword::APPID_MAXLENGTH ||
187 !is_array( $row->bp_grants )
192 $row->bp_restrictions = $row->bp_restrictions->toJson();
193 $row->bp_grants = FormatJson::encode( $row->bp_grants );
195 if ( isset( $data[
'user'] ) ) {
197 $row->bp_user = $this->centralIdLookup->centralIdFromLocalUser(
199 CentralIdLookup::AUDIENCE_RAW,
202 } elseif ( isset( $data[
'username'] ) ) {
203 $row->bp_user = $this->centralIdLookup->centralIdFromName(
205 CentralIdLookup::AUDIENCE_RAW,
208 } elseif ( isset( $data[
'centralId'] ) ) {
209 $row->bp_user = $data[
'centralId'];
211 if ( !$row->bp_user ) {
231 $res = $this->validateBotPassword( $botPassword );
232 if ( !
$res->isGood() ) {
236 if ( $password ===
null ) {
237 $password = PasswordFactory::newInvalidPassword();
241 'bp_app_id' => $botPassword->
getAppId(),
244 'bp_grants' => FormatJson::encode( $botPassword->
getGrants() ),
245 'bp_password' => $password->toString(),
256 $ok = (bool)$dbw->affectedRows();
258 $token = $dbw->selectField(
263 'bp_app_id' => $botPassword->
getAppId(),
267 return StatusValue::newGood( $token );
269 return StatusValue::newFatal(
'botpasswords-insert-failed', $botPassword->
getAppId() );
285 $res = $this->validateBotPassword( $botPassword );
286 if ( !
$res->isGood() ) {
292 'bp_app_id' => $botPassword->
getAppId(),
297 'bp_grants' => FormatJson::encode( $botPassword->
getGrants() ),
299 if ( $password !==
null ) {
300 $fields[
'bp_password'] = $password->toString();
311 $ok = (bool)$dbw->affectedRows();
313 $token = $dbw->selectField(
319 return StatusValue::newGood( $token );
321 return StatusValue::newFatal(
'botpasswords-update-failed', $botPassword->
getAppId() );
335 if ( strlen( $restrictions ) > BotPassword::RESTRICTIONS_MAXLENGTH ) {
336 $res->fatal(
'botpasswords-toolong-restrictions' );
339 $grants = FormatJson::encode( $botPassword->
getGrants() );
340 if ( strlen( $grants ) > BotPassword::GRANTS_MAXLENGTH ) {
341 $res->fatal(
'botpasswords-toolong-grants' );
359 'bp_app_id' => $botPassword->
getAppId(),
364 return (
bool)$dbw->affectedRows();
373 if ( !$this->options->get(
'EnableBotPasswords' ) ) {
377 $centralId = $this->centralIdLookup->centralIdFromName(
379 CentralIdLookup::AUDIENCE_RAW,
380 CentralIdLookup::READ_LATEST
389 [
'bp_password' => PasswordFactory::newInvalidPassword()->toString() ],
390 [
'bp_user' => $centralId ],
393 return (
bool)$dbw->affectedRows();
402 if ( !$this->options->get(
'EnableBotPasswords' ) ) {
406 $centralId = $this->centralIdLookup->centralIdFromName(
408 CentralIdLookup::AUDIENCE_RAW,
409 CentralIdLookup::READ_LATEST
418 [
'bp_user' => $centralId ],
421 return (
bool)$dbw->affectedRows();
if(ini_get('mbstring.func_overload')) if(!defined('MW_ENTRY_POINT'))
Pre-config setup: Before loading LocalSettings.php.
Utility class for bot passwords.
getUserCentralId()
Get the central user ID.
The CentralIdLookup service allows for connecting local users with cluster-wide IDs.
Helper class for DAO classes.
A class to check request restrictions expressed as a JSON object.
Factory class for creating and checking Password objects.
Represents a password hash for use in authentication.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
const TOKEN_LENGTH
Number of characters required for the user_token field.
Interface for database access objects.