User:逆襲的天邪鬼/Twinkle-lzh/twinklewarn.js: Difference between revisions

no edit summary
mNo edit summary
No edit summary
 
(4 intermediate revisions by the same user not shown)
Line 84:
Window.display();
result.previewer = new Morebits.wiki.preview($(result).find('div#twinklewarn-previewbox').last()[0]);
 
// We must init the first choice (General Note);
var evt = document.createEvent( "Event" );
evt.initEvent( 'change', true, true );
result.main_group.dispatchEvent( evt );
};
 
// This is all the messages that might be dispatched by the code
// Each of the individual templates require the following information:
// label (required): A short description displayed in the dialog
// summary (required): The edit summary used. If an article name is entered, the summary is postfixed with "on [[article]]", and it is always postfixed with ". $summaryAd"
// suppressArticleInSummary (optional): Set to true to suppress showing the article name in the edit summary. Useful if the warning relates to attack pages, or some such.
Twinkle.warn.messages = {
"'非建設編輯"': {
"'uw-vandalism1"': "'毀文觀(提醒)"',
"'uw-vandalism2"': "'毀文觀(警告)"',
"'uw-vandalism3"': "'毀文觀(最後警告)"',
},
"'文法"': {
"'uw-lzh1"': "'非文言"',
"'uw-lzh2"': "'非文言(最後警告)"',
"'uw-lzh-en"': "'非文言(英文警告)"',
"'uw-lzh-en-2"': "'非文言(英文最後警告)"',
"'uw-simp"': "'簡體字"',
"'uw-blp"': "'生不立傳"',
},
"'態度"': {
"'uw-sign"': "'沒有簽名"',
"'uw-civil1"': "'不文明(提醒)"',
"'uw-civil2"': "'不文明(警告)"',
"'uw-editwar"': "'編輯戰"',
"'uw-baduserpage"': "'政治、宗教用戶頁"'
},
};
Twinkle.warn.summary = {
'uw-vandalism1': '提醒:毀文觀',
'uw-vandalism2': '警告:毀文觀',
'uw-vandalism3': '最後警告:毀文觀',
'uw-lzh1': '非文言',
'uw-lzh2': '最後警告:非文言',
'uw-lzh-en': 'Warning: Not Classical Chinese / 警告:非文言',
'uw-lzh-en-2': 'FINAL Warning: Not Classical Chinese / 最後警告:非文言',
'uw-simp': '提醒:莫用簡體字',
'uw-blp': '提醒:生不立傳',
'uw-sign': '提醒:請簽名',
'uw-civil1': '提醒:不文明',
'uw-civil2': '警告:不文明',
'uw-editwar': '警告:編輯戰',
'uw-baduserpage': '提醒:禁止政治、宗教用戶頁'
};
Twinkle.warn.heading = {
'*': '提醒',
'uw-vandalism2': '警示',
'uw-vandalism3': '末示!',
'uw-lzh2': '警示',
'uw-lzh-en': 'Warning',
'uw-lzh-en-2': 'Final warning',
'uw-civil2': '警示',
'uw-editwar': '警示',
};
 
Line 151 ⟶ 168:
 
Twinkle.warn.callbacks = {
getWarningWikitext: function(templateName, article, reason, isCustom) {
var text = "{{subst:" + templateName;
 
Line 159 ⟶ 176:
}
 
if (reason && !isCustom) {
// we assume that custom warnings lack a {{{2}}} parameter
text += "|2=" + reason;
Line 173 ⟶ 190:
 
templatetext = Twinkle.warn.callbacks.getWarningWikitext(templatename, linkedarticle,
form.reason.value, form.main_group.value === 'custom');
 
form.previewer.beginRender(templatetext);
Line 180 ⟶ 197:
var text = pageobj.getPageText();
var params = pageobj.getCallbackParameters();
var messageData = params.messageData;
var date = new Date();
 
var heading = Twinkle.warn.heading[params.sub_group] || Twinkle.warn.heading['*'];
var dateHeaderRegex = new RegExp( "^==+\\s*" + date.getUTCFullYear() + "年" + (date.getUTCMonth() + 1) + "月" +
"\\s*==+", 'mg' );
var dateHeaderRegexLast, dateHeaderRegexResult;
while ((dateHeaderRegexLast = dateHeaderRegex.exec( text )) !== null) {
dateHeaderRegexResult = dateHeaderRegexLast;
}
// If dateHeaderRegexResult is null then lastHeaderIndex is never checked. If it is not null but
// \n== is not found, then the date header must be at the very start of the page. lastIndexOf
// returns -1 in this case, so lastHeaderIndex gets set to 0 as desired.
var lastHeaderIndex = text.lastIndexOf( "\n==" ) + 1;
 
if( text.length > 0 ) {
Line 198 ⟶ 204:
}
 
if(text += "== " + messageData.heading )+ " {==\n";
text += "== " + messageData.heading + " ==\n";
} else if( !dateHeaderRegexResult || dateHeaderRegexResult.index !== lastHeaderIndex ) {
Morebits.status.info( '信息', '未找到當月標題,將建立新的' );
text += "== " + date.getUTCFullYear() + "年" + (date.getUTCMonth() + 1) + "月 " + " ==\n";
}
text += Twinkle.warn.callbacks.getWarningWikitext(params.sub_group, params.article,
params.reason, params.main_group === 'custom') + "--~~~~";
 
if ( Twinkle.getPref('showSharedIPNotice') && Morebits.isIPAddress( mw.config.get('wgTitle') ) ) {
Line 214 ⟶ 215:
// build the edit summary
var summary;
 
if( params.main_group === 'custom' ) {
switch(summary = Twinkle.warn.summary[params.sub_group.substr( -1 )] )|| {'';
if ( params.main_group === 'custom'article ) {
case "1":
summary += "提醒,於[[" + params.article + "]]";
break;
case "2":
summary = "注意";
break;
case "3":
summary = "警告";
break;
case "4":
summary = "最後警告";
break;
case "m":
if( params.sub_group.substr( -3 ) === "4im" ) {
summary = "唯一警告";
break;
}
summary = "提示";
break;
default:
summary = "提示";
break;
}
summary += ":" + Morebits.string.toUpperCaseFirstChar(messageData.label);
} else {
summary = messageData.summary;
if ( messageData.suppressArticleInSummary !== true && params.article ) {
summary += ",於[[" + params.article + "]]";
}
}
 
summary += Twinkle.getPref("summaryAd");
 
Line 257 ⟶ 232:
Twinkle.warn.callback.evaluate = function twinklewarnCallbackEvaluate(e) {
var userTalkPage = 'User_talk:' + Morebits.wiki.flow.relevantUserName();
 
// Find the selected <option> element so we can fetch the data structure
var selectedEl = $(e.target.sub_group).find('option[value="' + $(e.target.sub_group).val() + '"]');
 
// Then, grab all the values provided by the form
var params = {
reason: e.target.reason.value,
main_group: e.target.main_group.value,
sub_group: e.target.sub_group.value,
article: e.target.article.value, // .replace( /^(Image|Category):/i, ':$1:' ), -- apparently no longer needed...
messageData: selectedEl.data("messageData")
};