This is a PowerShell module for interfacing with a MediaWiki API endpoint that I have worked at on and off occasionally over the last couple of years. It was initially created to assist me in performing various maintenance tasks for the PCGamingWiki (PCGW) community project.
A major focus of the module have been to ensure pipeline compatibility across the cmdlets.
...
While other more powerful alternatives exists (e.g. pymediawiki), I prefer working with and use PowerShell as I like that a well-defined PowerShell module exposes APIs and datasets to regular users and allows them to interact with the dataset without the need of any additional dependencies.
Note that due to its focus on the PCGamingWiki and its outdated version of MediaWiki, the module might not support all options/flags added in newer versions. While most of the development has been performed by consulting the official MediaWiki Action API documentation, incompatible stuff have been disabled in favor of making it work more flawlessly with PCGW.
Due to its rather early stage of development, the module might see frequent and massive changes throughout the codebase as I learn, rethink, and redesign functions or the internal components.
If authenticating, a bot password needs to be used as the module does not support OAuth. Anonymous logins are of course also supported!
-
Download or clone the repository to a local folder called
MediaWiki. -
Launch a new PowerShell session and import the module by using
Import-Module <path-to-the-MediaWiki-folder>(e.g.Import-Module .\MediaWiki)- Be sure to omit any trailing backslash in the path as otherwise the command will fail.
-
Connect to a MediaWiki endpoint using one of these alternatives:
- To establish a new connection:
Connect-MWSession - To use/setup a persistent config:
Connect-MWSession -Persistent - To log in anonymously as a guest:
Connect-MWSession -Guest - To use a persistent config as a guest:
Connect-MWSession -Persistent -Guest - To disconnect from an active session, use
Disconnect-MWSession
- To establish a new connection:
-
Once a connection has been established, use one of the supported cmdlets.
For more real-world examples, visit the AemonyBot repository.
Retrieve the wikitext of a page:
Get-MWPage 'NieR: Automata' -WikitextAdd new content to the end of a specific section:
(Get-MWPage 'NieR: Automata').Sections | Where Line -eq 'Inventory Editor' | Add-MWSection -Content "In Summer of 2038 an updated version was released with bug fixes and QoL improvements." -Summary "Added information pertaining to the 2038 update."Forces a deeper cache purge of a page by performing an empty edit on it:
Get-MWPage 'NieR: Automata' | Update-MWPage -ForcePerforms a Cargo query to retrieve all pages using the SecuROM DRM:
Get-MWCargoQuery -Table Availability -Where "Uses_DRM HOLDS LIKE 'SecuROM%'" -Fields 'Uses_DRM' -ResultSize UnlimitedPerforms a deep cache purge on all SecuROM pages:
$Pages = Get-MWCargoQuery -Table Availability -Where "Uses_DRM HOLDS LIKE 'SecuROM%'" -Fields 'Uses_DRM' -ResultSize Unlimited
$Pages | Update-MWPage -ForcePages
Add-MWPage- Add content to a page.- Implemented as a variant of
Set-MWPage.
- Implemented as a variant of
Get-MWPage- Retrieves information about a page. Use-Wikitextto also fetch the wikitext of the page.- Interface for action=parse.
Get-MWPageInfo- Retrieves additional properties of a page.- Interface for prop=info.
Get-MWPageLink- Retrieve all internal wiki links of a page.- Uses the links generator.
Clear-MWPage- Clears all content on the specified page.- Implemented as a variant of
Set-MWPage.
- Implemented as a variant of
Find-MWPage- List all pages on the wiki.- Interface for list=allpages.
Move-MWPage- Moves a page.- Interface for action=move.
New-MWPage- Creates a new page. Implemented as a variant ofSet-MWPage.Remove-MWPage- Deletes a page.- Interface for action=delete.
Rename-MWPage- Alias forMove-MWPage.Search-MWPage- Perform a full text search on the site.- Interface for list=search.
Set-MWPage- Edit the contents of a page.- Interface for action=edit.
Update-MWPage- Purges the cache for a page. Use-Forcefor a deeper purge by performing an empty edit of the page.- An empty edit (
-Force) can at times trigger backend refreshes (e.g. extensions such as Cargo) that otherwise would not be affected by a normal cache purge. - Interface for action=purge. Imlemented as a variant of
Set-MWPagewhen used with-Force.
- An empty edit (
Undo-MWPageEdit- Undo specific edits of a page. Use-Rollbackto undo all edits made by the last user to edit the page.- Imlemented as a variant of
Set-MWPage. Interface for action=rollback when used with-Rollback.
- Imlemented as a variant of
Sections
Add-MWSection- Add content to a section.- Implemented as a variant of
Set-MWPage.
- Implemented as a variant of
Clear-MWSection- Clear the content from a section.- Implemented as a variant of
Set-MWPage.
- Implemented as a variant of
Get-MWSection- Retrieves information about a section. Use-Wikitextto also fetch the wikitext of the section.- Implemented as a variant of
Get-MWPage.
- Implemented as a variant of
Remove-MWSection- Removes a section.- Implemented as a variant of
Set-MWPage.
- Implemented as a variant of
Rename-MWSection- Changes the title/header of a section.- Implemented as a variant of
Set-MWPage.
- Implemented as a variant of
Set-MWSection- Sets the content of a section.- Implemented as a variant of
Set-MWPage.
- Implemented as a variant of
Files/Images
Find-MWFile- List all files/images.- Interface for list=allimages.
Find-MWFileDuplicate- Find duplicates of a file/image, if any exists.- Uses the allimages generator.
Get-MWFileInfo- List file information and upload history.- Interface for prop=imageinfo.
Get-MWFileUsage- List all pages that use a file/image.- Interface for list=imageusage.
Links / Redirects
Get-MWBackLink- List all pages which links to a page.- Interface for list=backlinks.
Find-MWRedirect- Variant ofFind-MWPageto list all redirect pages.Find-MWRedirectOrphan- Helper to generate a list of all orphaned redirects. Takes a long time with ~50k pages, so be warned. :)
Categories
Get-MWCategoryMember- List all pages in a category.- Interface for list=categorymembers.
Templates
Get-MWEmbeddedIn- List all other pages a page is embedded in.- Interface for list=embeddedin.
Get-MWTranscludedIn- Alias forGet-MWEmbeddedIn.
Namespaces
Get-MWNamespace- Retrieves all registered namespaces on the site.Get-MWNamespacePage- List all pages in a namespace.- Implemented as a variant of
Find-MWPage.
- Implemented as a variant of
Recent Changes
Get-MWRecentChanges- List all recent changes on the site.- Interface for list=recentchanges.
Connection
Connect-MWSession- Connect to an API endpoint.Disconnect-MWSession- Disconnect from the API endpoint.
Site information
Get-MWChangeTag- List all recognized change tags on the site.- Interface for list=tags.
Get-MWProtectionLevel- Retrieves all registered protection levels on the site.- Implemented as a variant of
Get-MWSiteInfo.
- Implemented as a variant of
Get-MWProtectionType- Retrieves all registered protection types on the site.- Implemented as a variant of
Get-MWSiteInfo.
- Implemented as a variant of
Get-MWSiteInfo- Retrieve general information about the site.- Interface for meta=siteinfo.
Users
Get-MWUser- Retrieve information about a user.Get-MWCurrentUser- Retrieve general information about the signed in user.- Interface for meta=userinfo
Get-MWCurrentUserPreference- Retrieve the perferences of the current user.- Implemented as a variant of
Get-MWCurrentUser.
- Implemented as a variant of
Get-MWCurrentUserGroup- Retrieve the groups the current user is a member of.- Implemented as a variant of
Get-MWCurrentUser.
- Implemented as a variant of
Get-MWCurrentUserRateLimit- Retrieve the rate limits applied to the current user.- Implemented as a variant of
Get-MWCurrentUser.
- Implemented as a variant of
Get-MWCurrentUserRight- Retrieve the permissions/rights of the current user.- Implemented as a variant of
Get-MWCurrentUser.
- Implemented as a variant of
Watchlist
Watch-MWPage- Not implemented. Will probably end up watching or unwatching a page maybe?
Extensions
Get-MWCargoQuery- Performs a query against the Cargo backend, provided Extension:Cargo is installed.
Misc
ConvertTo-MWParsedOutput- Have the site parse the input wikitext and reply with the results.- Limited interface for action=parse.
Invoke-MWApiContinueRequest- Useful helper that automatically handles continuing API requests when there are more results available.Invoke-MWApiRequest- Handles the core aspects of performing an API request.
If actively working on the module and its code, I find the below one-liner to be quite helpful to reload the whole thing quickly:
Disconnect-MWSession; Remove-Module MediaWiki; Import-Module .\MediaWiki; Connect-MWSession -Persistent -Guest
Random personal thoughts and ideas that have come up...
- Summarizing the functions for this readme had me realize that the Find- / Get- verbs in the function names might need a rethink in some cases?
- Change
Get-MWGroupMemberto actually retrieve the users of a given group? - Add more helpers/variants e.g. Add-/Remove- ?
Third-party code is noted in the source code, with the appropriate license links. This is a short overview of the code being used: