MediaWiki:Gadget-LiveRC.js/Extensions/PreviewAllLinksExtension.js
Apparence
Note : après avoir enregistré la page, vous devrez forcer le rechargement complet du cache de votre navigateur pour voir les changements.
Mozilla / Firefox / Konqueror / Safari : maintenez la touche Majuscule (Shift) en cliquant sur le bouton Actualiser (Reload) ou pressez Maj-Ctrl-R (Cmd-R sur Apple Mac) ;
Firefox (sur GNU/Linux) / Chrome / Internet Explorer / Opera : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl-F5./*
--------------------------------------------------------------------------------------
---------LLLL---------III--------------------------RRRRRRRRRR--------CCCCC------------
---------LLLL---------III--------------------------RRRRRRRRRRRR----CCCCCCCCC----------
---------LLLL--------------------------------------RRR------RRR---CCC-----CCC---------
---------LLLL---------III--VV-----VV--EEEEEEEEE----RRR------RRR--CCC------------------
---------LLLL---------III---VV---VV---EEE----------RRRRRRRRRRR---CCC------------------
---------LLLL---------III---VV---VV---EEEEEE-------RRRRRRRRRR----CCC------------------
---------LLLL---------III----VV-VV----EEEEEE-------RRR-----RRR----CCC-----CCC---------
---------LLLLLLLLLLL--III----VVVVV----EEE----------RRR------RRR----CCCCCCCCC----------
---------LLLLLLLLLLL--III-----VVV-----EEEEEEEEE----RRR-------RRR-----CCCCC------------
--------------------------------------------------------------------------------------
'''Extension de LiveRC'''
Tous les liens internes de la prévisualisation lancent une prévisualisation
* Licence : ...?
* Documentation :
* Auteur : [[:fr:User:Dr Brains]]
* Développement et maintenance :
{{Catégorisation JS|LiveRC}}
<source lang=javascript> */
if(typeof(LiveRC_AddHook)==="function"){ // DÉBUT IF
LiveRC_Config["InstalledLiveRCExtensions"].push("PreviewAllLinksExtension");
/* ************************************************************************************************************************************************ */
lrcTexts["LIVELINK"] = ' (live)';
window.DebugLimit = 5;
window.DebugIndex = 0;
window.LinkHasClass = function(node, classNames) {
if(!node || !node.classList){
return false;
}
for(var a=0,l=classNames.length;a<l;a++){
if(node.classList.contains(classNames[a])){
return true;
}
}
return false;
}
window.liveAllLinks = function(){
var Element = document.getElementById("livePreview");
if(!Element) return;
var Toc = getElementWithId("toc", "table", Element);
if(Toc){
var TocLinks = Toc.getElementsByTagName("a");
for(var a=0,l=TocLinks.length;a<l;a++){
if(TocLinks[a].href.indexOf('javascript:') != 0)
TocLinks[a].href = "javascript:;";
}
}
var Links = Element.getElementsByTagName("a");
for(var a=0,l=Links.length;a<l;a++){
var Url = Links[a].href;
if(!Url) continue;
try{ Url = decodeURIComponent(Url); }catch(e){ }
if(Url.indexOf("#")!=-1){
Links[a].href = Url.substring(0, Url.indexOf("#"));
}
if(Links[a].href == "") Links[a].href = "javascript;";
if(
LinkHasClass(Links[a].parentNode, new Array("reference", "mw-cite-backlink")) ||
LinkHasClass(Links[a].parentNode.parentNode, new Array("mw-cite-backlink"))
){
var NewLink = document.createElement('a');
NewLink.href = "javascript;";
NewLink.innerHTML = Links[a].innerHTML;
Links[a].parentNode.insertBefore(NewLink,Links[a]);
Links[a].style.display = "none";
}
if(!(
LinkHasClass(Links[a].parentNode, new Array('cachelinks', "patrollink")) ||
LinkHasClass(Links[a], new Array('noprint', 'external')) ||
Links[a].href.indexOf('javascript:') == 0 ||
Links[a].href == "#"
)){
lrcAddClass(Links[a], "PreviewAllLinks_ModifiedLink");
Links[a].title = (Links[a].title ? Links[a].title + lrcMakeText("LIVELINK") : lrcMakeText("LIVELINK"));
Links[a].onclick = function(){
return liveModifyLinks(this);
}
}
}
}
window.liveModifyLinks = function(Link, test){
var Href = Link.href;
try{ Href = decodeURIComponent(Href); }catch(e){ }
var ArticlePath = mw.config.get('wgArticlePath').split("$1").join("");
var ArticleReg = new RegExp(".*"+ArticlePath.replace(/\//g, "\\\/"));
var ScriptReg = new RegExp(".*"+mw.config.get('wgScript').replace(/\//g, "\\\/")+"\\?");
Href = Href.replace(ArticleReg, "");
Href = Href.replace(ScriptReg, "");
if(Href.indexOf("title=")==-1) Href = "title=" + Href;
if(Href.match(/^http/)!=null) return false;
var Onclick = "";
var Params = new Array();
var URL = Href.split("&");
for(var a=0,l=URL.length;a<l;a++){
if(URL[a].indexOf("=")==-1) continue;
var ParamName = URL[a].split("=")[0];
var ParamValue = URL[a].split("=")[1];
Params[ParamName] = ParamValue;
}
if(Params["title"]) Params["title"] = Params["title"].replace(/_/g, " ");
if(Params["action"]){
if(Params["action"]=="edit"){
var EditParams = "";
if(Params["oldid"]) EditParams += "&oldid="+Params["oldid"];
if(Params["section"]) EditParams += "§ion="+Params["section"];
if(Params["redlink"]) EditParams += "&redlink="+Params["redlink"];
Onclick = 'liveEdit('+lrcEscapeStr(Params["title"])+(EditParams ? ',\''+EditParams+'\'' : '')+')';
}
if(Params["action"]=="delete"){
Onclick = 'liveDelete('+lrcEscapeStr(Params["title"])+')';
}
if(Params["action"]=="protect"){
Onclick = 'liveProtect('+lrcEscapeStr(Params["title"])+')';
}
if(Params["action"]=="historysubmit"){
Onclick = 'liveDiff('+lrcEscapeStr(Params["title"])+','+lrcEscapeStr(Params["diff"])+','+lrcEscapeStr(Params["oldid"])+')';
}
}else{
var PageNamespaceNumber = getNamespaceInfoFromPage(Params["title"]);
var PageName = getNamespaceInfoFromPage(Params["title"], "PageName");
if(PageNamespaceNumber==-1){
if(PageName.indexOf("Movepage")!=-1 || PageName.indexOf("Renommer une page")!=-1){
var Page = PageName.replace(/[^\/]*\//, "");
Onclick = 'liveMove('+lrcEscapeStr(Page)+');';
}
if(PageName.indexOf("Contributions")!=-1){
var Page = Params["target"];
if(Page) Page = PageName.replace(/[^\/]*\//, "");
if(PageName.indexOf("DeletedContributions")!=-1 || PageName.indexOf("Contributions supprimées")!=-1){
Onclick = 'liveDeletedContrib('+lrcEscapeStr(Page)+');';
}else{
Onclick = 'liveContrib('+lrcEscapeStr(Page)+');';
}
}
if(PageName.indexOf("Blockip")!=-1 || PageName.indexOf("Bloquer")!=-1){
var Page = PageName.replace(/[^\/]*\//, "");
Onclick = 'liveBlock('+lrcEscapeStr(Page)+');';
}
if(PageName.indexOf("Log")!=-1 || PageName.indexOf("Journal")!=-1){
var Type = Params["type"];
var Page = Params["page"];
var User = Params["user"];
if(Page) Onclick = 'liveLog(\''+Type+'\',{page:'+lrcEscapeStr(Page)+',user:'+lrcEscapeStr(User)+'});';
}
}else{
if(Params["diff"]&&Params["oldid"]){
Onclick = 'liveDiff('+lrcEscapeStr(Params["title"])+','+lrcEscapeStr(Params["diff"])+','+lrcEscapeStr(Params["oldid"])+');';
}
if(Params["title"] && URL.length==1){
Onclick = 'liveArticle('+lrcEscapeStr(Params["title"])+');';
}
}
}
if(Onclick == ""){
var TitleCustom = (Params["title"] ? ','+lrcEscapeStr(Params["title"]) : "");
Onclick = 'liveCustom('+lrcEscapeStr(Link.href) + TitleCustom +');';
}
try{ eval(Onclick); }catch(e){ }
return false;
}
window.liveCustom = function(URL, Title){
lrcAddToHistory("liveCustom",new Array(lrcEscapeStr(URL), lrcEscapeStr(Title)), URL, Title);
if(!Title){
var ArticleReg = new RegExp(".*"+mw.config.get('wgArticlePath').split("$1").join("").replace(/\//g, "\\\/"));
var ScriptReg = new RegExp(".*"+mw.config.get('wgScript').replace(/\//g, "\\\/")+"\\?");
try{ Title=URL.replace(ArticleReg, "").replace(ScriptReg, ""); }catch(e){ }
}
if(!Title) Title = URL;
buildBlanckPreviewBar("<b style='text-decoration: blink;'>Custom : <span style='color:red'>"+Title+"</span>...</b>");
wpajax.http({url: URL,
onSuccess: getCustom,
onFailure: getCustom,
title:Title});
}
window.getCustom = function(xmlreq, data){
var c = data.title;
if(c) buildBlanckPreviewBar('<b><a href="'+lrcGetPageURL(c)+'" target="_new">'+c+'</a></b>', true);
var bC = getPageContent(xmlreq);
var PreviewWindow = document.getElementById("livePreview");
PreviewWindow.innerHTML = "";
PreviewWindow.innerHTML = bC.innerHTML;
lrcCloseAll();
lrcAddClass(document.body, "LiveRCPreviewDisplayed");
updatePreviewWindowAttributes();
liveAllLinks();
}
////////////////////////////////////////// HOOKS
LiveRC_AddHook("AfterPreviewArticle", liveAllLinks);
LiveRC_AddHook("AfterPreviewDiff", liveAllLinks);
LiveRC_AddHook("AfterPreviewHistory", liveAllLinks);
LiveRC_AddHook("AfterPreviewContribs", liveAllLinks);
LiveRC_AddHook("AfterPreviewDeletedContribs", liveAllLinks);
LiveRC_AddHook("AfterPreviewEdit", liveAllLinks);
LiveRC_AddHook("AfterPreviewMove", liveAllLinks);
LiveRC_AddHook("AfterPreviewProtect", liveAllLinks);
LiveRC_AddHook("AfterPreviewDelete", liveAllLinks);
LiveRC_AddHook("AfterPreviewBlock", liveAllLinks);
LiveRC_AddHook("AfterPreviewRevisiondelete", liveAllLinks);
LiveRC_AddHook("AfterPreviewWhatlinkshere", liveAllLinks);
LiveRC_AddHook("AfterPreviewLog", liveAllLinks);
LiveRC_AddHook("AfterPreviewFilter", liveAllLinks);
// LiveRC_AddHook("AfterPreviewFeedback", liveAllLinks);
/* ************************************************************************************************************************************************ */
} // FIN IF
//</source>