Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

speedy/xfd: Add delete-templates on non-wikitext pages #206

Closed
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 42 additions & 28 deletions modules/twinklespeedy.js
Original file line number Diff line number Diff line change
Expand Up @@ -1233,8 +1233,7 @@ Twinkle.speedy.callbacks = {
main: function(pageobj) {
var statelem = pageobj.getStatusElement();

// defaults to /doc for lua modules, which may not exist
if (!pageobj.exists() && mw.config.get('wgPageContentModel') !== 'Scribunto') {
if (!pageobj.exists()) {
statelem.error(wgULS('页面不存在,可能已被删除', '頁面不存在,可能已被刪除'));
return;
}
Expand Down Expand Up @@ -1293,6 +1292,46 @@ Twinkle.speedy.callbacks = {
code += '\n{{subst:Copyvio/auto|url=* 請管理員檢查已刪歷史內容及侵權來源:[[Special:Undelete/' + params.copyvio + ']]|OldRevision=' + mw.config.get('wgRevisionId') + '}}';
}

if (mw.config.get('wgPageContentModel') === 'json') {
var json = JSON.parse(text);
if (params.blank) {
json = [{
_addText: code
}];
} else if (json instanceof Array) {
json.unshift({
_addText: code
});
} else {
json._addText = code;
}

text = JSON.stringify(json);
} else {
if (mw.config.get('wgPageContentModel') === 'Scribunto') {
var equals = '';
while (code.indexOf(']' + equals + ']') !== -1) {
equals += '=';
}
code = "require('Module:Module wikitext')._addText([" + equals + '[' + code + ']' + equals + ']);';
} else if (['javascript', 'css', 'sanitized-css'].indexOf(mw.config.get('wgPageContentModel')) > -1) {
if (code.indexOf('*/')) {
code = code.replace(/\*\//g, '*/');
}
Xi-Plus marked this conversation as resolved.
Show resolved Hide resolved
code = '/* _addText: ' + code + ' */';
}

// Blank attack pages
if (params.blank) {
text = code;
} else {
// Insert tag after short description or any hatnotes
var wikipage = new Morebits.wikitext.page(text);
text = wikipage.insertAfterTemplates(code + '\n', Twinkle.hatnoteRegex).getText();
}
}


// Generate edit summary for edit
var editsummary;
if (params.normalizeds.length > 1) {
Expand All @@ -1310,33 +1349,10 @@ Twinkle.speedy.callbacks = {
editsummary = wgULS('请求快速删除', '請求快速刪除') + '([[WP:CSD#' + params.normalizeds[0].toUpperCase() + '|CSD ' + params.normalizeds[0].toUpperCase() + ']])';
}


// Blank attack pages
if (params.blank) {
text = code;
} else {
// Insert tag after short description or any hatnotes
var wikipage = new Morebits.wikitext.page(text);
text = wikipage.insertAfterTemplates(code + '\n', Twinkle.hatnoteRegex).getText();
}


pageobj.setPageText(text);
pageobj.setEditSummary(editsummary);
pageobj.setChangeTags(Twinkle.changeTags);
pageobj.setWatchlist(params.watch);
if (params.scribunto) {
pageobj.setCreateOption('recreate'); // Module /doc might not exist
if (params.watch) {
// Watch module in addition to /doc subpage
var watch_query = {
action: 'watch',
titles: mw.config.get('wgPageName'),
token: mw.user.tokens.get('watchToken')
};
new Morebits.wiki.api(wgULS('将模块加入到监视列表', '將模組加入到監視清單'), watch_query).post();
}
}
pageobj.save(Twinkle.speedy.callbacks.user.tagComplete);
},

Expand Down Expand Up @@ -1756,9 +1772,7 @@ Twinkle.speedy.callback.evaluateUser = function twinklespeedyCallbackEvaluateUse
Morebits.wiki.actionCompleted.redirect = mw.config.get('wgPageName');
Morebits.wiki.actionCompleted.notice = wgULS('标记完成', '標記完成');

// Modules can't be tagged, follow standard at TfD and place on /doc subpage
params.scribunto = mw.config.get('wgPageContentModel') === 'Scribunto';
var wikipedia_page = params.scribunto ? new Morebits.wiki.page(mw.config.get('wgPageName') + '/doc', wgULS('标记模块文件页', '標記模組文件頁')) : new Morebits.wiki.page(mw.config.get('wgPageName'), wgULS('标记页面', '標記頁面'));
var wikipedia_page = new Morebits.wiki.page(mw.config.get('wgPageName'), wgULS('标记页面', '標記頁面'));
wikipedia_page.setCallbackParameters(params);
wikipedia_page.load(Twinkle.speedy.callbacks.user.main);
};
Expand Down
37 changes: 31 additions & 6 deletions modules/twinklexfd.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,35 @@ Twinkle.xfd.callbacks = {
pageobj.patrol();
}

// Insert tag after short description or any hatnotes
var wikipage = new Morebits.wikitext.page(text);
text = wikipage.insertAfterTemplates(tag, Twinkle.hatnoteRegex).getText();
if (mw.config.get('wgPageContentModel') === 'json') {
var json = JSON.parse(text);
if (json instanceof Array) {
json.unshift({
_addText: tag
});
} else {
json._addText = tag;
}

text = JSON.stringify(json);
} else {
if (mw.config.get('wgPageContentModel') === 'Scribunto') {
var equals = '';
while (tag.indexOf(']' + equals + ']') !== -1) {
equals += '=';
}
tag = "require('Module:Module wikitext')._addText([" + equals + '[' + tag + ']' + equals + ']);';
} else if (['javascript', 'css', 'sanitized-css'].indexOf(mw.config.get('wgPageContentModel')) > -1) {
if (tag.indexOf('*/')) {
tag = tag.replace(/\*\//g, '*/');
}
tag = '/* _addText: ' + tag + ' */';
Xi-Plus marked this conversation as resolved.
Show resolved Hide resolved
}

// Insert tag after short description or any hatnotes
var wikipage = new Morebits.wikitext.page(text);
text = wikipage.insertAfterTemplates(tag, Twinkle.hatnoteRegex).getText();
}

pageobj.setPageText(text);
pageobj.setEditSummary(wgULS('页面存废讨论:[[', '頁面存廢討論:[[') + params.logpage + '#' + Morebits.pageNameNorm + ']]');
Expand Down Expand Up @@ -450,7 +476,7 @@ Twinkle.xfd.callbacks = {
tryTagging: function (pageobj) {
var statelem = pageobj.getStatusElement();
// defaults to /doc for lua modules, which may not exist
if (!pageobj.exists() && mw.config.get('wgPageContentModel') !== 'Scribunto') {
if (!pageobj.exists()) {
statelem.error(wgULS('页面不存在,可能已被删除', '頁面不存在,可能已被刪除'));
return;
}
Expand Down Expand Up @@ -703,8 +729,7 @@ Twinkle.xfd.callback.evaluate = function(e) {
Morebits.wiki.actionCompleted.notice = wgULS('提名完成,重定向到讨论页', '提名完成,重新導向到討論頁');

// Tagging page
var isScribunto = mw.config.get('wgPageContentModel') === 'Scribunto';
wikipedia_page = isScribunto ? new Morebits.wiki.page(mw.config.get('wgPageName') + '/doc', wgULS('加入存废讨论模板到模块文件页', '加入存廢討論模板到模組文件頁')) : new Morebits.wiki.page(mw.config.get('wgPageName'), wgULS('加入存废讨论模板到页面', '加入存廢討論模板到頁面'));
wikipedia_page = new Morebits.wiki.page(mw.config.get('wgPageName'), wgULS('加入存废讨论模板到页面', '加入存廢討論模板到頁面'));
wikipedia_page.setFollowRedirect(false);
wikipedia_page.setCallbackParameters(params);
wikipedia_page.load(Twinkle.xfd.callbacks.afd.tryTagging);
Expand Down