Jump to content

Extension:PagePort

From mediawiki.org
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.
MediaWiki extensions manual
PagePort
Release status: stable
Implementation Data extraction
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.
MediaWiki 1.39+
License MIT License
Download
README
Translate the PagePort extension if it is available at translatewiki.net
Issues Open tasks ¡ Report a bug

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

Uses

[edit]

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:

[edit]
  • MediaWiki 1.30+
  • php-zip extension (optional)

Install

[edit]
  • 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

[edit]
# Export page from "Test" category, save to ~/export/ folder
php maintenance/exportPages.php --category Test --out ~/export/

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

# Export all the pages, save to ~/export/ folder
php 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/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

[edit]
# Import pages from ~/export/ directory
php maintenance/importPages.php --source ~/export/

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

PageExchange format

[edit]

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/exportPages.php --category Test --out ~/export/test.json --json

# Rewrite pages URLs to point them to a GitHub repository at "someone/Repo":
php 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/exportPages.php --category Test --out ~/export/ --json

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

See php 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

[edit]