Les témoins (cookies) nous aident à fournir nos services. En utilisant nos services, vous acceptez notre utilisation des témoins. Plus d’informations

Modifications

Aller à : navigation, rechercher

MediaWiki:Gadget-HotCat.js

24 881 octets supprimés, 2 septembre 2009 à 19:42
retour à la version française
//<source lang="javascript"nowiki>/** * Ajoute des liens après les catégories pour rapidement * supprimer / modifier / ajouter une catégorie sur un article. * Utilise Ajax et l'api MediaWiki pour rechercher une catégorie. * Version adaptée pour WP:fr de [[:commons:MediaWiki:HotCat.js]] * * Auteur original : Magnus Manske * Adaptation pour WP:fr : Zelda * [[Catégorie:MediaWiki:Fonction Monobook en JavaScript]] */
if (typeof (hotcat_loaded) == 'undefined') {var hotcat_loaded = false; // Guard against double inclusionsvar hotcat_running = 0 ;var hotcat_last_v = "" ;var hotcat_exists_yes = "http://upload.wikimedia.org/wikipedia/commons/thumb/b/be/P_yes.svg/20px-P_yes.svg.png" ;var hotcat_exists_no = "http://upload.wikimedia.org/wikipedia/commons/thumb/4/42/P_no.svg/20px-P_no.svg.png" ;var hotcat_upload = 0 ;var hotcat_no_autocommit = 0;var hotcat_old_onsubmit = null;var hotcat_nosuggestions = false;// hotcat_nosuggestions is set to true if we don't have XMLHttp! (On IE6, XMLHttp uses// ActiveX, and the user may deny execution.) If true, no suggestions will ever be// displayed, and there won't be any checking whether the category exists.// Lupo, 2008-01-20VARIABLES PERSONNALISABLES
// Suggestion delay in msvar hotcat_suggestion_delay = 100;var hotcat_editbox_width = 40200;// Fallbacks if we don't have JSconfig. Lupo, 2009-06-24
// Taille de la liste déroulante (en items)var hotcat_modify_blacklist hotcat_list_size = new Array ("CC-" ,"GFDL" ,"PD") 10;
function hotcat_remove_upload ( text ) {// Nombre de categories suggérées lors de la recherche var cats hotcat_list_items = document.getElementById ( "catlinks" ) 50; cats = cats.getElementsByTagName ( "span" ) ; for ( var i = 0 ; i < cats.length ; i++ ) { if (cats[i].hotcat_name && cats[i].hotcat_name == text) { cats[i].parentNode.removeChild ( cats[i].nextSibling ) ; cats[i].parentNode.removeChild ( cats[i] ) ; break ; } }}
function hotcat_check_upload () { // Don't do anything if not "Special:Upload", or user not logged in. if ( wgNamespaceNumber != -1 || wgCanonicalSpecialPageName != "Upload" || wgUserName == null) return ; var ip = document.getElementById ( "wpWatchthis" ) ; // Go to Special:Upload, choose a local file, enter a target file name without extension, // then submit: you get a page that is "Special:Upload", but that doesn't have any form! if (ip == null) return; var reupload = document.getElementById ('wpForReUpload'); var destFile = document.getElementById (Permet d'wpDestFileenregistrer automatiquement la modif sans repasser par la fenêtre d'); if ( (reupload && !!reupload.value) || (destFile && (destFile.disabled || destFile.readonly)))édition return; // re-upload form... hotcat_upload = 1 ; var tr = ip.parentNode.parentNode ; var ntr = document.createElement ( "tr" ) ; var ntd = document.createElement ( "td" ) ; var ntde = document.createElement ( "td" ) ; var catline = document.createElement ( "div" ) ; var np hotcat_autocommit = document.createElement ( "p" ) false;
ntde.setAttribute ('id', 'hotcatLabel'); var label = null; if (typeof (UFUI) != 'undefined' && typeof (UFUI.getLabel) == 'function') { try { label = UFUI.getLabel ('wpCategoriesUploadLbl'); } catch (ex) { label = null; } } if (label == null) ntde.appendChild (document.createTextNode ("Categories:")); else { ntde.setAttribute ('id', 'hotcatLabelTranslated'); // Change the ID to avoid that UploadForm tries to translate it again. ntde.appendChild (label); } ntde.style.textAlign = "right" ; ntde.style.verticalAlign = "middle" ; catline.id = "catlinks" ; // On the upload form, the Permet d'afficher la liste de suggestion box appears at the very top of the page. That is becausevers le bas // the innermost enclosing div of the upload form (and its table) that has position "relative" // is the bodyContent div. Try to fix that by giving catline relative positioning, so absolute // positioning within should be relative to catline. Lupo, 2008-01-18 catline.style.position ="relative"; catline.style.textAlign = "left"; // Otherwise, it looks bad in the Classic skin on the upload form. Lupo, 2008-05-16 np.className = "catlinks" ; np.style.textAlign var hotcat_list_down = "left"; catline.appendChild ( np ) ; ntd.appendChild ( catline ) ; ntde.className = 'mw-label'; ntr.appendChild ( ntde ) ; ntr.appendChild ( ntd ) false;
// Add handler for submit (changed by Lupo, 2008-01-18) var form = document.getElementById ('upload'); // Grrr... they changed the upload form! // http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/includes/SpecialUpload.php?r1=32033&r2=32190 if (!form) form = document.getElementById ('mw-upload-form'); if (form) { hotcat_old_onsubmit = form.onsubmit; form.onsubmit = hotcat_on_upload; tr.parentNode.insertBefore ( ntr , tr ) ; // Insert *above* "Watch this" box }}FIN DE LA PERSONNALISATION DES VARIABLES
function hotcat_on_upload () {var hotcat_running = 0 ;var hotcat_last_v = "" ; var hotcat_exists_yes = "http:// First, make sure that if we have an open category input form, we close itupload.wikimedia.org/wikipedia/commons/thumb/b/be/P_yes.svg/20px-P_yes.svg.png" ; var input hotcat_exists_no = document"http://upload.wikimedia.org/wikipedia/commons/thumb/4/42/P_no.getElementById ('hotcat_text'); if (input != null) hotcat_ok ()svg/20px-P_no.svg.png" ;
var do_submit = true; // Call previous onsubmit handler, if any if (hotcat_old_onsubmit) { if (typeof hotcat_old_onsubmit wgNamespaceNumber%2 == 'string') do_submit = eval (hotcat_old_onsubmit); else if (typeof hotcat_old_onsubmit == 'function') do_submit = hotcat_old_onsubmit (); } if (!do_submit) return false; // Only copy the categories if we do submit var cats = 0 && document.getElementById ( "catlinks" ) ; cats = catsURL.getElementsByTagName indexOf( "span" ) ; var eb printable= document.getElementById ( "wpUploadDescription" ) || document.getElementById ( "wpDescyes" ); // New upload form for ( var i = 0 ; i < cats.length ; i++ ) { var t = cats[i].hotcat_name; if (!t-1) continue ; var new_cat = "\[\[Category:" + t + "\]\]" ; // Only add if not already present if addOnloadHook (eb.value.indexOf (new_cathotcat ) < 0) eb.value += "\n" + new_cat ; } return true;}
function hotcat () {
// Note: although we use JSconfig for our user-preferences, these won't show up in your preference // page because gadgets are not loaded on Special:Preferences! if (typeof hotcat_check_action(JSconfig) != 'undefined') { JSconfig.registerKey('HotCatDelay', 100, 'HotCat autocompletion delay (ms):', 5)return ; JSconfig.registerKey('HotCatEditBoxWidth'// Edited page, 40, 'Width of Input box of HotCat (# of characters):', 5); }reloading anyway
if ( hotcat_check_action() ) return ; // Edited page, reloading anyway if (hotcat_loaded) return; // Guard against double inclusions hotcat_loaded var catlinks = true; hotcat_check_upload document.getElementById("catlinks") ;
function can_edit if (! catlinks){ // all except discussion { // let's create a fake one var container bodyC = null; switch document.getElementById(skin"bodyContent") { case 'cologneblue':; container catlinks = document.getElementById createElement('quickbar'"div"); // Fall through catlinks.id = "catlinks"; case 'standard': case 'nostalgia': catlinks.className = "catlinks"; if (!container) container catlinks = documentbodyC.getElementById appendChild('topbar'catlinks); } var lks catline = containerdocument.getElementsByTagName getElementById ('amw-normal-catlinks');// Since MW 1.13alpha for if(var i = 0; i < lks.length; i++!catline ) { if catline = catlinks.insertBefore( hotcatGetParamValue document.createElement('title', lks[i].href"div") == wgPageName && hotcatGetParamValue ('action', lks[i]catlinks.href) == 'edit'firstChild) return true; } return false; default: // all modern skins: return document catline.getElementById ('caid = "mw-normal-edit') != null; } return falsecatlinks";
}
 
if( (!can_edit () && !hotcat_upload) // User has no permission to edit
|| wgAction != 'view' // User is editing or previewing or...
|| wgNamespaceNumber == -1 && !hotcat_upload) // Special page other than Special:Upload
return;
if (!wgIsArticle && !hotcat_uploadcatline == null || typeof catline == 'undefined' ) return; // Diff pages... // Note that wgIsArticle is also set to true for category, talk, user, etc. pages: anything that // can be edited. It is false for diff pages, special pages, and ...
var visible_cats = document.getElementById ('mw-normal-catlinks') || // MW 1.13alpha getElementsByClassName hotcat_modify_existing ( document , "p" , "catlinks" catline ) [0]; // MW < 1.13 && Special:Upload var hidden_cats = document.getElementById hotcat_append_add_span ('mw-hidden-catlinks'catline ); if (visible_cats == null) { // Insert an empty category line var footer = null; if (hidden_cats == null) { footer = getElementsByClassName (document , "div" , "printfooter")[0]; if (!footer) return; // Don't know where to insert the category line } visible_cats = document.createElement ('div'); visible_cats.setAttribute ('id', 'mw-normal-catlinks'); var label = document.createElement ('a'); label.setAttribute ('href', wgArticlePath.replace (/\$1/, 'Special:Categories')); label.setAttribute ('title', 'Special:Categories'); label.appendChild (document.createTextNode ('Category')); visible_cats.appendChild (label); visible_cats.appendChild (document.createTextNode (':')); if (hidden_cats == null) { var container = document.createElement ('div'); container.setAttribute ('id', 'catlinks'); container.className = 'catlinks'; container.appendChild (visible_cats); footer.parentNode.insertBefore (container, footer.nextSibling); } else { hidden_cats.parentNode.insertBefore (visible_cats, hidden_cats); hidden_cats.parentNode.className = 'catlinks'; hidden_cats.parentNode.style.display = ""; // For good measure, in case this changes again } } // end if no categories
visible_cats.style.position var hotcat_edit_id_map= 'relative'[]; hotcat_modify_existing function hotcatGetEditId( visible_cats ob) ;{ hotcat_append_add_span ( visible_cats ) var i// Check for state restoration (Lupo, 2008-02-06i=0;i<hotcat_edit_id_map.length;i++) if ( hotcat_upload && typeof (UploadFormhotcat_edit_id_map[i]===ob) != 'undefined'return i; && typeof (UploadForm.previous_hotcat_state) ! i= 'undefined' && UploadFormhotcat_edit_id_map.previous_hotcat_state != null)length; UploadForm hotcat_edit_id_map.previous_hotcat_state = hotcat_set_state push(UploadForm.previous_hotcat_stateob); return i;
}
function hotcat_append_add_span ( catline ) {
var span_add = document.createElement ( "span" ) ;
var span_sep = document.createTextNode ( " | " ) ; if ( catline.getElementsByTagNamefirstChild ) catline.appendChild ( span_sep ) ; else { var a = document.createElement('spana')[0] ); a.href = '/wiki/Catégorie:Accueil'; a.title = 'Catégorie:Accueil'; catline a.appendChild (document.createTextNode (" | "'Catégories')); else if ( catline.firstChildappendChild(a); catline.appendChild (document.createTextNode (' : ')); } catline.appendChild ( span_add ); hotcat_create_span ( span_add );
}
}
function hotcat_is_on_blacklist ( cat_title ) { if ( !cat_title ) return 0 ; // cat_title = cat_title.split(":",2).pop() ; // Not needed anymore: we work without 'Category:' for ( var i = 0 ; i < hotcat_modify_blacklist.length ; i++ ) { if ( cat_title.substr ( 0 , hotcat_modify_blacklist[i].length ) == hotcat_modify_blacklist[i] ) return 1 ; } return 0 ;} function hotcat_modify_span ( span , i ) { //var cat_title = span.firstChild.getAttribute ( "title" ) ; // This fails with MW 1.13alpha if the category is a redlink, because MW 1.13alpha appends // [[MediaWiki:Red-link-title]] to the category name... it also fails if the category name // contains "&" (because that is represented by &amp; in the XHTML both in the title and in // the link's content (innerHTML). Extract the category name from the href insteadRemoving leading Category: var cat_title = null; var classes = " " + spancat_title.firstChildsubstr(cat_title.className + " "; var href = span.firstChild.getAttribute indexOf('href', 2); // Extra param "2" is ignored on W3C compliant browsers. It's for IE only. Note: // span.firstChild.href is the normalized URL, getAttribute ('href') should be the text from // the XHTML source, but IE somehow (a) also returns a full URL with server part, and (b) // IE6 insists on wrongly decoding encoded UTF-8 characters ("K%C3%B6ln-Riehl" becomes // "Köln-Riehl"). The work-around is to use the special IE variant with the extra parameter, // which Microsoft says returns the simple string as found in the XHTML. See their docu at // http://msdn.microsoft.com/en-us/library/ms536429(VS.85).aspx . if (!href+ 1) return; if (classes && classesvar sep1 = document.indexOf createTextNode (' new ') >= 0) { // href="/w/index.php?title=...&action=edit" cat_title = hotcatGetParamValue ('title', href); } else { // href="/wiki/..." var prefix a1 = wgArticlePathdocument.replace createTextNode ('$1', ""); if (href.indexOf (prefix) != 0" ) prefix = wgServer + prefix; // Fully expanded URL? if (href.indexOf (prefix) == 0) { cat_title = decodeURIComponent (href.substring (prefix.length)); } } if (!cat_title) return; // Strip namespace, replace _ by blank cat_title = cat_title.substring (cat_title.indexOf (':') + 1).replace (/_/g, ' '); 
var remove_link = document.createElement ( "a" ) ;
// Set the href to a dummy value to make sure we don't move if somehow the onclick handler // is bypassed. remove_link.href = "#catlinksjavascript:hotcat_remove(\"" + cat_title + "\"); remove_link.onclick = hotcat_remove" ; remove_link.appendChild ( document.createTextNode ( "(-)" ) a1 ) ; span.appendChild ( document.createTextNode ( " " ) sep1 ) ;
span.appendChild ( remove_link ) ;
if var i=hotcatGetEditId( hotcat_is_on_blacklist ( cat_title ) span) return ;
var mod_id = "hotcat_modify_" + i ;
var sep2 = document.createTextNode ( " " ) ;
var a2 = document.createTextNode ( "(±)" ) ;
var modify_link = document.createElement ( "a" ) ;
modify_link.id = mod_id ;
modify_link.href = "javascript:hotcat_modify(\"" + mod_id + "\");" ;
modify_link.appendChild ( document.createTextNode ( "(±)" ) a2 ) ; span.appendChild ( document.createTextNode ( " " ) sep2 ) ;
span.appendChild ( modify_link ) ;
span.hotcat_name = cat_title; //Store the extracted category name in our own new property of the span DOM node
}
var spans = catline.getElementsByTagName ( "span" ) ;
for ( var i = 0 ; i < spans.length ; i++ ) {
hotcat_modify_span ( spans[i] , i ) ; }} function hotcat_getEvt (evt) { return evt || window.event || window.Event; // Gecko, IE, Netscape} function hotcat_evt2node (evt) { var node = null; try { var e = hotcat_getEvt (evt); node = e.target; if (!node) node = e.srcElement; } catch (ex) { node = null; } return node;} function hotcat_evtkeys (evt) { var code = 0; try { var e = hotcat_getEvt (evt); if (typeof(e.ctrlKey) != 'undefined') { // All modern browsers if (e.ctrlKey) code |= 1; if (e.shiftKey) code |= 2; } else if (typeof (e.modifiers) != 'undefined') { // Netscape... if (e.modifiers & Event.CONTROL_MASK) code |= 1; if (e.modifiers & Event.SHIFT_MASK) code |= 2; } } catch (ex) {
}
return code;
}
function hotcat_killEvt hotcat_remove (evtcat_title ){ try { var e editlk = hotcat_getEvt document.getElementById(evt); if (typeof (e.preventDefault) != 'undefinedca-edit') { e.preventDefault (); e.stopPropagation getElementsByTagName('a'); } else e[0].cancelBubble = true; } catch (ex) { }} function hotcat_remove (evt) { var node = hotcat_evt2node (evt)href; if (!node) return false; // Get the category name from the original link to the category, which is at // node.parentNodewindow.firstChild (the DOM structure here is // <span><a...>Category</a> <a...>confirm("Voulez-vous vraiment supprimer la catégorie '" + cat_title + "' ?")</a>...</span>). var cat_title = node.parentNode.hotcat_name; if ( hotcat_upload ) { hotcat_remove_upload document.location = editlk + '&hotcat_removecat=' + encodeURIComponent( cat_title ) ; hotcat_killEvt (evt); return false;
}
var editlk = wgServer + wgScript + '?title=' + encodeURIComponent (wgPageName)
+ '&action=edit';
if (hotcat_evtkeys (evt) & 1) // CTRL pressed?
editlk = editlk + '&hotcat_nocommit=1';
hotcat_killEvt (evt);
document.location = editlk + '&hotcat_removecat=' + encodeURIComponent (cat_title);
return false;
}
function hotcatGetParamValue(paramName, h) {
if (typeof h == 'undefined' ) { h = document.location.href; } var cmdRe=RegExp('[&?]'+paramName+'=([^&]*)'); var m=cmdRe.exec(h); if (m) { try { return decodeURIComponent(m[1]); } catch (someError) {} } return null;} // New. Code by Lupo & Superm401, added by Lupo, 2008-02-27function hotcat_find_category (wikitext, category){ var cat_name = category.replace(/([\\\^\$\.\?\*\+\(\)])/g, "\\$1"); var initial = cat_name.substr (0, 1); var cat_regex = new RegExp ("\\[\\[\\s*[Cc]ategory\\s*:\\s*" + (initial == "\\" ? initial : "[" + initial.toUpperCase() + initial.toLowerCase() + "]") + cat_name.substring (1).replace (/[ _]/g, "[ _]") + "\\s*(\\|.*?)?\\]\\]", "g" ); var result = new Array (); var curr_match = null; while ((curr_match = cat_regex.exec (wikitext)) != null) { result [result.length] = {match : curr_match}; } return result; // An array containing all matches, with positions, in result[i].match
}
// All redirects to Template:Uncategorized
var hotcat_uncat_regex =
/\{\{\s*([Uu]ncat(egori[sz]ed( image)?)?|[Nn]ocat|[Nn]eedscategory)[^}]*\}\}/g;
 
// Rewritten (nearly) from scratch. Lupo, 2008-02-27
function hotcat_check_action () {
var ret = 0; if (wgAction != '"edit'" ) return ret; // Not an edit page, so not our no business... if (!document.editform || !document.editform.wpTextbox1) return ret; // No edit form??
var summary = new Array () ;
var t = document.editform.wpTextbox1.value ;
var prevent_autocommit = 01 ; if ( (typeof hotcat_no_autocommit hotcat_autocommit != "'undefined" ' && hotcat_no_autocommit) || hotcatGetParamValue ('hotcat_nocommit') == '1'hotcat_autocommit ) prevent_autocommit = 10 ;
var cat_rm = hotcatGetParamValue ('hotcat_removecat');// Remove existing category? var cat_add hrc = hotcatGetParamValue ('hotcat_newcathotcat_removecat'); var comment = hotcatGetParamValue ('hotcat_comment') || "";// Add new category? var cat_key hnc = hotcatGetParamValue ('hotcat_sortkeyhotcat_newcat');
if (cat_key typeof hrc != "undefined" && hrc != null&& hrc != "" ) cat_key { var hcre = 'new RegExp("(\\s*)\\[\\[ *(?:Catégorie|' Category) *: *" + cat_key; if hrc.replace(/(cat_rm != null && cat_rm[\\\^\$\*\+\?\.length > 0\|\{\}\[\]\(\)])/g, "\\$1") + " *(\\|[^\\]]*)?\\]\\]", "gi") {; var matches = hotcat_find_category t.match(t, cat_rmhcre); if (matches !matches || = null && matches.length == 01) {// Found one occurrence of the category - good! alert if ('Category typeof hnc != "undefined" && hnc != null && hnc != "" ) { t = t.replace(hcre, "$1[[Catégorie:"' + cat_rm hnc + '" not found$2]]"); maybe it is in a template?' summary.push ( "Modification de la catégorie [[Catégorie:" + hrc + "]] → [[Catégorie:" + hnc + "]]" ); prevent_autocommit = 1; } else if { t = t.replace(matches.length > 1hcre, "") {; alert summary.push ('Category "' Retrait de la catégorie [[Catégorie:" + cat_rm hrc + "\" found several times; don't know which occurrence to remove.]]"); prevent_autocommit } ret = 1;
} else {
if alert (cat_add != null && cat_add.length > 0 && matches[0].match.length > 1) cat_key = matches[0].match[1]; // Remember the category key, if any. var t1 = t.substring (0, matches[0].match.index); var t2 = t.substring (matches[0].match.index + matches[0].match[0].length); // Remove whitespace (properly): strip whitespace, but only up to the next line feed. // If we then have two linefeeds in a row, remove one. Otherwise, if we have two non- // whitespace characters, insert a blank. var i = t1.length - 1; while (i >= 0 && t1.charAt (i) != '"Impossible de trouver une occurrence unique de \n' && t1.substr (i, 1).search (/\s/) >= 0) i--; var j = 0; while (j < t2.length && t2.charAt (j) != '\n' && t1.substr (j, 1).search (/\s/) >= 0) j++; if (i >= 0 && t1.charAt (i) == '\n' && j < t2.length && t2.charAt (j) == '\n') i--; if (i >= 0) t1 = t1.substring (0, i+1); else t1 = ""; if (j < t2.length) t2 = t2.substring (j); else t2 = ""; if (t1.length > 0 && t1.substring (t1.length - 1).search (/\S/) >= 0 && t2.length > 0 && t2.substr (0, 1).search (/\S/) >= 0) t1 = t1 + ' '; t = t1 hrc + t2; summary.push ( "Removed category \[\[:Category:" + cat_rm + "|" + cat_rm + "\]\]- elle est peut-être incluse via un modèle" ) ; ret prevent_autocommit = 1;
}
}else { // Only adding? if (cat_add typeof hnc != null "undefined" && cat_add.length > 0) { var matches hnc != hotcat_find_category (t, cat_add); if (matches null && matches.length > 0hnc != "" ) { alert // Looking for last cat var re = /\[\[('?:Catégorie|Category "' ):[^\]]+ cat_add + '" already exists; not added.');\]\]/ig prevent_autocommit var index = -1; } else { if while (tre.charAt exec(t.length - 1) != '\n'null) t index = t + '\n're.lastIndex; t var txt = t + '\"[\[CategoryCatégorie:' " + cat_add hnc + (cat_key != null ? cat_key : "") + '\]\]\n'" ; summary.push if ("Quick-adding category \[\[:Category:" index < 0) { t = t + cat_add + "|" + cat_add + "'\]\]" n' + comment)txt ; var t2 } else { t = t.replacesubstring(hotcat_uncat_regex0, ""index); // Remove "uncat" templates if (t2.length != + '\n' + txt + t.length) { t = t2; summary.push substring( "removed {{uncategorized}}" index) ;
}
summary.push ( "Ajout rapide de la catégorie [[Catégorie:" + hnc + "]]" ) ; ret = 1;
}
}
  if (ret) {
document.editform.wpTextbox1.value = t ;
document.editform.wpSummary.value = summary.join( "; " ) + " (using avec [[MediaWiki:Gadget-HotCatHotCats.js|HotCat.jsHotCats]])" ;
document.editform.wpMinoredit.checked = true ;
if (!prevent_autocommit) { document.getElementById("bodyContent").style.display = "none" ; // Hide Hiding the entire edit section so as not to tempt the user into editing... var content = document.getElementById ("bodyContent") // "monobook" skin || document.getElementById ("mw_contentholder") // "modern" skin || documenteditform.getElementById ("article"); // classic skins if (content) content.style.display = "none" ; document.editformwpSave.submit click();
}
}
  // This is the end, my friend, the end... return ret;
}
var link = document.getElementById ( link_id ) ;
var span = link.parentNode ;
var catname = span.hotcat_namefirstChild.firstChild.data ;
while ( span.firstChild.nextSibling ) span.removeChild ( span.firstChild.nextSibling ) ;
hotcat_last_v = "" ;
hotcat_create_new_span ( span_add , "" ) ;
}
 
