Skip to content
This repository has been archived by the owner on Feb 4, 2021. It is now read-only.

Commit

Permalink
RELEASE: 25 September 2013
Browse files Browse the repository at this point in the history
The 25 September release brings with it a brand new interface to add
WikiProject templates to talk pages, widespread CSD logging, integrated
[[User:Ohconfucius/script/formatgeneral.js|formatgeneral.js]] cleanup,
automatic deletion of redirects in the way of acceptance (admins only),
bug fixes, speed improvements, and unicorns.
  • Loading branch information
theopolisme committed Sep 25, 2013
1 parent b4cb0f3 commit 344930a
Show file tree
Hide file tree
Showing 7 changed files with 519 additions and 290 deletions.
5 changes: 5 additions & 0 deletions README.md
Expand Up @@ -20,5 +20,10 @@ To import a script, add it to [your common.js page](http://en.wikipedia.org/wiki


The only exception to this is for the `master` script: to use it, you just need to check the box next to "Yet Another AFC Helper Script" in [your preferences](http://en.wikipedia.org/wiki/Special:Preferences#mw-prefsection-gadgets). The only exception to this is for the `master` script: to use it, you just need to check the box next to "Yet Another AFC Helper Script" in [your preferences](http://en.wikipedia.org/wiki/Special:Preferences#mw-prefsection-gadgets).


If the script isn't showing up (for `beta` and `develop`), try clearing your cache first.

## License ## License
The script is licensed under the [Creative Commons Attribution-ShareAlike 3.0 Unported License](http://en.wikipedia.org/wiki/Wikipedia:Text_of_Creative_Commons_Attribution-ShareAlike_3.0_Unported_License) and the [GNU Free Documentation License](http://en.wikipedia.org/wiki/Wikipedia:Text_of_the_GNU_Free_Documentation_License). The script is licensed under the [Creative Commons Attribution-ShareAlike 3.0 Unported License](http://en.wikipedia.org/wiki/Wikipedia:Text_of_Creative_Commons_Attribution-ShareAlike_3.0_Unported_License) and the [GNU Free Documentation License](http://en.wikipedia.org/wiki/Wikipedia:Text_of_the_GNU_Free_Documentation_License).

## Chat
If you need help or want to discuss something directly, we have a IRC located at freenode.net #wikipedia-en-afc (Webchat: https://webchat.freenode.net/?channels=wikipedia-en-afc ).
6 changes: 5 additions & 1 deletion STYLE_GUIDE.md
Expand Up @@ -4,5 +4,9 @@ Style Guide
## CSS ## CSS
If vendor specific CSS rules are added, please add as many as possible. If vendor specific CSS rules are added, please add as many as possible.


### Other stuff ## Variables
Variables containing a regular expression should contain at the end of the variable name a "_re".


## Other stuff
Buttons and links prompting the user for more information should include ellipsis (HTML code `…`). Buttons and links prompting the user for more information should include ellipsis (HTML code `…`).
72 changes: 43 additions & 29 deletions src/MediaWiki:Gadget-afchelper.css
Expand Up @@ -12,42 +12,46 @@ div#afcHelper_betanotice {
font-style: italic; font-style: italic;
} }


input[type=text]:hover { /* Small shadow on textarea hover */
box-shadow: 0px 0px 1px rgba(0, 0, 0, 0.3) inset;
}

.afcHelper_button { .afcHelper_button {
background-repeat: repeat-x; background-repeat: repeat-x;
border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25); border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
display: inline-block; display: inline-block;
padding: 2px 5px; padding: 2px 5px;
font-size: 13px; font-size: 13px;
line-height: 18px; line-height: 18px;
text-align: center; text-align: center;
vertical-align: middle; vertical-align: middle;
cursor: pointer; cursor: pointer;
border-width: 1px; border-width: 1px;
border-style: solid; border-style: solid;
-moz-border-top-colors: none; -moz-border-top-colors: none;
-moz-border-right-colors: none; -moz-border-right-colors: none;
-moz-border-bottom-colors: none; -moz-border-bottom-colors: none;
-moz-border-left-colors: none; -moz-border-left-colors: none;
border-image: none; border-image: none;
border-radius: 4px 4px 4px 4px; border-radius: 4px 4px 4px 4px;
box-shadow: 0px 1px 0px rgba(255, 255, 255, 0.2) inset, 0px 1px 2px rgba(0, 0, 0, 0.05); box-shadow: 0px 1px 0px rgba(255, 255, 255, 0.2) inset, 0px 1px 2px rgba(0, 0, 0, 0.05);
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: normal; font-weight: normal;
margin: 0px; margin: 0px;
margin-right: 2px; margin-right: 2px;
} }


