Skip to main content

mediawiki-abusefilter

CI Documentation status PyPI Python License Latest Release

Python client for working with MediaWiki AbuseFilters.

It provides a simple interface for listing, searching, creating, editing, and reviewing filters from Python.

Installation

pip install mediawiki-abusefilter

Quick start

import mediawiki_abusefilter as mwaf

filters = mwaf.filters(
    "https://example.org",
    username="Username",
    password="PASSWORD"
)

filter = filters.get(123)

print(filter.description)
print(filter.rules)

The authentication object can also be created separately and reused:

auth = mwaf.auth(
    "https://example.org",
    username="Username",
    password="PASSWORD"
)

filters = mwaf.filters("https://example.org", auth=auth)

Listing filters

filters.list()

Filters can be narrowed by status and visibility:

filters.list(enabled=True)
filters.list(public=True)
filters.list(private=True)

To search by text:

matches = filters.search("spam")

Large result sets can be limited with limit:

filters.list(limit=100)
filters.search("spam", limit=20)

Creating a filter

filter = filters.create(
    "Low edit count edits",
    "page_namespace == 0 & user_editcount < 10"
)

Filters can also be created with notes, actions, and other options:

filter = filters.create(
    "Example filter",
    "page_namespace == 0",
    notes="Created for testing",
    enabled=False,
    public=False,
    actions={
        "warn": "abusefilter-warning",
        "tag": ["review", "test"]
    }
)

Use dry_run=True to preview a new filter without saving it:

change = filters.create(
    "Example filter",
    "page_namespace == 0",
    dry_run=True
)

print(change)

Editing a filter

Get the filter and change only the values you need:

filter = filters.get(123)

filter.edit(description="Updated description")
filter.edit(enabled=False)
filter.edit(public=False)

Values that are not supplied are left unchanged.

Several changes can be made together:

filter.edit(
    description="Updated filter",
    rules="page_namespace == 0 & user_editcount < 20",
    enabled=True,
    public=True,
    actions={"warn": "abusefilter-warning"}
)

Notes

Notes are appended by default:

filter.edit(notes="Changed the edit-count limit")

To replace the existing notes:

filter.edit(
    notes="Updated notes",
    notes_mode="replace"
)

To clear the notes:

filter.edit(
    notes="",
    notes_mode="replace"
)

Notes can also include the current account and date:

filter.edit(
    notes="Changed the rule",
    sign_notes=True
)

Rule changes

Replace the complete rule:

filter.edit(
    rules="page_namespace == 0"
)

Or modify part of the existing rule:

filter.edit(replace=("old text", "new text"))
filter.edit(append=" & user_editcount < 20")
filter.edit(prepend="page_namespace == 0 & ")
filter.edit(remove=" & page_namespace == 1")
filter.edit(regex=(r"user_editcount\s*<\s*10", "user_editcount < 20"))

Replacement operations are strict by default. Use strict=False when a missing match should not raise an error:

filter.edit(
    replace=("old text", "new text"),
    strict=False
)

Actions

Actions can be configured when creating or editing a filter:

filter.edit(
    actions={
        "warn": "abusefilter-warning",
        "disallow": "abusefilter-disallowed",
        "blockautopromote": True,
        "block": {
            "talk": True,
            "anonymous": "1 day",
            "user": "1 day"
        },
        "tag": ["review", "bot"],
        "throttle": {
            "count": 5,
            "period": 120,
            "groups": "user"
        }
    }
)

Set an action to False to remove it:

filter.edit(
    actions={
        "warn": False,
        "tag": False
    }
)

History

Filter history is available through history():

for entry in filter.history(limit=20):
    print(
        entry["id"],
        entry["user"],
        entry["description"]
    )

Previewing changes

Use dry_run=True to inspect a change before applying it:

change = filter.edit(
    description="Preview only",
    rules="page_namespace == 0",
    dry_run=True
)

print(change)

Changes made through edit() and create() are verified by default.

Set verify=False when you specifically need to skip that verification:

filter.edit(
    rules="page_namespace == 0",
    verify=False
)

Account information

The current account can be inspected with whoami():

info = filters.whoami()

print(info["name"])
print(info["groups"])

Delete

filter.delete()

Requirements

Python 3.9 or newer.

Limitations

BotPassword login does not work with this package.

The package uses the MediaWiki web interface for filter creation and editing, which requires a normal user login.

Documentation

Full API documentation and usage examples are available on Read the Docs.

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mediawiki_abusefilter-0.1.3.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mediawiki_abusefilter-0.1.3-py3-none-any.whl (15.7 kB view details)

Uploaded Python 3

File details

Details for the file mediawiki_abusefilter-0.1.3.tar.gz.

File metadata

  • Download URL: mediawiki_abusefilter-0.1.3.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.3

File hashes

Hashes for mediawiki_abusefilter-0.1.3.tar.gz
Algorithm Hash digest
SHA256 d185d34485b9d2ade60ecef2dae32871013ff7641fcbf0eaad06aa9bf0f5ed3e
MD5 803ae933a99d33da79514c723b6e7686
BLAKE2b-256 f70afe503dd8552a5c918a9cc9b1823b61c1ecf99764e19f38ed1fc9e79a0298

See more details on using hashes here.

File details

Details for the file mediawiki_abusefilter-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for mediawiki_abusefilter-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b26b5604c002e6a88dd79b350b4bfc325fa26d54c864adbd85f5f15942b90a64
MD5 d27e962d01b7bf935ece4e75dc7fa8eb
BLAKE2b-256 f6d0a11cd716e76c48f880a08b33075c74012fdf06521de8be5b80893ba1747f

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page