PageToGitHub (P2G) is a MediaWiki extension that automatically uploads page content to a GitHub repository on every page save. It listens for the PageSaveComplete hook and can be scoped to a specific namespace and an optional keyword that must be present in the page body.
It was originally conceived and written by Luca Mauri for use in WikiTrek and is released as open source in case it is useful to others.
- Automatically uploads wikitext content to a GitHub repository on page save
- Configurable namespace filter: only pages in the specified namespace are synced
- Optional keyword filter: only pages containing a specific string are synced
- Optional filename prefix: the keyword can be prepended to the uploaded filename
- Minor edits can be excluded from syncing
- Upload and commit messages use the wiki's i18n system
- Special page (
Special:PageToGitHub) shows the current configuration
- PHP 8.1 or later
- MediaWiki 1.42 or later
- A GitHub personal access token with repository write permissions
- Composer for dependency management
The easiest way to install the extension is using Composer: it will automatically resolve and install all dependencies.
Add the following to composer.local.json at 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 root of your MediaWiki installation:
composer install --no-devAdd the following line near the rest of the extension loading calls in LocalSettings.php:
wfLoadExtension( 'PageToGitHub' );Then add the configuration parameters described in the Configuration section below.
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; // optionalThe GitHub personal access token used to authenticate API calls. Generate one in your GitHub account under Settings > Developer settings > Personal access tokens. The token must have repository write permissions.
When set to true (the default), page saves flagged as minor edits are not synced to GitHub.
Only pages belonging to this namespace are synced. Set to the namespace label as a string, e.g. 'Module'.
The GitHub username or organisation that owns the target repository.
The name of the GitHub repository where files are uploaded.
An optional keyword string. When set, only pages whose content contains this string are synced. Leave empty (the default) to sync all pages in the configured namespace.
When set to true and $wgP2GKeyword is non-empty, the keyword is prepended to the uploaded filename, e.g. a page named Foo with keyword bar is uploaded as bar-Foo.lua. Defaults to false.
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 the GitHub releases page for the full changelog.
This extension is released under the GNU General Public License 2.0 or later.