Logo Wikimedia Database

Wikimedia Database

Cộng đồng
fuzheado
wikimedia-database

Execute SQL queries against Wikipedia database replicas (enwiki, wikidata, commonswiki) via an SSH tunnel to Toolforge, with connection management and data handling guardrails

Tổng quan

Nhà phát hànhfuzheado
Kho mãWikipedia-AI-Skills
Tên kỹ năngwikimedia-database
Sao
27
Bản fork
10
Tệp đi kèm
7
Giấy phépMIT
Liên kết
  • Hướng dẫn bằng Markdown

    Tệp SKILL.md được mô hình tải khi cần, nên chỉ tốn token khi có yêu cầu thực sự phù hợp.

  • Dùng được với mọi LLM

    Kỹ năng AI là Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên dùng được với GPT, Claude, Gemini, Grok hoặc mô hình cục bộ.

  • 7 tệp đi kèm

    Các tập lệnh, mẫu và tài liệu tham khảo mà mô hình có thể đọc khi làm việc. Các tệp chỉ cho phép đọc và không bao giờ được thực thi.

  • Mã nguồn mở

    Được fuzheado công bố trên GitHub. Hãy đọc nội dung nguồn trước khi cài đặt.

Cài đặt

Cài đặt kỹ năng AI Wikimedia Database trong TypingMind để dùng với bất kỳ LLM nào, hoặc thêm vào một tác nhân AI khác có thể đọc SKILL.md.

1

Cài đặt trong TypingMind

TypingMind cài đặt kỹ năng trực tiếp từ thư mục GitHub — đọc SKILL.md, đóng gói các tệp tài nguyên và lưu kết quả trên máy.

  1. Mở ứng dụng và vào Plugin → Kỹ năng.
  2. Chọn "Cài đặt từ GitHub".
  3. Dán URL thư mục kỹ năng bên dưới và xác nhận.
    https://github.com/fuzheado/Wikipedia-AI-Skills/tree/main/.claude/skills/wikimedia-database
  4. Bật kỹ năng trong từng cuộc trò chuyện mà bạn muốn sử dụng kỹ năng đó.
Plugin → Kỹ năng → Thêm kỹ năng → Từ URL GitHub, sau đó dán URL thư mục và nhấn Tiếp tục.
2

Cài đặt trong tác nhân AI khác

Bất kỳ tác nhân AI nào đọc được định dạng Agent Skills đều có thể dùng kỹ năng này — hãy sao chép thư mục vào thư mục kỹ năng của tác nhân AI đó.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/fuzheado/Wikipedia-AI-Skills.git /tmp/Wikipedia-AI-Skills
mkdir -p .claude/skills
cp -r /tmp/Wikipedia-AI-Skills/.claude/skills/wikimedia-database .claude/skills/wikimedia-database
Khởi động lại Claude Code sau khi sao chép để ứng dụng nhận kỹ năng mới.

Sử dụng trong TypingMind

Bật Wikimedia Database trong bất kỳ cuộc trò chuyện nào trên TypingMind, mô hình sẽ tự xử lý phần còn lại. Tên và mô tả của kỹ năng nằm trong prompt hệ thống. Ngay khi có yêu cầu phù hợp, mô hình tự tải toàn bộ hướng dẫn — bạn không cần gọi thủ công và kỹ năng không tốn token cho đến khi thực sự được dùng.

Mô hình tự tải Wikimedia Database ngay khi có yêu cầu phù hợp.

Dùng được với mọi mô hình AI

Kỹ năng AI là các hướng dẫn Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên Wikimedia Database không bị giới hạn ở mô hình mà kỹ năng này được viết cho. Chỉ cần cài đặt một lần trong TypingMind rồi dùng với GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama hoặc mô hình cục bộ do bạn tự chạy — tất cả đều dùng khóa API của riêng bạn.

  • Chỉ tải khi cần

    Prompt hệ thống chỉ chứa tên và mô tả. Hướng dẫn được tải khi có yêu cầu phù hợp đầu tiên, nên kỹ năng chưa dùng không tốn chi phí.

  • Đổi mô hình ngay trong cuộc trò chuyện

    Vì kỹ năng là hướng dẫn chứ không phải mã, việc đổi mô hình không làm kỹ năng ngừng hoạt động — mô hình tiếp theo vẫn đọc cùng tệp SKILL.md.

