'type' => 'check',
'label-message' => 'botpasswords-label-resetpassword',
];
+ if ( $this->botPassword->isInvalid() ) {
+ $fields['resetPassword']['default'] = true;
+ }
}
$lang = $this->getLanguage();
$showGrants
),
'default' => array_map(
- function( $g ) {
+ function ( $g ) {
return "grant-$g";
},
$this->botPassword->getGrants()
'tooltips' => array_combine(
array_map( 'MWGrants::getGrantsLink', $showGrants ),
array_map(
- function( $rights ) use ( $lang ) {
+ function ( $rights ) use ( $lang ) {
return $lang->semicolonList( array_map( 'User::getRightDescription', $rights ) );
},
array_intersect_key( MWGrants::getRightsByGrant(), array_flip( $showGrants ) )
)
),
'force-options-on' => array_map(
- function( $g ) {
+ function ( $g ) {
return "grant-$g";
},
MWGrants::getHiddenGrants()
];
$fields['restrictions'] = [
- 'type' => 'textarea',
- 'label-message' => 'botpasswords-label-restrictions',
+ 'class' => HTMLRestrictionsField::class,
'required' => true,
- 'default' => $this->botPassword->getRestrictions()->toJson( true ),
- 'rows' => 5,
- 'validation-callback' => function ( $v ) {
- try {
- MWRestrictions::newFromJson( $v );
- return true;
- } catch ( InvalidArgumentException $ex ) {
- return $ex->getMessage();
- }
- },
+ 'default' => $this->botPassword->getRestrictions(),
];
} else {
$linkRenderer = $this->getLinkRenderer();
+ $passwordFactory = new PasswordFactory();
+ $passwordFactory->init( $this->getConfig() );
+
$dbr = BotPassword::getDB( DB_REPLICA );
$res = $dbr->select(
'bot_passwords',
- [ 'bp_app_id' ],
+ [ 'bp_app_id', 'bp_password' ],
[ 'bp_user' => $this->userId ],
__METHOD__
);
foreach ( $res as $row ) {
+ try {
+ $password = $passwordFactory->newFromCiphertext( $row->bp_password );
+ $passwordInvalid = $password instanceof InvalidPassword;
+ unset( $password );
+ } catch ( PasswordError $ex ) {
+ $passwordInvalid = true;
+ }
+
+ $text = $linkRenderer->makeKnownLink(
+ $this->getPageTitle( $row->bp_app_id ),
+ $row->bp_app_id
+ );
+ if ( $passwordInvalid ) {
+ $text .= $this->msg( 'word-separator' )->escaped()
+ . $this->msg( 'botpasswords-label-needsreset' )->parse();
+ }
+
$fields[] = [
'section' => 'existing',
'type' => 'info',
'raw' => true,
- 'default' => $linkRenderer->makeKnownLink(
- $this->getPageTitle( $row->bp_app_id ),
- $row->bp_app_id
- ),
+ 'default' => $text,
];
}
'name' => 'op',
'value' => 'create',
'label-message' => 'botpasswords-label-create',
- 'flags' => [ 'primary', 'constructive' ],
+ 'flags' => [ 'primary', 'progressive' ],
] );
}
$bp = BotPassword::newUnsaved( [
'centralId' => $this->userId,
'appId' => $this->par,
- 'restrictions' => MWRestrictions::newFromJson( $data['restrictions'] ),
+ 'restrictions' => $data['restrictions'],
'grants' => array_merge(
MWGrants::getHiddenGrants(),
preg_replace( '/^grant-/', '', $data['grants'] )