미디어위키:Gadget-friendlywelcome.js
참고: 설정을 저장한 후에 바뀐 점을 확인하기 위해서는 브라우저의 캐시를 새로 고쳐야 합니다.
- 파이어폭스 / 사파리: Shift 키를 누르면서 새로 고침을 클릭하거나, Ctrl-F5 또는 Ctrl-R을 입력 (Mac에서는 ⌘-R)
- 구글 크롬: Ctrl-Shift-R키를 입력 (Mac에서는 ⌘-Shift-R)
- 엣지: Ctrl 키를 누르면서 새로 고침을 클릭하거나, Ctrl-F5를 입력.
//<nowiki>
(function($){
/*
****************************************
*** friendlywelcome.js: Welcome module
****************************************
* Mode of invocation: Tab ("Wel"), or from links on diff pages
* Active on: Existing user talk pages, diff pages
* Config directives in: FriendlyConfig
*/
Twinkle.welcome = function friendlywelcome() {
if( Morebits.queryString.exists( 'friendlywelcome' ) ) {
if( Morebits.queryString.get( 'friendlywelcome' ) === 'auto' ) {
Twinkle.welcome.auto();
} else {
Twinkle.welcome.semiauto();
}
} else {
Twinkle.welcome.normal();
}
};
Twinkle.welcome.auto = function() {
if( Morebits.queryString.get( 'action' ) !== 'edit' ) {
// userpage not empty, aborting auto-welcome
return;
}
Twinkle.welcome.welcomeUser();
};
Twinkle.welcome.semiauto = function() {
Twinkle.welcome.callback( mw.config.get( 'wgTitle' ).split( '/' )[0].replace( /\"/, "\\\"") );
};
Twinkle.welcome.normal = function() {
if( Morebits.queryString.exists( 'diff' ) ) {
// check whether the contributors' talk pages exist yet
var $oList = $("#mw-diff-otitle2").find("span.mw-usertoollinks a.new:contains(talk)").first();
var $nList = $("#mw-diff-ntitle2").find("span.mw-usertoollinks a.new:contains(talk)").first();
if( $oList.length > 0 || $nList.length > 0 ) {
var spanTag = function( color, content ) {
var span = document.createElement( 'span' );
span.style.color = color;
span.appendChild( document.createTextNode( content ) );
return span;
};
var welcomeNode = document.createElement('strong');
var welcomeLink = document.createElement('a');
welcomeLink.appendChild( spanTag( 'Black', '[' ) );
welcomeLink.appendChild( spanTag( 'Goldenrod', 'welcome' ) );
welcomeLink.appendChild( spanTag( 'Black', ']' ) );
welcomeNode.appendChild(welcomeLink);
if( $oList.length > 0 ) {
var oHref = $oList.attr("href");
var oWelcomeNode = welcomeNode.cloneNode( true );
oWelcomeNode.firstChild.setAttribute( 'href', oHref + '&' + Morebits.queryString.create( {
'friendlywelcome': Twinkle.getFriendlyPref('quickWelcomeMode') === 'auto' ? 'auto': 'norm',
'vanarticle': Morebits.pageNameNorm
} ) );
$oList[0].parentNode.parentNode.appendChild( document.createTextNode( ' ' ) );
$oList[0].parentNode.parentNode.appendChild( oWelcomeNode );
}
if( $nList.length > 0 ) {
var nHref = $nList.attr("href");
var nWelcomeNode = welcomeNode.cloneNode( true );
nWelcomeNode.firstChild.setAttribute( 'href', nHref + '&' + Morebits.queryString.create( {
'friendlywelcome': Twinkle.getFriendlyPref('quickWelcomeMode') === 'auto' ? 'auto': 'norm',
'vanarticle': Morebits.pageNameNorm
} ) );
$nList[0].parentNode.parentNode.appendChild( document.createTextNode( ' ' ) );
$nList[0].parentNode.parentNode.appendChild( nWelcomeNode );
}
}
}
if( mw.config.get( 'wgNamespaceNumber' ) === 3 ) {
var username = mw.config.get( 'wgTitle' ).split( '/' )[0].replace( /\"/, "\\\""); // only first part before any slashes
Twinkle.addPortletLink( function(){ Twinkle.welcome.callback(username); }, "환영", "friendly-welcome", "사용자를 환영합니다" );
}
};
Twinkle.welcome.welcomeUser = function welcomeUser() {
Morebits.status.init( document.getElementById('mw-content-text') );
$( '#catlinks' ).remove();
var params = {
value: Twinkle.getFriendlyPref('quickWelcomeTemplate'),
article: Morebits.queryString.exists( 'vanarticle' ) ? Morebits.queryString.get( 'vanarticle' ) : '',
mode: 'auto'
};
Morebits.wiki.actionCompleted.redirect = mw.config.get('wgPageName');
Morebits.wiki.actionCompleted.notice = "환영을 완료했습니다. 수 초 안에 토론 문서를 다시 로드합니다.";
var wikipedia_page = new Morebits.wiki.page(mw.config.get('wgPageName'), "사용자 토론 수정");
wikipedia_page.setFollowRedirect(true);
wikipedia_page.setCallbackParameters(params);
wikipedia_page.load(Twinkle.welcome.callbacks.main);
};
Twinkle.welcome.callback = function friendlywelcomeCallback( uid ) {
if( uid === mw.config.get('wgUserName') && !confirm( '자기 자신에게 환영하시겠습니까?...' ) ){
return;
}
var Window = new Morebits.simpleWindow( 600, 420 );
Window.setTitle( "사용자 환영" );
Window.setScriptName( "트윙클" );
Window.addFooterLink( "환영위원회", "위키백과:환영위원회" );
Window.addFooterLink( "트윙클 도움말", ":en:WP:TW/DOC#welcome" );
var form = new Morebits.quickForm( Twinkle.welcome.callback.evaluate );
form.append({
type: 'select',
name: 'type',
label: '환영 종류: ',
event: Twinkle.welcome.populateWelcomeList,
list: [
{ type: 'option', value: 'standard', label: '표준 환영', selected: !Morebits.isIPAddress(mw.config.get('wgTitle')) }
]
});
form.append( {
type: 'div',
id: 'welcomeWorkArea',
className: 'morebits-scrollbox'
} );
form.append( {
type: 'input',
name: 'article',
label: '* 연결된 문서 (틀이 지원하는 경우):',
value:( Morebits.queryString.exists( 'vanarticle' ) ? Morebits.queryString.get( 'vanarticle' ) : '' ),
tooltip: '틀이 지원하는 경우 환영 틀 안에 문서를 링크할 수 있습니다.'
} );
var previewlink = document.createElement( 'a' );
$(previewlink).click(function(){
Twinkle.welcome.callbacks.preview(result); // |result| is defined below
});
previewlink.style.cursor = "pointer";
previewlink.textContent = '미리보기';
form.append( { type: 'div', name: 'welcomepreview', label: [ previewlink ] } );
form.append( { type: 'submit' } );
var result = form.render();
Window.setContent( result );
Window.display();
// initialize the welcome list
var evt = document.createEvent( "Event" );
evt.initEvent( 'change', true, true );
result.type.dispatchEvent( evt );
};
Twinkle.welcome.populateWelcomeList = function(e) {
var type = e.target.value;
var container = new Morebits.quickForm.element({ type: "fragment" });
if ((type === "standard") && Twinkle.getFriendlyPref("customWelcomeList").length) {
container.append({ type: 'header', label: '사용자 정의 환영 틀' });
container.append({
type: 'radio',
name: 'template',
list: Twinkle.getFriendlyPref("customWelcomeList"),
event: Twinkle.welcome.selectTemplate
});
}
var appendTemplates = function(list) {
container.append({
type: 'radio',
name: 'template',
list: list.map(function(obj) {
var properties = Twinkle.welcome.templates[obj];
var result = (properties ? {
value: obj,
label: "{{" + obj + "}}: " + properties.description + (properties.linkedArticle ? "\u00A0*" : ""), // U+00A0 NO-BREAK SPACE
tooltip: properties.tooltip // may be undefined
} : {
value: obj,
label: "{{" + obj + "}}"
});
return result;
}),
event: Twinkle.welcome.selectTemplate
});
};
switch (type) {
case "standard":
container.append({ type: 'header', label: '일반 환영 틀' });
appendTemplates([
"환영합니다",
]);
break;
default:
container.append({ type: 'div', label: 'Twinkle.welcome.populateWelcomeList: 무언가 잘못되었습니다.' });
break;
}
var rendered = container.render();
$(e.target.form).find("div#welcomeWorkArea").empty().append(rendered);
var firstRadio = e.target.form.template[0];
firstRadio.checked = true;
Twinkle.welcome.selectTemplate({ target: firstRadio });
};
Twinkle.welcome.selectTemplate = function(e) {
var properties = Twinkle.welcome.templates[e.target.values];
e.target.form.article.disabled = (properties ? !properties.linkedArticle : false);
};
// A list of welcome templates and their properties and syntax
// The four fields that are available are "description", "linkedArticle", "syntax", and "tooltip".
// The three magic words that can be used in the "syntax" field are:
// - $USERNAME$ - replaced by the welcomer's username, depending on user's preferences
// - $ARTICLE$ - replaced by an article name, if "linkedArticle" is true
// - $HEADER$ - adds a level 2 header (most templates already include this)
Twinkle.welcome.templates = {
// GENERAL WELCOMES
"환영합니다": {
description: "표준 환영 틀",
linkedArticle: true,
syntax: "{{환영합니다}} ~~~~"
}
};
Twinkle.welcome.getTemplateWikitext = function(template, article) {
var properties = Twinkle.welcome.templates[template];
if (properties) {
return properties.syntax.
replace("$USERNAME$", Twinkle.getFriendlyPref("insertUsername") ? mw.config.get("wgUserName") : "").
replace("$ARTICLE$", article ? article : "").
replace(/\$HEADER\$\s*/, "== 환영합니다 ==\n\n").
replace("$EXTRA$", ""); // EXTRA is not implemented yet
} else {
return "{{" + template + "}}" +
(Twinkle.getFriendlyPref("customWelcomeSignature") ? " ~~~~" : "");
}
};
Twinkle.welcome.callbacks = {
preview: function(form) {
var previewDialog = new Morebits.simpleWindow(750, 400);
previewDialog.setTitle("환영 틀 미리보기");
previewDialog.setScriptName("사용자를 환영합니다");
previewDialog.setModality(true);
var previewdiv = document.createElement("div");
previewdiv.style.marginLeft = previewdiv.style.marginRight = "0.5em";
previewdiv.style.fontSize = "small";
previewDialog.setContent(previewdiv);
var previewer = new Morebits.wiki.preview(previewdiv);
previewer.beginRender(Twinkle.welcome.getTemplateWikitext(form.getChecked("template"), form.article.value));
var submit = document.createElement("input");
submit.setAttribute("type", "submit");
submit.setAttribute("value", "닫기");
previewDialog.addContent(submit);
previewDialog.display();
$(submit).click(function(e) {
previewDialog.close();
});
},
main: function( pageobj ) {
var params = pageobj.getCallbackParameters();
var text = pageobj.getPageText();
// abort if mode is auto and form is not empty
if( pageobj.exists() && params.mode === 'auto' ) {
Morebits.status.info( '경고', '사용자 토론 문서가 비어있지 않습니다. 자동 환영을 중단합니다.' );
Morebits.wiki.actionCompleted.event();
return;
}
var welcomeText = Twinkle.welcome.getTemplateWikitext(params.value, params.article);
if( Twinkle.getFriendlyPref('topWelcomes') ) {
text = welcomeText + '\n\n' + text;
} else {
text += "\n" + welcomeText;
}
var summaryText = "위키백과에 오신 것을 환영합니다!";
pageobj.setPageText(text);
pageobj.setEditSummary(summaryText + Twinkle.getPref('summaryAd'));
pageobj.setWatchlist(Twinkle.getFriendlyPref('watchWelcomes'));
pageobj.setCreateOption('recreate');
pageobj.save();
}
};
Twinkle.welcome.callback.evaluate = function friendlywelcomeCallbackEvaluate(e) {
var form = e.target;
var params = {
value: form.getChecked("template"),
article: form.article.value,
mode: 'manual'
};
Morebits.simpleWindow.setButtonsEnabled( false );
Morebits.status.init( form );
Morebits.wiki.actionCompleted.redirect = mw.config.get('wgPageName');
Morebits.wiki.actionCompleted.notice = "환영을 완료했습니다. 수 초 안에 토론 문서를 다시 로드합니다.";
var wikipedia_page = new Morebits.wiki.page(mw.config.get('wgPageName'), "사용자 토론 문서 수정");
wikipedia_page.setFollowRedirect(true);
wikipedia_page.setCallbackParameters(params);
wikipedia_page.load(Twinkle.welcome.callbacks.main);
};
})(jQuery);
//</nowiki>