User:Inductiveload/maintain
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
Installation
[edit]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.js: the core framework
- maintain-ws-tools.js: Tools for Wikisource
Maintain actions
[edit]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.
Configuration
[edit]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 listcfg.noconfirm_tools
: add IDs of tools to skip the confirmation step for. Be careful: you are still responsible for the edit.
Adding a tool
[edit]Tools are a dict of:
label
the label to showid
a unique IDtransform
: a function that returns an object with atransformed
text field and asummary
.
[].push.apply( cfg.tools, [
{
label: '{{' + 'incomplete}}',
id: 'ws.incomplete',
transform: function () {
return maintain.transforms.add_template( false, 'incomplete' );
}
}
] );
Transforms
[edit]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 templateappend
: true to append to the page, false to prependtemplate
: the template nameparams
: 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 ordersummary
summary (required)
delete_templates( templates, summary )
: delete templates (use with caution on nested templates)templates
: list of template namessummary
summary (optional: default is generated from the template name if not given)
Replace
[edit]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.
Technical
[edit]- User:Inductiveload/maintain.js
- User:Inductiveload/maintain/load.js
- User:Inductiveload/maintain-ws-tools.js
- Phab Workboard (file bugs here)
- ↑ Specifically, it must have been transcluded with the
<pages/>
tag.