User talk:Lupo/c.js

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

This is a re-implementation of the popular HotCat gadget. It is designed to be a backwards-compatible drop-in replacement: it should be possible to just copy the text from User:Lupo/c.js into MediaWiki:Gadget-HotCat.js. The only additional thing that would need to be done before doing so is to rewrite the help page to cover the new features in the UI: multi-changes and suggestion engine selection.

Improvements over HotCat[edit]

  1. Enables multiple category changes - Longstanding feature request
    Switched on automatically if more than one category editor is opened (change/add + change, or change/add + del), but can also be switched on manually (using the ++ link; to add or delete several categories). Multi-change mode does not autosave but presents the edit screen in the "show changes" view, so that the user can double check and provide a meaningful edit summary.
  2. Does not autocomplete if last input was a deletion - HotCat did, which was a minor nuisance
  3. Works for RTL wikis and languages - HotCat didn't
    Some minor problems in Konqueror, major troubles in IE6. Disabled for RTL on IE6.
  4. Correctly positions the suggestion list even on IE6 - Were always off in HotCat
    This is especially important for the skins using right-aligned category bars, such as the standard/classic skin.
  5. Suggestion engine can be selected - Was not possible in HotCat
    Three engines are implemented: search index (does some Unicode collation, showing also suggestions starting with similar characters, but is updated only at intervals and thus may miss newly created categories), page list (strictly alphabetic, so does not show suggestions starting with similar characters, but does show also recently created categories), and a combined engine using both, which is the default.
  6. Do not even offer to change transcluded categories - Another long-standing feature request. HotCat allowed this, and issued an error when trying to actually edit
    Works only if the client receives the wikitext of the page from the server within 4 seconds. It would be really nice if we had this information in some wg* variable in the inline JS on the page. Could save us a remote call, but would require a non-trivial server-side change.
    We'll just have to try this one out. It is just barely possible that making one unconditional extra call to the server to get the wikitext of the page is too much for the servers. If this indeed turns out to cause a performance problem for the servers, we'll have to disable this again and will have to push for the aforementioned server-side change (identifying the not-transcluded categories on the server side, including them in some wg* variable).
    Note that due to the time limit of four seconds, this may not work on slow connections.
  7. Treats cmd-click like ctrl-click (preventing autosave in single-change mode). - Needed because apparently ctrl-click is overloaded in FF on Mac.
  8. Code is cleaned up; adds far less global objects to the window object (less global namespace pollution) and has strings that are to be localized when porting the gadget to other wikis clearly separated from the main logic.
  9. Fixes a number of minor issues in HotCat that nobody had complained about yet.
    For instance the height of the suggestion list, if there are less than five suggestions, has been fixed to not show empty lines. Or ignoring categories in the wikitext within HTML comments and <nowiki> elements when removing/adding/changing a category. (HotCat only ignored HTML comments and nowikis when figuring out where to insert a new category, but not when deleting a category.)
  10. Keyboard navigation for the suggestion list (up/down arrows), correct handling of return/ctrl-return in all cases.
  11. Caching of suggestion requests

At the same time, this re-implementation preserves HotCat's lean and mean no-nonsense user interface.

Tested and working fine[edit]

  • FF 3.0.5 (Win), 3.5.5 (Mac)
  • Safari 4.0.4 (6531.21.10) (Mac)
  • IE8.0.6001.18702 (Win)
  • Chrome 4.0.249.78 (36714) (Win)
  • Opera 9.02, 9.50 (Win) - works, suggestions are a bit slow
  • Konqueror 4.2.3 and 4.4.0 (Win) - OK on LTR wikis, some display problems on RTL wikis.
    On RTL wikis, newly added categories suddenly appear at the end of the category bar, which is confusing. If somebody with RTL experience can figure out a workaround that doesn't break the other browsers, that'd be great.
  • IE6.0.2900.5512 (Win) - OK on LTR wikis & languages. Disabled on RTL wikis.
    On RTL wikis, there's totally weird stuff going on, such as links missing, or links performing the wrong actions. Also severe layout problems.

Trying it out[edit]

This section is obsolete. The new version has been deployed, and will be used by anybody who has the "HotCat" gadget enabled in his or her preferences.


To try it out, follow these steps:

  1. Disable the HotCat gadget in your preferences.
  2. Add the following line to your vector.js or monobook.js or other skin-specific user JS file:
if (wgNamespaceNumber >= 0) importScript ('User:Lupo/c.js');

Then refresh your browser's cache.

Beta testers[edit]

This section is obsolete. The new version has been deployed, and will be used by anybody who has the "HotCat" gadget enabled in his or her preferences.


Please sign here if you decide to beta-test this. If you want to be extra helpful, state which skin and browser you're using. Thank you.

Bug reports and improvement suggestions[edit]

Please report any errors or improvement suggestions at MediaWiki talk:Gadget-HotCat.js.

These sections are closed. The new version has been deployed, and will be used by anybody who has the "HotCat" gadget enabled in his or her preferences.


May 3, 2010[edit]

  • For #7, maybe this should also modify the default edit summary. -- User:Docu at 08:31, 3 May 2010 (UTC)[reply]
    Maybe. HotCat didn't. The idea in HotCat was that using a crtl-click gives the user the oppportunity to double-check and to provide his or her own summary, so HotCat didn't provide a summary. The new script just copied that behavior. Lupo 08:55, 3 May 2010 (UTC)[reply]
    I'm aware of that. I don't think people usually do and the default summary suggests nothing else was done. -- User:Docu at 09:05, 3 May 2010 (UTC)[reply]
  • For #1, we might want to save directly instead of stopping at the diff.
    That's on purpose. I'm fine with auto-saving single category changes, but for mutliple changes, I want the user to double-check. Things can get a bit messy if you add/delete/change several categories, and then maybe even undo some of these actions (using the × link). I also want the user to enter a summary; I can only provide a rather generic one automatically. Lupo 08:55, 3 May 2010 (UTC)[reply]
    Maybe make it a user pref? -- User:Docu at 09:05, 3 May 2010 (UTC)[reply]
  • At #1: leaves minor edit + watchlisting unchecked. -- User:Docu at 08:47, 3 May 2010 (UTC)[reply]
    Multi-category edits should never be minor, I think. As for watchlisting, I don't do anything with that; it should be set according to the "watchlist pages I edit" preference by the server. Lupo 08:55, 3 May 2010 (UTC)[reply]
    Ok for minor. Watchlisting doesn't seem to work. -- User:Docu at 09:05, 3 May 2010 (UTC)[reply]
    Hm, right, only clicking the "watch" box manually works, but the user preference isn't honored automatically. Lupo 09:17, 3 May 2010 (UTC)[reply]
    ✓ Done. Don't forget to refresh your browser's cache. Lupo 08:35, 4 May 2010 (UTC)[reply]
    Works now. -- User:Docu at 10:12, 4 May 2010 (UTC)[reply]
  • For #2: how does this work? It does autocomplete when using backspace (no problem though). -- User:Docu at 14:21, 3 May 2010 (UTC)[reply]
    Which inputs, which browser? basically, assume you have entered "Blah" (and got an autocompletion, which should be selected), hitting DEL or BS should get you "Blah", then "Bla", and then "Bl", without autocompleting, but still updating the suggestion list. (The suggestion list for "Bla" and "Bl" starts with the same five suggestions, though, you'll need to scroll down to see that it really changed.) The important part here is that it shouldn't autocomplete, otherwise, one will have to type BS twice in rapid succession to get rid of the autocompleted part. Lupo 14:36, 3 May 2010 (UTC)[reply]
    It works then. Indeed, it might have been a bit strange before. -- User:Docu at 14:44, 3 May 2010 (UTC)[reply]
    Just to clarify for the benefit of others who might read this, here's what HotCat does: upon input "Blah", it automatically completes it to "Blahn (photographer)", not even showing the other suggestions it should have for that input (that seems to be a bug in HotCat, BTW). The autocompletion "n (photographer)" is selected. Hitting BS deletes that, displays a list of five suggestions, and again autocompletes to "Blahn (photographer)". Only hitting BS a second time gets rid of the autocompletion. Hitting BS again leaves the input "Bla", which get immediately autocompleted to "Black". Hitting BS again leaves us with "Bla", and hitting BS once again gives "Bl", which is autocompleted to "Black" again. Lupo 14:50, 3 May 2010 (UTC)[reply]
  • For #1: after typing one category to add, it occurred to me that I should add a second one. Instead of clicking ok, one needs to go all the way to the left to click there. It might be helpful if there was a (+) next to the "ok" button to add more categories. -- User:Docu at 14:21, 3 May 2010 (UTC)[reply]
    Hmmm. I'll see what I can do. Lupo 14:36, 3 May 2010 (UTC)[reply]
    ✓ Done. Don't forget to refresh your browser's cache. Lupo 21:23, 3 May 2010 (UTC)[reply]
    Thanks. Works fine. -- User:Docu at 22:18, 3 May 2010 (UTC)[reply]
  • Other than the above, #1 worked fine. I didn't test #3, #4, #7, #9. Newly created categories get suggested (#5), excellent!. #6 seems to work too. -- User:Docu at 14:21, 3 May 2010 (UTC)[reply]
  • Non regression: adding, removing and replacing categories still works. Also adding categories directly through bookmarklets or links still works. Works with category redirects, disambiguations. Just tested on 1 browser though. -- User:Docu at 14:21, 3 May 2010 (UTC)[reply]
  • Currently links such as [addcat] add categories with underscores (sample). If there was an easy way around it, that might help. Otherwise, the current solution works too. -- User:Docu at 14:52, 3 May 2010 (UTC)[reply]
    ✓ Done. Needs a reload of your browser's cache before you'll have that change. Lupo 15:16, 3 May 2010 (UTC)[reply]
    Works fine. Thanks. -- User:Docu at 15:37, 3 May 2010 (UTC)[reply]
  • Works fine. No bug (until now). I used it with a newly (created less than 8 minutes before adding it to the file) category and it was OK. As I know my category will show up in the more simple "page list" mode, I switchted to that mode. I used the combined mode once or twice and it was OK too. Teofilo (talk) 17:09, 3 May 2010 (UTC)[reply]
    Cool. New categories should also show up in combined mode. Lupo 21:44, 3 May 2010 (UTC)[reply]
  • The page is not autosaving after multiple category edits. Is this a bug or a feature ? Teofilo (talk) 17:25, 3 May 2010 (UTC)[reply]
    That's a feature. I want people to review the changes made if they change multiple categories, and I want them to provide a meaningful edit summary, which the script cannot do automatically. If you add/delete/change several categories, maybe undoing some of the changes along the way, the user may inadvertently make changes he or she didn't intend. Showing the diff page is a safeguard against that. Lupo 17:32, 3 May 2010 (UTC)[reply]
    which the script cannot do automatically--> That means that the software cannot do it now. But can we imagine that in the future, further software developments could provide automatically a detailed "meaningful" summary ? Teofilo (talk) 17:45, 3 May 2010 (UTC)[reply]
    Not likely. Consider the length of the text. "Added categories X, Y, Z, changed categories A, B, C (redirects Q, R, Z resolved), deleted categories Foo, Fie, Fum". Insert real category names, and you get rather quickly above the edit summary limit of 250 bytes. Lupo 18:01, 3 May 2010 (UTC)[reply]
    The purpose of summaries is to tell other users who watch the history tab or have the page in their watch list what you have done. Generally adding things to a page is less sensitive than removing things. So perhaps we should concentrate on telling which categories were removed. So the summary could have the following pattern : "removed category:<AAAA>, changed 2 categories, added 1 category ; please see "diff" for details". That would remain short enough and quite substential. At the very least, the new multiple edit tool should not be worse than the old hotcat gadget : I mean it should be able to provide the old usual hotcat gadget summary when only one category is removed, changed, or added. Teofilo (talk) 21:02, 3 May 2010 (UTC)[reply]
    That much is true. I'll see what can be done. Lupo 21:23, 3 May 2010 (UTC)[reply]
    If you feel like cutting part of the summary, I think the removals would be more important to list. -- User:Docu at 22:18, 3 May 2010 (UTC)[reply]
    ✓ Done. Don't forget to refresh your browser's cache. If only one change, summary is the same as in single-change mode. Otherwise, if only one each of deletion/addition/change, summary contains the category names. If more in one category, only reports the number of deletions/additions/changes. Lupo 08:35, 4 May 2010 (UTC)[reply]
  • The multiple category edit tool should be useful when creating an entirely new category from scratch (inserting it into parent categories). However I get the following message "Could not retrieve the page text from the server" after clicking on "OK". Teofilo (talk) 20:47, 3 May 2010 (UTC)[reply]
    Good idea. I presume you tried going to a non-existing category page and then used the new script? Hm. I'll have to see whether I can actually make it work for that case. Lupo 21:02, 3 May 2010 (UTC)[reply]
    ✓ Done. Don't forget to refresh your browser's cache. Lupo 21:23, 3 May 2010 (UTC)[reply]
    What would be cool for new categories with a corresponding article at en_wiki, that is to add an interwiki, fetch all interwikis from en_wiki and, possibly, categories available there, if they exist at Commons ({{#subst:ifexist could do that, sample). -- User:Docu at 22:18, 3 May 2010 (UTC)[reply]
    Of course it would be cool :-) But I think a full-fledged "new category creation wizard" is a bit out of scope for HotCat or for this replacement. Also, we have no clean way of doing cross-domain calls. The only way is a hack using the equivalent of importScript, but there is no real cross-browser support support for handling of error conditions. Maybe later... Lupo 05:55, 4 May 2010 (UTC)[reply]
    It is quite a way from the standard category tool, but as it was Xmas yesterday, I thought, I should ask. -- User:Docu at 07:07, 4 May 2010 (UTC)[reply]
    When I create a new category from scratch, I usually leave the summary box empty, so that the Mediawiki sofware will automatically fill it with a copy-pasting of the input text. Unfortunately after I click on the "save" button, the gadget automatically fills the summary box with "Multiple category changes using HotCat)" (example (with gadget))(compare with this category start summary (without gadget)). Teofilo (talk) 05:47, 4 May 2010 (UTC)[reply]
    Yup, that should be improved. Lupo 05:55, 4 May 2010 (UTC)[reply]
    ✓ Done. Don't forget to refresh your browser's cache. Edit summary is left unchanged (empty) for page creations. Lupo 08:35, 4 May 2010 (UTC)[reply]
    Looks OK now (example with gadget). Teofilo (talk) 16:58, 16 May 2010 (UTC)[reply]

May 4, 2010[edit]

  • Computer speed problems. [I have been perhaps a bit over-optimistic in my first report yesterday, when I said it was OK. Later on, I experienced the gadget getting slower and slower: first, the gadget stops from fetching suggestions, and I need to use "backspace" and type the letters again to have it fetch suggestions again. Then it simply refuses to fetch anything, even when I try backspace and typing again. Sometimes the suggestions are provided in the list but the first one is not automatically typed). So I shut Firefox down, started it again and the gadget worked quickly again. Anyway, even without this specific gadget, I usually have to start Firefox again (or Windows or to reboot my computer) after I categorize 15 or 20 pictures (even if I carefully try not to open more than 2 tabs at a time)(or after making 2 or 3 "nominate for deletion" script requests). Additionnally, the Wikimedia servers might have been slow at times yesterday night (I had some problems for loading category pages). But my computer gets tired quite quickly]. So I would feel more comfortable if it was possible to have a "page list only" option. Using the mouse to switch to that mode on every page is a bit cumbersome, and I would be happy if the gadget could remember that this is my preference. Teofilo (talk) 06:35, 4 May 2010 (UTC)[reply]
    Maybe an option to disable #6 would be useful. -- User:Docu at 07:07, 4 May 2010 (UTC)[reply]
    Maybe... but I don't think that's necessary yet; if the wikitext doesn't arrive within 4 seconds, the script just goes ahead without it. Teofilo's problem description doesn't sound like it had something to do with this. Sounds more like slow servers, or a computer with not enough memory. (Though I'm using this without problems on a 1GB windows box several years old.) Lupo 08:14, 4 May 2010 (UTC)[reply]
    I saw that coming :-) That already exists. For now, it's just not yet documented. To use the page list by default, add the following to your monobook.js or other appropriate JS file (vector.js, or whatever):
