לדלג לתוכן

מדיה ויקי:AlertProtected.js: הבדלים בין גרסאות בדף

מתוך צפונות ויקי
מאין תקציר עריכה
depracation
שורה 9: שורה 9:
function protectNotice()
function protectNotice()
{
{
  if ( !mw.config.get('wgRestrictionEdit') || ( mw.config.get('wgRestrictionEdit')[0] != 'sysop' && mw.config.get('wgRestrictionEdit')[0] != 'autoconfirmed' && mw.config.get('wgRestrictionEdit')[0]!='autopatrol') ) return; // only protected pages
  var restrictionEdits = mw.config.get('wgRestrictionEdit') || [],
  if ( wgNamespaceNumber != 0 ) return; // only main namespace
restrictFirst = restrictionEdits[0];
  if ( wgAction != 'view' && wgAction != 'submit' ) return; // only view or preview mode
if ( $.inArray( restrictFirst, ['sysop', 'aautoconfirmed', 'autopatrol' ]) === -1 )  
  if ( document.getElementById('pl-noprotectionnotice') ) return; // no {{תב|ללא הודעת הגנה אוטומטית}} templates
return; // only protected pages
if ( document.getElementById('pl-autoconfirmed') ) return; // no {{תב|מוגן חלקית}} templates
  if ( mw.config.get( 'wgNamespaceNumber' ) != 0 ) return; // only main namespace
if ( document.getElementById('pl-protected') ) return; // no {{תב|מוגן}} templates
  if ( $.inArray( mw.config.get( 'wgAction' ), ['view', 'submit'] ) === -1 ) return; // only view or preview mode
  if ( $( '#pl-noprotectionnotice, #pl-autoconfirmed, #pl-protected').length ) return;  


  // load appropriate template according to protection level
  // load appropriate template according to protection level
  var templateUrl = wgServer + wgScriptPath + '/index.php?action=render&title=';
  var templateUrl = mw.util.wikiScript()  + '?action=render&title=';
  if (wgRestrictionEdit[0] == 'sysop')
  if (restrictFirst == 'sysop')
   templateUrl += encodeURIComponent('תבנית:מוגן/קוד');
   templateUrl += encodeURIComponent('תבנית:מוגן/קוד');
  else if(wgRestrictionEdit[0] == 'autopatrol')
  else if( restrictFirst == 'autopatrol')
   templateUrl += encodeURIComponent('תבנית:הגנה מוגברת/קוד');
   templateUrl += encodeURIComponent('תבנית:הגנה מוגברת/קוד');
  else
  else
שורה 31: שורה 32:
   // adjust text (links mainly)
   // adjust text (links mainly)
   var adjustedText = a.responseText;
   var adjustedText = a.responseText;
   var talklink = '<a href="/wiki/' + encodeURIComponent('שיחה:' + wgTitle) + '" title="דף השיחה">דף השיחה</a>';
   var talklink = '<a href="/wiki/' + encodeURIComponent('שיחה:' + mw.config.get( 'wgTitle' ) ) + '" title="דף השיחה">דף השיחה</a>';
   adjustedText = adjustedText.replace(/PLPROTECTEDTALK/g, talklink);
   adjustedText = adjustedText.replace(/PLPROTECTEDTALK/g, talklink);
   var histlink = '<a href="//he.wikipedia.org/w/index.php?title=' + encodeURIComponent(wgTitle) + '&action=history" title="דף הגרסאות הקודמות">דף הגרסאות הקודמות</a>';
   var histlink = '<a href="//he.wikipedia.org/w/index.php?title=' + encodeURIComponent(wgTitle) + '&action=history" title="דף הגרסאות הקודמות">דף הגרסאות הקודמות</a>';
שורה 50: שורה 51:
}
}


if ( wgNamespaceNumber === 0 && mw.config.get('wgRestrictionEdit') && ( mw.config.get('wgAction') === 'view' || mw.config.get('wgAction') === 'submit' ) ) $( protectNotice );
if ( mw.config.get( 'wgNamespaceNumber' ) === 0 && mw.config.get('wgRestrictionEdit') && ( mw.config.get('wgAction') === 'view' || mw.config.get('wgAction') === 'submit' ) ) $( protectNotice );

גרסה מ־22:26, 16 בינואר 2015

/*
 * 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()
{
 var restrictionEdits = mw.config.get('wgRestrictionEdit') || [],
 	restrictFirst = restrictionEdits[0];
 if ( $.inArray( restrictFirst, ['sysop', 'aautoconfirmed', 'autopatrol' ]) === -1 ) 
 	return; // only protected pages
 if ( mw.config.get( 'wgNamespaceNumber' ) != 0 ) return; // only main namespace
 if ( $.inArray( mw.config.get( 'wgAction' ), ['view', 'submit'] ) === -1 ) return; // only view or preview mode
 if ( $( '#pl-noprotectionnotice, #pl-autoconfirmed, #pl-protected').length ) return; 

 // load appropriate template according to protection level
 var templateUrl = mw.util.wikiScript()  + '?action=render&title=';
 if (restrictFirst == 'sysop')
  templateUrl += encodeURIComponent('תבנית:מוגן/קוד');
 else if( restrictFirst == 'autopatrol')
   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('שיחה:' + mw.config.get( 'wgTitle' ) ) + '" title="דף השיחה">דף השיחה</a>';
  adjustedText = adjustedText.replace(/PLPROTECTEDTALK/g, talklink);
  var histlink = '<a href="//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);
}

if ( mw.config.get( 'wgNamespaceNumber' ) === 0 && mw.config.get('wgRestrictionEdit') && ( mw.config.get('wgAction') === 'view' || mw.config.get('wgAction') === 'submit' ) ) $( protectNotice );