Skip to content

Commit

Permalink
morebits: remove Morebits.queryString (#725)
Browse files Browse the repository at this point in the history
Morebits.queryString is redundant to mw.util.getParamValue(), mw.util.getUrl() and jQuery.param(). All existing usages are easily replaced.
Specifically,
- Morebits.queryString.get() and Morebits.queryString.exists() are redundant to mw.util.getParamValue()
- Morebits.queryString.create() is redundant to mw.util.getUrl() and jQuery.param()

While queryString can be also used for constructing query string objects and getting/setting param values in them, this functionality is not used anywhere,
nor are there any reasonable potential usecases.

Co-authored-by: Siddharth VP <siddharthvp@gmail.com>
Co-authored-by: Amory Meltzer <Amorymeltzer@gmail.com>
  • Loading branch information
siddharthvp and Amorymeltzer committed Jan 23, 2020
1 parent 1696c69 commit 37d6b67
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 192 deletions.
16 changes: 8 additions & 8 deletions modules/friendlywelcome.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
*/

Twinkle.welcome = function friendlywelcome() {
if (Morebits.queryString.exists('friendlywelcome')) {
if (Morebits.queryString.get('friendlywelcome') === 'auto') {
if (mw.util.getParamValue('friendlywelcome')) {
if (mw.util.getParamValue('friendlywelcome') === 'auto') {
Twinkle.welcome.auto();
} else {
Twinkle.welcome.semiauto();
Expand All @@ -26,7 +26,7 @@ Twinkle.welcome = function friendlywelcome() {
};

Twinkle.welcome.auto = function() {
if (Morebits.queryString.get('action') !== 'edit') {
if (mw.util.getParamValue('action') !== 'edit') {
// userpage not empty, aborting auto-welcome
return;
}
Expand All @@ -39,7 +39,7 @@ Twinkle.welcome.semiauto = function() {
};

Twinkle.welcome.normal = function() {
if (Morebits.queryString.exists('diff')) {
if (mw.util.getParamValue('diff')) {
// check whether the contributors' talk pages exist yet
var $oList = $('#mw-diff-otitle2').find('span.mw-usertoollinks a.new:contains(talk)').first();
var $nList = $('#mw-diff-ntitle2').find('span.mw-usertoollinks a.new:contains(talk)').first();
Expand All @@ -63,7 +63,7 @@ Twinkle.welcome.normal = function() {
var oHref = $oList.attr('href');

var oWelcomeNode = welcomeNode.cloneNode(true);
oWelcomeNode.firstChild.setAttribute('href', oHref + '&' + Morebits.queryString.create({
oWelcomeNode.firstChild.setAttribute('href', oHref + '&' + $.param({
'friendlywelcome': Twinkle.getPref('quickWelcomeMode') === 'auto' ? 'auto' : 'norm',
'vanarticle': Morebits.pageNameNorm
}));
Expand All @@ -75,7 +75,7 @@ Twinkle.welcome.normal = function() {
var nHref = $nList.attr('href');

var nWelcomeNode = welcomeNode.cloneNode(true);
nWelcomeNode.firstChild.setAttribute('href', nHref + '&' + Morebits.queryString.create({
nWelcomeNode.firstChild.setAttribute('href', nHref + '&' + $.param({
'friendlywelcome': Twinkle.getPref('quickWelcomeMode') === 'auto' ? 'auto' : 'norm',
'vanarticle': Morebits.pageNameNorm
}));
Expand All @@ -97,7 +97,7 @@ Twinkle.welcome.welcomeUser = function welcomeUser() {

var params = {
value: Twinkle.getPref('quickWelcomeTemplate'),
article: Morebits.queryString.exists('vanarticle') ? Morebits.queryString.get('vanarticle') : '',
article: mw.util.getParamValue('vanarticle') || '',
mode: 'auto'
};

Expand Down Expand Up @@ -147,7 +147,7 @@ Twinkle.welcome.callback = function friendlywelcomeCallback(uid) {
type: 'input',
name: 'article',
label: '* Linked article (if supported by template):',
value: Morebits.queryString.exists('vanarticle') ? Morebits.queryString.get('vanarticle') : '',
value: mw.util.getParamValue('vanarticle') || '',
tooltip: 'An article might be linked from within the welcome if the template supports it. Leave empty for no article to be linked. Templates that support a linked article are marked with an asterisk.'
});

Expand Down
10 changes: 5 additions & 5 deletions modules/twinklearv.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ Twinkle.arv.callback.changeCategory = function (e) {
name: 'page',
label: 'Primary linked page: ',
tooltip: 'Leave blank to not link to the page in the report',
value: Morebits.queryString.exists('vanarticle') ? Morebits.queryString.get('vanarticle') : '',
value: mw.util.getParamValue('vanarticle') || '',
event: function(e) {
var value = e.target.value;
var root = e.target.form;
Expand All @@ -126,8 +126,8 @@ Twinkle.arv.callback.changeCategory = function (e) {
name: 'badid',
label: 'Revision ID for target page when vandalised: ',
tooltip: 'Leave blank for no diff link',
value: Morebits.queryString.exists('vanarticlerevid') ? Morebits.queryString.get('vanarticlerevid') : '',
disabled: !Morebits.queryString.exists('vanarticle'),
value: mw.util.getParamValue('vanarticlerevid') || '',
disabled: !mw.util.getParamValue('vanarticle'),
event: function(e) {
var value = e.target.value;
var root = e.target.form;
Expand All @@ -139,8 +139,8 @@ Twinkle.arv.callback.changeCategory = function (e) {
name: 'goodid',
label: 'Last good revision ID before vandalism of target page: ',
tooltip: 'Leave blank for diff link to previous revision',
value: Morebits.queryString.exists('vanarticlegoodrevid') ? Morebits.queryString.get('vanarticlegoodrevid') : '',
disabled: !Morebits.queryString.exists('vanarticle') || Morebits.queryString.exists('vanarticlerevid')
value: mw.util.getParamValue('vanarticlegoodrevid') || '',
disabled: !mw.util.getParamValue('vanarticle') || mw.util.getParamValue('vanarticlerevid')
});
work_area.append({
type: 'checkbox',
Expand Down
6 changes: 3 additions & 3 deletions modules/twinklebatchdelete.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ Twinkle.batchdelete.callback = function twinklebatchdeleteCallback() {

query.generator = 'allpages';
query.gaplimit = Twinkle.getPref('batchMax');
if (Morebits.queryString.exists('prefix')) {
query.gapnamespace = Morebits.queryString.get('namespace');
query.gapprefix = Morebits.string.toUpperCaseFirstChar(Morebits.queryString.get('prefix'));
if (mw.util.getParamValue('prefix')) {
query.gapnamespace = mw.util.getParamValue('namespace');
query.gapprefix = Morebits.string.toUpperCaseFirstChar(mw.util.getParamValue('prefix'));
} else {
var pathSplit = decodeURIComponent(location.pathname).split('/');
if (pathSplit.length < 3 || pathSplit[2] !== 'Special:PrefixIndex') {
Expand Down
5 changes: 2 additions & 3 deletions modules/twinklebatchprotect.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,8 @@ Twinkle.batchprotect.callback = function twinklebatchprotectCallback() {
query.gcmlimit = Twinkle.getPref('batchMax');
} else if (mw.config.get('wgCanonicalSpecialPageName') === 'Prefixindex') {
query.generator = 'allpages';
query.gapnamespace = Morebits.queryString.exists('namespace') ? Morebits.queryString.get('namespace') : $('select[name=namespace]').val();
query.gapprefix = Morebits.queryString.exists('from') ? Morebits.string.toUpperCaseFirstChar(Morebits.queryString.get('from').replace('+', ' ')) :
Morebits.string.toUpperCaseFirstChar($('input[name=prefix]').val());
query.gapnamespace = mw.util.getParamValue('namespace') || $('select[name=namespace]').val();
query.gapprefix = Morebits.string.toUpperCaseFirstChar(mw.util.getParamValue('from') ? mw.util.getParamValue('from').replace('+', ' ') : $('input[name=prefix]').val());
query.gaplimit = Twinkle.getPref('batchMax');
} else {
query.generator = 'links';
Expand Down
28 changes: 7 additions & 21 deletions modules/twinklediff.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,10 @@ Twinkle.diff = function twinklediff() {
if (mw.config.get('wgNamespaceNumber') < 0 || !mw.config.get('wgArticleId')) {
return;
}

var query = {
'title': mw.config.get('wgPageName'),
'diff': 'cur',
'oldid': 'prev'
};

Twinkle.addPortletLink(mw.util.wikiScript('index') + '?' + $.param(query), 'Last', 'tw-lastdiff', 'Show most recent diff');
Twinkle.addPortletLink(mw.util.getUrl(mw.config.get('wgPageName'), {diff: 'cur', oldid: 'prev'}), 'Last', 'tw-lastdiff', 'Show most recent diff');

// Show additional tabs only on diff pages
if (Morebits.queryString.exists('diff')) {
if (mw.util.getParamValue('diff')) {
Twinkle.addPortletLink(function() {
Twinkle.diff.evaluate(false);
}, 'Since', 'tw-since', 'Show difference between last diff and the revision made by previous user');
Expand All @@ -35,12 +28,7 @@ Twinkle.diff = function twinklediff() {
}, 'Since mine', 'tw-sincemine', 'Show difference between last diff and my last revision');

var oldid = /oldid=(.+)/.exec($('#mw-diff-ntitle1').find('strong a').first().attr('href'))[1];
query = {
'title': mw.config.get('wgPageName'),
'diff': 'cur',
'oldid': oldid
};
Twinkle.addPortletLink(mw.util.wikiScript('index') + '?' + $.param(query), 'Current', 'tw-curdiff', 'Show difference to current revision');
Twinkle.addPortletLink(mw.util.getUrl(mw.config.get('wgPageName'), {diff: 'cur', oldid: oldid}), 'Current', 'tw-curdiff', 'Show difference to current revision');
}
};

Expand Down Expand Up @@ -81,12 +69,10 @@ Twinkle.diff.callbacks = {
self.statelem.error('no suitable earlier revision found, or ' + self.params.user + ' is the only contributor. Aborting.');
return;
}
var query = {
'title': mw.config.get('wgPageName'),
'oldid': revid,
'diff': mw.config.get('wgCurRevisionId')
};
window.location = mw.util.wikiScript('index') + '?' + Morebits.queryString.create(query);
window.location = mw.util.getUrl(mw.config.get('wgPageName'), {
diff: mw.config.get('wgCurRevisionId'),
oldid: revid
});
}
};
})(jQuery);
Expand Down
14 changes: 7 additions & 7 deletions modules/twinklefluff.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Twinkle.fluff = function twinklefluff() {
'SineBot'
];

if (Morebits.queryString.exists('twinklerevert')) {
if (mw.util.getParamValue('twinklerevert')) {
// Return if the user can't edit the page in question
if (!mw.config.get('wgIsProbablyEditable')) {
alert("Unable to edit the page, it's probably protected.");
Expand Down Expand Up @@ -80,7 +80,7 @@ Twinkle.fluff.auto = function twinklefluffauto() {

var vandal = $('#mw-diff-ntitle2').find('a.mw-userlink').text();

Twinkle.fluff.revert(Morebits.queryString.get('twinklerevert'), vandal, true);
Twinkle.fluff.revert(mw.util.getParamValue('twinklerevert'), vandal, true);
};

Twinkle.fluff.addLinks = {
Expand Down Expand Up @@ -108,11 +108,11 @@ Twinkle.fluff.addLinks = {
var href = $(current).find('.mw-changeslist-diff').attr('href');
current.appendChild(document.createTextNode(' '));
var tmpNode = revNode.cloneNode(true);
tmpNode.firstChild.setAttribute('href', href + '&' + Morebits.queryString.create({ 'twinklerevert': 'norm' }));
tmpNode.firstChild.setAttribute('href', href + '&twinklerevert=norm');
current.appendChild(tmpNode);
current.appendChild(document.createTextNode(' '));
tmpNode = revVandNode.cloneNode(true);
tmpNode.firstChild.setAttribute('href', href + '&' + Morebits.queryString.create({ 'twinklerevert': 'vand' }));
tmpNode.firstChild.setAttribute('href', href + '&twinklerevert=vand');
current.appendChild(tmpNode);
});
}
Expand Down Expand Up @@ -483,16 +483,16 @@ Twinkle.fluff.callbacks = {

switch (Twinkle.getPref('userTalkPageMode')) {
case 'tab':
window.open(mw.util.wikiScript('index') + '?' + Morebits.queryString.create(query), '_blank');
window.open(mw.util.getUrl('', query), '_blank');
break;
case 'blank':
window.open(mw.util.wikiScript('index') + '?' + Morebits.queryString.create(query), '_blank',
window.open(mw.util.getUrl('', query), '_blank',
'location=no,toolbar=no,status=no,directories=no,scrollbars=yes,width=1200,height=800');
break;
case 'window':
/* falls through */
default:
window.open(mw.util.wikiScript('index') + '?' + Morebits.queryString.create(query),
window.open(mw.util.getUrl('', query),
window.name === 'twinklewarnwindow' ? '_blank' : 'twinklewarnwindow',
'location=no,toolbar=no,status=no,directories=no,scrollbars=yes,width=1200,height=800');
break;
Expand Down
2 changes: 1 addition & 1 deletion modules/twinklewarn.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Twinkle.warn.callback = function twinklewarnCallback() {
type: 'input',
name: 'article',
label: 'Linked page',
value: Morebits.queryString.exists('vanarticle') ? Morebits.queryString.get('vanarticle') : '',
value: mw.util.getParamValue('vanarticle') || '',
tooltip: 'A page can be linked within the notice, perhaps because it was a revert to said page that dispatched this notice. Leave empty for no page to be linked.'
});

Expand Down
Loading

0 comments on commit 37d6b67

Please sign in to comment.