Utilisateur:Utilisateur exemple/GlobalManager.js
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.// <pre><nowiki>
/***************************************************************************************************************
* GLOBAL-MANAGER *
* Pour installer et configurer ce gestionnaire : Voir [[Discussion utilisateur:Dr Brains/GlobalManager.js]] *
***************************************************************************************************************/
////////////////////////////// PARTIE PERSONNALISABLE (1/8) : DÉFINITION DU SKIN ACTIF ET DES SKINS SUPPORTÉS //////////////////////////////////////////////////////////////////////
if( skin == "monobook" ){
var cspSkin = "monobook";
var cspSkinalt1 = "modern";
var cspSkinalt2 = "vector";
var cspSkinalt3 = "cologneblue";
var cspSkinalt4 = "chick";
var cspSkinalt5 = "simple";
var cspSkinalt6 = "nostalgia";
var cspSkinalt7 = "standard";
var cspSkinalt8 = "myskin";
}
if( skin == "modern" ){
var cspSkin = "modern";
var cspSkinalt1 = "monobook";
var cspSkinalt2 = "vector";
var cspSkinalt3 = "cologneblue";
var cspSkinalt4 = "chick";
var cspSkinalt5 = "simple";
var cspSkinalt6 = "nostalgia";
var cspSkinalt7 = "standard";
var cspSkinalt8 = "myskin";
}
if( skin == "vector" ){
var cspSkin = "vector";
var cspSkinalt1 = "monobook";
var cspSkinalt2 = "modern";
var cspSkinalt3 = "cologneblue";
var cspSkinalt4 = "chick";
var cspSkinalt5 = "simple";
var cspSkinalt6 = "nostalgia";
var cspSkinalt7 = "standard";
var cspSkinalt8 = "myskin";
}
if( skin == "cologneblue" ){
var cspSkin = "cologneblue";
var cspSkinalt1 = "monobook";
var cspSkinalt2 = "modern";
var cspSkinalt3 = "vector";
var cspSkinalt4 = "chick";
var cspSkinalt5 = "simple";
var cspSkinalt6 = "nostalgia";
var cspSkinalt7 = "standard";
var cspSkinalt8 = "myskin";
}
if( skin == "chick" ){
var cspSkin = "chick";
var cspSkinalt1 = "monobook";
var cspSkinalt2 = "modern";
var cspSkinalt3 = "vector";
var cspSkinalt4 = "cologneblue";
var cspSkinalt5 = "simple";
var cspSkinalt6 = "nostalgia";
var cspSkinalt7 = "standard";
var cspSkinalt8 = "myskin";
}
if( skin == "nostalgia" ){
var cspSkin = "nostalgia";
var cspSkinalt1 = "monobook";
var cspSkinalt2 = "modern";
var cspSkinalt3 = "vector";
var cspSkinalt4 = "cologneblue";
var cspSkinalt5 = "chick";
var cspSkinalt6 = "simple";
var cspSkinalt7 = "standard";
var cspSkinalt8 = "myskin";
}
if( skin == "standard" ){
var cspSkin = "standard";
var cspSkinalt1 = "monobook";
var cspSkinalt2 = "modern";
var cspSkinalt3 = "vector";
var cspSkinalt4 = "cologneblue";
var cspSkinalt5 = "chick";
var cspSkinalt6 = "simple";
var cspSkinalt7 = "nostalgia";
var cspSkinalt8 = "myskin";
}
if( skin == "myskin" ){
var cspSkin = "myskin";
var cspSkinalt1 = "monobook";
var cspSkinalt2 = "modern";
var cspSkinalt3 = "vector";
var cspSkinalt4 = "cologneblue";
var cspSkinalt5 = "chick";
var cspSkinalt6 = "simple";
var cspSkinalt7 = "nostalgia";
var cspSkinalt8 = "standard";
}
var cspEntryPage = 'Utilisateur:' + mw.config.get('wgUserName').replace(/ /,"_") + '/' + cspSkin + '.js'; //Pages JS où le script s'active
var cspEntryPagealt1 = 'Utilisateur:' + mw.config.get('wgUserName').replace(/ /,"_") + '/' + cspSkinalt1 + '.js';
var cspEntryPagealt2 = 'Utilisateur:' + mw.config.get('wgUserName').replace(/ /,"_") + '/' + cspSkinalt2 + '.js';
var cspEntryPagealt3 = 'Utilisateur:' + mw.config.get('wgUserName').replace(/ /,"_") + '/' + cspSkinalt3 + '.js';
var cspEntryPagealt4 = 'Utilisateur:' + mw.config.get('wgUserName').replace(/ /,"_") + '/' + cspSkinalt4 + '.js';
var cspEntryPagealt5 = 'Utilisateur:' + mw.config.get('wgUserName').replace(/ /,"_") + '/' + cspSkinalt5 + '.js';
var cspEntryPagealt6 = 'Utilisateur:' + mw.config.get('wgUserName').replace(/ /,"_") + '/' + cspSkinalt6 + '.js';
var cspEntryPagealt7 = 'Utilisateur:' + mw.config.get('wgUserName').replace(/ /,"_") + '/' + cspSkinalt7 + '.js';
var cspEntryPagealt8 = 'Utilisateur:' + mw.config.get('wgUserName').replace(/ /,"_") + '/' + cspSkinalt8 + '.js';
var cspCssPage = 'Utilisateur:' + mw.config.get('wgUserName').replace(/ /,"_") + '/' + cspSkin + '.css'; //Pages CSS où le script s'active
var cspCssPagealt1 = 'Utilisateur:' + mw.config.get('wgUserName').replace(/ /,"_") + '/' + cspSkinalt1 + '.css';
var cspCssPagealt2 = 'Utilisateur:' + mw.config.get('wgUserName').replace(/ /,"_") + '/' + cspSkinalt2 + '.css';
var cspCssPagealt3 = 'Utilisateur:' + mw.config.get('wgUserName').replace(/ /,"_") + '/' + cspSkinalt3 + '.css';
var cspCssPagealt4 = 'Utilisateur:' + mw.config.get('wgUserName').replace(/ /,"_") + '/' + cspSkinalt4 + '.css';
var cspCssPagealt5 = 'Utilisateur:' + mw.config.get('wgUserName').replace(/ /,"_") + '/' + cspSkinalt5 + '.css';
var cspCssPagealt6 = 'Utilisateur:' + mw.config.get('wgUserName').replace(/ /,"_") + '/' + cspSkinalt6 + '.css';
var cspCssPagealt7 = 'Utilisateur:' + mw.config.get('wgUserName').replace(/ /,"_") + '/' + cspSkinalt7 + '.css';
var cspCssPagealt8 = 'Utilisateur:' + mw.config.get('wgUserName').replace(/ /,"_") + '/' + cspSkinalt8 + '.css';
////////////////////////////// PARTIE PERSONNALISABLE (2/8) : PARAMÈTRES ///////////////////////////////////////////////////////////////////////////////////////////////////////////
//Adresses du site :
var SiteURL = 'http://fr.wikipedia.org/wiki/' //* Adresse normale
var SiteURLbis = 'http://fr.wikipedia.org/w/index.php?title=' //* Adresse en cours d'action
var cspCssRepos = 'Utilisateur:' + mw.config.get('wgUserName').replace(/ /,"_") + '/'; //Répertoire par défaut des pages personnelles css
var cspCssLinks = SiteURL + cspCssRepos ; //Url du répertoire par défaut des pages personnelles css
var cspScriptRepos = 'Utilisateur:' + mw.config.get('wgUserName').replace(/ /,"_") + '/'; //Répertoire par défaut des scripts personnels
var cspScriptLinks = SiteURL + cspScriptRepos ; //Url du répertoire par défaut
var cspGadgetsRepos = 'MediaWiki:Gadget-'; //Répertoire des gadgets
var cspGadgetsLinks = SiteURL + cspGadgetsRepos ; //Url du répertoire des gadgets
var cspMainScript = 'Utilisateur:' + mw.config.get('wgUserName').replace(/ /,"_") + '/GlobalManager.js'; //Page où est copié le code du manager
var cspSummary = 'Mise à jour avec [[' + cspMainScript + ']]'; //Résumé de modification JS
var cspCssSummary = 'Mise à jour avec [[' + cspMainScript + ']]'; //Résumé de modification CSS
var cspCssStartComment = '/\* jncsp-start'; //Commentaire inséré au début du .css
var cspCssStartComment2 = ' La section ci-dessous est produite par le script : [[' + cspMainScript + ']] \*/'; //Commentaire supplémentaire inséré au début du .css
var cspCssConfigComment = '/\* jncsp-config'; //Commentaire de configuration du .css
var cspCssEndComment = '/\* jncsp-end \*/'; //Commentaire inséré à la fin du .css
var cspStartComment = '// jncsp-start'; //Commentaire inséré au début du .js
var cspStartComment2 = ' La section ci-dessous est produite par le script : [[' + cspMainScript + ']]'; //Commentaire supplémentaire inséré au début du .js
var cspConfigComment = '// jncsp-config'; //Commentaire de configuration du .js
var cspEndComment = '// jncsp-end'; //Commentaire inséré à la fin du .js
////////////////////////////// PARTIE PERSONNALISABLE (3/8) : DÉFINITION CSS /////////////////////////////////////////////////////////////////////////////////////////////////////////////
var cspCssFragments = [
/**********************************************************************************************************************************************
* id = un identifiant unique, généralement le nom de la fonction principale *
* type = 0 (défaut) : inclusion d'une page .css *
* 1 : le contenu de la variable page est recopié dans la page css *
* 2 : Titre de chapitre niveau 2 *
* 3 : Titre de chapitre niveau 3 *
* 4 : Titre de chapitre niveau 4 *
* 5 : Titre de chapitre niveau 5 *
* 6 : Titre de chapitre niveau 6 *
* 8 : Texte normal (HTML) *
* page = nom de la page où le css à inclure est stocké *
* rev = numéro de révision de la page (si inclusion d'une page archivée) *
* desc = description du css *
**********************************************************************************************************************************************/
{ desc: 'Comment ça marche ?', type: 2 },
{ desc: 'Insertion d\'une page personnelle', type: 3 },
{ id: 'setup-StylePerso',
page: cspCssRepos + 'StylePerso.css',
type: 0,
desc: '<a href=' + cspCssLinks + 'StylePerso.css>StylePerso</a>'
},
{ desc: 'Pour se faire une composition...', type: 3 },
{ desc: 'Liens', type: 4 },
{ id: 'setup-Liens-Roses',
page: 'a {text-decoration: none;color:#ff00ff;background: none;}',
type: 1,
desc: 'Rose '
},
{ id: 'setup-Liens-Rouges',
page: 'a {text-decoration: none;color:#ff0000;background: none;}',
type: 1,
desc: 'Rouge '
},
{ id: 'setup-Liens-Bleus',
page: 'a {text-decoration: none;color:#0000ff;background: none;}',
type: 1,
desc: 'Bleu '
},
{ id: 'setup-Liens-Verts',
page: 'a {text-decoration: none;color:#00ff00;background: none;}',
type: 1,
desc: 'Vert '
},
{ id: 'setup-Liens-Noirs',
page: 'a {text-decoration: none;color:#000000;background: none;}',
type: 1,
desc: 'Noir '
},
{ desc: 'Liens visités', type: 4 },
{ id: 'setup-Liens-Visités-Roses',
page: 'a:visited {color: #ff00ff;}',
type: 1,
desc: 'Rose '
},
{ id: 'setup-Liens-Visités-Rouges',
page: 'a:visited {color: #ff0000;}',
type: 1,
desc: 'Rouge '
},
{ id: 'setup-Liens-Visités-Bleus',
page: 'a:visited {color: #0000ff;}',
type: 1,
desc: 'Bleu '
},
{ id: 'setup-Liens-Visités-Verts',
page: 'a:visited {color: #00ff00;}',
type: 1,
desc: 'Vert '
},
{ id: 'setup-Liens-Visités-Noirs',
page: 'a:visited {color: #ffffff;}',
type: 1,
desc: 'Noir '
},
{ desc: 'Liens actif', type: 4 },
{ id: 'setup-Liens-Actifs-Roses',
page: 'a:active {color: #ff00ff;}',
type: 1,
desc: 'Rose '
},
{ id: 'setup-LiensActifs-Rouges',
page: 'a:active {color: #ff0000;}',
type: 1,
desc: 'Rouge '
},
{ id: 'setup-Liens-Actifs-Bleus',
page: 'a:active {color: #0000ff;}',
type: 1,
desc: 'Bleu '
},
{ id: 'setup-Liens-Actifs-Verts',
page: 'a:active {color: #00ff00;}',
type: 1,
desc: 'Vert '
},
{ id: 'setup-Liens-Actifs-Noirs',
page: 'a:active {color: #ffffff;}',
type: 1,
desc: 'Noir '
},
];
////////////////////////////// PARTIE PERSONNALISABLE (4/8) : DÉFINITION JS /////////////////////////////////////////////////////////////////////////////////////////////////////////////
var cspFragments = [
/**********************************************************************************************************************************************
* id = un identifiant unique, généralement le nom de la fonction principale *
* type = 0 (défaut) : Le script sera entièrement recopié dans la page. (Peut se révéler problématique avec certains caractères spéciaux.) *
* 1 : Le script sera inclus par un élément <script> (solution préférable) *
* 2 : Titre de chapitre niveau 2 *
* 3 : Titre de chapitre niveau 3 *
* 4 : Titre de chapitre niveau 4 *
* 5 : Titre de chapitre niveau 5 *
* 6 : Titre de chapitre niveau 6 *
* 8 : Texte normal (HTML) *
* page = nom de la page où le script à inclure est stocké *
* rev = numéro de révision de la page (si inclusion d'une page archivée) *
* deps = liste des dépendances, à ignorer si il n'y en a pas *
* desc = description du script *
**********************************************************************************************************************************************/
{ desc: 'Comment ça marche ?', type: 2 },
{ desc: 'Insertion d\'une page personnelle', type: 3 },
{ id: 'setup-BacASable',
page: cspScriptRepos + 'BacASable.js',
type: 1,
desc: '<a href=' + cspScriptLinks + 'BacASable.js>BacASable</a>'
},
{ desc: 'Insertion d\'un gadget', type: 3 },
{ id: 'setup-HotCats',
page: cspGadgetsRepos + 'HotCats.js',
type: 1,
desc: '<a href=' + cspGadgetsLinks + 'HotCats.js>HotCats</a>'
},
{ desc: 'Insertion d\'une autre page du wiki', type: 3 },
{ id: 'setup-favoris',
page: 'Utilisateur:Dr_Brains/favoris.js',
type: 1,
desc: '<a href=' + SiteURL + 'Utilisateur:Dr_Brains/favoris.js>favoris</a>'
},
];
//////////////////////////////////////////////////// FIN DE LA PARTIE PERSONNALISABLE ///////////////////////////////////////////////////////////////////////////////////////////////////////////
// LANCEMENT DU BOUZIN ...
// Petits liens en haut de page
$(RunManager);
// Gestion Javascript
if(
(
mw.config.get('wgPageName').match( cspEntryPage ) ||
mw.config.get('wgPageName').match( cspEntryPagealt1 )||
mw.config.get('wgPageName').match( cspEntryPagealt2 )||
mw.config.get('wgPageName').match( cspEntryPagealt3 )||
mw.config.get('wgPageName').match( cspEntryPagealt4 )||
mw.config.get('wgPageName').match( cspEntryPagealt5 )||
mw.config.get('wgPageName').match( cspEntryPagealt6 )||
mw.config.get('wgPageName').match( cspEntryPagealt7 )||
mw.config.get('wgPageName').match( cspEntryPagealt8 )
) && mw.config.get('wgAction')=="view" ){
addOnloadHook(clientSidePreferencesLoadFunction);
}
//Gestion CSS
if(
(
mw.config.get('wgPageName').match( cspCssPage ) ||
mw.config.get('wgPageName').match( cspCssPagealt1 )||
mw.config.get('wgPageName').match( cspCssPagealt2 )||
mw.config.get('wgPageName').match( cspCssPagealt3 )||
mw.config.get('wgPageName').match( cspCssPagealt4 )||
mw.config.get('wgPageName').match( cspCssPagealt5 )||
mw.config.get('wgPageName').match( cspCssPagealt6 )||
mw.config.get('wgPageName').match( cspCssPagealt7 )||
mw.config.get('wgPageName').match( cspCssPagealt8 )
) && mw.config.get('wgAction')=="view" ){
addOnloadHook(CSSclientSidePreferencesLoadFunction);
}
function cspCSSGetForm(CSS_oldconfig){
var f, i, CSS_res;
//////////////////////////////////////// PARTIE PERSONNALISABLE (5/8) : ENTÊTE CSS /////////////////////////////////////////////////////////////////////////////////////////////////////
CSS_res = '<p>'
+ '<table style=\"float:right;clear:right;\">'
+ '<td>'
+ '<div style=\"background:#EEE;\">'
+ '<center><h5>Styles CSS</h5></center>'
+ '<div style=\"font-size: 95%;background-color: white;color: black;border-collapse: collapse;border: 1px solid #aaa;padding: 0 .8em .3em .5em;\"><ul>'
+ '<li><b><a href=' + SiteURL + cspCssPage + '>' + cspSkin + '</a></b></li>'
+ '<li><a href=' + SiteURL + cspCssPagealt1 + '>' + cspSkinalt1 + '</a></li>'
+ '<li><a href=' + SiteURL + cspCssPagealt2 + '>' + cspSkinalt2 + '</a></li>'
+ '<li><a href=' + SiteURL + cspCssPagealt3 + '>' + cspSkinalt3 + '</a></li>'
+ '<li><a href=' + SiteURL + cspCssPagealt4 + '>' + cspSkinalt4 + '</a></li>'
+ '<li><a href=' + SiteURL + cspCssPagealt5 + '>' + cspSkinalt5 + '</a></li>'
+ '<li><a href=' + SiteURL + cspCssPagealt6 + '>' + cspSkinalt6 + '</a></li>'
+ '<li><a href=' + SiteURL + cspCssPagealt7 + '>' + cspSkinalt7 + '</a></li>'
+ '<li><a href=' + SiteURL + cspCssPagealt8 + '>' + cspSkinalt8 + '</a></li>'
+ '</ul></div></div>'
+ '</td>'
+ '<td>'
+ '<div style=\"background:#EEE;\">'
+ '<center><h5>Scripts JS</h5></center>'
+ '<div style=\"font-size: 95%;background-color: white;color: black;border-collapse: collapse;border: 1px solid #aaa;padding: 0 .8em .3em .5em;\"><ul>'
+ '<li><b><a href=' + SiteURL + cspEntryPage + '>' + cspSkin + '</a></b></li>'
+ '<li><a href=' + SiteURL + cspEntryPagealt1 + '>' + cspSkinalt1 + '</a></li>'
+ '<li><a href=' + SiteURL + cspEntryPagealt2 + '>' + cspSkinalt2 + '</a></li>'
+ '<li><a href=' + SiteURL + cspEntryPagealt3 + '>' + cspSkinalt3 + '</a></li>'
+ '<li><a href=' + SiteURL + cspEntryPagealt4 + '>' + cspSkinalt4 + '</a></li>'
+ '<li><a href=' + SiteURL + cspEntryPagealt5 + '>' + cspSkinalt5 + '</a></li>'
+ '<li><a href=' + SiteURL + cspEntryPagealt6 + '>' + cspSkinalt6 + '</a></li>'
+ '<li><a href=' + SiteURL + cspEntryPagealt7 + '>' + cspSkinalt7 + '</a></li>'
+ '<li><a href=' + SiteURL + cspEntryPagealt8 + '>' + cspSkinalt8 + '</a></li>'
+ '</ul></div></div>'
+ '</td>'
+ '</table>'
+ 'Sélectionner les styles à ajouter à la page : <big><b>' + mw.config.get('wgPageName') + '</b></big> '
+ '<sup><small><a href=http://fr.wikipedia.org/wiki/Discussion_Utilisateur:Dr_Brains/GlobalManager.js>Aide</a></small></sup>'
+ '<br />'
+ '<br />'
+ '<b>Note :</b>'
+ ' Après avoir publié la page, vous devrez forcer son rechargement pour voir les changements :'
+ ' <b>Mozilla / Konqueror / Firefox / Opera</b> : <tt>Shift-Ctrl-R</tt>,'
+ ' <b>Internet Explorer</b> : <tt>Ctrl-F5</tt>,'
+ ' <b>Safari</b> : <tt>Cmd-R</tt>.'
+ '</p>\n'
+ '<form>\n';
//////////////////////////////////////// FIN DE LA PARTIE PERSONNALISABLE ///////////////////////////////////////////////////////////////////////////////////////////////////////////
for (i=0; i<cspCssFragments.length; i++) {
f = cspCssFragments[i];
if (!f.desc) continue;
if (f.type == 2) {
if (i != 0) CSS_res += '</p>\n';
CSS_res += '<h2><span class="mw-headline">' + f.desc
+ '</span></h2>\n'
+ '<p>\n';
} else {
if (f.type == 3) {
if (i != 0) CSS_res += '</p>\n';
CSS_res += '<h3><span class="mw-headline">' + f.desc
+ '</span></h3>\n'
+ '<p>\n';
} else {
if (f.type == 4) {
if (i != 0) CSS_res += '</p>\n';
CSS_res += '<h4><span class="mw-headline">' + f.desc
+ '</span></h4>\n'
+ '<p>\n';
} else {
if (f.type == 5) {
if (i != 0) CSS_res += '</p>\n';
CSS_res += '<h5><span class="mw-headline">' + f.desc
+ '</span></h5>\n'
+ '<p>\n';
} else {
if (f.type == 6) {
if (i != 0) CSS_res += '</p>\n';
CSS_res += '<h6><span class="mw-headline">' + f.desc
+ '</span></h6>\n'
+ '<p>\n';
} else {
if (f.type == 8) {
if (i != 0) CSS_res += '</p>\n';
CSS_res += f.desc + '<p>\n';
} else {
CSS_res += '<input type="checkbox" name="' + f.id + '" ';
if (CSS_oldconfig.indexOf(f.id) != -1)
CSS_res += 'checked ';
CSS_res += '/> ' + f.desc + '\n';
}
}
}
}
}
}
}
CSS_res += '<br /><br /><input type="button" onclick="cspCSSProcessForm();" value="Générer le style" /></p>\n'
+ '</form>\n';
return CSS_res;
}
function cspGetForm(oldconfig){
var f, i, res;
//////////////////////////////////////// PARTIE PERSONNALISABLE (6/8) : ENTÊTE JS /////////////////////////////////////////////////////////////////////////////////////////////////////
res = '<p>'
+ '<table style=\"float:right;clear:right;\">'
+ '<td>'
+ '<div style=\"background:#EEE;\">'
+ '<center><h5>Styles CSS</h5></center>'
+ '<div style=\"font-size: 95%;background-color: white;color: black;border-collapse: collapse;border: 1px solid #aaa;padding: 0 .8em .3em .5em;\"><ul>'
+ '<li><b><a href=' + SiteURL + cspCssPage + '>' + cspSkin + '</a></b></li>'
+ '<li><a href=' + SiteURL + cspCssPagealt1 + '>' + cspSkinalt1 + '</a></li>'
+ '<li><a href=' + SiteURL + cspCssPagealt2 + '>' + cspSkinalt2 + '</a></li>'
+ '<li><a href=' + SiteURL + cspCssPagealt3 + '>' + cspSkinalt3 + '</a></li>'
+ '<li><a href=' + SiteURL + cspCssPagealt4 + '>' + cspSkinalt4 + '</a></li>'
+ '<li><a href=' + SiteURL + cspCssPagealt5 + '>' + cspSkinalt5 + '</a></li>'
+ '<li><a href=' + SiteURL + cspCssPagealt6 + '>' + cspSkinalt6 + '</a></li>'
+ '<li><a href=' + SiteURL + cspCssPagealt7 + '>' + cspSkinalt7 + '</a></li>'
+ '<li><a href=' + SiteURL + cspCssPagealt8 + '>' + cspSkinalt8 + '</a></li>'
+ '</ul></div></div>'
+ '</td>'
+ '<td>'
+ '<div style=\"background:#EEE;\">'
+ '<center><h5>Scripts JS</h5></center>'
+ '<div style=\"font-size: 95%;background-color: white;color: black;border-collapse: collapse;border: 1px solid #aaa;padding: 0 .8em .3em .5em;\"><ul>'
+ '<li><b><a href=' + SiteURL + cspEntryPage + '>' + cspSkin + '</a></b></li>'
+ '<li><a href=' + SiteURL + cspEntryPagealt1 + '>' + cspSkinalt1 + '</a></li>'
+ '<li><a href=' + SiteURL + cspEntryPagealt2 + '>' + cspSkinalt2 + '</a></li>'
+ '<li><a href=' + SiteURL + cspEntryPagealt3 + '>' + cspSkinalt3 + '</a></li>'
+ '<li><a href=' + SiteURL + cspEntryPagealt4 + '>' + cspSkinalt4 + '</a></li>'
+ '<li><a href=' + SiteURL + cspEntryPagealt5 + '>' + cspSkinalt5 + '</a></li>'
+ '<li><a href=' + SiteURL + cspEntryPagealt6 + '>' + cspSkinalt6 + '</a></li>'
+ '<li><a href=' + SiteURL + cspEntryPagealt7 + '>' + cspSkinalt7 + '</a></li>'
+ '<li><a href=' + SiteURL + cspEntryPagealt8 + '>' + cspSkinalt8 + '</a></li>'
+ '</ul></div></div>'
+ '</td>'
+ '</table>'
+ 'Sélectionner les scripts à ajouter à la page : <big><b>' + mw.config.get('wgPageName') + '</b></big> '
+ '<sup><small><a href=http://fr.wikipedia.org/wiki/Discussion_Utilisateur:Dr_Brains/GlobalManager.js>Aide</a></small></sup>'
+ '<br />'
+ '<br />'
+ '<b>Note :</b>'
+ ' Après avoir publié la page, vous devrez forcer son rechargement pour voir les changements :'
+ ' <b>Mozilla / Konqueror / Firefox / Opera</b> : <tt>Shift-Ctrl-R</tt>,'
+ ' <b>Internet Explorer</b> : <tt>Ctrl-F5</tt>,'
+ ' <b>Safari</b> : <tt>Cmd-R</tt>.'
+ '</p>\n'
+ '<form>\n';
//////////////////////////////////////// FIN DE LA PARTIE PERSONNALISABLE ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
for (i=0; i<cspFragments.length; i++) {
f = cspFragments[i];
if (!f.desc) continue;
if (f.type == 2) {
if (i != 0) res += '</p>\n';
res += '<h2><span class="mw-headline">' + f.desc
+ '</span></h2>\n'
+ '<p>\n';
} else {
if (f.type == 3) {
if (i != 0) res += '</p>\n';
res += '<h3><span class="mw-headline">' + f.desc
+ '</span></h3>\n'
+ '<p>\n';
} else {
if (f.type == 4) {
if (i != 0) res += '</p>\n';
res += '<h4><span class="mw-headline">' + f.desc
+ '</span></h4>\n'
+ '<p>\n';
} else {
if (f.type == 5) {
if (i != 0) res += '</p>\n';
res += '<h5><span class="mw-headline">' + f.desc
+ '</span></h5>\n'
+ '<p>\n';
} else {
if (f.type == 6) {
if (i != 0) res += '</p>\n';
res += '<h6><span class="mw-headline">' + f.desc
+ '</span></h6>\n'
+ '<p>\n';
} else {
if (f.type == 8) {
if (i != 0) res += '</p>\n';
res += f.desc + '<p>\n';
} else {
res += '<input type="checkbox" name="' + f.id + '" ';
if (oldconfig.indexOf(f.id) != -1)
res += 'checked ';
res += '/> ' + f.desc + ' \n';
}
}
}
}
}
}
}
res += '<br /><br /><input type="button" onclick="cspProcessForm();" value="Générer le script" /></p>\n'
+ '</form>\n';
return res;
}
function RunManager(){
var ManagerlinkDiv = document.createElement("div");
//////////////////////////////////////// PARTIE PERSONNALISABLE (7/8) : PETITS LIENS PERMANENTS /////////////////////////////////////////////////////////////////////////////////////////////////////
ManagerlinkDiv.innerHTML = "<small><center>"
+ "<a href=" + SiteURL + cspEntryPage + ">" + cspSkin + ".js</a> • "
+ "<sup><a href=" + SiteURL + cspMainScript + ">Manager</a></sup> • "
+ "<a href=" + SiteURL + cspCssPage + ">" + cspSkin + ".css</a>"
+ "</center></small>";
//////////////////////////////////////// FIN DE LA PARTIE PERSONNALISABLE ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ManagerlinkDiv.id = "ManagerLink";
//////////////////////////////////////// PARTIE PERSONNALISABLE (8/8) : AFFICHAGE /////////////////////////////////////////////////////////////////////////////////////////////////////
if( skin == "monobook" ){
var contentNode = document.getElementById("content");
contentNode.insertBefore(ManagerlinkDiv, contentNode.firstChild);
}
if( skin == "vector" ){
var contentNode = document.getElementById("content");
contentNode.insertBefore(ManagerlinkDiv, contentNode.firstChild);
}
if( skin == "chick" ){
var contentNode = document.getElementById("content");
contentNode.insertBefore(ManagerlinkDiv, contentNode.firstChild);
}
if( skin == "modern" ){
var contentNode = document.getElementById("mw_contentholder");
contentNode.insertBefore(ManagerlinkDiv, contentNode.firstChild);
}
if( skin == "cologneblue" ){
var contentNode = document.getElementById("article");
contentNode.insertBefore(ManagerlinkDiv, contentNode.firstChild);
}
if( skin == "nostalgia" ){
var contentNode = document.getElementById("article");
contentNode.insertBefore(ManagerlinkDiv, contentNode.firstChild);
}
if( skin == "standard" ){
var contentNode = document.getElementById("article");
contentNode.insertBefore(ManagerlinkDiv, contentNode.firstChild);
}
//if( skin == "myskin" ){ // "Myskin" ne marche pas (pour l'instant...)
// var contentNode = document.getElementById("???????");
// contentNode.insertBefore(ManagerlinkDiv, contentNode.firstChild);
//}
//if( skin == "simple" ){ // "Simple" ne marche pas (pour l'instant...)
// var contentNode = document.getElementById("???????");
// contentNode.insertBefore(ManagerlinkDiv, contentNode.firstChild);
//}
}
function cspReplacePage(x){
if( skin == "monobook" ){
var el = document.getElementById('bodyContent').childNodes[0];
}
if( skin == "vector" ){
var el = document.getElementById('bodyContent').childNodes[0];
}
if( skin == "chick" ){
var el = document.getElementById('bodyContent').childNodes[0];
}
if( skin == "modern" ){
var el = document.getElementById('mw_contentholder').childNodes[0];
}
if( skin == "cologneblue" ){
var el = document.getElementById('article').childNodes[0];
}
if( skin == "nostalgia" ){
var el = document.getElementById('article').childNodes[0];
}
if( skin == "standard" ){
var el = document.getElementById('article').childNodes[0];
}
//if( skin == "myskin" ){ // "Myskin" ne marche pas (pour l'instant...)
// var el = document.getElementById('???????').childNodes[0];
//}
//if( skin == "simple" ){ // "Simple" ne marche pas (pour l'instant...)
// var el = document.getElementById('???????').childNodes[0];
//}
while (el.nextSibling) {
el = el.nextSibling;
if (el.tagName && el.tagName.toLowerCase() == 'p')
break;
}
el.parentNode.replaceChild(x, el);
}
function cspCSSReplacePage(x){
if( skin == "monobook" ){
var CSS_el = document.getElementById('bodyContent').childNodes[0];
}
if( skin == "vector" ){
var CSS_el = document.getElementById('bodyContent').childNodes[0];
}
if( skin == "chick" ){
var CSS_el = document.getElementById('bodyContent').childNodes[0];
}
if( skin == "modern" ){
var CSS_el = document.getElementById('mw_contentholder').childNodes[0];
}
if( skin == "cologneblue" ){
var CSS_el = document.getElementById('article').childNodes[0];
}
if( skin == "nostalgia" ){
var CSS_el = document.getElementById('article').childNodes[0];
}
if( skin == "standard" ){
var CSS_el = document.getElementById('article').childNodes[0];
}
//if( skin == "myskin" ){ // "Myskin" ne marche pas (pour l'instant...)
// var CSS_el = document.getElementById('???????').childNodes[0];
//}
//if( skin == "simple" ){ // "Simple" ne marche pas (pour l'instant...)
// var CSS_el = document.getElementById('???????').childNodes[0];
//}
while (CSS_el.nextSibling) {
CSS_el = CSS_el.nextSibling;
if (CSS_el.tagName && CSS_el.tagName.toLowerCase() == 'p')
break;
}
CSS_el.parentNode.replaceChild(x, CSS_el);
}
//////////////////////////////////////// FIN DE LA PARTIE PERSONNALISABLE ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//****************************************************************************** FONCTIONS SKIN CSS ******************************************************************************
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/* Construct an XMLHttpRequest **************************************************************************/
function cspCSSConstructHttpRequest()
{
var CSS_res;
// Copied from http://developer.mozilla.org/en/docs/AJAX:Getting_Started
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
CSS_res = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE
CSS_res = new ActiveXObject("Microsoft.XMLHTTP");
}
return CSS_res;
}
/**************************************************************************************************************/
function getCSSXmlObj(req) {
if (req.responseXML && req.responseXML.documentElement)
return req.responseXML;
// Note: this doesn't work in konqueror, and the natural fix
// var doc=document.implementation.createDocument(); doc.loadXML(req.responseXML)
// results in a segfault :-(
try {
var CSS_doc = new ActiveXObject("Microsoft.XMLDOM");
CSS_doc.async = "false";
CSS_doc.loadXML(req.responseText);
}
catch (err) {
return null;
}
return CSS_doc;
}
/* Checks whether the request has finished successfully req = XMLHtmlRequest Returns true or false **************************/
function cspCSSRequestDone(req)
{
if (req.readyState != 4) {
// still not ready
return false;
}
if (window.http_request.status != 200) {
alert('Il y a eu un problème avec la requête.');
return false;
}
return true;
}
// Source: http://www.albionresearch.com/misc/urlencode.php ************************************************************
function URLEncode( plaintext )
{
// The Javascript escape and unescape functions do not correspond
// with what browsers actually do...
var SAFECHARS = "0123456789" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "-_.!~*'()";
var HEX = "0123456789ABCDEF";
var encoded = "";
for (var i = 0; i < plaintext.length; i++ ) {
var ch = plaintext.charAt(i);
if (ch == " ") {
encoded += "+"; // x-www-urlencoded, rather than %20
} else if (SAFECHARS.indexOf(ch) != -1) {
encoded += ch;
} else {
var charCode = ch.charCodeAt(0);
if (charCode > 255) {
alert( "Le caractère Unicode '" + ch + "' ne peut pas être encodé en URL standard.\n" +
"(l'encodage URL supporte seulement les caractères de 8 bits.)\n" +
"Un espace (+) sera substitué." );
encoded += "+";
} else {
encoded += "%";
encoded += HEX.charAt((charCode >> 4) & 0xF);
encoded += HEX.charAt(charCode & 0xF);
}
}
} // for
return encoded;
}
/* Returns dictionary with form data *****************************************************************/
function cspCSSFormData(CSS_form) {
var CSS_res = new Object();
for (var i=0; i<CSS_form.elements.length; ++i) {
var CSS_el = CSS_form.elements[i];
var CSS_data;
if (!CSS_el.name)
continue;
if (CSS_el.tagname && CSS_el.tagname == 'textarea')
CSS_data = CSS_el.childNodes[0].CSS_data;
else if (CSS_el.checked)
CSS_data = ((CSS_el.checked == 'checked') ? 'on' : 'off');
else if (CSS_el.value)
CSS_data = CSS_el.value;
else
continue;
CSS_res[CSS_el.name] = CSS_data;
}
return CSS_res;
}
/* Returns index of fragment with given id in fraglist, or -1 if it is not there. ******************************************/
function cspCSSFindFragment(id, fraglist)
{
for (var n=0; n<fraglist.length; n++) {
if (fraglist[n].id == id)
return n;
}
return -1;
}
/* Add fragment f to the list of fragments to be downloaded */
function cspCSSAddFragment(f)
{
var d, pos, i, tmp;
/* If f is already on the list, we're done */
if (cspCSSFindFragment(f.id, window.fragments) != -1)
return;
pos = -1;
if (f.deps) {
/* Add all dependencies */
for (i=0; i<f.deps.length; i++) {
tmp = cspCSSFindFragment(f.deps[i], cspCssFragments);
if (tmp == -1)
alert("Erreur dans cspCSSAddFragment : Impossible de trouver " + f.deps[i]);
cspCSSAddFragment(cspCssFragments[tmp]);
}
/* Find the last dependency */
for (i=0; i<f.deps.length; i++) {
tmp = cspCssFindFragment(f.deps[i], window.fragments);
if (tmp>pos)
pos = tmp;
}
}
/* Add f after all its dependencies */
window.fragments.splice(pos+1, 0, f);
}
/**************************************************************************************************** Main script ****************/
/* This function is called if the user visits the entry page. */
function CSSclientSidePreferencesLoadFunction()
{
var CSS_p = document.createElement("p");
CSS_p.innerHTML = "<p>Veuillez patienter pendant l\'analyse de votre configuration …</p>";
cspCSSReplacePage(CSS_p);
window.http_request = cspCSSConstructHttpRequest();
window.http_request.onreadystatechange = cspCSSReceivedOldScript;
var url = SiteURLbis + mw.config.get('wgPageName') + '&action=raw'; /////////////////////////////////////////////////////////////////////////////////////////////////////////// Analyse
window.http_request.open('GET', url, true);
window.http_request.send(null);
}
/* This function is called when the old user script is received. ***********************************************/
function cspCSSReceivedOldScript()
{
if (!cspCSSRequestDone(window.http_request))
return;
window.oldscript = window.http_request.responseText;
var CSS_oldconfig = [];
var i = window.oldscript.indexOf(cspCssConfigComment);
if (i != -1) {
var i2 = window.oldscript.indexOf('\n', i);
var CSS_oldconfig = window.oldscript.substring(i+cspCssConfigComment.length+1, i2).split(' ');
}
cspCSSDisplayForm(CSS_oldconfig);
}
/* Creates and display the HTML form. ****************************************************************************************************************/
function cspCSSDisplayForm(CSS_oldconfig)
{
var cspCssForm = document.createElement("form");
cspCssForm.innerHTML = cspCSSGetForm(CSS_oldconfig);
cspCssForm.name = 'cspCssForm';
cspCSSReplacePage(cspCssForm);
}
/* This function is called when the user presses the "Generate script" button. **************************************************************************
It collects all fragments that should be downloaded in window.fragments
and starts building the new script in window.newscript */
function cspCSSProcessForm()
{
window.fragments = new Array();
var CSS_newconfig = '';
for (var i=0; i<cspCssFragments.length; i++) {
var f = cspCssFragments[i];
if (f.desc && f.type <= 1 && document.cspCssForm[f.id].checked) {
cspCSSAddFragment(f);
CSS_newconfig += ' ' + f.id;
}
}
window.newscript = '';
var i = window.oldscript.indexOf(cspStartComment);
if (i != -1)
window.newscript += window.oldscript.substr(0, i)
window.newscript += cspCssStartComment + cspCssStartComment2 + '\n';
window.newscript += cspCssConfigComment + CSS_newconfig + " \*/" + '\n\n';
var s = '';
window.newscript += s;
window.bottom = document.cspCssForm;
cspCSSGetFragments();
}
/* Go through the fragments listed in window.fragments and ************************************************************************
build window.newscript */
function cspCSSGetFragments()
{
if (window.fragments.length == 0) {
cspCSSFinalizeScript();
return;
}
var f = window.fragments[0];
if (f.type == 1)
cspCSSImportFragment(f);
else
cspCSSImportPage(f)
}
/* Callback for HTTP request initiated in cspDownloadFragment() **********************************************************************************************/
function cspCSSReceivedFragment()
{
if (!cspCSSRequestDone(window.http_request))
return;
var msg = document.createTextNode(' OK');
window.bottom = window.bottom.parentNode.insertBefore(msg, bottom.nextSibling);
window.bottom = window.bottom.parentNode.insertBefore(document.createElement('BR'), bottom.nextSibling);
var txt = window.http_request.responseText;
var tmp = /\/\/[ ]*<pre><nowiki>[ ]*\n/.exec(txt);
if (tmp)
txt = txt.slice(tmp.index + tmp[0].length);
tmp = /\/\/[ ]*<\/nowiki><\/pre>[ ]*(\n|$)/.exec(txt);
if (tmp)
txt = txt.slice(0, tmp.index);
else {
tmp = /\/\*.*<pre>.*\*\/\n/.exec(txt);
if (tmp)
txt = txt.slice(tmp.index + tmp[0].length);
tmp = /\/\*.*<\/pre>.*\*\/(\n|$)/.exec(txt);
if (tmp)
txt = txt.slice(0, tmp.index);
else {
tmp = /<pre>[ ]*\n/.exec(txt);
if (tmp)
txt = txt.slice(tmp.index + tmp[0].length);
tmp = /<\/pre>[ ]*(\n|$)/.exec(txt);
if (tmp)
txt = txt.slice(0, tmp.index);
}
}
window.newscript += '\n/\* Copie de [[' + (window.fragments[0].page).replace('_', ' ')
+ ', revision ' + window.fragments[0].rev + '\n\n' + txt + ' \*/\n';
window.fragments = window.fragments.slice(1);
cspCSSGetFragments();
}
/* *********************************************************************************************/
function cspCSSImportFragment(f)
{
var msg = document.createTextNode('Copie de ' + f.page);
window.bottom = window.bottom.parentNode.insertBefore(msg, bottom.nextSibling);
window.bottom = window.bottom.parentNode.insertBefore(document.createElement('BR'), bottom.nextSibling);
window.newscript += '\n/\* Copie de ' + (window.fragments[0].page).replace('_', ' ') + ' \*/ \n\n'
+ f.page ;
window.fragments = window.fragments.slice(1);
cspCSSGetFragments();
}
/* *********************************************************************************************/
function cspCSSImportPage(f)
{
var msg = document.createTextNode('Importation de ' + f.page);
window.bottom = window.bottom.parentNode.insertBefore(msg, bottom.nextSibling);
window.bottom = window.bottom.parentNode.insertBefore(document.createElement('BR'), bottom.nextSibling);
window.newscript += '\n/\* Importation de [[' + (window.fragments[0].page).replace('_', ' ') + ']] \*/\n\n'
+ '@import url(' + SiteURLbis + f.page + '&action=raw&ctype=text/css); \n';
window.fragments = window.fragments.slice(1);
cspCSSGetFragments();
}
/****************************************************************************************************/
function cspCSSFinalizeScript()
{
window.newscript += '\n' + cspCssEndComment;
var i = window.oldscript.indexOf(cspCssEndComment);
if (i != -1)
window.newscript += window.oldscript.substr(i+cspCssEndComment.length)
cspCSSLoadEditPage();
}
/****************************************************************************************************/
function cspCSSLoadEditPage()
{
var msg = document.createTextNode('Chargement de votre style ...');
window.bottom = window.bottom.parentNode.insertBefore(msg, bottom.nextSibling);
window.http_request = cspCSSConstructHttpRequest();
window.http_request.overrideMimeType('text/xml');
window.http_request.onreadystatechange = cspCSSReceivedEditPage;
var url = SiteURLbis + mw.config.get('wgPageName') + '&action=edit'; /////////////////////////////////////////////////////////////////////////////////////////////////////////// Édition
window.http_request.open('GET', url, true);
window.http_request.send(null);
}
/****************************************************************************************************/
function cspCSSReceivedEditPage()
{
if (!cspCSSRequestDone(window.http_request))
return;
var doc = window.http_request.responseXML;
var editform = doc.getElementById('editform');
var CSS_data = cspCSSFormData(editform);
CSS_data['wpTextbox1'] = window.newscript;
CSS_data['wpSummary'] = cspCssSummary;
CSS_data['wpMinoredit'] = 'on';
CSS_data['wpPreview'] = null;
CSS_data['wpDiff'] = null;
var msg = document.createTextNode(' Sauvegarde de votre style ...');
window.bottom = window.bottom.parentNode.insertBefore(msg, bottom.nextSibling);
window.http_request = cspCSSConstructHttpRequest();
window.http_request.overrideMimeType('text/xml');
window.http_request.onreadystatechange = cspCSSEditPageSaved;
var url = SiteURLbis + mw.config.get('wgPageName') + '&action=submit'; /////////////////////////////////////////////////////////////////////////////////////////////////////////// Sauvegarde
window.http_request.open('POST', url, true);
window.http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
CSS_sendMe = '';
for (var name in CSS_data) {
if (CSS_data[name]) {
if (CSS_sendMe.length > 0)
CSS_sendMe += '&';
CSS_sendMe += URLEncode(name) + '=' + URLEncode(CSS_data[name]);
}
}
window.http_request.send(CSS_sendMe);
}
/****************************************************************************************************/
function cspCSSEditPageSaved()
{
if (!cspCSSRequestDone(window.http_request))
return;
var msg = document.createTextNode(' OK');
window.bottom = window.bottom.parentNode.insertBefore(msg, bottom.nextSibling);
window.bottom = window.bottom.parentNode.insertBefore(document.createElement('BR'), bottom.nextSibling);
window.location.reload();
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//****************************************************************************** FONCTIONS SCRIPT JS ******************************************************************************
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/* Construct an XMLHttpRequest */
function cspConstructHttpRequest()
{
var res;
// Copied from http://developer.mozilla.org/en/docs/AJAX:Getting_Started
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
res = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE
res = new ActiveXObject("Microsoft.XMLHTTP");
}
return res;
}
function getXmlObj(req) {
if (req.responseXML && req.responseXML.documentElement)
return req.responseXML;
// Note: this doesn't work in konqueror, and the natural fix
// var doc=document.implementation.createDocument(); doc.loadXML(req.responseXML)
// results in a segfault :-(
try {
var doc = new ActiveXObject("Microsoft.XMLDOM");
doc.async = "false";
doc.loadXML(req.responseText);
}
catch (err) {
return null;
}
return doc;
}
/* Checks whether the request has finished successfully
req = XMLHtmlRequest
Returns true or false */
function cspRequestDone(req)
{
if (req.readyState != 4) {
// still not ready
return false;
}
if (window.http_request.status != 200) {
alert('Il y a eu un problème avec la requête.');
return false;
}
return true;
}
// Source: http://www.albionresearch.com/misc/urlencode.php
function URLEncode( plaintext )
{
// The Javascript escape and unescape functions do not correspond
// with what browsers actually do...
var SAFECHARS = "0123456789" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "-_.!~*'()";
var HEX = "0123456789ABCDEF";
var encoded = "";
for (var i = 0; i < plaintext.length; i++ ) {
var ch = plaintext.charAt(i);
if (ch == " ") {
encoded += "+"; // x-www-urlencoded, rather than %20
} else if (SAFECHARS.indexOf(ch) != -1) {
encoded += ch;
} else {
var charCode = ch.charCodeAt(0);
if (charCode > 255) {
alert( "Le caractère Unicode '" + ch + "' ne peut pas être encodé en URL standard.\n" +
"(l'encodage URL supporte seulement les caractères de 8 bits.)\n" +
"Un espace (+) sera substitué." );
encoded += "+";
} else {
encoded += "%";
encoded += HEX.charAt((charCode >> 4) & 0xF);
encoded += HEX.charAt(charCode & 0xF);
}
}
} // for
return encoded;
}
/* Returns dictionary with form data */
function cspFormData(form) {
var res = new Object();
for (var i=0; i<form.elements.length; ++i) {
var el = form.elements[i];
var data;
if (!el.name)
continue;
if (el.tagname && el.tagname == 'textarea')
data = el.childNodes[0].data;
else if (el.checked)
data = ((el.checked == 'checked') ? 'on' : 'off');
else if (el.value)
data = el.value;
else
continue;
res[el.name] = data;
}
return res;
}
/* Returns index of fragment with given id in fraglist, or -1 if it is not there. */
function cspFindFragment(id, fraglist)
{
for (var n=0; n<fraglist.length; n++) {
if (fraglist[n].id == id)
return n;
}
return -1;
}
/* Add fragment f to the list of fragments to be downloaded */
function cspAddFragment(f)
{
var d, pos, i, tmp;
/* If f is already on the list, we're done */
if (cspFindFragment(f.id, window.fragments) != -1)
return;
pos = -1;
if (f.deps) {
/* Add all dependencies */
for (i=0; i<f.deps.length; i++) {
tmp = cspFindFragment(f.deps[i], cspFragments);
if (tmp == -1)
alert("Erreur dans cspAddFragment : Impossible de trouver " + f.deps[i]);
cspAddFragment(cspFragments[tmp]);
}
/* Find the last dependency */
for (i=0; i<f.deps.length; i++) {
tmp = cspFindFragment(f.deps[i], window.fragments);
if (tmp>pos)
pos = tmp;
}
}
/* Add f after all its dependencies */
window.fragments.splice(pos+1, 0, f);
}
/********** Main script **********/
/* This function is called if the user visits the entry page. */
function clientSidePreferencesLoadFunction()
{
var p = document.createElement("p");
p.innerHTML = "<p>Veuillez patienter pendant l\'analyse de votre configuration …</p>";
cspReplacePage(p);
window.http_request = cspConstructHttpRequest();
window.http_request.onreadystatechange = cspReceivedOldScript;
var url = SiteURLbis + mw.config.get('wgPageName') + '&action=raw'; ////////////////////////////////////////////*********************************************
window.http_request.open('GET', url, true);
window.http_request.send(null);
}
/* This function is called when the old user script is received. */
function cspReceivedOldScript()
{
if (!cspRequestDone(window.http_request))
return;
window.oldscript = window.http_request.responseText;
var oldconfig = [];
var i = window.oldscript.indexOf(cspConfigComment);
if (i != -1) {
var i2 = window.oldscript.indexOf('\n', i);
var oldconfig = window.oldscript.substring(i+cspConfigComment.length+1, i2).split(' ');
}
cspDisplayForm(oldconfig);
}
/* Creates and display the HTML form. */
function cspDisplayForm(oldconfig)
{
var cspForm = document.createElement("form");
cspForm.innerHTML = cspGetForm(oldconfig);
cspForm.name = 'cspForm';
cspReplacePage(cspForm);
}
/* This function is called when the user presses the "Generate script" button.
It collects all fragments that should be downloaded in window.fragments
and starts building the new script in window.newscript */
function cspProcessForm()
{
window.fragments = new Array();
var newconfig = '';
for (var i=0; i<cspFragments.length; i++) {
var f = cspFragments[i];
if (f.desc && f.type <= 1 && document.cspForm[f.id].checked) {
cspAddFragment(f);
newconfig += ' ' + f.id;
}
}
window.newscript = '';
var i = window.oldscript.indexOf(cspStartComment);
if (i != -1)
window.newscript += window.oldscript.substr(0, i)
window.newscript += cspStartComment + cspStartComment2 + '\n';
window.newscript += cspConfigComment + newconfig + '\n\n';
var s = 'document.write(\'<script type="text/javascript" src="' + SiteURLbis + cspMainScript + '&action=raw&ctype=text/javascript"></script>\'); \n';
window.newscript += s;
window.bottom = document.cspForm;
cspGetFragments();
}
/* Go through the fragments listed in window.fragments and
build window.newscript */
function cspGetFragments()
{
if (window.fragments.length == 0) {
cspFinalizeScript();
return;
}
var f = window.fragments[0];
if (f.type == 1)
cspImportFragment(f);
else
cspDownloadFragment(f)
}
/* Download a JavaScript fragment to be included in the user script */
function cspDownloadFragment(f)
{
var msg = document.createTextNode('Copie de ' + f.page + ' ...');
window.bottom = window.bottom.parentNode.insertBefore(msg, bottom.nextSibling);
window.http_request = cspConstructHttpRequest();
window.http_request.onreadystatechange = cspReceivedFragment;
var url = + SiteURLbis + f.page + '&oldid=' + f.rev + '&action=raw&ctype=text/javascript';
window.http_request.open('GET', url, true);
window.http_request.send(null);
}
/* Callback for HTTP request initiated in cspDownloadFragment() */
function cspReceivedFragment()
{
if (!cspRequestDone(window.http_request))
return;
var msg = document.createTextNode(' OK');
window.bottom = window.bottom.parentNode.insertBefore(msg, bottom.nextSibling);
window.bottom = window.bottom.parentNode.insertBefore(document.createElement('BR'), bottom.nextSibling);
var txt = window.http_request.responseText;
var tmp = /\/\/[ ]*<pre><nowiki>[ ]*\n/.exec(txt);
if (tmp)
txt = txt.slice(tmp.index + tmp[0].length);
tmp = /\/\/[ ]*<\/nowiki><\/pre>[ ]*(\n|$)/.exec(txt);
if (tmp)
txt = txt.slice(0, tmp.index);
else {
tmp = /\/\*.*<pre>.*\*\/\n/.exec(txt);
if (tmp)
txt = txt.slice(tmp.index + tmp[0].length);
tmp = /\/\*.*<\/pre>.*\*\/(\n|$)/.exec(txt);
if (tmp)
txt = txt.slice(0, tmp.index);
else {
tmp = /<pre>[ ]*\n/.exec(txt);
if (tmp)
txt = txt.slice(tmp.index + tmp[0].length);
tmp = /<\/pre>[ ]*(\n|$)/.exec(txt);
if (tmp)
txt = txt.slice(0, tmp.index);
}
}
window.newscript += '\n// Copie de [[' + (window.fragments[0].page).replace('_', ' ')
+ ']], revision ' + window.fragments[0].rev + '\n\n' + txt + '\n';
window.fragments = window.fragments.slice(1);
cspGetFragments();
}
/* Import JavaScript using a <script> tag */
function cspImportFragment(f)
{
var msg = document.createTextNode('Importation de ' + f.page);
window.bottom = window.bottom.parentNode.insertBefore(msg, bottom.nextSibling);
window.bottom = window.bottom.parentNode.insertBefore(document.createElement('BR'), bottom.nextSibling);
window.newscript += '\n// Importation de [[' + (window.fragments[0].page).replace('_', ' ') + ']]\n\n'
+ 'document.write(\'<script type="text/javascript" src="' + SiteURLbis + f.page + '&action=raw&ctype=text/javascript"></script>\'); \n';
window.fragments = window.fragments.slice(1);
cspGetFragments();
}
function cspFinalizeScript()
{
window.newscript += '\n' + cspEndComment;
var i = window.oldscript.indexOf(cspEndComment);
if (i != -1)
window.newscript += window.oldscript.substr(i+cspEndComment.length)
cspLoadEditPage();
}
function cspLoadEditPage()
{
var msg = document.createTextNode('Chargement de votre script ...');
window.bottom = window.bottom.parentNode.insertBefore(msg, bottom.nextSibling);
window.http_request = cspConstructHttpRequest();
window.http_request.overrideMimeType('text/xml');
window.http_request.onreadystatechange = cspReceivedEditPage;
var url = SiteURLbis + mw.config.get('wgPageName') + '&action=edit'; ////////////////////////////////////////******************************************************
window.http_request.open('GET', url, true);
window.http_request.send(null);
}
function cspReceivedEditPage()
{
if (!cspRequestDone(window.http_request))
return;
var doc = window.http_request.responseXML;
var editform = doc.getElementById('editform');
var data = cspFormData(editform);
data['wpTextbox1'] = window.newscript;
data['wpSummary'] = cspSummary;
data['wpMinoredit'] = 'on';
data['wpPreview'] = null;
data['wpDiff'] = null;
var msg = document.createTextNode(' Sauvegarde de votre script ...');
window.bottom = window.bottom.parentNode.insertBefore(msg, bottom.nextSibling);
window.http_request = cspConstructHttpRequest();
window.http_request.overrideMimeType('text/xml');
window.http_request.onreadystatechange = cspEditPageSaved;
var url = SiteURLbis + mw.config.get('wgPageName') + '&action=submit'; ///////////////////////////////////******************************************
window.http_request.open('POST', url, true);
window.http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
sendMe = '';
for (var name in data) {
if (data[name]) {
if (sendMe.length > 0)
sendMe += '&';
sendMe += URLEncode(name) + '=' + URLEncode(data[name]);
}
}
window.http_request.send(sendMe);
}
function cspEditPageSaved()
{
if (!cspRequestDone(window.http_request))
return;
var msg = document.createTextNode(' OK');
window.bottom = window.bottom.parentNode.insertBefore(msg, bottom.nextSibling);
window.bottom = window.bottom.parentNode.insertBefore(document.createElement('BR'), bottom.nextSibling);
window.location.reload();
}
/****************************************************************************************************/
//</nowiki></pre>