Skip to content

MediaWiki Bots & Automation — Pywikibot, AutoWikiBrowser, and Bot Passwords

DodaTech Updated 2026-06-26 10 min read

In this tutorial, you will learn about MediaWiki Bots & Automation. We cover key concepts, practical examples, and best practices to help you master this topic.

Bots and automation in MediaWiki use scripts to perform repetitive tasks like fixing links, updating templates, and generating reports — leveraging tools like Pywikibot and AutoWikiBrowser with bot passwords for secure API access, the same automation infrastructure that Wikipedia uses for millions of automated edits.

What You'll Learn

  • Setting up a bot account with bot passwords
  • Installing and configuring Pywikibot
  • Writing basic Pywikibot scripts
  • Using AutoWikiBrowser for Windows
  • Creating custom maintenance scripts
  • Best practices for responsible bot operation

Why It Matters

Manual wiki maintenance does not scale. If you have 500 pages that need a template updated, doing it by hand takes hours and is error-prone. A bot does it in seconds with perfect accuracy. Bots handle repetitive tasks: fixing broken links, updating date stamps, migrating template syntax, generating reports, and cleaning up categories. Every large wiki relies on bots to stay maintainable.

Real-World Use

A DodaTech wiki has 2,000 documentation pages. Each page includes a footer template with the current year. Every January, a bot updates the copyright year on all 2,000 pages in under 2 minutes. Another bot runs weekly to find broken external links and report them. A third bot generates a "Most Viewed Pages" report every Monday morning.

Learning Path

flowchart LR
  A["21: User Rights"] --> B["22: Email & Notifications"]
  B --> C["23: Bots & Automation"]
  C:::current
  D["24: User Preferences"]
  E["25: Extension Installation"]
  F["26: Semantic MediaWiki"]

  C --> D --> E --> F

  classDef current fill#38bdf8,color#0f172a,stroke-width:2px

Step 1: Create a Bot Account

A bot should have its own user account, separate from your personal account.

  1. Register a new account: "DodaBot"
  2. Go to Special:BotPasswords while logged in as DodaBot
  3. Click "Create a new bot password"
  4. Name it "Pywikibot"
  5. Select the grants the bot needs (e.g., "Edit existing pages," "Create new pages," "Read pages")
  6. Click "Create"

MediaWiki generates a password like DodaBot@Pywikibot with a long random string. Save this securely — it is shown only once.

Why Bot Passwords?

Bot passwords are separate from the account password. They have limited grants, so even if the bot password is compromised, the main account is safe. You can create multiple bot passwords for different scripts, each with different permissions.

Step 2: Install Pywikibot

Pywikibot is the most popular Python framework for MediaWiki automation.

# Clone the repository
git clone --recursive https://gerrit.wikimedia.org/r/pywikibot/core.git pywikibot
cd pywikibot

# Install dependencies
python3 -m pip install -r requirements.txt

Configure Pywikibot

Create a user-config.py file in the pywikibot directory:

# -*- coding: utf-8 -*-
family = 'dodatech'
mylang = 'en'

# Wiki connection details
usernames['dodatech']['en'] = 'DodaBot'

# Bot password authentication
authenticate['yourwiki.dodatech.com'] = 'DodaBot@Pywikibot'

If your wiki is not in Pywikibot's family list, create a custom family file:

# families/dodatech_family.py
from pywikibot import family

class Family(family.Family):
    name = 'dodatech'
    langs = {
        'en': 'yourwiki.dodatech.com',
    }

    def scriptpath(self, code):
        return '/w'

    def protocol(self, code):
        return 'https'

Step 3: Basic Pywikibot Scripts

Script 1: Replace Text on a Page

#!/usr/bin/env python3
import pywikibot

site = pywikibot.Site()
page = pywikibot.Page(site, 'DodaBrowser')
text = page.text

# Replace old text with new text
text = text.replace('old version 1.0', 'new version 2.0')

page.text = text
page.save('Updated version number from 1.0 to 2.0')

Save this as update_version.py and run:

python3 update_version.py

The script loads the page, replaces the text, and saves with the given edit summary. Pywikibot handles login, token management, and error handling automatically.

Script 2: Batch Edit All Pages in a Category

#!/usr/bin/env python3
import pywikibot
from pywikibot import pagegenerators

site = pywikibot.Site()
category = pywikibot.Category(site, 'Installation Guides')

