Jump to content

WikiFAIR/Monitoring

From Meta, a Wikimedia project coordination wiki

You can monitor uploaded data via Watchlists or by using Maintenance Queries. This page outlines both approaches, helping you keep an eye on important item changes and quickly spot issues.

Why Monitor?

[edit]

Monitoring is important because Wikidata is a collaborative environment where anybody can edit items. Keeping track of specific items ensures you can:

  • Detect and revert vandalism or other problematic edits.
  • See and learn from improvements contributed by other editors.
  • Keep records accurate and up to date.
  • Maintain quality control over items that are critical for your project.

Watchlists

[edit]

Watchlists are mainly used for monitoring entire items and require little setup. If your project wants to keep track of some specific items, this is a quick and straightforward way to do it.

  • They are highly configurable and filterable (e.g., by namespace or user).
  • You can set up RSS feeds or email notifications for changes.
  • You can add items to your watchlist individually or by uploading a raw list of item IDs here.

Creating Watchlists automatically

[edit]

Some projects could benefit from finding items that were touched by project accounts to monitor, here is a python script to do this:

#!/usr/bin/env python3
import requests
import argparse

def get_items_edited_by(user):
    """
    Query the Wikidata API for all user contributions in the main namespace for the given user.
    """
    URL = "https://www.wikidata.org/w/api.php"
    params = {
       "action": "query",
       "list": "usercontribs",
       "ucuser": user,
       "ucnamespace": 0,
       "uclimit": "max",
       "format": "json"
    }
    
    items = set()
    while True:
        response = requests.get(URL, params=params)
        data = response.json()
        if "query" not in data or "usercontribs" not in data["query"]:
            break
        for contrib in data["query"]["usercontribs"]:
            items.add(contrib["title"])
        if "continue" in data:
            params.update(data["continue"])
        else:
            break
    return items

def main():
    parser = argparse.ArgumentParser(
        description="Export a list of all Wikidata Items edited by a specified user."
    )
    parser.add_argument("username", help="Wikidata username")
    parser.add_argument("--output", "-o", default="edited_items.txt",
                        help="Output file name (default: edited_items.txt)")
    args = parser.parse_args()
    
    items = get_items_edited_by(args.username)
    print(f"Found {len(items)} unique items edited by {args.username}")
    
    with open(args.output, "w", encoding="utf-8") as f:
        for item in sorted(items):
            f.write(item + "\n")
    print(f"Exported list to {args.output}")

if __name__ == "__main__":
    main()

Maintenance Queries

[edit]

Another method for monitoring items is using maintenance queries. For example, you can set up SPARQL queries to regularly check for missing statements, incorrect values, or other issues. See the WikiProject Chess Maintenance Queries for inspiration on how to organize your own.

ShapeExpressions/Schemas

[edit]

Creating a detailed Shape Expression for items of interest to the project is a powerful way to ensure quality and monitor changes.

Property Constraints

[edit]

If there is a property defined by the project, property constraints can be used to ensure specific values exists and violations are highlighted in the constraint violation database.