מדיה ויקי:Block-newbie-edit.js

הערה: לאחר הפרסום, ייתכן שיהיה צורך לנקות את זיכרון המטמון (cache) של הדפדפן כדי להבחין בשינויים.

  • פיירפוקס / ספארי: להחזיק את המקש Shift בעת לחיצה על טעינה מחדש (Reload) או ללחוץ על צירוף המקשים Ctrl-F5 או Ctrl-R (במחשב מק: ⌘-R).
  • גוגל כרום: ללחוץ על צירוף המקשים Ctrl-Shift-R (במחשב מק: ⌘-Shift-R).
  • אינטרנט אקספלורר / אדג': להחזיק את המקש Ctrl בעת לחיצה על רענן (Refresh) או ללחוץ על צירוף המקשים Ctrl-F5.
  • אופרה: ללחוץ על Ctrl-F5.
/*

Prevent newbies from editing semi-protected pages.

Written by: [[User:Guycn2]] and [[User:קיפודנחש]]

*/

(function() {
	var ug = 	mw.config.get("wgUserGroups"),
		prot = mw.config.get("wgRestrictionEdit"),
		// run if page is semi-protectedted and user is autoconfirmed but not autopatroller, patroller, or an admin
		needToCheck = 
			prot[0] == 'autoconfirmed'
			&&	ug.includes('autoconfirmed')
			&&  ! ug.includes('autopatrolled')
			&&  ! ug.includes('patroller')
			&&  ! ug.includes('sysop');

	if (! needToCheck) {
		return;
	}
	
	// Check if user meets the requirements for editing semi-protected pages:
	mw.loader.using(["mediawiki.api", "mediawiki.util"], function() {
		new mw.Api().get({
			list: "users",
			usprop: "editcount|registration",
			ususers: mw.config.get("wgUserName")
		}).done(function(data) {
			var hasEnoughEdits = data.query.users[0].editcount >= 100;
			var registrationTimeInUnix = new Date(data.query.users[0].registration).getTime();
			var hasEnoughDays = ((Date.now() - registrationTimeInUnix) / 24 / 60 / 60 / 1000) >= 30;
			// autoconfirmed that does not meet hewiki criterion for "autoconfirmed"
			// vandalism filter will block save, so let's prevent edit, to save some tears.
			if (! hasEnoughEdits || ! hasEnoughDays) { 
				$(hideEditLinks);
				if (mw.config.get("wgAction") === "edit") {
					$(preventEditing);
				}
			}
		});
	});
	
	function hideEditLinks() {
		// Hide visual edit tab & links:
		$("#ca-ve-edit, .mw-editsection-visualeditor").hide();
		
		// Hide leftover pipe divider in section [edit] links:
		$(".mw-editsection-visualeditor").prev(".mw-editsection-divider").hide();
		
		// Change text and tooltip of edit tab & links.
		// Note that the HTML structure is a little different in certain skins.
		if (mw.config.get("skin") === "monobook") {
			$("#ca-edit > a").text("הצגת מקור");
		} else if (mw.config.get("skin") === "minerva") {
			$("#ca-edit")
				.text("הצגת מקור")
				.attr("title", "הצגת קוד המקור של פסקת הפתיח בדף זה");
		} else {
			$("#ca-edit > a > span").text("הצגת מקור");
		}
		$(".mw-editsection > a:first-of-type")
			.text("הצגת מקור")
			.attr("title", "הצגת קוד המקור של פסקה זו");
		$("#ca-edit > a")
			.attr({
				title: "הצגת קוד המקור של דף זה",
				href: mw.util.getUrl(mw.config.get('wgPageName'), { action: 'edit'})
			});
	}
	
	function preventEditing() {
		mw.loader.using("oojs-ui-windows", function() {
			// Notify user:
			OO.ui.alert($("<div>", {
				html: "<strong>לתשומת ליבך:</strong><br> דף זה <a href='/wiki/ויקיפדיה:דף_מוגן'>מוגן חלקית</a> מפני עריכה. בהתאם ל<a href='/wiki/ויקיפדיה:פרלמנט/ארכיון_62#הגדרת_משתמש_ותיק'>החלטה שהתקבלה על ידי קהילת ויקיפדיה</a>, רק משתמשים רשומים בעלי ותק של 30 ימים ו־100 עריכות לפחות יכולים לערוך דפים כאלה. מכיוון שחשבונך עדיין אינו עומד בתנאים הללו, אין באפשרותך לערוך דף זה."
			}));
		});
		
		// Make editing box read-only:
		$("textarea[name='wpTextbox1']").attr("readonly", true);
		
		// Hide edit toolbar & edit options:
		$("#wikiEditor-ui-toolbar, .editOptions, .mw-editTools").hide();
		
		// new source editor. somewhat partial
		var newsource = $('.ve-init-target-source');
		if (newsource.length) {
			var newTextArea = $('<textarea aria-label="עורך קוד מקור" tabindex="1" accesskey="," id="wpTextbox1" cols="80" rows="25" readonly="true" class="mw-editfont-monospace">');
			newsource.after(newTextArea);
			newsource.remove();
			new mw.Api().get(
				{
					action: 'parse',
					page: mw.config.get('wgPageName'),
					prop: 'wikitext'
				}).then(function(data) {
					newTextArea.val(data.parse.wikitext['*']);
				});
		}
	}
	
})();