.afcHelper_button:active { .afcHelper_button:active {
border: 1px solid #aaa; border: 1px solid #aaa;
border-bottom: 1px solid #888; border-bottom: 1px solid #888;
-moz-box-shadow: inset 0 0 2px 2px #888; -moz-box-shadow: inset 0 0 2px 2px #888;
-webkit-box-shadow: inset 0 0 2px 2px #888; -webkit-box-shadow: inset 0 0 2px 2px #888;
box-shadow: inset 0 0 2px 2px #888; box-shadow: inset 0 0 2px 2px #888;
} }


#afcHelper_accept_button { #afcHelper_accept_button {
background-color: #adfcad; background-color: #adfcad;
background-image: -moz-linear-gradient(center top, #B8FFB8, #A7F3A7); background-image: -moz-linear-gradient(center top, #B8FFB8, #A7F3A7);
} }


#afcHelper_decline_button, .afcHelper_button.decline { #afcHelper_decline_button, .afcHelper_button.decline {
Expand Down Expand Up @@ -77,3 +81,13 @@ div#afcHelper_betanotice {
#afcHelper_g13_button { #afcHelper_g13_button {
background-color: #ff3333; background-color: #ff3333;
} }

.afcHelper_expand {
height: 1em;
width: 50%;
padding: 3px;
}

#afcHelper_extra select {
vertical-align: middle;
}
100 changes: 87 additions & 13 deletions src/core.js
@@ -1,6 +1,10 @@
//<nowiki> //<nowiki>
// Script should be located at [[MediaWiki:Gadget-afchelper.js/core.js]] // Script should be located at [[MediaWiki:Gadget-afchelper.js/core.js]]


