Järjestelmäviesti:Common.js
Jedipediasta, vapaasta Tähtien sota-tietosanakirjasta tänään, 19. huhtikuuta 2024
Siirry navigaatioonSiirry hakuunHuomautus: Selaimen välimuisti pitää tyhjentää asetusten tallentamisen jälkeen, jotta muutokset tulisivat voimaan.
- Firefox ja Safari: Napsauta Shift-näppäin pohjassa Päivitä, tai paina Ctrl-F5 tai Ctrl-R (⌘-R Macilla)
- Google Chrome: Paina Ctrl-Shift-R (⌘-Shift-R Macilla)
- Internet Explorer: Napsauta Ctrl-näppäin pohjassa Päivitä tai paina Ctrl-F5
- Opera: Valikko → Asetukset (Opera → Asetukset Macilla) ja sitten Tietosuoja ja turvallisuus → Tyhjennä selaustiedot → Välimuistissa olevat kuvat ja tiedostot.
/* <nowiki> */
/* global $, ActiveXObject, mw */
/* If you need help with these JS functions (i.e. you want some features, like standard summaries, for your own wiki), please ask [[User:Jack Phoenix|Jack Phoenix]]. */
// onload stuff
var firstRun = true;
function loadFunc() {
if ( firstRun ) {
firstRun = false;
} else {
return;
}
window.pageName = mw.config.get( 'wgPageName' );
window.storagePresent = ( typeof localStorage != 'undefined' );
// DEPRECATED
if ( document.getElementById( 'infoboxinternal' ) !== null && document.getElementById( 'infoboxend' ) !== null ) {
document.getElementById( 'infoboxend' ).innerHTML = '<a id="infoboxtoggle" href="javascript:infoboxToggle()">[Piilota]</a>';
}
// Upload form - need to run before adding hide buttons
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Upload' ) {
setupUploadForm();
fixDestinationNamePrefill();
}
addHideButtons();
if ( document.getElementById( 'mp3-navlink' ) !== null ) {
document.getElementById( 'mp3-navlink' ).onclick = onArticleNavClick;
document.getElementById( 'mp3-navlink' ).getElementsByTagName( 'a' )[0].href = 'javascript:void(0)';
}
if ( window.storagePresent ) {
initVisibility();
}
fillEditSummaries();
fillPreloads();
substUsername();
substUsernameTOC();
showEras( 'title-eraicons' );
showEras( 'title-shortcut' );
checkblock();
hideContentSub();
addWookAttribution();
if ( typeof onPageLoad != 'undefined' ) {
onPageLoad();
}
}
function infoboxToggle() {
var page = window.pageName.replace( /\W/g, '_' );
var nowShown;
if ( document.getElementById( 'infoboxtoggle' ).innerHTML == '[Piilota]' ) {
document.getElementById( 'infoboxinternal' ).style.display = 'none';
document.getElementById( 'infoboxtoggle' ).innerHTML = '[Näytä]';
nowShown = false;
} else {
document.getElementById( 'infoboxinternal' ).style.display = 'block';
document.getElementById( 'infoboxtoggle' ).innerHTML = '[Piilota]';
nowShown = true;
}
if ( window.storagePresent ) {
localStorage.setItem( 'infoboxshow-' + page, nowShown );
}
}
/**
* jQuery version of Sikon's fillEditSummaries
* @author Grunny
*/
function fillEditSummaries() {
if ( !$( '#wpSummaryLabel' ).length ) {
return;
}
$.get( mw.config.get( 'wgScript' ), { title: 'Malline:Yhteenvedot', action: 'raw', ctype: 'text/plain' } ).done( function( data ) {
var $summaryOptionsList,
$summaryLabel = $( '#wpSummaryLabel' ),
lines = data.split( '\n' ),
$wrapper = $( '<div>').addClass( 'edit-widemode-hide' ).text( 'Yleiset yhteenvedot: ' );
$summaryOptionsList = $( '<select />' ).attr( 'id', 'stdEditSummaries' ).change( function() {
var editSummary = $( this ).val();
if ( editSummary !== '' ) {
$( '#wpSummaryWidget input[name="wpSummary"]' ).val( editSummary );
}
} );
for ( var i = 0; i < lines.length; i++ ) {
var editSummaryText = ( lines[i].indexOf( '-- ' ) === 0 ) ? lines[i].substring(3) : '';
$summaryOptionsList.append( $( '<option>' ).val( editSummaryText ).text( lines[i] ) );
}
$summaryLabel.prepend( $wrapper.append( $summaryOptionsList ) );
} );
}
/**
* jQuery version of Sikon's fillPreloads
* @author Grunny
*/
function fillPreloads() {
if ( !$( '#lf-preload' ).length ) {
return;
}
$( '#lf-preload' ).attr( 'style', 'display: block' );
$.get( mw.config.get( 'wgScript' ), { title: 'Malline:Stdpreloads', action: 'raw', ctype: 'text/plain' } ).done( function( data ) {
var $preloadOptionsList,
lines = data.split( '\n' );
$preloadOptionsList = $( '<select />' ).attr( 'id', 'stdSummaries' ).change( function() {
var templateName = $( this ).val();
if ( templateName !== '' ) {
templateName = 'Malline:' + templateName + '/preload';
templateName = templateName.replace( ' ', '_' );
$.get( mw.config.get( 'wgScript' ), { title: templateName, action: 'raw', ctype: 'text/plain' } ).done( function( data ) {
insertAtCursor( document.getElementById( 'wpTextbox1' ), data );
} );
}
} );
for ( var i = 0; i < lines.length; i++ ) {
var templateText = ( lines[i].indexOf( '-- ' ) === 0 ) ? lines[i].substring(3) : '';
$preloadOptionsList.append( $( '<option>' ).val( templateText ).text( lines[i] ) );
}
$( '#lf-preload-cbox' ).html( $preloadOptionsList );
} );
$( '#lf-preload-pagename' ).html( '<input type="text" class="textbox" />' );
$( '#lf-preload-button' ).html( '<input type="button" class="button" value="Insert" onclick="doCustomPreload()" />' );
}
function doCustomPreload() {
var value = $( '#lf-preload-pagename > input' ).val();
value = value.replace( ' ', '_' );
$.get( mw.config.get( 'wgScript' ), { title: value, action: 'raw', ctype: 'text/plain' } ).done( function( data ) {
insertAtCursor( document.getElementById( 'wpTextbox1' ), data );
} );
}
/* Stores the (unmodified) page title. */
function storePageName() {
if ( mw.config.get( 'skin' ) == 'monobook' || mw.config.get( 'skin' ) == 'vector' ) {
window.pageName = $( 'h1#firstHeading span' ).text();
} else if ( mw.config.get( 'skin' ) == 'bluecloud' || mw.config.get( 'skin' ) == 'eminence' || mw.config.get( 'skin' ) == 'monaco' ) {
window.pageName = $( 'h1.firstHeading' ).text();
} else if ( mw.config.get( 'skin' ) == 'games' || mw.config.get( 'skin' ) == 'nimbus' || mw.config.get( 'skin' ) == 'sports' ) {
window.pageName = $( 'h1.pagetitle' ).text();
} else if ( mw.config.get( 'skin' ) == 'hope' ) {
window.pageName = $( 'h2#one' ).text();
} else if ( mw.config.get( 'skin' ) == 'modern' ) {
window.pageName = $( 'h1#firstHeading span' ).text();
} else if ( mw.config.get( 'skin' ) == 'truglass' ) {
window.pageName = $( 'h1#title' ).text();
}
}
/* Adds a trim method to string variables. */
String.prototype.trim = function() {
return this.replace( /^\s+|\s+$/g, '' );
};
/* Searches an array for an element and returns its index, or -1 if it's not in the array. */
function arrayFind( array, value ) {
for ( var i = 0; i < array.length; i++ ) {
if ( array[i] == value ) {
return i;
}
}
return -1;
}
/* Removes the first occurrence of an element in an array, if it is there. */
function arrayRemove( array, value ) {
var i = arrayFind( array, value );
if ( i != -1 ) {
array.splice( i, 1 );
}
}
/*
the ContentLoader class to encapsulate "creative differences" with XHR
Usage:
- construct a ContentLoader object: var loader = new ContentLoader();
- set necessary state parameters (via fields); e.g. loader.myvar = 'mytext';
- set the callback: loader.callback = myfunc;
- send the request:
loader.send(url, postdata = null, contentType = 'application/x-www-form-urlencoded');
(if postdata isn't null or omitted, POST is used, otherwise GET)
- the callback function is called when the content is loaded
- the ContentLoader object is this
- the raw response data is this.text
- the XML DOM object, if any, is this.document
*/
function ContentLoader() {
this.cache = true;
}
ContentLoader.prototype.enableCache = function( caching ) {
this.cache = ( caching === null ) ? true : this.cache;
};
ContentLoader.prototype.createRequest = function() {
if ( typeof XMLHttpRequest != 'undefined' ) {
return new XMLHttpRequest();
} else if ( typeof ActiveXObject != 'undefined' ) {
return new ActiveXObject( 'Msxml2.XMLHTTP' );
}
return null;
};
ContentLoader.prototype.send = function( url, postdata, contentType ) {
var method = ( postdata === null ) ? 'GET' : 'POST';
this.request = this.createRequest();
this.request.open( method, url );
if ( !this.cache ) {
this.request.setRequestHeader( 'If-Modified-Since', 'Sat, 1 Jan 2000 00:00:00 GMT' );
}
var request = this.request;
var loader = this;
if ( postdata === null ) {
if ( contentType === null ) {
contentType = 'application/x-www-form-urlencoded';
}
request.setRequestHeader( 'Content-type', contentType );
}
var f = function() {
if ( request.readyState == 4 ) {
loader.text = request.responseText;
loader.document = request.responseXML;
request = null;
loader.request = null;
loader.callback();
}
};
this.request.onreadystatechange = f;
this.request.send( postdata );
};
/* end ContentLoader */
/*
Source: http://www.dustindiaz.com/getelementsbyclass/
getElementsByClass, which complements getElementById and getElementsByTagName, returns an array of all subelements of ''node'' that are tagged with a specific CSS class (''searchClass'') and are of the tag name ''tag''. If tag is null, it searches for any suitable elements regardless of the tag name.
Example: getElementsByClass('infobox', document.getElementById('content'), 'div') selects the same elements as the CSS declaration #content div.infobox
*/
function ClassTester( className ) {
this.regex = new RegExp( "(^|\\s)" + className + "(\\s|$)" );
}
ClassTester.prototype.isMatch = function( element ) {
return this.regex.test( element.className );
};
function getElementsByClass( searchClass, node, tag ) {
var classElements = [];
if ( node === null || node === undefined ) {
node = document;
}
if ( tag === null ) {
tag = '*';
}
var els = node.getElementsByTagName( tag );
var elsLen = els.length;
var tester = new ClassTester( searchClass );
var i, j;
for ( i = 0, j = 0; i < elsLen; i++ ) {
if ( tester.isMatch( els[i] ) ) {
classElements[j] = els[i];
j++;
}
}
return classElements;
}
/* end getElementsByClass */
/* Returns h1.firstHeading (the page title element). */
function getFirstHeading() {
var elements = getElementsByClass( 'firstHeading', document.getElementById( 'content' ), 'h1' );
return ( elements !== null && elements.length > 0 ) ? elements[0] : null;
}
/* Returns the element's nearest parent that has the specified CSS class. */
function getParentByClass( className, element ) {
var tester = new ClassTester( className );
var node = element.parentNode;
while ( node !== null && node != document ) {
if ( tester.isMatch( node ) ) {
return node;
}
node = node.parentNode;
}
return null;
}
/*
Replaces {{USERNAME}} with the name of the user browsing the page.
Requires copying Template:USERNAME.
*/
function substUsername() {
var username = mw.config.get( 'wgUserName' );
if ( username === null ) {
return;
}
$( 'span.insertusername' ).html( username );
}
/* Force preview for anons */
/* by Marc Mongenet, 2006, fr.wikipedia */
function forcePreview() {
if ( mw.config.get( 'wgUserName' ) !== null || mw.config.get( 'wgAction' ) != 'edit' ) {
return;
}
var saveButton = document.getElementById( 'wpSave' );
if ( !saveButton ) {
return;
}
saveButton.disabled = true;
saveButton.value = 'Tallenna sivu (esikatsele muokkauksiasi ensiksi)';
saveButton.style.fontWeight = 'normal';
saveButton.style.color = 'gray';
document.getElementById( 'wpPreview' ).style.fontWeight = 'bold';
}
$( forcePreview );
/* End of forcePreview */
// ============================================================
// BEGIN JavaScript title rewrite -- jQuery version and new wikia skin fixes by Grunny
function showEras( className ) {
if ( typeof window.SKIP_ERAS != 'undefined' && window.SKIP_ERAS ) {
return;
}
var titleDiv = document.getElementById( className );
if ( titleDiv === null || titleDiv === undefined ) {
return;
}
var cloneNode = titleDiv.cloneNode( true );
var firstHeading = getFirstHeading();
firstHeading.insertBefore( cloneNode, firstHeading.childNodes[0] );
cloneNode.style.display = 'block';
}
// END JavaScript title rewrite
function initVisibility() {
var page = window.pageName.replace( /\W/g, '_' );
var show = localStorage.getItem( 'infoboxshow-' + page );
if ( show == 'false' ) {
infoboxToggle();
}
var hidables = getElementsByClass( 'hidable' );
for ( var i = 0; i < hidables.length; i++ ) {
show = localStorage.getItem( 'hidableshow-' + i + '_' + page );
var content, button;
if ( show == 'false' ) {
content = getElementsByClass( 'hidable-content', hidables[i] );
button = getElementsByClass( 'hidable-button', hidables[i] );
if (
content !== null && content.length > 0 &&
button !== null && button.length > 0 &&
content[0].style.display != 'none'
)
{
button[0].onclick( 'bypass' );
}
} else if ( show == 'true' ) {
content = getElementsByClass( 'hidable-content', hidables[i] );
button = getElementsByClass( 'hidable-button', hidables[i] );
if (
content !== null && content.length > 0 &&
button !== null && button.length > 0 &&
content[0].style.display == 'none'
)
{
button[0].onclick( 'bypass' );
}
}
}
}
function onArticleNavClick() {
var div = document.getElementById( 'mp3-nav' );
if ( div.style.display == 'block' ) {
div.style.display = 'none';
} else {
div.style.display = 'block';
}
}
function addHideButtons() {
var hidables = getElementsByClass( 'hidable' );
for ( var i = 0; i < hidables.length; i++ ) {
var box = hidables[i];
var button = getElementsByClass( 'hidable-button', box, 'span' );
if ( button !== null && button.length > 0 ) {
button = button[0];
button.onclick = toggleHidable;
button.appendChild( document.createTextNode( '[Piilota]' ) );
if ( new ClassTester( 'start-hidden' ).isMatch( box ) ) {
button.onclick( 'bypass' );
}
}
}
}
function toggleHidable( bypassStorage ) {
var parent = getParentByClass( 'hidable', this );
var content = getElementsByClass( 'hidable-content', parent );
var nowShown;
if ( content !== null && content.length > 0 ) {
content = content[0];
if ( content.style.display == 'none' ) {
content.style.display = content.oldDisplayStyle;
this.firstChild.nodeValue = '[Piilota]';
nowShown = true;
} else {
content.oldDisplayStyle = content.style.display;
content.style.display = 'none';
this.firstChild.nodeValue = '[Näytä]';
nowShown = false;
}
if ( window.storagePresent && ( typeof bypassStorage == 'undefined' || bypassStorage != 'bypass' ) ) {
var page = window.pageName.replace( /\W/g, '_' );
var items = getElementsByClass( 'hidable' );
var item = -1;
for ( var i = 0; i < items.length; i++ ) {
if ( items[i] == parent ) {
item = i;
break;
}
}
if ( item == -1 ) {
return;
}
localStorage.setItem( 'hidableshow-' + item + '_' + page, nowShown );
}
}
}
function substUsernameTOC() {
var toc = $( '#toc' );
var userpage = $( '#pt-userpage' );
if ( !userpage || !toc ) {
return;
}
var username = $( '#pt-userpage' ).children( ':first-child' ).text();
$( 'span.toctext:not(:has(*)), span.toctext i', toc ).each( function() {
$( this ).text( $( this ).text().replace( '<insert name here>', username ) );
} );
}
$( loadFunc );
function checkblock() {
mw.loader.using( 'mediawiki.util', function () {
if ( mw.util.getParamValue( 'submitblock' ) == 'true' && document.getElementById( 'blockip' ) ) {
document.getElementById( 'blockip' ).wpBlock.click();
}
} );
}
/**
* Start upload form customisations
* @author Green tentacle
*/
function setupUploadForm() {
// Check if cookie has been set for form style. Overrides URL parameter if set.
var formstyle = localStorage.getItem( 'uploadform' );
$( '#uploadBasicLinkJS' ).show();
$( '#uploadTemplateNoJS' ).hide();
var wpLicense = $( '#wpLicense' );
if ( wpLicense.length && window.location.search.indexOf( 'wpForReUpload=1' ) == -1 ) {
if (
formstyle == 'guided' ||
( formstyle === '' && window.location.search.indexOf( 'basic=true' ) == -1 )
)
{
// Add link to basic form
$( '#uploadtext' ).prepend( '<div style="float: right;" id="uploadBasicLinkJS"><a href="' + mw.config.get( 'wgServer' ) + mw.config.get( 'wgScriptPath' ) + '/index.php?title=Toiminnot:Tallenna&basic=true" onclick="javascript:localStorage.setItem(\'uploadform\', \'basic\')">Vaihda tavalliseen tallennukseen</a></div>' );
// Stretch table to full width
$( '#mw-htmlform-description' ).css( 'width', '100%' );
// Bind upload button to verify function
$( '#mw-upload-form' ).on( 'submit', verifySummary );
// Hide existing rows
var rows = $( '#mw-htmlform-description' ).find( 'tr' );
$( 'tr.mw-htmlform-field-HTMLTextAreaField' ).hide();
$( 'tr.mw-htmlform-field-HTMLTextAreaField' ).next().detach();
$( '#mw-htmlform-description' ).addClass( 'hidable start-hidden' );
// Add new required rows
rows.eq( 1 ).after( '<tr><td class="mw-label" style="width: 125px;">Lähde:</td><td class="mw-input"><textarea id="sourceBox" cols="60" rows="2" style="overflow: auto;"></textarea></td></tr>' );
$( '#mw-htmlform-description' ).append( '<tbody class="hidable-content"></tbody>' );
var tbody1 = $( '#mw-htmlform-description' ).children( 'tbody' ).eq( 0 );
tbody1.append( '<tr><td class="mw-label" style="width: 125px;">Kuvaus:</td><td class="mw-input"><textarea id="descriptionBox" cols="60" rows="2" style="overflow: auto;"></textarea></td></tr>' );
tbody1.append( '<tr><td colspan="2" style="text-align: center;">Valinnaiset kentät <span class="hidable-button"></span></td></tr>' );
// Add new optional rows
var tbody2 = $( '#mw-htmlform-description' ).children( 'tbody' ).eq( 1 );
tbody2.append( '<tr><td class="mw-label" style="width: 125px;">Huomio:</td><td class="mw-input"><textarea id="attentionBox" cols="60" rows="2" style="overflow: auto;"></textarea></td></tr>' );
tbody2.append( '<tr><td class="mw-label" style="width: 125px;">Alkuperäinen tekijä / artisti:</td><td class="mw-input"><textarea id="artistBox" cols="60" rows="2" style="overflow: auto;"></textarea></td></tr>' );
tbody2.append( '<tr><td class="mw-label" style="width: 125px;">Muut versiot:</td><td class="mw-input"><textarea id="versionsBox" cols="60" rows="2" style="overflow: auto;"></textarea></td></tr>' );
tbody2.append( '<tr><td class="mw-label" style="width: 125px;">Luokat:</td><td class="mw-input"><textarea id="catBox" cols="60" rows="2" style="overflow: auto;"></textarea></td></tr>' );
} else {
// Old style form just needs Information template in the summary box
//$( '#wpUploadDescription' ).val( '{{Tiedot\r\n|huomio=\r\n|kuvaus=\r\n|lähde=\r\n|tekijä=\r\n|lisenssi=\r\n|muut versiot=\r\n}}' );
// Add link to guided form
$( '#uploadtext' ).prepend( '<div style="float: right;" id="uploadBasicLinkJS"><a href="' + mw.config.get( 'wgServer' ) + mw.config.get( 'wgScriptPath' ) + '/index.php?title=Toiminnot:Tallenna" onclick="javascript:localStorage.setItem(\'uploadform\', \'guided\')">Vaihda ohjattuun tallennukseen</a></div>' );
$( '#mw-upload-form' ).on( 'submit', verifyName );
}
}
}
function verifySummary() {
var wpLicense = document.getElementById( 'wpLicense' );
var wpDestFile = document.getElementById( 'wpDestFile' );
var skipWarnings = document.getElementById( 'wpIgnoreWarning' ).value === '1'; // [sic]!
// Check for licensing
if ( wpLicense.value === '' && !skipWarnings ) {
alert( 'Lisenssi on merkittävä.' );
return false;
}
// Check for source
if ( document.getElementById( 'sourceBox' ).value === '' && !skipWarnings ) {
alert( 'Lähde on merkittävä.' );
return false;
}
// Check for duplicated or capitalized file extensions
if ( wpDestFile.value.match( /(JPG|PNG|GIF|SVG|jpeg|jpg\.jpg|png\.png|gif\.gif|svg\.svg|svg\.png|PNG\.png|JPG\.jpg)$/ ) && !skipWarnings ) {
alert( 'Älä käytä isokirjaimisia, pidennettyjä tai kaksinkertaisia tiedostopäätteitä tiedoston nimessä.' );
return false;
}
var strBuilder = '{{Tiedot\r\n';
strBuilder += '|huomio=' + document.getElementById( 'attentionBox' ).value + '\r\n';
strBuilder += '|kuvaus=' + document.getElementById( 'descriptionBox' ).value + '\r\n';
strBuilder += '|lähde=' + document.getElementById( 'sourceBox' ).value + '\r\n';
strBuilder += '|tekijä=' + document.getElementById( 'artistBox' ).value + '\r\n';
strBuilder += '|lisenssi=' + wpLicense.options[wpLicense.selectedIndex].title + '\r\n';
strBuilder += '|muut versiot=' + document.getElementById( 'versionsBox' ).value + '\r\n';
strBuilder += '|luokat=' + document.getElementById( 'catBox' ).value + '\r\n';
strBuilder += '}}';
document.getElementById( 'wpUploadDescription' ).value = strBuilder;
wpLicense.selectedIndex = 0;
return true;
}
function verifyName() {
var wpDestFile = document.getElementById( 'wpDestFile' );
var wpLicense = document.getElementById( 'wpLicense' );
var skipWarnings = document.getElementById( 'wpIgnoreWarning' ).value === '1'; // [sic]!
// Check for duplicated or capitalized file extensions
if ( wpDestFile.value.match( /(JPG|PNG|GIF|SVG|jpeg|jpg\.jpg|png\.png|gif\.gif|svg\.svg|svg\.png|PNG\.png|JPG\.jpg)$/ ) && !skipWarnings ) {
alert( 'Älä käytä isokirjaimisia, pidennetttyjä tai kaksinkertaisia tiedostopäätteitä tiedoston nimessä.' );
return false;
}
// Check for annoying characters
if ( wpDestFile.value.match( /(\(|\)|!|\?|,|\+|\'|\’)/ ) && !skipWarnings ) {
alert( 'Älä käytä erikoismerkkejä tiedoston nimessä.' );
return false;
}
if ( wpLicense.value !== '' ) {
$( '#wpUploadDescription' ).val(
$( '#wpUploadDescription' ).val().replace( '|lisenssi=', '|lisenssi=' + wpLicense.options[wpLicense.selectedIndex].title )
);
wpLicense.selectedIndex = 0;
}
return true;
}
/**
* End upload form customisations
*/
/** Archive edit tab disabling *************************************
* Disables the edit tab on old forum topic pages to stop noobs bumping old topics.
* Page can still be edited by going via the edit tab on the history etc, or by
* typing the edit address manually.
* By [[:en:User:Spang|Spang]]
* Monaco support by [[:en:User:Uberfuzzy|Uberfuzzy]]
* Removal of new section tab on talk pages added by [[:en:User:Grunny|Grunny]]
* Vector support by [[User:--miki--|--miki--]]
*/
function disableOldForumEdit() {
if ( typeof window.enableOldForumEdit != 'undefined' && window.enableOldForumEdit ) {
return;
}
if (
!document.getElementById( 'archive-page' ) ||
!document.getElementById( 'ca-edit' ) ||
mw.config.get( 'wgNamespaceNumber' ) === 10
)
{
return;
}
var $editLink;
if ( mw.config.get( 'skin' ) == 'monaco' ) {
$editLink = $( '#ca-edit' );
} else if ( mw.config.get( 'skin' ) == 'monobook' || mw.config.get( 'skin' ) == 'vector' ) {
$editLink = $( '#ca-edit a' );
}
$editLink.removeAttr( 'href title' );
$editLink.css( 'color', 'gray');
$editLink.text( 'Arkisto' );
$( 'span.mw-editsection' ).remove();
$( '#control_addsection, #ca-addsection' ).remove();
}
$( disableOldForumEdit );
/**
* Konami Code JavaScript from http://snipplr.com/view/15785/jquery-konami-code-listener/
* Some fixes & MediaWikification by Jack Phoenix
* @date February 5, 2010
*/
function konamiCode() {
var kkeys = [],
// up, up, down, down, left, right, left, right, B, A
konami = '38,38,40,40,37,39,37,39,66,65';
$( document ).on( 'keydown', function( e ) {
kkeys.push( e.keyCode );
if ( kkeys.toString().indexOf( konami ) >= 0 ) {
var logoURL = 'https://images.shoutwiki.com/fi.darth/b/bc/Wiki.png';
// Hide the current logo...
mw.util.addCSS( '#p-logo a { display: none !important; }' );
// ...and append the new one!
mw.util.addCSS( '#p-logo {' +
'background-image: url("' + logoURL + '") !important;' +
'background-repeat: no-repeat !important;' +
'background-position: 35% 50% !important;' +
'display: block !important;' +
'}' );
}
} );
}
$( konamiCode );
// Katso [[Foorumi:SH:Malline:Suositeltu]]
/* Magic edit intro. Copied from Wikipedia's MediaWiki:Common.js, modified for use in both Monaco and Monobook skins by Sikon */
function addEditIntro( name ) {
// Top link
var el = document.getElementById( 'ca-edit' );
if ( typeof el.href == 'undefined' ) {
el = el.getElementsByTagName( 'a' )[0];
}
if ( el ) {
el.href += '&editintro=' + name;
}
// Section links
var spans = document.getElementsByTagName( 'span' );
for ( var i = 0; i < spans.length; i++ ) {
el = null;
if ( spans[i].className == 'editsection' ) {
el = spans[i].getElementsByTagName( 'a' )[0];
if ( el ) {
el.href += '&editintro=' + name;
}
} else if ( spans[i].className == 'editsection-upper' ) {
el = spans[i].getElementsByTagName( 'a' )[0];
if ( el ) {
el.href += '&editintro=' + name;
}
}
}
}
if ( mw.config.get( 'wgNamespaceNumber' ) === 0 ) {
$( function() {
var cats = document.getElementById( 'catlinks' );
if ( !cats ) {
return;
}
cats = cats.getElementsByTagName( 'a' );
for ( var i = 0; i < cats.length; i++ ) {
if ( cats[i].title === 'Luokka:Työn alla olevat artikkelit' ) {
addEditIntro( 'Malline:Työn_alla' );
break;
} else if ( cats[i].title === 'Luokka:Suositellut sivut' ) {
addEditIntro( 'Malline:Suositeltu' );
break;
} else if ( cats[i].title === 'Luokka:Hyvät artikkelit' ) {
addEditIntro( 'Malline:Hyvä' );
break;
} else if ( cats[i].title === 'Luokka:Legends-artikkelit, joista on vastine kaanonissa' ) {
addEditIntro( 'Malline:Legendsintro' );
break;
} else if ( cats[i].title === 'Luokka:Kaanonartikkelit, joista on vastine Legendsissä' ) {
addEditIntro( 'Malline:Kaanonintro' );
break;
}
}
} );
}
/**
* Hides the link to parent pages from subpages if {{HideContentSub}} is included
*/
function hideContentSub() {
if ( mw.config.get( 'wgNamespaceNumber' ) === 0 || $( '#hideContentSub' ).length > 0 ) {
if ( $( '#contentSub span.subpages' ).text().substring( 0, 1 ) === '<' ) {
$( '#contentSub span.subpages' ).hide();
}
}
}
// Lisätään artikkelin alareunaan tieto, että se perustuu Wookieepedian artikkeliin.
// {{HideWookAttribution}} poistaa tekstin kyseiseltä sivulta ja window.hideWookAttribution = true kokonaan käytöstä
function addWookAttribution() {
if ( window.hideWookAttribution ) { return; }
var wookLink = $( 'li.interwiki-en a:first' );
if ( mw.config.get( 'wgNamespaceNumber' ) !== 0 || $( '#hideWookAttribution' ).length > 0 || !wookLink.length ) {
return;
}
var wookArticle = wookLink.attr( 'title' ).replace( ' — English', '' );
$( '#bodyContent' ).append( '<div id="WookAttribution"><hr />Tämä artikkeli tai osa siitä perustuu <a rel="nofollow" href="https://starwars.fandom.com/">Wookieepedian</a> artikkeliin ”<a rel="nofollow" href="' + wookLink.attr( 'href' ) + '">' + wookArticle + '</a>”.</div>' );
}
// Käytettävyyskorjaus uudelle navigaatiovalikolle, ks. [[Foorumi:YA:Uusi navigaatiovalikko]]
$( function() {
if (
'ontouchstart' in window && // kosketusnäytöllinen laite
mw.config.get( 'wgTitle' ) === mw.config.get( 'wgMainPageTitle' ) // etusivu
)
{
$( '.topmenu > a' ).on( 'touchstart', function( e ) {
$( this ).off( 'touchstart' ).on( 'click', function( e ) {
e.preventDefault();
} );
e.preventDefault();
} );
}
} );
/**
* Fix the upload form destination name prefilling for Wikia image URLs
* (e.g. https://vignette.wikia.nocookie.net/starwars/images/0/0e/QueensShadow.png/revision/latest?cb=20190305210550&format=original)
*
* By default MediaWiki takes the part after the last slash and makes that the suggested
* destination name. For Wikia domains this is always wrong and the part after
* the last slash is garbage we don't care about.
*
* @date 18 March 2019
*/
function fixDestinationNamePrefill() {
if ( window.location.search.indexOf( 'wpForReUpload=1' ) == -1 ) {
$( '#wpUploadFileURL' ).change( function() {
var val = $( this ).val(),
splitArr = val.split( '/' );
if ( !String( val ).match( /nocookie.net/gi ) ) {
return;
}
if ( splitArr.length !== 10 ) {
return;
}
$( '#wpDestFile' ).val( splitArr[7] );
} );
}
}
/* Link FA */
window.FA_enabled = true;
function addFAicon() {
// early return if explicitly disabled
if ( !window.FA_enabled ) {
return;
}
// article namespace only
if ( mw.config.get( 'wgNamespaceNumber' ) !== 0 ) {
return;
}
var pLang = document.getElementById( 'p-lang' );
if ( !pLang ) {
return;
}
var lis = pLang.getElementsByTagName( 'li' );
for ( var i = 0; i < lis.length; i++ ) {
var li = lis[i];
// only links with a corresponding FA/GA/CA templates are interesting
if ( document.getElementById( 'interwiki-' + li.firstChild.lang + '-fa' ) ) {
// additional class so the template can be hidden with CSS
li.className += ' FA';
// change title (description on mouseover)
li.title = 'Tämä artikkeli on suositeltu sivu.';
} else if ( document.getElementById( 'interwiki-' + li.firstChild.lang + '-ga' ) ) {
// additional class so the template can be hidden with CSS
li.className += ' GA';
// change title (description on mouseover)
li.title = 'Tämä artikkeli on hyvä artikkeli.';
} else if ( document.getElementById( 'interwiki-' + li.firstChild.lang + '-ca' ) ) {
// additional class so the template can be hidden with CSS
li.className += ' CA';
// change title (description on mouseover)
li.title = 'Tämä artikkeli on lupaava artikkeli.';
}
}
}
$( addFAicon );
// Lazy load SWTOR article appearances list
$( function lazyLoadTorApp() {
var pageName = 'Star_Wars:_The_Old_Republic',
appPageName = encodeURIComponent( pageName + '/Esiintymiset' ),
$lazyLoadEl = $( '#WookTorLazyload' ),
includeHtml,
$editLink;
if ( mw.config.get( 'wgPageName' ) !== pageName || !$lazyLoadEl.length ) {
return;
}
$lazyLoadEl.html( '<img src="https://images.shoutwiki.com/fi.starwars/4/44/Spinner.gif" style="vertical-align: baseline;" border="0" alt="Ladataan..." />' );
$.getJSON( '/w/api.php?action=parse&page=' + appPageName + '&format=json' )
.done( function ( data ) {
if ( data.parse && data.parse.text ) {
includeHtml = data.parse.text['*'];
$lazyLoadEl.html( includeHtml );
$editLink = $lazyLoadEl.prev( 'h2' ).find( '.mw-editsection a' );
if ( $editLink.length ) {
$editLink.attr( 'href', '/w/index.php?title=' + appPageName + '&action=edit' );
}
// Korvaava toiminto MediaWikin omalle piilotustoiminnolle, joka ei toimi
$( '.mw-customtoggle-applist' ).click( function() {
$( '#mw-customcollapsible-applist' ).toggleClass( 'mw-collapsed' );
} );
}
} );
} );
//Etusivun navigaatiovalikoiden lataaminen
$( function loadDropdownOOU() {
var pageName = 'Etusivu',
appPageName = encodeURIComponent( 'Malline:Dropdown-OOU' ),
$lazyLoadEl = $( '#DropdownOOUload' ),
includeHtml;
if ( mw.config.get( 'wgPageName' ) !== pageName || !$lazyLoadEl.length ) {
return;
}
$lazyLoadEl.html( '<img src="https://images.shoutwiki.com/fi.starwars/4/44/Spinner.gif" style="vertical-align: baseline;" border="0" alt="Ladataan..." />' );
$.getJSON( '/w/api.php?action=parse&page=' + appPageName + '&format=json' )
.done( function ( data ) {
if ( data.parse && data.parse.text ) {
includeHtml = data.parse.text['*'];
$lazyLoadEl.html( includeHtml );
}
} );
} );
$( function loadDropdownIU() {
var pageName = 'Etusivu',
appPageName = encodeURIComponent( 'Malline:Dropdown-IU' ),
$lazyLoadEl = $( '#DropdownIUload' ),
includeHtml;
if ( mw.config.get( 'wgPageName' ) !== pageName || !$lazyLoadEl.length ) {
return;
}
$lazyLoadEl.html( '<img src="https://images.shoutwiki.com/fi.starwars/4/44/Spinner.gif" style="vertical-align: baseline;" border="0" alt="Ladataan..." />' );
$.getJSON( '/w/api.php?action=parse&page=' + appPageName + '&format=json' )
.done( function ( data ) {
if ( data.parse && data.parse.text ) {
includeHtml = data.parse.text['*'];
$lazyLoadEl.html( includeHtml );
}
} );
} );
/**
* Convert a number to have commas in it
* from mredkj.com
*/
function addCommas( nStr ) {
nStr += ''; // make it a string
var x = nStr;
var rgx = /(\d+)(\d{3})/;
while ( rgx.test( x ) ) {
x = x.replace( rgx, '$1' + ' ' + '$2' );
}
return x;
}
/* Mahdollistaa muiden wikien artikkelimäärän päivittämisen reaaliaikaisesti */
( function() {
var stats = [ 'articles', 'activeusers', 'admins', 'edits', 'images' ],
wikis = [],
regex = /^[0-9a-z\.-]+$/,
prefix = 'outwikistats-';
$( stats.map( function( name ) {
return '.outwikistats-' + name;
} ).join( ', ' ) ).each( function() {
var $this = $( this ),
wiki = $this.text();
$this.attr( {
'data-attr': $this.attr( 'class' ).substring( prefix.length ),
'data-wiki': wiki
} ).html( $( '<img>', {
src: 'https://images.shoutwiki.com/fi.starwars/4/44/Spinner.gif'
} ) );
if ( wikis.indexOf( wiki ) === -1 ) {
wikis.push( wiki );
}
} );
wikis.forEach( function( wiki ) {
if ( !wiki.match( regex ) ) {
return;
}
var url;
if ( wiki == 'de' ) {
url = 'https://www.jedipedia.net/w';
} else if ( wiki == 'pl' ) {
url = 'https://www.ossus.pl';
} else {
url = 'https://starwars.fandom.com/' + wiki;
}
$.ajax( {
type: 'GET',
url: url + '/api.php',
data: {
action: 'query',
meta: 'siteinfo',
siprop: 'statistics',
format: 'json'
},
dataType: 'jsonp',
jsonp: 'callback',
crossDomain: true,
success: function( data ) {
var stats = data.query.statistics;
if ( !stats ) {
return;
}
$( '[data-wiki="' + wiki + '"]' ).each( function() {
var $this = $( this ),
prop = $this.attr( 'data-attr' ),
result = stats[prop];
var cresult = addCommas( result );
$this.text( cresult );
} );
}
} );
} );
} )();
/* Piilotetaan poisto/siirtolokin merkintä niillä sivuilla, jotka on siirretty /Legends-päätteiseksi (ks. [[MediaWiki:Noarticletext]]) */
$( function() {
if ( $( '#hidelog' ).length ) {
$( 'div.mw-warning-with-logexcerpt' ).remove();
}
} );
/* Sisäänkirjautuminen ei toimi vanhaa fi.starwars.shoutwiki.com-osoitetta käytettäessä (liittynee
* evästeiden asettamiseen), joten kierrätetään nämä pyynnöt ShoutWikin suomenkielisen keskuswikin kautta
*/
mw.loader.using( 'mediawiki.util', function () {
if ( location.hostname == 'fi.starwars.shoutwiki.com' ) {
$( '#pt-login a' ).attr( 'href', 'http://fi.shoutwiki.com/w/index.php?title=Toiminnot:Kirjaudu_sis%C3%A4%C3%A4n&returnto=s:w:fi.starwars:' + mw.util.wikiUrlencode( mw.config.get( 'wgPageName' ) ) );
}
} );
// </nowiki>