No edit summary |
Add admin speedy delete option Tags: Mobile edit Mobile web edit Advanced mobile edit |
||
| Line 29: | Line 29: | ||
] } | ] } | ||
]; | ]; | ||
function talkTitle( title ) { | |||
var i = title.indexOf( ':' ); | |||
if ( i === -1 ) { return 'Talk:' + title; } | |||
var ns = title.slice( 0, i ), rest = title.slice( i + 1 ); | |||
if ( ns === 'Talk' ) { return title; } | |||
return ns + ' talk:' + rest; | |||
} | |||
function deletePage( title, reason ) { | |||
return BM.core.api().postWithToken( 'delete', { | |||
action: 'delete', title: title, reason: reason, format: 'json' | |||
} ).then( function ( r ) { | |||
if ( r && r.delete ) { return r; } | |||
throw new Error( 'Could not delete ' + title + '.' ); | |||
} ); | |||
} | |||
function criterionLabel( code ) { | |||
var label = code; | |||
GROUPS.forEach( function ( g ) { | |||
g.options.forEach( function ( o ) { if ( o[ 0 ] === code ) { label = o[ 1 ]; } } ); | |||
} ); | |||
return label; | |||
} | |||
function deleteDialog() { | |||
var title = mw.config.get( 'wgPageName' ).replace( /_/g, ' ' ); | |||
BM.core.dialog( { | |||
title: 'Delete page now (speedy)', | |||
help: 'Page: ' + title + '. This deletes the page at once under a speedy deletion criterion. Only administrators can do this.', | |||
fields: [ | |||
{ name: 'criterion', label: 'Criterion', type: 'select', required: true, options: GROUPS }, | |||
{ name: 'note', label: 'Extra note for the deletion log', type: 'text' }, | |||
{ name: 'talk', label: 'Also delete the talk page', type: 'checkbox', value: true } | |||
], | |||
preview: function ( v ) { | |||
return 'This page will be deleted with the reason: Speedy deletion (' + | |||
criterionLabel( v.criterion ) + ')' + | |||
( BM.core.cleanParam( v.note ) ? '. ' + BM.core.cleanParam( v.note ) : '' ); | |||
}, | |||
previewTitle: function () { return title; }, | |||
submitLabel: 'Delete the page', | |||
success: 'The page has been deleted.', | |||
onSubmit: function ( v ) { | |||
var reason = 'Speedy deletion (' + criterionLabel( v.criterion ) + ')' + | |||
( BM.core.cleanParam( v.note ) ? '. ' + BM.core.cleanParam( v.note ) : '' ) + | |||
' (using [[Bharatpedia:Bharat Mitra|Bharat Mitra]])'; | |||
return deletePage( title, reason ).then( function () { | |||
if ( !v.talk ) { return null; } | |||
var tt = talkTitle( title ); | |||
return BM.core.getPage( tt ).then( function ( tp ) { | |||
if ( tp.exists ) { return deletePage( tt, reason ); } | |||
return null; | |||
} ); | |||
} ); | |||
} | |||
} ); | |||
} | |||
function buildTag( v ) { | function buildTag( v ) { | ||
/* The Db templates exist only with a lowercase code (Db-a7, Db-g11, | /* The Db templates exist only with a lowercase code (Db-a7, Db-g11, | ||
| Line 84: | Line 139: | ||
} ); | } ); | ||
} ); | } ); | ||
} | }, | ||
openDelete: function () { deleteDialog(); } | |||
} ); | } ); | ||
}() ); | }() ); | ||
/* </nowiki> */ | /* </nowiki> */ | ||
Latest revision as of 10:36, 18 November 2026
/* <nowiki> */
/* Bharat Mitra: speedy deletion module */
( function () {
'use strict';
var BM = window.BharatMitra;
var GROUPS = [
{ group: 'General', options: [
[ 'G11', 'G11: Spam or advertising' ],
[ 'G3', 'G3: Vandalism or hoax' ],
[ 'G1', 'G1: Nonsense or gibberish' ],
[ 'G2', 'G2: Test page' ],
[ 'G12', 'G12: Copyright violation' ],
[ 'G10', 'G10: Attack page' ]
] },
{ group: 'Articles', options: [
[ 'A7', 'A7: No indication of importance, no reliable sources' ],
[ 'A2', 'A2: Foreign-language article with no context' ],
[ 'A1', 'A1: Very short article, no context' ],
[ 'G4', 'G4: Recreated deleted material without improvement' ]
] },
{ group: 'Redirects', options: [
[ 'G8', 'G8: Broken redirect to a page that does not exist' ],
[ 'R3', 'R3: Redirect from an implausible typo' ]
] },
{ group: 'Files', options: [
[ 'F3', 'F3: Image with an unacceptable licence' ],
[ 'F1', 'F1: Redundant image' ],
[ 'F5', 'F5: Unused non-free image' ]
] }
];
function talkTitle( title ) {
var i = title.indexOf( ':' );
if ( i === -1 ) { return 'Talk:' + title; }
var ns = title.slice( 0, i ), rest = title.slice( i + 1 );
if ( ns === 'Talk' ) { return title; }
return ns + ' talk:' + rest;
}
function deletePage( title, reason ) {
return BM.core.api().postWithToken( 'delete', {
action: 'delete', title: title, reason: reason, format: 'json'
} ).then( function ( r ) {
if ( r && r.delete ) { return r; }
throw new Error( 'Could not delete ' + title + '.' );
} );
}
function criterionLabel( code ) {
var label = code;
GROUPS.forEach( function ( g ) {
g.options.forEach( function ( o ) { if ( o[ 0 ] === code ) { label = o[ 1 ]; } } );
} );
return label;
}
function deleteDialog() {
var title = mw.config.get( 'wgPageName' ).replace( /_/g, ' ' );
BM.core.dialog( {
title: 'Delete page now (speedy)',
help: 'Page: ' + title + '. This deletes the page at once under a speedy deletion criterion. Only administrators can do this.',
fields: [
{ name: 'criterion', label: 'Criterion', type: 'select', required: true, options: GROUPS },
{ name: 'note', label: 'Extra note for the deletion log', type: 'text' },
{ name: 'talk', label: 'Also delete the talk page', type: 'checkbox', value: true }
],
preview: function ( v ) {
return 'This page will be deleted with the reason: Speedy deletion (' +
criterionLabel( v.criterion ) + ')' +
( BM.core.cleanParam( v.note ) ? '. ' + BM.core.cleanParam( v.note ) : '' );
},
previewTitle: function () { return title; },
submitLabel: 'Delete the page',
success: 'The page has been deleted.',
onSubmit: function ( v ) {
var reason = 'Speedy deletion (' + criterionLabel( v.criterion ) + ')' +
( BM.core.cleanParam( v.note ) ? '. ' + BM.core.cleanParam( v.note ) : '' ) +
' (using [[Bharatpedia:Bharat Mitra|Bharat Mitra]])';
return deletePage( title, reason ).then( function () {
if ( !v.talk ) { return null; }
var tt = talkTitle( title );
return BM.core.getPage( tt ).then( function ( tp ) {
if ( tp.exists ) { return deletePage( tt, reason ); }
return null;
} );
} );
}
} );
}
function buildTag( v ) {
/* The Db templates exist only with a lowercase code (Db-a7, Db-g11,
Db-r3 and so on); Db-A7 / Db-G11 are missing templates, so the
criterion must be lowercased or the tag never renders. */
return '{{subst:db-' + v.criterion.toLowerCase() + '}}';
}
BM.register( 'speedy', {
open: function () {
var title = mw.config.get( 'wgPageName' ).replace( /_/g, ' ' );
BM.core.getConfig().then( function ( cfg ) {
BM.core.dialog( {
title: 'Nominate for speedy deletion',
help: 'Page: ' + title + '. The criteria are those listed at Bharatpedia:Criteria for speedy deletion. The creator will be notified under this month\'s section.',
fields: [
{ name: 'criterion', label: 'Criterion', type: 'select', required: true, options: GROUPS },
{ name: 'note', label: 'Note (goes in the edit summary)', type: 'text' },
{ name: 'notify', label: 'Notify the creator', type: 'checkbox', value: cfg.speedyNotify !== false }
],
preview: function ( v ) { return buildTag( v ); },
previewTitle: function () { return title; },
submitLabel: 'Nominate',
success: 'The page has been nominated for speedy deletion.',
onSubmit: function ( v ) {
return BM.core.getPage( title ).then( function ( p ) {
if ( !p.exists ) { throw new Error( 'This page does not exist.' ); }
if ( /\{\{\s*(?:subst:)?db/i.test( p.content ) ) {
throw new Error( 'This page already has a speedy deletion tag.' );
}
var tag = buildTag( v );
var nl = p.content.indexOf( '\n' );
var firstLine = nl === -1 ? p.content : p.content.slice( 0, nl );
var newContent;
if ( /^\s*#\s*REDIRECT/i.test( firstLine ) && nl !== -1 ) {
newContent = firstLine + '\n' + tag + p.content.slice( nl );
} else {
newContent = tag + '\n' + p.content;
}
var note = BM.core.cleanParam( v.note );
var summary = 'Nominated for speedy deletion (' + v.criterion + ')' +
( note ? ': ' + note : '' ) + ' (using [[Bharatpedia:Bharat Mitra|Bharat Mitra]])';
return BM.core.savePage( title, newContent, summary, p.revid ).then( function () {
if ( !v.notify ) { return null; }
var block = '{{subst:Db-notice|' + BM.core.cleanParam( title ) + '}}\n' + BM.SIG;
return BM.core.notifyCreator( title, block,
'Speedy deletion notice (using [[Bharatpedia:Bharat Mitra|Bharat Mitra]])' ).then( function ( status ) {
if ( status === 'skipped' || status === 'failed' ) {
mw.notify( 'The page has been nominated, but the creator could not be notified (no local account for the creator).', { type: 'warn' } );
}
return null;
} );
} );
} );
}
} );
} );
},
openDelete: function () { deleteDialog(); }
} );
}() );
/* </nowiki> */