Skip to content

MooncellWiki/mediawiki-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mediawiki-cli

A command-line tool for interacting with MediaWiki APIs.

Installation

cargo build --release
# binary at target/release/mediawiki-cli

Global Options

Option Default Description
--api-url https://prts.wiki/api.php MediaWiki API endpoint
--cookie Custom Cookie header, overrides stored login cookie
--log-level warn Log level: error | warn | info | debug | trace

Commands

auth login <username>

Log in and store the session cookie. Prompts for password interactively. Supports 2FA — if the wiki requires a second factor, you'll be prompted for it automatically.

mediawiki-cli auth login MyUser

Session cookies are persisted to ~/.config/mediawiki-cli/cookies.json (keyed by API URL).

auth status

Show current login status: username, user groups, rights, edit count, registration date, and email.

mediawiki-cli auth status

page get [<title>] [--revid <ID>]

Fetch raw wikitext for a page or a specific revision. You must specify either a title or --revid.

mediawiki-cli page get "Main Page"
mediawiki-cli page get --revid 12345

page edit <title> [options]

Edit a page. Content can be provided via stdin, a file, the --content flag, the --replace flag, or as a null edit.

Option Description
-s, --summary <text> Edit summary
--minor Mark as minor edit
--create-only Only create the page; fail if it already exists
-f, --file <path> Read content from a file
-c, --content <text> Provide content directly on the command line
--replace <OLD> <NEW> Replace a single occurrence of OLD with NEW in the page
--null-edit Submit a null edit (resubmit current content without changes)
# from stdin
echo "new content" | mediawiki-cli page edit "Sandbox" -s "update"

# from file
mediawiki-cli page edit "Sandbox" -f content.txt -s "update from file"

# inline content
mediawiki-cli page edit "Sandbox" --content "hello world"

# find-and-replace (exact one match required)
mediawiki-cli page edit "Sandbox" --replace "old text" "new text"

# null edit
mediawiki-cli page edit "Sandbox" --null-edit

page info [<title>] [--revid <ID>] [--templates]

Show page metadata (title, page ID, URL, categories). Use --templates to list all transcluded templates.

mediawiki-cli page info "Main Page"
mediawiki-cli page info "Main Page" --templates
mediawiki-cli page info --revid 12345

page history <title> [--limit <N>]

List page revision history. Outputs rev ID, timestamp, user, size, and comment in a tab-separated format.

mediawiki-cli page history "Main Page"
mediawiki-cli page history "Main Page" --limit 50

page category <title> [--limit <N>]

List all pages in a category. The category name can be provided with or without the "Category:" prefix. By default, all members are listed; use --limit to cap the number of results.

mediawiki-cli page category "Templates"
mediawiki-cli page category "Category:Templates" --limit 50

page search <query> [--limit <N>]

Search pages by keyword. Outputs title, page ID, and snippet.

mediawiki-cli page search "arknights"
mediawiki-cli page search "arknights" --limit 20

page embedded-in <title> [--limit <N>]

List pages that embed (transclude) the given page. Useful for finding where a template is used.

mediawiki-cli page embedded-in "Template:Infobox"
mediawiki-cli page embedded-in "Template:Infobox" --limit 50

cargo tables

List all Cargo database tables on the wiki. Outputs table names sorted alphabetically.

mediawiki-cli cargo tables

cargo fields <table>

Show all fields and their types for a given Cargo table. Outputs field name and type (e.g. String, Wikitext) in a tab-separated format.

mediawiki-cli cargo fields chara

cargo query --tables <tables> --fields <fields> [options]

Run a Cargo query against the wiki database. Results are output as tab-separated values with a header row.

Option Description
--tables <tables> Comma-separated table names to query
--fields <fields> Comma-separated field names to retrieve
--where <clause> SQL-style WHERE condition
--join-on <clause> SQL-style JOIN ON condition
--group-by <clause> SQL-style GROUP BY clause
--having <clause> SQL-style HAVING clause
--order-by <clause> SQL-style ORDER BY clause
--limit <N> Maximum number of results (default: 50)
--offset <N> Query offset
mediawiki-cli cargo query --tables chara --fields name,rarity --limit 5
mediawiki-cli cargo query --tables building_skill2 --fields name,room --where "room='控制中枢'" --limit 10

Authentication

mediawiki-cli uses the MediaWiki clientlogin API for authentication. After logging in with auth login, the session cookie is stored locally and automatically sent with subsequent requests. You can also pass a cookie directly with --cookie without using the login flow.

About

A cli for mediawiki

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages