MediaWiki:Monobook.js: Difference between revisions
From BoyWiki
No edit summary |
No edit summary |
||
Line 5: | Line 5: | ||
function addlinkportletmenu() { | function addlinkportletmenu() { | ||
if (wgUserName != null) | if (wgUserName != null) | ||
addPortletLink("p-navigation", "https://en.boywiki.org/wiki/BoyWiki:Agora", | addPortletLink("p-navigation", "https://en.boywiki.org/wiki/BoyWiki:Agora", "Agora", "n-agora", "A place to discuss the administration and editing of BoyWiki"); | ||
"Agora", "n-agora", "A place to discuss the administration and editing of BoyWiki"); | |||
} | } | ||
Line 25: | Line 24: | ||
addOnloadHook(attrib_class_dialog); | addOnloadHook(attrib_class_dialog); | ||
/* Agora : if new sub-page created append | /* Agora : if new sub-page created append a title section link (called by | ||
submit) */ | submit) */ | ||
Line 31: | Line 30: | ||
/* only if agora new page and write permission */ | /* only if agora new page and write permission */ | ||
if (wgAction != 'edit' && wgAction != 'submit') return true; | if (wgAction != 'edit' && wgAction != 'submit') return true; | ||
if (wgUserGroups == null || wgUserGroups.join(" | if (wgUserGroups == null || wgUserGroups.join("").match(/scribe|sysop|fsc|bureaucrat/) == null) return true; | ||
").match(/scribe|sysop|fsc|bureaucrat/) == null) return true; | if (wgPageName == null || wgPageName.match(/^BoyWiki:Agora\//) == null) return true; | ||
if (wgPageName == null || wgPageName.match(/^BoyWiki:Agora\//) == null) | |||
return true; | |||
if (wgTitle == null) return true; | if (wgTitle == null) return true; | ||
if (wgArticleId != 0) return true; | if (wgArticleId != 0) return true; | ||
if (document.forms['editform'].elements['wpSummary'] == undefined) return true; | if (document.forms['editform'].elements['wpSummary'] == undefined) return true; | ||
if | if (document.getElementById('wpSummaryLabel').firstChild.firstChild.data.match(/Subject\/title/) == null) return true; | ||
(document.getElementById('wpSummaryLabel').firstChild.firstChild.data.match(/ | |||
== null) return true; | |||
/* retrieve text */ | /* retrieve text */ | ||
Line 47: | Line 42: | ||
if (content.match(/^\n?=\[\[[^\]\/]*Agora\/[^\]]*\]\]=/)) return true; | if (content.match(/^\n?=\[\[[^\]\/]*Agora\/[^\]]*\]\]=/)) return true; | ||
/* otherwise copy subject sub-title */ | /* otherwise copy subject sub-title */ | ||
var subject = document.forms['editform'].elements['wpSummary'].value; | var subject = document.forms['editform'].elements['wpSummary'].value; document.forms['editform'].elements['wpSummary'].value = ""; if (subject.length) subject = "=="+subject+"==\n"; | ||
/* and insert title + subject at beginning of page */ | /* and insert title + subject at beginning of page */ | ||
var title = "=[[BoyWiki:"+wgTitle+"|"+wgTitle+"]]=\n"; | var title = "=[[BoyWiki:"+wgTitle+"|"+wgTitle+"]]=\n"; document.forms['editform'].elements['wpTextbox1'].value = title + subject + content; return true; | ||
+ content; | |||
} | } | ||
Line 60: | Line 50: | ||
function initeventpostform() { | function initeventpostform() { | ||
if (wgAction == 'edit' || wgAction == 'submit') { | if (wgAction == 'edit' || wgAction == 'submit') {if (document.forms['editform'] == undefined || document.forms['editform'].elements['wpTextbox1'] == undefined) return; document.forms['editform'].onsubmit = function() | ||
{ | |||
document.forms['editform'].elements['wpTextbox1'] == undefined) return; | |||
/* for agora pages: append section title link */ | /* for agora pages: append section title link */ | ||
pgagora_insert_topsection(); | pgagora_insert_topsection(); |
Revision as of 19:33, 24 September 2012
/* Any JavaScript here will be loaded for users using the MonoBook skin */
/* Append an Agora link to Navigation menu (if connected) */
function addlinkportletmenu() {
if (wgUserName != null)
addPortletLink("p-navigation", "https://en.boywiki.org/wiki/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(/page-Discussion_/)
|| bodyclass.match(/page-Discuss_/))
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(/scribe|sysop|fsc|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\/title/) == 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 subject = document.forms['editform'].elements['wpSummary'].value; document.forms['editform'].elements['wpSummary'].value = ""; if (subject.length) subject = "=="+subject+"==\n";
/* and insert title + subject at beginning of page */
var title = "=[[BoyWiki:"+wgTitle+"|"+wgTitle+"]]=\n"; document.forms['editform'].elements['wpTextbox1'].value = title + subject + content; return true;
}
/* 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);