Skip to content

Commit

Permalink
tag: fix merge function, move translationListPage into main callback,
Browse files Browse the repository at this point in the history
move multipleIssuesException to below article tags list, some comment changes,
other minor fixes
  • Loading branch information
siddharthvp committed May 14, 2019
1 parent d599148 commit e0061ac
Showing 1 changed file with 32 additions and 33 deletions.
65 changes: 32 additions & 33 deletions modules/friendlytag.js
Original file line number Diff line number Diff line change
Expand Up @@ -1141,11 +1141,12 @@ Twinkle.tag.callbacks = {
var params = pageobj.getCallbackParameters();

/**
* Saves the page following the removal of tags if any. The last step
* Saves the page following the removal of tags if any. The last step.
* Called from removeTags()
*/
var postRemoval = function() {

if(params.tagsToRemove.length) {
if (params.tagsToRemove.length) {
// Finish summary text
summaryText += ' tag' + ( params.tagsToRemove.length > 1 ? 's' : '') + ' from article';

Expand Down Expand Up @@ -1198,7 +1199,7 @@ Twinkle.tag.callbacks = {
var otherpage = new Morebits.wiki.page(params.mergeTarget, "Tagging other page (" +
params.mergeTarget + ")");
otherpage.setCallbackParameters(newParams);
otherpage.load(Twinkle.tag.callbacks.article.main);
otherpage.load(Twinkle.tag.callbacks.article);
}

// post at WP:PNT for {{not English}} and {{rough translation}} tag
Expand All @@ -1211,7 +1212,33 @@ Twinkle.tag.callbacks = {
lang: params.translationLanguage,
reason: params.translationComments
});
pntPage.load(Twinkle.tag.callbacks.translationListPage);
pntPage.load(function friendlytagCallbacksTranslationListPage(pageobj) {
var old_text = pageobj.getPageText();
var params = pageobj.getCallbackParameters();
var statelem = pageobj.getStatusElement();

var templateText = "{{subst:" + params.template + "|pg=" + Morebits.pageNameNorm + "|Language=" +
(params.lang || "uncertain") + "|Comments=" + params.reason.trim() + "}} ~~~~";

var text, summary;
if (params.template === "duflu") {
text = old_text + "\n\n" + templateText;
summary = "Translation cleanup requested on ";
} else {
text = old_text.replace(/\n+(==\s?Translated pages that could still use some cleanup\s?==)/,
"\n\n" + templateText + "\n\n$1");
summary = "Translation" + (params.lang ? (" from " + params.lang) : "") + " requested on ";
}

if (text === old_text) {
statelem.error('failed to find target spot for the discussion');
return;
}
pageobj.setPageText(text);
pageobj.setEditSummary(summary + " [[:" + Morebits.pageNameNorm + "]]" + Twinkle.getPref('summaryAd'));
pageobj.setCreateOption('recreate');
pageobj.save();
});
}
if (params.translationNotify) {
pageobj.lookupCreator(function(innerPageobj) {
Expand Down Expand Up @@ -1321,7 +1348,7 @@ Twinkle.tag.callbacks = {
$(page).find('lh').each(function(idx, el) {
var tag = $(el).attr('title').slice(9);
var tag_re = new RegExp('\\{\\{' + Morebits.pageNameRegex(tag) + '\\s*(\\|[^}]*)?\\}\\}\\n?');
if(tag_re.test(pageText)) {
if (tag_re.test(pageText)) {
pageText = pageText.replace(tag_re, '');
removed = true;
return false; // break out of $.each
Expand Down Expand Up @@ -1746,34 +1773,6 @@ Twinkle.tag.callbacks = {

},

translationListPage: function friendlytagCallbacksTranslationListPage(pageobj) {
var old_text = pageobj.getPageText();
var params = pageobj.getCallbackParameters();
var statelem = pageobj.getStatusElement();

var templateText = "{{subst:" + params.template + "|pg=" + Morebits.pageNameNorm + "|Language=" +
(params.lang || "uncertain") + "|Comments=" + params.reason.trim() + "}} ~~~~";

var text, summary;
if (params.template === "duflu") {
text = old_text + "\n\n" + templateText;
summary = "Translation cleanup requested on ";
} else {
text = old_text.replace(/\n+(==\s?Translated pages that could still use some cleanup\s?==)/,
"\n\n" + templateText + "\n\n$1");
summary = "Translation" + (params.lang ? (" from " + params.lang) : "") + " requested on ";
}

if (text === old_text) {
statelem.error('failed to find target spot for the discussion');
return;
}
pageobj.setPageText(text);
pageobj.setEditSummary(summary + " [[:" + Morebits.pageNameNorm + "]]" + Twinkle.getPref('summaryAd'));
pageobj.setCreateOption('recreate');
pageobj.save();
},

file: function friendlytagCallbacksFile(pageobj) {
var text = pageobj.getPageText();
var params = pageobj.getCallbackParameters();
Expand Down

0 comments on commit e0061ac

Please sign in to comment.