انتقل إلى المحتوى

مستخدم:حبيشان/Gadget-BandeauxPortails.js

من ويكيبيديا، الموسوعة الحرة

ملاحظة: بعد الحفظ، قد يلزمك محو الاختزان لرؤية التغييرات (محو الاختزان الآن).

// @source [[:fr:MediaWiki:Gadget-BandeauxPortails.js]]

/////////////////////////////////////////////////////////////////////////////////// Variables personnalisables

// Publication automatique
if (typeof window.BandeauxPortails_AutoEdit === 'undefined') window.BandeauxPortails_AutoEdit = true;

// Modification mineure
if (typeof window.BandeauxPortails_MinorEdit === 'undefined') window.BandeauxPortails_MinorEdit = true;

// Ajout à la liste de suivi ( -1 = défaut préférences, 0 = jamais, 1 = toujours)
if (typeof window.BandeauxPortails_Watchthis === 'undefined') window.BandeauxPortails_Watchthis = -1;

// Nombre de suggestions
if (typeof window.BandeauxPortails_TailleListe === 'undefined') window.BandeauxPortails_TailleListe = 10;

// Affichage des suggestions vers le bas
if (typeof window.BandeauxPortails_ListeBas === 'undefined') window.BandeauxPortails_ListeBas = false;

// Affichage des redirections de bandeaux
if (typeof window.BandeauxPortails_ShowRedirect === 'undefined') window.BandeauxPortails_ShowRedirect = false;

// Non-confirmation de la suppression des bandeaux
if (typeof window.BandeauxPortails_SkipConfirm === 'undefined') window.BandeauxPortails_SkipConfirm = false;

// Groupe nécessaire pour appliquer une balise
if (typeof window.BandeauxPortails_TagGroup === 'undefined') window.BandeauxPortails_TagGroup = "user";

// Balise à appliquer aux modifs
if (typeof window.BandeauxPortails_Tag === 'undefined') {
	window.BandeauxPortails_Tag = "";
	if (mw.config.get('wgServer') == '//ar.wikipedia.org') window.BandeauxPortails_Tag = "تعديل شريط البوابات";
}

var BandeauxPortails_EditParams = {};

var conf = mw.config.values;
// when running on mobile domain - do not use wgServer.
var wgServer = window.location.host.indexOf('.m.') > -1 ?
	'//' + window.location.host : conf.wgServer;

/////////////////////////////////////////////////////////////////////////////////// Édition

var BandeauxPortails_ajax = {
	http: function (bundle) {
		var xmlhttp;
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			try {
				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {
					xmlhttp = false;
				}
			}
		}
		if (xmlhttp) {
			xmlhttp.onreadystatechange = function () {
				if (xmlhttp.readyState == 4)
					BandeauxPortails_ajax.httpComplete(xmlhttp, bundle);
			};
			xmlhttp.open(bundle.method ? bundle.method : "GET", bundle.url, bundle.async == false ? false : true);
			if (bundle.headers) {
				for (var field in bundle.headers)
					try {
						xmlhttp.setRequestHeader(field, bundle.headers[field]);
					} catch (err) { }
			}
			xmlhttp.send(bundle.data ? bundle.data : null);
		}
		return xmlhttp;
	},
	httpComplete: function (xmlhttp, bundle) {
		if (xmlhttp.status == 200 || xmlhttp.status == 302) {
			if (bundle.onSuccess) bundle.onSuccess(xmlhttp, bundle);
		} else if (bundle.onFailure) {
			bundle.onFailure(xmlhttp, bundle);
		}
	}
};

// Nettoyage modèle (espaces, retour à la ligne, pipes)
function BandeauxPortails_CleanModele(Modele) {
	Modele = Modele.replace(/\n/ig, "");
	Modele = Modele.replace(/ \|/ig, "\|");
	Modele = Modele.replace(/\| /ig, "\|");
	Modele = Modele.replace(/\|\|/ig, "\|");
	Modele = Modele.replace(/\|\}/ig, "\}");
	return Modele;
}

