2012-05-25 19:50:48 +00:00
|
|
|
<?php
|
2012-07-19 00:11:26 +00:00
|
|
|
/**
|
2015-09-14 16:13:31 +00:00
|
|
|
* Parsoid/RESTBase+MediaWiki API wrapper.
|
2012-07-19 21:25:16 +00:00
|
|
|
*
|
2012-07-19 00:11:26 +00:00
|
|
|
* @file
|
|
|
|
* @ingroup Extensions
|
2017-01-03 16:58:33 +00:00
|
|
|
* @copyright 2011-2017 VisualEditor Team and others; see AUTHORS.txt
|
2012-07-19 00:11:26 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
2016-12-31 04:37:10 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
|
2012-05-25 19:50:48 +00:00
|
|
|
class ApiVisualEditor extends ApiBase {
|
2014-08-13 08:15:42 +00:00
|
|
|
/**
|
|
|
|
* @var Config
|
|
|
|
*/
|
|
|
|
protected $veConfig;
|
|
|
|
|
2014-12-18 00:49:55 +00:00
|
|
|
/**
|
|
|
|
* @var VirtualRESTServiceClient
|
|
|
|
*/
|
|
|
|
protected $serviceClient;
|
|
|
|
|
2014-08-13 08:15:42 +00:00
|
|
|
public function __construct( ApiMain $main, $name, Config $config ) {
|
|
|
|
parent::__construct( $main, $name );
|
|
|
|
$this->veConfig = $config;
|
2016-02-17 16:18:02 +00:00
|
|
|
$this->serviceClient = new VirtualRESTServiceClient( new MultiHttpClient( [] ) );
|
2015-03-04 14:52:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates the virtual REST service object to be used in VE's API calls. The
|
|
|
|
* method determines whether to instantiate a ParsoidVirtualRESTService or a
|
|
|
|
* RestbaseVirtualRESTService object based on configuration directives: if
|
|
|
|
* $wgVirtualRestConfig['modules']['restbase'] is defined, RESTBase is chosen,
|
|
|
|
* otherwise Parsoid is used (either by using the MW Core config, or the
|
|
|
|
* VE-local one).
|
|
|
|
*
|
|
|
|
* @return VirtualRESTService the VirtualRESTService object to use
|
|
|
|
*/
|
2017-05-08 23:42:20 +00:00
|
|
|
protected function getVRSObject() {
|
2015-03-04 14:52:07 +00:00
|
|
|
// the params array to create the service object with
|
2016-02-17 16:18:02 +00:00
|
|
|
$params = [];
|
2015-03-04 14:52:07 +00:00
|
|
|
// the VRS class to use, defaults to Parsoid
|
2016-10-27 19:33:17 +00:00
|
|
|
$class = ParsoidVirtualRESTService::class;
|
2015-03-04 14:52:07 +00:00
|
|
|
$config = $this->veConfig;
|
2016-02-05 20:37:55 +00:00
|
|
|
// The global virtual rest service config object, if any
|
2015-03-04 14:52:07 +00:00
|
|
|
$vrs = $this->getConfig()->get( 'VirtualRestConfig' );
|
|
|
|
if ( isset( $vrs['modules'] ) && isset( $vrs['modules']['restbase'] ) ) {
|
|
|
|
// if restbase is available, use it
|
|
|
|
$params = $vrs['modules']['restbase'];
|
2017-05-04 22:27:27 +00:00
|
|
|
// backward compatibility
|
|
|
|
$params['parsoidCompat'] = false;
|
2016-10-27 19:33:17 +00:00
|
|
|
$class = RestbaseVirtualRESTService::class;
|
2015-03-04 14:52:07 +00:00
|
|
|
} elseif ( isset( $vrs['modules'] ) && isset( $vrs['modules']['parsoid'] ) ) {
|
|
|
|
// there's a global parsoid config, use it next
|
|
|
|
$params = $vrs['modules']['parsoid'];
|
2015-06-13 04:54:23 +00:00
|
|
|
$params['restbaseCompat'] = true;
|
2015-03-04 14:52:07 +00:00
|
|
|
} else {
|
2016-02-05 20:37:55 +00:00
|
|
|
// No global modules defined, so no way to contact the document server.
|
|
|
|
$this->dieUsage(
|
|
|
|
'The VirtualRESTService for the document server is not defined; see ' .
|
|
|
|
'https://www.mediawiki.org/wiki/Extension:VisualEditor',
|
|
|
|
'no_vrs'
|
|
|
|
);
|
2015-03-04 14:52:07 +00:00
|
|
|
}
|
|
|
|
// merge the global and service-specific params
|
|
|
|
if ( isset( $vrs['global'] ) ) {
|
|
|
|
$params = array_merge( $vrs['global'], $params );
|
|
|
|
}
|
|
|
|
// set up cookie forwarding
|
2016-07-12 17:01:24 +00:00
|
|
|
if ( $params['forwardCookies'] ) {
|
2015-03-04 14:52:07 +00:00
|
|
|
$params['forwardCookies'] = RequestContext::getMain()->getRequest()->getHeader( 'Cookie' );
|
|
|
|
} else {
|
|
|
|
$params['forwardCookies'] = false;
|
|
|
|
}
|
|
|
|
// create the VRS object and return it
|
|
|
|
return new $class( $params );
|
2014-02-07 16:10:59 +00:00
|
|
|
}
|
|
|
|
|
2016-09-08 04:28:59 +00:00
|
|
|
protected function requestRestbase( $method, $path, $params, $reqheaders = [] ) {
|
2016-03-30 00:05:50 +00:00
|
|
|
global $wgVersion;
|
2016-02-17 16:18:02 +00:00
|
|
|
$request = [
|
2014-12-18 00:49:55 +00:00
|
|
|
'method' => $method,
|
2015-06-13 04:54:23 +00:00
|
|
|
'url' => '/restbase/local/v1/' . $path
|
2016-02-17 16:18:02 +00:00
|
|
|
];
|
2014-12-18 00:49:55 +00:00
|
|
|
if ( $method === 'GET' ) {
|
|
|
|
$request['query'] = $params;
|
2014-04-18 20:17:02 +00:00
|
|
|
} else {
|
2014-12-18 00:49:55 +00:00
|
|
|
$request['body'] = $params;
|
2014-04-18 20:17:02 +00:00
|
|
|
}
|
2016-02-27 01:58:13 +00:00
|
|
|
// Should be synchronised with modules/ve-mw/init/ve.init.mw.ArticleTargetLoader.js
|
2016-03-02 15:37:00 +00:00
|
|
|
$reqheaders['Accept'] = 'text/html; charset=utf-8; profile="mediawiki.org/specs/html/1.2.0"';
|
2016-03-30 00:05:50 +00:00
|
|
|
$reqheaders['User-Agent'] = 'VisualEditor-MediaWiki/' . $wgVersion;
|
2016-10-27 15:54:46 +00:00
|
|
|
$reqheaders['Api-User-Agent'] = 'VisualEditor-MediaWiki/' . $wgVersion;
|
2015-10-08 22:16:56 +00:00
|
|
|
$request['headers'] = $reqheaders;
|
2014-12-18 00:49:55 +00:00
|
|
|
$response = $this->serviceClient->run( $request );
|
|
|
|
if ( $response['code'] === 200 && $response['error'] === "" ) {
|
2015-03-25 02:36:44 +00:00
|
|
|
// If response was served directly from Varnish, use the response
|
|
|
|
// (RP) header to declare the cache hit and pass the data to the client.
|
2015-02-16 01:13:54 +00:00
|
|
|
$headers = $response['headers'];
|
2015-03-25 02:36:44 +00:00
|
|
|
$rp = null;
|
2015-02-16 01:13:54 +00:00
|
|
|
if ( isset( $headers['x-cache'] ) && strpos( $headers['x-cache'], 'hit' ) !== false ) {
|
2015-03-25 02:36:44 +00:00
|
|
|
$rp = 'cached-response=true';
|
2014-04-18 20:17:02 +00:00
|
|
|
}
|
2015-03-25 02:36:44 +00:00
|
|
|
if ( $rp !== null ) {
|
2014-04-18 20:17:02 +00:00
|
|
|
$resp = $this->getRequest()->response();
|
2015-03-25 02:36:44 +00:00
|
|
|
$resp->header( 'X-Cache: ' . $rp );
|
2014-04-18 20:17:02 +00:00
|
|
|
}
|
2014-12-18 00:49:55 +00:00
|
|
|
} elseif ( $response['error'] !== '' ) {
|
2016-11-03 19:16:57 +00:00
|
|
|
$this->dieWithError(
|
|
|
|
[ 'apierror-visualeditor-docserver-http-error', wfEscapeWikiText( $response['error'] ) ],
|
2017-01-04 14:59:51 +00:00
|
|
|
'apierror-visualeditor-docserver-http-error'
|
2016-11-03 19:16:57 +00:00
|
|
|
);
|
2017-05-04 22:27:27 +00:00
|
|
|
} else {
|
|
|
|
// error null, code not 200
|
2016-11-03 19:16:57 +00:00
|
|
|
$this->dieWithError(
|
|
|
|
[ 'apierror-visualeditor-docserver-http', $response['code'] ],
|
2017-01-04 14:59:51 +00:00
|
|
|
'apierror-visualeditor-docserver-http'
|
2016-11-03 19:16:57 +00:00
|
|
|
);
|
2014-04-18 20:17:02 +00:00
|
|
|
}
|
2014-12-18 00:49:55 +00:00
|
|
|
return $response['body'];
|
2014-04-18 20:17:02 +00:00
|
|
|
}
|
|
|
|
|
2014-10-22 22:47:21 +00:00
|
|
|
protected function pstWikitext( $title, $wikitext ) {
|
2015-03-17 20:43:03 +00:00
|
|
|
return ContentHandler::makeContent( $wikitext, $title, CONTENT_MODEL_WIKITEXT )
|
2014-10-22 22:47:21 +00:00
|
|
|
->preSaveTransform(
|
|
|
|
$title,
|
|
|
|
$this->getUser(),
|
|
|
|
WikiPage::factory( $title )->makeParserOptions( $this->getContext() )
|
|
|
|
)
|
|
|
|
->serialize( 'text/x-wiki' );
|
|
|
|
}
|
|
|
|
|
2014-04-18 20:19:54 +00:00
|
|
|
protected function parseWikitextFragment( $title, $wikitext ) {
|
2015-06-13 04:54:23 +00:00
|
|
|
return $this->requestRestbase(
|
2015-01-07 21:56:19 +00:00
|
|
|
'POST',
|
|
|
|
'transform/wikitext/to/html/' . urlencode( $title->getPrefixedDBkey() ),
|
2016-02-17 16:18:02 +00:00
|
|
|
[
|
2014-12-18 00:49:55 +00:00
|
|
|
'wikitext' => $wikitext,
|
2015-09-30 14:31:05 +00:00
|
|
|
'body_only' => 1,
|
2016-02-17 16:18:02 +00:00
|
|
|
]
|
2014-04-18 20:19:54 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-12-04 15:30:21 +00:00
|
|
|
protected function getLangLinks( $title ) {
|
2016-02-17 16:18:02 +00:00
|
|
|
$apiParams = [
|
2013-12-04 15:30:21 +00:00
|
|
|
'action' => 'query',
|
|
|
|
'prop' => 'langlinks',
|
|
|
|
'lllimit' => 500,
|
|
|
|
'titles' => $title->getPrefixedDBkey(),
|
2016-02-17 16:18:02 +00:00
|
|
|
];
|
2013-12-04 15:30:21 +00:00
|
|
|
$api = new ApiMain(
|
|
|
|
new DerivativeRequest(
|
|
|
|
$this->getRequest(),
|
|
|
|
$apiParams,
|
2017-05-04 22:27:27 +00:00
|
|
|
/* was posted? */ false
|
2013-12-04 15:30:21 +00:00
|
|
|
),
|
2017-05-04 22:27:27 +00:00
|
|
|
/* enable write? */ true
|
2013-12-04 15:30:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$api->execute();
|
2016-09-08 17:28:30 +00:00
|
|
|
$result = $api->getResult()->getResultData();
|
2016-09-08 17:15:56 +00:00
|
|
|
if ( !isset( $result['query']['pages'][$title->getArticleID()] ) ) {
|
2013-12-04 15:30:21 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-09-08 17:15:56 +00:00
|
|
|
$page = $result['query']['pages'][$title->getArticleID()];
|
|
|
|
if ( !isset( $page['langlinks'] ) ) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
$langlinks = $page['langlinks'];
|
2013-12-04 15:30:21 +00:00
|
|
|
$langnames = Language::fetchLanguageNames();
|
|
|
|
foreach ( $langlinks as $i => $lang ) {
|
2017-01-10 22:27:25 +00:00
|
|
|
if ( isset( $langnames[$lang['lang']] ) ) {
|
|
|
|
$langlinks[$i]['langname'] = $langnames[$lang['lang']];
|
|
|
|
}
|
2013-12-04 15:30:21 +00:00
|
|
|
}
|
|
|
|
return $langlinks;
|
|
|
|
}
|
|
|
|
|
2012-05-25 19:50:48 +00:00
|
|
|
public function execute() {
|
2017-05-02 18:42:28 +00:00
|
|
|
$this->serviceClient->mount( '/restbase/', $this->getVRSObject() );
|
|
|
|
|
2012-07-21 17:37:20 +00:00
|
|
|
$user = $this->getUser();
|
2012-05-25 19:50:48 +00:00
|
|
|
$params = $this->extractRequestParams();
|
2014-03-21 00:44:30 +00:00
|
|
|
|
2015-03-26 19:32:01 +00:00
|
|
|
$title = Title::newFromText( $params['page'] );
|
2016-10-25 20:44:26 +00:00
|
|
|
if ( $title && $title->isSpecial( 'CollabPad' ) ) {
|
|
|
|
// Convert Special:CollabPad/MyPage to MyPage so we can parsefragment properly
|
|
|
|
$title = Title::newFromText( preg_replace( '`^([^/]+/)`', '', $params['page'] ) );
|
|
|
|
}
|
2015-03-26 19:32:01 +00:00
|
|
|
if ( !$title ) {
|
2016-11-03 19:16:57 +00:00
|
|
|
$this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $params['page'] ) ] );
|
2012-11-14 18:33:57 +00:00
|
|
|
}
|
2015-04-02 00:41:59 +00:00
|
|
|
|
2016-02-17 16:18:02 +00:00
|
|
|
$parserParams = [];
|
2013-05-15 23:51:11 +00:00
|
|
|
if ( isset( $params['oldid'] ) ) {
|
|
|
|
$parserParams['oldid'] = $params['oldid'];
|
|
|
|
}
|
2012-08-23 19:01:07 +00:00
|
|
|
|
2015-03-26 19:32:01 +00:00
|
|
|
wfDebugLog( 'visualeditor', "called on '$title' with paction: '{$params['paction']}'" );
|
2013-05-15 21:17:06 +00:00
|
|
|
switch ( $params['paction'] ) {
|
|
|
|
case 'parse':
|
2016-05-26 12:08:26 +00:00
|
|
|
case 'wikitext':
|
2015-03-13 22:15:17 +00:00
|
|
|
case 'metadata':
|
2013-05-15 21:17:06 +00:00
|
|
|
// Dirty hack to provide the correct context for edit notices
|
2017-05-04 22:27:27 +00:00
|
|
|
// FIXME Don't write to globals! Eww.
|
|
|
|
global $wgTitle;
|
2015-03-26 19:32:01 +00:00
|
|
|
$wgTitle = $title;
|
|
|
|
RequestContext::getMain()->setTitle( $title );
|
2015-03-13 22:15:17 +00:00
|
|
|
|
|
|
|
// Get information about current revision
|
|
|
|
if ( $title->exists() ) {
|
|
|
|
$latestRevision = Revision::newFromTitle( $title );
|
|
|
|
if ( $latestRevision === null ) {
|
2016-11-03 19:16:57 +00:00
|
|
|
$this->dieWithError( 'apierror-visualeditor-latestnotfound', 'latestnotfound' );
|
2015-03-13 22:15:17 +00:00
|
|
|
}
|
|
|
|
$revision = null;
|
|
|
|
if ( !isset( $parserParams['oldid'] ) || $parserParams['oldid'] === 0 ) {
|
|
|
|
$parserParams['oldid'] = $latestRevision->getId();
|
|
|
|
$revision = $latestRevision;
|
|
|
|
} else {
|
|
|
|
$revision = Revision::newFromId( $parserParams['oldid'] );
|
|
|
|
if ( $revision === null ) {
|
2016-11-03 19:16:57 +00:00
|
|
|
$this->dieWithError( [ 'apierror-nosuchrevid', $parserParams['oldid'] ], 'oldidnotfound' );
|
2015-03-13 22:15:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$restoring = $revision && !$revision->isCurrent();
|
|
|
|
$baseTimestamp = $latestRevision->getTimestamp();
|
|
|
|
$oldid = intval( $parserParams['oldid'] );
|
|
|
|
|
2015-06-13 04:54:23 +00:00
|
|
|
// If requested, request HTML from Parsoid/RESTBase
|
2015-03-13 22:15:17 +00:00
|
|
|
if ( $params['paction'] === 'parse' ) {
|
2015-06-13 04:54:23 +00:00
|
|
|
$content = $this->requestRestbase(
|
2015-03-13 22:15:17 +00:00
|
|
|
'GET',
|
2016-04-09 02:34:34 +00:00
|
|
|
'page/html/' . urlencode( $title->getPrefixedDBkey() ) . '/' . $oldid . '?redirect=false',
|
2016-02-17 16:18:02 +00:00
|
|
|
[]
|
2015-03-13 22:15:17 +00:00
|
|
|
);
|
|
|
|
if ( $content === false ) {
|
2016-11-03 19:16:57 +00:00
|
|
|
$this->dieWithError( 'apierror-visualeditor-docserver', 'docserver' );
|
2015-03-13 22:15:17 +00:00
|
|
|
}
|
2016-05-26 12:08:26 +00:00
|
|
|
} elseif ( $params['paction'] === 'wikitext' ) {
|
|
|
|
$apiParams = [
|
|
|
|
'action' => 'query',
|
2016-11-23 00:47:42 +00:00
|
|
|
'revids' => $oldid,
|
2016-05-26 12:08:26 +00:00
|
|
|
'prop' => 'revisions',
|
2016-11-23 00:47:42 +00:00
|
|
|
'rvprop' => 'content|ids'
|
2016-05-26 12:08:26 +00:00
|
|
|
];
|
2016-09-06 19:16:55 +00:00
|
|
|
|
2016-12-18 11:30:18 +00:00
|
|
|
$section = isset( $params['section'] ) ? $params['section'] : null;
|
2016-09-06 19:16:55 +00:00
|
|
|
|
2016-12-08 19:24:10 +00:00
|
|
|
if ( $section === 'new' ) {
|
|
|
|
$content = '';
|
|
|
|
} else {
|
|
|
|
$apiParams['rvsection'] = $section;
|
|
|
|
|
|
|
|
$api = new ApiMain(
|
|
|
|
new DerivativeRequest(
|
|
|
|
$this->getRequest(),
|
|
|
|
$apiParams,
|
2017-05-04 22:27:27 +00:00
|
|
|
/* was posted? */ false
|
2016-12-08 19:24:10 +00:00
|
|
|
),
|
2017-05-04 22:27:27 +00:00
|
|
|
/* enable write? */ true
|
2016-12-08 19:24:10 +00:00
|
|
|
);
|
|
|
|
$api->execute();
|
|
|
|
$result = $api->getResult()->getResultData();
|
|
|
|
$pid = $title->getArticleID();
|
|
|
|
$content = false;
|
|
|
|
if ( isset( $result['query']['pages'][$pid]['revisions'] ) ) {
|
|
|
|
foreach ( $result['query']['pages'][$pid]['revisions'] as $revArr ) {
|
|
|
|
if ( $revArr['revid'] === $oldid ) {
|
|
|
|
$content = $revArr['content'];
|
|
|
|
}
|
2016-11-23 00:47:42 +00:00
|
|
|
}
|
|
|
|
}
|
2016-12-08 19:24:10 +00:00
|
|
|
if ( $content === false ) {
|
|
|
|
$this->dieWithError( 'apierror-visualeditor-docserver', 'docserver' );
|
|
|
|
}
|
2016-05-26 12:08:26 +00:00
|
|
|
}
|
2015-03-13 22:15:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$content = '';
|
2016-06-24 12:46:52 +00:00
|
|
|
Hooks::run( 'EditFormPreloadText', [ &$content, &$title ] );
|
|
|
|
if ( $content !== '' ) {
|
|
|
|
$content = $this->parseWikitextFragment( $title, $content );
|
|
|
|
}
|
2017-09-14 20:08:09 +00:00
|
|
|
if ( $content === '' && $params['preload'] ) {
|
|
|
|
$preloadTitle = Title::newFromText( $params['preload'] );
|
2017-09-18 19:46:38 +00:00
|
|
|
// Check for existence to avoid getting MediaWiki:Noarticletext
|
2017-09-14 20:08:09 +00:00
|
|
|
if ( $preloadTitle instanceof Title &&
|
|
|
|
$preloadTitle->exists() &&
|
|
|
|
$preloadTitle->userCan( 'read' )
|
|
|
|
) {
|
|
|
|
$preloadPage = WikiPage::factory( $preloadTitle );
|
|
|
|
if ( $preloadPage->isRedirect() ) {
|
|
|
|
$preloadTitle = $preloadPage->getRedirectTarget();
|
|
|
|
$preloadPage = WikiPage::factory( $preloadTitle );
|
|
|
|
}
|
|
|
|
|
|
|
|
$content = $preloadPage->getContent( Revision::RAW );
|
|
|
|
$parserOptions = ParserOptions::newFromUser( $wgUser );
|
|
|
|
|
|
|
|
$content = $content->preloadTransform(
|
|
|
|
$preloadTitle,
|
|
|
|
$parserOptions,
|
|
|
|
$params['preloadparams']
|
|
|
|
)->serialize();
|
|
|
|
|
|
|
|
if ( $params['paction'] !== 'wikitext' ) {
|
|
|
|
// We need to turn this transformed wikitext into parsoid html
|
|
|
|
$content = $this->parseWikitextFragment( $title, $content );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-03-13 22:15:17 +00:00
|
|
|
$baseTimestamp = wfTimestampNow();
|
|
|
|
$oldid = 0;
|
|
|
|
$restoring = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get edit notices
|
2015-03-26 19:32:01 +00:00
|
|
|
$notices = $title->getEditNotices();
|
2015-03-13 22:15:17 +00:00
|
|
|
|
|
|
|
// Anonymous user notice
|
2013-05-15 21:17:06 +00:00
|
|
|
if ( $user->isAnon() ) {
|
2014-09-02 18:56:55 +00:00
|
|
|
$notices[] = $this->msg(
|
|
|
|
'anoneditwarning',
|
|
|
|
// Log-in link
|
|
|
|
'{{fullurl:Special:UserLogin|returnto={{FULLPAGENAMEE}}}}',
|
|
|
|
// Sign-up link
|
|
|
|
'{{fullurl:Special:UserLogin/signup|returnto={{FULLPAGENAMEE}}}}'
|
|
|
|
)->parseAsBlock();
|
2012-12-11 03:40:09 +00:00
|
|
|
}
|
2015-03-13 22:15:17 +00:00
|
|
|
|
2016-12-31 17:02:33 +00:00
|
|
|
// From EditPage#showCustomIntro
|
|
|
|
if ( $params['editintro'] ) {
|
|
|
|
$eiTitle = Title::newFromText( $params['editintro'] );
|
|
|
|
if ( $eiTitle instanceof Title && $eiTitle->exists() && $eiTitle->userCan( 'read' ) ) {
|
|
|
|
global $wgParser;
|
|
|
|
$notices[] = $wgParser->parse(
|
|
|
|
'<div class="mw-editintro">{{:' . $eiTitle->getFullText() . '}}</div>',
|
|
|
|
$title,
|
|
|
|
new ParserOptions()
|
|
|
|
)->getText();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-13 22:15:17 +00:00
|
|
|
// Old revision notice
|
|
|
|
if ( $restoring ) {
|
2014-03-26 22:20:08 +00:00
|
|
|
$notices[] = $this->msg( 'editingold' )->parseAsBlock();
|
2014-03-26 21:33:19 +00:00
|
|
|
}
|
|
|
|
|
2016-03-10 18:58:41 +00:00
|
|
|
if ( wfReadOnly() ) {
|
|
|
|
$notices[] = $this->msg( 'readonlywarning', wfReadOnlyReason() );
|
|
|
|
}
|
|
|
|
|
2015-03-13 22:15:17 +00:00
|
|
|
// New page notices
|
2015-03-26 19:32:01 +00:00
|
|
|
if ( !$title->exists() ) {
|
2015-07-02 10:25:19 +00:00
|
|
|
$notices[] = $this->msg(
|
2014-03-26 21:33:19 +00:00
|
|
|
$user->isLoggedIn() ? 'newarticletext' : 'newarticletextanon',
|
2015-05-06 20:01:59 +00:00
|
|
|
wfExpandUrl( Skin::makeInternalOrExternalUrl(
|
2014-03-26 21:33:19 +00:00
|
|
|
$this->msg( 'helppage' )->inContentLanguage()->text()
|
2015-05-06 20:01:59 +00:00
|
|
|
) )
|
2014-03-26 21:33:19 +00:00
|
|
|
)->parseAsBlock();
|
2013-07-24 09:43:21 +00:00
|
|
|
// Page protected from creation
|
2015-03-26 19:32:01 +00:00
|
|
|
if ( $title->getRestrictions( 'create' ) ) {
|
2014-03-26 21:33:19 +00:00
|
|
|
$notices[] = $this->msg( 'titleprotectedwarning' )->parseAsBlock();
|
2013-05-15 21:17:06 +00:00
|
|
|
}
|
|
|
|
}
|
2014-03-26 21:33:19 +00:00
|
|
|
|
2014-04-30 19:28:29 +00:00
|
|
|
// Look at protection status to set up notices + surface class(es)
|
2016-02-17 16:18:02 +00:00
|
|
|
$protectedClasses = [];
|
|
|
|
if ( MWNamespace::getRestrictionLevels( $title->getNamespace() ) !== [ '' ] ) {
|
2014-04-16 23:16:06 +00:00
|
|
|
// Page protected from editing
|
2015-03-26 19:32:01 +00:00
|
|
|
if ( $title->isProtected( 'edit' ) ) {
|
2017-09-18 19:46:38 +00:00
|
|
|
// Is the title semi-protected?
|
2015-03-26 19:32:01 +00:00
|
|
|
if ( $title->isSemiProtected() ) {
|
2014-04-30 19:28:29 +00:00
|
|
|
$protectedClasses[] = 'mw-textarea-sprotected';
|
|
|
|
|
2014-04-16 23:16:06 +00:00
|
|
|
$noticeMsg = 'semiprotectedpagewarning';
|
|
|
|
} else {
|
2014-04-30 19:28:29 +00:00
|
|
|
$protectedClasses[] = 'mw-textarea-protected';
|
|
|
|
|
2017-09-18 19:46:38 +00:00
|
|
|
// Then it must be protected based on static groups (regular)
|
2014-04-16 23:16:06 +00:00
|
|
|
$noticeMsg = 'protectedpagewarning';
|
|
|
|
}
|
|
|
|
$notices[] = $this->msg( $noticeMsg )->parseAsBlock() .
|
2015-03-26 19:32:01 +00:00
|
|
|
$this->getLastLogEntry( $title, 'protect' );
|
2014-03-17 22:11:01 +00:00
|
|
|
}
|
|
|
|
|
2014-04-16 23:16:06 +00:00
|
|
|
// Deal with cascading edit protection
|
2015-03-26 19:32:01 +00:00
|
|
|
list( $sources, $restrictions ) = $title->getCascadeProtectionSources();
|
2014-04-16 23:16:06 +00:00
|
|
|
if ( isset( $restrictions['edit'] ) ) {
|
2014-04-30 19:28:29 +00:00
|
|
|
$protectedClasses[] = ' mw-textarea-cprotected';
|
|
|
|
|
2014-04-16 23:16:06 +00:00
|
|
|
$notice = $this->msg( 'cascadeprotectedwarning' )->parseAsBlock() . '<ul>';
|
|
|
|
// Unfortunately there's no nice way to get only the pages which cause
|
|
|
|
// editing to be restricted
|
|
|
|
foreach ( $sources as $source ) {
|
2016-12-31 04:37:10 +00:00
|
|
|
$notice .= "<li>" .
|
|
|
|
MediaWikiServices::getInstance()->getLinkRenderer()->makeLink( $source ) .
|
|
|
|
"</li>";
|
2014-04-16 23:16:06 +00:00
|
|
|
}
|
|
|
|
$notice .= '</ul>';
|
|
|
|
$notices[] = $notice;
|
|
|
|
}
|
2014-03-26 20:39:45 +00:00
|
|
|
}
|
|
|
|
|
2015-03-13 22:15:17 +00:00
|
|
|
// Permission notice
|
2016-08-28 17:16:08 +00:00
|
|
|
$permErrors = $title->getUserPermissionsErrors( 'create', $user, 'quick' );
|
2015-11-05 02:55:24 +00:00
|
|
|
if ( $permErrors && !$title->exists() ) {
|
2014-07-05 19:09:23 +00:00
|
|
|
$notices[] = $this->msg(
|
|
|
|
'permissionserrorstext-withaction', 1, $this->msg( 'action-createpage' )
|
2016-02-17 16:18:02 +00:00
|
|
|
) . "<br>" . call_user_func_array( [ $this, 'msg' ], $permErrors[0] )->parse();
|
2014-07-05 19:09:23 +00:00
|
|
|
}
|
|
|
|
|
2014-03-26 20:39:45 +00:00
|
|
|
// Show notice when editing user / user talk page of a user that doesn't exist
|
|
|
|
// or who is blocked
|
|
|
|
// HACK of course this code is partly duplicated from EditPage.php :(
|
2015-03-26 19:32:01 +00:00
|
|
|
if ( $title->getNamespace() == NS_USER || $title->getNamespace() == NS_USER_TALK ) {
|
|
|
|
$parts = explode( '/', $title->getText(), 2 );
|
2014-03-26 20:39:45 +00:00
|
|
|
$targetUsername = $parts[0];
|
2017-05-04 22:27:27 +00:00
|
|
|
$targetUser = User::newFromName(
|
|
|
|
$targetUsername,
|
|
|
|
/* allow IP users*/ false
|
|
|
|
);
|
2014-03-26 20:39:45 +00:00
|
|
|
|
|
|
|
if (
|
|
|
|
!( $targetUser && $targetUser->isLoggedIn() ) &&
|
|
|
|
!User::isIP( $targetUsername )
|
2017-05-04 22:27:27 +00:00
|
|
|
) {
|
|
|
|
// User does not exist
|
2014-03-26 20:39:45 +00:00
|
|
|
$notices[] = "<div class=\"mw-userpage-userdoesnotexist error\">\n" .
|
|
|
|
$this->msg( 'userpage-userdoesnotexist', wfEscapeWikiText( $targetUsername ) ) .
|
|
|
|
"\n</div>";
|
2016-09-08 06:22:29 +00:00
|
|
|
} elseif ( $targetUser->isBlocked() ) {
|
|
|
|
// Show log extract if the user is currently blocked
|
2014-03-26 20:39:45 +00:00
|
|
|
$notices[] = $this->msg(
|
|
|
|
'blocked-notice-logextract',
|
2017-05-04 22:27:27 +00:00
|
|
|
// Support GENDER in notice
|
|
|
|
$targetUser->getName()
|
2014-03-26 20:39:45 +00:00
|
|
|
)->parseAsBlock() . $this->getLastLogEntry( $targetUser->getUserPage(), 'block' );
|
|
|
|
}
|
2014-03-17 22:11:01 +00:00
|
|
|
}
|
Render check boxes from EditPage
EditPage has a lovely getCheckboxes() function which includes the
minor and watch checkboxes as rendered by MW core, as well as any
checkboxes extensions like FlaggedRevs might have added. Output
these in the API, render them, and send their values back.
ApiVisualEditor.php:
* Build a fake EditPage, get its checkboxes, and return them
ApiVisualEditorEdit.php:
* Pass through posted request data to ApiEdit, which passes it
through to EditPage thanks to Idab5b524b0e3 in core
ve.init.mw.ViewPageTarget.js:
* Remove minor and watch checkboxes from the save dialog template
and replace them with a generic checkbox container
* Have getSaveOptions() pull the state of all checkboxes in
** Special-case minor and watch, and pass the rest straight through
** Move normalization from true/false to presence/absence here, from
ve.init.mw.Target.prototype.save(), because here we know which ones
are checkboxes and we don't know that in save() without
special-casing
* Remove getSaveDialogHtml(), we don't need to hide checkboxes based on
rights anymore because in that case the API just won't send them to us.
** Moved logic for checking the watch checkbox down to where the same
logic for the minor checkbox already is
* Unwrap getSaveDialogHtml() in setupSaveDialog()
* Access minor and watch by their new IDs throughout
ve.init.mw.Target.js:
* Get and store checkboxes from the API
* Pass all keys straight through to the API
Bug: 49699
Change-Id: I09d02a42b05146bc9b7080ab38338ae869bf15e3
2013-07-24 06:39:03 +00:00
|
|
|
|
2015-03-13 22:15:17 +00:00
|
|
|
// Blocked user notice
|
2016-09-13 15:15:09 +00:00
|
|
|
if (
|
|
|
|
$user->isBlockedFrom( $title, true ) &&
|
|
|
|
$user->getBlock()->prevents( 'edit' ) !== false
|
2016-09-08 06:22:29 +00:00
|
|
|
) {
|
2014-03-17 21:22:41 +00:00
|
|
|
$notices[] = call_user_func_array(
|
2016-02-17 16:18:02 +00:00
|
|
|
[ $this, 'msg' ],
|
2014-03-17 21:22:41 +00:00
|
|
|
$user->getBlock()->getPermissionsError( $this->getContext() )
|
|
|
|
)->parseAsBlock();
|
|
|
|
}
|
|
|
|
|
2015-03-13 22:15:17 +00:00
|
|
|
// Blocked user notice for global blocks
|
2016-04-25 21:49:16 +00:00
|
|
|
if ( $user->isBlockedGlobally() ) {
|
|
|
|
$notices[] = call_user_func_array(
|
|
|
|
[ $this, 'msg' ],
|
|
|
|
$user->getGlobalBlock()->getPermissionsError( $this->getContext() )
|
|
|
|
)->parseAsBlock();
|
2014-04-22 00:22:48 +00:00
|
|
|
}
|
|
|
|
|
Render check boxes from EditPage
EditPage has a lovely getCheckboxes() function which includes the
minor and watch checkboxes as rendered by MW core, as well as any
checkboxes extensions like FlaggedRevs might have added. Output
these in the API, render them, and send their values back.
ApiVisualEditor.php:
* Build a fake EditPage, get its checkboxes, and return them
ApiVisualEditorEdit.php:
* Pass through posted request data to ApiEdit, which passes it
through to EditPage thanks to Idab5b524b0e3 in core
ve.init.mw.ViewPageTarget.js:
* Remove minor and watch checkboxes from the save dialog template
and replace them with a generic checkbox container
* Have getSaveOptions() pull the state of all checkboxes in
** Special-case minor and watch, and pass the rest straight through
** Move normalization from true/false to presence/absence here, from
ve.init.mw.Target.prototype.save(), because here we know which ones
are checkboxes and we don't know that in save() without
special-casing
* Remove getSaveDialogHtml(), we don't need to hide checkboxes based on
rights anymore because in that case the API just won't send them to us.
** Moved logic for checking the watch checkbox down to where the same
logic for the minor checkbox already is
* Unwrap getSaveDialogHtml() in setupSaveDialog()
* Access minor and watch by their new IDs throughout
ve.init.mw.Target.js:
* Get and store checkboxes from the API
* Pass all keys straight through to the API
Bug: 49699
Change-Id: I09d02a42b05146bc9b7080ab38338ae869bf15e3
2013-07-24 06:39:03 +00:00
|
|
|
// HACK: Build a fake EditPage so we can get checkboxes from it
|
2017-05-04 22:27:27 +00:00
|
|
|
// Deliberately omitting ,0 so oldid comes from request
|
|
|
|
$article = new Article( $title );
|
2016-12-18 19:04:20 +00:00
|
|
|
$editPage = new EditPage( $article );
|
2013-08-02 18:37:30 +00:00
|
|
|
$req = $this->getRequest();
|
2016-12-18 19:04:20 +00:00
|
|
|
$req->setVal( 'format', $editPage->contentFormat );
|
2017-05-04 22:27:27 +00:00
|
|
|
// By reference for some reason (T54466)
|
|
|
|
$editPage->importFormData( $req );
|
2016-04-03 12:55:20 +00:00
|
|
|
$states = [
|
|
|
|
'minor' => $user->getOption( 'minordefault' ) && $title->exists(),
|
|
|
|
'watch' => $user->getOption( 'watchdefault' ) ||
|
|
|
|
( $user->getOption( 'watchcreations' ) && !$title->exists() ) ||
|
|
|
|
$user->isWatched( $title ),
|
|
|
|
];
|
2017-08-31 15:18:45 +00:00
|
|
|
$checkboxesDef = $editPage->getCheckboxesDefinition( $states );
|
2017-09-19 19:14:25 +00:00
|
|
|
$checkboxesMessagesList = [];
|
|
|
|
foreach ( $checkboxesDef as $name => &$options ) {
|
2017-08-31 15:18:45 +00:00
|
|
|
if ( isset( $options['tooltip'] ) ) {
|
2017-09-19 19:14:25 +00:00
|
|
|
$checkboxesMessagesList[] = "accesskey-{$options['tooltip']}";
|
|
|
|
$checkboxesMessagesList[] = "tooltip-{$options['tooltip']}";
|
2017-08-31 15:18:45 +00:00
|
|
|
}
|
|
|
|
if ( isset( $options['title-message'] ) ) {
|
2017-09-19 19:14:25 +00:00
|
|
|
$checkboxesMessagesList[] = $options['title-message'];
|
|
|
|
if ( !is_string( $options['title-message'] ) ) {
|
|
|
|
// Extract only the key. Any parameters are included in the fake message definition
|
|
|
|
// passed via $checkboxesMessages. (This changes $checkboxesDef by reference.)
|
|
|
|
$options['title-message'] = $this->msg( $options['title-message'] )->getKey();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$checkboxesMessagesList[] = $options['label-message'];
|
|
|
|
if ( !is_string( $options['label-message'] ) ) {
|
|
|
|
// Extract only the key. Any parameters are included in the fake message definition
|
|
|
|
// passed via $checkboxesMessages. (This changes $checkboxesDef by reference.)
|
|
|
|
$options['label-message'] = $this->msg( $options['label-message'] )->getKey();
|
2017-08-31 15:18:45 +00:00
|
|
|
}
|
2017-09-19 19:14:25 +00:00
|
|
|
}
|
|
|
|
$checkboxesMessages = [];
|
|
|
|
foreach ( $checkboxesMessagesList as $messageSpecifier ) {
|
|
|
|
// $messageSpecifier may be a string or a Message object
|
|
|
|
$message = $this->msg( $messageSpecifier );
|
|
|
|
$checkboxesMessages[ $message->getKey() ] = $message->plain();
|
2017-08-31 15:18:45 +00:00
|
|
|
}
|
2016-12-18 19:04:20 +00:00
|
|
|
$templates = $editPage->makeTemplatesOnThisPageList( $editPage->getTemplates() );
|
Render check boxes from EditPage
EditPage has a lovely getCheckboxes() function which includes the
minor and watch checkboxes as rendered by MW core, as well as any
checkboxes extensions like FlaggedRevs might have added. Output
these in the API, render them, and send their values back.
ApiVisualEditor.php:
* Build a fake EditPage, get its checkboxes, and return them
ApiVisualEditorEdit.php:
* Pass through posted request data to ApiEdit, which passes it
through to EditPage thanks to Idab5b524b0e3 in core
ve.init.mw.ViewPageTarget.js:
* Remove minor and watch checkboxes from the save dialog template
and replace them with a generic checkbox container
* Have getSaveOptions() pull the state of all checkboxes in
** Special-case minor and watch, and pass the rest straight through
** Move normalization from true/false to presence/absence here, from
ve.init.mw.Target.prototype.save(), because here we know which ones
are checkboxes and we don't know that in save() without
special-casing
* Remove getSaveDialogHtml(), we don't need to hide checkboxes based on
rights anymore because in that case the API just won't send them to us.
** Moved logic for checking the watch checkbox down to where the same
logic for the minor checkbox already is
* Unwrap getSaveDialogHtml() in setupSaveDialog()
* Access minor and watch by their new IDs throughout
ve.init.mw.Target.js:
* Get and store checkboxes from the API
* Pass all keys straight through to the API
Bug: 49699
Change-Id: I09d02a42b05146bc9b7080ab38338ae869bf15e3
2013-07-24 06:39:03 +00:00
|
|
|
|
2014-03-11 00:46:26 +00:00
|
|
|
// HACK: Find out which red links are on the page
|
|
|
|
// We do the lookup for the current version. This might not be entirely complete
|
|
|
|
// if we're loading an oldid, but it'll probably be close enough, and LinkCache
|
|
|
|
// will automatically request any additional data it needs.
|
2017-01-13 00:33:49 +00:00
|
|
|
// We only do this for visual edits, as the wikitext editor doesn't need to know
|
|
|
|
// about redlinks on the page. If the user switches to VE, they will do a fresh
|
|
|
|
// metadata request at that point.
|
|
|
|
$links = null;
|
|
|
|
if ( $params['paction'] !== 'wikitext' ) {
|
|
|
|
$wikipage = WikiPage::factory( $title );
|
|
|
|
$popts = $wikipage->makeParserOptions( 'canonical' );
|
2017-09-09 00:21:16 +00:00
|
|
|
$cached = MediaWikiServices::getInstance()->getParserCache()->get( $article, $popts, true );
|
2017-01-13 00:33:49 +00:00
|
|
|
$links = [
|
|
|
|
// Array of linked pages that are missing
|
|
|
|
'missing' => [],
|
|
|
|
// For current revisions: 1 (treat all non-missing pages as known)
|
|
|
|
// For old revisions: array of linked pages that are known
|
|
|
|
'known' => $restoring || !$cached ? [] : 1,
|
|
|
|
];
|
|
|
|
if ( $cached ) {
|
|
|
|
foreach ( $cached->getLinks() as $namespace => $cachedTitles ) {
|
|
|
|
foreach ( $cachedTitles as $cachedTitleText => $exists ) {
|
|
|
|
$cachedTitle = Title::makeTitle( $namespace, $cachedTitleText );
|
|
|
|
if ( !$cachedTitle->isKnown() ) {
|
|
|
|
$links['missing'][] = $cachedTitle->getPrefixedText();
|
|
|
|
} elseif ( $links['known'] !== 1 ) {
|
|
|
|
$links['known'][] = $cachedTitle->getPrefixedText();
|
|
|
|
}
|
2015-02-03 04:30:00 +00:00
|
|
|
}
|
2014-03-11 00:46:26 +00:00
|
|
|
}
|
|
|
|
}
|
2017-01-13 00:33:49 +00:00
|
|
|
// Add information about current page
|
|
|
|
if ( !$title->isKnown() ) {
|
|
|
|
$links['missing'][] = $title->getPrefixedText();
|
|
|
|
} elseif ( $links['known'] !== 1 ) {
|
|
|
|
$links['known'][] = $title->getPrefixedText();
|
|
|
|
}
|
2015-02-03 04:30:00 +00:00
|
|
|
}
|
2014-12-17 01:07:57 +00:00
|
|
|
|
2014-03-11 00:46:26 +00:00
|
|
|
// On parser cache miss, just don't bother populating red link data
|
|
|
|
|
2017-08-31 15:18:45 +00:00
|
|
|
foreach ( $checkboxesDef as &$value ) {
|
|
|
|
// Don't convert the boolean to empty string with formatversion=1
|
|
|
|
$value[ApiResult::META_BC_BOOLS] = [ 'default' ];
|
|
|
|
}
|
2016-02-17 16:18:02 +00:00
|
|
|
$result = [
|
2015-03-13 22:15:17 +00:00
|
|
|
'result' => 'success',
|
|
|
|
'notices' => $notices,
|
2017-08-31 15:18:45 +00:00
|
|
|
'checkboxesDef' => $checkboxesDef,
|
|
|
|
'checkboxesMessages' => $checkboxesMessages,
|
2016-12-18 19:04:20 +00:00
|
|
|
'templates' => $templates,
|
2015-03-13 22:15:17 +00:00
|
|
|
'links' => $links,
|
|
|
|
'protectedClasses' => implode( ' ', $protectedClasses ),
|
|
|
|
'basetimestamp' => $baseTimestamp,
|
|
|
|
'starttimestamp' => wfTimestampNow(),
|
|
|
|
'oldid' => $oldid,
|
|
|
|
|
2016-02-17 16:18:02 +00:00
|
|
|
];
|
2017-09-14 20:08:09 +00:00
|
|
|
if ( $params['paction'] === 'parse' ||
|
|
|
|
$params['paction'] === 'wikitext' ||
|
|
|
|
$params['preload']
|
|
|
|
) {
|
2015-03-13 22:15:17 +00:00
|
|
|
$result['content'] = $content;
|
2013-05-15 21:17:06 +00:00
|
|
|
}
|
|
|
|
break;
|
2013-12-04 15:30:21 +00:00
|
|
|
|
2013-05-15 23:51:11 +00:00
|
|
|
case 'parsefragment':
|
2014-10-22 22:47:21 +00:00
|
|
|
$wikitext = $params['wikitext'];
|
|
|
|
if ( $params['pst'] ) {
|
2015-03-26 19:32:01 +00:00
|
|
|
$wikitext = $this->pstWikitext( $title, $wikitext );
|
2014-10-22 22:47:21 +00:00
|
|
|
}
|
2015-03-26 19:32:01 +00:00
|
|
|
$content = $this->parseWikitextFragment( $title, $wikitext );
|
2013-05-15 23:51:11 +00:00
|
|
|
if ( $content === false ) {
|
2016-11-03 19:16:57 +00:00
|
|
|
$this->dieWithError( 'apierror-visualeditor-docserver', 'docserver' );
|
2013-05-15 23:51:11 +00:00
|
|
|
} else {
|
2016-02-17 16:18:02 +00:00
|
|
|
$result = [
|
2013-05-15 23:51:11 +00:00
|
|
|
'result' => 'success',
|
|
|
|
'content' => $content
|
2016-02-17 16:18:02 +00:00
|
|
|
];
|
2013-05-15 23:51:11 +00:00
|
|
|
}
|
|
|
|
break;
|
2013-12-04 15:30:21 +00:00
|
|
|
|
|
|
|
case 'getlanglinks':
|
2015-03-26 19:32:01 +00:00
|
|
|
$langlinks = $this->getLangLinks( $title );
|
2013-12-04 15:30:21 +00:00
|
|
|
if ( $langlinks === false ) {
|
2016-11-03 19:16:57 +00:00
|
|
|
$this->dieWithError( 'apierror-visualeditor-api-langlinks-error', 'api-langlinks-error' );
|
2013-12-04 15:30:21 +00:00
|
|
|
} else {
|
2016-02-17 16:18:02 +00:00
|
|
|
$result = [ 'result' => 'success', 'langlinks' => $langlinks ];
|
2013-12-04 15:30:21 +00:00
|
|
|
}
|
|
|
|
break;
|
2012-05-25 19:50:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->getResult()->addValue( null, $this->getModuleName(), $result );
|
|
|
|
}
|
|
|
|
|
2016-04-29 16:00:57 +00:00
|
|
|
/**
|
|
|
|
* Check if the configured allowed namespaces include the specified namespace
|
|
|
|
*
|
|
|
|
* @param Config $config Configuration object
|
|
|
|
* @param int $namespaceId Namespace ID
|
2017-07-25 14:49:56 +00:00
|
|
|
* @return bool
|
2016-04-29 16:00:57 +00:00
|
|
|
*/
|
|
|
|
public static function isAllowedNamespace( Config $config, $namespaceId ) {
|
2016-06-01 16:06:22 +00:00
|
|
|
$availableNamespaces = self::getAvailableNamespaceIds( $config );
|
|
|
|
return in_array( $namespaceId, $availableNamespaces );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a list of allowed namespace IDs
|
|
|
|
*
|
|
|
|
* @param Config $config Configuration object
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public static function getAvailableNamespaceIds( Config $config ) {
|
2016-06-29 21:10:45 +00:00
|
|
|
$availableNamespaces =
|
|
|
|
// Note: existing numeric keys might exist, and so array_merge cannot be used
|
2017-05-04 22:07:10 +00:00
|
|
|
(array)$config->get( 'VisualEditorAvailableNamespaces' ) +
|
|
|
|
(array)ExtensionRegistry::getInstance()->getAttribute( 'VisualEditorAvailableNamespaces' );
|
2016-06-30 19:34:29 +00:00
|
|
|
return array_values( array_unique( array_map( function ( $namespace ) {
|
2016-06-01 16:06:22 +00:00
|
|
|
// Convert canonical namespace names to IDs
|
|
|
|
return is_numeric( $namespace ) ?
|
|
|
|
$namespace :
|
|
|
|
MWNamespace::getCanonicalIndex( strtolower( $namespace ) );
|
2016-06-30 19:34:29 +00:00
|
|
|
}, array_keys( array_filter( $availableNamespaces ) ) ) ) );
|
2016-04-21 11:40:42 +00:00
|
|
|
}
|
2016-04-29 16:00:57 +00:00
|
|
|
|
2016-04-21 11:40:42 +00:00
|
|
|
/**
|
|
|
|
* Check if the configured allowed content models include the specified content model
|
|
|
|
*
|
|
|
|
* @param Config $config Configuration object
|
|
|
|
* @param string $contentModel Content model ID
|
2017-07-25 14:49:56 +00:00
|
|
|
* @return bool
|
2016-04-21 11:40:42 +00:00
|
|
|
*/
|
|
|
|
public static function isAllowedContentType( Config $config, $contentModel ) {
|
2016-06-01 16:06:22 +00:00
|
|
|
$availableContentModels = array_merge(
|
|
|
|
ExtensionRegistry::getInstance()->getAttribute( 'VisualEditorAvailableContentModels' ),
|
|
|
|
$config->get( 'VisualEditorAvailableContentModels' )
|
|
|
|
);
|
|
|
|
return
|
|
|
|
isset( $availableContentModels[ $contentModel ] ) &&
|
|
|
|
$availableContentModels[ $contentModel ];
|
2016-04-29 16:00:57 +00:00
|
|
|
}
|
|
|
|
|
2014-03-26 20:39:45 +00:00
|
|
|
/**
|
|
|
|
* Gets the relevant HTML for the latest log entry on a given title, including a full log link.
|
|
|
|
*
|
|
|
|
* @param $title Title
|
|
|
|
* @param $types array|string
|
2014-08-17 19:43:56 +00:00
|
|
|
* @return string
|
2014-03-26 20:39:45 +00:00
|
|
|
*/
|
|
|
|
private function getLastLogEntry( $title, $types = '' ) {
|
|
|
|
$lp = new LogPager(
|
|
|
|
new LogEventsList( $this->getContext() ),
|
|
|
|
$types,
|
|
|
|
'',
|
|
|
|
$title->getPrefixedDbKey()
|
|
|
|
);
|
|
|
|
$lp->mLimit = 1;
|
|
|
|
|
2016-12-31 04:37:10 +00:00
|
|
|
return $lp->getBody() . MediaWikiServices::getInstance()->getLinkRenderer()->makeLink(
|
2014-03-26 20:39:45 +00:00
|
|
|
SpecialPage::getTitleFor( 'Log' ),
|
2016-12-31 04:37:10 +00:00
|
|
|
$this->msg( 'log-fulllog' )->text(),
|
2016-02-17 16:18:02 +00:00
|
|
|
[],
|
|
|
|
[
|
2014-03-26 20:39:45 +00:00
|
|
|
'page' => $title->getPrefixedDBkey(),
|
|
|
|
'type' => is_string( $types ) ? $types : null
|
2016-02-17 16:18:02 +00:00
|
|
|
]
|
2014-03-26 20:39:45 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-05-25 19:50:48 +00:00
|
|
|
public function getAllowedParams() {
|
2016-02-17 16:18:02 +00:00
|
|
|
return [
|
|
|
|
'page' => [
|
2012-05-25 19:50:48 +00:00
|
|
|
ApiBase::PARAM_REQUIRED => true,
|
2016-02-17 16:18:02 +00:00
|
|
|
],
|
|
|
|
'format' => [
|
2015-02-03 18:24:51 +00:00
|
|
|
ApiBase::PARAM_DFLT => 'jsonfm',
|
2016-02-17 16:18:02 +00:00
|
|
|
ApiBase::PARAM_TYPE => [ 'json', 'jsonfm' ],
|
|
|
|
],
|
|
|
|
'paction' => [
|
2012-05-25 19:50:48 +00:00
|
|
|
ApiBase::PARAM_REQUIRED => true,
|
2016-02-17 16:18:02 +00:00
|
|
|
ApiBase::PARAM_TYPE => [
|
2014-03-21 00:44:30 +00:00
|
|
|
'parse',
|
2015-03-13 22:15:17 +00:00
|
|
|
'metadata',
|
2016-05-26 12:08:26 +00:00
|
|
|
'wikitext',
|
2014-03-21 00:44:30 +00:00
|
|
|
'parsefragment',
|
|
|
|
'getlanglinks',
|
2016-02-17 16:18:02 +00:00
|
|
|
],
|
|
|
|
],
|
2013-05-15 23:51:11 +00:00
|
|
|
'wikitext' => null,
|
2016-09-06 19:16:55 +00:00
|
|
|
'section' => null,
|
2013-05-15 23:51:11 +00:00
|
|
|
'oldid' => null,
|
2016-12-31 17:02:33 +00:00
|
|
|
'editintro' => null,
|
2014-10-22 22:47:21 +00:00
|
|
|
'pst' => false,
|
2017-09-14 20:08:09 +00:00
|
|
|
'preload' => null,
|
|
|
|
'preloadparams' => null,
|
2016-02-17 16:18:02 +00:00
|
|
|
];
|
2012-05-25 19:50:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function needsToken() {
|
2013-07-11 17:09:28 +00:00
|
|
|
return false;
|
2012-11-14 18:33:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function mustBePosted() {
|
2013-12-04 15:30:21 +00:00
|
|
|
return false;
|
2012-11-14 18:33:57 +00:00
|
|
|
}
|
|
|
|
|
2014-10-14 00:20:50 +00:00
|
|
|
public function isInternal() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-11-14 18:33:57 +00:00
|
|
|
public function isWriteMode() {
|
2016-03-10 18:58:41 +00:00
|
|
|
return false;
|
2012-05-25 19:50:48 +00:00
|
|
|
}
|
|
|
|
}
|