Extension:PagePort

This extension is professionally maintained by the WikiTeq team.
WikiTeq provides official support for MediaWiki LTS releases only. It may work with other MediaWiki releases.
Category:Extensions by WikiTeq Category:Extensions without an imageCategory:MIT licensed extensions
MediaWiki extensions manual
PagePort
Release status: stableCategory:Stable extensions
Implementation Data extractionCategory:Data extraction extensions
Description Provides a maintenance script to export and import wiki pages in a git-book format and JSON format
Author(s) WikiTeq, Vedmaka
Maintainer(s) WikiTeq team
Latest version 1.1.0 (2024-11-24)
Compatibility policy For every MediaWiki release that is a Long Term Support release there is a corresponding branch in the extension.Category:Extensions with long-term support release branches compatibility policy
MediaWiki 1.39+Category:Extensions with manual MediaWiki version
License MIT License
Download Category:Extensions in Wikimedia version control
README
Quarterly downloads 0
Translate the PagePort extension if it is available at translatewiki.net
Issues Open tasks · Report a bug
Category:All extensions

PagePort provides maintenance scripts to export and import wiki pages in a git-book format and JSON format.

Uses

This extension is designed for cases like setting up wikis quickly from a preassembled batch of pages. For example, templates common when setting up new wikis, or importing content common in a wiki farm.

This is convenient to store in a revision tracker like git, so that new sites can be deployed from it, and changes made without hand-editing complex XML or JSON documents. In fact, when used with Extension:Page Exchange, pages can be imported directly from Github.

This extension does not include any changes to the wiki user interface; all interaction is done on the command line.

Requirements:

  • MediaWiki 1.30+
  • php-zip extension (optional)

Install

  • Download and move the extracted PagePort folder to your extensions/ directory.
    Developers and code contributors should install the extension from Git instead, using:cd extensions/
    git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/PagePort
  • Add the following code at the bottom of your LocalSettings.php file:
    wfLoadExtension( 'PagePort' );
    
  • Yes Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Exporting pages

# Export page from "Test" category, save to ~/export/ folder
php maintenance/run.php ./extensions/PagePort/maintenance/exportPages.php --category Test --out ~/export/

# Export page listed in pages.txt, save to ~/export/ folder
php maintenance/run.php ./extensions/PagePort/maintenance/exportPages.php --pagelist pages.txt --out ~/export/

# Export all the pages, save to ~/export/ folder
php maintenance/run.php ./extensions/PagePort/maintenance/exportPages.php --full Test --out ~/export/

# Export all the pages, save to ~/export/ folder, zip it and save the archive to ~/full.zip
php maintenance/run.php ./extensions/PagePort/maintenance/exportPages.php --full Test --out ~/export/ --zip ~/full.zip

Exporting pages will produce a layout on the file system similar to this one, which can then be edited as needed, or even tracked in git:

/
- Main
-- Main Page.mediawiki
-- Page2.mediawiki
-- Page2#Subpage.mediawiki
- Category:
-- Category1.mediawiki
-- Category2.mediawiki
- Form:
-- Form1.mediawiki
-- Form2.mediawiki
...

Importing pages

# Import pages from ~/export/ directory
php maintenance/run.php ./extensions/PagePort/maintenance/importPages.php --source ~/export/

# Import pages from ~/export/ directory, make edits on behalf of the Admin user
php maintenance/run.php ./extensions/PagePort/maintenance/importPages.php --source ~/export/ --user Admin

PageExchange format

It's possible to export JSON instead of set of flat files. This JSON format is compatible with the PageExchange extension.

# Export pages from "Test" category, save to ~/export/test.json file
php maintenance/run.php ./extensions/PagePort/maintenance/exportPages.php --category Test --out ~/export/test.json --json

# Rewrite pages URLs to point them to a GitHub repository at "someone/Repo":
php maintenance/run.php ./extensions/PagePort/maintenance/exportPages.php --category Test --out ~/export/test.json --json --github "someone/Repo"

# You can also omit the filename, in that case filename will be generated based on time():
php maintenance/run.php ./extensions/PagePort/maintenance/exportPages.php --category Test --out ~/export/ --json

# It's also possible to specify package details:
php maintenance/run.php ./extensions/PagePort/maintenance/exportPages.php --category Test --out ~/export/test.json --json /
    / --version 1.0 --package "MyPackage" --desc "My description"

See php maintenance/run.php ./extensions/PagePort/maintenance/exportPages.php --help for details

Sample JSON output looks like this:

{
	"publisher": "Test",
	"author": [
		"Test"
	],
	"language": "en",
	"url": "https://github.com/Test/test",
	"packages": {
        "Books demo (SMW)": {
            "globalID": "com.test.test",
            "publisherURL": "https://test.com",
            "description": "Lorem",
            "version": "0.1",
            "pages": [
                {
                    "name": "Page1",
                    "namespace": "NS_MAIN",
                    "url": "https://raw.githubusercontent.com/Test/test/master/Main/Test"
                },
                ...
            ]
        }
    }
}

See also

Category:Import extensions Category:Extensions in Wikimedia version control
Category:All extensions Category:Data extraction extensions Category:Extensions by WikiTeq Category:Extensions in Wikimedia version control Category:Extensions with long-term support release branches compatibility policy Category:Extensions with manual MediaWiki version Category:Extensions without an image Category:Import extensions Category:MIT licensed extensions Category:Stable extensions