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

close: wrap new del template in ns10 page and improved regex for existing del template #306

Merged
merged 4 commits into from
Dec 8, 2024
Merged
Changes from 2 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
12 changes: 9 additions & 3 deletions modules/twinkleclose.js
Original file line number Diff line number Diff line change
Expand Up @@ -815,14 +815,20 @@ Twinkle.close.callbacks = {

var params = pageobj.getCallbackParameters();
var text = pageobj.getPageText();

// HACK: match template w/ or w/o date param, and {{vfd|(reason)}} in one regex

if (/{{[rsaiftcmv]fd\s*(\|.*)?\|\s*date\s*=[^|}]*.*}}/.test(text)) {
text = text.replace(/({{[rsaiftcmv]fd\s*(?:\|.*)?\|\s*date\s*=)[^|}]*(.*}})/, '$1' + params.date + '$2');
if (/{{[rsaiftcmv]fd\s*\|\s*[^|}]*}}/is.test(text) && !/{{[rsaiftcmv]fd\s*\|\s*date\s*=/is.test(text)) {
text = text.replace(/({{[rsaiftcmv]fd[^|}]*)\|([^|}]*}})/is, '$1|date=' + params.date + '|$2');
} else if (/{{[rsaiftcmv]fd[^|}]*(?:\|[^}]*)?\|(?:[^|}]*date[^|}]*=)?(?=\d{4})[^|}]*[^}]*}}/is.test(text)) {
text = text.replace(/({{[rsaiftcmv]fd[^|}]*(?:\|[^}]*)?\|(?:[^|}]*date[^|}]*=)?(?=\d{4}))[^|}]*([^}]*}})/is, '$1' + params.date + '$2');
} else {
Morebits.status.warn(conv({ hans: '重新标记', hant: '重新標記' }), conv({ hans: '找不到提删模板,重新插入', hant: '找不到提刪模板,重新插入' }));
// Insert tag after short description or any hatnotes
var wikipage = new Morebits.wikitext.page(text);
var tag = '{{vfd|date=' + params.date + '}}\n';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你把這行刪掉了啊...

if (pageobj.getPageName().substring(0, 9) === 'Template:') {
tag = '<noinclude>' + tag + '</noinclude>';
}
text = wikipage.insertAfterTemplates(tag, Twinkle.hatnoteRegex).getText();
}

Expand Down
Loading