Page MenuHomePhabricator

VisualEditor (MW 1.35): apierror-visualeditor-docserver-http-error
Closed, ResolvedPublic

Description

I am trying to enable the Visual Editor in MediaWiki 1.35.

I'm using the docker image out of the box: https://github.com/wikimedia/mediawiki-docker/blob/master/1.35/apache/Dockerfile

I've not made any changes to the image - just run the installer and enabled the extension:

wfLoadExtension( 'VisualEditor' );

Trying to open the editor produces apierror-visualeditor-docserver-http-error (from here, maybe?).

This StackOverflow post is similar, but with a different error message.

I'm not familiar with MediaWiki, but my understanding is that 1.35 removed the need for Parsoid, but this error looks like it's coming from a Parsoid client. I'm not sure why that is being called if it's not required.

Event Timeline

Parsoid is still used, but as of 1.35 it's included by default with MediaWiki. It's still possible to not enable it though, which would cause this error.

I suspect this is a problem with the Docker image, or perhaps you need to run some magical command to enable things. I'm not familiar with it, sorry.

I've worked it out - it was because the hostname visible from the server was different to the public hostname that was set in $wgServer.

In my case I had set $wgServer to http://localhost:4000 - because docker was forwarding the container's port 80 to 4000 on my host machine. However, from inside the container, it was exposed on port 80. Changing $wgServer to http://localhost fixed it the editor, but broke other things due to the port number being wrong from my host machine.

I'm not sure if this is a potential bug when private/public hostnames differ, or just a configuration error.

There's a $wgInternalServer config variable, can you see if changing it fixes this?

No luck. It seems that it's using $wgServer (looking into if I can get more detailed console logging).

I set

$wgServer = "http://invalid";
$wgInternalServer = "http://localhost";

And get this in the server debug log when trying to open the editor.

[ContentHandler] Registered handler for wikitext: WikitextContentHandler
[http] GET: http://invalid/rest.php/invalid/v3/page/html/Main_Page/9?redirect=false&stash=true
[http] Error fetching URL "http://invalid/rest.php/invalid/v3/page/html/Main_Page/9?redirect=false&stash=true": (curl error: 6) Couldn't resolve host name

I have the same problem.

I published the port 80 via traefik with letsencrypt on 443, so that might confuse the API.
I tried several configs with $wgServer and so on, just can't it get running. Everything except visual editor works well. Hope there is a solution

I have the same problem. Have tried much of what is out there on Google no luck.

I have it running on windows docker on a server. So other computers access via servername:8080. However internally the server needs to be localhost.

I have a possible solution. Even if mine doesn't necessarily match yours, here's how you find out. I switched on every conceivable debugging option listed in:

https://www.mediawiki.org/wiki/Manual:How_to_debug

These settings are to be added to LocalSettings.php, as follows:

  1. At the top, right under <?php
error_reporting( -1 ); 
ini_set( 'display_errors', 1 );
  1. At the bottom, underneath "# Add more configuration options below."
$wgShowExceptionDetails = true; 
$wgDebugToolbar = true; 
$wgShowDebug = true; 
$wgDevelopmentWarnings = true; 
$wgDebugDumpSql = true;

I then started requesting the visual editor URL in a new tab, incrementally subtracting query parameters until I discovered that leaving off the json query parameter gives me a proper error output as expected from the debug options which were previously enabled.

http://<your domain>/api.php?action=visualeditor&format=json&paction=parse&page=Main_Page&uselang=en&formatversion=2

In other words, at some point I got to format=json, removed it, reloaded and got the following output:

