Jump to content

Extension:PageToGitHub

From mediawiki.org
MediaWiki extensions manual
PageToGitHub
Release status: stable
Implementation Hook
Description Uploads page content to a GitHub repository as a file on every page save
Author(s) Luca Mauri (Lucamauritalk)
Latest version 2.1.0 (2026-04-24)
MediaWiki 1.42+
PHP 8.1+
Composer lucamauri/page-to-github
  • $wgP2GAuthToken
  • $wgP2GIgnoreMinor
  • $wgP2GNameSpace
  • $wgP2GOwner
  • $wgP2GRepo
  • $wgP2GKeyword
  • $wgP2GAddKeyword
Licence GNU General Public License 2.0 or later
Download
https://github.com/lucamauri/PageToGitHub/blob/main/README.md
https://github.com/lucamauri/PageToGitHub/releases
Example WikiTrek (Italian Star Trek wiki)

PageToGitHub (P2G) is a MediaWiki extension that automatically uploads the wikitext content of a page to a GitHub repository every time the page is saved. It listens for the PageSaveComplete hook and can be scoped to a specific namespace, with an optional keyword filter that restricts syncing to pages containing a particular string.

It was originally written by Luca Mauri for WikiTrek, an Italian Star Trek wiki, and is released as open source for use by any MediaWiki installation.

Features

[edit]
  • Automatically uploads wikitext to a GitHub repository on every page save
  • Configurable namespace filter — only pages in the specified namespace are synced
  • Optional keyword filter — only pages whose content contains a specific string are synced
  • Optional filename prefix — the keyword can be prepended to the uploaded filename
  • Minor edits can be excluded from syncing via configuration
  • Upload and commit messages use the wiki's i18n system
  • Special:PageToGitHub shows a summary of the current configuration

Requirements

[edit]

Installation

[edit]

The recommended installation method is via Composer. Add the following to composer.local.json in the root of your MediaWiki installation (create the file if it does not exist):

{
    "require": {
        "lucamauri/page-to-github": "~2.1"
    },
    "extra": {
        "merge-plugin": {
            "include": []
        }
    },
    "config": {}
}

Then run Composer from the MediaWiki root:

composer install --no-dev

Add the following line to LocalSettings.php, near the other extension loading calls:

wfLoadExtension( 'PageToGitHub' );

Then add the configuration parameters described below.

Configuration

[edit]

Add the following to LocalSettings.php:

$wgP2GAuthToken   = 'your-github-personal-access-token';
$wgP2GIgnoreMinor = true;
$wgP2GNameSpace   = 'Module';
$wgP2GOwner       = 'github-username-or-organisation';
$wgP2GRepo        = 'repository-name';
$wgP2GKeyword     = '';     // optional
$wgP2GAddKeyword  = false;  // optional
Parameter Default Description Required?
$wgP2GAuthToken null GitHub personal access token used to authenticate API calls. Generate one in your GitHub account under SettingsDeveloper settingsPersonal access tokens. The token must have repository write permissions. Required
$wgP2GIgnoreMinor true When true, page saves flagged as minor edits are not synced to GitHub. Optional
$wgP2GNameSpace null Only pages in this namespace are synced. Set to the namespace label as a string, e.g. 'Module'. Required
$wgP2GOwner null The GitHub username or organisation that owns the target repository. Required
$wgP2GRepo null The name of the GitHub repository where files are uploaded. Required
$wgP2GKeyword "" When set, only pages whose content contains this string are synced. Leave empty to sync all pages in the configured namespace. Optional
$wgP2GAddKeyword false When true and $wgP2GKeyword is non-empty, the keyword is prepended to the uploaded filename. For example, a page named Foo with keyword bar is uploaded as bar-Foo.lua. Optional

Special page

[edit]

The extension registers Special:PageToGitHub, which displays a table of all configuration variables and their current values. The authentication token ($wgP2GAuthToken) is never read or displayed — its row always shows hidden.

Troubleshooting

[edit]

To read detailed log messages, intercept the log group named PageToGitHub by adding the following to LocalSettings.php:

$wgShowExceptionDetails = true;
$wgDebugLogGroups['PageToGitHub'] = "/var/log/mediawiki/PageToGitHub-{$wgDBname}.log";

See also

[edit]