Saintapedia:Bots

From Saintapedia
Jump to navigation Jump to search

MediaWiki bots are automated or semi-automated tools designed to interact with a MediaWiki-based website (like Wikipedia, Wiktionary, or a private corporate wiki) to perform repetitive, high-volume tasks that would be tedious or impossible for a human to do manually.

Think of them as the janitors and librarians of the wiki world.

How They Work

Unlike a human who uses a web browser to click "Edit," bots typically interact directly with the MediaWiki Action API.

  • API Interaction: The bot sends HTTP requests to the wiki's API (e.g., api.php). It can "query" data (get page content, list categories) or "edit" data (submit changes, delete pages).
  • Bot Accounts: Most wikis require bots to have a dedicated user account (e.g., User:CleanupBot). These accounts are often granted a special "Bot" flag.
  • The "Bot" Flag: This is a crucial technical feature. When an account has this flag, its edits are hidden by default from the Recent Changes feed. This prevents thousands of minor bot edits from drowning out the work of human editors.

Common Bot Tasks

Bots are used for tasks that follow clear rules and patterns. If a task requires nuanced "human" judgment (like deciding if a poem is good), a bot is usually a poor choice.

  • Maintenance: Fixing "double redirects" (when Page A points to Page B, which points to Page C), adding templates to pages, or fixing broken links.
  • Categorization: Automatically moving pages into the correct categories based on their content or templates.
  • Anti-Spam & Vandalism: Reverting obvious "test" edits or blocking known spam URLs within seconds of the edit being made.
  • Data Migration: Importing thousands of entries from an external database (like a government census) into the wiki format.
  • Archiving: Moving old discussions on talk pages to archive sub-pages to keep the main page readable.

Popular Frameworks

You don't have to write a bot from scratch. Most developers use existing libraries that handle the "heavy lifting" of logging in and managing API tokens.

Framework Language Notes
Pywikibot Python The most popular and powerful framework; used by most Wikipedia bots.
mwn JavaScript/Node Great for modern web developers; supports TypeScript.
mwclient Python A lighter, more "Pythonic" alternative to Pywikibot.
MediaWiki-Bot PHP Often used for tools that run directly on the server hosting the wiki.

The "Social Contract" (Policy)

On large public wikis like Wikipedia, you can't just unleash a bot. There is a strict governance process:

  1. Request for Approval (BRFA): The operator must explain what the bot will do and why it’s useful.
  2. Trial Period: The bot runs for a few days (e.g., 50 edits) while the community watches for bugs.
  3. Operator Responsibility: If the bot breaks and "vandalizes" 10,000 pages, the human operator is responsible for fixing it.
  4. Rate Limiting: Bots are expected to "breathe" (e.g., wait 5–10 seconds between edits) to avoid overloading the server.

Helpful vs. Malicious Bots

It is important to distinguish between MediaWiki Bots (tools sanctioned by the wiki) and Malicious Crawlers.

  • Helpful Bots: Log in, respect robots.txt, and identify themselves on their user page.
  • Malicious Crawlers: Scrape content without permission, ignore rate limits, and often try to find security vulnerabilities or post spam.

Pro Tip: If you're building your first bot, start with Pywikibot. It has a "Simulation" mode (Dry Run) that lets you see what the bot would have done without actually making any changes to the wiki.