Hướng dẫn của kỹ năng

Đây là nội dung SKILL.md mà mô hình tải. Hãy đọc trước khi cài đặt — kỹ năng là những hướng dẫn mà mô hình của bạn sẽ làm theo.

⚠️ User-Agent required: While this skill primarily uses SQL via SSH tunnel, any direct API calls (e.g., for verification via curl or requests) must include a descriptive User-Agent header. See the wikimedia-api-access skill for the correct format.

Enables the agent to execute dynamic SQL queries against Wikimedia production replicas (e.g., enwiki, enwiki_p, wikidata, commonswiki) by leveraging a local SSH tunnel and specific environment variables for multi-layer authentication.

⚠️ Commons links tables moved to a separate cluster (x4) on 2026-09-08. The links tables on commonswiki (categorylinks, pagelinks, templatelinks, imagelinks, globalimagelinks, linktarget, externallinks, iwlinks, langlinks, existencelinks, collation) are no longer on the core cluster. Connect to links.commonswiki.analytics.db.svc.wikimedia.cloud for those tables, and join them to page / redirect / revision in application code — cross-cluster JOINs are not possible. The old copies on the core cluster are no longer updated, so any query still hitting them silently returns stale data. Table/column names are unchanged, and page + redirect remain available on both clusters. Since 2026-09-14 the x4 section is exposed on the Wiki Replicas, so the links hostnames return fresh data again (the s4 copies are no longer reachable from the replicas). Details: News/2026 Commons links tables database split and references/schema-replicas.md (hostname mapping + code-side join pattern).

Prerequisites

  • Authentication: The following variables must be set in the .env file:

  • TOOLFORGE_USER: The shell/LDAP username for SSH (e.g., janesmith).

  • TOOLFORGE_SQL_USER: The replica database username (e.g., u1234).

  • TOOLFORGE_SQL_PASSWORD: The replica database password.

  • TOOLFORGE_DB_PORT: The local port for the SSH tunnel (default: 3307). Set if you need a different port to avoid conflicts with a local MySQL/MariaDB instance.

  • SSH Config: The user must have their SSH keys added to the ssh-agent to allow non-interactive connections.

Standard Operating Procedure (SOP)

1. Connection Management

Before executing any SQL, the agent must ensure the tunnel is active.

  • Check: Attempt a connection to 127.0.0.1:${TOOLFORGE_DB_PORT:-3307}.
  • Auto-Establish: If the port is closed, the agent should attempt to spawn a background SSH process: ssh -L ${TOOLFORGE_DB_PORT:-3307}:enwiki.analytics.db.svc.wikimedia.cloud:3306 ${TOOLFORGE_USER}@login.toolforge.org -N
  • Persistence (Recommended): For long-running data generation, use autossh instead of plain ssh. Autossh monitors the connection and re-establishes it if the tunnel drops, which happens frequently during multi-hour sessions. Install with brew install autossh (macOS) or apt install autossh (Linux), then use: autossh -M 0 -o "ServerAliveInterval 30" -o "ServerAliveCountMax 3" -L ${TOOLFORGE_DB_PORT:-3307}:enwiki.analytics.db.svc.wikimedia.cloud:3306 ${TOOLFORGE_USER}@login.toolforge.org -N -v
  • Escalation: If the tunnel fails to open, provide the user with the command above to run manually.

2. Implementation Pattern (Python)

The agent should use pymysql to interact with the replicas.

python
import os
import socket
import subprocess
import pymysql
from dotenv import load_dotenv

load_dotenv()

