User:Inductiveload/maintain

Maintain.js

This script is a framework for tools that can automate some actions and avoid having to dig about in an edit box after finding an issue on a page.

It is alpha-grade: expect bugs, use with care In particular, the API for config and adding hook can and probably will change.

There are a few WS-centric tools included, and you can add your own

InstallationEdit

The basic script can be installed by adding the following to your common.js page:

mw.loader.load('//en.wikisource.org/w/index.php?title=User:Inductiveload/maintain/load.js&action=raw&ctype=text/javascript');

This will load:

Maintain actionsEdit

The Maintenance link in the side bar brings up the "Action dialog", where you can choose a pre-set action to take.

Which actions are included depends on the page and what you have configured. Clicking an action will either present more options (e.g. a dropdown for page statuses) or take you directly to the confirmation dialog.

Some actions generate their own summaries. You can always amend the summary at that stage, even if an auto-summary is generated.

ConfigurationEdit

Add a handler to the <nowik>maintain_replace.config</nowiki> hook:

mw.hook( 'maintain_replace.config' ).add( function ( maintain, cfg ) {
    // modify cfg here
} );

The handler is called with two parameters:

  • maintain: contains useful functions for tools
  • cfg: the config object to add your tools to
    • cfg.tools: add tools to this list
    • cfg.noconfirm_tools: add IDs of tools to skip the confirmation step for. Be careful: you are still responsible for the edit.

Adding a toolEdit

Tools are a dict of:

  • label the label to show
  • id a unique ID
  • transform: a function that returns an object with a transformed text field and a summary.
    [].push.apply( cfg.tools, [
        {
            label: '{{' + 'incomplete}}',
            id: 'ws.incomplete',
            transform: function () {
                return maintain.transforms.add_template( false, 'incomplete' );
            }
        }
    ] );

TransformsEdit

The following transforms are included in maintain.transforms:

  • append( suffix, separation, summary )
  • prepend( prefix, separation, summary )
    • summary summary (optional, default is generated from the text if not given)
    • separation how to separate the new content from the existing content (default: \n)
  • add_template( append, template, params, config ): append/prepend a template
    • append: true to append to the page, false to prepend
    • template: the template name
    • params: list of parameters (not a dict!)
    • config: object of config options:
      • summary summary (optional, default is generated from the template name if not given)
      • params_newlines add newline between items (block-style, default is inline-style)
      • sign add a signature: ~~~~
      • separation how to separate the template from the existing content (default: \n)
  • regex_transform( res, summary )
    • res list of [ regex, replacement ] pairs to apply in order
    • summary summary (required)
  • delete_templates( templates, summary ): delete templates (use with caution on nested templates)
    • templates: list of template names
    • summary summary (optional: default is generated from the template name if not given)

ReplaceEdit

A simple replace dialog is included so you can fix typos without having to edit the page and locate the error:

You will be shown the proposed diff before the edit is saved, and you can amend the summary.

If you select text in the mainspace that appears to be transcluded from the page namespace[1], the replacement will be attempted at the source Page namespace page. You should still make sure the edit is correct.

TechnicalEdit

  1. Specifically, it must have been transcluded with the <pages/> tag.