Wiki Parsoid error - cannot connect to Parsoid Server - wikimedia

I'm trying to set Parsoid extension and Visual Editor on my wiki page. It is NOT on my localhost. Those who will use the Visual Editor must log in, but the content of the wiki can be read without logging in.
The address is http://contractor.bg/wikimedia/index.php?title=Main_Page
I downloaded the Parsoid extension (in the extension files there is no settings.js file, so I created it according to an example).
My settings are:
in the LocalSettings.php file:
require_once "$IP/extensions/VisualEditor/VisualEditor.php";
$wgDefaultUserOptions['visualeditor-enable'] = 1;
$wgHiddenPrefs[] = 'visualeditor-enable';
wfLoadExtension( 'Parsoid' );
$wgVisualEditorParsoidURL = 'http://contractor.bg:2083';
$wgVisualEditorParsoidPrefix = 'wikimedia';
//$wgSessionsInObjectCache = true;
//$wgVisualEditorParsoidForwardCookies = true;
//$wgVisualEditorParsoidTimeout = 120;
I tried with to uncomment the last lines, but it still does not work.
In the settings.js file:
parsoidConfig.setMwApi( 'wikimedia', { uri: 'http://contractor.bg/wikimedia/api.php' } ); // I also tried setting an interwiki value, I am not quite sure what is the difference)
parsoidConfig.serverPort = 2083;
parsoidConfig.serverInterface = 'contractor.bg';
parsoidConfig.strictSSL = false;
parsoidConfig.allowCORS = 'contractor.bg/wikimedia'; // I also tried only contractor.bg)
At the moment when I try to Edit a page with the Visual Editor, I receive an error:
Error loading data from server: 401: parsoidserver-http: HTTP 401. Would you like to retry?

Parsoid is not a MediaWiki extension (well, there was an extension with this name as a support mechanism for the actual Parsoid, but it was never standalone and is no longer required). It is an external service.
You need to actually start the Parsoid service by running node bin/server.js from the Parsoid directory. Ensure it is actually running on the port you specify in the VisualEditor config (2083) - it looks like you have something else there.

Related

Workstation hosted vscode extension not processing message from remote hosted extension

QV https://github.com/microsoft/vscode-remote-release/issues/7736
I have two extensions. One of them is of uiKind workspace and may run locally or remotely depending on the workspace, and the other is of uiKind ui and always runs locally.
The ui extension is responsible for spawning a browser on the user's workstation to load a URI provided by the argument of a command print.launchBrowser that it registers using vscode.commands.registerCommand
The workspace extension uses vscode.commands.executeCommand to invoke print.launchBrowser.
The point of this arrangement is to allow the browser to be launched on the workstation irrespective of whether the extension host is local or remote.
This should work. The following documentation explicitly says it works: https://code.visualstudio.com/api/advanced-topics/remote-extensions#communicating-between-extensions-using-commands
However, when I test it works only when both extensions run on the workstation.
Before anyone tells me to use vscode.env.openExternal(Uri) I am aware of this and am using it to launch the default browser, but this is no use for launching a non-default browser. Many of my users exploit the support for an alternate browser to use Chrome for printing while using a less invasive alternative as their daily drive.
What could cause this to fail? Here's the abovementioned documentation:
Some extensions return APIs as a part of their activation that are intended for use by other extensions (via vscode.extension.getExtension(extensionName).exports). While these will work if all extensions involved are on the same side (either all UI Extensions or all Workspace Extensions), these will not work between UI and Workspace Extensions.
Fortunately, VS Code automatically routes any executed commands to the correct extension regardless of its location. You can freely invoke any command (including those provided by other extensions) without worrying about impacts.
That's not ambiguous.
Since the code for the browser agent is very short I present it in its entirety.
import * as vscode from 'vscode';
import * as child_process from "child_process";
export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(vscode.commands.registerCommand("print.launchBrowser", url => {
const browserPath = vscode.workspace.getConfiguration("print").browserPath;
child_process.exec(`${escapePath(browserPath)} ${url}`, (error: child_process.ExecException | null, stdout: string, stderr: string) => {
if (error || stderr) {
const err = error ? error.message : stderr;
if (!err.startsWith("[")) {
vscode.window.showErrorMessage(err);
}
}
});
}));
}
function escapePath(path: string) {
switch (process.platform) {
case "win32":
return path.includes('"') || !path.includes(" ") ? path : `"${path}"`;
default:
return path.replace(/ /g, "\\ ");
}
}
Code to call it is straightforward. Any extension containing the following should open a browser window and load the bing.com default page, although if you want to use the agent above you'll need to either supply the print.browserPath setting with a value containing the workstation path to a browser or put in such a path as a literal for testing purposes.
There aren't any tests for things like whether browserPath has a value that resolves to a file. That's all in the calling extension, which is designed to use the agent only when it runs in a remote workspace. The agent is essentially nothing but a platform independent remote procedure call.
vscode.commands.executeCommand("print.launchBrowser", "https://bing.com");
All this has been tested and failed on two separate computers and also with VS Code Insiders 1.75.0, which also resolves the question of whether I have a borked VS Code installation.

