From SCP: Secret Laboratory Hub Wiki
(Created page with "//BASED ON: https://pl.wikipedia.org/w/index.php?title=MediaWiki:Gadget-heading-icons.js&oldid=45528861 window.headingIconGadget = { version: 3, enabled: true...") |
No edit summary |
||
Line 141: | Line 141: | ||
} | } | ||
headingIconGadget.init(); | |||
} | } |
Revision as of 17:58, 31 August 2018
//BASED ON: https://pl.wikipedia.org/w/index.php?title=MediaWiki:Gadget-heading-icons.js&oldid=45528861 window.headingIconGadget = { version: 3, enabled: true, firstHeading: null, managedElements: [], sortWeights: { editsection: 1, padlock: 2, // other = 5 coordinates: 10, shortcut_upper: 11 } }; /* Translatable strings */ mw.messages.set( { 'msg-semi-protection': 'Only registered users can edit this page.', 'msg-full-protection': 'Only administrators users can edit this page.', 'msg-editor-protection': 'Only editors can edit this page.', 'msg-steward-protection': 'Only stewards can edit this page.', } ); headingIconGadget.append = function( element ) { if ( !this.firstHeading ) { return; } var sortKey = 5; if ( this.sortWeights[element.id] ) { sortKey = this.sortWeights[element.id] } else if ( this.sortWeights[element.className] ) { sortKey = this.sortWeights[element.className]; } this.managedElements.push( { 'element': element, 'sortKey': sortKey } ); this.firstHeading.insertBefore( element, this.firstHeading.firstChild ); } headingIconGadget.grab = function() { var that = this; jQuery( "span.put-in-header" ).add( "div.put-in-header" ).each( function() { this.style.cssText = 'position:static; display:inline-block; float:right; padding:3px 5px; font-size:50%;'; that.append( this ); } ); } // correction in 0-section edit link headingIconGadget.fix0SectionEdit = function() { if ( this.managedElements.length == 0 ) { return; } var secEdit = jQuery( 'div.editsection' ); if ( secEdit.length ) { secEdit[0].style.cssText = 'padding:.7em 0 0 1.0em; float:right; font-size:50%;'; this.append( secEdit[0] ); } } /** * Shows padlock in the right corner * when page is protected */ headingIconGadget.padlockIcon = function() { // no padlock on main page if ( mw.config.get( 'wgTitle' ) == mw.config.get( 'wgMainPageTitle' ) ) { return; } // no protection? var wgRestrictionEdit = mw.config.get( 'wgRestrictionEdit' ); if ( wgRestrictionEdit == null || wgRestrictionEdit.length < 1 || wgRestrictionEdit[0] == "" ) { return; } // print? if ( mw.util.getParamValue( 'printable' ) == 'yes' ) { return; } var img = document.createElement( 'img' ); if ( wgRestrictionEdit[0] == "autoconfirmed" ) { img.src = "https://upload.wikimedia.org/wikipedia/commons/thumb/8/8a/Padlock-green.svg/22px-Padlock-green.svg.png"; img.title = mw.msg( 'msg-semi-protection' ); } else if ( wgRestrictionEdit[0] == "sysop" ) { img.src = "https://upload.wikimedia.org/wikipedia/commons/thumb/4/48/Padlock-red.svg/22px-Padlock-red.svg.png"; img.title = mw.msg( 'msg-full-protection' ); } else if ( wgRestrictionEdit[0] == "editor" ) { img.src = "https://upload.wikimedia.org/wikipedia/commons/thumb/e/e0/Padlock-gold.svg/22px-Padlock-gold.svg.png"; img.title = mw.msg( 'msg-editor-protection' ); } else if ( wgRestrictionEdit[0] == "steward" ) { img.src = "https://upload.wikimedia.org/wikipedia/commons/thumb/d/d9/Padlock-black.svg/22px-Padlock-black.svg.png"; img.title = mw.msg( 'msg-steward-protection' ); } img.alt = "padlock"; var link = document.createElement( 'a' ); link.id = "padlock"; //link.href = mw.util.getUrl( "Wikipedia:Strona zabezpieczona" ); link.style.cssText = 'position:static; display:inline-block; float:right; padding:3px 5px; font-size:50%;'; link.appendChild( img ); this.append( link ); } headingIconGadget.sortElements = function() { if ( this.managedElements.length < 2 ) { return; } // sort array this.managedElements.sort( function( a, b ) { return a.sortKey - b.sortKey; } ); // sort elements for ( var i = this.managedElements.length - 1; i >= 0; i-- ) { this.firstHeading.insertBefore( this.managedElements[i].element, this.firstHeading.firstChild ); } } headingIconGadget.init = function() { this.firstHeading = document.getElementById( 'firstHeading' ); if ( !this.firstHeading ) { return; } headingIconGadget.grab(); headingIconGadget.padlockIcon(); headingIconGadget.fix0SectionEdit(); headingIconGadget.sortElements(); } headingIconGadget.init(); }
Cookies help us deliver our services. By using our services, you agree to our use of cookies.
- This page was last edited on 31 August 2018, at 17:58.
- Content is available under CC BY-SA 3.0 unless otherwise noted.
- Privacy policy
- About SCP: Secret Laboratory Hub Wiki
- Disclaimers