미디어위키:Gadget-twinklexfd.js
참고: 설정을 저장한 후에 바뀐 점을 확인하기 위해서는 브라우저의 캐시를 새로 고쳐야 합니다.
- 파이어폭스 / 사파리: Shift 키를 누르면서 새로 고침을 클릭하거나, Ctrl-F5 또는 Ctrl-R을 입력 (Mac에서는 ⌘-R)
- 구글 크롬: Ctrl-Shift-R키를 입력 (Mac에서는 ⌘-Shift-R)
- 엣지: Ctrl 키를 누르면서 새로 고침을 클릭하거나, Ctrl-F5를 입력.
//<nowiki>
(function($){
/*
****************************************
*** twinklexfd.js: XFD module
****************************************
* Mode of invocation: Tab ("XFD")
* Active on: Existing, non-special pages, except for file pages with no local (non-Commons) file which are not redirects
* Config directives in: TwinkleConfig
*/
Twinkle.xfd = function twinklexfd() {
// Disable on:
// * special pages
// * non-existent pages
// * files on Commons, whether there is a local page or not (unneeded local pages of files on Commons are eligible for CSD F2)
// * file pages without actual files (these are eligible for CSD G8)
if ( mw.config.get('wgNamespaceNumber') < 0 || !mw.config.get('wgArticleId') || (mw.config.get('wgNamespaceNumber') === 6 && (document.getElementById('mw-sharedupload') || (!document.getElementById('mw-imagepage-section-filehistory') && !Morebits.wiki.isPageRedirect()))) ) {
return;
}
Twinkle.addPortletLink( Twinkle.xfd.callback, "삭제 토론", "tw-xfd", "삭제 토론" );
};
Twinkle.xfd.num2order = function twinklexfdNum2order( num ) {
switch( num ) {
case 1: return '';
case 2: return '2nd';
case 3: return '3rd';
default: return num + 'th';
}
};
Twinkle.xfd.currentRationale = null;
// error callback on Morebits.status.object
Twinkle.xfd.printRationale = function twinklexfdPrintRationale() {
if (Twinkle.xfd.currentRationale) {
Morebits.status.printUserText(Twinkle.xfd.currentRationale, "Your deletion rationale is provided below, which you can copy and paste into a new XFD dialog if you wish to try again:");
// only need to print the rationale once
Twinkle.xfd.currentRationale = null;
}
};
Twinkle.xfd.callback = function twinklexfdCallback() {
var Window = new Morebits.simpleWindow( 600, 350 );
Window.setTitle( "삭제 토론" );
Window.setScriptName( "트윙클" );
Window.addFooterLink( "삭제 토론 정보", "위키백과:삭제토론" );
Window.addFooterLink( "트윙클 도움말", ":en:WP:TW/DOC#xfd" );
var form = new Morebits.quickForm( Twinkle.xfd.callback.evaluate );
var categories = form.append( {
type: 'select',
name: 'category',
label: '삭제가 논의되는 장소:',
tooltip: '삭제에 가장 적절한 장소를 선택합니다.',
event: Twinkle.xfd.callback.change_category
} );
categories.append( {
type: 'option',
label: '삭제 토론',
selected: mw.config.get('wgNamespaceNumber') === 0, // Main namespace
value: 'afd'
} );
form.append( {
type: 'checkbox',
list: [
{
label: '가능하면 문서 작성자에게 알립니다',
value: 'notify',
name: 'notify',
tooltip: "알림 틀이 사용자 토론 문서에 부착됩니다.",
checked: true
}
]
}
);
form.append( {
type: 'field',
label:'작업 영역',
name: 'work_area'
} );
var previewlink = document.createElement( 'a' );
$(previewlink).click(function(){
Twinkle.xfd.callbacks.preview(result); // |result| is defined below
});
previewlink.style.cursor = "pointer";
previewlink.textContent = '미리보기';
form.append( { type: 'div', id: 'xfdpreview', label: [ previewlink ] } );
form.append( { type: 'div', id: 'twinklexfd-previewbox', style: 'display: none' } );
form.append( { type:'submit' } );
var result = form.render();
Window.setContent( result );
Window.display();
result.previewer = new Morebits.wiki.preview($(result).find('div#twinklexfd-previewbox').last()[0]);
// We must init the controls
var evt = document.createEvent( "Event" );
evt.initEvent( 'change', true, true );
result.category.dispatchEvent( evt );
};
Twinkle.xfd.previousNotify = true;
Twinkle.xfd.callback.change_category = function twinklexfdCallbackChangeCategory(e) {
var value = e.target.value;
var form = e.target.form;
var old_area = Morebits.quickForm.getElements(e.target.form, "work_area")[0];
var work_area = null;
var oldreasontextbox = form.getElementsByTagName('textarea')[0];
var oldreason = (oldreasontextbox ? oldreasontextbox.value : '');
var appendReasonBox = function twinklexfdAppendReasonBox() {
work_area.append( {
type: 'textarea',
name: 'xfdreason',
label: 'Reason: ',
value: oldreason,
tooltip: 'You can use wikimarkup in your reason. Twinkle will automatically sign your post.'
} );
// TODO possible future "preview" link here
};
form.previewer.closePreview();
switch( value ) {
case 'afd':
work_area = new Morebits.quickForm.element( {
type: 'field',
label: '삭제 토론',
name: 'work_area'
} );
work_area.append( {
type: 'checkbox',
list: [
{
label: '삭제 태그를 <noinclude>로 감싸기',
value: 'noinclude',
name: 'noinclude',
tooltip: '삭제 태그를 <noinclude> 태그로 감싸면 transclude 처리되지 않습니다. 이 옵션은 일반적으로 필수 사항이 아닙니다.'
}
]
} );
var afd_category = work_area.append( {
type:'select',
name:'xfdcat',
label:'분류를 선택하십시오:'
} );
afd_category.append( { type:'option', label:'알 수 없음', value:'?', selected:true } );
/*
afd_category.append( { type:'option', label:'Media and music', value:'M' } );
afd_category.append( { type:'option', label:'Organisation, corporation, or product', value:'O' } );
afd_category.append( { type:'option', label:'Biographical', value:'B' } );
afd_category.append( { type:'option', label:'Society topics', value:'S' } );
afd_category.append( { type:'option', label:'Web or internet', value:'W' } );
afd_category.append( { type:'option', label:'Games or sports', value:'G' } );
afd_category.append( { type:'option', label:'Science and technology', value:'T' } );
afd_category.append( { type:'option', label:'Fiction and the arts', value:'F' } );
afd_category.append( { type:'option', label:'Places and transportation', value:'P' } );
afd_category.append( { type:'option', label:'Indiscernible or unclassifiable topic', value:'I' } );
afd_category.append( { type:'option', label:'Debate not yet sorted', value:'U' } );
*/
appendReasonBox();
work_area = work_area.render();
old_area.parentNode.replaceChild( work_area, old_area );
break;
default:
work_area = new Morebits.quickForm.element( {
type: 'field',
label: 'Nothing for anything',
name: 'work_area'
} );
work_area = work_area.render();
old_area.parentNode.replaceChild( work_area, old_area );
break;
}
// No creator notification for CFDS
if (value === "cfds") {
Twinkle.xfd.previousNotify = form.notify.checked;
form.notify.checked = false;
form.notify.disabled = true;
} else {
form.notify.checked = Twinkle.xfd.previousNotify;
form.notify.disabled = false;
}
};
Twinkle.xfd.callbacks = {
// Currently supports afd, mfd, tfd/tfm, ffd
getDiscussionWikitext: function(venue, params) {
var text = "{{풀기:삭제 토론";
text += "|" + Morebits.pageNameNorm + "}}";
//params.target;
return text;
},
showPreview: function(form, venue, params) {
templatetext = Twinkle.xfd.callbacks.getDiscussionWikitext(venue, params);
form.previewer.beginRender(templatetext, Morebits.pageNameNorm);
},
preview: function(form) {
var templatetext;
var venue = form.category.value;
if (venue !== "afd") {
alert("이 토론 장소에서는 미리보기가 지원되지 않습니다! :(");
return;
}
var params = {
reason: form.xfdreason.value,
};
if (form.xfdcat) {
params.xfdcat = form.xfdcat.value;
}
if (form.xfdtarget) {
params.target = form.xfdtarget.value;
}
if (venue === "ffd") {
// Fetch the uploader
var page = new Morebits.wiki.page(mw.config.get('wgPageName'));
page.lookupCreator(function() {
params.uploader = page.getCreator();
Twinkle.xfd.callbacks.showPreview(form, venue, params);
});
} else {
Twinkle.xfd.callbacks.showPreview(form, venue, params);
}
},
afd: {
main: function(apiobj) {
var xmlDoc = apiobj.responseXML;
var titles = $(xmlDoc).find('allpages p');
// There has been no earlier entries with this prefix, just go on.
if( titles.length <= 0 ) {
apiobj.params.numbering = apiobj.params.number = '';
} else {
var number = 0;
for( var i = 0; i < titles.length; ++i ) {
var title = titles[i].getAttribute('title');
// First, simple test, is there an instance with this exact name?
if( title === '위키백과:삭제 토론/' + Morebits.pageNameNorm ) {
number = Math.max( number, 1 );
continue;
}
var order_re = new RegExp( '^' +
RegExp.escape( '위키백과:삭제 토론/' + Morebits.pageNameNorm, true ) +
'\\s*\\(\\s*(\\d+)(?:(?:th|nd|rd|st) nom(?:ination)?)?\\s*\\)\\s*$');
var match = order_re.exec( title );
// No match; A non-good value
if( !match ) {
continue;
}
// A match, set number to the max of current
number = Math.max( number, Number(match[1]) );
}
apiobj.params.number = Twinkle.xfd.num2order( parseInt( number, 10 ) + 1);
apiobj.params.numbering = number > 0 ? ' (' + apiobj.params.number + ' nomination)' : '';
}
apiobj.params.discussionpage = '위키백과:삭제 토론/' + Morebits.pageNameNorm + apiobj.params.numbering;
Morebits.status.info( "다음 토론 문서", "[[" + apiobj.params.discussionpage + "]]" );
// Updating data for the action completed event
Morebits.wiki.actionCompleted.redirect = apiobj.params.discussionpage;
Morebits.wiki.actionCompleted.notice = "Nomination completed, now redirecting to the discussion page";
// Tagging article
var wikipedia_page = new Morebits.wiki.page(mw.config.get('wgPageName'), "삭제 태그를 문서에 추가하는 중");
wikipedia_page.setFollowRedirect(true); // should never be needed, but if the article is moved, we would want to follow the redirect
wikipedia_page.setCallbackParameters(apiobj.params);
wikipedia_page.load(Twinkle.xfd.callbacks.afd.taggingArticle);
},
// Tagging needs to happen before everything else: this means we can check if there is an AfD tag already on the page
taggingArticle: function(pageobj) {
var text = pageobj.getPageText();
var params = pageobj.getCallbackParameters();
var statelem = pageobj.getStatusElement();
if (!pageobj.exists()) {
statelem.error("It seems that the page doesn't exist; perhaps it has already been deleted");
return;
}
// Check for existing AfD tag, for the benefit of new page patrollers
var textNoAfd = text.replace(/\{\{\s*(Article for deletion\/dated|AfDM)\s*(\|(?:\{\{[^{}]*\}\}|[^{}])*)?\}\}\s*/g, "");
if (text !== textNoAfd) {
if (confirm("An AfD tag was found on this article. Maybe someone beat you to it. \nClick OK to replace the current AfD tag (not recommended), or Cancel to abandon your nomination.")) {
text = textNoAfd;
} else {
statelem.error("Article already tagged with AfD tag, and you chose to abort");
window.location.reload();
return;
}
}
// Now we know we want to go ahead with it, trigger the other AJAX requests
// Mark the page as patrolled, if wanted
if (Twinkle.getPref('markXfdPagesAsPatrolled')) {
pageobj.patrol();
}
// Starting discussion page
var wikipedia_page = new Morebits.wiki.page(params.discussionpage, "Creating article deletion discussion page");
wikipedia_page.setCallbackParameters(params);
wikipedia_page.load(Twinkle.xfd.callbacks.afd.discussionPage);
// Today's list
var date = new Date();
wikipedia_page = new Morebits.wiki.page('위키백과:삭제 토론/' + date.getUTCFullYear() + ' ' +
date.getUTCMonthName() + ' ' + date.getUTCDate(), "Adding discussion to today's list");
wikipedia_page.setFollowRedirect(true);
wikipedia_page.setCallbackParameters(params);
wikipedia_page.load(Twinkle.xfd.callbacks.afd.todaysList);
// Notification to first contributor
if (params.usertalk) {
var thispage = new Morebits.wiki.page(mw.config.get('wgPageName'));
thispage.setCallbackParameters(params);
thispage.lookupCreator(Twinkle.xfd.callbacks.afd.userNotification);
}
pageobj.setPageText((params.noinclude ? "<noinclude>{{" : "{{") + (params.number === '' ? "subst:afd|help=off" : ('subst:afdx|' +
params.number + "|help=off")) + (params.noinclude ? "}}</noinclude>\n" : "}}\n") + text);
pageobj.setEditSummary("Nominated for deletion; see [[" + params.discussionpage + "]]." + Twinkle.getPref('summaryAd'));
switch (Twinkle.getPref('xfdWatchPage')) {
case 'yes':
pageobj.setWatchlist(true);
break;
case 'no':
pageobj.setWatchlistFromPreferences(false);
break;
default:
pageobj.setWatchlistFromPreferences(true);
break;
}
pageobj.setCreateOption('nocreate');
pageobj.save();
},
discussionPage: function(pageobj) {
var params = pageobj.getCallbackParameters();
pageobj.setPageText(Twinkle.xfd.callbacks.getDiscussionWikitext("afd", params));
pageobj.setEditSummary("Creating deletion discussion page for [[" + Morebits.pageNameNorm + "]]." + Twinkle.getPref('summaryAd'));
switch (Twinkle.getPref('xfdWatchDiscussion')) {
case 'yes':
pageobj.setWatchlist(true);
break;
case 'no':
pageobj.setWatchlistFromPreferences(false);
break;
default:
pageobj.setWatchlistFromPreferences(true);
break;
}
pageobj.setCreateOption('createonly');
pageobj.save(function() {
Twinkle.xfd.currentRationale = null; // any errors from now on do not need to print the rationale, as it is safely saved on-wiki
});
},
todaysList: function(pageobj) {
var old_text = pageobj.getPageText() + "\n"; // MW strips trailing blanks, but we like them, so we add a fake one
var params = pageobj.getCallbackParameters();
var statelem = pageobj.getStatusElement();
var text = old_text.replace( /(<\!-- Add new entries to the TOP of the following list -->\n+)/, "$1{{subst:afd3|pg=" + Morebits.pageNameNorm + params.numbering + "}}\n");
if( text === old_text ) {
var linknode = document.createElement('a');
linknode.setAttribute("href", mw.util.getUrl("Wikipedia:Twinkle/Fixing AFD") + "?action=purge" );
linknode.appendChild(document.createTextNode('How to fix AFD'));
statelem.error( [ 'Could not find the target spot for the discussion. To fix this problem, please see ', linknode, '.' ] );
return;
}
pageobj.setPageText(text);
pageobj.setEditSummary("Adding [[" + params.discussionpage + "]]." + Twinkle.getPref('summaryAd'));
switch (Twinkle.getPref('xfdWatchList')) {
case 'yes':
pageobj.setWatchlist(true);
break;
case 'no':
pageobj.setWatchlistFromPreferences(false);
break;
default:
pageobj.setWatchlistFromPreferences(true);
break;
}
pageobj.setCreateOption('recreate');
pageobj.save();
},
userNotification: function(pageobj) {
var params = pageobj.getCallbackParameters();
var initialContrib = pageobj.getCreator();
// Disallow warning yourself
if (initialContrib === mw.config.get('wgUserName')) {
pageobj.getStatusElement().warn("You (" + initialContrib + ") created this page; skipping user notification");
return;
}
var usertalkpage = new Morebits.wiki.page('사용자토론:' + initialContrib, "Notifying initial contributor (" + initialContrib + ")");
var notifytext = "\n{{subst:삭제 토론 알림|" + Morebits.pageNameNorm + ( params.numbering !== '' ? '|order= ' + params.numbering : '' ) + "}} ~~~~";
usertalkpage.setAppendText(notifytext);
usertalkpage.setEditSummary("Notification: listing at [[WP:AFD|articles for deletion]] of [[" + Morebits.pageNameNorm + "]]." + Twinkle.getPref('summaryAd'));
usertalkpage.setCreateOption('recreate');
switch (Twinkle.getPref('xfdWatchUser')) {
case 'yes':
usertalkpage.setWatchlist(true);
break;
case 'no':
usertalkpage.setWatchlistFromPreferences(false);
break;
default:
usertalkpage.setWatchlistFromPreferences(true);
break;
}
usertalkpage.setFollowRedirect(true);
usertalkpage.append();
}
}
};
Twinkle.xfd.callback.evaluate = function(e) {
var type = e.target.category.value;
var usertalk = e.target.notify.checked;
var reason = e.target.xfdreason.value;
var xfdcat, xfdtarget, xfdtarget2, noinclude, tfdtype, notifyuserspace;
if( type === "afd") {
noinclude = e.target.noinclude.checked;
}
Morebits.simpleWindow.setButtonsEnabled( false );
Morebits.status.init( e.target );
Twinkle.xfd.currentRationale = reason;
Morebits.status.onError(Twinkle.xfd.printRationale);
if( !type ) {
Morebits.status.error( 'Error', 'no action given' );
return;
}
var query, wikipedia_page, wikipedia_api, logpage, params;
var date = new Date();
switch( type ) {
case 'afd': // AFD
query = {
'action': 'query',
'list': 'allpages',
'apprefix': '삭제 토론/' + Morebits.pageNameNorm,
'apnamespace': 4,
'apfilterredir': 'nonredirects',
'aplimit': Morebits.userIsInGroup( 'sysop' ) ? 5000 : 500
};
wikipedia_api = new Morebits.wiki.api( 'Tagging article with deletion tag', query, Twinkle.xfd.callbacks.afd.main );
wikipedia_api.params = { usertalk:usertalk, reason:reason, noinclude:noinclude, xfdcat:xfdcat };
wikipedia_api.post();
break;
default:
alert("twinklexfd: unknown XFD discussion venue");
break;
}
};
})(jQuery);
//</nowiki>