Page MenuHomePhabricator

VisualEditor can edit, but not save pages, if $wgServer is a protocol-relative URL on a secure site: "Error contacting the Parsoid/RESTBase server (HTTP 415)"
Open, Needs TriagePublicBUG REPORT

Description

List of steps to reproduce (step by step, including full links if applicable):

  • Create a plain vanilla MediaWiki site with HTTPS
  • In LocalSettings.php, set $wgServer using a protocol-relative URL, such as $wgServer = '//mywiki.com';
  • Confirm that the wiki can edit and save pages.
  • Install VisualEditor and load it in LocalSettings.php like so: wfLoadExtensions(array('VisualEditor'));
  • Click "Edit" to edit a page with VisualEditor. This should work fine.
  • Type some text on the page you are editing. This should work fine
  • Attempt to save the edited page. The save fails with the error: Error contacting the Parsoid/RESTBase server (HTTP 415)
  • Now, in LocalSettings.php, set $wgServer to use an explicit https URL, such as $wgServer = 'https://mywiki.com';
  • Edit and save a page using VisualEditor. It should work fine.

What happens?:
When $wgServer is protocol-relative, a dialog appears, Error contacting the Parsoid/RESTBase server (HTTP 415)

What should have happened instead?:
VisualEditor should save pages correctly.

Note: The problem does not occur on an HTTP (non-secure) site. VisualEditor saves pages correctly if $wgServer is protocol-relative.

Software version (if not a Wikimedia wiki), browser information, screenshots, other information, etc.:
MediaWiki 1.37.1
VisualEditor 0.1.2

See ticket T268277 for early attempts to debug this problem. It was originally misidentified as a $wgGroupPermissions issue.

Relevant configuration files:

Here is my complete LocalSettings.php, sanitized:

<?php
if ( !defined( 'MEDIAWIKI' ) ) {
        exit;
}

$wgScriptPath = "/w";
$wgScriptExtension = ".php";
$wgStylePath = "$wgScriptPath/skins";
$wgServer = '//mywiki.com';
$wgSitename = "Test Site";
$wgArticlePath = "/notes/$1";

## Database settings
$wgDBtype = "mysql";
$wgDBserver = "localhost";
$wgDBname = "wikidb";
$wgDBuser = "wikiuser";
$wgDBpassword = "password here";
$wgDBprefix = "wp_";
$wgDBTableOptions = "ENGINE=InnoDB, DEFAULT CHARSET=binary";
$wgDBmysql5 = true;

# Secret keys
$wgSecretKey = "1234567890123456789012345678900987654321123123123123123123123123";
$wgUpgradeKey = "1234567890987654";

# VisualEditor
$wgDefaultSkin = "vector";
wfLoadSkin('Vector');
wfLoadExtensions(array(
    'VisualEditor',
));

Here is the Apache config:

<IfModule mod_ssl.c>
<VirtualHost *:443>
    ServerName mywiki.com
    ServerAdmin admin@blazemonger.com

    # Index file and Document Root (where the public files are located)
    DirectoryIndex index.html index.php
    DocumentRoot /var/www/mywiki.com/public_html
    # Log file locations
    LogLevel warn
    ErrorLog  /var/www/mywiki.com/log/error.log
    CustomLog /var/www/mywiki.com/log/access.log combined

    # Root redirect
    RedirectMatch ^/$ http://mywiki.com/w

    ServerAlias www.mywiki.com
    ServerAlias *.mywiki.com
    ServerAlias mywiki.net
    ServerAlias *.mywiki.net

    SSLCertificateFile /etc/letsencrypt/live/mywiki.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/mywiki.com/privkey.pem
    Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

<Directory "/var/www/mywiki.com/public_html">
    AllowOverride None
    RewriteEngine On
    RewriteRule ^/?notes(/.*)?$ %{DOCUMENT_ROOT}/w/index.php [L]
    RewriteRule ^/*$ %{DOCUMENT_ROOT}/w/index.php [L]
</Directory>

<Directory "/var/www/mywiki.com/public_html/w/images">
    # Ignore .htaccess files
    AllowOverride None

    # Serve HTML as plaintext, don't execute SHTML
    AddType text/plain .html .htm .shtml .php .phtml .php5

    # Don't run arbitrary PHP code.
    php_admin_flag engine off
</Directory>

Event Timeline

It would be interesting to determine whether the same can be reproduced when using Nginx as the webserver.

Does it work if $wgServer is a protocol-relative URL, but you also have set $wgCanonicalServer to an absolute URL?

@matmarex : Yes, setting $wgCanonicalServer as follows makes VisualEditor work:

$wgServer = '//mywiki.com';
$wgCanonicalServer = 'https:' . $wgServer;

In case this helps: setting $wgForceHTTPS does not make VisualEditor work:

$wgServer = '//mywiki.com';
$wgForceHTTPS = true;                    // does not help