「MediaWiki:Common.js/edit.js」:修訂間差異

出自竹園Wiki
跳至導覽 跳至搜尋
無編輯摘要
無編輯摘要
 
(未顯示同一使用者於中間所作的 3 次修訂)
行 1: 行 1:
//<source lang="javascript">

/*
/*

所有用戶在加載任何頁面時,這裡的JavaScript都會加載
== 編輯工具欄 ==
*/
*/


/**
mw.log.deprecate( window, 'JSConfig', {} );
* tip for custom edittools
*
* Maintainers: fdcn@zh.wikipedia
*/
$( function(){
//在提交新段落時,讓主題欄在特定情況下失效
if(document.getElementById('no-new-title') && document.editform.wpSection.value=="new") {
if(summaryinput=document.getElementById("wpSummary")) {
summaryinput.disabled=true;
summaryinput.value='';
}
}
});


( function( $, mw ) { $( function() {
mw.loader.using(['mediawiki.util', 'ext.gadget.site-lib'], function () {
if ( $( '#editform input[name=wpSection]' ).val() === 'new' ) {
(function ($, mw) {
if ( $( '#no-new-title' ).length ) {

$( '#wpSummary' ).attr( 'disabled', true );
/* 當需要時載入對應的 scripts */
}
if (mw.config.get('wgAction') == "edit" || mw.config.get('wgAction') == "submit" || mw.config.get('wgCanonicalSpecialPageName') == 'Search') { // scripts specific to editing pages
return;
importScript('MediaWiki:Common.js/edit.js');
}
}
$( '#wpSummaryLabel .mw-summary-preset' ).on( 'click', '.mw-summary-preset-item a', function( e ) {

e.preventDefault();
// wiki URL
var $this = $( this ), summary = $( '#wpSummary' ).val();
window.wgProjectURL = {
var $item = $this.parent( '.mw-summary-preset-item' );
en: '//en.wikipedia.org',
summary = summary.replace( /\s+$/g, '' );
de: '//de.wikipedia.org',
if ( summary != '' ) {
fr: '//fr.wikipedia.org',
pl: '//pl.wikipedia.org',
summary += ' ';
ja: '//ja.wikipedia.org',
it: '//it.wikipedia.org',
nl: '//nl.wikipedia.org',
pt: '//pt.wikipedia.org',
es: '//es.wikipedia.org',
sv: '//sv.wikipedia.org',
// 僅列前十名其它語言百科
m: '//meta.wikimedia.org',
b: '//zh.wikibooks.org',
q: '//zh.wikiquote.org',
n: '//zh.wikinews.org',
wikt: '//zh.wiktionary.org',
mw: '//www.mediawiki.org',
commons: '//commons.wikimedia.org'
};

/** 将页面名称转换为URL
*
* @param page 页面名称
* @param paras 附加后缀对象,用空对象{}做参数可以取得源码
*/
window.getWikiPath = function (page, paras) {
var reg = /^[a-z]+:/;
var pre = page.match(reg);
pre = pre && wgProjectURL[pre[0].replace(/:$/, '').toLowerCase()];
if (pre) {
page = page.replace(reg, '');
} else {
pre = mw.config.get('wgServer');
} // 保障没有相对路径,以照顾在线代理。
var url = pre + mw.config.get('wgScript') + '?title=' + encodeURI(page.replace(' ', '_'));
if (typeof paras == 'object') {
paras.ctype = paras.ctype || 'text';
paras.action = paras.action || 'raw';
for (var k in paras) {
url += '&' + k + '=' + paras[k];
}
}
summary += $item.attr( 'title' ) || $this.text();
}
$this.replaceWith( $this.contents() );
return url;
$( '#wpSummary' ).val( summary );
};
} );
} ); } )( jQuery, mediaWiki );


/**
/*
* Helper script for .hlist class in Common.css
* Add pseudo-selector class to last-child list items in IE8
* @source mediawiki.org/wiki/Snippets/Horizontal_lists
* @revision 6 (2014-08-23)
* @author [[User:Edokter]]
*/
var profile = $.client.profile();
if ( profile.name === 'msie' && profile.versionNumber === 8 ) {
mw.hook( 'wikipage.content' ).add( function ( $content ) {
$content.find( '.hlist' ).find( 'dd:last-child, dt:last-child, li:last-child' )
.addClass( 'hlist-last-child' );
} );
}


== 強制預覽 ==
/* Fixes for Windows XP font rendering */
[[mw:Manual:Force preview]]
if (navigator.appVersion.search(/windows nt 5/i) != -1) {
*/
mw.util.addCSS('.IPA {font-family: "Lucida Sans Unicode", "Arial Unicode MS";} ' +
'.Unicode {font-family: "Arial Unicode MS", "Lucida Sans Unicode";}');
}


// -------------------------------------------------------------------------------
// 修正摺疊後定位變化
// Force Preview JavaScript code - Start
$(function () {
//
if (location.hash) {
// To allow any group to bypass being forced to preview,
location.href = location.hash;
// enter the group name in the permittedGroups array.
}
});
// E.g.
// var permittedGroups = []; // force everyone
// var permittedGroups = [ "user"]; // permit logged-in users
// var permittedGroups = [ "sysop", "bureaucrat"]; // permit sysop, bureaucrat
// -------------------------------------------------------------------------------
var permittedGroups = [ 'confirmed', 'autoconfirmed' ];
Array.prototype.intersects = function() {
// --------------------------------------------------------
// Returns true if any element in the argument array
// is the same as an element in this array
// --------------------------------------------------------
if ( !arguments.length ) return false;


var array2 = arguments[0];
/** metaBox
*
* Funcionament de la Plantilla:Metacaixa
* Implementat per: Usuari:Peleguer.
* Actualitzat per Joanjoc seguint les indicacions d'en Martorell
*/
function MetaCaixaInit() {
// S'executa al carregar-se la pàgina, si hi ha metacaixes,
// s'assignen els esdeveniments als botons
//alert("MetaCaixaInit");
var i = 0; // Inicialitzem comptador de caixes
for (i = 0; i <= 9; i++) {
var vMc = document.getElementById("mc" + i);
if (!vMc) break;
//alert("MetaCaixaInit, trobada Metacaixa mc"+i);
var j = 1; // Inicialitzem comptador de botons dins de la caixa
var vPsIni = 0; // Pestanya visible inicial
for (j = 1; j <= 9; j++) {
var vBt = document.getElementById("mc" + i + "bt" + j);
if (!vBt) break;
//alert("MetaCaixaInit, trobat botó mc"+i+"bt"+j);
vBt.onclick = MetaCaixaMostraPestanya; // A cada botó assignem l'esdeveniment onclick
//alert (vBt.className);
if (vBt.className == "mcBotoSel") vPsIni = j; // Si tenim un botó seleccionat, en guardem l'index
}
//alert ("mc="+i+", ps="+j+", psini="+vPsIni );
if (vPsIni === 0) { // Si no tenim cap botó seleccionat, n'agafem un aleatòriament
vPsIni = 1 + Math.floor((j - 1) * Math.random());
//alert ("Activant Pestanya a l'atzar; _mc"+i+"bt"+vPsIni +"_");
document.getElementById("mc" + i + "ps" + vPsIni).style.display = "block";
document.getElementById("mc" + i + "ps" + vPsIni).style.visibility = "visible";
document.getElementById("mc" + i + "bt" + vPsIni).className = "mcBotoSel";
}
}
}


var len1 = this.length;
function MetaCaixaMostraPestanya() {
var len2 = array2.length;
// S'executa al clicar una pestanya,
if ( len2 == 0 ) return false;
// aquella es fa visible i les altres s'oculten
var vMcNom = this.id.substr(0, 3); // A partir del nom del botó, deduïm el nom de la caixa
var vIndex = this.id.substr(5, 1); // I l'index
var i = 1;
for (i = 1; i <= 9; i++) { // busquem totes les pestanyes d'aquella caixa
//alert(vMcNom+"ps"+i);
var vPsElem = document.getElementById(vMcNom + "ps" + i);
if (!vPsElem) break;
if (vIndex == i) { // Si és la pestanya bona la mostrem i canviem la classe de botó
vPsElem.style.display = "block";
vPsElem.style.visibility = "visible";
document.getElementById(vMcNom + "bt" + i).className = "mcBotoSel";
} else { // Sinó, l'ocultem i canviem la classe de botó
vPsElem.style.display = "none";
vPsElem.style.visibility = "hidden";
document.getElementById(vMcNom + "bt" + i).className = "mcBoto";
}
}
return false; // evitem la recàrrega de la pàgina
}
$(MetaCaixaInit);


for ( var i = 0; i < len1; i++ ) {
/* 智能讨论页编辑(新建) */
$(function () {
for ( var j = 0; j < len2; j++ ) {
if ( this[i] === array2[j] ) return true;
var catalk = $('#ca-talk');
}
if (catalk.hasClass('new') && mw.config.get('wgNamespaceNumber') != 2) {
}
var a = $('a:first', catalk);
return false;
a.attr('href', a.attr('href') + '&section=new');
};
}
});
function forcePreview() {

if ( mw.config.get( "wgAction" ) != "edit" ) return;
/**
if ( mw.config.get( "wgUserGroups" ).intersects( permittedGroups ) ) return;
* Magic editintros ****************************************************
// Doesn't work correctly with live preview
*
if ( mw.user.options.get( "uselivepreview" ) == "1" ) return;
* Description: Adds editintros on disambiguation pages and BLP pages.
var saveButton = document.getElementById( "wpSave" );
* Maintainers: [[User:RockMFR]]
if ( !saveButton ) return;
*/
saveButton.disabled = true;
function addEditIntro( name ) {
saveButton.value = saveButton.value + wgULS( '(請先預覽)', '(請先預覽)' );
$( '.mw-editsection, #ca-edit' ).find( 'a' ).each( function ( i, el ) {
saveButton.style.fontWeight = "normal";
el.href = $( this ).attr( 'href' ) + '&editintro=' + name;
document.getElementById("wpPreview").style.fontWeight = "bold";
} );
}
}


jQuery(document).ready( forcePreview );
if ( mw.config.get( 'wgNamespaceNumber' ) === 0 ) {
// -----------------------------------------------------
$( function () {
// Force Preview JavaScript code - End
if ( document.getElementById( 'disambigbox' ) ) {
// -----------------------------------------------------
addEditIntro( 'Template:Disambig_editintro' );
}
} );


/*
$( function () {
var cats = mw.config.get('wgCategories');
if ( !cats ) {
return;
}
if ( $.inArray( '在世人物', cats ) !== -1 ) {
addEditIntro( 'Template:BLP_editintro' );
}
} );
}


== 取消修訂編輯摘要修正 ==
/* 引用錯誤標籤名字解碼 */
*/
$(function () {
$('.anchordecodeme').each(function () {
$(this).text(decodeURIComponent($(this).text().replace(/\.([0-9A-F]{2})/g, '%$1')));
});
});

/** &withCSS= and &withJS= URL parameters
* Allow to try custom scripts from MediaWiki space
* without editing personal .css or .js files
*/
/**
/**
fix edit summary prompt for undo
* @source www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
this code fixes the fact that the undo function combined with the "no edit summary prompter" causes problems if leaving the edit summary unchanged
* @rev 6
this was added by [[:en:User:Deskana]], code by [[:en:User:Tra]]
*/
*/
var extraCSS = mw.util.getParamValue( 'withCSS' ),
$ (function () {
extraJS = mw.util.getParamValue( 'withJS' );
var autoSummary=document.getElementsByName('wpAutoSummary')[0];
if (document.location.search.indexOf("undo=") != -1 && autoSummary)
{ autoSummary.value=''; }
});


/*
if ( extraCSS ) {
if ( extraCSS.match( /^MediaWiki:[^&<>=%#]*\.css$/ ) ) {
importStylesheet( extraCSS );
} else {
mw.notify( '只允许从MediaWiki名字空间加载。', { title: '无效的withCSS值' } );
}
}


== WP:DYKC編輯時取消編輯摘要空段落標示 ==
if ( extraJS ) {
*/
if ( extraJS.match( /^MediaWiki:[^&<>=%#]*\.js$/ ) ) {
$( function(){
importScript( extraJS );
var $wpSummary=$("#editform #wpSummary"), $wpTextbox1=$("#editform #wpTextbox1");
} else {
if($wpSummary.length==0 || $wpTextbox1.length==0) return;
mw.notify( '只允许从MediaWiki名字空间加载。', { title: '无效的withJS值' } );
var wpSummary=$wpSummary.get(0), wpTextbox1=$wpTextbox1.get(0);
}
var keyReg= /(?:\n|.)*\|\s*article\s*= *([\S ]*)(?:\n|.)*/m ;
}
if(wpSummary.value.indexOf("  ")>=0) wpSummary.value="";
if(mw.config.get("wgPageName")!="Wikipedia:新條目推薦/候選") return;
if(wpSummary.value=="/"+"* *"+"/ " && wpTextbox1.value.match(keyReg) ){}else return;
var temp=wpTextbox1.value.replace(keyReg, '$1');
if(!temp) return;
wpSummary.value=wpSummary.defaultValue="\/"+"* "+temp+" *"+"\/ ";
});




/* Check for any client-side simplified/traditional Chinese conversion */
/* 页面历史加&hilight=高亮 */
var checkAntiConv = function() {
{
var hilight = mw.util.getParamValue('hilight');
var $ac = $('#wpAntiConv');
if (mw.config.get('wgAction') === 'history' && hilight) {
if ($ac.length && $ac.val() != '\u6c49\u6f22') {
$.each(hilight.split(','), function (_, v) {
var text = $('#wpTextbox1').val();
$('input[name=oldid][value=' + v + ']').parent().addClass('not-patrolled');
var section = $('input[name=wpSection]').val();
var basetimestamp = $('input[name=wpEdittime]').val();
});
var starttimestamp = $('input[name=wpStarttime]').val();
}
$('#editform :input').attr({disabled:true,readOnly:true});
mw.loader.using(['mediawiki.notify','mediawiki.notification'],function(){
mw.notify(wgULS(
'系統檢測到您使用了客戶端繁簡轉換軟件,且此軟件對文本框中的內容進行了轉換。請關閉此軟件後重新打開編輯界面,再進行編輯。',
'系統檢測到您使用了用戶端繁簡轉換軟體,且此軟體對文字方塊中的內容進行了轉換。請關閉此軟體後重新打開編輯介面,再進行編輯。'
),{autoHide:false});
});
} else {
setTimeout(checkAntiConv, 1000);
}
}
};

setTimeout(checkAntiConv, 1000);
/* Main page hacks */
//</source>
if ( mw.config.get( 'wgIsMainPage' ) && mw.config.get( 'wgAction' ) == 'view' ) {
/* 维基百科语言列表 */
$( function () {
mw.util.addPortletLink(
'p-lang',
mw.util.getUrl( 'Wikipedia:维基百科语言列表' ),
wgULS( '维基百科语言列表', '維基百科語言列表' ),
'interwiki-completelist',
wgULS( '维基百科的完整各语言列表', '維基百科的完整各語言列表' )
);
} );
/* Remove red links */
$( '#mw-content-text a.new' ).contents().unwrap();
}
})(jQuery, mediaWiki);
});

/* Check for any client-side simplified/traditional Chinese conversion */
/* This routine must be placed here to make sure the field is inserted in time */
$('#antispam-container').append(
$('<input type="text" />').attr({
id: 'wpAntiConv',
value: '\u6c49\u6f22'
})
);

於 2016年4月12日 (二) 17:52 的最新修訂

//<source lang="javascript">

/*

== 編輯工具欄 ==
*/

/**
 * tip for custom edittools
 * 
 * Maintainers: fdcn@zh.wikipedia
 */
$( function(){
	//在提交新段落時,讓主題欄在特定情況下失效
	if(document.getElementById('no-new-title') && document.editform.wpSection.value=="new") {
		if(summaryinput=document.getElementById("wpSummary")) {
                        summaryinput.disabled=true;
                        summaryinput.value='';
                }
	}
});

( function( $, mw ) { $( function() {
    if ( $( '#editform input[name=wpSection]' ).val() === 'new' ) {
        if ( $( '#no-new-title' ).length ) {
            $( '#wpSummary' ).attr( 'disabled', true );
        }
        return;
    }
    $( '#wpSummaryLabel .mw-summary-preset' ).on( 'click', '.mw-summary-preset-item a', function( e ) {
        e.preventDefault();
        var $this = $( this ), summary = $( '#wpSummary' ).val();
        var $item = $this.parent( '.mw-summary-preset-item' );
        summary = summary.replace( /\s+$/g, '' );
        if ( summary != '' ) {
            summary += ' ';
        }
        summary += $item.attr( 'title' ) || $this.text();
        $this.replaceWith( $this.contents() );
        $( '#wpSummary' ).val( summary );
    } );
} ); } )( jQuery, mediaWiki );

/*

== 強制預覽 ==
[[mw:Manual:Force preview]]
*/

// -------------------------------------------------------------------------------
//  Force Preview  JavaScript code - Start
//
//  To allow any group to bypass being forced to preview, 
//  enter the group name in the permittedGroups array.
//  E.g.
//    var permittedGroups = [];                       // force everyone
//    var permittedGroups = [ "user"];                // permit logged-in users 
//    var permittedGroups = [ "sysop", "bureaucrat"]; // permit sysop, bureaucrat 
// -------------------------------------------------------------------------------
var permittedGroups = [ 'confirmed', 'autoconfirmed' ];
 
Array.prototype.intersects = function() {
	// --------------------------------------------------------
	//  Returns true if any element in the argument array
	//  is the same as an element in this array
	// --------------------------------------------------------
	if ( !arguments.length ) return false;

	var array2 = arguments[0];

	var len1 = this.length;
	var len2 = array2.length;
	if ( len2 == 0 ) return false;

	for ( var i = 0; i < len1; i++ ) {
		for ( var j = 0; j < len2; j++ ) {
			if ( this[i] === array2[j] ) return true;
		}
	}
	return false;
};
 
function forcePreview() {
	if ( mw.config.get( "wgAction" ) != "edit" ) return;
	if ( mw.config.get( "wgUserGroups" ).intersects( permittedGroups ) ) return;
	// Doesn't work correctly with live preview
	if ( mw.user.options.get( "uselivepreview" ) == "1" ) return;
	var saveButton = document.getElementById( "wpSave" );
	if ( !saveButton ) return;
	saveButton.disabled = true;
	saveButton.value = saveButton.value + wgULS( '(請先預覽)', '(請先預覽)' );
	saveButton.style.fontWeight = "normal";
	document.getElementById("wpPreview").style.fontWeight = "bold";
}

jQuery(document).ready( forcePreview );
// -----------------------------------------------------
//  Force Preview  JavaScript code - End
// -----------------------------------------------------

/*

== 取消修訂編輯摘要修正 ==
*/
/**
  fix edit summary prompt for undo
  this code fixes the fact that the undo function combined with the "no edit summary prompter" causes problems if leaving the edit summary unchanged
  this was added by [[:en:User:Deskana]], code by [[:en:User:Tra]]
*/
$ (function () {
	var autoSummary=document.getElementsByName('wpAutoSummary')[0];
	if (document.location.search.indexOf("undo=") != -1 && autoSummary)
	{ autoSummary.value=''; }
});

/*

== WP:DYKC編輯時取消編輯摘要空段落標示 ==
*/
$( function(){
	var $wpSummary=$("#editform #wpSummary"), $wpTextbox1=$("#editform #wpTextbox1");
	if($wpSummary.length==0 || $wpTextbox1.length==0) return;
	var wpSummary=$wpSummary.get(0), wpTextbox1=$wpTextbox1.get(0);
	var keyReg= /(?:\n|.)*\|\s*article\s*= *([\S ]*)(?:\n|.)*/m ;
	if(wpSummary.value.indexOf("  ")>=0) wpSummary.value="";
	if(mw.config.get("wgPageName")!="Wikipedia:新條目推薦/候選") return;
	if(wpSummary.value=="/"+"*  *"+"/ " && wpTextbox1.value.match(keyReg) ){}else return;
	var temp=wpTextbox1.value.replace(keyReg, '$1');
	if(!temp) return;
	wpSummary.value=wpSummary.defaultValue="\/"+"* "+temp+" *"+"\/ ";
});


/* Check for any client-side simplified/traditional Chinese conversion */
var checkAntiConv = function() {
    var $ac = $('#wpAntiConv');
    if ($ac.length && $ac.val() != '\u6c49\u6f22') {
        var text = $('#wpTextbox1').val();
        var section = $('input[name=wpSection]').val();
        var basetimestamp = $('input[name=wpEdittime]').val();
        var starttimestamp = $('input[name=wpStarttime]').val();
        $('#editform :input').attr({disabled:true,readOnly:true});
        mw.loader.using(['mediawiki.notify','mediawiki.notification'],function(){
            mw.notify(wgULS(
                '系統檢測到您使用了客戶端繁簡轉換軟件,且此軟件對文本框中的內容進行了轉換。請關閉此軟件後重新打開編輯界面,再進行編輯。',
                '系統檢測到您使用了用戶端繁簡轉換軟體,且此軟體對文字方塊中的內容進行了轉換。請關閉此軟體後重新打開編輯介面,再進行編輯。'
            ),{autoHide:false});
        });
    } else {
        setTimeout(checkAntiConv, 1000);
    }
};
setTimeout(checkAntiConv, 1000);
//</source>