/** Import module *************************************************************
*
* Description: Includes a raw wiki page as javascript or CSS,
* used for including user made modules.
* Maintainers: [[User:AzaToth]]
*/
importedScripts = {}; // object keeping track of included scripts, so a script ain't included twice
function importScript( page ) {
if( importedScripts[page] ) {
return;
}
importedScripts[page] = true;
var url = wgScriptPath
+ '/index.php?title='
+ encodeURIComponent( page.replace( ' ', '_' ) )
+ '&action=raw&ctype=text/javascript';
var scriptElem = document.createElement( 'script' );
scriptElem.setAttribute( 'src' , url );
scriptElem.setAttribute( 'type' , 'text/javascript' );
document.getElementsByTagName( 'head' )[0].appendChild( scriptElem );
}
function importStylesheet( page ) {
var sheet = '@import "'
+ wgScriptPath
+ '/index.php?title='
+ encodeURIComponent( page.replace( ' ', '_' ) )
+ '&action=raw&ctype=text/css";'
var styleElem = document.createElement( 'style' );
styleElem.setAttribute( 'type' , 'text/css' );
styleElem.appendChild( document.createTextNode( sheet ) );
document.getElementsByTagName( 'head' )[0].appendChild( styleElem );
}
/*
以下のスクリプトはパブリックドメインとします。
改変・再配布を含め自由にお使いいただけますが、自己責任でお願いします。
These scripts below are under public domain.
You can freely use, modify or redistribute, at your own risk.
*/
function createLink(href, text) {
var newLink = document.createElement('a');
newLink.href = href;
newLink.appendChild(document.createTextNode(text));
return newLink;
}
//「ナビゲーション」ボックスに「全てのログ」のリンクを追加する
function addLogNav() {
var refNav = document.getElementById('n-randompage');
if(!refNav) return;
var newNav = document.createElement('li');
newNav.id = 'n-log'
newNav.appendChild(createLink('/wiki/%E7%89%B9%E5%88%A5:Log','全てのログ' ));
newNav.id = 'n-uplog'
newNav.appendChild(createLink('/w/index.php?title=%E7%89%B9%E5%88%A5%3ALog&type=upload&user=&page=','アップロードログ' ));
refNav.parentNode.insertBefore(newNav, refNav);
}
function addlogtab()
{
// get title from URL
var u = location.href;
if(/[\?&]title=([^&]+)/.test(u)) u = RegExp.$1;
else if(/\/wiki\/([^\?]+)/.test(u)) u = RegExp.$1;
else return;
// insertion point of toolbox
var lit = document.getElementById('t-recentchangeslinked');
if(!lit) lit = document.getElementById('t-whatlinkshere');
// if not found, we're in special page
if(!lit) return;
// insertion point of actions tab
var act = document.getElementById('p-cactions');
act = act.getElementsByTagName('ul')[0];
// get namespace number
var ns = document.body.className.split(' ');
for(var i = 0; i < ns.length; ++i) {
var r = /^ns-([0-9]+)$/.exec(ns[i]);
if(r) { ns = parseInt(r[1]); break; }
}
if(typeof ns != 'number') return;
// User: or User_talk:
if(ns == 2 || ns == 3) {
// strip subpage
var user = decodeURI(u).replace(/^[^:]+:/, '').replace(/\/.*/, '');
// IP address
var m = /^\d+\.\d+\.\d+\.\d+$/.exec(user);
if(m) {
a = document.createElement('a');
a.appendChild(document.createTextNode('whois'));
a.setAttribute('href', 'http://linky.wikipedia.jp/whois?key=' + encodeURI(user));
a.setAttribute('title', 'whois query for ' + user);
li = document.createElement('li');
li.appendChild(a);
act.appendChild(li);
}
}
// Page log
a = document.createElement('a');
a.appendChild(document.createTextNode('ページのログ'));
a.setAttribute('href', '/wiki/Special:Log?page=' + u);
a.setAttribute('title', decodeURI(u));
li = document.createElement('li');
li.appendChild(a);
lit.parentNode.insertBefore(li, lit.nextSibling);
// Image: or Image_talk:
if((ns == 6 || ns == 7) && location.host != 'commons.wikimedia.org') {
var img = u.replace(/^[^:]+:/, (ns == 6 ? 'Image:' : 'Image_talk:'));
// link to commons
a = document.createElement('a');
a.appendChild(document.createTextNode('コモンズ'));
a.setAttribute('href', 'http://commons.wikimedia.org/wiki/' + img);
a.setAttribute('title', 'commons:' + decodeURI(img));
li = document.createElement('li');
li.appendChild(a);
act.appendChild(li);
}
}
$(addLogNav);
$(addlogtab);