Parsoid/PHP

From MediaWiki.org
Jump to navigation Jump to search

Parsoid/PHP is the Parsoid codebase implemented in PHP. It is a port of (and replaces) the original Parsoid codebase, written in JavaScript.

Parsoid/PHP is the version running on Wikimedia Foundation servers in production on the current development version of MediaWiki (1.35). The integration of Parsoid/PHP with the core MediaWiki codebase is still in active development. If you are running MediaWiki 1.34 or earlier, you should probably stick with the JavaScript implementation of Parsoid for now. Installation instructions for Parsoid/JS are on the main Parsoid page.

Developer setup[edit]

You need to install the Parsoid and VisualEditor extensions (assuming you want to test VisualEditor).

Then add the following to your LocalSettings.php:

## Parsoid required configuration
$PARSOID_INSTALL_DIR = '/your/path/to/a/git/checkout/of/Parsoid';
// For developers: ensure Parsoid is executed from $PARSOID_INSTALL_DIR,
// (not the version included in mediawiki-core by default)
// Must occur *before* wfLoadExtension()
AutoLoader::$psr4Namespaces += [
    // Keep this in sync with the "autoload" clause in
    // $PARSOID_INSTALL_DIR/composer.json
    'Wikimedia\\Parsoid\\' => "$PARSOID_INSTALL_DIR/src",
];
wfLoadExtension( 'Parsoid', "$PARSOID_INSTALL_DIR/extension.json" );

// Enable Parsoid
$wgEnableRestAPI = true;
$wgParsoidSettings = [
    'useSelser' => true,
    'rtTestMode' => false,
    'linting' => false,
];
// Enable VisualEditor
wfLoadExtension('VisualEditor');
$wgDefaultUserOptions['visualeditor-enable'] = 1;
$wgVirtualRestConfig['modules']['parsoid'] = [
    # once https://gerrit.wikimedia.org/r/583430 lands you can leave this blank
	'url' => $wgServer . $wgScriptPath . '/rest.php',
    'domain' => $wgServer,
];
// OPTIONAL: Enable VisualEditor's experimental code features
$wgVisualEditorEnableExperimentalCode = true;
// OPTIONAL: Enable VisualEditor in other namespaces
// (By default, VE is only enabled in NS_MAIN)
$wgVisualEditorNamespaces[] = NS_USER;

Note that the business with $PARSOID_INSTALL_DIR and AutoLoader::$psr4Namespaces is only necessary for developers, who want to ensure they are running from the latest git version of Parsoid, not the version included in mediawiki-core as a library. As the MediaWiki 1.35 LTS release nears, we'll provide alternative (simpler) install directions for ordinary users. If you're serving MediaWiki with Nginx, you'll need to also add something like this to your server conf:

location /rest.php/ {
	try_files $uri $uri/ /rest.php?$query_string;
}

To test proper configuration, visit {$wgScriptPath}/rest.php/{$domain}/v3/page/html/Main%20Page where $domain is the hostname in your $wgCanonicalServer. (Note that production WMF servers do not expose the Parsoid REST api to the external network.)

Some other notes about configuration:

Historical notes[edit]