def get_db_connection(db_name='enwiki_p'):
    host = '127.0.0.1'
    port = int(os.getenv('TOOLFORGE_DB_PORT', '3307'))
    
    # Check if tunnel is open
    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
        s.settimeout(1)
        if s.connect_ex((host, port)) != 0:
            user = os.getenv("TOOLFORGE_USER")
            # Spawn persistent background tunnel
            cmd = ["ssh", "-L", f"{port}:enwiki.analytics.db.svc.wikimedia.cloud:3306", f"{user}@login.toolforge.org", "-N"]
            subprocess.Popen(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
            
    return pymysql.connect(
        host=host,
        port=port,
        user=os.getenv("TOOLFORGE_SQL_USER"),
        password=os.getenv("TOOLFORGE_SQL_PASSWORD"),
        database=db_name,
        cursorclass=pymysql.cursors.DictCursor,
        charset='utf8mb4'
    )

def query_wiki(sql, db='enwiki_p'):
    conn = get_db_connection(db)
    try:
        with conn.cursor() as cursor:
            cursor.execute(sql)
            return cursor.fetchall()
    finally:
        conn.close()

3. Data Handling Guardrails

  • Read-Only: Only generate SELECT statements.
  • Namespace Filtering: Always consider page_namespace (e.g., 0 for Main/Article space).
  • Binary Decoding: Many strings (titles, user names) are stored as Varbinary. If the output looks like b'Title', the agent must apply .decode('utf-8').
  • Safety Limits: Every exploratory query must include a LIMIT (suggested default: 10-50).
  • Database Naming: Project names must end in _p (e.g., wikidatawiki_p, commonswiki_p).

MySQL 9+ compatibility

If you get ERROR 2059: Authentication plugin 'mysql_native_password' cannot be loaded when using the mysql CLI, this is because MySQL 9.x removed the mysql_native_password plugin entirely from the client — both as a loadable .so and as a compiled-in implementation. Neither --default-auth nor any other flag can work around this.

The fix is to use pymysql (pure Python). It implements the MySQL protocol natively and handles mysql_native_password authentication without any external plugins:

bash
pip install pymysql python-dotenv

The query.sh script will automatically use pymysql if available, falling back to the mysql CLI only if Python dependencies are missing.

Example Use Cases

  • Prompt: "What are the 5 oldest pages in the 'Draft' namespace?"

  • Action: Execute SELECT page_title, page_touched FROM page WHERE page_namespace = 118 ORDER BY page_id ASC LIMIT 5;

  • Prompt: "Count revisions by 'ExampleUser' on enwiki."

  • Action: Execute SELECT COUNT(*) FROM revision_userindex JOIN actor ON rev_actor = actor_id WHERE actor_name = 'ExampleUser';

  • Prompt: "Search edit summaries mentioning 'revert' by a specific user."

  • Action: Execute constrained SQL — the comment table has no full-text index, so queries MUST include both actor_name and rev_timestamp filters to avoid timeouts. See references/edit-summary-search.md for the full guide to edit-summary search across all approaches (SQL, Sigma tool, XML dumps, EventStreams).


Tooling

This skill includes helper scripts, reference docs, and templates:

🔧 Tunnel Management (scripts/setup-tunnel.sh)

Establishes an SSH tunnel to Toolforge. Auto-detects if tunnel is already active, prefers autossh for auto-reconnecting, and verifies the connection.

bash
./scripts/setup-tunnel.sh --yes                    # defaults
./scripts/setup-tunnel.sh [db_host] [local_port]

Refuses to run with no arguments: its default action is to background a long-lived SSH tunnel, so that has to be requested. Use --yes for the defaults.

Requires: TOOLFORGE_USER environment variable and SSH key loaded in agent.

🔧 Query Runner (scripts/query.sh)

Run a SQL query against a replica and see results in the terminal.

bash
./scripts/query.sh "SELECT page_title, page_len FROM page LIMIT 10" [database]

Includes safety guardrails: only SELECT allowed, missing env vars detected.

🔧 Tunnel Closer (scripts/close-tunnel.sh)

Cleanly tear down the SSH tunnel.

bash
./scripts/close-tunnel.sh [local_port]

📚 Schema Reference (references/schema-replicas.md)

Full reference of Wikimedia replica database tables (page, revision, actor, page_props, categorylinks, pagelinks) with column descriptions and common queries.

📚 Edit Summary Search (references/edit-summary-search.md)

Comprehensive guide to searching Wikipedia edit summaries. Covers the comment table indexing gap, constrained SQL patterns, the Σ (Sigma) Toolforge tool, XML dump processing, and EventStreams filtering. Load this when the task involves finding edits by their summary text.

📚 Connection Guide (references/connection-guide.md)

Step-by-step guide for setting up Toolforge access, getting credentials, and troubleshooting common issues.

🧩 Environment Template (assets/.env.example)

bash
cp assets/.env.example .env
# Edit .env with your credentials

🧩 Sample SQL Queries (assets/sample-queries.sql)

50+ pre-built SQL queries organized by category (page info, stats, categories, pageviews, Wikidata, revisions, links, cross-refs, user activity).


Cross-References

Related SkillWhy
wikimedia-toolforgeSSH tunnel setup and Toolforge access
wikimedia-page-assessmentPageAssessments queries use the same database connection pattern
wikimedia-pageviewsPageview SQL queries via page_props table
wikimedia-api-accessUser-Agent format for any follow-up API calls

Tệp đi kèm

Mô hình đọc các tệp này khi cần trong lúc kỹ năng được tải. Các tệp được cung cấp ở dạng có thể đọc và không bao giờ được thực thi.

Câu hỏi thường gặp

Kỹ năng AI Wikimedia Database làm được gì?

Execute SQL queries against Wikipedia database replicas (enwiki, wikidata, commonswiki) via an SSH tunnel to Toolforge, with connection management and data handling guardrails

Vì sao nên dùng Wikimedia Database trên TypingMind?

Vì bạn chỉ cần cài một lần rồi dùng với bất kỳ mô hình nào. Wikimedia Database là nội dung Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên cùng một kỹ năng có thể chạy trên GPT-5, Claude, Gemini, Grok hoặc mô hình trên thiết bị — và bạn có thể đổi mô hình ngay trong cuộc trò chuyện mà kỹ năng vẫn hoạt động. TypingMind dùng khóa API riêng của bạn, nên bạn thanh toán trực tiếp cho nhà cung cấp thay vì trả phí thuê bao theo suất người dùng, đồng thời kỹ năng và các cuộc trò chuyện vẫn nằm trong bộ lưu trữ của bạn.

Làm thế nào để cài Wikimedia Database trong TypingMind?

Mở Plugin → Kỹ năng → Cài đặt từ GitHub trong TypingMind rồi dán https://github.com/fuzheado/Wikipedia-AI-Skills/tree/main/.claude/skills/wikimedia-database. TypingMind đọc tệp SKILL.md, đóng gói các tệp đi kèm và cài đặt thành một kỹ năng mà bạn có thể bật cho từng cuộc trò chuyện.

Những mô hình AI nào có thể dùng Wikimedia Database?

Bất kỳ mô hình nào bạn kết nối trong TypingMind. Kỹ năng AI là các hướng dẫn bằng Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên GPT, Claude, Gemini, Grok và các mô hình chạy trên thiết bị đều có thể tải kỹ năng này khi có yêu cầu phù hợp.

Bạn có thể dùng Wikimedia Database với bao nhiêu mô hình AI?

Bao nhiêu cũng được. Miễn là mô hình hỗ trợ kỹ năng, bạn có thể dùng Wikimedia Database với mô hình đó — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama và nhiều mô hình khác — tất cả đều trên TypingMind với khóa API riêng của bạn.

Kỹ năng AI Wikimedia Database có miễn phí không?

Có. Kỹ năng này được fuzheado phát hành trên GitHub theo giấy phép MIT. Bạn chỉ trả tiền cho nhà cung cấp AI của mình theo số token đã dùng.

Kỹ năng AI là gì?

Kỹ năng AI là một gói hướng dẫn có thể tái sử dụng, chỉ cho mô hình AI cách thực hiện một tác vụ cụ thể. Kỹ năng tuân theo định dạng mở Agent Skills: một tệp SKILL.md chứa tên và mô tả, cùng các tập lệnh, mẫu hoặc tệp tham khảo mà mô hình có thể cần. Mô hình chỉ đọc hướng dẫn khi yêu cầu của bạn phù hợp với kỹ năng, nên kỹ năng đã cài đặt không phát sinh chi phí cho đến khi được sử dụng.

Kỹ năng AI khác gì với plugin hoặc máy chủ MCP?

Plugin hoặc máy chủ MCP cung cấp cho mô hình các công cụ mới để gọi — mã được chạy ở đâu đó và trả về kết quả. Còn kỹ năng AI cung cấp kiến thức và quy trình: cách tiếp cận tác vụ, các bước cần thực hiện và tiêu chí của đầu ra tốt. Kỹ năng chỉ là nội dung Markdown, nên không cần máy chủ, khóa API hay môi trường thực thi và hoạt động với mọi mô hình.

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