PageToGitHub, P2G in short, is a MediaWiki extension to automatically transfer code from a MediaWiki wiki to GitHub. It was originally conceived and written by Luca Mauri for use in Wikitrek: it is released as open source here in case it can be useful to anybody else.
Easiest way to install the extension is using Composer: it will automatically resolve all the dependencies and install them as well.
Add the require
configuration as in the following example to the composer.local.json
at the root of your mediawiki installation, or create the file if it does not exist yet:
{
"require": {
"lucamauri/page-to-github": "~2.0"
},
"extra": {
"merge-plugin": {
"include": [
]
}
},
"config": {
}
}
and, in a command prompt, run Composer in the root of your mediawiki installation:
composer install --no-dev
Add the following code near the rest of the extensions loading in the site's LocalSettings.php
:
wfLoadExtension('PageToGitHub');
Below this line, add the configuration parameters as explained below in Configuration section.
In the LocalSettigs.php
file add:
$wgP2GAuthToken = 'GitHub-Token';
$wgP2GIgnoreMinor = true;
$wgP2GKeyword = 'Keyword';
$wgP2GAddKeyword = true;
$wgP2GNameSpace = 'Module';
$wgP2GOwner = 'Project-Or-Person';
$wgP2GRepo = 'Name-Of-Your-Repository';
The GitHub token needed to authenticate and made modification the the repository. You can generate one in your GitHub account in Settings > Developer settings > Personal access tokens
If empty or set as true
the revision is not pushed to GitHub if is marked as Minor
An optional keyword to check into the page. When present, P2G will not upload pages if the keyword is not written in the page. If the parameter is omitted, P2G will upload all pages in the Namespace specified above.
An optional boolean parameter: when set to true
the word defined in $wgP2GKeyword is added before the name of the page to form the filename.
P2G will upload pages only belonging to the namespace spedified in this variable
The Person or Organization owner of the repository
The name of the repository where the code must be uploaded
To read detailed logging messages, you can intercept the log group named PageToGitHub
: for instace with the following configuration into LocalSetting.php
:
$wgShowExceptionDetails = true;
$wgDebugLogGroups['PageToGitHub'] = "/var/log/mediawiki/PageToGitHub-{$wgDBname}.log";