« 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.checkCategoryprepare, 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.checkCategoryprepare, 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() {
var oldCatNamethis.oldTitle = mw.config.get( 'wgTitle' ),;
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;
this.reason = this.reasonInput.getValue(),.trim();
}
if ( mw.Title.makeTitle( 14, this.newNameInput.getValue().trim()newName ) === null ) {
thisreturn new OO.errorHandlerui.Error( 'Le titre de la catégorie demandée est non valide, vide, ou mal formé.' );
};
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é.' );
return this.deferred;
}
 
Ligne 194 ⟶ 219 :
'formatversion': 2,
'prop': 'categoryinfo',
'titles': 'Category:' + this.newNameInput.getValue()newPageName
} ).then( function( data ) {
console.log( data );
Ligne 397 ⟶ 422 :
*/
CatRename.prototype.editMembers = function() {
var dialog = this;,
var totalPages = this.members.length;,
oldCatRegex = this.buildRegex( oldCatNamethis.oldTitle ),
newCatRegex = buildRegex( newCatNamethis.newTitle ),
summary = 'Remplacement de la catégorie [[Catégorie:$1]] par [[Catégorie:$2]] : $3'
.replace( '$1', oldCatNamethis.oldTitle )
.replace( '$2', newCatNamethis.newTitle )
.replace( '$3', this.reason ),
commonPayload = {
summary: summary,
minor: true,
tags: TAG
};
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 ),
newCatName = this.newNameInput.getValue(),
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[[' + mwthis.config.get('wgFormattedNamespaces')[ 14 ] + ':' + newCatNamenewPageName + '$6]]'
);
}
Ligne 459 ⟶ 480 :
setTimeout( doEdit, dialog.noSpammingDelay );
} )
.fail( function ( reasoncode, data ) {
console.log( reasoncode );
console.log( data );
if ( reasoncode === 'protectedpage' ) {
dialog.logFailedPages( member, 'La page est protégée en écriture.' );
doEdit();
}
else {
dialog.errorHandler( reasoncode );
}
} );
Ligne 493 ⟶ 514 :
'format': 'json',
'from': mw.config.get( 'wgPageName' ),
'to': 'Category:' + this.newNameInput.getValue()newPageName,
'reason': this.reasonInput.getValue()reason,
'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.newNameInput.getValue()newPageName ) );
}
else {
Ligne 543 ⟶ 564 :
var content = '\n{{Déplacement catégorie'
+ '|ancienne=' + mw.config.get( 'wgPageName' )
+ '|nouvelle=' + 'Catégorie:' + this.newNameInput.getValue()newPageName
+ '|raison=' + this.reasonInput.getValue()reason
+ '}}';
 
Ligne 599 ⟶ 620 :
 
setTimeout( function() {
window.location = mw.util.getUrl( 'Category:' + dialog.newNameInput.getValue()newPageName );
}, 1000 );
};
Ligne 656 ⟶ 677 :
*/
CatRename.prototype.errorHandler = function ( error, recoverable, warning ) {
recoverablevar errorMessage = new OO.ui.Error( error, { recoverable: recoverable || true, warning: warning || false } );
warning = warning || false;
this.unlockMultitabs();
Ligne 663 ⟶ 683 :
this.$body.append( this.configContent.$element );
this.deferred.reject( new OO.ui.Error( error, { recoverable: recoverable, warning: warning } )errorMessage );
};