var hotcat_suggestions="pagelist";
Lupo 08:14, 4 May 2010 (UTC)[reply]
Besides, the servers are slow to respond this morning. I'm currently seeing delays of more than 10 seconds until the server sends back the suggestion list. Lupo 08:29, 4 May 2010 (UTC)[reply]
  • Bug (preexisting in the old hotcats gaget too) : the right arrow key is having an end key behavior, and I miss the expected right arrow behavior.

If I begin typing (with the intention of writing "Ancient Roman cities and villages in France by Latin name"):

Ancient R

the gadget autotypes:

Ancient Roman Forts at Masada

or if I begin typing (with the intention of writing "Archaeological sites in France")

Archaeolo

the gadget autotypes:

Archaeological Area in Brazil

This behavior is perfectly normal, but something could be improved here.

I want to reuse the "oman" part after "Ancient R" (and discard the "Forts at Masada" part) instead of needing to type it again.

I want to reuse the "gical" part after "Archaeolo" (and discard the "Area in Brazil" part) instead of needing to type it again.

The typing prompt (|) is located just after the R in "Ancient R|oman Forts at Masada" and just after the second "o" in "Archaeolo|gical Area in Brazil".

So what I expect here is to move the typing prompt forward with the right arrow key (→) five times, providing "Ancient Roman |Forts at Masada" or six times to provide "Archaeological |Area in Brazil", so that I can easily delete the following parts needing to be discarded.

