Advertisement
Guest User

MediaWiki.js

a guest
Apr 4th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // --------------------------------------------------------
  2. // Variables
  3. // --------------------------------------------------------
  4. var action = mw.config.get("wgAction");
  5. var pageName = mw.config.get("wgPageName");
  6. var canonicalNamespace = mw.config.get("wgCanonicalNamespace");
  7. var server = mw.config.get("wgServer");
  8. var groups = mw.config.get("wgUserGroups");
  9.  
  10. // Any JavaScript here will be loaded for all users on every page load.
  11. mw.loader.load( '/index.php?title=MediaWiki:Tabs.js&action=raw&ctype=text/javascript' );
  12. mw.loader.load( '/index.php?title=MediaWiki:Toggle.js&action=raw&ctype=text/javascript' );
  13. mw.loader.load( '/index.php?title=MediaWiki:Scrollbar.js&action=raw&ctype=text/javascript' );
  14. mw.loader.load( '/index.php?title=MediaWiki:Fonts.js&action=raw&ctype=text/javascript' );
  15.  
  16. // --------------------------------------------------------
  17. // Rights
  18. // Sets a variable "rights" which will return "false" if the
  19. // currently logged in user is a bureaucrat, administrator, or autoconfirmed user. It will return true otherwise.
  20. // it also defines variables which may be used elsewhere in scripts.
  21. // --------------------------------------------------------
  22.  
  23. if (groups){
  24.  
  25.  var rights_isAuto = (groups.toString().indexOf('autoconfirmed') != -1);
  26.  var rights_isAdmin = (groups.toString().indexOf('sysop') != -1);
  27.  var rights_isCrat = (groups.toString().indexOf('bureaucrat') != -1);
  28.  var rights_isRetired= (groups.toString().indexOf('retired') != -1);
  29.  var rights = true;
  30. }
  31. else {
  32.  var rights = false;
  33. }
  34.  
  35. // --------------------------------------------------------
  36. // staffrights.js          (adapted from http://en.wikipedia.org/wiki/User:Ais523/adminrights.js)
  37. // This script changes the color of links to staffs' userpages in the bodyContent of Special, History pages, diff pages,
  38. // and old page revisions.
  39. // ("bodyContent" being everything but the tabs,personal links at the top of the screen and sidebar).
  40. //
  41. // Highlighting script. Based on [[User:ais523/highlightmyname.js]].
  42. // --------------------------------------------------------
  43.  
  44. var adminrights=new Array();
  45. var traineerights=new Array();
  46. var execrights=new Array();
  47. var botrights=new Array();
  48. var retiredrights=new Array();
  49.  
  50. adminrights['52katie']=1;
  51. adminrights['Clefairy52']=1;
  52. adminrights['Androidos18']=1;
  53. adminrights['Astroninja1']=1;
  54. adminrights['AzelleAx']=1;
  55. adminrights['Azelleax']=1;
  56. adminrights['Chuck']=1;
  57. adminrights['Caralista']=1;
  58. adminrights['EzloSpirit']=1;
  59. adminrights['Ezlospirit']=1;
  60. adminrights['KokoroSenshi']=1;
  61. adminrights['Link_Lab']=1;
  62. adminrights['Midoro']=1;
  63. adminrights['Pixel']=1;
  64. adminrights['SnorlaxMonster']=1;
  65. adminrights['Snorlaxmonster']=1;
  66. adminrights['Vaati_The_Wind_Demon']=1;
  67.  
  68. traineerights['Barquero']=1;
  69. adminrights['Barquero']=1;
  70. traineerights['Mrbarquero']=1;
  71. adminrights['Mrbarquero']=1;
  72. traineerights['Barquero13095']=1;
  73. adminrights['Barquero13095']=1;
  74. traineerights['Bwar']=1;
  75. adminrights['Bwar']=1;
  76. traineerights['Bwar1133']=1;
  77. adminrights['Bwar1133']=1;
  78. traineerights['Tralinde']=1;
  79. adminrights['Tralinde']=1;
  80. traineerights['Ganman3']=1;
  81. adminrights['Ganman3']=1;
  82. traineerights['Djanonx']=1;
  83. adminrights['Djanonx']=1;
  84. traineerights['Legend_of_Zelda_Freak']=1;
  85. adminrights['Legend_of_Zelda_Freak']=1;
  86. traineerights['Hylian_Pi']=1;
  87. adminrights['Hylian_Pi']=1;
  88. traineerights['Hylian_pi']=1;
  89. adminrights['Hylian_pi']=1;
  90. traineerights['Paragonfishhead']=1;
  91. adminrights['Paragonfishhead']=1;
  92. traineerights['Jjgodden']=1;
  93. adminrights['Jjgodden']=1;
  94. traineerights['benfitzy']=1;
  95. adminrights['benfitzy']=1;
  96. traineerights['Benfitzy']=1;
  97. adminrights['Benfitzy']=1;
  98. adminrights['MannedTooth']=1;
  99. traineerights['MannedTooth']=1;
  100.  
  101. execrights['Calebzw']=1;
  102. execrights['Cody']=1;
  103. execrights['Cody2958']=1;
  104. execrights['Codydaviestv']=1;
  105. execrights['GoldenChaos']=1;
  106. execrights['Hylian_King']=1;
  107. execrights['HylianKing']=1;
  108. execrights['Jason']=1;
  109. execrights['Joshua']=1;
  110. execrights['Justin']=1;
  111. execrights['Justin4408']=1;
  112. execrights['Shona']=1;
  113. execrights['Shona3212']=1;
  114. execrights['Tony']=1;
  115. execrights['TriforceTony']=1;
  116.  
  117. botrights['Ashler89']=1;
  118. botrights['KaeporaGaebora']=1;
  119. botrights['KaeporaGaebora4988']=1;
  120. botrights['Redirect_fixer']=1;
  121. botrights['The_Groosenator']=1;
  122. botrights['Yuga']=1;
  123. botrights['Yuga17953']=1;
  124. botrights['Rescue_Knight']=1;
  125.  
  126. retiredrights['Abdullah']=1;
  127. retiredrights['Abdullah5599']=1;
  128. retiredrights['Adam']=1;
  129. retiredrights['Adam660']=1;
  130. retiredrights['Alexander']=1;
  131. retiredrights['Ando']=1;
  132. retiredrights['Aranok']=1;
  133. retiredrights['AtrumLevis']=1;
  134. retiredrights['Autydi']=1;
  135. retiredrights['Axiomist']=1;
  136. retiredrights['Axle_the_Beast']=1;
  137. retiredrights['Bob23']=1;
  138. retiredrights['Captain_Cornflake']=1;
  139. retiredrights['Captain_Desdinova']=1;
  140. retiredrights['Cartoons']=1;
  141. retiredrights['Chocoroko']=1;
  142. retiredrights['Chrono']=1;
  143. retiredrights['Cipriano']=1;
  144. retiredrights['Dannyboy601']=1;
  145. retiredrights['Dany36']=1;
  146. retiredrights['Davogones']=1;
  147. retiredrights['Deku_Link']=1;
  148. retiredrights['DIUM']=1;
  149. retiredrights['Dustin']=1;
  150. retiredrights['EA']=1;
  151. retiredrights['Einstein95']=1;
  152. retiredrights['Eientei95']=1;
  153. retiredrights['Embyr_75']=1;
  154. retiredrights['EpicFaceLOL991']=1;
  155. retiredrights['Fizzle']=1;
  156. retiredrights['Fox']=1;
  157. retiredrights['Fury_Three']=1;
  158. retiredrights['Gateway2Drillbit ']=1;
  159. retiredrights['Hammer_Bro._Mike']=1;
  160. retiredrights['Henhouse']=1;
  161. retiredrights['Ice_Medallion']=1;
  162. retiredrights['Jin']=1;
  163. retiredrights['JohnGames']=1;
  164. retiredrights['K2L']=1;
  165. retiredrights['Kain']=1;
  166. retiredrights['Lahvu']=1;
  167. retiredrights['Lars']=1;
  168. retiredrights['Lee']=1;
  169. retiredrights['LegendZelda']=1;
  170. retiredrights['Leminnes']=1;
  171. retiredrights['Liyuanzao']=1;
  172. retiredrights['Lord-of-shadow']=1;
  173. retiredrights['Lord_of_the_Twilight']=1;
  174. retiredrights['Lozzie']=1;
  175. retiredrights['Mandi']=1;
  176. retiredrights['Mases']=1;
  177. retiredrights['Matt']=1;
  178. retiredrights['Melchizedek']=1;
  179. retiredrights['Minish_Link']=1;
  180. retiredrights['Mr._Wiggles']=1;
  181. retiredrights['Nathan']=1;
  182. retiredrights['Noble_Wrot']=1;
  183. retiredrights['Nox']=1;
  184. retiredrights['Owl']=1;
  185. retiredrights['Peefy']=1;
  186. retiredrights['Petenu']=1;
  187. retiredrights['PPLToast']=1;
  188. retiredrights['Sadida']=1;
  189. retiredrights['Sagasaki']=1;
  190. retiredrights['Scott']=1;
  191. retiredrights['SearanoX']=1;
  192. retiredrights['Shetani']=1;
  193. retiredrights['Shiningpikablu252']=1;
  194. retiredrights['Sluzorz']=1;
  195. retiredrights['Steven']=1;
  196. retiredrights['Steven2113']=1;
  197. retiredrights['Tappy']=1;
  198. retiredrights['The_Forbidden_One']=1;
  199. retiredrights['TheDarkHunter']=1;
  200. retiredrights['Thewindmaker']=1;
  201. retiredrights['Toby']=1;
  202. retiredrights['Trico']=1;
  203. retiredrights['Triforce_of_the_Gods']=1;
  204. retiredrights['Wielder_of_the_Sword']=1;
  205. retiredrights['WilliamLC']=1;
  206. retiredrights['Xizor']=1;
  207. retiredrights['Yami']=1;
  208.  
  209. function highlightstaff(n){ //node
  210.   while(n!=null){
  211.     if(n.nodeType==1&&n.tagName.toLowerCase()=="a"){ //anchor
  212.  
  213.       if(n.href.indexOf("/User:")!=-1){
  214.         var u=n.href.split("/User:")[1];
  215.         if(adminrights[u]==1)        n.className += " admin";
  216.         else if(execrights[u]==1)    n.className += " executive";
  217.         else if(botrights[u]==1)     n.className += " bot";
  218.         else if(retiredrights[u]==1) n.className += " retired";
  219.         if(traineerights[u]==1)      n.className += " trainee";
  220.       }
  221.  
  222.       else if(n.href.indexOf("/index.php?title=User:")!=-1){
  223.         var u=n.href.split("/index.php?title=User:")[1];
  224.         if(adminrights[u]==1)        n.className += " admin";
  225.         else if(execrights[u]==1)    n.className += " exec";
  226.         else if(botrights[u]==1)     n.className += " bot";
  227.         else if(retiredrights[u]==1) n.className += " retired";
  228.         if(traineerights[u]==1) n.className += " trainee";
  229.       }
  230.  
  231.       else
  232.         if(n.firstChild!=null) highlightstaff(n.firstChild);
  233.     }
  234.  
  235.     else{
  236.       if(n.firstChild!=null) highlightstaff(n.firstChild);
  237.     }
  238.     n=n.nextSibling;
  239.   }
  240. }
  241.  
  242.  
  243. if (canonicalNamespace == 'Special' || action == 'history' || document.URL.indexOf('diff=') > 0 || document.URL.indexOf('oldid=') > 0)
  244. {
  245.   $(document).ready(function() {
  246.     highlightstaff(document.getElementById('bodyContent').firstChild);
  247.   });
  248. }
  249.  
  250. // --------------------------------------------------------
  251. // last diff
  252. // Adds a tab which gives the latest diff for a page.
  253. // --------------------------------------------------------
  254. function lastdiff() {
  255.     mediaWiki.util.addPortletLink("p-cactions", server +  "/index.php?title=" + encodeURIComponent(pageName) + "&diff=cur&oldid=prev",
  256.         "last", "ca-last", "Show most recent diff", '2');
  257. }
  258. if (canonicalNamespace != 'Special' && action != 'edit' && action != 'delete' && action != 'watch' && action
  259. != 'unwatch' && action != 'protect'){
  260. $(document).ready(lastdiff);
  261. }
  262. //
  263.  
  264. // --------------------------------------------------------
  265. // redirects
  266. // adds a tab to the top of pages, when clicked it highlights all links on the page that are redirects.
  267. // --------------------------------------------------------
  268. if (canonicalNamespace != 'Special' && action != 'history' && action != 'delete' && action != 'watch' && action
  269. != 'unwatch' && action != 'protect' && action != 'markpatrolled' && action != 'rollback' && document.URL.indexOf('diff=') <= 0)
  270. {
  271. var highlightRedirects = {
  272.  
  273.  tab_redirects : null,
  274.  
  275.  addStylesheetRule : function(tag, style) {
  276.   var ss = document.styleSheets[0];
  277.   if (ss.insertRule) {
  278.    ss.insertRule(tag + '{' + style + '}', ss.cssRules.length);
  279.   } else if (ss.addRule) {
  280.    ss.addRule(tag, style);
  281.   }
  282.  },
  283.  
  284.  run : function()
  285.  {
  286.   highlightRedirects.addStylesheetRule('a.mw-redirect', 'color:black');
  287.   highlightRedirects.addStylesheetRule('a.mw-redirect', 'background-color:yellow');
  288.   highlightRedirects.addStylesheetRule('a.mw-redirect:visited', 'color:dimgrey');
  289.   highlightRedirects.addStylesheetRule('a.mw-redirect:visited', 'background-color:yellow');
  290.  },
  291.  
  292.  install : function()
  293.  {
  294.   with(highlightRedirects)
  295.   {
  296.    mediaWiki.util.addPortletLink ('p-cactions', 'javascript:highlightRedirects.run();', 'redirects', 'ca-redirects', 'Highlights all links which are redirects', 'r') ||
  297.    mediaWiki.util.addPortletLink ('views', 'javascript:highlightRedirects.run();', 'redirects', 'ca-redirects', 'Highlights all links which are redirects', 'r');
  298.   }
  299.  }
  300.  
  301. };
  302.  
  303. $(document).ready(highlightRedirects.install);
  304. }
  305. //
  306.  
  307.  
  308. // --------------------------------------------------------
  309. // Special:MovePage
  310. // Uncheck "Leave a redirect behind" if moving a file
  311. // --------------------------------------------------------
  312. $(function() {
  313.     var isMovingFile = pageName.startsWith("Special:MovePage/File");
  314.     if(isMovingFile) {
  315.         var leaveRedirectCheckbox = $("input[name=wpLeaveRedirect]")[0];
  316.         leaveRedirectCheckbox.checked = false;
  317.     }
  318. });
  319.  
  320.  
  321. // --------------------------------------------------------
  322. // Special:ExpandTemplates
  323. // Check "Suppress <nowiki> tags in result" when using ExpandTemplates
  324. // --------------------------------------------------------
  325. $(function() {
  326.         if (pageName == "Special:ExpandTemplates") {
  327.                 document.getElementById( 'removenowiki' ).checked = true;
  328.         }
  329. });
  330.  
  331.  
  332. // --------------------------------------------------------
  333. // ForcePreviewLite
  334. // A modified version of http://en.wikipedia.org/wiki/Wikipedia:WikiProject_User_scripts/Scripts/Force_edit_summary_alternative
  335. // NOTE: This is not a completed script, only a test of possible options for future addition. Implementation of this script would be done by combining the code of "function forceSummary()" into "function forcePreview()" at http://www.mediawiki.org/wiki/Manual:Force_preview
  336.  // --------------------------------------------------------
  337.  
  338. function addForceSummary()
  339. {
  340.     if(!/&action=edit/.test(window.location.href) && !/&action=submit/.test(window.location.href)) return;
  341.     if(/&section=new/.test(window.location.href)) return;
  342.     if(!document.forms.editform) return;
  343.     document.forms.editform.wpSave.onclick = forceSummary;
  344. }
  345.  
  346. function forceSummary()
  347. {
  348.         flashcolour(7);
  349.         document.forms.editform.wpSave.onclick = "";
  350.         return false;
  351. }
  352.  
  353. var flashcolour_timer;
  354. function flashcolour(count) {
  355.     if (count%2 == 1)
  356.         document.getElementById("wpPreview").style.backgroundColor = "silver";
  357.     else
  358.         document.getElementById("wpPreview").style.backgroundColor = "yellow";
  359.  
  360.  
  361.     if (flashcolour_timer != null) {
  362.         clearTimeout(flashcolour_timer);
  363.         flashcolour_timer = null;
  364.     }
  365.  
  366.     if (count > 0)
  367.         flashcolour_timer = window.setTimeout("flashcolour(" + (count-1) + ")",350);
  368. }
  369.  
  370. if (action != "submit" && rights == false)
  371. {
  372. $(document).ready(addForceSummary);
  373. }
  374.  
  375.  
  376. // --------------------------------------------------------
  377. // Contains citation templates to be added to the toolbar.
  378. // Source: [http://mediawiki.org/wiki/Manual:Custom_edit_buttons MediaWiki.org]
  379. // Credit to [[User:RAP|RAP]] for the images.
  380. // --------------------------------------------------------
  381.  
  382. // We begin by getting the date for use in certain citations.
  383.     var time = new Date();
  384.     var curday = time.getDate();
  385.     var month=new Array();
  386.     month[0]="January";
  387.     month[1]="February";
  388.     month[2]="March";
  389.     month[3]="April";
  390.     month[4]="May";
  391.     month[5]="June";
  392.     month[6]="July";
  393.     month[7]="August";
  394.     month[8]="September";
  395.     month[9]="October";
  396.     month[10]="November";
  397.     month[11]="December";
  398.     var curmonth = month[time.getMonth()];
  399.     var nowyear = time.getYear()+1900;
  400.     var nowday = curday.toString();
  401.     var nowmonth = curmonth.toString();
  402.  
  403. // Now we make the function itself
  404. var addExtraButtons = function(){
  405.  
  406. // Start with web cite
  407.         mw.toolbar.addButton( {
  408.                 imageFile: 'https://zeldawiki.org/images/9/91/Button_cite_web.png',
  409.                 speedTip: 'Web Citation',
  410.                 tagOpen: "<ref>{{Cite web|quote= |author= |published= |retrieved=" + nowmonth + " " + nowday + ", " + nowyear + "|url= |title= |site= |type=",
  411.                 tagClose: '}}</ref>',
  412.                 sampleText: '',
  413.                 imageId: ''
  414.         } );
  415. // Cite book
  416. mw.toolbar.addButton( {
  417.                 imageFile: 'https://zeldawiki.org/images/e/ef/Button_cite_book.png',
  418.                 speedTip: 'Cite book',
  419.                 tagOpen: '<ref>{{Cite book|quote= |book= |publisher= |page= ',
  420.                 tagClose: '}}</ref>',
  421.                 sampleText: '',
  422.                 imageId: ''
  423.         } );
  424.  
  425. // Cite person
  426. mw.toolbar.addButton( {
  427.                 imageFile: 'https://zeldawiki.org/images/5/53/Button_cite_person.png',
  428.                 speedTip: 'Cite person',
  429.                 tagOpen: '<ref>{{Cite person|quote= |name= |url= |title= ',
  430.                 tagClose: '}}</ref>',
  431.                 sampleText: '',
  432.                 imageId: ''
  433.         } );
  434.  
  435. // Cite episode
  436. mw.toolbar.addButton( {
  437.                 imageFile: 'https://zeldawiki.org/images/1/1c/Button_cite_episode.png',
  438.                 speedTip: 'Cite episode',
  439.                 tagOpen: '<ref>{{Cite episode|quote= |name= |show= |episode= |time= ',
  440.                 tagClose: '}}</ref>',
  441.                 sampleText: '',
  442.                 imageId: ''
  443.         } );
  444.  
  445. // Cite manual
  446. mw.toolbar.addButton( {
  447.                 imageFile: 'https://zeldawiki.org/images/5/5d/Button_cite_manual.png',
  448.                 speedTip: 'Cite manual',
  449.                 tagOpen: '<ref>{{Cite manual|quote= |game= |page= ',
  450.                 tagClose: '}}</ref>',
  451.                 sampleText: '',
  452.                 imageId: ''
  453.         } );
  454.  
  455. // Regular cite template
  456. mw.toolbar.addButton( {
  457.                 imageFile: 'https://zeldawiki.org/images/2/20/Button_cite_template.png',
  458.                 speedTip: 'Regular citation',
  459.                 tagOpen: '<ref>{{Cite|(Quote)|(Person)|(Game)',
  460.                 tagClose: '}}</ref>',
  461.                 sampleText: '',
  462.                 imageId: ''
  463.         } );
  464.  
  465. };
  466.  
  467. if( $.inArray( action, [ 'edit', 'submit' ] ) !== -1 ) {
  468.         mw.loader.using( 'user.options', function () {
  469.                 if ( ! mw.user.options.get( 'usebetatoolbar' ) ) {
  470.                         mw.loader.using( 'mediawiki.action.edit', function(){
  471.                                 $( addExtraButtons );
  472.                         } );
  473.                 }
  474.         } );
  475. }
  476.  
  477. // --------------------------------------------------
  478. // Page logs. Because they're not just for admins :P
  479. // --------------------------------------------------
  480. if (canonicalNamespace != "Special"){
  481. mediaWiki.util.addPortletLink("p-tb", "http://zeldawiki.org/index.php?title=Special%3ALog&type=&user=&page=" + pageName,
  482.         "Page Logs", "t-logs", "Show all relevant logs for this page.", '3');
  483. }
  484.  
  485. // --------------------------------------------------
  486. // Preview button for Special:Upload
  487. // --------------------------------------------------
  488. if (pageName == 'Special:Upload')
  489. {
  490.   mw.loader.load( '/index.php?title=MediaWiki:UploadPreview.js&action=raw&ctype=text/javascript' );
  491. }
  492.  
  493. /**
  494.  * Force lowercase file extensions
  495.  */
  496. function force_lowercase(){
  497.     $('#mw-upload-form').on('submit', function(){
  498.         var dest = $('#wpDestFile').val();
  499.         var ext = dest.split("").reverse().join("").split('.');
  500.         ext = ext[0].split("").reverse().join("").toLowerCase();
  501.         $('#wpDestFile').val(dest.slice(0, -3) + ext);
  502.     });
  503. }
  504. $(force_lowercase());
  505.  
  506. ///CrazyEgg Tracking
  507. setTimeout(function(){var a=document.createElement("script");
  508. var b=document.getElementsByTagName("script")[0];
  509. a.src=document.location.protocol+"//script.crazyegg.com/pages/scripts/0011/8371.js?"+Math.floor(new Date().getTime()/3600000);
  510. a.async=true;a.type="text/javascript";b.parentNode.insertBefore(a,b)}, 1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement