User:Cameltrader/Advisor

From Wikipedia, the free encyclopedia
< User:Cameltrader  (Redirected from Wikipedia:ADVISOR)
Jump to: navigation, search
Shortcut:

This script identifies common formatting and stylistic issues by examining the wikitext as you type.

Installation[edit]

This is what it looks like.
(without the trademarked Wikipedia logo)

Add the following to your personal js:

importScript('User:Cameltrader/Advisor.js');

Then refresh. From now on, a list of suggestions will appear above your edit box while you are editing a page. Clicking on a suggestion name highlights the text it refers to. Clicking twice pops up a help message. The "fix" link next to it inserts the proposed replacement at the appropriate place.

If you are suspicious about stuff you add to your common.js, and suspicious you should be, you might want to review the code before using it.

Features[edit]

You might be given any of the following suggestions while editing:

Known issues[edit]

Please report new ones to the talk page.

  • Automatic textarea scrolling in Opera seems impossible hard to implement. It ignores setting the scrollTop property. Opera 9.5 will likely fix this issue (Opera 9.5 Beta 1 changelog, search for "scrollTop"). A workaround could be implemented by wrapping the textarea in a div element and scrolling the div instead.discuss
Opera O.png
If you use Opera and you do not see highlighted text in the textarea, press on your keyboard and the cursor will be right after the fixable text; you can click the suggestion link again to highlight it.
  • After clicking "Preview", the proposed summary is lost. In other words: you edit a page, you "fix" some of the suggestions on top, the names of the changes get accumulated and appear with an "Add to summary" link just above the "Edit summary" line, then you click "Preview" (without clicking "Add to summary"), and your accumulated names of changes disappear, so you have to go back. It's a usability issue.
  • WikEd logo64x64.gif
    Advisor.js is incompatible with wikEd. The reason for this is that wikEd renders the wikitext not in the usual TEXTAREA but as a dynamically created DOM tree in an IFRAME; that's because of the syntax highlighting. What I need is to be able to select text between two certain offsets (including scrolling it into view) and to replace that text. User:Cacycle suggested a way to do it, and I started implementing the solution. However I've been having a hard time with it this weekend, and only highlighting is functional until now. Scrolling to the correct offset and replacing the highlighted text do not work yet.
  • There is no easy way to switch the script on and off without modifying monobook.js—this could be useful for mobile access. The script should either be proposed for inclusion as a WP:Gadget or a toggle button should be implemented.discuss (I already proposed its inclusion as a gadget.)
  • The "mdash" rule is undocumented and doesn't work as expected. It should only replace the hyphen with an em dash, without converting the space before it to a nbsp. The latter should be handled by "nbsp-dash".discuss
  • It is annoying to be warned about trailing whitespace all the time while you type.
  • After accepting a fix, the undo history is no longer functional in IE and Opera.

Further development[edit]

These are not yet in Advisor.js, but are worth considering:

  • ipa: Sequences of IPA characters should be enclosed like this: {{IPA|kʰæmɫ.tɹeɪdə}}, in order to let MediaWiki add browser quirks.
  • AmE-BrE-bias: if there are sufficiently good hints in the article that it uses or should use American English rather than British English, or vice versa, Advisor.js should suggest conforming to the majority.
  • date-bias: same for American-style dates ("[[January 1]], [[2000]]", some other parts of the world use it, too) vs conventional dates ("[[1 January]] [[2000]]"). I believe the topic of the article (e. g. if it is related to the US) should influence the balance, if there's a good heuristic to recognize Americanisms.
  • as-of, as-of-month: Suggest linking of "as of 2000" as "[[as of 2000]]", and converting "[[as of January 2000]]" to "[[as of 2000|as of January 2000]]" per WP:AO.
  • Suggest adding maintenance tags, such as:discuss
    • {{Sections}} to articles that have no headings
    • {{subst:Trivia-now}} below any sections labeled "Trivia" or "Miscellany"
    • {{Nofootnotes}} to any article that lacks a <ref> tag
    • {{subst:dated|uncategorized}} to any article that does not have a category or template transcluded into it (as so many templates add articles to categories)
    • {{Deadend}} to articles that have less than three (for instance) links
    • {{ExcessiveLinks}} or {{Too many links}} to articles that have more than 20 (again, an arbitrary number) links outside of <refs>, or to more than 20 links under a "External links" heading
    • {{Too many categories}} to articles that have more than 20 (arbitrary) categories

Discuss these or propose a new one

Contributors[edit]

I am open for new ideas and happy to implement them. But if you have a little knowledge of JavaScript, you might consider submitting some code of your own—here is an example of how to do it:

ct.rules.push(function (s) {
 
    // A ``rule'' is a JavaScript function that accepts a string as a
    // parameter (the wikitext of the page being edited) and returns an array
    // of ``suggestion'' objects.
 
    var matches = ct.getAllMatches(/int he/g, s);
    // getAllMatches() is a utility function of mine, you are not required to use it
 
    var suggestions = [];
    // A ``suggestion'' object must have the following properties:
    //     * start---the 0-based inclusive index of the first character to be replaced
    //     * end---analogous to start, but exclusive
    //     * (optional) replacement---the proposed wikitext, if any
    //     * name---this is what appears at the top of the page
    //     * description---used as a tooltip for the name of the suggestion
    //     * (optional) help---an HTML fragment as a string, it will appear in a yellow
    //                         box when a suggestion is double-clicked
 
    for (var i = 0; i < matches.length; i++) {
        var match = matches[i];
        suggestions.push({
                start: match.start,
                end: match.end,
                replacement: "in the",
                name: "spelling-example",
                description: "You probably meant ``in the'' instead of ``int he''."
        });
    }
 
    return suggestions;
 
});

One way to test this is to copy Advisor's source to some page in your private namespace, add the custom code, and do an importScript() for the new page instead of the original Advisor.js. (I wasn't able to achieve my goal by putting the custom code in a separate page and importing both. Probably importScript() imports scripts in some unpredictable order, I don't know...)

However, in order to reduce unnecessary load on Wikipedia servers, I recommend running some simple web server at localhost (such as lighttpd, Apache, Tomcat, or whichever you might be familiar with) at localhost, and replacing your monobook.js with something like:

document.write('<script src="http://localhost:8000/AdvisorCustom.js" type="text/javascript"></script>');

Thus, you can experiment freely without cluttering your list of contributions.