function hotcat_button_label (id, defaultText)
{
var label = null;
if (hotcat_upload
&& typeof (UFUI) != 'undefined'
&& typeof (UFUI.getLabel) == 'function') {
try {
label = UFUI.getLabel (id, true);
// Extract the plain text. IE doesn't know that Node.TEXT_NODE == 3
while (label && label.nodeType != 3) label = label.firstChild;
} catch (ex) {
label = null;
}
}
if (label == null || !label.data) return defaultText;
return label.data;
}
var form = document.createElement ( "form" ) ;
form.method = "post" ;
form.onsubmit = function () { hotcat_ok(); return false; } ;
form.id = "hotcat_form" ;
form.style.display = "inline" ;
var list = null; if (!hotcat_nosuggestions) { // Only do this if we may actually use XMLHttp... list = document.createElement ( "select" ) ; list.id = "hotcat_list" ; list.onclick = function () { var l = document.getElementById("hotcat_listhotcat_text"); if (l !.value = null) document.getElementById("hotcat_texthotcat_list").value = l.options[l.selectedIndex].text; hotcat_text_changed(); }; list.ondblclick = function (evt) { var l = document.getElementById("hotcat_listhotcat_text"); if (l !.value = null) document.getElementById("hotcat_texthotcat_list").value = l.options[l.selectedIndex].text; // Don't call text_changed here if on upload form: hotcat_ok will remove the list // anyway, so we must not ask for new suggestions since show_suggestions might // raise an exception if it tried to show a no longer existing list. // Lupo, 2008-01-20 if (!hotcat_upload) hotcat_text_changed(); hotcat_ok(hotcat_evtkeys (evt) & 1); // CTRL pressed? }; list.style.display = "none" ; }
var text = document.createElement ( "input" ) ;
var default_width = (typeof (JSconfig) != 'undefined' ? JSconfig.keys['HotCatEditBoxWidth'] : hotcat_editbox_width ); var default_delay = (typeof (JSconfig) != 'undefined' ? JSconfig.keys['HotCatDelay'] : hotcat_suggestion_delay ); if (default_delay < 0) default_delay = 0; text.size = (default_width < 40 ? 40 : default_width);
text.id = "hotcat_text" ;
text.type = "text" ;
text.value = init_text ;
text.onkeyup = function () { window.setTimeout ("hotcat_text_changed ();", default_delayhotcat_suggestion_delay ); };
var exists = null; if (!hotcat_nosuggestions) { exists = document.createElement ( "img" ) ; exists.id = "hotcat_exists" ; exists.src = hotcat_exists_no ; }
var OK = document.createElement ( "input" ) ;
OK.type = "button" ;
OK.value = hotcat_button_label ('wpOkUploadLbl', '"OK') " ; OK.onclick = function (evt) { hotcat_ok (hotcat_evtkeys (evt) & 1); };
var cancel = document.createElement ( "input" ) ;
cancel.type = "button" ;
cancel.value = hotcat_button_label ('wpCancelUploadLbl', 'Cancel') "Annuler" ;
cancel.onclick = hotcat_cancel ;
if (list != null) form.appendChild ( list ) ;
form.appendChild ( text ) ;
if (exists != null) form.appendChild ( exists ) ;
form.appendChild ( OK ) ;
form.appendChild ( cancel ) ;
}
function hotcat_ok (nocommit) {
var text = document.getElementById ( "hotcat_text" ) ;
var v = text.value || ""; v = v.replace(/_/g, ' ').replace(/^\s\s*/, '').replace(/\s\s*$/, ''); // Trim leading and trailing blanks
// Empty category ?
if (!v== "" ) {
hotcat_cancel() ;
return ;
}
// Get the links and the categories of the chosen category page var url = wgServer + wgScriptPath + '/api.php?action=query&titles=' + encodeURIComponent ('Category:' + v) + '&prop=info|links|categories&plnamespace=14&format=json'; var request = sajax_init_object() ; if (request == null) { //Oops! We don't have XMLHttp... hotcat_nosuggestions = true; hotcat_closeform (nocommit); hotcat_running = 0; return; } request.open ('GET', url, true); request.onreadystatechange = function () { if (request.readyState != 4) return; if (request.status != 200) { hotcat_closeform (nocommit); } else { var do_submit = hotcat_json_resolve (eval ('(' + request.responseText + ')')); if (do_submit) { var txt editlk = document.getElementById ('hotcat_text'); hotcat_closeform ( nocommit ,(txt && txt.value != v) ? " (redirect \[\[:Category:" + v + "|" + v + "\]\] resolved)" : null ); } } }; request.setRequestHeader ('Pragma', 'cache=yes'); request.setRequestHeader ('Cacheca-Control', 'no-transform'); request.send (null);} function hotcat_json_resolve (params){ function resolve (page) { var cats = page.categories; var is_dab = false; var is_redir = typeof (page.redirect) == 'string'; // Hard redirect? if (!is_redir && cats) { for (var c = 0; c < cats.length; c++) { var cat = cats[c]["title"]; if (cat) cat = cat.substring (cat.indexOf (':') + 1); // Strip namespace prefix if (cat == 'Disambiguation') { is_dab = true; break; } else if (cat == 'Category_redirects' || cat == edit'Category redirects') { is_redir = true; break; } } } if (!is_redir && !is_dab) return true; var lks = page.links; var titles = new Array (); for (i = 0; i < lks.length; i++) { if ( lks[i]["ns"] == 14 // Category namespace && lks[i]["title"] && lks[i]["title"].length > 0) { // Name not empty // Internal link to existing thingy. Extract the page name. var match = lks[i]["title"]; // Remove the category prefix match = match.substring (match.indexOf getElementsByTagName(':a') + 1); titles.push (match); if (is_redir) break; } } if (titles.length > 1) { // Disambiguation page hotcat_show_suggestions (titles); return false; } else if (titles.length == 1) { var text = document.getElementById ("hotcat_text"); if (text) text.value = titles[0]; } return true; } // end local function resolve  // We should have at most one page here for (var page in params.query.pages) return resolve (params.query.pages[page]); return true; // In case we have none.} function hotcat_closeform (nocommit, comment){ var text = document.getElementById ( "hotcat_text" ) ; var v = text.value || ""; v = v.replace(/_/g, ' ').replace(/^\s\s*/, '').replace(/\s\s*$/, ''); // Trim leading and trailing blanks if (!v // Empty || wgNamespaceNumber == 14 && v == wgTitle // Self-reference || text.parentNode.parentNode.id != 'hotcat_add' // Modifying, but && text.parentNode.parentNode.hotcat_name == v) // name unchanged { hotcat_cancel (); return; } if (hotcat_upload) { hotcat_just_add (v) ; // Close the form return ; } var editlk = wgServer + wgScript + '?title=' + encodeURIComponent (wgPageName) + '&action=edit'href;
var url = editlk + '&hotcat_newcat=' + encodeURIComponent( v ) ;
// Editing existing?
var span = text.parentNode.parentNode ; // span.form.text
if ( span.id != "hotcat_add" ) { // Not plain "addition" var cat_title = span.firstChild.innerHTML ; // Removing leading Category: cat_title = cat_title.substr(cat_title.indexOf(":") + 1); url += '&hotcat_removecat=' + encodeURIComponent (span.hotcat_namecat_title );
}
if (nocommit) url = url + '&hotcat_nocommit=1'; if (comment) url = url + '&hotcat_comment=' + encodeURIComponent (comment); // Make the list disappear: var list = document.getElementById ( "hotcat_list" ) ; if (list) list.style.display = 'none';
document.location = url ;
}
 
