npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mwn

v2.0.4

Published

JavaScript & TypeScript MediaWiki bot framework for Node.js

Downloads

9,060

Readme

mwn

Node.js CI CodeQL NPM version Coverage Status PRs Welcome

Quick links: Getting StartedGitHubNPMUser DocumentationAPI Documentation

Mwn is a modern and comprehensive MediaWiki bot framework for Node.js, originally adapted from mwbot.

Mwn works with both JavaScript and TypeScript. It is created with a design philosophy of allowing bot developers to easily and quickly write bot code, without having to deal with the MediaWiki API complications and idiosyncrasies such as logins, tokens, maxlag, query continuations and error handling. Making raw API calls is also supported for complete flexibility. Mwn uses JSON with formatversion 2 by default. The axios library is used for HTTP requests.

This library provides TypeScript type definitions for all its functions, as well as for MediaWiki API request objects (MW core + several extensions). API responses are also typed for the common operations.

This library uses mocha and chai for tests, and has extensive test coverage. Testing is automated using a CI workflow on GitHub Actions.

To install, run npm install mwn.

Download stats

Documentation

Up-to-date documentation is hosted on Toolforge.

API documentation (automatically generated via typedoc) is also available at https://mwn.toolforge.org/docs/api.

Features

  • Handling multiple users and wikis: Mwn can seamlessly work with multiple bot users signed into the same wiki, and multiple wikis at the same time. You just have to create multiple bot instances – each one representing a wiki + user. Each bot instance uses an isolated cookie jar; all settings are also isolated.

  • Token handling: Tokens are automatically fetched as part of mwn.init() or bot.login() or bot.getTokensAndSiteInfo(). Once retrieved, they are stored in the bot state and can be reused any number of times. If any API request fails due to an expired or missing token, the request is automatically retried after fetching a new token. bot.getTokens() can be used to refresh the token cache, though mwn manages this, so you'd never need to explicitly use that.

  • Maxlag: The default maxlag parameter used by mwn is 5 seconds. Requests failing due to maxlag will be automatically retried after pausing for the duration specified in the Retry-After header of the response (or a configurable retryPause – default 5 seconds, if there's no such header). A maximum of maxRetries will take place (default 3).

  • Retries: Mwn automatically retries failing requests bot.options.maxRetries times (default: 3). This is useful in case of connectivity resets and the like. As for errors raised by the API itself, note that MediaWiki generally handles these at the response level rather than the protocol level (they still emit a 200 OK response). Mwn will attempt retries for these errors based on the error code. For instance, if the error is readonly or maxlag , retry is done after a delay. If it's assertuserfailed or assertbotfailed (indicates a session loss), mwn will try to log in again and then retry. If it's badtoken, retry is done after fetching a fresh edit token.

  • Handling query continuation: Mwn uses asynchronous generators, (for await...of loops) to provide a very intuitive interface around MediaWiki API's query continuation. See Handling query continuation.

  • Parsing wikitext: Mwn provides methods for common wikitext parsing needs (templates, links, and simple tables).

  • Titles: Work with page titles with the very same API as the in-browser mw.Title that userscript/gadget developers are familiar with.

  • Emergency shutoff

  • Bot exclusion compliance

  • Batch operations: Perform a large number of tasks (like page edits) with control over the concurrency (default 5). Failing actions can be set to automatically retry.

Compatibility

Mwn is currently compatible with Node.js v10 and above. In the future, compatibility with EOL Node versions may be dropped.

As for MediaWiki support, the CI pipelines only check for compatibility with the latest LTS version. But it should work fine with version 1.35 and above.

Contributing

Patches are very much welcome. See https://mwn.toolforge.org/docs/developing for instructions.

Licensing

Mwn is released under GNU Lesser General Public License (LGPL) v3.0, since it borrows quite a bit of code from MediaWiki core (GPL v2). LGPL is a more permissive variant of GNU GPL. Unlike GPL, it enables this library to be used in software not released under GPL-compatible licenses, and even in proprietary software. However, any derivatives of this library should be released under an GPL-compatible license (like LGPL). That being said, this is not legal advice.