How can I replace the server in Web Component Tester

I have a project set up based around the Polymer Starter Kit, which includes Web-Component-Tester
This project includes php server code which I would also like to test by writing tests to run in the browser which will utilise the PHP server code through Ajax Calls.
This implies replacing the server that Web Component Tester is using ONLY when testing server side code. I hope to make a separate gulp task for this.
Unfortunately, I don't understand the relationship between WCT, Selenium and what ever server is run currently. I can see that WCT command starts Selenium, but I can't find out what the web server is and how that is started. I suspect it is WCT, because there is configuration of the mapping of directories to urls, but other than that I haven't a clue, despite trying to read the code.
Can someone explain how I go about making it run its own server when testing the client, but relying on an already set up web server (nginx) when running the server. I can set nginx to run from local host, or an other domain if that is a way to choose a different configuration.
EDIT: I have now found that runner/webserver.js starts an express server, and that urls get mapped so the base directory for the test runner and the bower_components directory both get mapped to the /components url.
What is currently confusing me is in what circumstances this gets run. It appears that loading plugins somehow does it, but my understanding from reading the code for this is tenuous.
The answer is that web component tester itself has a comment in the runner/config.js file.
In wct-conf.js, you can use registerHooks key into the Object that gets returned to add a function that does
registerHooks: function(wct) {
wct.hook('prepare:webserver', function(app, done) {
var proxy = require('express-http-proxy');
app.use('/api',
proxy('pas.dev', {
forwardPath: function(req, res) {
return require('url').parse(req.url).path;
}
})
);
done();
});
This register hook function allows you to provide a route (/api in my case) which this proxies to a server which can run the php scripts.

MobileFirst JavaScript adapter load local config file

I am creating multiple applications which works the same. For every application I use an adapter which contains the same procedures, but perform the request to a different back end (same host, only different path).
The thing I would like is to add a configuration file (json / xml) to the adapters which I can load and fetch some information from such as the path so I know which back end I need to call. The configuration is now in top of the file, but in the future it would be lovely to be able to update the adapter without changing the configuration afterwards.
Is there a way to load a second file located in the same directory (as where the adapter xml and implementation file are)? I tried using XMLHttpRequest, but this doesn't work as it is unavailable. The code I tried, but couldn't test as the fifth line already breaks.
var config = null;
function loadConfiguration() {
var loader = new XMLHttpRequest();
loader.overrideMimeType('application/json');
loader.open('GET', 'config.json', false);
loader.onreadystatechange = function () {
// Only for async calls.
config = loader.responseText;
};
config = loader.send();
}
If there is a better way, I would love to hear it! We upgraded to MFPF 7.0 if there are any new possibilities.
You cannot do this with JavaScript adapters, however in MFPF 7.0 there is a new type of adapters: Java adapters. Using Java adapters you can achieve this.
The following blog post explains how you can provide a single adapter that will allow you to point to different hosts or differents paths in the same host, etc...
See here: Changing the adapter host at runtime

How to load local resources?

How can I access the resources (CSS, JS and images stored in the project folders) from Worklight?
For example is there an absolute path (a Worklight URL) that points to local internal Worklight resources? Or is maybe another way to load resources from filesystem?
(The reason I'm trying to load resources from local is to speed up the page loading)
Edit: from discussion in the comments it sounds like only looking at the filesystem in the rooted device should suffice.
Edit 2: If what you are looking for is the fastest option to load resources, you shouldn't load them remotely to begin with. Put the index.html in the device. You can't both use Portal to load content remotely, and expect fast loading time. By definition, by loading content remotely, you Will experience possible slowdowns.
Worklight does not supply this path.
Theoretically, you may be able to access the application's sandbox (and thus the web resources) by using the Cordova File API.
You can get a reference to the device's filesystem:
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
From there you could access the application's sandbox and find the desired file(s). Since you are the one putting the resources in the app, you should know where you've placed it.
function gotFS(fileSystem) {
fileSystem.root.getFile("readme.txt", null, gotFileEntry, fail);
}
To experiment and find out the paths to the content, you can root your device and then via Eclipse you could traverse the file system. This way you should be able to find the path to the file you've placed.
The only way I managed to access local fiiles in Worklight running an Android environment is using a XMLHttpRequest:
//Works only on Android
function prendiCaricaRisorsaWorklight(percorsoPiuNomeFile) {
var xmlhttp = new XMLHttpRequest();
var risposta = "";
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4
&& (xmlhttp.status == 200 || xmlhttp.status == 0)) {
risposta = xmlhttp.responseText;
alert(risposta);
}
}
xmlhttp.open("GET", "file:///android_asset/www/default/"
+ percorsoPiuNomeFile, true);
xmlhttp.send(null);
}
Usage example:
prendiCaricaRisorsaWorklight("css/cssInterno.css");
prendiCaricaRisorsaWorklight("js/jsInterno.js");
This shows on Android an alert with the file content.

