This is an information page. It is not one of Bharatpedia's policies or guidelines, but rather intends to describe some aspect(s) of Bharatpedia's norms, customs, technicalities, or practices. It may reflect varying levels of consensus and vetting. |
| Warning: You take full responsibility for any action you perform using any user script. You must understand Bharatpedia policies and use this tool within these policies, or risk being blocked from editing. |
User scripts are programs written in JavaScript that can be used to customize and enhance editing and other tasks on Bharatpedia. User scripts can add functions or tools that are not available by default, helping users perform repetitive or specialized tasks more efficiently.
Many user scripts may be available for users to install. Users can also create their own scripts, either by modifying an existing script or by writing one from scratch.
Security[edit source]
User scripts run in the user's web browser and can interact with the Bharatpedia interface using the permissions available to the logged-in user. This means that a user script may be capable of performing actions on Bharatpedia on the user's behalf.
Unlike applications that use controlled authentication mechanisms such as OAuth or bot passwords, a user script generally operates within the user's browser session. Depending on what the script is designed to do, it may be able to read or modify information that the user could access or modify manually.
Users should therefore install scripts only when they understand and trust their source. This is particularly important for users with advanced permissions or access to sensitive administrative functions.
Users are responsible for actions performed through their account, including actions initiated by a user script. If a script is imported from another user's script page, the source user may change the script at any time. Users should periodically review imported scripts and remove any that they no longer trust or need.
List of user scripts[edit source]
If you create or discover a useful Bharatpedia user script, consider adding it to the Bharatpedia user scripts list so that other users can find it.
To add a script, provide at least:
- the name of the script;
- the page containing its JavaScript code; and
- a short description of what the script does.
If documentation is available, a link to the documentation page should also be provided.
For example:
{{User script table row
|name=My script
|code=User:Example/MyJSpage.js
|doc=User:Example/MyJSdocumentationPage
|desc=This script performs a useful editing task.
}}
The exact template parameters may vary depending on the user-script listing system used on Bharatpedia.
Searching for user scripts[edit source]
If you cannot find a script that performs a particular task, you can search existing user scripts or request that a new script be developed.
You can search within the source code of JavaScript user scripts using Bharatpedia's search function.
You can also search for user scripts by their page title:
Installation[edit source]
Automatic installation[edit source]
If Bharatpedia provides a user-script installation gadget, users can enable it through their preferences and then install supported scripts directly from the user-script list.
- Open your user preferences and enable the user-script installation option, if available.
- Visit the Bharatpedia user scripts list.
- Select Install next to the script you want to use.
- Follow any additional instructions provided by the script's documentation.
Not all scripts can necessarily be installed automatically. Some scripts may require manual installation or additional configuration.
Manual installation[edit source]
For scripts hosted on Bharatpedia, user scripts can generally be loaded through the user's JavaScript configuration pages.
- Make sure you are logged in. User scripts are available only to logged-in users.
- Open your common.js page.
- Add the appropriate script-loading code.
- Save the page.
- Purge your cache or bypass your browser cache if necessary.
For example, a script located at:
User:Example/MyScript.jsmay be loaded using:
mw.loader.load( '/w/index.php?title=User:Example/MyScript.js&action=raw&ctype=text/javascript' );The exact loading method may depend on Bharatpedia's configuration and the location of the script.
Users should follow the installation instructions provided by the script's documentation where available.
Remote scripts[edit source]
A user may also load a script hosted on another MediaWiki installation. However, remote scripts should be used with caution.
A script written for another wiki may depend on features, extensions, namespaces, URLs, configuration settings, or templates that do not exist on Bharatpedia. As a result, a script that works on another wiki may not work correctly on Bharatpedia.
Remote scripts can also introduce security and maintenance risks. Users should install remote scripts only when they trust the source and understand what the script does.
For example, a remote JavaScript file may be loaded using:
mw.loader.load( 'https://example.org/path/to/script.js' );The remote server must permit the script to be loaded by the browser, and the script must be compatible with Bharatpedia.
If a remote script is also copied into a user's local JavaScript configuration, the same script may be loaded more than once. This can cause errors or unexpected behaviour.
Troubleshooting user scripts[edit source]
If a user script causes problems, first determine whether the problem is caused by the script or by another part of the site.
The following steps may help:
- Purge the Bharatpedia page cache.
- Clear or bypass your browser cache.
- Temporarily disable recently installed user scripts.
- Check the script's documentation for known problems or required dependencies.
- Check whether the problem occurs when the script is disabled.
- If the problem continues, report the issue to the script's author or through the appropriate Bharatpedia support channel.
If a script significantly interferes with the site, users may be able to temporarily disable user scripts by using Bharatpedia's safe mode, if enabled by the site.
For example, a safe-mode URL may use:
?safemode=1For a page whose URL already contains query parameters, the safe-mode parameter can be added with &safemode=1.
The exact availability and behaviour of safe mode depends on Bharatpedia's MediaWiki configuration.
User scripts generally do not run on certain system pages, including user preference pages, allowing users to access their account settings even when a faulty script is causing problems elsewhere.
Writing user scripts[edit source]
Users familiar with JavaScript can create their own user scripts.
A user script can be as simple as a small modification to the editing interface or as complex as a tool that performs multiple editing or maintenance tasks.
Before writing a script, users should become familiar with:
- JavaScript;
- the MediaWiki JavaScript API;
- the MediaWiki ResourceLoader;
- Bharatpedia's configuration and available extensions; and
- the permissions and limitations that apply to automated actions.
Scripts should be designed carefully, particularly when they make edits automatically or perform actions repeatedly.
Developing a user script[edit source]
A typical user script is stored as a JavaScript page in the user's namespace, for example:
User:Example/MyScript.jsThe script can then be loaded through the user's common.js file or another appropriate JavaScript configuration page.
A script should include documentation explaining its purpose, installation method, configuration options, dependencies, and known limitations.
Scripts that make edits or other changes automatically should also provide appropriate safeguards to prevent accidental or unintended actions.
Code snippets[edit source]
Common JavaScript and MediaWiki code snippets can be useful when developing user scripts. Developers should verify that older examples remain compatible with the current version of MediaWiki and Bharatpedia before using them.
User script developers[edit source]
Users who create user scripts may identify themselves as user-script developers on their user pages using an appropriate userbox, if Bharatpedia provides one.
For example:
{{user script developer}}The availability of particular userboxes depends on Bharatpedia's templates and configuration.
See also[edit source]
- Help:JavaScript – information about JavaScript on Bharatpedia
- Help:Editing – general information about editing Bharatpedia
- Help:Automated editing – information about automated editing
- Your common.js – your personal JavaScript configuration
- User preferences
- MediaWiki ResourceLoader – MediaWiki's JavaScript loading system