MediaWiki:Common.js

/*global mw, $, importStylesheet, importScript, importArticles, addOnloadHook, enableOldForumEdit */ /*jshint browser:true, curly:false, eqnull:true, strict:false */ mw.loader.using( ['mediawiki.util', 'jquery.client'], function { /* Begin of mw.loader.using callback */ "use strict";

importArticles({   type: 'script',    articles: [        'MediaWiki:ReferencePopups/code.js',        'u:dev:Tooltips/code.js',        'u:dev:FileUsageAuto-update/code.js'    ] }, {    type: 'style',    articles: [        'MediaWiki:Anime-common.css',        'MediaWiki:Wikimedia.css',        'MediaWiki:Cardtable.css',        'MediaWiki:Diffs.css'    ] });

/** * Map addPortletLink to mw.util * * @deprecated: Use mw.util.addPortletLink instead. */ window.addPortletLink = function { return mw.util.addPortletLink.apply( mw.util, arguments ); };

/** * Extract a URL parameter from the current URL * * @deprecated: Use mw.util.getParamValue with proper escaping */ window.getURLParamValue = function { return mw.util.getParamValue.apply( mw.util, arguments ); };

/** * Test if an element has a certain class * * @deprecated: Use $(element).hasClass instead. */ window.hasClass = function ( element, className ) { return $( element ).hasClass( className ); };

/** * Load scripts specific to Internet Explorer */ if ( $.client.profile.name === 'msie' ) { importScript( 'MediaWiki:Common.js/IEFixes.js' ); }

/** * Collapsible tables ********************************************************* * * Description: Allows tables to be collapsed, showing only the header. See *             wikipedia:Wikipedia:NavFrame. * Maintainers: wikipedia:User:R. Koot */

var autoCollapse = 2; var collapseCaption = 'hide'; var expandCaption = 'show';

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 ( i = 1; i < Rows.length; i++ ) { Rows[i].style.display = 'none'; }       Button.firstChild.data = expandCaption; } else { for ( 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' ); var i;

function handleButtonLink( index, e ) { window.collapseTable( index ); e.preventDefault; }

for ( i = 0; i < Tables.length; i++ ) { if ( $( 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', '#' ); $( ButtonLink ).on( 'click', $.proxy( handleButtonLink, ButtonLink, tableIndex ) ); ButtonLink.appendChild( ButtonText );

Button.appendChild( document.createTextNode( '[' ) ); Button.appendChild( ButtonLink ); Button.appendChild( document.createTextNode( ']' ) );

Header.insertBefore( Button, Header.firstChild ); tableIndex++; }   }

for ( i = 0; i < tableIndex; i++ ) { if ( $( NavigationBoxes[i] ).hasClass( 'collapsed' ) || ( tableIndex >= autoCollapse && $( NavigationBoxes[i] ).hasClass( 'autocollapse' ) ) ) { window.collapseTable( i ); }       else if ( $( NavigationBoxes[i] ).hasClass ( 'innercollapse' ) ) { var element = NavigationBoxes[i]; while ((element = element.parentNode)) { if ( $( element ).hasClass( 'outercollapse' ) ) { window.collapseTable ( i ); break; }           }        }    } }

$( createCollapseButtons ); /*** end copied from wikipedia:MediaWiki:Common.js ***/

// ================================================== //           Archive edit tab/button disabling // ==================================================

/* Disables the edit tab/button on discussion pages to stop people bumping old forum threads or editing archive pages. * Page can still be edited by going via the edit tab on the history etc, or by * typing the edit address manually. * By Spang * Monaco support by Uberfuzzy * Wikia (Oasis) support by Uberfuzzy */

if ( mw.config.get('wgNamespaceNumber') === 110 || mw.config.get('wgNamespaceNumber') % 2 === 1 ) {

function disableEditLink { if ( mw.config.get('skin') !== 'oasis' && mw.config.get('skin') !== 'monobook' ) { return; } if ( $.inArray( 'sysop', mw.config.get('wgUserGroups') > -1 ) ) { return; } // disable completely for admins if ( enableOldForumEdit !== 'undefined' ) { return; } if ( !$('#archived-edit-link')[0] ) { return; }

var editLink = mw.config.get('skin') === 'oasis' ? $('#ca-edit') : $('#ca-edit a'); if ( !editLink[0] ) { return; }

editLink.html('Archived').removeAttr('href').removeAttr('title').css('color','gray');

$('span.editsection-upper').remove;

} $( disableEditLink ); }

// Cleanup excessive space in hlist elements if (document.getElementsByClassName('hlist')[0]) {   var hlists = document.getElementsByClassName('hlist'); for (var i = 0; i < hlists.length; i++) {       var items = hlists[i].getElementsByTagName('li'); for (var j = 0; j < items.length; j++) items[j].innerHTML = items[j].innerHTML.trim; } }

/** Page format checking ********************************************************* * * Maintainers: User:Falzar FZ */ var mNamespace = mw.config.get('wgCanonicalNamespace'); var mAction   = mw.util.getParamValue('action'); var mPreload  = mw.util.getParamValue('preload'); var mRedlink  = mw.util.getParamValue('redlink'); var mUseFormat = mw.util.getParamValue('useFormat'); var mSection  = mw.util.getParamValue('section');

/*    * Check that you have signed your post on Talk pages and Forum pages.

* Disable for yourself on every page by adding: var signCheck = "Disable"; to Special:MyPage/common.js

* Alternatively, if you sign with 3 tildes, add: var signCheck = 3;

* To disable checking on a specific page for everyone, add: to that page somewhere, it will overlook it each time. */ if (mNamespace.match(/talk/i) || mNamespace == "Forum") { if (!document.URL.match("&undo") && !document.URL.match("/Archive")) { addOnloadHook(function {           $('#wpSave, #wpPreview').mousedown(signChecker);        });

var vSignCheckerCounter = 0; var mInitialLength = $('#wpTextbox1').val.length; function signChecker { var vTildes = '\'; var vForumMessage = "Be sure to sign your edits with four tildes: " + vTildes; // Bypassing the line in the forum template. var vNoWiki = " " + vTildes + " "; var vMinorChecked = $('#wpMinoredit').is(':checked'); var mFinalLength = $('#wpTextbox1').val.length;

var vText = $('#wpTextbox1').val.replace(vForumMessage, "").replace(vNoWiki, ""); if (vSignCheckerCounter < 3 && !vText.match(vTildes) &&                  vText != "{\{Talkheader}}" && !vText.match("{\{Delete") &&                   !vMinorChecked && !$('#wpSummary').val.match(/move/i) &&                   !$('#wpSummary').val.match(/archive/i) &&                   mFinalLength > mInitialLength + 15) { vSignCheckerCounter++; if (!window.signCheck) { alert("Please sign your post by adding 4 tildes (" + vTildes + ") to the end of your post."); } else if (window.signCheck == 3) { alert("Please sign your post by adding 3 tildes (~\) to the end of your post."); } else if (window.signCheck == "Disable") { vSignCheckerCounter = 9; }           }        }    } }

// Add Template:Navigation if it's not there. if (mNamespace == "Card_Gallery" ||       (mNamespace == "Card_Rulings" && $('#wpTextbox1').val.indexOf("[\[Category:Group Rulings") == -1) ||        mNamespace == "Card_Errata" ||        mNamespace == "Card_Tips" ||        mNamespace == "Card_Appearances" ||        mNamespace == "Card_Trivia" ||        mNamespace == "Card_Lores" ||        mNamespace == "Card_Artworks" ||        mNamespace == "Card_Names" ||        mNamespace == "Card_Sets") { if (!mSection && mAction != "submit" && typeof $('#wpTextbox1').val != 'undefined') { addOnloadHook(addNav);

function addNav { var vText = $('#wpTextbox1').val.replace("{\{navigation", "{\{Navigation").replace("{\{Navigation2}", "{\{Navigation|mode=nonGame}"); if (!vText.match("{\{Navigation") && !vText.match("{\{Delete")) { $('#wpTextbox1').val("{\{Navigation}}\n\n" + vText); } else { $('#wpTextbox1').val(vText); }

$('form[name=editform]').submit(function {               if ($('#wpTextbox1').val == "{\{Navigation}}\n\n") {                    alert("You have not made any changes to the template.");                    return false;                }            }); }   } }

// Add Template:Talkheader if it's not there. if (mNamespace.match(/talk/i) && mNamespace != "User_talk" && !mSection && mAction != "submit") { addOnloadHook(addTalkheader);

function addTalkheader { var vText = $('#wpTextbox1').val.replace("{\{talkheader", "{\{Talkheader"); if (!vText.match("{\{Talkheader") && !vText.match("{\{Delete")) { $('#wpTextbox1').val("{\{Talkheader}}\n\n" + vText); } else { $('#wpTextbox1').val(vText); }   } }