{
  "message": "Error: exception of type RuntimeException: bcmath or gmp extension required for 32 bit machines.",
  "exception": {
    "id": "f1802bf2024967674634873f",
    "type": "RuntimeException",
    "file": "/var/www/html/includes/libs/uuid/GlobalIdGenerator.php",
    "line": 637,
    "message": "bcmath or gmp extension required for 32 bit machines.",
    "code": 0,
    "url": "/rest.php/<your domain>/v3/page/html/Foo1/14?redirect=false&stash=true",
    "caught_by": "other",
    "backtrace": [
      {
        "file": "/var/www/html/includes/libs/uuid/GlobalIdGenerator.php",
        "line": 222,
        "function": "intervalsSinceGregorianBinary",
        "class": "Wikimedia\\UUID\\GlobalIdGenerator",
        "type": "->",
        "args": [
          "array",
          "integer"
        ]
      },
      {
        "file": "/var/www/html/includes/libs/uuid/GlobalIdGenerator.php",
        "line": 211,
        "function": "getUUIDv1",
        "class": "Wikimedia\\UUID\\GlobalIdGenerator",
        "type": "->",
        "args": [
          "array"
        ]
      },
      {
        "file": "/var/www/html/includes/utils/UIDGenerator.php",
        "line": 88,
        "function": "newUUIDv1",
        "class": "Wikimedia\\UUID\\GlobalIdGenerator",
        "type": "->",
        "args": []
      },
      {
        "file": "/var/www/html/extensions/VisualEditor/includes/VEParsoid/src/Rest/Handler/ParsoidHandler.php",
        "line": 610,
        "function": "newUUIDv1",
        "class": "UIDGenerator",
        "type": "::",
        "args": []
      },
      {
        "file": "/var/www/html/extensions/VisualEditor/includes/VEParsoid/src/Rest/Handler/PageHandler.php",
        "line": 90,
        "function": "wt2html",
        "class": "VEParsoid\\Rest\\Handler\\ParsoidHandler",
        "type": "->",
        "args": [
          "VEParsoid\\Config\\PageConfig",
          "array"
        ]
      },
      {
        "file": "/var/www/html/includes/Rest/Router.php",
        "line": 414,
        "function": "execute",
        "class": "VEParsoid\\Rest\\Handler\\PageHandler",
        "type": "->",
        "args": []
      },
      {
        "file": "/var/www/html/includes/Rest/Router.php",
        "line": 338,
        "function": "executeHandler",
        "class": "MediaWiki\\Rest\\Router",
        "type": "->",
        "args": [
          "VEParsoid\\Rest\\Handler\\PageHandler"
        ]
      },
      {
        "file": "/var/www/html/includes/Rest/EntryPoint.php",
        "line": 168,
        "function": "execute",
        "class": "MediaWiki\\Rest\\Router",
        "type": "->",
        "args": [
          "MediaWiki\\Rest\\RequestFromGlobals"
        ]
      },
      {
        "file": "/var/www/html/includes/Rest/EntryPoint.php",
        "line": 133,
        "function": "execute",
        "class": "MediaWiki\\Rest\\EntryPoint",
        "type": "->",
        "args": []
      },
      {
        "file": "/var/www/html/rest.php",
        "line": 31,
        "function": "main",
        "class": "MediaWiki\\Rest\\EntryPoint",
        "type": "::",
        "args": []
      }
    ]
  },
  "httpCode": 500,
  "httpReason": "Internal Server Error"
}

I was using Docker, and I needed to install bcmath.

In docker, first you enter the Docker container (named "mediawiki" in my case, you may have a different name, or even a hashed id) and start a shell inside it like so:

docker exec -it mediawiki /bin/bash

Then, you install bcmath, like so:

docker-php-ext-install bcmath

Then, you exit, and you restart the container, like so:

docker restart mediawiki

Visual editing now works. This was necessary for me, because my Docker image runs on ARM 32-bit.

Note that e.g. x86 Ubuntu users running php 7.4 can install the package with:

sudo apt update && sudo apt -y install php7.4-bcmath

...And they can adjust the php version in the package name to a different version if so required.

matmarex claimed this task.
matmarex added a project: MW-1.41-notes.

This problem should no longer occur on MediaWiki 1.41 and later, as VisualEditor no longer uses HTTP requests internally to contact Parsoid, it just calls the PHP methods directly (see T320529 for related work).

Please try MediaWiki 1.41 and hopefully VisualEditor will now finally just work. If you still encounter some issues, please file a new task.