Jump to content

Wikipedia:AutoEd/Customization

From Wikipedia, the free encyclopedia

AutoEd was designed with a high level of customizability in mind, which allows it to be greatly altered by each person who wants to use it, and it can even support the creation of new modules which effectively create entirely new user scripts. This page will serve to document how you can customize and change AutoEd to fit your personal tastes and preferences and how to create new modules. A knowledge of JavaScript may be helpful for more advanced customization, but shouldn't be required once the basic use and creation of regular expressions is documented here. This page is not yet complete, but all information that is on it should be accurate.

Basic customization: Variables

[edit]

AutoEd features a number of built in "variables" which you can change for your own use. To change the variables, just copy the following into your monobook.js page, where you should also have the "basic" preset imported (some of the other presets have set variables already, so changing some variables in conjunction with using non-basic presets could cause errors. To avoid this, you may want to consider either creating your own preset or defining the script's main function manually, both of which will be described below).

autoEdMinor = true;
autoEdClick = true;
autoEdTag = "Cleaned up using [[WP:AutoEd|AutoEd]]";
autoEdLinkHover = "Run AutoEd";
autoEdLinkName = "auto ed";
autoEdLinkLocation = "p-cactions";

Each of these variables is described below. The first two variables are "boolean"; they can be set to either true or false, and nothing else. The next three are strings; you can change the text within the string to anything you'd like, just remember to leave the quotation marks in. The final variable is a little more complicated; see the description below for details. If you'd like, you can remove the entire line for each variable that you don't change from the defaults listed above.

Remember in each case to leave the semicolon at the end; otherwise the script won't work.

autoEdMinor
This defines whether or not the "minor" checkbox is checked when you use the script. By default, the box is automatically checked. Setting this value to false will uncheck the box each time that you run the script (note that it will still uncheck it if you wanted it to be marked as minor, so remember to double check this before saving). (It appears that setting this value to false now makes AutoEd not mess with the minor checkbox. — sligocki (talk) 07:45, 24 October 2009 (UTC))[reply]
autoEdClick
This defines whether or not the "show diff" button is automatically clicked after the script makes its changes. The default clicks it automatically; setting this to false will cause the script to make its changes without automatically showing the diff. This can be useful if you usually make other changes at the same time that you use the script, but make sure to check the diff manually before saving.
autoEdTag
This string is added to the edit summary box when you run the script. If you change this variable, it would be much appreciated if you still provide a link to Wikipedia:AutoEd so that other users can find the script more easily, although this isn't strictly required.
autoEdLinkHover
This string contains the "tooltip" text shown when you hover your mouse over the link to run the script.
autoEdLinkName
This string defines the name of the tab which initiates the script.
autoEdLinkLocation
By default, the "auto ed" link used to run the script appears as a tab above the page. This row of tabs is technically called "p-cactions", short for "content actions portlet". If you'd rather have the link somewhere else, this variable gives you two other options: "p-personal" and "p-tb". The first of these adds the link to run the script to your list of "personal" links at the very top of the page. This doesn't really make much sense, but could be useful if you have other user scripts which would cause the "content actions" tabs to overflow the screen. "p-tb" adds the link to the "toolbox" in the sidebar. In both cases, the standard tab is hidden from view.

Choosing your own modules

[edit]

Although the length of this section may make it look complicated, selecting your own modules (sets of automatically-made changes) is actually pretty easy. The presets provide an easy way to quickly start the script, but you can pick and choose what change you want to have the script make easily, and you can even use your own, new modules.

When using this form of customization to select your own modules, please do not also import one of the presets; this could cause a malfunction. Instead, you can look at the code used in the presets to determine what modules are needed to duplicate their effects.

Generally, you add this code to your monobook.js page. If you think that your code is different enough from the presets that other users may want to have it as an easy-to-use selection, you can instead create the preset separately at Wikipedia:AutoEd/nameofpreset.js, replacing "nameofpreset" with the chosen name.

These instructions are set up in the order the code should be added to whatever page you are putting it on, so you can just go through it one step at a time.

Initial requirements

[edit]

Any use of AutoEd requires that Wikipedia:AutoEd/core.js be imported for use, because this defines the set of core functions needed to make the script work... things like creating the "auto ed" tab, defining the default parameters for variables, and adding text to the edit summary. To do so, simply add the following text:

importScript('Wikipedia:AutoEd/core.js'); //Imports the "framework" script needed to make this function

Note: If you are creating your script somewhere other than in your userspace, you need to put the text

//<syntaxhighlight lang="javascript">

before anything else in the script.

Setting variables

[edit]

After importing the core framework, you should set any variables that you want to have different from the default. See #Basic customization: Variables for details on the different variables.

Importing modules

[edit]

Now you can choose what modules you want to use; Wikipedia:AutoEd#Modules contains a useful list. You can also create your own modules, as will be described below, although this is slightly more complicated.

For each module that you want to use, add the following text:

importScript('Wikipedia:AutoEd/NAMEOFMODULE.js');

For example, to import UnicodeControlChars, you would add that text and replace "NAMEOFMODULE" with "unicodecontrolchars". If you want to use a module that isn't a subpage of Wikipedia:AutoEd (such as those created in your userspace), replace all of the text between the two apostrophes with the name of the page where the module is located.

Defining the main function

[edit]

One JavaScript "function" needs to be defined for the script to work: autoEdFunctions(). This actually uses the imported modules and allows the script to know what changes need to be made. To create this function, add the following text:

function autoEdFunctions() { //Activates individual modules when "auto ed" tab is clicked
    var txt = document.editform.wpTextbox1;

This starts the function and also creates a variable ("txt") which contains the entire text of the on-screen edit box.

Next you need to add the following text for each module that you imported:

    txt.value = FUNCTIONNAME(txt.value);

For each module, you then need to open up the module's description page and look at the name of the function used there. Usually this is located at the top of the module's description, although sometimes it is further down. It should look like a list of various code. Replace FUNCTIONNAME with that function's name. For example, in Wikipedia:AutoEd/unicodecontrolchars.js, you see that the "main function" is titled "autoEdUnicodeControlChars", so you replace "FUNCTIONNAME" with "autoEdUnicodeControlChars" for that line. The next module that you use in our example is Wikipedia:AutoEd/wikilinks.js. You open up that module description page and see two functions: TurnFirstToLower and autoEdWikilinks. The first of these doesn't look very list-like and also isn't marked as a "main function", so you use "autoEdWikilinks" to replace "FUNCTIONNAME".

Finally, you need to "close" the function. To do so, just adding the following text:

}

Note: If you are creating the script somewhere other than in your userspace, also add the following after everything else.

//</syntaxhighlight>

Need help?

[edit]

If this is a bit too confusing, please feel free to ask for help or clarification at Wikipedia talk:AutoEd, and one of the script's maintainers should be able to help you out. Alternatively, you can look at the code used in presets to see their format, which should be pretty similar to what you create here. One preset which contains everything discussed here, including variables different from the defaults, can be seen at Wikipedia:AutoEd/wikichecker.js. Looking at that code may be able to help you figure out how to write yours.