# Get all pages in the category
generator = pagegenerators.CategorizedPageGenerator(category)

for page in generator:
    text = page.text
    if '{{Stub}}' in text:
        text = text.replace('{{Stub}}', '{{Stub|needs=installation steps}}')
        page.text = text
        page.save('Updated stub template with reason')
        print(f'Updated: {page.title()}')

This script finds every page in "Installation Guides," checks if it has a {{Stub}} template, and updates it with an extended version.

Script 3: Generate a Site Report

#!/usr/bin/env python3
import pywikibot

site = pywikibot.Site()

# Count pages by namespace
ns_counts = {}
for ns in site.namespaces():
    count = site.nsindex(ns.id)
    ns_counts[ns.id] = count

# Print report
print('=== Wiki Statistics Report ===')
print(f'Generated: {pywikibot.Timestamp.now()}')
print()
for ns_id, count in sorted(ns_counts.items()):
    if count > 0:
        ns_name = site.namespace(ns_id)
        print(f'{ns_name}: {count} pages')

Run this as a cron job to email the report weekly.

Step 4: AutoWikiBrowser (Windows)

AutoWikiBrowser (AWB) is a Windows desktop application for wiki automation. It provides a graphical interface for common tasks.

Installing AWB

  1. Download from https://en.wikipedia.org/wiki/Wikipedia:AutoWikiBrowser
  2. Extract the ZIP file
  3. Run AutoWikiBrowser.exe

Configuring AWB

  1. Enter your wiki URL and bot credentials
  2. Set the bot username and bot password
  3. Configure the edit summary prefix
  4. Enable "Check for errors" for safety

Common AWB Tasks

  • Find and replace: Regex-based text replacement across multiple pages
  • Fix redirects: Update double redirects
  • Category changes: Move pages between categories
  • Template substitution: Replace template calls with substituted content
  • Genfixes: Apply standard formatting fixes

Safety Features

AWB includes multiple safety mechanisms:

  • Edit rate limiter: Slows down edits to avoid flooding RecentChanges
  • Preview mode: Shows what changes will look like before saving
  • Edit filter: Skip pages matching certain patterns
  • Revert protection: Avoid editing pages you already edited in a session

Step 5: API-Based Automation

For simple tasks, use the MediaWiki API directly with Python's requests library:

import requests

API_URL = 'https://yourwiki.dodatech.com/api.php'

def edit_page(title, text, summary, bot_password):
    # Step 1: Log in
    session = requests.Session()
    login_params = {
        'action': 'login',
        'lgname': 'DodaBot',
        'lgpassword': bot_password,
        'format': 'json',
    }
    session.post(API_URL, data=login_params)

    # Step 2: Get edit token
    token_params = {
        'action': 'query',
        'meta': 'tokens',
        'type': 'csrf',
        'format': 'json',
    }
    token_response = session.get(API_URL, params=token_params)
    token = token_response.json()['query']['tokens']['csrftoken']

    # Step 3: Edit the page
    edit_params = {
        'action': 'edit',
        'title': title,
        'text': text,
        'summary': summary,
        'token': token,
        'bot': 'true',
        'format': 'json',
    }
    response = session.post(API_URL, data=edit_params)
    return response.json()

# Usage
edit_page(
    'DodaBrowser',
    'This is the updated content.',
    'Bot: Updated content',
    'DodaBot@Pywikibot-password'
)

This approach is useful when you only need basic operations without the full Pywikibot dependency.

Step 6: Responsible Bot Operation

Bot Flag

Always ensure your bot account has the bot permission. Bot edits are hidden from RecentChanges by default, preventing the wiki's activity feed from being overwhelmed.

Edit Rate

Limit your bot's edit rate. A bot making 60 edits per minute floods RecentChanges for human patrollers. Add delays:

import time

for page in pages:
    # Edit the page
    page.save('Bot: Updating template')
    # Wait 2 seconds between edits
    time.sleep(2)

Editing Guidelines

  • Always use a descriptive edit summary: "Bot: Updated copyright year to 2026" not "Updated"
  • Avoid editing pages with recent human edits: Skip pages edited by humans in the last 24 hours
  • Test on a small batch first: Run your bot on 5 pages before letting it run on 500
  • Monitor the results: Check a sample of bot edits after each run
  • Have a kill switch: Know how to block the bot account if it malfunctions

Step 7: Scheduling Bot Tasks

Use cron (Linux) or Task Scheduler (Windows) to run bots on a schedule.

