« MediaWiki:Gadget-CatRename.js » : différence entre les versions
Contenu supprimé Contenu ajouté
m petit réarrangement de l'ordre de certaines méthodes, pour clarifier un peu le code |
Récupération, traitement (merci Od1n !) et validation des inputs de l'utilisateur une fois pour toute en début de process |
||
Ligne 121 :
CatRename.prototype.getActionProcess = function ( action ) {
if ( action === 'rename' ) {
return new OO.ui.Process()
.next( this. .next( this.checkCategory, this )
.next( this.getMembers, this )
.next( this.lockMultitabs, this )
Ligne 132 ⟶ 134 :
}
else if ( action === 'rbot' ) {
return new OO.ui.Process()
.next( this. .next( this.checkCategory, this )
.next( this.getMembers, this )
.next( this.postRBot, this )
.next( this.renameCategory, this )
.next( this.unlockMultitabs, this )
.next( this.success, this )
.next( this.close, this );
}
else if ( action === 'cancel' ) {
return new OO.ui.Process()
.next( this.unlockMultitabs, this ) .next( this.close, this );
}
Ligne 158 ⟶ 165 :
/* Process step methods */
/**
* Fetch and validate user's input to make it easily accessible later.
*
* @return {undefined|OO.ui.Error} Error message for the ProcessDialog
* to display, if any.
*/
CatRename.prototype.prepare = function() {
this.newTitle = this.newNameInput.getValue().trim().replace(/^([Cc]atégorie|[Cc]ategory):/, '');
this.oldPageName = mw.config.get('wgFormattedNamespaces')[ 14 ] + ':' + this.oldTitle;
this.newPageName = mw.config.get('wgFormattedNamespaces')[ 14 ] + ':' + this.newdTitle;
if ( this.reason === '' ) {
return new OO.ui.Error( 'Veuillez indiquer une explication pour ce renommage.' );
}
return;
};
/**
Ligne 182 ⟶ 212 :
return this.deferred;
}
▲ }
▲ if ( mw.Title.makeTitle( 14, this.newNameInput.getValue().trim() ) === null ) {
▲ this.errorHandler( 'Le titre de la catégorie demandée est non valide, vide, ou mal formé.' );
}
Ligne 194 ⟶ 219 :
'formatversion': 2,
'prop': 'categoryinfo',
'titles':
} ).then( function( data ) {
console.log( data );
Ligne 397 ⟶ 422 :
*/
CatRename.prototype.editMembers = function() {
var dialog = this
.replace( '$3', this.reason ),▼
};
this.deferred = $.Deferred();
▲ var totalPages = this.members.length;
console.log( '---> Édition des membres de la catégorie' );
▲ var oldCatName = mw.config.get( 'wgTitle' ),
▲ oldCatRegex = this.buildRegex( oldCatName ),
▲ newCatRegex = buildRegex( newCatName ),
▲ reason = this.reasonInput.getValue(),
▲ summary = 'Remplacement de la catégorie [[Catégorie:$1]] par [[Catégorie:$2]] : $3'
▲ .replace( '$1', oldCatName )
▲ .replace( '$2', newCatName )
▲ .replace( '$3', reason ),
▲ commonPayload = {
▲ summary: summary,
▲ minor: true,
▲ tags: TAG
▲ };
if ( this.userInGroup( 'bot' ) ) {
Ligne 445 ⟶ 466 :
content = content.replace(
oldCatRegex,
'$1[[' +
);
}
Ligne 459 ⟶ 480 :
setTimeout( doEdit, dialog.noSpammingDelay );
} )
.fail( function (
console.log(
console.log( data );
if (
dialog.logFailedPages( member, 'La page est protégée en écriture.' );
doEdit();
}
else {
dialog.errorHandler(
}
} );
Ligne 493 ⟶ 514 :
'format': 'json',
'from': mw.config.get( 'wgPageName' ),
'to':
'reason': this.
'tags': TAG,
'formatversion': '2'
Ligne 518 ⟶ 539 :
} ).fail( function( error ) {
if ( error === 'articleexists' ) {
dialog.errorHandler( 'Impossible de déplacer la catégorie, la page de destination « $1 » existe déjà.'.replace( '$1', dialog.
}
else {
Ligne 543 ⟶ 564 :
var content = '\n{{Déplacement catégorie'
+ '|ancienne=' + mw.config.get( 'wgPageName' )
+ '|nouvelle=
+ '|raison=' + this.
+ '}}';
Ligne 599 ⟶ 620 :
setTimeout( function() {
window.location = mw.util.getUrl(
}, 1000 );
};
Ligne 656 ⟶ 677 :
*/
CatRename.prototype.errorHandler = function ( error, recoverable, warning ) {
this.unlockMultitabs();
Ligne 663 ⟶ 683 :
this.$body.append( this.configContent.$element );
this.deferred.reject(
};
|