差分

MediaWiki:Common.js

3,401 バイト追加2015年6月23日 (火) 03:20
/* ここに書いたスクリプトは全ての外装に反映されます */
typeof mw != 'undefined' && (function() {
/* mw に依存する部分の始まり */
/** 現在のURLから URLパラメータを取り出す **********
* [[en:MediaWiki:Common.js]] より。paramName : 取り出すパラメータの名前
*/
function window.getURLParamValue= function( paramName, url)
{
if (typeof (url) == 'undefined' || url === null) url = document.location.href;
if (m && m.length > 1) return decodeURIComponent(m[1]);
return null;
};
/** &withJS= URL parameter, &withCSS= URL parameter *******
// </div>
// </nowiki>An element with id=DisableRealTitle disables the function.
var window.disableRealTitle = 0; // users can disable this by making this true from their monobook.js
if (wgIsArticle) { // don't display the RealTitle when editing, since it is apparently inconsistent (doesn't show when editing sections, doesn't show when not previewing)
$(function() {
// similar to innerHTML, but only returns the text portions of the insides, excludes HTML
function window.pickUpText= function(aParentElement) {
var str = "";
return str;
};
/* Test if an element has a certain class **************************************
*/
var window.hasClass = (function () {
var reCache = {};
return function (element, className) {
})();
/** * Collapsible tables ********************************************************* * * * Description: Allows tables to be collapsed, showing only the header. See * [[Wikipedia:NavFrame]]. * * Maintainers: [[:en:User:R. Koot]] */
var window.autoCollapse = 2; var window.collapseCaption = "隠す"; var window.expandCaption = "表示";
function window.collapseTable= function ( tableIndex ) { var Button = document.getElementById( "'collapseButton" ' + tableIndex ); var Table = document.getElementById( "'collapsibleTable" ' + tableIndex );
if ( !Table || !Button ) { return false; }
var Rows = Table.rows; var i;
if ( Button.firstChild.data === collapseCaption ) { for ( var i = 1; i < Rows.length; i++ ) { Rows[i].style.display = "'none"'; } Button.firstChild.data = expandCaption; } else { for ( var i = 1; i < Rows.length; i++ ) { Rows[i].style.display = Rows[0].style.display; } Button.firstChild.data = collapseCaption; } };
function window.createCollapseButtons= function(){
var tableIndex = 0;
var NavigationBoxes = new Object(){}; var Tables = document.getElementsByTagName( "'table" ' ); var i; function handleButtonLink( index, e ) { window.collapseTable( index ); e.preventDefault(); }
for ( var i = 0; i < Tables.length; i++ ) { if ( hasClass$( Tables[i], ").hasClass( 'collapsible" ' ) ) {
/* only add button and increment count if there is a header row to work with */
var HeaderRow = Tables[i].getElementsByTagName( "'tr" ' )[0]; if (!HeaderRow) continue; var Header = HeaderRow.getElementsByTagName( "'th" ' )[0]; if (!Header) continue;
NavigationBoxes[ tableIndex ] = Tables[i];
Tables[i].setAttribute( "'id"', "'collapsibleTable" ' + tableIndex );
var Button = document.createElement( "'span" ' ); var ButtonLink = document.createElement( "'a" ' );
var ButtonText = document.createTextNode( collapseCaption );
Button.className = "'collapseButton"'; //* Styles are declared in Common.css*/
ButtonLink.style.color = Header.style.color;
ButtonLink.setAttribute( "'id"', "'collapseButton" ' + tableIndex ); ButtonLink.setAttribute( "'href"', "'#" ' ); addHandler$( ButtonLink, ").on( 'click"', new Function$.proxy( "evt"handleButtonLink, ButtonLink, "collapseTable(" + tableIndex + " ); return killEvt( evt );") );
ButtonLink.appendChild( ButtonText );
Button.appendChild( document.createTextNode( "'[" ' ) );
Button.appendChild( ButtonLink );
Button.appendChild( document.createTextNode( "']" ' ) );
Header.insertBefore( Button, Header.childNodes[0] firstChild );
tableIndex++;
}
}
for ( var i = 0; i < tableIndex; i++ ) { if ( hasClass$( NavigationBoxes[i], ").hasClass( 'collapsed" ' ) || ( tableIndex >= autoCollapse && hasClass$( NavigationBoxes[i], ").hasClass( 'autocollapse" ' ) ) ) { window.collapseTable( i );
}
else if ( hasClass$( NavigationBoxes[i], ").hasClass ( 'innercollapse" ' ) ) {
var element = NavigationBoxes[i];
while ((element = element.parentNode)) { if ( hasClass$( element, ").hasClass( 'outercollapse" ' ) ) { window.collapseTable ( i );
break;
}
}
}
};
$mw.hook( 'wikipage.content' ).add( createCollapseButtons );
/** Dynamic Navigation Bars (experimental) *************************************
// set up the words in your language
var window.NavigationBarHide = '[' + collapseCaption + ']'; var window.NavigationBarShow = '[' + expandCaption + ']';
// set up max count of Navigation Bars on page,
// if there are more, all will be hidden
var window.NavigationBarShowDefault = 0; // all bars will be hidden
// NavigationBarShowDefault = 1; // on pages with more than 1 bar all bars will be hidden
//var NavigationBarShowDefault = autoCollapse;
// Parameters:
// indexNavigationBar: the index of navigation bar to be toggled
function window.toggleNavigationBar= function(indexNavigationBar)
{
var NavToggle = document.getElementById("NavToggle" + indexNavigationBar);
NavToggle.firstChild.data = NavigationBarHide;
}
};
// adds show/hide-button to navigation bars
function window.createNavigationBarToggleButton= function()
{
var indexNavigationBar = 0;
}
};
$( createNavigationBarToggleButton );
* 無効化のフラグ変数。無効化は、利用者のユーザスクリプトで真に設定することでする。
*/
var window.disableTitleChecker = false;
/*
* 記事名チェッカによる処理を適用しない記事名のリスト (除外リスト)。
*/
var window.TitleChecker_exclude = [
// [名前空間番号, 項目名], ...
];
* ただし、処理が「許可」であるときは false。
*/
function window.TitleChecker_check= function(ns, title, body) {
var platform; // プラットフォームを識別する名称。
var is_redirect; // リダイレクトであるかどうか。
if (action == 0) return false;
return [action, reason, for_redirect];
}; /* * 記事名を検査した結果を表示する。 * 引数: * mark: 説明文などを挿入する場所のelement。 * action: 処理。 * reason: [[説明文, [ガイドライン等, ...]], ...] * for_redirect: リダイレクトの即時削除対象でありうるかどうか。 * 返値: * なし。 */window.TitleChecker_warn = function(mark, action, reason, for_redirect) { var esc = function(str) { var e = document.createElement('div'); e.appendChild(document.createTextNode(str)); return e.innerHTML; }; var wl = function(title) { title = title.replace(/_/g, ' '); return '<a href="/wiki/' + encodeURIComponent(title.replace(/ /g, '_')).replace(/%2F/g, '/').replace(/%3A/g, ':') + '" title="' + esc(title) + '">' + esc(arguments[1] || title) + '</a>'; };  var text = ''; text = text + '<p><strong>警告: このページの記事名の付け方は、' + '当ウィキペディアのガイドラインなどにそっていないかもしれません。' + '理由は以下のとおりです。</strong></p>'; if (reason) { text = text + '<ul>'; for ( var i = 0; i < reason.length; i++) { text = text + '<li>' + esc(reason[i][0]); if (reason[i][1]) { var rl = []; for ( var j = 0; j < reason[i][1].length; j++) { rl.push(wl(reason[i][1][j])); } text = text + '詳しくは、' + rl.join('、') + 'を参照してください。'; } text = text + '</li>'; } text = text + '</ul>'; } text = text + '<p>ガイドラインにそっていないときは、記事名の変更を検討してみてください。' + 'なお、記事名を変更したときは、' + wl('特別:Whatlinkshere/' + wgPageName, 'このページのリンク元') + 'を調べて、新しい記事へのリンクに変更するようにしてください。</p>' + '<p>記事名チェック機能の詳細は、' + wl('Help:記事名のチェック') + 'をご覧ください。</p>'; if (for_redirect && wgArticleId) text = text + '<p>編集中のページは' + wl('Wikipedia:リダイレクト', 'リダイレクト') + 'ですが、' + '即時削除に出せるかもしれません。' + 'リダイレクトの即時削除に出すことができるのは、以下のすべてが該当する場合です。</p><ul>' + '<li>項目名の書き誤りで、それが誰が見ても明らかに誤りだとわかる。</li>' + '<li>項目が有益な履歴を持っていない。</li>' + '<li>項目がどこからもリンクされていない。</li>' + '</ul><p>リダイレクトの即時削除についての詳細は、' + wl('Wikipedia:即時削除の方針')+'を参照してください。</p>';  var div = document.createElement('div'); div.innerHTML = text; mark.parentNode.insertBefore(div, mark.nextSibling);  return;};
/*
* なし。
*/
function window.TitleChecker= function() {
var dis = function() {
for(var i = 0; i < arguments.length; ++i) {
mark = document.getElementById('specialpages') ?
document.getElementById('topbar') :
getElementsByClassName$(document, 'h1', '.pagetitle')[0].nextSibling;
break;
default:
return;
};
/*
/* Internet Explorer に対してのみ適用 */
var window.prof = $.client.profile();
if (prof.name == 'msie' && prof.versionBase == '6') {
// PNGアルファチャンネルの透過処理
// wikitableが崩れる問題への対処
mw.loader.load(mw.config.get("wgServer") + mw.config.get("wgScript") + "?action=raw&ctype=text/javascript&title=" + mw.util.wikiUrlencode("MediaWiki:Common.js/IE60TableFixes.js"), "text/javascript");
}
if (prof.name == 'msie') {
mw.loader.load(mw.config.get("wgServer") + mw.config.get("wgScript") + "?action=raw&ctype=text/javascript&title=" + mw.util.wikiUrlencode("MediaWiki:Common.js/IEFixes.js"), "text/javascript");
}
for (var i = 0; i < lis.length; i++) {
var li = lis[i];
var className = li.className.match(/interwiki-[-\w]+/);
// only links with a corresponding Link_FA/GA template are interesting
if (document.getElementById(li.className + '-fa')&& li.className.indexOf('badge-featuredarticle') === -1) {
li.className += ' FA';
li.title = linkFA_description;
continue;
}
if (document.getElementById(li.className + '-ga')&& li.className.indexOf('badge-goodarticle') === -1) {
li.className += ' GA';
li.title = linkGA_description;
*/
function window.modifyEditsection= function(){
// メッセージのセットアップ
var messages = {};
var heading = document.getElementById('firstHeading') // simple, chick, vector, myskin, modern, monobook
|| getElementsByClassName$(document, 'h1', '.pagetitle')[0];
// standard, cologneblue, nostalgia
/* || document.getElementsByTagName('h1')[0] */; // others - フェールセーフ用
var edits = getElementsByClassName$(document, 'span', '.editsection');
// editsection が存在しなければ何もしない。
if(! messages[wgUserLanguage]['historyTitle']){
messages[wgUserLanguage]['historyTitle'] = ca('history');
}
if(! messages[wgUserLanguage]['watchTitle'] && wgAjaxWatch && wgAjaxWatch['watchMsg']){
messages[wgUserLanguage]['watchTitle'] = wgAjaxWatch['watchMsg'].toLowerCase();
}
expanded[transUri] = level;
var section = getElementsByClassName$(parent, 'span', '.mw-headline', parent)[0].innerHTML
.replace(/^(\s|(&nbsp;))*/, '').replace(/(\s|(&nbsp;))*$/, '');
var transTitle = a.title;
var sectionId = null;
var headline = getElementsByClassName$(parent, 'span', '.mw-headline', parent);
if(headline){
headline = headline[0];
edits[i].appendChild(extensions);
}
};
if( (wgAction == 'view' || wgAction == 'purge') && wgNamespaceNumber >= 0 ){
// カテゴリ名と表示テンプレートの対応テーブル。名前空間は書かない。
var window.CATEGORY_EDITINTRO_TABLE = {
'存命人物': 'BLP editintro' ,
'学校記事': '学校記事 editintro' /* ,
};
function window.addEditIntro= function(templateName) {
var editURI = wgScript + '?title=' + encodeTitle(wgPageName) + '&action=edit';
return encodeURIComponent(title.replace(/ /g, '_')).replace(/%2F/gi, '/').replace(/%3A/gi, ':');
}
};
if (wgNamespaceNumber == 0) {
*/
function window.UsernameReplace= function() {
if(window.disableUsernameReplace || wgUserName == null) return;
var un = getElementsByClassName$(document, 'span', '.insertusername');
for (var i=0;i<un.length;i++) {
var d = 0;
}
}
};
$(UsernameReplace);
/* mw に依存する部分の終わり */
}());
// </source>
ビューロクラット管理者
78
回編集