מדיה ויקי:AlertProtected.js: הבדלים בין גרסאות בדף
מראה
אין תקציר עריכה |
סקריפט מעודכן |
||
| שורה 7: | שורה 7: | ||
*/ | */ | ||
function | function protectNotice() | ||
{ | { | ||
if ( wgRestrictionEdit[0] != 'sysop' && wgRestrictionEdit[0] != 'autoconfirmed' ) return; // only protected pages | |||
if ( wgNamespaceNumber != 0 ) return; // only main namespace | |||
if ( wgAction != 'view' && wgAction != 'submit' ) return; // only view or preview mode | |||
if ( document.getElementById('pl-noprotectionnotice') ) return; // no {{תב|ללא הודעת הגנה אוטומטית}} templates | |||
if ( document.getElementById('pl-autoconfirmed') ) return; // no {{תב|מוגן חלקית}} templates | |||
if ( document.getElementById('pl-protected') ) return; // no {{תב|מוגן}} templates | |||
// load appropriate template according to protection level | |||
var templateUrl = wgServer + wgScriptPath + '/index.php?action=render&title='; | |||
if (wgRestrictionEdit[0] == 'sysop') | |||
templateUrl += encodeURIComponent('תבנית:מוגן/קוד'); | |||
else | |||
templateUrl += encodeURIComponent('תבנית:מוגן חלקית/קוד'); | |||
var a = sajax_init_object(); | |||
a.open('GET', templateUrl, true); | |||
a.onreadystatechange = function() { | |||
if (a.readyState != 4) return; | |||
// adjust text (links mainly) | |||
var adjustedText = a.responseText; | |||
var talklink = '<a href="/wiki/' + encodeURIComponent('שיחה:' + wgTitle) + '" title="דף השיחה">דף השיחה</a>'; | |||
adjustedText = adjustedText.replace(/PLPROTECTEDTALK/g, talklink); | |||
var histlink = '<a href="http://he.wikipedia.org/w/index.php?title=' + encodeURIComponent(wgTitle) + '&action=history" title="דף הגרסאות הקודמות">דף הגרסאות הקודמות</a>'; | |||
adjustedText = adjustedText.replace(/PLPROTECTEDPAGE/g, histlink); | |||
// add text to container | |||
var divContainer = document.createElement('div'); | |||
divContainer.className = 'plprotected'; | |||
divContainer.innerHTML = adjustedText; | |||
// attach container before categories (or footer) | |||
var attachHere = document.getElementById('catlinks'); | |||
if (!attachHere) attachHere = getElementsByClassName(document, 'DIV', 'printfooter')[0]; | |||
attachHere.parentNode.insertBefore(divContainer, attachHere); | |||
}; | |||
a.send(null); | |||
} | } | ||
addOnloadHook( | addOnloadHook(protectNotice); | ||
גרסה מ־00:39, 27 בספטמבר 2009
/*
* Adds an automatic "{{תב|מוגן}}" or "{{תב|מוגן חלקית}}" template when the page is protected.
* You can use the {{תב|ללא הודעת הגנה אוטומטית}} to prevent the protection notice from being inserted.
*
* written by [[User:Yonidebest]]
*
*/
function protectNotice()
{
if ( wgRestrictionEdit[0] != 'sysop' && wgRestrictionEdit[0] != 'autoconfirmed' ) return; // only protected pages
if ( wgNamespaceNumber != 0 ) return; // only main namespace
if ( wgAction != 'view' && wgAction != 'submit' ) return; // only view or preview mode
if ( document.getElementById('pl-noprotectionnotice') ) return; // no {{תב|ללא הודעת הגנה אוטומטית}} templates
if ( document.getElementById('pl-autoconfirmed') ) return; // no {{תב|מוגן חלקית}} templates
if ( document.getElementById('pl-protected') ) return; // no {{תב|מוגן}} templates
// load appropriate template according to protection level
var templateUrl = wgServer + wgScriptPath + '/index.php?action=render&title=';
if (wgRestrictionEdit[0] == 'sysop')
templateUrl += encodeURIComponent('תבנית:מוגן/קוד');
else
templateUrl += encodeURIComponent('תבנית:מוגן חלקית/קוד');
var a = sajax_init_object();
a.open('GET', templateUrl, true);
a.onreadystatechange = function() {
if (a.readyState != 4) return;
// adjust text (links mainly)
var adjustedText = a.responseText;
var talklink = '<a href="/wiki/' + encodeURIComponent('שיחה:' + wgTitle) + '" title="דף השיחה">דף השיחה</a>';
adjustedText = adjustedText.replace(/PLPROTECTEDTALK/g, talklink);
var histlink = '<a href="http://he.wikipedia.org/w/index.php?title=' + encodeURIComponent(wgTitle) + '&action=history" title="דף הגרסאות הקודמות">דף הגרסאות הקודמות</a>';
adjustedText = adjustedText.replace(/PLPROTECTEDPAGE/g, histlink);
// add text to container
var divContainer = document.createElement('div');
divContainer.className = 'plprotected';
divContainer.innerHTML = adjustedText;
// attach container before categories (or footer)
var attachHere = document.getElementById('catlinks');
if (!attachHere) attachHere = getElementsByClassName(document, 'DIV', 'printfooter')[0];
attachHere.parentNode.insertBefore(divContainer, attachHere);
};
a.send(null);
}
addOnloadHook(protectNotice);