Unable to configure SabreDAV to test Webdav and CardDAV

Steps I followed:
Downloaded the Sabredav zip file - unzipped it.
Downloaded apache webserver 2.2 and PHP 5.3
Then followed the instructions mentioned in the 'get Started' section on Sabredav website.
Created 'data and public' fiels (located them in /sabredav/vendor/)
Created the server.php file (located it in /sabredav/vendor/)
Now tried to open the server.php file in browser -
Here it opens using the file protocol..
Fails to open in expected - 'http ://mydomain/sabredav/server.php
Can anybody please help me on this ?
Thanks
In server.php, use the browser plugin tu see files in Public folder.
Your server must be like this:
include 'SabreDAV/vendor/autoload.php';
use
Sabre\DAV;
$rootDirectory = new DAV\FS\Directory('public');
// The server object is responsible for making sense out of the WebDAV protocol
$server = new DAV\Server($rootDirectory);
// If your server is not on your webroot, make sure the following line has the correct information
$server->setBaseUri('/server.php'); // if its in some kind of home directory
// The lock manager is reponsible for making sure users don't overwrite each others changes. Change 'data' to a different
// directory, if you're storing your data somewhere else.
$lockBackend = new DAV\Locks\Backend\File('data/locks');
$lockPlugin = new DAV\Locks\Plugin($lockBackend);
$server->addPlugin($lockPlugin);
$server->addPlugin(new \Sabre\DAV\Browser\GuessContentType());
$plugin = new \Sabre\DAV\Browser\Plugin();
$server->addPlugin($plugin);
// All we need to do now, is to fire up the server
$server->exec();