GitHub - Pathoschild/Wikimedia-contrib: A collection of user scripts and Tool Labs tools intended for users of Wikimedia Foundation wikis.

GitHub

5 min read Original article ↗

Wikimedia-contrib is a collection of user scripts and Toolforge tools intended for users of Wikimedia Foundation wikis.

Tools

Toolforge is part of the Wikimedia Cloud infrastructure hosted by the Wikimedia Foundation for community-developed tools and bots. These tools provide analysis and data to support wiki editors and functionaries.

  • Account Eligibility analyzes a user account to determine whether it's eligible to vote in the specified event.
  • Category Analysis analyzes edits to pages in the category tree rooted at the specified category (or pages rooted at a prefix). This is primarily intended for test project analysis by the Wikimedia Foundation language committee.
  • Crosswiki Activity measures a user's latest edit, bureaucrat, or sysop activity across all wikis.
  • Global Groups shows a live review of extra permissions assigned to global groups on Wikimedia Foundation wikis.
  • Global User Search searches and filters global users on Wikimedia wikis.
  • Magic Redirect redirects to an arbitrary URL with tokens based on user and wiki filled in. This is primarily intended for Wikimedia templates (see example).
  • Stalktoy shows global details about a user across all Wikimedia wikis. You can provide an account name (like Pathoschild), an IPv4 address (like 127.0.0.1), an IPv6 address (like 2001:db8:1234::), or a CIDR block (like 212.75.0.1/16 or 2600:3C00::/48).
  • Stewardry estimates which users in a group are available based on their last edit or action.
  • Synchbot synchronises user pages across Wikimedia projects in every language. This allows users to create user pages on every wiki, or to have global JavaScript and CSS. (Due to the potential for misuse, this bot is not open-source.)
  • User Pages shows a user's pages on all wikis (or finds wikis where they don't have user pages).

User scripts

These user scripts extend the wiki interface seen by a user, and they're sometimes available to all users as gadgets (particularly TemplateScript). See Gadget kitchen for an introduction to user scripts & gadgets.

  • ForceLTR enforces left-to-right layout and editing on right-to-left wikis. This resolves editing glitches in many browsers when one's preferred language is left-to-right, and corrects display when the interface language is not right-to-left.
  • StewardScript extends the user interface for Wikimedia stewards' convenience. It extends the sidebar (with links to steward pages), Special:Block (with links to stalktoy and Special:CentralAuth if preloaded with a target), Special:CentralAuth (with links to external tools, one-click status selection, a preselected template reason, and convenient links in the 'local accounts' list), global renaming and Special:UserRights (with template summaries).
  • TemplateScript adds a menu of configurable templates and scripts to the sidebar. It automatically handles templates for various forms (from editing to protection), edit summaries, auto-submission, and filtering which templates are shown based on namespace, form, or arbitrary conditions. Templates can be inserted at the cursor position or at a preconfigured position, and scripts can be invoked when a sidebar link is activated. TemplateScript is also used as a framework for other scripts, and includes a fully-featured regex editor.
  • UseJS imports JavaScript for the current page when the URL contains a parameter like &usejs=MediaWiki:Common.js. It only accepts scripts in the protected MediaWiki: namespace.

Deploy to Toolforge

Tool accounts

Each tool has its own account, with a subdomain matching its folder name. For example, Stalktoy is at stalktoy.toolforge.org.

To deploy a tool from scratch:

  1. Connect to Toolforge via SSH.
  2. Run this script (editing the # configure section as needed):
    # configure
    become stalktoy
    toolName=stalktoy
    
    # add required folders
    mkdir -p bin cache logs public_html
    
    # add tool files
    git clone https://github.com/Pathoschild/Wikimedia-contrib.git git/wikimedia-contrib
    ln -s git/wikimedia-contrib/tool-labs/.lighttpd.conf .lighttpd.conf
    ln -s git/wikimedia-contrib/tool-labs/backend public_html/backend --relative
    ln -s git/wikimedia-contrib/tool-labs/content public_html/content --relative
    ln -s git/wikimedia-contrib/tool-labs/$toolName public_html/tool --relative
    cp /usr/bin/kubectl bin/kubectl # scheduled jobs (jobs.yaml) can only access home folder
    
    # launch server
    toolforge webservice php8.2 start --cpu 2 --mem 2Gi
    
    # start scheduled jobs (e.g. log rotation)
    toolforge jobs load ~/git/wikimedia-contrib/tool-labs/_scheduledJobs/jobs.yaml

To deploy an update:

  1. Connect to Toolforge via SSH.
  2. Run this script (editing the # configure section as needed):
    # configure
    become stalktoy
    
    # update tool
    git -C git/wikimedia-contrib pull
    cp --update /usr/bin/kubectl bin/kubectl
    
    # (optional) update jobs if they changed
    toolforge jobs load ~/git/wikimedia-contrib/tool-labs/_scheduledJobs/jobs.yaml
    
    # (optional) restart service to bypass caching, or if .lighttpd.conf changed
    webservice restart

User scripts

The user scripts are deployed to the shared meta account, and made available through the Toolforge static CDN (via https://tools-static.wmflabs.org/meta/scripts/*.js).

To deploy the meta account from scratch:

  1. Connect to Toolforge via SSH.
  2. Run this script:
    # switch to the project
    become meta
    
    # add required folders
    mkdir -p bin logs
    
    ## add tool files
    git clone https://github.com/Pathoschild/Wikimedia-contrib.git git/wikimedia-contrib
    ln -s git/wikimedia-contrib/tool-labs/.lighttpd.conf .lighttpd.conf
    cp /usr/bin/kubectl bin/kubectl # scheduled jobs (jobs.yaml) can only access home folder
    
    # set up script CDN
    mkdir -p www/static
    ln -s git/wikimedia-contrib/user-scripts www/static/scripts --relative
    
    ## launch server
    toolforge webservice php8.2 start --cpu 2 --mem 2Gi
    
    ## start scheduled jobs (e.g. log rotation)
    toolforge jobs load ~/git/wikimedia-contrib/tool-labs/_scheduledJobs/jobs.yaml

To deploy an update, follow the same process as other tools.

Legacy redirects

The tools were previously hosted in three shared tool accounts (meta, meta2, and meta3). These still exist to redirect requests to the new per-tool accounts.

To deploy meta, see user scripts above.

To deploy meta2 or meta3 from scratch:

  1. Connect to Toolforge via SSH.
  2. Run this script (editing the # configure section as needed):
    # switch to the project
    become meta2
    
    ## set up tool files
    git clone https://github.com/Pathoschild/Wikimedia-contrib.git git/wikimedia-contrib
    mkdir -p bin logs public_html
    ln -s git/wikimedia-contrib/tool-labs/.lighttpd.conf .lighttpd.conf
    cp /usr/bin/kubectl bin/kubectl # scheduled jobs (jobs.yaml) can only access home folder
    
    ## launch server
    toolforge webservice php8.2 start --cpu 2 --mem 2Gi
    
    ## start scheduled jobs (e.g. log rotation)
    toolforge jobs load ~/git/wikimedia-contrib/tool-labs/_scheduledJobs/jobs.yaml

To deploy an update, follow the same process as other tools.

Web logs

With the above setup, these logs are created automatically on each tool account:

  • ~/error.log logs Lighttpd errors (enabled by default).
  • ~/logs/access.log logs each incoming request via Lighttpd (configured via ~/.lighttpd.conf).
  • ~/logs/rotate-logs.out + ~/logs/rotate-logs.err logs output from the log rotation job.

The log files are rotated daily, with one week of backups in ~/logs.