Topic on Talk:Parsoid

Parsoid and Private wiki

6
Summary by Arlolra

Determine the value of $_SERVER['REMOTE_ADDR']

Hvdeynde (talkcontribs)

Visual Editor (and hence Parsoid) work fine, but when I want to make this wiki a private one (by denying read access to anyone who is not logged in), it stops working.

I tried changing

if ( $_SERVER['REMOTE_ADDR'] == '127.0.0.1' ) {
  $wgGroupPermissions['*']['read'] = true;
  $wgGroupPermissions['*']['edit'] = true;
};

to

if ( $_SERVER['REMOTE_ADDR'] == '127.0.0.1' ) {
  $wgGroupPermissions['*']['read'] = true;
  $wgGroupPermissions['*']['edit'] = true;
} else {
  $wgGroupPermissions['user']['read'] = true;
  $wgGroupPermissions['*']['read'] = false;
};

But that results in a fatal request because of lack of read permissions:

{"name":"../src/lib/index.js","hostname":"edgwiki","pid":5213,"level":60,"logType":"fatal/request","wiki":"wiki$0","title":"NS_SBX:SBX_Sandbox_Test_Page_1","oldId":null,"reqId":null,"userAgent":"VisualEditor-MediaWiki/1.28.1","msg":"API response Error for TemplateRequest: request=; error={\"code\":\"readapidenied\",\"info\":\"You need read permission to use this module\",\"*\":\"See http://edgwiki.hit.local/hit-wiki/api.php for API usage\"}","stack":"Error: API response Error for TemplateRequest: request=; error={\"code\":\"readapidenied\",\"info\":\"You need read permission to use this module\",\"*\":\"See http://edgwiki.hit.local/hit-wiki/api.php for API usage\"}\n    at TemplateRequest.ApiRequest._errorObj (/usr/lib/parsoid/src/lib/mw/ApiRequest.js:346:9)\n    at TemplateRequest._handleJSON (/usr/lib/parsoid/src/lib/mw/ApiRequest.js:551:16)\n    at TemplateRequest.ApiRequest._handleBody (/usr/lib/parsoid/src/lib/mw/ApiRequest.js:473:7)\n    at TemplateRequest.ApiRequest._requestCB (/usr/lib/parsoid/src/lib/mw/ApiRequest.js:420:8)\n    at Request.self.callback (/usr/lib/parsoid/node_modules/request/request.js:186:22)\n    at emitTwo (events.js:87:13)\n    at Request.emit (events.js:172:7)\n    at Request.<anonymous> (/usr/lib/parsoid/node_modules/request/request.js:1081:10)\n    at emitOne (events.js:77:13)\n    at Request.emit (events.js:169:7)\n    at IncomingMessage.<anonymous> (/usr/lib/parsoid/node_modules/request/request.js:1001:12)\n    at IncomingMessage.g (events.js:260:16)\n    at emitNone (events.js:72:20)\n    at IncomingMessage.emit (events.js:166:7)\n    at endReadableNT (_stream_readable.js:905:12)\n    at nextTickCallbackWith2Args (node.js:441:9)","longMsg":"API response Error for TemplateRequest: request=; error={\"code\":\"readapidenied\",\"info\":\"You need read permission to use this module\",\"*\":\"See http://edgwiki.hit.local/hit-wiki/api.php for API usage\"}","levelPath":"fatal/request","time":"2017-05-24T13:37:38.201Z","v":0}

Could anyone assist me with this issue?

Arlolra (talkcontribs)
Hvdeynde (talkcontribs)
Arlolra (talkcontribs)

Did you confirm what value of $_SERVER['REMOTE_ADDR'] you're getting?

Try setting something like this in your LocalSettings.php,

ini_set( 'error_log', '/tmp/php-error.log' );

then,

error_log( $_SERVER['REMOTE_ADDR'] );

Hvdeynde (talkcontribs)

That is a useful trick. Not knowing PHP, I've been wondering how to check the values of such variables.

In this case, $_SERVER['REMOTE_ADDR'] has the value of the server's IP address, not 127.0.0.1, which was the value I expected.

Hvdeynde (talkcontribs)

P.S. Replacing '127.0.0.1' in Andru's example by the server's actual IP address works fine as well.