Unfortunately, after I push once on the right arrow key, the prompt jumps to the end (to "Ancient Roman Forts at Masada|" and "Archaeological Area in Brazil|". This is an en:end key behavior! This is not what a right arrow key is supposed to do!

Then removing the parts needing to be discarded becomes quite uneasy : from the end of "Ancient Roman Forts at Masada|" , you need to use the left arrow key ← 15 times going backwards to "Ancient Roman |Forts at Masada"or 14 times backwards to "Archaeological |Area in Brazil". Teofilo (talk) 07:28, 4 May 2010 (UTC)[reply]

That is not a bug. It is the normal behavior of the → key when there is a selection: the text cursor is placed at the end of the selection, and the selection is cleared. There's nothing I can do to change this browser behavior. Work-around: type ← once, then → five times. Lupo 08:04, 4 May 2010 (UTC)[reply]
Oh thank you. That little work around is clever and simple. Teofilo (talk) 17:09, 16 May 2010 (UTC)[reply]

May 5, 2010[edit]

When i enter category "Unidentified fish" and press OK it automatically change category to "Fishes" instead of "Unidentified fishes"? --Smooth_O (talk) 07:30, 5 May 2010 (UTC)[reply]

Hm. That's the redirect resolution. Category:Unidentified fish is a category redirect to Category:Unidentified fishes. The problem is that the script (like the old HotCat, so the old HotCat does the same) doesn't know really which the redirected-to category is; it just uses the first category link. But Category:Unidentified fish contains another category link before the redirect, namely Category:Fish. Thus the redirect resolution goes wrong in this case.
This cannot be fixed easily in the script. The best way to fix this is probably to just remove the {{Unidentified header}} from Category:Unidentified fish, which I've done now. Soft category redirects should contain only a {{Category redirect}}. Lupo 08:02, 5 May 2010 (UTC)[reply]

First edit using the beta, at Category:Eagle Harbor Lighthouse, clicked on minus on the redundant category Lighthouses in Michigan, got:

Your edit has been rejected because your client mangled the punctuation characters in the edit token. The edit has been rejected to prevent corruption of the page text. This sometimes happens when you are using a buggy web-based anonymous proxy service.

It left me in Preview mode with the deletion actually done. Vector,Firefox 3.5.9, W2K SP4. Not knowing the status of the edit, I backed out of it without hitting save. . . . . Jim . . . . Jameslwoodward (talkcontribs) 11:30, 5 May 2010 (UTC)[reply]

Can you reproduce this? Because I can't, and User:Docu apparently couldn't either. (See the history.) If it's reproducible, what other Gadgets do you have activated? If it's not reproducible: I have noticed that session information appears to get lost from time to time during normal editing (i.e., nothing to do with HotCat or this script), and then you also get that behavior, albeit with a slightly different error message. maybe it was a server hiccup? Lupo 14:30, 5 May 2010 (UTC)[reply]
I did it three times before I reported it, and once after I noticed User:Docu try it, but it did not happen on the edit I just made. So let's let it lie unless it happens again. Thanks for a speedy response. . . . . Jim . . . . Jameslwoodward (talkcontribs) 15:36, 5 May 2010 (UTC) Ah, computers -- can't live without them, but sometimes they're inscrutable.[reply]
Reading this, I enabled the EoMagicalConversion gadget and I got the same error message when trying to do this change with that gadget enabled. -- User:Docu at 15:52, 5 May 2010 (UTC)[reply]
Indeed, that's the culprit. What an ugly and buggy hack! This thing does modify the editToken, and doesn't always properly restore it. It would be better if it stored its global state somewhere else! Not a problem of HotCat or of this script, then. Lupo 16:45, 5 May 2010 (UTC)[reply]
Aha.
  • My bad for not telling you I had made a change in my preferences between the two events.
  • A ? for how the EoMagicalConversion gadget got itself enabled.
  • A barnstar for you both for diligent detective work.
. . . . Jim . . . . Jameslwoodward (talkcontribs) 12:05, 6 May 2010 (UTC)[reply]

May 7, 2010[edit]

May 13, 2010[edit]

It's live[edit]

I've gone live with this. Thanks everybody for testing, you've been a great help! You may now remove that line from your user script; re-enable the HotCat gadget, and reload your browser cache. All further development will now happen on MediaWiki:Gadget-HotCat.js. Further bug reports and improvement suggestions over at MediaWiki talk:Gadget-HotCat.js, please. (Yes, Docu, I haven't forgotten your last suggestion. Will see how to do this best.) Lupo 07:37, 26 May 2010 (UTC)[reply]

Good work.
Don't worry about that suggestion, it's not that important.
BTW, to avoid loading pages twice, I limited this to file and category namespaces. In general, maybe it should treat other namespaces differently. (For WP, one might include namespace 0). -- User:Docu at 07:32, 2 June 2010 (UTC)[reply]
Well, if you're using the gadget, it's enabled nearly anywhere, and so far loading the wikitext doesn't seem to cause performance problems. Lupo 19:08, 2 June 2010 (UTC)[reply]
I'm using it with if (wgNamespaceNumber == 6) importScript ('MediaWiki:Gadget-HotCat.js');
It's mainly at COM:VP where I think I noticed that it took some time to load. -- User:Docu at 12:08, 4 June 2010 (UTC)[reply]