User:Zackmann08/scripts/SetupAutoArchive.js
//<nowiki>
function getArchiveCounter(current) {
var url = "https://en.wikipedia.org/w/api.php?action=query&titles=" + mw.config.get('wgPageName') + "/Archive_" + current + "&format=json&formatversion=2";
var cont = true;
$.ajax({
async: false,
type: 'GET',
url: url,
success: function(data) {
if (data.query.pages["0"].missing) {
cont = false;
}
}
});
if(cont){
return getArchiveCounter(current+1);
}
return current>1 ? current-1 : current;
}
function parse_text(text) {
//Check if already configured for auto-archiving
if (text.search("User:MiszaBot\/config") >=0 || text.search("User:ClueBot III\/ArchiveThis") >= 0 ) {
alert('Auto archiving already added, aborting.');
return null;
}
// Insert the template at the top of the page.
var new_text = ("{{subst:"
+ "Setup auto archiving|small=yes|notice=yes|counter="
+ getArchiveCounter(1)
+ "|talk=yes}}\n"
+ text).replace(/{{archive\s*me}}|{{long\s*talk}}|{{Tpcleanup}}|{{talk\s*header}}|{{talk\s*page}}|{{tph}}|{{archive\s*request}}/ig, '');
return new_text;
}
function callApi() {
mw.loader.using( "mediawiki.api", function () {
var api = new mw.Api();
api.get( {
prop: 'revisions',
rvprop: 'content',
rvlimit: 1,
titles: mw.config.get( "wgPageName" )
} ).done( function ( data ) {
if ( !data.query || !data.query.pages ) return;
var pageid = Object.getOwnPropertyNames( data.query.pages )[0],
text = data.query.pages[pageid].revisions[0]["*"];
var new_text = parse_text(text);
if (new_text == null) {
return;
}
var summary = '';
if (mw.config.get('wgNamespaceNumber') == 3) {
summary = " Helping you out by setting up [[WP:ARCHIVE|auto-archiving]] using [[User:Zackmann08/scripts/SetupAutoArchive|SetupAutoArchive.js]]. " +
"This is not required, but is helpful, particularly for [[WP:TALKSIZE|large talk pages]]. You are free to revert if not desired.";
} else {
summary = "Setting up automatic archiving using [[User:Zackmann08/scripts/SetupAutoArchive|SetupAutoArchive.js]]";
}
api.postWithEditToken( {
action: "edit",
title: mw.config.get( "wgPageName" ),
summary: summary,
text: new_text
} ).done ( function ( data ) {
if ( data && data.edit && data.edit.result && data.edit.result == 'Success' ) {
mw.notify( "Archiving successfully setup! Reloading in 2 seconds...", {type: 'success'} );
window.setTimeout( function () {
document.location.reload( true );
}, 2000 );
}
} );
} );
} );
}
function startAutoArchive() {
var common_list = window.DoNotArchive || [];
var do_not_archive = ['ElijahPepe', 'EEng'];
do_not_archive.push(...common_list);
var pagename = mw.config.get('wgTitle');
if (do_not_archive.includes(pagename)) {
alert(pagename + ' is on the reject list. Aborting.');
} else {
mw.notify( "Setting up archive", {type: 'notice'} );
callApi();
}
}
jQuery(document).ready(function($) {
if (["talk", "wikipedia"].some(function (str) {
return mw.config.get('wgCanonicalNamespace').toLowerCase().indexOf(str) > -1;
})) {
mw.util.addPortletLink(
"p-cactions",
"javascript:startAutoArchive()",
"Setup Archive",
"autoArchive",
"Add auto archiving",
"");
}
});
//</nowiki>
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.