function hotcat_just_add ( text ) {
var span = document.getElementById("hotcat_form") ;
while ( span.tagName != "SPAN" ) span = span.parentNode ;
var add = 0 ;
if ( span.id == "hotcat_add" ) add = 1 ;
span.id = "" ;
while ( span.firstChild ) span.removeChild ( span.firstChild ) ;
var na = document.createElement ( "a" ) ;
na.href = wgArticlePath.split("$1").join("Category:" + encodeURI (text)) ;
na.appendChild ( document.createTextNode ( text ) ) ;
na.setAttribute ( "title" , "Category:" + text ) ;
span.appendChild ( na ) ;
var catline = getElementsByClassName ( document , "p" , "catlinks" ) [0] ;
if ( add ) hotcat_append_add_span ( catline ) ;
 
for ( var i = 0 ; i < span.parentNode.childNodes.length ; i++ ) {
if ( span.parentNode.childNodes[i] != span ) continue ;
hotcat_modify_span ( span , i ) ;
break ;
}
}
while ( span.firstChild.nextSibling ) span.removeChild ( span.firstChild.nextSibling ) ;
span.firstChild.style.display = "" ;
for ( var i = 0 ; i < span.parentNode.childNodes.length ; i++ ) { if ( span.parentNode.childNodes[i] != span ) continue ; hotcat_modify_span ( span , i ) ; break ; }
}
}
if ( hotcat_last_v == v ) return ; // Nothing's changed...
if (hotcat_nosuggestions) {
// On IE, XMLHttp uses ActiveX, and the user may deny execution... just make sure
// the list is not displayed.
var list = document.getElementById ('hotcat_list');
if (list != null) list.style.display = "none" ;
var exists = document.getElementById ('hotcat_exists');
if (exists != null) exists.style.display = "none" ;
return;
}
hotcat_running = 1 ;
hotcat_last_v = v ;
if ( v != "" ) {
var url = wgServer + "/" + wgScriptPath + "/api.php?format=xml&action=query&list=allpages&apnamespace=14&apfrom=" + encodeURIComponent( v ) ; var request + "&aplimit= sajax_init_object" + encodeURIComponent(hotcat_list_items ) ; if (request == null) { //Oops! We don't have XMLHttp... hotcat_nosuggestions = true; var list = document.getElementById typeof ('hotcat_list'hotcat_xmlhttp ); if (list != null) list.style.display = "noneundefined" ; var exists = document) hotcat_xmlhttp.getElementById abort('hotcat_exists'); if (exists != null) exists// Just to make sure..style.display = "none" ; hotcat_running hotcat_xmlhttp = 0; returnnew sajax_init_object() ; } requesthotcat_xmlhttp.open('GET', url, true); requesthotcat_xmlhttp.onreadystatechange = function () { if ( typeof hotcat_xmlhttp == "undefined" ) return ; if (requesthotcat_xmlhttp.readyState == 4) { var xml = requesthotcat_xmlhttp.responseXML ; if ( xml == null ) return ; var pages = xml.getElementsByTagName( "p" ) ; // results are *with* namespace here var titles = new Array () ; for ( var i = 0 ; i < pages.length ; i++ ) { // Remove the namespace. No hardcoding of 'Category:', please, other Wikis may have // local names ("Kategorie:" on de-WP, for instance). Also don't break on category // names containing a colon var s = pages[i].getAttribute("title"); // Removing leading "Category:" s = s.substring substr(s.indexOf ('":'") + 1); if ( s.substr ( 0 , hotcat_last_v.length ) != hotcat_last_v ) break ; titles.push ( s ) ; } hotcat_show_suggestions ( titles ) ;
}
hotcat_show_suggestions ( titles ) ;
}
};
request.setRequestHeader ('Pragma', 'cache=yes'); request.setRequestHeader ('Cache-Control', 'no-transform'); requesthotcat_xmlhttp.send(null);
} else {
hotcat_show_suggestions ( var titles = new Array () ; hotcat_show_suggestions ( titles ) ;
}
hotcat_running = 0 ;
var list = document.getElementById ( "hotcat_list" ) ;
var icon = document.getElementById ( "hotcat_exists" ) ;
// Somehow, after a double click on the selection list, we still get here in IE, but
// the list may no longer exist... Lupo, 2008-01-20
if (list == null) return;
if (hotcat_nosuggestions) {
list.style.display = "none" ;
if (icon != null) icon.style.display = "none";
return;
}
if ( titles.length == 0 ) {
list.style.display = "none" ;
}
// Set list size to minimum of 5 and actual number of var listh = hotcat_list_size * 20 ; if (titles. Formerly was just 5length < hotcat_list_size) { listh = titles.length * 20 ; } // Lupo, 2008var nl = parseInt ( text.parentNode.offsetLeft ) -01-201 ; list.size var nt = parseInt(titles.length > 5 ? 5 : titlestext.lengthoffsetTop) - listh ; // Avoid Parameter to show suggestion list height 1: double-click doesn't work in FF. Lupo, 2008-02-27beneath categories instead of above if (list.size typeof hotcat_list_down !="undefined" && hotcat_list_down) { nt = 1) text.offsetTop + text.offsetHeight; } list.size = 25 ;
list.style.align = "left" ;
list.style.zIndex = 5 ;
list.style.position = "absolute" ;
 
// Was listh = titles.length * 20: that makes no sense if titles.length > list.size
// Lupo, 2008-01-20
var listh = list.size * 20;
var nl = parseInt (text.offsetLeft) - 1 ;
var nt = parseInt (text.offsetTop) - listh ;
if (skin == 'nostalgia' || skin == 'cologneblue' || skin == 'standard') {
// These three skins have the category line at the top of the page. Make the suggestions
// appear *below* out input field.
nt = parseInt (text.offsetTop) + parseInt (text.offsetHeight) + 3;
}
list.style.top = nt + "px" ;
list.style.width = text.offsetWidth + "px"; // No fixed width (yet)
list.style.height = listh + "px" ;
list.style.left = nl + "px" ;
var ot = document.createTextNode ( titles[i] ) ;
opt.appendChild ( ot ) ;
//opt.setAttribute( "value = ", titles[i] );
list.appendChild ( opt ) ;
}
list.style.display = "block" ;
 
icon.src = hotcat_exists_yes ;
var nof_titles = titles.length;
var first_title = titles.shift () ;
var v = text.value.ucFirst() ; text.focus (); if ( first_title == v ) { if (nof_titles == 1hotcat_last_v ) { // Only one result, and it's the same as whatever is in the input box: makes no sense // to show the list. list.style.display = 'none'; } return ; }  if (list.offsetWidth < text.offsetWidth) list.style.width = text.offsetWidth + "px"; else {  function position (node) { var t = 0, l = 0; do { t = t + (node.offsetTop || 0); l = l + (node.offsetLeft || 0); node = node.offsetParent; } while (node); return {x : l, y : t}; }  function scroll_offset (what) { var s = 'scroll' + what; return (document.documentElement ? document.documentElement[s] : 0) || document.body[s] || 0; }  function viewport (what) { if (typeof (is_safari) != 'undefined' && is_safari && !document.evaluate) return window['inner' + what]; var s = 'client' + what; if (typeof (is_opera) != 'undefined' && is_opera) return document.body[s]; return (document.documentElement ? document.documentElement[s] : 0) || document.body[s] || 0; }
var scroll = scroll_offset ('Left'); var view_w = viewport ('Width'); var l_pos = position (list); var w = list.offsetWidth; if (l_pos.x + w > scroll + view_w) { if (w > view_w) w = view_w; list.style.width = w + "px"; list.style.left = nl - (l_pos.x + w - scroll - view_w) + "px"; } }  list.style.display suggestion = "block" first_title;
// Put the first entry of the title list into the text field, and select the // new suffix such that it'll be overwritten if the user keeps typing. // ONLY do this if we have a way to select parts of the content of a text // field, otherwise, this is very annoying for the user. Note: IE does it // again differently from the two versions previously implemented. // Lupo, 2008-01-20 // Only put first entry into the list if the user hasn't typed something // conflicting yet Dschwen 2008-02-18value = suggestion ; if ( ( text.setSelectionRange || text.createTextRange || typeof (text.selectionStart) != 'undefined' && typeof (text.selectionEnd) != 'undefined' ) && v == first_title.substr(0,v.length) ) { // taking hotcat_last_v was a major annoyance, // since it constantly killed text that was typed in // _since_ the last AJAX request was fired! Dschwen 2008-02-18IE var nosel ra = v.length ; text.value = first_title ; if createTextRange(text.setSelectionRange) // e.g. khtml text.setSelectionRange (nosel, first_title.length); else if (textra.createTextRange) { // IE var new_selection = text.createTextRange(); new_selection.move moveStart("character", noselhotcat_last_v.length); new_selection ra.moveEnd ("character", first_titlesuggestion.length - nosel); new_selection ra.select(); } else { text.selectionStart = nosel; text.selectionEnd = first_title.length; } }} function hotcat_get_state (){ var cats = document.getElementById ('catlinks'); if (cats == null) return ""; var result = null; cats = cats.getElementsByTagName ('span') ; for (var i = 0; i < cats.length; i++ is_khtml ) { var text = cats[i].hotcat_name; if setSelectionRange(text) { if (result == null) result = text; else result = result + '\n' + text; } } return result;} function hotcat_set_state (state){ var cats = state.split ('\n'); if (catshotcat_last_v.length == 0) return null; var parent = document.getElementById ('catlinks'); if (parent == null) return state; // HotCat uses a 'p' element inside the 'div' to wrap its spans... parent = parent.firstChild; if (parent == null || parent.className != 'catlinks') return state; var n = (parent.childNodes ? parent.childNodes, suggestion.length - 1 : 0); if (n < 0) n = 0;} else { var before = parent text.lastChild; for (var i selectionStart = 0; i < catshotcat_last_v.length; i++) { if (cats[i]text.length > 0) { var lk selectionEnd = documentsuggestion.createElement ('a')length ; lk.href = wgArticlePath.split ('$1').join ('Category:' + encodeURI (cats[i])); lk.appendChild (document.createTextNode (cats[i])); lk.setAttribute ('title', cats[i]); var span = document.createElement ('span'); span.appendChild (lk); parent.insertBefore (span, before); if (before != null) parent.insertBefore (document.createTextNode (' | '), before); hotcat_modify_span (span, n++); }
}
return null;
}
 addOnloadHook ( hotcat ) ; } // end if (guard)//</sourcenowiki>
6 447
modifications

Menu de navigation