function jqEsc(expression) {
return expression.replace(/[!"#$%&'()*+,.\/:;<=>?@\[\\\]^`{|}~]/g, '\\$&');
}

importScript('User:Timotheus Canens/displaymessage.js'); importScript('User:Timotheus Canens/displaymessage.js');
var afchelper_baseurl = mw.config.get('wgServer') + '/w/index.php?action=raw&ctype=text/javascript&title=MediaWiki:Gadget-afchelper.js'; var afchelper_baseurl = mw.config.get('wgServer') + '/w/index.php?action=raw&ctype=text/javascript&title=MediaWiki:Gadget-afchelper.js';


Expand Down Expand Up @@ -28,8 +32,13 @@ if (afchelper_baseurl.indexOf('MediaWiki:'+'Gadget-afchelper.js' /* hack to stop
else else
var BETA = false; var BETA = false;


// Manually load mw.api() only if we're not using the gadget...with the gadget, it's already a dependency if (BETA) {
if (BETA) mw.loader.load('mediawiki.api'); // Manually load mw.api() and chosen only if we're not using the gadget...with the gadget, they are already dependencies
mw.loader.load('mediawiki.api');
mw.loader.load('jquery.chosen');
// Set the summary to denote that we're using a "beta" version of the script
var afcHelper_advert = ' ([[WP:AFCH|AFCH]] beta)';
}


function afcHelper_generateSelect(title, options, onchange) { function afcHelper_generateSelect(title, options, onchange) {
var text = '<select name="' + title + '" id="' + title + '" '; var text = '<select name="' + title + '" id="' + title + '" ';
Expand All @@ -46,14 +55,24 @@ function afcHelper_generateSelect(title, options, onchange) {
return text; return text;
} }


function afcHelper_generateChzn(title,placeholder,optionsdict) {
// given a dictionary of "title","value"
var text = '<select data-placeholder="' + placeholder + '" id="' + title + '" style="width:350px;" class="chzn-select" multiple>';
$.each(optionsdict, function(k, v){
text += '<option value="' + afcHelper_escapeHtmlChars(v) + '" >' + k + '</option>';
});
text += "</select>";
return text;
}

function afcHelper_escapeHtmlChars(original) { function afcHelper_escapeHtmlChars(original) {
return original.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;"); return original.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
} }


function afcHelper_getPageText(title, show, redirectcheck, timestamp) { function afcHelper_getPageText(title, show, redirectcheck, timestamp) {
if (show) document.getElementById('afcHelper_status').innerHTML += '<li id="afcHelper_get' + escape(title) + '">Getting <a href="' + wgArticlePath.replace("$1", encodeURI(title)) + '" title="' + title + '">' + title + '</a></li>'; if (show) $('#afcHelper_status').html($('#afcHelper_status').html() + '<li id="afcHelper_get' + jqEsc(title) + '">Getting <a href="' + wgArticlePath.replace("$1", encodeURI(title)) + '" title="' + title + '">' + title + '</a></li>');


request = { var request = {
'action': 'query', 'action': 'query',
'prop': 'revisions', 'prop': 'revisions',
'rvprop': 'content', 'rvprop': 'content',
Expand All @@ -75,7 +94,7 @@ function afcHelper_getPageText(title, show, redirectcheck, timestamp) {


pageid = response['query']['pageids'][0]; pageid = response['query']['pageids'][0];
if (pageid === "-1") { if (pageid === "-1") {
if (show) document.getElementById('afcHelper_get' + escape(title)).innerHTML = 'The page <a class="new" href="' + wgArticlePath.replace("$1", encodeURI(title)) + '" title="' + title + '">' + title + '</a> does not exist'; if (show) $('#afcHelper_get' +jqEsc(title)).html('The page <a class="new" href="' + wgArticlePath.replace("$1", encodeURI(title)) + '" title="' + title + '">' + title + '</a> does not exist');
return ''; return '';
} }
var newtext = response['query']['pages'][pageid]['revisions'][0]['*']; var newtext = response['query']['pages'][pageid]['revisions'][0]['*'];
Expand All @@ -85,27 +104,82 @@ function afcHelper_getPageText(title, show, redirectcheck, timestamp) {
if ((typeof(oldusername) !== 'undefined') && (typeof(newusername) !== 'undefined') && (oldusername != newusername)){ if ((typeof(oldusername) !== 'undefined') && (typeof(newusername) !== 'undefined') && (oldusername != newusername)){
usertalkpage = newusername; usertalkpage = newusername;
if (show) { if (show) {
document.getElementById('afcHelper_status').innerHTML += '<li id="afcHelper_get' + escape(title) + '">Got <a href="' + wgArticlePath.replace("$1", encodeURI(title)) + '" title="' + newusername + '">' + newusername + '</a> (page was renamed from ' + oldusername + ')</li>'; $('#afcHelper_status').html($('#afcHelper_status').html() + '<li id="afcHelper_get' + jqEsc(title) + '">Got <a href="' + wgArticlePath.replace("$1", encodeURI(title)) + '" title="' + newusername + '">' + newusername + '</a> (page was renamed from ' + oldusername + ')</li>');
} }
} else { } else {
redirectcheck = false; redirectcheck = false;
} }
} else { } else {
redirectcheck = false; redirectcheck = false;
} }
if (show && !redirectcheck) document.getElementById('afcHelper_status').innerHTML += '<li id="afcHelper_get' + escape(title) + '">Got <a href="' + wgArticlePath.replace("$1", encodeURI(title)) + '" title="' + title + '">' + title + '</a></li>'; if (show && !redirectcheck) $('#afcHelper_status').html($('#afcHelper_status').html() + '<li id="afcHelper_get' + jqEsc(title) + '">Got <a href="' + wgArticlePath.replace("$1", encodeURI(title)) + '" title="' + title + '">' + title + '</a></li>');
if (!timestamp) return newtext; if (!timestamp) return newtext;
else return {'pagetext':newtext,'timestamp':response['query']['pages'][pageid]['revisions'][0]['timestamp']} else return {'pagetext':newtext,'timestamp':response['query']['pages'][pageid]['revisions'][0]['timestamp']}
} }


function afcHelper_deletePage(title,reason) {
// First set up the status log
$("#afcHelper_finished_wrapper").html('<span id="afcHelper_AJAX_finished_' + afcHelper_AJAXnumber + '" style="display:none">' + $("#afcHelper_finished_wrapper").html() + '</span>');
var func_id = afcHelper_AJAXnumber;
afcHelper_AJAXnumber++;
document.getElementById('afcHelper_status').innerHTML += '<li id="afcHelper_delete' + escape(title) + '">Deleting <a href="' + wgArticlePath.replace("$1", encodeURI(title)) + '" title="' + title + '">' + title + '</a></li>';

// Then get the deletion token
var tokenrequest = {
'action': 'query',
'prop': 'info',
'format': 'json',
'intoken': 'delete',
'indexpageids': true,
'titles' : title
};
var tokenresponse = JSON.parse(
$.ajax({
url: mw.util.wikiScript('api'),
data: tokenrequest,
async: false
})
.responseText
);

pageid = tokenresponse['query']['pageids'][0];
token = tokenresponse['query']['pages'][pageid]['deletetoken'];

// And finally delete the page
var delrequest = {
'action': 'delete',
'reason': reason + afcHelper_advert,
'format': 'json',
'token': token,
'title' : title
}
var delresponse = JSON.parse(
$.ajax({
type: "POST",
url: mw.util.wikiScript('api'),
data: delrequest,
async: false
})
.responseText
);

if (delresponse && delresponse.delete) {
document.getElementById('afcHelper_delete' + escape(title)).innerHTML = 'Deleted <a href="' + wgArticlePath.replace("$1", encodeURI(title)) + '" title="' + title + '">' + title + '</a>';
return true;
} else {
document.getElementById('afcHelper_delete' + escape(title)).innerHTML = '<div style="color:red"><b>Deletion failed on <a href="' + wgArticlePath.replace("$1", encodeURI(title)) + '" title="' + title + '">' + title + '</a></b></div>. Error info:' + error;
return false;
}
}

function afcHelper_editPage(title, newtext, summary, createonly) { function afcHelper_editPage(title, newtext, summary, createonly) {
var edittoken = mw.user.tokens.get('editToken'); var edittoken = mw.user.tokens.get('editToken');
summary += afcHelper_advert; summary += afcHelper_advert;
$("#afcHelper_finished_wrapper").html('<span id="afcHelper_AJAX_finished_' + afcHelper_AJAXnumber + '" style="display:none">' + $("#afcHelper_finished_wrapper").html() + '</span>'); $("#afcHelper_finished_wrapper").html('<span id="afcHelper_AJAX_finished_' + afcHelper_AJAXnumber + '" style="display:none">' + $("#afcHelper_finished_wrapper").html() + '</span>');
var func_id = afcHelper_AJAXnumber; var func_id = afcHelper_AJAXnumber;
afcHelper_AJAXnumber++; afcHelper_AJAXnumber++;
document.getElementById('afcHelper_status').innerHTML += '<li id="afcHelper_edit' + escape(title) + '">Editing <a href="' + wgArticlePath.replace("$1", encodeURI(title)) + '" title="' + title + '">' + title + '</a></li>'; $('#afcHelper_status').html($('#afcHelper_status').html() + '<li id="afcHelper_edit' + jqEsc(title) + '">Editing <a href="' + wgArticlePath.replace("$1", encodeURI(title)) + '" title="' + title + '">' + title + '</a></li>');
request = { var request = {
'action': 'edit', 'action': 'edit',
'title': title, 'title': title,
'text': newtext, 'text': newtext,
Expand All @@ -118,16 +192,16 @@ function afcHelper_editPage(title, newtext, summary, createonly) {
api.post(request) api.post(request)
.done(function ( data ) { .done(function ( data ) {
if ( data && data.edit && data.edit.result && data.edit.result == 'Success' ) { if ( data && data.edit && data.edit.result && data.edit.result == 'Success' ) {
document.getElementById('afcHelper_edit' + escape(title)).innerHTML = 'Saved <a href="' + wgArticlePath.replace("$1", encodeURI(title)) + '" title="' + title + '">' + title + '</a>'; $('#afcHelper_edit' + jqEsc(title)).html('Saved <a href="' + wgArticlePath.replace("$1", encodeURI(title)) + '" title="' + title + '">' + title + '</a>');
} else { } else {
document.getElementById('afcHelper_edit' + escape(title)).innerHTML = '<div style="color:red"><b>Edit failed on <a href="' + wgArticlePath.replace("$1", encodeURI(title)) + '" title="' + title + '">' + title + '</a></b></div>. Error info:' + error; $('#afcHelper_edit' + jqEsc(title)).html('<div class="notice"><b>Edit failed on <a href="' + wgArticlePath.replace("$1", encodeURI(title)) + '" title="' + title + '">' + title + '</a></b></div>. Error info:' + response['error']['code'] + ' : ' + response['error']['info']);
} }
} ) } )
.fail( function ( error ) { .fail( function ( error ) {
if (createonly && error == "articleexists") if (createonly && error == "articleexists")
document.getElementById('afcHelper_edit' + escape(title)).innerHTML = '<div style="color:red"><b>Edit failed on <a href="' + wgArticlePath.replace("$1", encodeURI(title)) + '" title="' + title + '">' + title + '</a></b></div>. Error info: The article already exists!'; $('#afcHelper_edit' + jqEsc(title)).html('<div class="notice"><b>Edit failed on <a href="' + wgArticlePath.replace("$1", encodeURI(title)) + '" title="' + title + '">' + title + '</a></b></div>. Error info: The article already exists!');
else else
document.getElementById('afcHelper_edit' + escape(title)).innerHTML = '<div style="color:red"><b>Edit failed on <a href="' + wgArticlePath.replace("$1", encodeURI(title)) + '" title="' + title + '">' + title + '</a></b></div>. Error info:' + error; $('#afcHelper_edit' + jqEsc(title)).html('<div class="notice"><b>Edit failed on <a href="' + wgArticlePath.replace("$1", encodeURI(title)) + '" title="' + title + '">' + title + '</a></b></div>. Error info: ' + error);
}) })
.always( function () { .always( function () {
$("#afcHelper_AJAX_finished_" + func_id).css("display", ''); $("#afcHelper_AJAX_finished_" + func_id).css("display", '');
Expand Down

0 comments on commit 344930a

Please sign in to comment.