// Add a preload depending on the namespace during page creation from redlink. if (mRedlink) {

if (mNamespace == "Card_Tips" ||           mNamespace == "Card_Trivia" ||            mNamespace == "Card_Names") { var vCardNavTemplate = "{\{Navigation}}\n\n* "; // Deliberate no "\n" at the end. addOnloadHook(addPreload(vCardNavTemplate)); } else if (mNamespace == "Card_Gallery") { var vCardGalleryTemplate = "{\{Navigation}}\n\n{\{GalleryHeader|lang=en}}\n\n|}\n"; addOnloadHook(addPreload(vCardArtworksTemplate)); }

function addPreload(pBlankTemplate) { $('#wpTextbox1').val(pBlankTemplate);

$('#wpSave, #wpPreview').mousedown(cleanUpStuff); function cleanUpStuff { $('#wpTextbox1').val($('#wpTextbox1').val.replace("{\{Navigation2}}", "{\{Navigation|mode=nonGame}}")).replace("{\{Navigation3}}", "{\{Navigation|mode=otherGame}}"); }

$('form[name=editform]').submit(function {           if ($('#wpTextbox1').val == pBlankTemplate) {                alert("You have not made any changes to the template.");                return false;            }        });

}

}

// Prevent "accidental" save of the default (MediaWiki:Newpagelayout) "blank" new page template. if (mUseFormat) { addOnloadHook(function {       var vNewPageLayout = "Write the first paragraph of your article here.\n\n==Section heading==\n\nWrite the first section of your article here. \n\n==Section heading==\n\nWrite the second section of your article here.\n";        $('form[name=editform]').submit(function { if ($('#wpTextbox1').val == vNewPageLayout) { alert("You have not made any changes to the template."); return false; }       });    }); }

//Add missing preload to MediaWiki:Createbox-exists. Using js since there doesn't seem to be a "getURL" option in the wikia magic words. if (mAction == "create" && $('[name="preload"]').val === "") { $('[name="preload"]').val(mPreload); }

/* remove empty rows from transclusions */ $('.infobox tr').each(function {    if (!$.trim($(this).text) && !$(this).find('img').length && !$(this).find('hr').length ) $(this).remove; });

// Allow for redirecting Luster_Dragon#2 to Luster_Dragon_2 etc. via if ($('.hash_redirect')) {   var redirects = document.getElementsByClassName('hash_redirect'); var hash = window.location.hash.substring(1);

for (var i = 0; i < redirects.length; i++) if (redirects[i].getAttribute('data-value') == hash) window.location = window.location.href.replace('#', '_'); } // End of .hash_redirect

/* End of mw.loader.using callback; code should be added above this line */ } ); /* DO NOT ADD CODE BELOW THIS LINE */