MediaWiki:Common.js: Różnice pomiędzy wersjami
Przejdź do nawigacji
Przejdź do wyszukiwania
| Linia 1: | Linia 1: | ||
| − | + | /* Deprecated functions now in the central mw software */ | |
| − | + | ||
| − | + | window.getParamValue = mw.util.getParamValue; | |
| − | + | ||
| − | + | /** | |
| − | ); | + | * Scripts imported from wikisource.org |
| + | */ | ||
| + | |||
| + | // Messages are configurable here | ||
| + | self.ws_messages = { | ||
| + | 'optlist':'Display options', | ||
| + | 'hide_page_numbers':'Hide page links', | ||
| + | 'show_page_numbers':'Show page links', | ||
| + | 'layout':'Layout', | ||
| + | 'author':'Author', | ||
| + | 'translator':'Translator', | ||
| + | 'editor':'Editor', | ||
| + | 'publisher':'Publisher', | ||
| + | 'place':'Place', | ||
| + | 'volume':'Volume', | ||
| + | 'school':'School', | ||
| + | 'book':'Book', | ||
| + | 'collection':'Collection', | ||
| + | 'journal':'Journal or magazine', | ||
| + | 'phdthesis':'Thesis, report', | ||
| + | 'dictionary':'Dictionary', | ||
| + | 'progress':'Progress', | ||
| + | 'progress_T':'Done', | ||
| + | 'progress_V':'To be validated', | ||
| + | 'progress_C':'To be proofread', | ||
| + | 'progress_MS':'Ready for Match & Split', | ||
| + | 'progress_OCR':'Needs an OCR text layer', | ||
| + | 'progress_L':'Source file is incorrect (missing pages, unordered pages, etc)', | ||
| + | '▲':'Return to the top of the page.', | ||
| + | |||
| + | 'corr_list':"List of corrections performed on this page" , | ||
| + | 'corr_link':"Corrections" , | ||
| + | 'corr_one':"One typo </a> has been corrected." , | ||
| + | 'corr_many':" typos</a> have been corrected." , | ||
| + | 'corr_close':"Close." , | ||
| + | |||
| + | 'iwtrans':'Its text comes from', | ||
| + | 'iwtrans2':'Its text comes from other Wikisource subdomains.' | ||
| + | }; | ||
| + | |||
| + | // Dynamic layouts | ||
| + | if ( !self.ws_layouts ) { | ||
| + | self.ws_layouts = {}; | ||
} | } | ||
| − | /* | + | self.ws_layouts['Layout 1'] = { |
| − | /* | + | '#text-wrap':"", |
| + | '#text-container':"" , | ||
| + | '#text':"", | ||
| + | '.sidenote-right':"float:right;margin:0.5em;padding:3px;border:solid 1px gray;max-width:9em;text-indent:0em;text-align:left;", | ||
| + | '.sidenote-left':"float:left;margin:0.5em;padding:3px;border:solid 1px gray;max-width:9em;text-indent:0em;text-align:left;", | ||
| + | '.editsection':"display:none", | ||
| + | '#headertemplate':"" | ||
| + | }; | ||
| + | self.ws_layouts['Layout 2'] = { | ||
| + | '#text-wrap':"position:relative;margin-left:3em;margin-right:3em;", | ||
| + | '#text-container':"width:36em;margin:0px auto;font-family:Georgia,serif;" , | ||
| + | '#text':"text-align:justify;", | ||
| + | '.sidenote-right':"position:absolute; left:37em;width:16em;text-indent:0em;text-align:left;", | ||
| + | '.sidenote-left':"position:absolute; right:37em;width:16em;text-indent:0em;text-align:right;", | ||
| + | '.editsection':"display:none", | ||
| + | '#headertemplate':"" | ||
| + | }; | ||
| + | self.ws_layouts['Layout 3'] = { | ||
| + | '#text-wrap':"margin-left:3em", | ||
| + | '#text-container':"position:relative; min-width:60em; float:left; width:100%; margin-right:-23em;" , | ||
| + | '#text':"text-align:justify;margin-right:23em; text-indent:0em; padding-left:0px; padding-right:0px;width:auto; position:relative;", | ||
| + | '.sidenote-right':"position:absolute; right:-10em; width:9em; background-color:#eeeeee;text-indent:0em;text-align:left;", | ||
| + | '.sidenote-left':"position:absolute; right:-10em; width:9em; background-color:#eeeeee;text-indent:0em;text-align:left;", | ||
| + | '.editsection':"display:none", | ||
| + | '#headertemplate':"position:absolute; top:0em; right:-23em; width:21em;float:right; text-align:left;" | ||
| + | }; | ||
| + | |||
| + | self.proofreadpage_add_container = true; | ||
| + | |||
| + | importScriptURI('//wikisource.org/w/index.php?title=MediaWiki:Base.js&action=raw&ctype=text/javascript'); | ||
| + | /*importScriptURI('//wikisource.org/w/index.php?title=MediaWiki:OCR.js&action=raw&ctype=text/javascript');*/ /*hasn't functioned in a long time */ | ||
| + | importScriptURI('//wikisource.org/w/index.php?title=MediaWiki:DisplayFooter.js&action=raw&ctype=text/javascript'); | ||
| + | importScriptURI('//wikisource.org/w/index.php?title=MediaWiki:PageNumbers.js&action=raw&ctype=text/javascript'); | ||
| + | importScriptURI('//wikisource.org/w/index.php?title=MediaWiki:Corrections.js&action=raw&ctype=text/javascript'); | ||
| + | importScriptURI('//wikisource.org/w/index.php?title=MediaWiki:IndexForm.js&action=raw&ctype=text/javascript'); | ||
| + | importScriptURI('//wikisource.org/w/index.php?title=MediaWiki:Dictionary.js&action=raw&ctype=text/javascript'); | ||
| + | importScriptURI('//wikisource.org/w/index.php?title=MediaWiki:InterWikiTransclusion.js&action=raw&ctype=text/javascript'); | ||
| + | |||
| + | // Mouse wheel zoom should work now for most browsers. | ||
| + | // If it does not work for you, set this to true in your javascript. | ||
| + | self.proofreadpage_disable_wheelzoom = false; | ||
| + | |||
| + | |||
| + | /** | ||
| + | * Allow descriptive labels next to sidebar language links using {{interwiki-info}} | ||
| + | * by [[user:ThomasV]] | ||
| + | */ | ||
| + | function interwikiExtra() { | ||
| + | // iterate over all <span>-elements | ||
| + | for(var i=0; a=document.getElementsByTagName('span')[i]; i++) { | ||
| + | // if found a linkInfo span | ||
| + | if(a.className == 'interwiki-info') { | ||
| + | // iterate over all <li>-elements | ||
| + | var count=0; | ||
| + | for(var j=0; b=document.getElementsByTagName('li')[j]; j++) { | ||
| + | if(b.className == 'interwiki-' + a.id) { | ||
| + | b.innerHTML = b.innerHTML + ' ' + a.title; | ||
| + | if(a.title == '(vo)') { | ||
| + | b.title = 'Original Version'; | ||
| + | } | ||
| + | } | ||
| + | else if(b.className == 'interwiki-' + a.id.substr(0, a.id.length-1)) { | ||
| + | count++; | ||
| + | if(a.id.charAt(a.id.length-1) == count) { | ||
| + | b.innerHTML = b.innerHTML + ' ' + a.title; | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | addOnloadHook(interwikiExtra); | ||
| + | |||
| + | |||
| + | /** | ||
| + | * Quality indicators on "article" tab | ||
| + | * by [[user:ThomasV]] | ||
| + | */ | ||
| + | // Return src for icon given percentage | ||
| + | function icon_src(t){ | ||
| + | var src='//upload.wikimedia.org/wikipedia/commons/'; | ||
| + | switch(t){ | ||
| + | case '0%': src+='8/8f/00'; break; | ||
| + | case '25%': src+='5/5b/25'; break; | ||
| + | case '50%': src+='3/3a/50'; break; | ||
| + | case '75%': src+='c/cd/75'; break; | ||
| + | case '100%': src+='6/64/100'; break; | ||
| + | } | ||
| + | return src + '%25.png'; | ||
| + | } | ||
| + | |||
| + | // add indicator | ||
| + | function pageQuality() { | ||
| + | var a = document.getElementById('ca-nstab-main'); | ||
| + | if(!a) return; | ||
| + | |||
| + | var pr_index = document.getElementById('pr_index'); | ||
| + | if(pr_index) return; | ||
| + | |||
| + | var q = document.getElementById('textquality'); | ||
| + | var new_img; | ||
| + | if(q) { | ||
| + | new_img = document.createElement('img'); | ||
| + | new_img.setAttribute('src', icon_src(q.className)); | ||
| + | a.firstChild.appendChild(new_img); | ||
| + | } | ||
| + | |||
| + | for(var i=0; spanElem = document.getElementsByTagName('span')[i]; i++) { | ||
| + | if (spanElem.className == 'pagequality') { | ||
| + | new_img = document.createElement('img'); | ||
| + | new_img.setAttribute('src', icon_src(spanElem.title)); | ||
| + | |||
| + | if(wgCanonicalNamespace == 'Page') { | ||
| + | a.firstChild.appendChild(new_img); | ||
| + | } | ||
| + | else { | ||
| + | s1 = spanElem.parentNode.previousSibling; | ||
| + | opttext = s1.firstChild.firstChild; | ||
| + | img = opttext.firstChild.nextSibling.nextSibling.nextSibling; | ||
| + | next = img.nextSibling; | ||
| + | opttext.removeChild(img); | ||
| + | opttext.insertBefore(new_img,next); | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | addOnloadHook(pageQuality); | ||
| + | |||
| + | // Add link to the extension [[user:sanbeg]] | ||
| + | function pr_add_quality_buttons_link(){ | ||
| + | if(typeof proofreadPageMessageStatus == 'undefined') return; | ||
| + | if( self.proofreadpage_no_quality_buttons ) return; | ||
| + | var ig = document.getElementById("wpWatchthis"); | ||
| + | if( !ig ) return; | ||
| + | var f = document.createElement("span"); | ||
| + | f.innerHTML = ' (<a href="/wiki/Help:Page Status">help</a>)'; | ||
| + | |||
| + | ig.parentNode.insertBefore(f,ig.nextSibling.nextSibling.nextSibling.nextSibling); | ||
| + | } | ||
| + | addOnloadHook(pr_add_quality_buttons_link); | ||
| + | |||
| + | |||
| + | /** | ||
| + | * Add arrows on sidebar to compare current page to interlanguage link'd page | ||
| + | * by [[user:Pathoschild]], based on older script by unknown | ||
| + | */ | ||
| + | function BilingualLink() { | ||
| + | if ( document.getElementById('p-lang') ) { | ||
| + | // get list of links | ||
| + | var biboxes = document.getElementById('p-lang').getElementsByTagName('li'); | ||
| + | |||
| + | // iterate over links | ||
| + | for(var i=0; i<biboxes.length; i++) { | ||
| + | // get link | ||
| + | var bilink = biboxes[i].getElementsByTagName('a')[0]; | ||
| + | |||
| + | // create new URL | ||
| + | var bilang = bilink.getAttribute('href').match(/\/\/([^\.]+)\.wikisource/)[1]; | ||
| + | var bilanglink = mw.util.wikiGetlink( wgPageName ) + '?match=' + bilang; | ||
| + | |||
| + | // create link | ||
| + | var bianchor = document.createElement('a'); | ||
| + | bianchor.setAttribute('href',bilanglink); | ||
| + | bianchor.setAttribute('title','Compare this page with the '+bilang+' version.'); | ||
| + | bianchor.appendChild(document.createTextNode(' ⇔')); | ||
| + | |||
| + | // add link | ||
| + | biboxes[i].appendChild(bianchor); | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | addOnloadHook(BilingualLink); | ||
| + | |||
| + | /** | ||
| + | * Allows extra script to run in Special:Watchlist — addition of announcements | ||
| + | * script allows users to dismiss Mediawiki:watchlist-announcements, as per sitenotice | ||
| + | * user:billinghurst 20100522, as hacked from WP script | ||
| + | */ | ||
| + | if ( mw.config.get('wgCanonicalSpecialPageName') == 'Watchlist' ) { | ||
| + | importScript('MediaWiki:Common.js/watchlist.js'); | ||
| + | } | ||
| + | |||
| + | // (should be redundant with the implementation of protocol relative urls (201101004); if not reactivated can be cleansed by end of 2011 | ||
| + | // Script to rewrite external links to other Wikimedia projects to | ||
| + | // use the secure server when already browsing from https://secure.wikimedia.org | ||
| + | // | ||
| + | //if ( mw.config.get('wgServer') == 'https://secure.wikimedia.org' ) { | ||
| + | // mw.loader.load('//en.wikipedia.org/w/index.php?title=MediaWiki:Common.js/secure.js&action=raw&ctype=text/javascript'); | ||
| + | //} | ||
| + | |||
| + | /** Collapsible tables ********************************************************* | ||
| + | * | ||
| + | * Description: Allows tables to be collapsed, showing only the header. See | ||
| + | * [[w:Wikipedia:NavFrame]]. | ||
| + | * Maintainers: [[w:User:R. Koot]] | ||
| + | */ | ||
| + | |||
| + | var autoCollapse = 2; | ||
| + | var collapseCaption = "hide"; | ||
| + | var expandCaption = "show"; | ||
| + | |||
| + | function collapseTable( tableIndex ){ | ||
| + | var Button = document.getElementById( "collapseButton" + tableIndex ); | ||
| + | var Table = document.getElementById( "collapsibleTable" + tableIndex ); | ||
| + | |||
| + | if ( !Table || !Button ) { | ||
| + | return false; | ||
| + | } | ||
| + | |||
| + | var Rows = Table.rows; | ||
| + | |||
| + | 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 createCollapseButtons(){ | ||
| + | var tableIndex = 0; | ||
| + | var NavigationBoxes = {}; | ||
| + | var Tables = document.getElementsByTagName( "table" ); | ||
| + | |||
| + | for ( var i = 0; i < Tables.length; i++ ) { | ||
| + | if ( hasClass( Tables[i], "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.style.styleFloat = "right"; // | ||
| + | Button.style.cssFloat = "right"; // REMOVE THESE LINES | ||
| + | Button.style.fontWeight = "normal"; // ON 10 FEBRUARY 2009 | ||
| + | Button.style.textAlign = "right"; // | ||
| + | Button.style.width = "6em"; // | ||
| − | // | + | Button.className = "collapseButton"; //Styles are declared in Common.css |
| − | // var | + | |
| − | var | + | ButtonLink.style.color = Header.style.color; |
| − | + | ButtonLink.setAttribute( "id", "collapseButton" + tableIndex ); | |
| − | // | + | ButtonLink.setAttribute( "href", "javascript:collapseTable(" + tableIndex + ");" ); |
| − | + | ButtonLink.appendChild( ButtonText ); | |
| − | /* | + | |
| − | // | + | Button.appendChild( document.createTextNode( "[" ) ); |
| − | var | + | Button.appendChild( ButtonLink ); |
| − | + | Button.appendChild( document.createTextNode( "]" ) ); | |
| − | // | + | |
| − | + | Header.insertBefore( Button, Header.childNodes[0] ); | |
| + | tableIndex++; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | for ( var i = 0; i < tableIndex; i++ ) { | ||
| + | if ( hasClass( NavigationBoxes[i], "collapsed" ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], "autocollapse" ) ) ) { | ||
| + | collapseTable( i ); | ||
| + | } | ||
| + | else if ( hasClass( NavigationBoxes[i], "innercollapse" ) ) { | ||
| + | var element = NavigationBoxes[i]; | ||
| + | while (element = element.parentNode) { | ||
| + | if ( hasClass( element, "outercollapse" ) ) { | ||
| + | collapseTable ( i ); | ||
| + | break; | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | addOnloadHook( createCollapseButtons ); | ||
| + | |||
| + | |||
| + | /** Dynamic Navigation Bars (experimental) ************************************* | ||
| + | * | ||
| + | * Description: See [[w:Wikipedia:NavFrame]]. | ||
| + | * Maintainers: UNMAINTAINED | ||
| + | */ | ||
| + | |||
| + | // set up the words in your language | ||
| + | var NavigationBarHide = '[' + collapseCaption + ']'; | ||
| + | var NavigationBarShow = '[' + expandCaption + ']'; | ||
| + | |||
| + | // shows and hides content and picture (if available) of navigation bars | ||
| + | // Parameters: | ||
| + | // indexNavigationBar: the index of navigation bar to be toggled | ||
| + | function toggleNavigationBar(indexNavigationBar){ | ||
| + | var NavToggle = document.getElementById("NavToggle" + indexNavigationBar); | ||
| + | var NavFrame = document.getElementById("NavFrame" + indexNavigationBar); | ||
| + | |||
| + | if (!NavFrame || !NavToggle) { | ||
| + | return false; | ||
| + | } | ||
| + | |||
| + | // if shown now | ||
| + | if (NavToggle.firstChild.data == NavigationBarHide) { | ||
| + | for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) { | ||
| + | if ( hasClass( NavChild, 'NavPic' ) ) { | ||
| + | NavChild.style.display = 'none'; | ||
| + | } | ||
| + | if ( hasClass( NavChild, 'NavContent') ) { | ||
| + | NavChild.style.display = 'none'; | ||
| + | } | ||
| + | } | ||
| + | NavToggle.firstChild.data = NavigationBarShow; | ||
| + | |||
| + | // if hidden now | ||
| + | } else if (NavToggle.firstChild.data == NavigationBarShow) { | ||
| + | for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) { | ||
| + | if (hasClass(NavChild, 'NavPic')) { | ||
| + | NavChild.style.display = 'block'; | ||
| + | } | ||
| + | if (hasClass(NavChild, 'NavContent')) { | ||
| + | NavChild.style.display = 'block'; | ||
| + | } | ||
| + | } | ||
| + | NavToggle.firstChild.data = NavigationBarHide; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | // adds show/hide-button to navigation bars | ||
| + | function createNavigationBarToggleButton(){ | ||
| + | var indexNavigationBar = 0; | ||
| + | // iterate over all < div >-elements | ||
| + | var divs = document.getElementsByTagName("div"); | ||
| + | for (var i = 0; NavFrame = divs[i]; i++) { | ||
| + | // if found a navigation bar | ||
| + | if (hasClass(NavFrame, "NavFrame")) { | ||
| + | |||
| + | indexNavigationBar++; | ||
| + | var NavToggle = document.createElement("a"); | ||
| + | NavToggle.className = 'NavToggle'; | ||
| + | NavToggle.setAttribute('id', 'NavToggle' + indexNavigationBar); | ||
| + | NavToggle.setAttribute('href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');'); | ||
| + | |||
| + | var isCollapsed = hasClass( NavFrame, "collapsed" ); | ||
| + | /* | ||
| + | * Check if any children are already hidden. This loop is here for backwards compatibility: | ||
| + | * the old way of making NavFrames start out collapsed was to manually add style="display:none" | ||
| + | * to all the NavPic/NavContent elements. Since this was bad for accessibility (no way to make | ||
| + | * the content visible without JavaScript support), the new recommended way is to add the class | ||
| + | * "collapsed" to the NavFrame itself, just like with collapsible tables. | ||
| + | */ | ||
| + | for (var NavChild = NavFrame.firstChild; NavChild != null && !isCollapsed; NavChild = NavChild.nextSibling) { | ||
| + | if ( hasClass( NavChild, 'NavPic' ) || hasClass( NavChild, 'NavContent' ) ) { | ||
| + | if ( NavChild.style.display == 'none' ) { | ||
| + | isCollapsed = true; | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | if (isCollapsed) { | ||
| + | for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) { | ||
| + | if ( hasClass( NavChild, 'NavPic' ) || hasClass( NavChild, 'NavContent' ) ) { | ||
| + | NavChild.style.display = 'none'; | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | var NavToggleText = document.createTextNode(isCollapsed ? NavigationBarShow : NavigationBarHide); | ||
| + | NavToggle.appendChild(NavToggleText); | ||
| + | |||
| + | // Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked) | ||
| + | for(var j=0; j < NavFrame.childNodes.length; j++) { | ||
| + | if (hasClass(NavFrame.childNodes[j], "NavHead")) { | ||
| + | NavFrame.childNodes[j].appendChild(NavToggle); | ||
| + | } | ||
| + | } | ||
| + | NavFrame.setAttribute('id', 'NavFrame' + indexNavigationBar); | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | |||
| + | addOnloadHook( createNavigationBarToggleButton ); | ||
| + | |||
| + | |||
| + | /** | ||
| + | * Description: Uses regular expressions and caching for better performance to determine if an element has a class. | ||
| + | * original authors (stolen from wikipedia): w:User:Mike Dillon, w:User:R. Koot, w:User:SG | ||
| + | */ | ||
| + | var hasClass = (function () { | ||
| + | var reCache = {}; | ||
| + | return function (element, className) { | ||
| + | return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className); | ||
| + | }; | ||
| + | })(); | ||
| + | |||
| + | /* | ||
| + | * port from [[:he:mediawiki:common.js]] for [[mediawiki:edittools]] -Steve | ||
| + | */ | ||
| + | /* פונקציה שמשמשת לאיפשור ניקוד ב[[מדיה ויקי:edittools]] */ | ||
| + | function nikud(){ | ||
| + | if (document.getElementById('edit-templates')!=null){ | ||
| + | for(var i=0; a = document.getElementsByTagName("span")[i]; i++) { | ||
| + | if(a.className == "nikud") { | ||
| + | a.onclick=function(){insertTags('', this.title, '');return false;}; | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | addOnloadHook(nikud); | ||
| + | |||
| + | |||
| + | /** | ||
| + | * withJS | ||
| + | * | ||
| + | * Allow to load custom scripts from the MediaWiki namespace without | ||
| + | * editing [[Special:Mypage/common.js]] | ||
| + | * | ||
| + | * Maintainer: [[User:Platonides]], [[User:Lupo]] | ||
| + | */ | ||
| + | var extraJS = mw.util.getParamValue('withJS'); | ||
| + | // Leave here for backwards compatibility | ||
| + | (function (extraJS) { | ||
| + | if (!extraJS) { | ||
| + | return; | ||
| + | } | ||
| + | if (extraJS.match(/^MediaWiki:[^&<>=%#]*\.js$/)) { | ||
| + | // Disallow some characters in file name | ||
| + | importScript(extraJS); | ||
| + | } else { | ||
| + | // Dont use alert but the jsMsg system. Run jsMsg only once the DOM is ready. | ||
| + | $(function () { | ||
| + | jsMsg(extraJS + ' javascript not allowed to be loaded.', 'error'); | ||
| + | }); | ||
| + | } | ||
| + | })(extraJS); | ||
| + | |||
| + | |||
| + | /** | ||
| + | * Icons on the top right of the article. | ||
| + | * See also CSS | ||
| + | * | ||
| + | * @source: http://www.mediawiki.org/wiki/Snippets/Top_icons | ||
| + | * @rev: 2 | ||
| + | */ | ||
| + | jQuery( document ).ready( function( $ ) { | ||
| + | $( '.Top_icon_raw' ) | ||
| + | .removeClass( 'Top_icon_raw' ) | ||
| + | .addClass( 'Top_icon_dynamic' ) | ||
| + | .prependTo( '#firstHeading' ); | ||
| + | } ); | ||
| + | |||
| + | /*Script to allow language links to Old Wikisource (http://wikisource.org) */ | ||
| + | importScriptURI('//en.wikisource.org/w/index.php?title=User:Doug/oldws.js&action=raw&ctype=text/javascript'); | ||
Wersja z 23:42, 30 paź 2011
/* Deprecated functions now in the central mw software */
window.getParamValue = mw.util.getParamValue;
/**
* Scripts imported from wikisource.org
*/
// Messages are configurable here
self.ws_messages = {
'optlist':'Display options',
'hide_page_numbers':'Hide page links',
'show_page_numbers':'Show page links',
'layout':'Layout',
'author':'Author',
'translator':'Translator',
'editor':'Editor',
'publisher':'Publisher',
'place':'Place',
'volume':'Volume',
'school':'School',
'book':'Book',
'collection':'Collection',
'journal':'Journal or magazine',
'phdthesis':'Thesis, report',
'dictionary':'Dictionary',
'progress':'Progress',
'progress_T':'Done',
'progress_V':'To be validated',
'progress_C':'To be proofread',
'progress_MS':'Ready for Match & Split',
'progress_OCR':'Needs an OCR text layer',
'progress_L':'Source file is incorrect (missing pages, unordered pages, etc)',
'▲':'Return to the top of the page.',
'corr_list':"List of corrections performed on this page" ,
'corr_link':"Corrections" ,
'corr_one':"One typo </a> has been corrected." ,
'corr_many':" typos</a> have been corrected." ,
'corr_close':"Close." ,
'iwtrans':'Its text comes from',
'iwtrans2':'Its text comes from other Wikisource subdomains.'
};
// Dynamic layouts
if ( !self.ws_layouts ) {
self.ws_layouts = {};
}
self.ws_layouts['Layout 1'] = {
'#text-wrap':"",
'#text-container':"" ,
'#text':"",
'.sidenote-right':"float:right;margin:0.5em;padding:3px;border:solid 1px gray;max-width:9em;text-indent:0em;text-align:left;",
'.sidenote-left':"float:left;margin:0.5em;padding:3px;border:solid 1px gray;max-width:9em;text-indent:0em;text-align:left;",
'.editsection':"display:none",
'#headertemplate':""
};
self.ws_layouts['Layout 2'] = {
'#text-wrap':"position:relative;margin-left:3em;margin-right:3em;",
'#text-container':"width:36em;margin:0px auto;font-family:Georgia,serif;" ,
'#text':"text-align:justify;",
'.sidenote-right':"position:absolute; left:37em;width:16em;text-indent:0em;text-align:left;",
'.sidenote-left':"position:absolute; right:37em;width:16em;text-indent:0em;text-align:right;",
'.editsection':"display:none",
'#headertemplate':""
};
self.ws_layouts['Layout 3'] = {
'#text-wrap':"margin-left:3em",
'#text-container':"position:relative; min-width:60em; float:left; width:100%; margin-right:-23em;" ,
'#text':"text-align:justify;margin-right:23em; text-indent:0em; padding-left:0px; padding-right:0px;width:auto; position:relative;",
'.sidenote-right':"position:absolute; right:-10em; width:9em; background-color:#eeeeee;text-indent:0em;text-align:left;",
'.sidenote-left':"position:absolute; right:-10em; width:9em; background-color:#eeeeee;text-indent:0em;text-align:left;",
'.editsection':"display:none",
'#headertemplate':"position:absolute; top:0em; right:-23em; width:21em;float:right; text-align:left;"
};
self.proofreadpage_add_container = true;
importScriptURI('//wikisource.org/w/index.php?title=MediaWiki:Base.js&action=raw&ctype=text/javascript');
/*importScriptURI('//wikisource.org/w/index.php?title=MediaWiki:OCR.js&action=raw&ctype=text/javascript');*/ /*hasn't functioned in a long time */
importScriptURI('//wikisource.org/w/index.php?title=MediaWiki:DisplayFooter.js&action=raw&ctype=text/javascript');
importScriptURI('//wikisource.org/w/index.php?title=MediaWiki:PageNumbers.js&action=raw&ctype=text/javascript');
importScriptURI('//wikisource.org/w/index.php?title=MediaWiki:Corrections.js&action=raw&ctype=text/javascript');
importScriptURI('//wikisource.org/w/index.php?title=MediaWiki:IndexForm.js&action=raw&ctype=text/javascript');
importScriptURI('//wikisource.org/w/index.php?title=MediaWiki:Dictionary.js&action=raw&ctype=text/javascript');
importScriptURI('//wikisource.org/w/index.php?title=MediaWiki:InterWikiTransclusion.js&action=raw&ctype=text/javascript');
// Mouse wheel zoom should work now for most browsers.
// If it does not work for you, set this to true in your javascript.
self.proofreadpage_disable_wheelzoom = false;
/**
* Allow descriptive labels next to sidebar language links using {{interwiki-info}}
* by [[user:ThomasV]]
*/
function interwikiExtra() {
// iterate over all <span>-elements
for(var i=0; a=document.getElementsByTagName('span')[i]; i++) {
// if found a linkInfo span
if(a.className == 'interwiki-info') {
// iterate over all <li>-elements
var count=0;
for(var j=0; b=document.getElementsByTagName('li')[j]; j++) {
if(b.className == 'interwiki-' + a.id) {
b.innerHTML = b.innerHTML + ' ' + a.title;
if(a.title == '(vo)') {
b.title = 'Original Version';
}
}
else if(b.className == 'interwiki-' + a.id.substr(0, a.id.length-1)) {
count++;
if(a.id.charAt(a.id.length-1) == count) {
b.innerHTML = b.innerHTML + ' ' + a.title;
}
}
}
}
}
}
addOnloadHook(interwikiExtra);
/**
* Quality indicators on "article" tab
* by [[user:ThomasV]]
*/
// Return src for icon given percentage
function icon_src(t){
var src='//upload.wikimedia.org/wikipedia/commons/';
switch(t){
case '0%': src+='8/8f/00'; break;
case '25%': src+='5/5b/25'; break;
case '50%': src+='3/3a/50'; break;
case '75%': src+='c/cd/75'; break;
case '100%': src+='6/64/100'; break;
}
return src + '%25.png';
}
// add indicator
function pageQuality() {
var a = document.getElementById('ca-nstab-main');
if(!a) return;
var pr_index = document.getElementById('pr_index');
if(pr_index) return;
var q = document.getElementById('textquality');
var new_img;
if(q) {
new_img = document.createElement('img');
new_img.setAttribute('src', icon_src(q.className));
a.firstChild.appendChild(new_img);
}
for(var i=0; spanElem = document.getElementsByTagName('span')[i]; i++) {
if (spanElem.className == 'pagequality') {
new_img = document.createElement('img');
new_img.setAttribute('src', icon_src(spanElem.title));
if(wgCanonicalNamespace == 'Page') {
a.firstChild.appendChild(new_img);
}
else {
s1 = spanElem.parentNode.previousSibling;
opttext = s1.firstChild.firstChild;
img = opttext.firstChild.nextSibling.nextSibling.nextSibling;
next = img.nextSibling;
opttext.removeChild(img);
opttext.insertBefore(new_img,next);
}
}
}
}
addOnloadHook(pageQuality);
// Add link to the extension [[user:sanbeg]]
function pr_add_quality_buttons_link(){
if(typeof proofreadPageMessageStatus == 'undefined') return;
if( self.proofreadpage_no_quality_buttons ) return;
var ig = document.getElementById("wpWatchthis");
if( !ig ) return;
var f = document.createElement("span");
f.innerHTML = ' (<a href="/wiki/Help:Page Status">help</a>)';
ig.parentNode.insertBefore(f,ig.nextSibling.nextSibling.nextSibling.nextSibling);
}
addOnloadHook(pr_add_quality_buttons_link);
/**
* Add arrows on sidebar to compare current page to interlanguage link'd page
* by [[user:Pathoschild]], based on older script by unknown
*/
function BilingualLink() {
if ( document.getElementById('p-lang') ) {
// get list of links
var biboxes = document.getElementById('p-lang').getElementsByTagName('li');
// iterate over links
for(var i=0; i<biboxes.length; i++) {
// get link
var bilink = biboxes[i].getElementsByTagName('a')[0];
// create new URL
var bilang = bilink.getAttribute('href').match(/\/\/([^\.]+)\.wikisource/)[1];
var bilanglink = mw.util.wikiGetlink( wgPageName ) + '?match=' + bilang;
// create link
var bianchor = document.createElement('a');
bianchor.setAttribute('href',bilanglink);
bianchor.setAttribute('title','Compare this page with the '+bilang+' version.');
bianchor.appendChild(document.createTextNode(' ⇔'));
// add link
biboxes[i].appendChild(bianchor);
}
}
}
addOnloadHook(BilingualLink);
/**
* Allows extra script to run in Special:Watchlist — addition of announcements
* script allows users to dismiss Mediawiki:watchlist-announcements, as per sitenotice
* user:billinghurst 20100522, as hacked from WP script
*/
if ( mw.config.get('wgCanonicalSpecialPageName') == 'Watchlist' ) {
importScript('MediaWiki:Common.js/watchlist.js');
}
// (should be redundant with the implementation of protocol relative urls (201101004); if not reactivated can be cleansed by end of 2011
// Script to rewrite external links to other Wikimedia projects to
// use the secure server when already browsing from https://secure.wikimedia.org
//
//if ( mw.config.get('wgServer') == 'https://secure.wikimedia.org' ) {
// mw.loader.load('//en.wikipedia.org/w/index.php?title=MediaWiki:Common.js/secure.js&action=raw&ctype=text/javascript');
//}
/** Collapsible tables *********************************************************
*
* Description: Allows tables to be collapsed, showing only the header. See
* [[w:Wikipedia:NavFrame]].
* Maintainers: [[w:User:R. Koot]]
*/
var autoCollapse = 2;
var collapseCaption = "hide";
var expandCaption = "show";
function collapseTable( tableIndex ){
var Button = document.getElementById( "collapseButton" + tableIndex );
var Table = document.getElementById( "collapsibleTable" + tableIndex );
if ( !Table || !Button ) {
return false;
}
var Rows = Table.rows;
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 createCollapseButtons(){
var tableIndex = 0;
var NavigationBoxes = {};
var Tables = document.getElementsByTagName( "table" );
for ( var i = 0; i < Tables.length; i++ ) {
if ( hasClass( Tables[i], "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.style.styleFloat = "right"; //
Button.style.cssFloat = "right"; // REMOVE THESE LINES
Button.style.fontWeight = "normal"; // ON 10 FEBRUARY 2009
Button.style.textAlign = "right"; //
Button.style.width = "6em"; //
Button.className = "collapseButton"; //Styles are declared in Common.css
ButtonLink.style.color = Header.style.color;
ButtonLink.setAttribute( "id", "collapseButton" + tableIndex );
ButtonLink.setAttribute( "href", "javascript:collapseTable(" + tableIndex + ");" );
ButtonLink.appendChild( ButtonText );
Button.appendChild( document.createTextNode( "[" ) );
Button.appendChild( ButtonLink );
Button.appendChild( document.createTextNode( "]" ) );
Header.insertBefore( Button, Header.childNodes[0] );
tableIndex++;
}
}
for ( var i = 0; i < tableIndex; i++ ) {
if ( hasClass( NavigationBoxes[i], "collapsed" ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], "autocollapse" ) ) ) {
collapseTable( i );
}
else if ( hasClass( NavigationBoxes[i], "innercollapse" ) ) {
var element = NavigationBoxes[i];
while (element = element.parentNode) {
if ( hasClass( element, "outercollapse" ) ) {
collapseTable ( i );
break;
}
}
}
}
}
addOnloadHook( createCollapseButtons );
/** Dynamic Navigation Bars (experimental) *************************************
*
* Description: See [[w:Wikipedia:NavFrame]].
* Maintainers: UNMAINTAINED
*/
// set up the words in your language
var NavigationBarHide = '[' + collapseCaption + ']';
var NavigationBarShow = '[' + expandCaption + ']';
// shows and hides content and picture (if available) of navigation bars
// Parameters:
// indexNavigationBar: the index of navigation bar to be toggled
function toggleNavigationBar(indexNavigationBar){
var NavToggle = document.getElementById("NavToggle" + indexNavigationBar);
var NavFrame = document.getElementById("NavFrame" + indexNavigationBar);
if (!NavFrame || !NavToggle) {
return false;
}
// if shown now
if (NavToggle.firstChild.data == NavigationBarHide) {
for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
if ( hasClass( NavChild, 'NavPic' ) ) {
NavChild.style.display = 'none';
}
if ( hasClass( NavChild, 'NavContent') ) {
NavChild.style.display = 'none';
}
}
NavToggle.firstChild.data = NavigationBarShow;
// if hidden now
} else if (NavToggle.firstChild.data == NavigationBarShow) {
for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
if (hasClass(NavChild, 'NavPic')) {
NavChild.style.display = 'block';
}
if (hasClass(NavChild, 'NavContent')) {
NavChild.style.display = 'block';
}
}
NavToggle.firstChild.data = NavigationBarHide;
}
}
// adds show/hide-button to navigation bars
function createNavigationBarToggleButton(){
var indexNavigationBar = 0;
// iterate over all < div >-elements
var divs = document.getElementsByTagName("div");
for (var i = 0; NavFrame = divs[i]; i++) {
// if found a navigation bar
if (hasClass(NavFrame, "NavFrame")) {
indexNavigationBar++;
var NavToggle = document.createElement("a");
NavToggle.className = 'NavToggle';
NavToggle.setAttribute('id', 'NavToggle' + indexNavigationBar);
NavToggle.setAttribute('href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');');
var isCollapsed = hasClass( NavFrame, "collapsed" );
/*
* Check if any children are already hidden. This loop is here for backwards compatibility:
* the old way of making NavFrames start out collapsed was to manually add style="display:none"
* to all the NavPic/NavContent elements. Since this was bad for accessibility (no way to make
* the content visible without JavaScript support), the new recommended way is to add the class
* "collapsed" to the NavFrame itself, just like with collapsible tables.
*/
for (var NavChild = NavFrame.firstChild; NavChild != null && !isCollapsed; NavChild = NavChild.nextSibling) {
if ( hasClass( NavChild, 'NavPic' ) || hasClass( NavChild, 'NavContent' ) ) {
if ( NavChild.style.display == 'none' ) {
isCollapsed = true;
}
}
}
if (isCollapsed) {
for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
if ( hasClass( NavChild, 'NavPic' ) || hasClass( NavChild, 'NavContent' ) ) {
NavChild.style.display = 'none';
}
}
}
var NavToggleText = document.createTextNode(isCollapsed ? NavigationBarShow : NavigationBarHide);
NavToggle.appendChild(NavToggleText);
// Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked)
for(var j=0; j < NavFrame.childNodes.length; j++) {
if (hasClass(NavFrame.childNodes[j], "NavHead")) {
NavFrame.childNodes[j].appendChild(NavToggle);
}
}
NavFrame.setAttribute('id', 'NavFrame' + indexNavigationBar);
}
}
}
addOnloadHook( createNavigationBarToggleButton );
/**
* Description: Uses regular expressions and caching for better performance to determine if an element has a class.
* original authors (stolen from wikipedia): w:User:Mike Dillon, w:User:R. Koot, w:User:SG
*/
var hasClass = (function () {
var reCache = {};
return function (element, className) {
return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
};
})();
/*
* port from [[:he:mediawiki:common.js]] for [[mediawiki:edittools]] -Steve
*/
/* פונקציה שמשמשת לאיפשור ניקוד ב[[מדיה ויקי:edittools]] */
function nikud(){
if (document.getElementById('edit-templates')!=null){
for(var i=0; a = document.getElementsByTagName("span")[i]; i++) {
if(a.className == "nikud") {
a.onclick=function(){insertTags('', this.title, '');return false;};
}
}
}
}
addOnloadHook(nikud);
/**
* withJS
*
* Allow to load custom scripts from the MediaWiki namespace without
* editing [[Special:Mypage/common.js]]
*
* Maintainer: [[User:Platonides]], [[User:Lupo]]
*/
var extraJS = mw.util.getParamValue('withJS');
// Leave here for backwards compatibility
(function (extraJS) {
if (!extraJS) {
return;
}
if (extraJS.match(/^MediaWiki:[^&<>=%#]*\.js$/)) {
// Disallow some characters in file name
importScript(extraJS);
} else {
// Dont use alert but the jsMsg system. Run jsMsg only once the DOM is ready.
$(function () {
jsMsg(extraJS + ' javascript not allowed to be loaded.', 'error');
});
}
})(extraJS);
/**
* Icons on the top right of the article.
* See also CSS
*
* @source: http://www.mediawiki.org/wiki/Snippets/Top_icons
* @rev: 2
*/
jQuery( document ).ready( function( $ ) {
$( '.Top_icon_raw' )
.removeClass( 'Top_icon_raw' )
.addClass( 'Top_icon_dynamic' )
.prependTo( '#firstHeading' );
} );
/*Script to allow language links to Old Wikisource (http://wikisource.org) */
importScriptURI('//en.wikisource.org/w/index.php?title=User:Doug/oldws.js&action=raw&ctype=text/javascript');