window.BandeauxPortails_gettag = function () {
	if (!BandeauxPortails_Tag || !BandeauxPortails_TagGroup) return false;
	var UserGroups = conf.wgUserGroups;
	if (UserGroups === null) UserGroups = ["*"];
	if (UserGroups.indexOf(BandeauxPortails_TagGroup) !== -1) return BandeauxPortails_Tag;
	return false;
};

function BandeauxPortails_DoEdit(Req, data) {
	while (document.body.firstChild) { document.body.removeChild(document.body.firstChild); }
	document.body.innerHTML = Req.responseText;
	var TextArea = document.getElementById('wpTextbox1');
	if (!TextArea) return;
	if (BandeauxPortails_AutoEdit) document.editform.style.display = "none";

	var RemovePortalText = data.remove;
	var AddPortalText = data.add;
	if (AddPortalText) AddPortalText = AddPortalText.replace(/\|$/g, '');

	var OldText = TextArea.value;
	OldText = OldText.replace(/\{\{شريط بوابة /ig, "\{\{شريط بوابات\|"); // Cas d'un bandeau unique : {{شريط بوابات Truc}} -> {{شريط بوابات|Truc}}

	if ((OldText.indexOf('{{شريط بوابات|') != -1) || (OldText.indexOf('{{شريط بوابة|') != -1)) {
		// ==================================================================================== Il y a déjà un modèle {{شريط بوابات}}
		var AvantModeleUp = OldText.substring(0, OldText.indexOf('{{شريط بوابات'));
		var AvantModeleLow = OldText.substring(0, OldText.indexOf('{{شريط بوابة'));
		var ApresModele = OldText.split(AvantModeleUp).join('').split(AvantModeleLow).join('');
		var DebutModele = OldText.split(ApresModele).join('');
		var OldModele = ApresModele.substring(0, ApresModele.indexOf('}}')) + '}}';
		var SuiteModele = ApresModele.split(OldModele).join('');

		OldModele = BandeauxPortails_CleanModele(OldModele);

		if (AddPortalText) {
			if (((OldModele.indexOf('|' + AddPortalText + '|') != -1) || (OldModele.indexOf('|' + AddPortalText + '}') != -1))) {
				alert('بوابة ' + AddPortalText + ' موجودة.');
				document.editform.style.display = "";
				return;
			}
		}
		if (RemovePortalText && AddPortalText) {
			var NouveauModele = OldModele;
			NouveauModele = NouveauModele.split('|' + RemovePortalText + '|').join('|');
			NouveauModele = NouveauModele.split('|' + RemovePortalText + '}}').join('}}');
			NouveauModele = NouveauModele.split('}}').join('|' + AddPortalText + '}}');
			var Sommaire = 'تعديل سريع ل{{شريط بوابات}}: حذف  ' + RemovePortalText + ' وإضافة ' + AddPortalText.replace(/\|/g, "، ");
		} else if (RemovePortalText) {
			var NouveauModele = OldModele;
			NouveauModele = NouveauModele.split('|' + RemovePortalText + '|').join('|');
			NouveauModele = NouveauModele.split('|' + RemovePortalText + '}}').join('}}');
			var Sommaire = 'حذف [[قالب:شريط بوابات|بوابة]] ' + RemovePortalText;
		} else if (AddPortalText) {
			var NouveauModele = OldModele.split('}}').join('|' + AddPortalText + '}}');
			var Sommaire = 'إضافة [[قالب:شريط بوابات|بوابة]] ' + AddPortalText.replace(/\|/g, "، ");
		}
		NouveauModele = BandeauxPortails_CleanModele(NouveauModele);
		if (NouveauModele.indexOf('|') == -1) {
			if (BandeauxPortails_SkipConfirm || confirm('خطأ :\nيجب إضافة بوابة واحدة على الأقل.\n\nأتريد إزالة [[قالب:شريط بوابات|قالب البوابات]]؟')) {
				NouveauModele = "";
			} else {
				document.editform.style.display = "block";
				return;
			}
		}
	} else {
		// ==================================================================================== Il n'y a pas de modèle {{شريط بوابات}}
		if (!AddPortalText) {
			alert('ما من بوابة للإضافة.');
			document.editform.style.display = "";
			return;
		}
		var NouveauModele = '{{شريط بوابات|' + AddPortalText + '}}\n\n';
		var Sommaire = 'إضافة [[قالب:شريط بوابات|بوابة]] ' + AddPortalText.replace(/\|/g, " , + ");
		if ((OldText.indexOf('{{DEFAULTSORT:') != -1) || (OldText.indexOf('{{ترتيب_افتراضي:') != -1) || (OldText.indexOf('{{ترتيب_غيابي:') != -1) || (OldText.indexOf('[[تصنيف:') != -1) || (OldText.indexOf('[[Category:') != -1) || (OldText.indexOf('[[category:') != -1)) {
			// ------------------------------------------------------------------------------------ Il y a des تصنيفs
			var DebutModele1 = OldText.substring(0, OldText.indexOf('{{DEFAULTSORT:'));
			var DebutModele2 = OldText.substring(0, OldText.indexOf('{{ترتيب_افتراضي:'));
			var DebutModele3 = OldText.substring(0, OldText.indexOf('{{ترتيب_غيابي:'));
			var DebutModele4 = OldText.substring(0, OldText.indexOf('[[تصنيف:'));
			var DebutModele5 = OldText.substring(0, OldText.indexOf('[[Category:'));
			var DebutModele6 = OldText.substring(0, OldText.indexOf('[[category:'));
			var SuiteModele = OldText.split(DebutModele1).join('').split(DebutModele2).join('').split(DebutModele3).join('').split(DebutModele4).join('').split(DebutModele5).join('').split(DebutModele6).join('');
			var DebutModele = OldText.split(SuiteModele).join('');
		} else {
			// ------------------------------------------------------------------------------------ Il n'y a pas de تصنيفs
			var interWiki = new RegExp('^\\s*\\[\\[([a-z][a-z].?(x?-[^\\]]+)?|simple|tokipona):([^\\]]*)\\]\\]\\s*$');
			var blank = new RegExp('^\\s*$');
			var lines = OldText.split('\n');
			var DebutModele = '';
			var SuiteModele = '';
			for (var lineId = lines.length - 1; lineId >= 0; --lineId) {
				if (!interWiki.test(lines[lineId]) && !blank.test(lines[lineId])) {
					DebutModele = lines.slice(0, lineId + 1).join('\n') + '\n\n';
					SuiteModele = lines.slice(lineId + 1).join('\n');
					break;
				}
			}
			if (DebutModele === '') {
				// edge case: source has nothing else than interwikis
				SuiteModele = OldText;
			}
			while (SuiteModele.indexOf('\n\n') != -1) {
				SuiteModele = SuiteModele.split("\n\n").join("\n");
			}
			SuiteModele = SuiteModele.replace(/^\n/, "");
		}
	}
	var TexteFinal = DebutModele + NouveauModele + SuiteModele;
	var TexteFinal = TexteFinal.replace(/\n\{\{\s*(مقالات بحاجة لشريط بوابات)[^}]*\}\}\n/g, "");
	var SommaireFinal = Sommaire + ' ([[وب:شب|شريط البوابات]])';
	document.getElementById('wpMinoredit').checked = BandeauxPortails_MinorEdit;
	if (BandeauxPortails_Watchthis == 1) document.getElementById('wpWatchthis').checked = "checked";
	if (BandeauxPortails_Watchthis == 0) document.getElementById('wpWatchthis').checked = false;
	document.getElementById('wpTextbox1').value = TexteFinal;
	document.getElementById('wpSummary').value = SommaireFinal;
	if (BandeauxPortails_AutoEdit) {
		var watchthisparam = {};
		watchthisparam[-1] = "nochange";
		watchthisparam[0] = "unwatch";
		watchthisparam[1] = "watch";
		var datas = {
			action: 'edit',
			title: conf.wgPageName,
			text: TexteFinal,
			summary: SommaireFinal,
			minor: (document.editform.wpMinoredit.checked ? 1 : 0),
			watchlist: watchthisparam[BandeauxPortails_Watchthis],
			token: document.editform.wpEditToken.value
		};
		var ApplyTag = BandeauxPortails_gettag();
		if (ApplyTag) {
			datas.summary = Sommaire;
			datas.tags = ApplyTag;
		}
		var api = new mw.Api();
		api.post(datas, { 'contentType': 'application/x-www-form-urlencoded' }).then(function (data) {
			window.location.reload();
		});
	}
}

function BandeauxPortails_Edit() {
	var ToRemove = (BandeauxPortails_EditParams["PortalToRemove"] ? BandeauxPortails_EditParams["PortalToRemove"] : (BandeauxPortails_EditParams["PortalToModifyFrom"] ? BandeauxPortails_EditParams["PortalToModifyFrom"] : false));
	var ToAdd = (BandeauxPortails_EditParams["PortalToAdd"] ? BandeauxPortails_EditParams["PortalToAdd"] : (BandeauxPortails_EditParams["PortalToModifyTo"] ? BandeauxPortails_EditParams["PortalToModifyTo"] : false));
	var URL = wgServer + conf.wgScript + "?title=" + encodeURIComponent(conf.wgPageName) + "&action=submit";
	BandeauxPortails_ajax.http({
		url: URL,
		onSuccess: BandeauxPortails_DoEdit,
		remove: ToRemove,
		add: ToAdd
	});
}

/////////////////////////////////////////////////////////////////////////////////// Mise à jour des bandeaux effectivement présents

function BandeauxPortails_Update() {
	var URL = wgServer + conf.wgScript + '?title=' + encodeURIComponent(conf.wgPageName) + '&oldid=' + conf.wgCurRevisionId + '&action=raw';
	BandeauxPortails_ajax.http({ url: URL, onSuccess: BandeauxPortails_UpdateDone });
}
window.BandeauxPortails_UpdateDone = function (Req, data) {
	var Contenu = Req.responseText;
	if (Contenu == '') return;
	Contenu = Contenu.replace(/\{\{شريط بوابة/ig, "\{\{شريط بوابات");
	Contenu = Contenu.replace(/\{\{بوابة /ig, "\{\{شريط بوابات\|");
	if (Contenu.indexOf('{{شريط بوابات|') == -1) return;
	var ParamsModele = Contenu.split('{{شريط بوابات|')[1].split('}}')[0] + '|';
	ParamsModele = BandeauxPortails_CleanModele(ParamsModele);
	var AllParamsModele = new Array();
	while (ParamsModele.indexOf('|') != -1) {
		var NewParam = ParamsModele.split('|')[0];
		if (NewParam != '') AllParamsModele.push(NewParam);
		ParamsModele = ParamsModele.split(NewParam + '|')[1];
	}
	for (var m = 0; m < AllParamsModele.length; m++) {
		var Span = document.getElementById('lienPortail_' + m);
		if (!Span) continue;
		var LienRemove = Span.getElementsByTagName('a')[1];
		LienRemove.href = "javascript:BandeauxPortails_SupprOne(\'" + encodeURIComponent(AllParamsModele[m]).replace(/'/g, "ZAPPOSTROPHE") + "\')";
		LienRemove.title = "حذف وصلة بوابة " + AllParamsModele[m];
		var LienModify = Span.getElementsByTagName('a')[2];
		LienModify.href = "javascript:BandeauxPortails_ModifyOne(\'" + m + "\',\'" + encodeURIComponent(AllParamsModele[m]).replace(/'/g, "ZAPPOSTROPHE") + "\')";
		LienModify.title = "تعديل وصلة بوابة " + AllParamsModele[m];
	}
};

/////////////////////////////////////////////////////////////////////////////////// Formulaires

window.BandeauxPortails_Cancel = function (id) {
	var Span = document.getElementById(id);
	Span.style.display = 'inline';
	var Parent = Span.parentNode;
	var Form = Parent.getElementsByTagName('form')[0];
	Parent.removeChild(Form);
};

window.BandeauxPortails_SupprOne = function (Portail) {
	Portail = Portail.replace(/ZAPPOSTROPHE/g, "'");
	if (BandeauxPortails_SkipConfirm || confirm('أتريد حذف وصلة بوابة «' + Portail + '»؟')) {
		BandeauxPortails_EditParams["PortalToRemove"] = Portail;
		BandeauxPortails_Edit();
	}
	// ********************************************************************************************************
};

window.BandeauxPortails_ModifyThatOne = function (id, oldportail) {
	oldportail = oldportail.replace(/ZAPPOSTROPHE/g, "'");
	var Input = document.getElementById('InputModify_' + id);
	var Portail = Input.value;
	if ((Portail != '') && (Portail != oldportail)) {
		// ********************************************************************************************************
		BandeauxPortails_EditParams["PortalToModifyFrom"] = oldportail;
		BandeauxPortails_EditParams["PortalToModifyTo"] = Portail;
		BandeauxPortails_Edit();
		// ********************************************************************************************************
	} else {
		BandeauxPortails_Cancel('lienPortail_' + id);
	}
};

window.BandeauxPortails_ModifyOne = function (id, portail) {
	portail = portail.replace(/ZAPPOSTROPHE/g, "'");
	var Span = document.getElementById('lienPortail_' + id);
	Span.style.display = "none";
	var Form = document.createElement('form');
	Form.id = "BP_Form_" + id;
	Form.portail = portail.replace(/'/g, "ZAPPOSTROPHE");
	Form.method = "post";
	Form.onsubmit = function () {
		var FormIndex = this.id.split("BP_Form_").join("");
		var OldPortail = this.portail;
		BandeauxPortails_ModifyThatOne(FormIndex, OldPortail);
		return false;
	};

	Form.style.display = "inline";
	Form.innerHTML = '<select id="SelectModify_' + id + '" style="display:none;" title="اقتراحات البوابات" />'
		+ '<input id="InputModify_' + id + '" type="text" value="' + portail + '" '
		+ 'onkeyup="BandeauxPortails_TextChanged(\'SelectModify_' + id + '\')" />'
		+ '<input type="button" '
		+ 'onclick="BandeauxPortails_ModifyThatOne(\'' + id + '\',\'' + portail.replace(/'/g, "ZAPPOSTROPHE") + '\');" '
		+ 'onselect="BandeauxPortails_ModifyThatOne(\'' + id + '\',\'' + portail.replace(/'/g, "ZAPPOSTROPHE") + '\');" '
		+ 'value="أكد"/>'
		+ '<input type="button" '
		+ 'onclick="BandeauxPortails_Cancel(\'lienPortail_' + id + '\')" '
		+ 'onselect="BandeauxPortails_Cancel(\'lienPortail_' + id + '\')" '
		+ 'value="ألغ"/>';
	Span.parentNode.insertBefore(Form, Span);
	document.getElementById('InputModify_' + id).focus();
};

window.BandeauxPortails_AddThatOne = function () {
	var Input = document.getElementById('InputAdd');
	var Portail = Input.value;
	if (Portail != '') {
		// ********************************************************************************************************
		BandeauxPortails_EditParams["PortalToAdd"] = Portail;
		BandeauxPortails_Edit();
		// ********************************************************************************************************
	} else {
		BandeauxPortails_Cancel('BandeauxPortails_Add');
	}
};

window.BandeauxPortails_AddOne = function () {
	var Span = document.getElementById('BandeauxPortails_Add');
	Span.style.display = "none";
	var Form = document.createElement('form');
	Form.style.display = "inline";
	Form.id = "BP_Form_Add";
	Form.method = "post";
	Form.onsubmit = function () {
		BandeauxPortails_AddThatOne();
		return false;
	};
	Form.innerHTML = '<select id="SelectAdd" style="display:none;" title="اقتراحات البوابات" />'
		+ '<input id="InputAdd" type="text" value="" onkeyup="BandeauxPortails_TextChanged(\'SelectAdd\')" />'
		+ '<input type="button" '
		+ 'onclick="BandeauxPortails_AddThatOne();" '
		+ 'onselect="BandeauxPortails_AddThatOne();" '
		+ 'value="أكد"/>'
		+ '<input type="button" '
		+ 'onclick="BandeauxPortails_Cancel(\'BandeauxPortails_Add\')" '
		+ 'onselect="BandeauxPortails_Cancel(\'BandeauxPortails_Add\')" '
		+ 'value="ألغ"/>';
	Span.parentNode.insertBefore(Form, Span);
	document.getElementById('InputAdd').focus();

};

/////////////////////////////////////////////////////////////////////////////////// Suggestions

var BandeauxPortails_TextChanged_running = 0;
var BandeauxPortails_Results = new Array();

function BandeauxPortails_KeypressedOnList(e) {
	if (!e) var e = window.event;
	if (e.keyCode != 13) {
		var IsEnter = false;
	} else {
		var IsEnter = true;
	}
	return IsEnter;
}

function BandeauxPortails_TextChanged_MergeNoaccent(text) {
	text = text.toLowerCase();
	text = text.replace(/â/g, "a");
	text = text.replace(/å/g, "a");
	text = text.replace(/é/g, "e");
	text = text.replace(/è/g, "e");
	text = text.replace(/ê/g, "e");
	text = text.replace(/ë/g, "e");
	text = text.replace(/î/g, "i");
	text = text.replace(/ï/g, "i");
	text = text.replace(/ô/g, "o");
	text = text.replace(/œ/g, "oe");
	text = text.replace(/ç/g, "c");
	text = text.replace(/š/g, "s");
	text = text.replace(/-/g, " ");
	text = text.replace(/'/g, " ");
	text = text.replace(/;/g, "");
	return text;
}

function BandeauxPortails_TextChanged_Set(id, text) {
	text = text.replace(/ZAPOSTROPHE/g, "'");
	var OldValue = document.getElementById(id).value;
	if (OldValue.indexOf('|') != -1) {
		var AllParams = OldValue.split("|");
		AllParams[(AllParams.length - 1)] = text;
		var NewValue = AllParams.join("|");
	} else {
		var NewValue = text;
	}
	document.getElementById(id).value = NewValue;
	document.getElementById(id).focus();
}

function BandeauxPortails_TextChanged_Display(ResultArray, id) {
	var Select = document.getElementById(id);
	var idInput = id.split('Select').join('Input');
	var Input = document.getElementById(idInput);
	if ((!Input) || (!Select)) return;
	Select.innerHTML = '';
	var NbOptions = 0;
	for (var a = 0; a < ResultArray.length; a++) {
		var TitrePage = ResultArray[a];
		var TitrePageEncode = TitrePage.replace(/'/g, "ZAPOSTROPHE");
		var Option = document.createElement('option');
		Option.value = TitrePage;
		Option.innerHTML = TitrePage;
		Option.onclick = function () {
			var PageEncode = this.value;
			BandeauxPortails_TextChanged_Set(this.parentNode.id.split('Select').join('Input'), PageEncode);
			BandeauxPortails_TextChanged(this.parentNode.id);
		};
		if (a == 0) Option.selected = "selected";
		Select.appendChild(Option);
		NbOptions++;
	}
	if (NbOptions > 0) {
		Select.onkeyup = function (e) {
			if (!e) var e = window.event;
			var IsEnter = BandeauxPortails_KeypressedOnList(e);
			if (!IsEnter) return;

			var Selected = this.getElementsByTagName('option');
			for (var a = 0; a < Selected.length; a++) {
				if (Selected[a].selected) {
					var TextSelected = Selected[a].value;
				}
			}
			BandeauxPortails_TextChanged_Set(idInput, TextSelected);
			BandeauxPortails_TextChanged(id);
		};
		Select.size = NbOptions;
		Select.style.display = 'inline';
		Select.style.zIndex = 5;
		Select.style.position = "absolute";
		Input.style.width = Select.offsetWidth + "px";

		if (BandeauxPortails_ListeBas) {
			Select.style.top = (parseInt(Input.offsetTop) + parseInt(Input.offsetHeight)) + 'px';
		} else {
			Select.style.top = (parseInt(Input.offsetTop) - Select.offsetHeight) + 'px';
		}
		Select.style.left = (parseInt(Input.parentNode.offsetLeft) - 1) + 'px';
	} else {
		Select.style.display = 'none';
		Select.innerHTML = '';
	}
}


function BandeauxPortails_TextChanged_Request(Value, id) {
	if (BandeauxPortails_TextChanged_running) return;
	BandeauxPortails_TextChanged_running = 1;

	var Redirect = (BandeauxPortails_ShowRedirect ? "" : "&apfilterredir=nonredirects");
	var URL = wgServer + conf.wgScriptPath
		+ '/api.php?action=query&cmdir=asc&cmnamespace=100&format=xml&list=categorymembers'
		+ '&cmtitle=' + encodeURIComponent('تصنيف:قائمة_البوابات')
		+ '&cmlimit=' + BandeauxPortails_TailleListe
		+ '&cmstartsortkeyprefix=' + encodeURIComponent(Value);
	BandeauxPortails_ajax.http({
		url: URL,
		onSuccess: BandeauxPortails_TextChanged_Request_Bis,
		value: Value,
		id: id
	});
}

function BandeauxPortails_TextChanged_Request_Bis(Req, data) {
	var Value = data.value;
	var id = data.id;
	BandeauxPortails_Results = [];
	var ObjetXML = Req.responseXML;
	var AllPages = ObjetXML.getElementsByTagName('cm');
	for (var b = 0; b < AllPages.length; b++) {
		var Titre = AllPages[b].getAttribute('title').replace(/بوابة:/, "");

		if (Titre.indexOf(Value) != -1 && Titre.indexOf("/") == -1 && BandeauxPortails_Results.indexOf(Titre) == -1) {
			BandeauxPortails_Results.push(Titre);
		}
	}
	BandeauxPortails_TextChanged_running = 0;
	BandeauxPortails_TextChanged_Display(BandeauxPortails_Results, id);
}


window.BandeauxPortails_TextChanged = function (id) {
	if (BandeauxPortails_TailleListe == 0) return;
	var Select = document.getElementById(id);
	var idInput = id.split('Select').join('Input');
	var Input = document.getElementById(idInput);
	if ((!Input) || (!Select)) return;
	var Value = Input.value;
	Value = Value.replace(/.*\|/g, "");
	if (Value == '') return;
	BandeauxPortails_TextChanged_Request(Value, id);
};

/////////////////////////////////////////////////////////////////////////////////// Fonctions actives au chargement de la page

function BandeauxPortails_CreateUl() {
	var CatLinks = document.getElementById('catlinks');
	var Bandeau;
	if (!CatLinks) return;
	mw.loader.load('//ar.wikipedia.org/w/index.php?title=Module:Portal/styles.css&action=raw&ctype=text/css', 'text/css').then(function () {
		Bandeau = document.createElement('ul');
		Bandeau.id = 'bandeau-portail';
		Bandeau.className = 'bandeau-portail';
		CatLinks.parentNode.insertBefore(Bandeau, CatLinks);
	});
}

function BandeauxPortails_ModifyUl() {
	var BandeauUl = document.getElementById('bandeau-portail');
	if (!BandeauUl) return;
	var BandeauLi = BandeauUl.getElementsByTagName('li');
	for (var a = 0; a < BandeauLi.length; a++) {
		var Li = BandeauLi[a];
		var Lien = Li.getElementsByTagName('a')[1];
		if (Lien) {
			var TitreDecode = Lien.title.split('بوابة:').join('');
			TitreDecode = TitreDecode.replace(/ \(صفحة غير موجودة\)/g, "");
			var Titre = encodeURIComponent(TitreDecode);
			var SpanLien = Lien.parentNode;
			SpanLien.id = 'lienPortail_' + a;
			SpanLien.innerHTML += ' • '
				+ '<a href="javascript:BandeauxPortails_SupprOne(\'' + Titre + '\')" title="حذف وصلة بوابة ' + TitreDecode + '">(-)</a>'
				+ ' • '
				+ '<a href="javascript:BandeauxPortails_ModifyOne(\'' + a + '\',\'' + Titre + '\')" title="تعديل وصلة بوابة ' + TitreDecode + '">(±)</a>';
		}
	}
	var BandeauInexistant = BandeauUl.getElementsByTagName('a');
	for (var a = 100; a < (BandeauInexistant.length + 100); a++) {
		if ($(BandeauInexistant[a - 100]).hasClass('new')) {
			var Lien = BandeauInexistant[(a - 100)];
			if (Lien.title.indexOf("بوابة:") == -1) {
				var TitreDecode = Lien.innerHTML.split('قالب:شريط بوابة').join('');
				TitreDecode = TitreDecode.replace(/^ /, '');
				Titre = encodeURIComponent(TitreDecode).replace(/'/g, "ZAPPOSTROPHE");
				var NewLi = document.createElement('li');
				NewLi.innerHTML = '<span id="lienPortail_' + a + '" >'
					+ '<a class="new" href="' + Lien.href + '" title="' + Lien.title + '" >' + TitreDecode + '</a>'
					+ ' • '
					+ '<a href="javascript:BandeauxPortails_SupprOne(\'' + Titre + '\')" title="حذف وصلة بوابة ' + TitreDecode + '">(-)</a>'
					+ ' • '
					+ '<a href="javascript:BandeauxPortails_ModifyOne(\'' + a + '\',\'' + Titre + '\')" title="تعديل وصلة بوابة ' + TitreDecode + '">(±)</a>';
				Lien.parentNode.insertBefore(NewLi, Lien);
				Lien.parentNode.removeChild(Lien);
			}
		}
	}
	var AddLi = document.createElement('li');
	AddLi.id = 'lienPortail_add';
	AddLi.innerHTML += '<span class="bandeau-portail-element">'
		+ '<span class="bandeau-portail-texte" id="BandeauxPortails_Add" >'
		+ '<a href="javascript:BandeauxPortails_AddOne()" title="إضافة وصلة بوابة" >(+)</a>'
		+ '</span>'
		+ '</span>';
	BandeauUl.appendChild(AddLi);
	BandeauxPortails_Update();
}

window.BandeauxPortails = function () {
	var Homonymie = document.getElementById("homonymie");
	var UlBandeaux = document.getElementById('bandeau-portail');
	if (Homonymie && !UlBandeaux) return;

	if (!UlBandeaux) BandeauxPortails_CreateUl();
	BandeauxPortails_ModifyUl();
};

if ((conf.wgAction === 'view' || conf.wgAction === 'purge') &&
	conf.wgNamespaceNumber === 0 &&
	conf.wgArticleId > 0 &&
	conf.wgIsProbablyEditable &&
	!conf.wgIsRedirect &&
	!conf.wgIsMainPage) {
	mw.loader.using('mediawiki.api', function () {
		$(BandeauxPortails);
	});
}