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="MyBot@mybotpassword",
    password="BOT_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="MyBot@mybotpassword",
    password="BOT_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.

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.1.tar.gz (12.7 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.1-py3-none-any.whl (15.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mediawiki_abusefilter-0.1.1.tar.gz
  • Upload date:
  • Size: 12.7 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.1.tar.gz
Algorithm Hash digest
SHA256 8a4eefe617385983a85290f0bae9140a5884b11b054694df2965a20fade60ca6
MD5 220900f3e4ae09704596a5d02a98e385
BLAKE2b-256 5b510377193a885d8474b51334368a41c0365a68e6515580e1271ff1bb6964c1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mediawiki_abusefilter-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 94eaacce3be4a81a203f9866657c95b114e5a933f42dbfded97cac2d70539b6f
MD5 61c137867d1d3db7f641299cf678a7fd
BLAKE2b-256 9d9a20f75394026faf8c3021290f8048b81b7a15325c219e5246078ecd29cfa4

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.3

2 files

0.1.2

2 files

This release

0.1.1 This release

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