|
|
| Zeile 1: |
Zeile 1: |
| /* Script: [[User:TheDJ/Gadget-HotCat.js]] | | // <nowiki> |
| * HotCat: Adds an easy way to add, modify and remove categories
| | // Einfaches Hinzufügen und Entfernen von Kategorien in Artikeln. |
| * Documentation: [[User:TheDJ/HotCat]]
| | // Von http://commons.wikimedia.org/wiki/MediaWiki:HotCat.js und |
| * Originally written by: Magnus Manske
| | // http://fr.wikipedia.org/wiki/MediaWiki:JSScripts/HotCats übernommen |
| *
| | // Version: 28. 11. 2007 |
| * This version was forked from http://commons.wikimedia.org/w/index.php?title=MediaWiki:Gadget-HotCat.js&oldid=10204404
| | |
| * In sync with version: http://commons.wikimedia.org/w/index.php?title=MediaWiki:Gadget-HotCat.js&oldid=19600669
| | // Konfigurationsvariablen: |
| * Major changes:
| | // Zeit bis die Auswahlliste erscheint |
| * - all code for the uploadForm has been removed
| | var hotcat_suggestion_delay = 200; |
| * - autocommit is disabled
| | // Anzahl der Zeilen in der Auswahlliste |
| * - will be enabled on pages without categories so that you can easily add them
| | var hotcat_list_size = 10; |
| * - uses javascript:void() as a dummy value for href in order to avoid a conflict with popups.
| | // Anzahl der Elemente in der Auswahlliste |
| * - checks for {{Uncategorized}} and removes it if a category is added
| | var hotcat_list_items = 50; |
| * - does not use JSconfig for configuration options like its Commons original
| | // Wenn true: Automatisches Speichern der Änderung ohne Bearbeitungsfenster |
| * - tries to detect other categories and if possible, add to the end of them.
| | // var hotcat_autocommit = false; |
| * - fixes a bug in the suggestion list with titles containing : character
| | // Wenn true: Auswahlliste nach unten statt nach oben ausklappen |
| * - Uses opensearch API to look for categories. Allows for case insensitive search.
| | // var hotcat_list_down = false; |
| * - Postfix blacklisting in addition to prefix blacklisting.
| | |
| * [[User:TheDJ]] 2009-04-18
| | // interne Variablen |
| <source lang="javascript"><nowiki> */
| |
| var hotcat_running = 0 ; | | var hotcat_running = 0 ; |
| var hotcat_last_v = "" ; | | 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_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_exists_no = "http://upload.wikimedia.org/wikipedia/commons/thumb/4/42/P_no.svg/20px-P_no.svg.png" ; |
|
| |
| var hotcat_no_autocommit = 0;
| |
| // In Commons hotcat_suggestion_delay is configurable trough JSconfig
| |
| var hotcat_suggestion_delay = 100;
| |
|
| |
| 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-20
| |
|
| |
| var hotcat_modify_blacklist = new Array (
| |
| " stubs"
| |
| ) ;
| |
|
| |
| var hotcat_cnames=["[Cc]ategory"]; // namespaces and alias of category
| |
| // in chinese: categoryNames=["[Cc]ategory","分类","分類"];
| |
|
| |
|
| addOnloadHook ( hotcat ) ; | | addOnloadHook ( hotcat ) ; |
| Zeile 47: |
Zeile 28: |
| if ( hotcat_check_action() ) return ; // Edited page, reloading anyway | | if ( hotcat_check_action() ) return ; // Edited page, reloading anyway |
|
| |
|
| // Do not add interface to protected pages, if user has no edit permission | | var catlinks = document.getElementById("catlinks"); |
| // Also disable it on preview pages: on a preview, we *are* already editing,
| |
| // and HotCat must not open the page for editing a second time. Lupo, 2008-02-27
| |
| if( wgAction != "view" || document.getElementById('ca-viewsource' ) != null ||
| |
| wgNamespaceNumber == -1 || wgNamespaceNumber == 10 )
| |
| return;
| |
|
| |
|
| // If we have no Categories div, then add one | | if (!catlinks && wgNamespaceNumber % 2 == 0) { // all except discussion |
| // TheDJ, 2008-02-28
| | // let's create a fake one |
|
| | var bodyC = document.getElementById("bodyContent"); |
| var visible_catlinks = document.getElementById ('mw-normal-catlinks') || getElementsByClassName ( document , "p" , "catlinks" ) [0];
| | if (!bodyC) bodyC = document.getElementById("mw_contentholder"); |
| var hidden_catlinks = document.getElementById ('mw-hidden-catlinks');
| | catlinks = document.createElement("div"); |
| | | catlinks.id = "catlinks"; |
| if ( visible_catlinks == null || typeof( visible_catlinks ) == 'undefined' ) {
| | catlinks.appendChild(document.createElement("p")); |
| d3 = document.createElement ( "div" );
| | catlinks.firstChild.className = "catlinks"; |
| d3.id = "mw-normal-catlinks";
| | bodyC.appendChild(catlinks); |
| d3.innerHTML = '<a href="/wiki/Special:Categories" title="Special:Categories">Categories</a>: ';
| | } |
| visible_catlinks = d3;
| |
| | |
| if ( hidden_catlinks ) {
| |
| // There are hidden categories.
| |
| hidden_catlinks.parentNode.insertBefore( d3, hidden_catlinks );
| |
| hidden_catlinks.parentNode.className = "catlinks";
| |
| } else {
| |
| // This page has no categories at all, lets create a section where we can add them.
| |
| var footer = getElementsByClassName ( document , "div" , "printfooter" ) [0];
| |
| if( !footer ) return; // We have no idea where we should add this.
| |
|
| |
|
| d1 = document.createElement ( "div" );
| | var catline = |
| d1.id = "catlinks";
| | document.getElementById ('mw-normal-catlinks') || |
| d1.className = "catlinks";
| | getElementsByClassName ( document , "p" , "catlinks" ) [0]; |
| d1.appendChild ( d3 );
| | if ( catline == null || typeof catline == 'undefined' ) return ; |
| footer.parentNode.insertBefore( d1, footer.nextSibling );
| |
| }
| |
| }
| |
|
| |
|
| hotcat_modify_existing ( visible_catlinks ) ; | | hotcat_modify_existing ( catline ) ; |
| hotcat_append_add_span ( visible_catlinks ) ; | | hotcat_append_add_span ( catline ) ; |
| } | | } |
|
| |
|
| Zeile 90: |
Zeile 53: |
| var span_add = document.createElement ( "span" ) ; | | var span_add = document.createElement ( "span" ) ; |
| var span_sep = document.createTextNode ( " | " ) ; | | var span_sep = document.createTextNode ( " | " ) ; |
| if ( catline.getElementsByTagName("span")[0] ) catline.appendChild ( span_sep ) ; | | if ( catline.firstChild ) catline.appendChild ( span_sep ) ; |
| catline.appendChild ( span_add ) ; | | catline.appendChild ( span_add ) ; |
| hotcat_create_span ( span_add ) ; | | hotcat_create_span ( span_add ) ; |
| Zeile 97: |
Zeile 60: |
| String.prototype.ucFirst = function () { | | String.prototype.ucFirst = function () { |
| return this.substr(0,1).toUpperCase() + this.substr(1,this.length); | | return this.substr(0,1).toUpperCase() + this.substr(1,this.length); |
| }
| |
|
| |
| function hotcat_is_on_blacklist ( cat_title ) {
| |
| if ( !cat_title ) return 0 ;
| |
| for ( var i = 0 ; i < hotcat_modify_blacklist.length ; i++ ) {
| |
| /* prefix */
| |
| if ( cat_title.substr ( 0 , hotcat_modify_blacklist[i].length )
| |
| == hotcat_modify_blacklist[i] ) return 1 ;
| |
| /* postfix */
| |
| var postfix_len = cat_title.length - hotcat_modify_blacklist[i].length;
| |
| if ( postfix_len >= 0 && cat_title.substr ( postfix_len, hotcat_modify_blacklist[i].length )
| |
| == hotcat_modify_blacklist[i] ) return 1 ;
| |
| }
| |
| return 0 ;
| |
| } | | } |
|
| |
|
| function hotcat_modify_span ( span , i ) { | | function hotcat_modify_span ( span , i ) { |
| //var cat_title = span.firstChild.getAttribute ( "title" ) ; | | var cat_title = span.firstChild.getAttribute ( "title" ) ; |
| // This fails with MW 1.13alpha if the category is a redlink, because MW 1.13alpha appends | | // Removing leading Category: |
| // [[MediaWiki:Red-link-title]] to the category name... it also fails if the category name
| | cat_title = cat_title.substr(cat_title.indexOf(":") + 1); |
| // contains "&" (because that is represented by & in the XHTML both in the title and in
| |
| // the link's content (innerHTML). Extract the category name from the href instead:
| |
| var cat_title = null;
| |
| var classes = span.firstChild.getAttribute ('class');
| |
| if (classes && classes.search (/\bnew\b/) >= 0) { // href="/w/index.php?title=...&action=edit"
| |
| cat_title = hotcatGetParamValue ('title', span.firstChild.href);
| |
| } else { // href="/wiki/..."
| |
| var re = new RegExp (wgArticlePath.replace (/\$1/, '(.*)'));
| |
| var matches = re.exec (span.firstChild.href);
| |
| if (matches && matches.length > 1)
| |
| cat_title = decodeURIComponent (matches[1]);
| |
| else
| |
| return;
| |
| }
| |
| // Strip namespace, replace _ by blank
| |
| cat_title = cat_title.substring (cat_title.indexOf (':') + 1).replace (/_/g, ' '); | |
| | |
| var sep1 = document.createTextNode ( " " ) ; | | var sep1 = document.createTextNode ( " " ) ; |
| var a1 = document.createTextNode ( "(-)" ) ; | | var a1 = document.createTextNode ( "(−)" ) ; |
| var remove_link = document.createElement ( "a" ) ; | | 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
| | remove_link.href = "javascript:hotcat_remove(\"" + cat_title + "\");" ; |
| // is bypassed.
| |
| remove_link.className = "noprint"; | |
| remove_link.href = "#catlinks";
| |
| remove_link.onclick = hotcat_remove;
| |
| remove_link.appendChild ( a1 ) ; | | remove_link.appendChild ( a1 ) ; |
| span.appendChild ( sep1 ) ; | | span.appendChild ( sep1 ) ; |
| span.appendChild ( remove_link ) ; | | span.appendChild ( remove_link ) ; |
|
| |
|
| if ( hotcat_is_on_blacklist ( cat_title ) ) return ;
| |
| var mod_id = "hotcat_modify_" + i ; | | var mod_id = "hotcat_modify_" + i ; |
| var sep2 = document.createTextNode ( " " ) ; | | var sep2 = document.createTextNode ( " " ) ; |
| Zeile 152: |
Zeile 79: |
| var modify_link = document.createElement ( "a" ) ; | | var modify_link = document.createElement ( "a" ) ; |
| modify_link.id = mod_id ; | | modify_link.id = mod_id ; |
| modify_link.className = "noprint";
| |
| modify_link.href = "javascript:hotcat_modify(\"" + mod_id + "\");" ; | | modify_link.href = "javascript:hotcat_modify(\"" + mod_id + "\");" ; |
| modify_link.appendChild ( a2 ) ; | | modify_link.appendChild ( a2 ) ; |
| span.appendChild ( sep2 ) ; | | span.appendChild ( sep2 ) ; |
| span.appendChild ( modify_link ) ; | | span.appendChild ( modify_link ) ; |
| span.hotcat_name = cat_title; //Store the extracted category name in our own new property of the span DOM node
| |
| } | | } |
|
| |
|
| Zeile 167: |
Zeile 92: |
| } | | } |
|
| |
|
| function hotcat_getEvt (evt) { | | function hotcat_remove ( cat_title ) { |
| return evt || window.event || window.Event; // Gecko, IE, Netscape | | var editlk = document.getElementById('ca-edit').getElementsByTagName('a')[0].href; |
| }
| | if (window.confirm("Soll die Kategorie '" + cat_title + "' wirklich entfernt werden?")) { |
|
| | document.location = editlk + '&hotcat_removecat=' + encodeURIComponent(cat_title) ; |
| 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;
| |
| if (e.altKey) code |= 4;
| |
| } else if (typeof (e.modifiers) != 'undefined') { // Netscape...
| |
| if (e.modifiers & Event.CONTROL_MASK) code |= 1;
| |
| if (e.modifiers & Event.SHIFT_MASK) code |= 2;
| |
| if (e.modifiers & Event.ALT_MASK) code |= 4;
| |
| }
| |
| } catch (ex) {
| |
| }
| |
| return code;
| |
| }
| |
|
| |
| function hotcat_killEvt (evt)
| |
| {
| |
| try {
| |
| var e = hotcat_getEvt (evt);
| |
| if (typeof (e.preventDefault) != 'undefined') {
| |
| e.preventDefault();
| |
| e.stopPropagation()
| |
| } else
| |
| e.cancelBubble = true;
| |
| } catch (ex) {
| |
| }
| |
| }
| |
|
| |
| function hotcat_remove (evt) {
| |
| var node = hotcat_evt2node (evt);
| |
| if (!node) return false;
| |
| // Get the category name from the original link to the category
| |
| var cat_title = node.parentNode.hotcat_name;
| |
|
| |
| var editlk = wgServer + wgScript + '?title=' + encodeURIComponent (wgPageName) + '&action=edit';
| |
| if ((hotcat_evtkeys (evt) & 1) || (hotcat_evtkeys (evt) & 4 )) // CTRL or ALT pressed?
| |
| editlk = editlk + '&hotcat_nocommit=1';
| |
| hotcat_killEvt (evt);
| |
| document.location = editlk + '&hotcat_removecat=' + encodeURIComponent(cat_title) ;
| |
| return false;
| |
| } | | } |
|
| |
|
| function hotcatGetParamValue(paramName, h) { | | function hotcatGetParamValue(paramName, h) { |
| if (typeof h == 'undefined' ) { h = document.location.href; }
| | if (typeof h == 'undefined' ) { h = document.location.href; } |
| var cmdRe=RegExp('[&?]'+paramName+'=([^&]*)');
| | var cmdRe=RegExp('[&?]'+paramName+'=([^&]*)'); |
| var m=cmdRe.exec(h);
| | var m=cmdRe.exec(h); |
| if (m) {
| | if (m) { |
| try {
| | try { |
| return decodeURIComponent(m[1]);
| | return decodeURIComponent(m[1]); |
| } catch (someError) {}
| | } catch (someError) {} |
| }
| | } |
| return null;
| | return null; |
| } | | } |
|
| |
|
| // New. Code by Lupo & Superm401, added by Lupo, 2008-02-2007
| |
| function hotcat_find_category (wikitext, Kategorie)
| |
| {
| |
| var cat_name = Kategorie.replace(/([\\\^\$\.\?\*\+\(\)])/g, "\\$1");
| |
| var initial = cat_name.substr (0, 1);
| |
| var cat_regex = new RegExp ("\\[\\[\\s*(?:" + hotcat_cnames.join("|") + ")\\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
| |
| }
| |
|
| |
| // New. Code by TheDJ, 2008-03-12
| |
| function hotcat_find_ins ( wikitext )
| |
| {
| |
| var re = new RegExp("\\[\\[\\s*(?:" + hotcat_cnames.join("|") + ")\\s*:\[^\\]\]+\\]\\]", "ig" );
| |
| var index = -1;
| |
| while( re.exec(wikitext) != null ) index = re.lastIndex;
| |
|
| |
| if( index > -1) return index;
| |
| //we should try to find interwiki links here, but that's for later.
| |
|
| |
| return -1;
| |
| }
| |
|
| |
| // Rewritten (nearly) from scratch. Lupo, 2008-02-27
| |
| function hotcat_check_action () { | | function hotcat_check_action () { |
| var ret = 0; | | var ret = 0 ; |
| if (wgAction != 'edit' || typeof(document.editform) == "undefined" ) return ret; // Not an edit page, so not our business... | | if ( wgAction != "edit" ) return ret ; // Not an edit page, so no business... |
| var summary = new Array () ; | | var summary = new Array () ; |
| var t = document.editform.wpTextbox1.value ; | | var t = document.editform.wpTextbox1.value ; |
| var prevent_autocommit = 0; | | var prevent_autocommit = 1 ; |
| if ( (typeof (hotcat_no_autocommit) != "undefined" && hotcat_no_autocommit) | | if ( typeof hotcat_autocommit != 'undefined' && hotcat_autocommit ) prevent_autocommit = 0 ; |
| || hotcatGetParamValue ('hotcat_nocommit') == '1')
| |
| prevent_autocommit = 1;
| |
|
| |
|
| var cat_rm = hotcatGetParamValue ('hotcat_removecat'); | | // Remove existing category? |
| var cat_add = hotcatGetParamValue ('hotcat_newcat'); | | var hrc = hotcatGetParamValue('hotcat_removecat') ; |
| var comment = hotcatGetParamValue ('hotcat_comment') || ""; | | // Add new category? |
| var cat_key = hotcatGetParamValue ('hotcat_sortkey'); | | var hnc = hotcatGetParamValue('hotcat_newcat') ; |
| if (cat_key != null) cat_key = '|' + cat_key;
| |
|
| |
|
| if (cat_rm != null && cat_rm.length > 0) { | | if ( typeof hrc != "undefined" && hrc != null && hrc != "" ) { |
| var matches = hotcat_find_category (t, cat_rm); | | var hcre = new RegExp("(\\s*)\\[\\[ *(?:Kategorie|Category) *: *" + hrc.replace(/([\\\^\$\*\+\?\.\|\{\}\[\]\(\)])/g, "\\$1") + " *(\\|[^\\]]*)?\\]\\]", "gi"); |
| if (!matches || matches.length == 0) { | | var matches = t.match(hcre); |
| alert ('Kategorie "' + cat_rm + '" not found; maybe it is in a template?'); | | if (matches != null && matches.length == 1) { // Found one occurrence of the category - good! |
| prevent_autocommit = 1; | | if ( typeof hnc != "undefined" && hnc != null && hnc != "" ) { |
| } else if (matches.length > 1) {
| | t = t.replace(hcre, "$1[[Kategorie:" + hnc + "$2]]"); |
| alert ('Kategorie "' + cat_rm
| | summary.push ( "[[Kategorie:" + hrc + "]] nach [[Kategorie:" + hnc + "]] geändert" ) ; |
| + "\" found several times; don't know which occurrence to remove.");
| | } else { |
| prevent_autocommit = 1; | | t = t.replace(hcre, ""); |
| | summary.push ( "[[Kategorie:" + hrc + "]] entfernt" ) ; |
| | } |
| | ret = 1 ; |
| } else { | | } else { |
| if (cat_add != null && cat_add.length > 0 && matches[0].match.length > 1) | | alert ( "Kategorie \"" + hrc + "\" wurde im Text nicht gefunden. Sie wird wahrscheinlich über eine Vorlage eingebunden." ) ; |
| cat_key = matches[0].match[1]; // Remember the category key, if any.
| | prevent_autocommit = 1 ; |
| 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) != '\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 + t2;
| |
| summary.push ( "[[Kategorie:" + hrc + "]] entfernt" ) ;
| |
| ret = 1; | |
| } | | } |
| } | | } else { |
| if (cat_add != null && cat_add.length > 0) {
| | // Only adding? |
| var matches = hotcat_find_category (t, cat_add);
| | if ( typeof hnc != "undefined" && hnc != null && hnc != "" ) { |
| if (matches && matches.length > 0) {
| | // Looking for last cat |
| alert ('Kategorie "' + cat_add + '" already exists; not added.'); | | var re = /\[\[(?:Kategorie|Category):[^\]]+\]\]/ig ; |
| prevent_autocommit = 1; | | var index = -1; |
| } else {
| | while (re.exec(t) != null) index = re.lastIndex; |
| var insertionpoint = hotcat_find_ins( t ); | | var txt = "[[Kategorie:" + hnc + "]]" ; |
| var newcatstring = '\n\[\[Kategorie:' + cat_add + (cat_key != null ? cat_key : "") + '\]\]'; | | if (index < 0) { |
| if( insertionpoint > -1 ) { | | t = t + '\n' + txt ; |
| t = t.substring(0, insertionpoint ) + newcatstring + t.substring( insertionpoint ); | |
| } else { | | } else { |
| t = t + newcatstring; | | t = t.substring(0, index) + '\n' + txt + t.substring(index); |
| } | | } |
| summary.push ( "[[Kategorie:" + hnc + "]] hinzugefügt" ) ; | | summary.push ( "[[Kategorie:" + hnc + "]] hinzugefügt" ) ; |
| var t2 = t.replace(/\{\{\s*([Uu]ncat(egori[sz]ed)?|[Nn]ocat|[Nn]eedscategory|[Cc]ategori[sz]e)[^}]*\}\}/g, ""); // Remove "uncategorized" template
| | ret = 1 ; |
| if (t2.length != t.length) {
| |
| t = t2;
| |
| summary.push ( "removed {{uncategorized}}" ) ;
| |
| }
| |
| ret = 1; | |
| } | | } |
| } | | } |
| if (ret) { | | |
| | if ( ret ) { |
| document.editform.wpTextbox1.value = t ; | | document.editform.wpTextbox1.value = t ; |
| document.editform.wpSummary.value = summary.join( "; " ) | | document.editform.wpSummary.value = summary.join( " ; " ) + " (mit [[Hilfe:Erweiterungen#HotCat|HotCat]])" ; |
| + " (mit HotCat)" ;
| |
| document.editform.wpMinoredit.checked = true ; | | document.editform.wpMinoredit.checked = true ; |
| if (!prevent_autocommit) { | | if ( !prevent_autocommit ) { |
| // Hide the entire edit section so as not to tempt the user into editing... | | document.getElementById("bodyContent").style.display = "none" ; // Hiding the entire edit section so as not to tempt the user into editing... |
| var bodyContentId = document.getElementById("bodyContent") //monobook skin | | document.editform.wpSave.click(); |
| || document.getElementById("mw_contentholder") // modern skin
| |
| || document.getElementById ("article"); // classic skin
| |
| bodyContentId.style.display = "none";
| |
| document.editform.submit();
| |
| } | | } |
| } | | } |
| return ret; | | |
| | // This is the end, my friend, the end... |
| | return ret ; |
| } | | } |
|
| |
|
| Zeile 371: |
Zeile 181: |
| var a_text = document.createTextNode ( "(+)" ) ; | | var a_text = document.createTextNode ( "(+)" ) ; |
| span_add.id = "hotcat_add" ; | | span_add.id = "hotcat_add" ; |
| a_add.className = "noprint";
| |
| a_add.href = "javascript:hotcat_add_new()" ; | | a_add.href = "javascript:hotcat_add_new()" ; |
| a_add.appendChild ( a_text ) ; | | a_add.appendChild ( a_text ) ; |
| Zeile 380: |
Zeile 189: |
| var link = document.getElementById ( link_id ) ; | | var link = document.getElementById ( link_id ) ; |
| var span = link.parentNode ; | | var span = link.parentNode ; |
| var catname = span.hotcat_name; | | var catname = span.firstChild.firstChild.data ; |
| | | |
| while ( span.firstChild.nextSibling ) span.removeChild ( span.firstChild.nextSibling ) ; | | while ( span.firstChild.nextSibling ) span.removeChild ( span.firstChild.nextSibling ) ; |
| span.firstChild.style.display = "none" ; | | span.firstChild.style.display = "none" ; |
| Zeile 399: |
Zeile 208: |
| var form = document.createElement ( "form" ) ; | | var form = document.createElement ( "form" ) ; |
| form.method = "post" ; | | form.method = "post" ; |
| form.onsubmit = function () { hotcat_ok(); return false; } ; | | form.onsubmit = function () { hotcat_ok(); return false; } ; |
| form.id = "hotcat_form" ; | | form.id = "hotcat_form" ; |
| form.style.display = "inline" ; | | form.style.display = "inline" ; |
|
| |
|
| var list = null; | | var list = document.createElement ( "select" ) ; |
|
| | list.id = "hotcat_list" ; |
| if (!hotcat_nosuggestions) {
| | list.onclick = function () { document.getElementById("hotcat_text").value = document.getElementById("hotcat_list").value ; hotcat_text_changed() ; } ; |
| // Only do this if we may actually use XMLHttp...
| | list.ondblclick = function () { document.getElementById("hotcat_text").value = document.getElementById("hotcat_list").value ; hotcat_text_changed() ; hotcat_ok(); } ; |
| list = document.createElement ( "select" ) ;
| | list.style.display = "none" ; |
| list.id = "hotcat_list" ;
| | |
| list.onclick = function ()
| |
| {
| |
| var l = document.getElementById("hotcat_list");
| |
| if (l != null)
| |
| document.getElementById("hotcat_text").value = l.options[l.selectedIndex].text;
| |
| hotcat_text_changed();
| |
| };
| |
| list.ondblclick = function (evt)
| |
| {
| |
| var l = document.getElementById("hotcat_list");
| |
| if (l != null)
| |
| document.getElementById("hotcat_text").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
| |
| hotcat_text_changed();
| |
| hotcat_ok((hotcat_evtkeys (evt) & 1) || (hotcat_evtkeys (evt) & 4)); // CTRL or ALT pressed?
| |
| };
| |
| list.style.display = "none" ;
| |
| }
| |
|
| |
| var text = document.createElement ( "input" ) ; | | var text = document.createElement ( "input" ) ; |
| text.size = 40 ; | | text.size = 40 ; |
| Zeile 438: |
Zeile 225: |
| text.onkeyup = function () { window.setTimeout("hotcat_text_changed();", hotcat_suggestion_delay ); } ; | | text.onkeyup = function () { window.setTimeout("hotcat_text_changed();", hotcat_suggestion_delay ); } ; |
|
| |
|
| var exists = null; | | var exists = document.createElement ( "img" ) ; |
| if (!hotcat_nosuggestions) {
| | exists.id = "hotcat_exists" ; |
| exists = document.createElement ( "img" ) ;
| | exists.src = hotcat_exists_no ; |
| exists.id = "hotcat_exists" ;
| |
| exists.src = hotcat_exists_no ;
| |
| }
| |
|
| |
|
| var OK = document.createElement ( "input" ) ; | | var OK = document.createElement ( "input" ) ; |
| OK.type = "button" ; | | OK.type = "button" ; |
| OK.value = "OK" ; | | OK.value = "OK" ; |
| OK.onclick = function (evt) { hotcat_ok ((hotcat_evtkeys (evt) & 1) || (hotcat_evtkeys (evt) & 4)); }; // CTRL or ALT pressed? | | OK.onclick = hotcat_ok ; |
|
| |
|
| var cancel = document.createElement ( "input" ) ; | | var cancel = document.createElement ( "input" ) ; |
| cancel.type = "button" ; | | cancel.type = "button" ; |
| cancel.value = "Cancel" ; | | cancel.value = "Abbrechen" ; |
| cancel.onclick = hotcat_cancel ; | | cancel.onclick = hotcat_cancel ; |
|
| |
|
| if (list != null) form.appendChild ( list ) ; | | form.appendChild ( list ) ; |
| form.appendChild ( text ) ; | | form.appendChild ( text ) ; |
| if (exists != null) form.appendChild ( exists ) ; | | form.appendChild ( exists ) ; |
| form.appendChild ( OK ) ; | | form.appendChild ( OK ) ; |
| form.appendChild ( cancel ) ; | | form.appendChild ( cancel ) ; |
| Zeile 464: |
Zeile 248: |
| } | | } |
|
| |
|
| function hotcat_ok (nocommit) { | | function hotcat_ok () { |
| var text = document.getElementById ( "hotcat_text" ) ; | | var text = document.getElementById ( "hotcat_text" ) ; |
| var v = text.value || ""; | | var v = text.value ; |
| v = v.replace(/_/g, ' ').replace(/^\s\s*/, '').replace(/\s\s*$/, ''); // Trim leading and trailing blanks
| | |
|
| |
| // Empty category ? | | // Empty category ? |
| if (!v) { | | if ( v == "" ) { |
| hotcat_cancel() ; | | hotcat_cancel() ; |
| return ; | | return ; |
| } else if ( hotcat_is_on_blacklist(v) ) {
| |
| alert( 'Dieser Kategorien-Typ muss mit einer Vorlage eingebunden werden.' );
| |
| return;
| |
| } | | } |
|
| |
|
| // Get the links and the categories of the chosen category page
| | var editlk = document.getElementById('ca-edit').getElementsByTagName('a')[0].href; |
| var url = wgServer + wgScriptPath + '/api.php?action=query&titles=' | |
| + encodeURIComponent ('Kategorie:' + v)
| |
| + '&prop=info|links|categories&plnamespace=14&format=json&callback=hotcat_json_resolve';
| |
| 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 = eval (request.responseText);
| |
| var txt = document.getElementById ('hotcat_text');
| |
| if (do_submit) {
| |
| hotcat_closeform (
| |
| nocommit
| |
| ,(txt && txt.value != v) ? " (Redirect \[\[:Kategorie:" + v + "\]\] resolved)" : null
| |
| );
| |
| }
| |
| }
| |
| };
| |
| request.setRequestHeader ('Pragma', 'cache=yes');
| |
| request.setRequestHeader ('Cache-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 ( /.*soft.redirected.categories.*/.test( cat ) ) {
| |
| 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 (':') + 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;
| |
| }
| |
|
| |
| var editlk = wgServer + wgScript + '?title=' + encodeURIComponent (wgPageName) + '&action=edit';
| |
| var url = editlk + '&hotcat_newcat=' + encodeURIComponent( v ) ; | | var url = editlk + '&hotcat_newcat=' + encodeURIComponent( v ) ; |
|
| |
|
| // Editing existing? | | // Editing existing? |
| var span = text.parentNode.parentNode ; // span.form.text | | var span = text.parentNode.parentNode ; // span.form.text |
| if ( span.id != "hotcat_add" ) { // Not plain "addition" | | if ( span.id != "hotcat_add" ) { // Not plain "addition" |
| url += '&hotcat_removecat=' + encodeURIComponent (span.hotcat_name); | | var cat_title = span.firstChild.innerHTML ; |
| | // Removing leading Category: |
| | cat_title = cat_title.substr(cat_title.indexOf(":") + 1); |
| | url += '&hotcat_removecat=' + encodeURIComponent( cat_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 ; | | 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("Kategorie:" + encodeURI (text)) ;
| |
| na.appendChild ( document.createTextNode ( text ) ) ;
| |
| na.setAttribute ( "title" , "Kategorie:" + 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 ;
| |
| }
| |
| } | | } |
|
| |
|
| Zeile 634: |
Zeile 294: |
| if ( hotcat_last_v == v ) return ; // Nothing's changed... | | 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_running = 1 ; |
| hotcat_last_v = v ; | | hotcat_last_v = v ; |
|
| |
|
| if ( v != "" ) { | | if ( v != "" ) { |
| var url = wgMWSuggestTemplate.replace("{namespaces}","14") | | var url = wgServer + "/" + wgScriptPath + "/api.php?format=xml&action=query&list=allpages&apnamespace=14&apfrom=" + encodeURIComponent( v ) + "&aplimit=" + encodeURIComponent( hotcat_list_items ); |
| .replace("{dbname}",wgDBname)
| | if ( typeof ( hotcat_xmlhttp ) != "undefined" ) hotcat_xmlhttp.abort() ; // Just to make sure... |
| .replace("{searchTerms}",encodeURIComponent(v));
| | hotcat_xmlhttp = new sajax_init_object() ; |
| var request = sajax_init_object() ;
| | hotcat_xmlhttp.open('GET', url, true); |
| if (request == null) { | | hotcat_xmlhttp.onreadystatechange = function () { |
| //Oops! We don't have XMLHttp...
| | if ( typeof hotcat_xmlhttp == "undefined" ) return ; |
| hotcat_nosuggestions = true;
| | if (hotcat_xmlhttp.readyState == 4) { |
| var list = document.getElementById ('hotcat_list');
| | var xml = hotcat_xmlhttp.responseXML ; |
| if (list != null) list.style.display = "none" ;
| | if ( xml == null ) return ; |
| var exists = document.getElementById ('hotcat_exists');
| | var pages = xml.getElementsByTagName( "p" ) ; |
| if (exists != null) exists.style.display = "none" ;
| | var titles = new Array () ; |
| hotcat_running = 0;
| | for ( var i = 0 ; i < pages.length ; i++ ) { |
| return;
| | var s = pages[i].getAttribute("title"); |
| }
| | // Removing leading "Category:" |
| request.open('GET', url, true); | | s = s.substr(s.indexOf(":") + 1); |
| request.onreadystatechange = | | if ( s.substr ( 0 , hotcat_last_v.length ) != hotcat_last_v ) break ; |
| function () {
| | titles.push ( s ) ; |
| if (request.readyState == 4) {
| | } |
| try {
| | hotcat_show_suggestions ( titles ) ; |
| eval( "var queryResult="+ request.responseText );
| |
| } catch (someError ) {
| |
| if( console && console.log )
| |
| console.log( "Oh dear, our JSON query went down the drain?\nError: " +someError );
| |
| return;
| |
| } | | } |
| var pages = queryResult[1]; // results are *with* namespace here
| |
| var titles = new Array();
| |
| for ( var i = 0 ; pages && 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].substring (pages[i].indexOf (':') + 1);
| |
| if ( s.substr ( 0 , hotcat_last_v.length ).toLowerCase() != hotcat_last_v.toLowerCase() ) break ;
| |
| titles.push ( s ) ;
| |
| }
| |
| hotcat_show_suggestions ( titles ) ;
| |
| }
| |
| }; | | }; |
| request.setRequestHeader ('Pragma', 'cache=yes'); | | hotcat_xmlhttp.send(null); |
| request.setRequestHeader ('Cache-Control', 'no-transform');
| |
| request.send(null);
| |
| } else { | | } else { |
| hotcat_show_suggestions ( new Array () ) ; | | var titles = new Array () ; |
| | hotcat_show_suggestions ( titles ) ; |
| } | | } |
| hotcat_running = 0 ; | | hotcat_running = 0 ; |
| Zeile 699: |
Zeile 331: |
| var list = document.getElementById ( "hotcat_list" ) ; | | var list = document.getElementById ( "hotcat_list" ) ; |
| var icon = document.getElementById ( "hotcat_exists" ) ; | | 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 ) { | | if ( titles.length == 0 ) { |
| list.style.display = "none" ; | | list.style.display = "none" ; |
| Zeile 713: |
Zeile 337: |
| } | | } |
| | | |
| // Set list size to minimum of 5 and actual number of titles. Formerly was just 5. | | var listh = hotcat_list_size * 20 ; |
| // Lupo, 2008-01-20 | | if (titles.length < hotcat_list_size) { |
| list.size = (titles.length > 5 ? 5 : titles.length) ; | | listh = titles.length * 20 ; |
| // Avoid list height 1: double-click doesn't work in FF. Lupo, 2008-02-27 | | } |
| if (list.size == 1) list.size = 2; | | var nl = parseInt ( text.parentNode.offsetLeft ) - 1 ; |
| | var nt = parseInt(text.offsetTop) - listh ; |
| | // Parameter to show suggestion list beneath categories instead of above |
| | if (typeof hotcat_list_down != "undefined" && hotcat_list_down) { |
| | nt = text.offsetTop + text.offsetHeight; |
| | } |
| | list.size = 5 ; |
| list.style.align = "left" ; | | list.style.align = "left" ; |
| list.style.zIndex = 5 ; | | list.style.zIndex = 5 ; |
| list.style.position = "absolute" ; | | 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.top = nt + "px" ; |
| list.style.width = text.offsetWidth + "px" ; | | list.style.width = text.offsetWidth + "px" ; |
| Zeile 741: |
Zeile 360: |
| var ot = document.createTextNode ( titles[i] ) ; | | var ot = document.createTextNode ( titles[i] ) ; |
| opt.appendChild ( ot ) ; | | opt.appendChild ( ot ) ; |
| //opt.value = titles[i] ; | | opt.setAttribute( "value", titles[i] ); |
| list.appendChild ( opt ) ; | | list.appendChild ( opt ) ; |
| } | | } |
| | | |
| | list.style.display = "block" ; |
| | |
| icon.src = hotcat_exists_yes ; | | icon.src = hotcat_exists_yes ; |
|
| |
|
| var nof_titles = titles.length;
| | var first_title = titles.shift () ; |
| var first_title = titles.shift (); | | if ( first_title == hotcat_last_v ) return ; |
| var v = text.value.ucFirst();
| |
| | |
| text.focus();
| |
| if ( first_title == v ) { | |
| if( nof_titles == 1 ) {
| |
| // 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;
| |
| }
| |
| list.style.display = "block" ;
| |
|
| |
|
| // Put the first entry of the title list into the text field, and select the | | var suggestion = first_title; |
| // 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-18
| |
| 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-18
| |
| var nosel = v.length ;
| |
| | | |
| text.value = first_title ;
| | text.value = suggestion ; |
|
| | if (text.createTextRange) { |
| if (text.setSelectionRange) // e.g. khtml
| | // IE |
| text.setSelectionRange (nosel, first_title.length);
| | var ra = text.createTextRange(); |
| else if (text.createTextRange) { // IE | | ra.moveStart("character", hotcat_last_v.length); |
| var new_selection = text.createTextRange();
| | ra.moveEnd("character", suggestion.length); |
| new_selection.move ("character", nosel);
| | ra.select(); |
| new_selection.moveEnd ("character", first_title.length - nosel);
| | } else if( is_khtml ) { |
| new_selection.select();
| | text.setSelectionRange( hotcat_last_v.length, suggestion.length ); |
| } else { | | } else { |
| text.selectionStart = nosel;
| | text.selectionStart = hotcat_last_v.length ; |
| text.selectionEnd = first_title.length;
| | text.selectionEnd = suggestion.length ; |
| }
| |
| } | | } |
| } | | } |
| /* </nowiki></source> */ | | // </nowiki> |