Cron Example (Linux)

# Run weekly report every Monday at 8 AM
0 8 * * 1 /usr/bin/python3 /home/dodatech/bots/weekly_report.py

# Run copyright update every January 1 at 12 AM
0 0 1 1 * /usr/bin/python3 /home/dodatech/bots/update_copyright.py

# Run link checker every Sunday at 6 AM
0 6 * * 0 /usr/bin/python3 /home/dodatech/bots/check_links.py

Log output to a file so you can verify the bot runs successfully.

What You Learned

  • Bot accounts use bot passwords for secure API authentication
  • Pywikibot is the primary Python framework for MediaWiki automation
  • AutoWikiBrowser provides a GUI for Windows users
  • The MediaWiki API can be used directly with Python requests
  • Responsible bot operation requires Rate Limiting and descriptive summaries
  • Cron and Task Scheduler automate bot scheduling

In the next lesson, you'll learn about user preferences and skins.

Common Mistakes

Mistake Why It Happens How to Fix
Bot edits appear in RecentChanges despite bot flag Bot account not added to bot group Add the bot account to the bot group via Special:UserRights. The bot permission flag hides edits from the default RecentChanges view.
Bot password authentication fails Wrong bot password name or password Verify the bot password format: "Username@BotName" not "Username". Regenerate the password if lost.
Pywikibot cannot connect to the wiki Incorrect family or URL configuration Check user-config.py for the correct wiki URL and script path. Test with a simple connection script first.
Bot edit rate triggers rate limiting Edits are too fast Add sleep intervals between edits. Pywikibot has built-in rate limiting. Enable it with pywikibot.config.put_throttle = 2.
Bot edits are reverted by human editors Bot made incorrect changes Test on a subset first. Run in preview mode. Include a rollback plan (revert all bot edits if needed).

Practice Questions

  1. What is the difference between a bot password and a regular account password?
  2. Write a Pywikibot script that finds all pages containing "http://olddomain.com" and replaces it with "https://newdomain.com".
  3. What safety measures should a bot implement before editing a large number of pages?
  4. Challenge: Build a complete bot system. Create a bot account with a bot password. Install Pywikibot and configure it for your wiki. Write a script that does the following: (a) finds all pages in the "Needs Update" category, (b) appends a "Last reviewed" notice to each page, (c) removes the page from "Needs Update" and adds it to "Reviewed," (d) limits edits to 10 per minute, (e) logs all changes to a file. Schedule the script to run weekly using cron or Task Scheduler. Verify the bot ran correctly by checking a sample of the edited pages.

FAQ

Can I run multiple bots simultaneously?

Yes, but each bot should have its own bot account with its own bot password. Running multiple bots from the same account can cause conflicts and makes it harder to track which bot did what.

What programming languages can I use for bot development?

Python (Pywikibot) is the most common. You can also use PHP, JavaScript (Node.js), or any language that can make HTTP requests. The MediaWiki API is language-agnostic.

How do I prevent my bot from editing protected pages?

Check page protection status before editing. In Pywikibot, use page.protection() to check protection levels. Skip pages where you lack edit permission.

What happens if my bot gets stuck in an infinite loop?

Block the bot account immediately via Special:Block. Then fix the script and unblock. Always include a maximum iteration count in your scripts to prevent infinite loops.

Can a bot edit pages with VisualEditor?

No. Bots must use the wikitext API. VisualEditor is a human interface only. All bot edits are made via the action API, which uses wikitext.

Mini Project

Goal: Build a complete bot automation system for routine wiki maintenance.

  1. Create a bot account "MaintenanceBot" on your wiki
  2. Generate a bot password with "Edit existing pages" and "Read pages" grants
  3. Install Pywikibot and configure it for your wiki
  4. Write a Python script that:
    • Finds all uncategorized pages using the API
    • Adds a "Needs Category" template to each
    • Adds the page to a "Uncategorized" hidden category
    • Limits edits to 6 per minute
    • Logs all changes to a file
  5. Test the script on a small batch of 3 test pages
  6. Run the script on all uncategorized pages
  7. Verify the results on a sample of pages
  8. Schedule the script to run daily at 2 AM

What's Next

Bots handle the repetitive work. Now let's look at personalized user experiences with preferences and skins.

Continue to Lesson 24: User Preferences & Skins — learn how users customize their experience with preferences, custom CSS, and skin selection.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro