MediaWiki:Common.js

From BoyWiki
Revision as of 08:15, 28 April 2014 by Pinocchio (talk | contribs) (cleaning useless code)

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */



/* Manage call to function() on submit action before sendind the page  */

function initeventpostform() {
   if (wgAction == 'edit' || wgAction == 'submit') {
      if (document.forms['editform'] == undefined || document.forms['editform'].elements['wpTextbox1'] == undefined) return;
      document.forms['editform'].onsubmit = function() {
        /* for agora pages: append section title link */
         pgagora_insert_topsection();
         /* other function */
      }
   }
}

addOnloadHook(initeventpostform);



/* Append an Agora link to Navigation menu (if connected) */

function addlinkportletmenu() {
  if (wgUserName != null)
  addPortletLink("p-navigation", "https://www.boywiki.org/en/BoyWiki:Agora", "Agora", "n-agora", "A place to discuss the administration and editing of BoyWiki");
}

addOnloadHook(addlinkportletmenu);



/* For the 'dialogue' pages attribute the dialog class to body */
/* Used by css to colorize indentation in Agora */

function attrib_class_dialog() {
  /* only for Agora or discussion pages */
  var bodyclass = document.body.className;
  if (bodyclass.match(/page-BoyWiki_Agora/) || bodyclass.match(/ns-talk/))
     document.body.className = bodyclass + ' dialog';
}

addOnloadHook(attrib_class_dialog);



/* Agora : if new sub-page created append a title section link (called by submit) */

function pgagora_insert_topsection() {
   /* only if agora new page and write permission */
   if (wgAction != 'edit' && wgAction != 'submit') return true;
   if (wgUserGroups == null || wgUserGroups.join(" ").match(/user|sysop|bureaucrat/) == null) return true;
   if (wgPageName == null || wgPageName.match(/^BoyWiki:Agora\//) == null) return true;
   if (wgTitle == null) return true;
   if (wgArticleId != 0) return true;
   if (document.forms['editform'].elements['wpSummary'] == undefined) return true;
   if (document.getElementById('wpSummaryLabel').firstChild.firstChild.data.match(/Subject.*\/.*headline/) == null) return true;
   
   /* retrieve text */
   var content = document.forms['editform'].elements['wpTextbox1'].value;
   /* if title already present */
   if (content.match(/^\n?=\[\[[^\]\/]*Agora\/[^\]]*\]\]=/)) return true;
   /* otherwise copy subject sub-title */
   var sujet = document.forms['editform'].elements['wpSummary'].value;
   document.forms['editform'].elements['wpSummary'].value = "";
   if (sujet.length) sujet = "=="+sujet+"==\n";
   /* and insert title + subject at beginning of page */
   var titre = "=[[BoyWiki:"+wgTitle+"|"+wgTitle+"]]=\n";
   document.forms['editform'].elements['wpTextbox1'].value =  titre + sujet + content;
   return true;
}