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
|
2016-01-03 22:56:59 +00:00
|
|
|
* @copyright 2011-2016 VisualEditor Team and others; see AUTHORS.txt
|
2012-07-19 00:11:26 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
2012-05-25 19:50:48 +00:00
|
|
|
class ApiVisualEditor extends ApiBase {
|
2015-04-02 00:41:59 +00:00
|
|
|
// These are safe even if VE is not enabled on the page.
|
|
|
|
// This is intended for other VE interfaces, such as Flow's.
|
|
|
|
protected static $SAFE_ACTIONS = array(
|
|
|
|
'parsefragment',
|
|
|
|
);
|
2013-07-05 07:56:28 +00:00
|
|
|
|
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;
|
2014-12-18 00:49:55 +00:00
|
|
|
$this->serviceClient = new VirtualRESTServiceClient( new MultiHttpClient( array() ) );
|
2015-06-13 04:54:23 +00:00
|
|
|
$this->serviceClient->mount( '/restbase/', $this->getVRSObject() );
|
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
|
|
|
|
*/
|
|
|
|
private function getVRSObject() {
|
|
|
|
// the params array to create the service object with
|
|
|
|
$params = array();
|
|
|
|
// the VRS class to use, defaults to Parsoid
|
|
|
|
$class = 'ParsoidVirtualRESTService';
|
|
|
|
$config = $this->veConfig;
|
|
|
|
// the global virtual rest service config object, if any
|
|
|
|
$vrs = $this->getConfig()->get( 'VirtualRestConfig' );
|
|
|
|
if ( isset( $vrs['modules'] ) && isset( $vrs['modules']['restbase'] ) ) {
|
|
|
|
// if restbase is available, use it
|
|
|
|
$params = $vrs['modules']['restbase'];
|
2015-06-13 04:54:23 +00:00
|
|
|
$params['parsoidCompat'] = false; // backward compatibility
|
2015-03-04 14:52:07 +00:00
|
|
|
$class = 'RestbaseVirtualRESTService';
|
|
|
|
} 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 {
|
|
|
|
// no global modules defined, fall back to old defaults
|
|
|
|
$params = array(
|
|
|
|
'URL' => $config->get( 'VisualEditorParsoidURL' ),
|
|
|
|
'prefix' => $config->get( 'VisualEditorParsoidPrefix' ),
|
2015-06-13 04:54:23 +00:00
|
|
|
'domain' => $config->get( 'VisualEditorParsoidDomain' ),
|
2015-03-04 14:52:07 +00:00
|
|
|
'timeout' => $config->get( 'VisualEditorParsoidTimeout' ),
|
|
|
|
'HTTPProxy' => $config->get( 'VisualEditorParsoidHTTPProxy' ),
|
2015-06-13 04:54:23 +00:00
|
|
|
'forwardCookies' => $config->get( 'VisualEditorParsoidForwardCookies' ),
|
|
|
|
'restbaseCompat' => true
|
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
|
|
|
|
if ( $params['forwardCookies'] && !User::isEveryoneAllowed( 'read' ) ) {
|
|
|
|
$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
|
|
|
}
|
|
|
|
|
2015-10-08 22:16:56 +00:00
|
|
|
private function requestRestbase( $method, $path, $params, $reqheaders = array() ) {
|
2014-12-18 00:49:55 +00:00
|
|
|
$request = array(
|
|
|
|
'method' => $method,
|
2015-06-13 04:54:23 +00:00
|
|
|
'url' => '/restbase/local/v1/' . $path
|
2014-04-18 20:17: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
|
|
|
}
|
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'] !== '' ) {
|
2015-09-14 16:13:31 +00:00
|
|
|
$this->dieUsage( 'docserver-http-error: ' . $response['error'], $response['error'] );
|
2014-12-18 00:49:55 +00:00
|
|
|
} else { // error null, code not 200
|
2015-09-14 16:13:31 +00:00
|
|
|
$this->dieUsage( 'docserver-http: HTTP ' . $response['code'], $response['code'] );
|
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
|
|
|
}
|
|
|
|
|
2015-10-08 22:16:56 +00:00
|
|
|
protected function storeInSerializationCache( $title, $oldid, $html, $etag ) {
|
2014-08-13 08:15:42 +00:00
|
|
|
global $wgMemc;
|
2015-03-27 23:22:37 +00:00
|
|
|
|
|
|
|
// Convert the VE HTML to wikitext
|
2015-10-08 22:16:56 +00:00
|
|
|
$text = $this->postHTML( $title, $html, array( 'oldid' => $oldid ), $etag );
|
2015-03-27 23:22:37 +00:00
|
|
|
if ( $text === false ) {
|
2013-11-01 21:30:22 +00:00
|
|
|
return false;
|
|
|
|
}
|
2015-03-27 23:22:37 +00:00
|
|
|
|
|
|
|
// Store the corresponding wikitext, referenceable by a new key
|
|
|
|
$hash = md5( $text );
|
2013-11-01 21:30:22 +00:00
|
|
|
$key = wfMemcKey( 'visualeditor', 'serialization', $hash );
|
2015-03-27 23:22:37 +00:00
|
|
|
$wgMemc->set( $key, $text,
|
|
|
|
$this->veConfig->get( 'VisualEditorSerializationCacheTimeout' ) );
|
|
|
|
|
|
|
|
// Also parse and prepare the edit in case it might be saved later
|
|
|
|
$page = WikiPage::factory( $title );
|
|
|
|
$content = ContentHandler::makeContent( $text, $title, CONTENT_MODEL_WIKITEXT );
|
|
|
|
|
|
|
|
$res = ApiStashEdit::parseAndStash( $page, $content, $this->getUser() );
|
|
|
|
if ( $res === ApiStashEdit::ERROR_NONE ) {
|
|
|
|
wfDebugLog( 'StashEdit', "Cached parser output for VE content key '$key'." );
|
|
|
|
}
|
|
|
|
|
2013-11-01 21:30:22 +00:00
|
|
|
return $hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function trySerializationCache( $hash ) {
|
|
|
|
global $wgMemc;
|
|
|
|
$key = wfMemcKey( 'visualeditor', 'serialization', $hash );
|
|
|
|
return $wgMemc->get( $key );
|
|
|
|
}
|
|
|
|
|
2015-10-08 22:16:56 +00:00
|
|
|
protected function postHTML( $title, $html, $parserParams, $etag ) {
|
2013-04-15 23:22:51 +00:00
|
|
|
if ( $parserParams['oldid'] === 0 ) {
|
|
|
|
$parserParams['oldid'] = '';
|
|
|
|
}
|
2015-06-13 04:54:23 +00:00
|
|
|
$path = 'transform/html/to/wikitext/' . urlencode( $title->getPrefixedDBkey() );
|
|
|
|
if ( $parserParams['oldid'] ) {
|
|
|
|
$path .= '/' . $parserParams['oldid'];
|
|
|
|
}
|
|
|
|
return $this->requestRestbase(
|
2015-01-07 21:56:19 +00:00
|
|
|
'POST',
|
2015-06-13 04:54:23 +00:00
|
|
|
$path,
|
2014-04-18 20:17:02 +00:00
|
|
|
array(
|
2014-12-18 00:49:55 +00:00
|
|
|
'html' => $html,
|
2015-10-07 19:22:50 +00:00
|
|
|
'scrub_wikitext' => 1,
|
2015-10-08 22:16:56 +00:00
|
|
|
),
|
|
|
|
array( 'If-Match' => $etag )
|
2012-11-14 18:33:57 +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() ),
|
2014-04-18 20:19:54 +00:00
|
|
|
array(
|
2014-12-18 00:49:55 +00:00
|
|
|
'wikitext' => $wikitext,
|
2015-09-30 14:31:05 +00:00
|
|
|
'body_only' => 1,
|
2014-04-18 20:19:54 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-11-14 18:33:57 +00:00
|
|
|
protected function diffWikitext( $title, $wikitext ) {
|
|
|
|
$apiParams = array(
|
|
|
|
'action' => 'query',
|
|
|
|
'prop' => 'revisions',
|
|
|
|
'titles' => $title->getPrefixedDBkey(),
|
2014-10-22 22:47:21 +00:00
|
|
|
'rvdifftotext' => $this->pstWikitext( $title, $wikitext )
|
2012-11-14 18:33:57 +00:00
|
|
|
);
|
|
|
|
$api = new ApiMain(
|
|
|
|
new DerivativeRequest(
|
|
|
|
$this->getRequest(),
|
|
|
|
$apiParams,
|
|
|
|
false // was posted?
|
|
|
|
),
|
|
|
|
false // enable write?
|
|
|
|
);
|
|
|
|
$api->execute();
|
2014-12-30 22:20:55 +00:00
|
|
|
if ( defined( 'ApiResult::META_CONTENT' ) ) {
|
2015-04-20 18:41:29 +00:00
|
|
|
$result = $api->getResult()->getResultData( null, array(
|
|
|
|
'BC' => array(), // Transform content nodes to '*'
|
|
|
|
'Types' => array(), // Add back-compat subelements
|
|
|
|
) );
|
2014-12-30 22:20:55 +00:00
|
|
|
} else {
|
|
|
|
$result = $api->getResultData();
|
|
|
|
}
|
2012-12-07 16:23:23 +00:00
|
|
|
if ( !isset( $result['query']['pages'][$title->getArticleID()]['revisions'][0]['diff']['*'] ) ) {
|
2013-05-14 17:40:00 +00:00
|
|
|
return array( 'result' => 'fail' );
|
2012-12-07 16:23:23 +00:00
|
|
|
}
|
|
|
|
$diffRows = $result['query']['pages'][$title->getArticleID()]['revisions'][0]['diff']['*'];
|
|
|
|
|
2013-05-10 22:32:23 +00:00
|
|
|
if ( $diffRows !== '' ) {
|
|
|
|
$context = new DerivativeContext( $this->getContext() );
|
|
|
|
$context->setTitle( $title );
|
|
|
|
$engine = new DifferenceEngine( $context );
|
2013-05-14 17:40:00 +00:00
|
|
|
return array(
|
|
|
|
'result' => 'success',
|
|
|
|
'diff' => $engine->addHeader(
|
|
|
|
$diffRows,
|
2014-12-17 23:41:15 +00:00
|
|
|
$context->msg( 'currentrev' )->parse(),
|
|
|
|
$context->msg( 'yourtext' )->parse()
|
2013-05-14 17:40:00 +00:00
|
|
|
)
|
2013-05-10 22:32:23 +00:00
|
|
|
);
|
|
|
|
} else {
|
2013-05-14 17:40:00 +00:00
|
|
|
return array( 'result' => 'nochanges' );
|
2013-05-10 22:32:23 +00:00
|
|
|
}
|
2012-11-14 18:33:57 +00:00
|
|
|
}
|
2012-05-25 22:23:40 +00:00
|
|
|
|
2013-12-04 15:30:21 +00:00
|
|
|
protected function getLangLinks( $title ) {
|
|
|
|
$apiParams = array(
|
|
|
|
'action' => 'query',
|
|
|
|
'prop' => 'langlinks',
|
|
|
|
'lllimit' => 500,
|
|
|
|
'titles' => $title->getPrefixedDBkey(),
|
|
|
|
'indexpageids' => 1,
|
|
|
|
);
|
|
|
|
$api = new ApiMain(
|
|
|
|
new DerivativeRequest(
|
|
|
|
$this->getRequest(),
|
|
|
|
$apiParams,
|
|
|
|
false // was posted?
|
|
|
|
),
|
|
|
|
true // enable write?
|
|
|
|
);
|
|
|
|
|
|
|
|
$api->execute();
|
2014-12-30 22:20:55 +00:00
|
|
|
if ( defined( 'ApiResult::META_CONTENT' ) ) {
|
2015-04-20 18:41:29 +00:00
|
|
|
$result = $api->getResult()->getResultData( null, array(
|
|
|
|
'BC' => array(), // Backwards-compatible structure transformations
|
|
|
|
'Types' => array(), // Backwards-compatible structure transformations
|
|
|
|
'Strip' => 'all', // Remove any metadata keys from the langlinks array
|
|
|
|
) );
|
2014-12-30 22:20:55 +00:00
|
|
|
} else {
|
|
|
|
$result = $api->getResultData();
|
|
|
|
}
|
2013-12-04 15:30:21 +00:00
|
|
|
if ( !isset( $result['query']['pages'][$title->getArticleID()]['langlinks'] ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$langlinks = $result['query']['pages'][$title->getArticleID()]['langlinks'];
|
|
|
|
$langnames = Language::fetchLanguageNames();
|
|
|
|
foreach ( $langlinks as $i => $lang ) {
|
|
|
|
$langlinks[$i]['langname'] = $langnames[$langlinks[$i]['lang']];
|
|
|
|
}
|
|
|
|
return $langlinks;
|
|
|
|
}
|
|
|
|
|
2012-05-25 19:50:48 +00:00
|
|
|
public function execute() {
|
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'] );
|
|
|
|
if ( !$title ) {
|
2012-11-14 18:33:57 +00:00
|
|
|
$this->dieUsageMsg( 'invalidtitle', $params['page'] );
|
|
|
|
}
|
2015-04-02 00:41:59 +00:00
|
|
|
|
|
|
|
$isSafeAction = in_array( $params['paction'], self::$SAFE_ACTIONS, true );
|
|
|
|
|
2015-08-02 21:30:43 +00:00
|
|
|
$availableNamespaces = $this->veConfig->get( 'VisualEditorAvailableNamespaces' );
|
|
|
|
if ( !$isSafeAction && (
|
|
|
|
!isset( $availableNamespaces[$title->getNamespace()] ) ||
|
|
|
|
!$availableNamespaces[$title->getNamespace()]
|
|
|
|
) ) {
|
2015-04-02 00:41:59 +00:00
|
|
|
|
2012-11-14 18:33:57 +00:00
|
|
|
$this->dieUsage( "VisualEditor is not enabled in namespace " .
|
2015-03-26 19:32:01 +00:00
|
|
|
$title->getNamespace(), 'novenamespace' );
|
2012-11-14 18:33:57 +00:00
|
|
|
}
|
2012-05-25 19:50:48 +00:00
|
|
|
|
2013-05-15 23:51:11 +00:00
|
|
|
$parserParams = array();
|
|
|
|
if ( isset( $params['oldid'] ) ) {
|
|
|
|
$parserParams['oldid'] = $params['oldid'];
|
|
|
|
}
|
2012-08-23 19:01:07 +00:00
|
|
|
|
2014-06-23 17:55:59 +00:00
|
|
|
$html = $params['html'];
|
|
|
|
if ( substr( $html, 0, 11 ) === 'rawdeflate,' ) {
|
2015-04-03 18:14:52 +00:00
|
|
|
$deflated = base64_decode( substr( $html, 11 ) );
|
|
|
|
wfSuppressWarnings();
|
|
|
|
$html = gzinflate( $deflated );
|
|
|
|
wfRestoreWarnings();
|
|
|
|
if ( $deflated === $html || $html === false ) {
|
|
|
|
$this->dieUsage( "HTML provided is not properly deflated", 'invaliddeflate' );
|
|
|
|
}
|
2014-06-23 17:55:59 +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':
|
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
|
|
|
|
global $wgTitle; // FIXME NOOOOOOOOES
|
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 ) {
|
|
|
|
$this->dieUsage( 'Could not find latest revision for title', 'latestnotfound' );
|
|
|
|
}
|
|
|
|
$revision = null;
|
|
|
|
if ( !isset( $parserParams['oldid'] ) || $parserParams['oldid'] === 0 ) {
|
|
|
|
$parserParams['oldid'] = $latestRevision->getId();
|
|
|
|
$revision = $latestRevision;
|
|
|
|
} else {
|
|
|
|
$revision = Revision::newFromId( $parserParams['oldid'] );
|
|
|
|
if ( $revision === null ) {
|
|
|
|
$this->dieUsage( 'Could not find revision ID ' . $parserParams['oldid'], 'oldidnotfound' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$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',
|
2015-06-13 04:54:23 +00:00
|
|
|
'page/html/' . urlencode( $title->getPrefixedDBkey() ) . '/' . $oldid,
|
|
|
|
array()
|
2015-03-13 22:15:17 +00:00
|
|
|
);
|
|
|
|
if ( $content === false ) {
|
2015-09-14 16:13:31 +00:00
|
|
|
$this->dieUsage( 'Error contacting the document server', 'docserver' );
|
2015-03-13 22:15:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$content = '';
|
|
|
|
$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
|
|
|
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
$protectedClasses = array();
|
2015-03-26 19:32:01 +00:00
|
|
|
if ( MWNamespace::getRestrictionLevels( $title->getNamespace() ) !== array( '' ) ) {
|
2014-04-16 23:16:06 +00:00
|
|
|
// Page protected from editing
|
2015-03-26 19:32:01 +00:00
|
|
|
if ( $title->isProtected( 'edit' ) ) {
|
2014-04-16 23:16:06 +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';
|
|
|
|
|
2014-04-16 23:16:06 +00:00
|
|
|
# Then it must be protected based on static groups (regular)
|
|
|
|
$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 ) {
|
|
|
|
$notice .= "<li>" . Linker::link( $source ) . "</li>";
|
|
|
|
}
|
|
|
|
$notice .= '</ul>';
|
|
|
|
$notices[] = $notice;
|
|
|
|
}
|
2014-03-26 20:39:45 +00:00
|
|
|
}
|
|
|
|
|
2015-03-13 22:15:17 +00:00
|
|
|
// Permission notice
|
2015-11-05 02:55:24 +00:00
|
|
|
$permErrors = $title->getUserPermissionsErrors( 'create', $user );
|
|
|
|
if ( $permErrors && !$title->exists() ) {
|
2014-07-05 19:09:23 +00:00
|
|
|
$notices[] = $this->msg(
|
|
|
|
'permissionserrorstext-withaction', 1, $this->msg( 'action-createpage' )
|
2015-11-05 02:55:24 +00:00
|
|
|
) . "<br>" . call_user_func_array( 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];
|
|
|
|
$targetUser = User::newFromName( $targetUsername, false /* allow IP users*/ );
|
|
|
|
|
|
|
|
if (
|
|
|
|
!( $targetUser && $targetUser->isLoggedIn() ) &&
|
|
|
|
!User::isIP( $targetUsername )
|
|
|
|
) { // User does not exist
|
|
|
|
$notices[] = "<div class=\"mw-userpage-userdoesnotexist error\">\n" .
|
|
|
|
$this->msg( 'userpage-userdoesnotexist', wfEscapeWikiText( $targetUsername ) ) .
|
|
|
|
"\n</div>";
|
|
|
|
} elseif ( $targetUser->isBlocked() ) { // Show log extract if the user is currently blocked
|
|
|
|
$notices[] = $this->msg(
|
|
|
|
'blocked-notice-logextract',
|
|
|
|
$targetUser->getName() // Support GENDER in notice
|
|
|
|
)->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
|
2015-03-26 19:32:01 +00:00
|
|
|
if ( $user->isBlockedFrom( $title ) && $user->getBlock()->prevents( 'edit' ) !== false ) {
|
2014-03-17 21:22:41 +00:00
|
|
|
$notices[] = call_user_func_array(
|
|
|
|
array( $this, 'msg' ),
|
|
|
|
$user->getBlock()->getPermissionsError( $this->getContext() )
|
|
|
|
)->parseAsBlock();
|
|
|
|
}
|
|
|
|
|
2015-03-13 22:15:17 +00:00
|
|
|
// Blocked user notice for global blocks
|
2014-04-22 00:22:48 +00:00
|
|
|
if ( class_exists( 'GlobalBlocking' ) ) {
|
|
|
|
$error = GlobalBlocking::getUserBlockErrors(
|
|
|
|
$user,
|
|
|
|
$this->getRequest()->getIP()
|
|
|
|
);
|
|
|
|
if ( count( $error ) ) {
|
|
|
|
$notices[] = call_user_func_array(
|
|
|
|
array( $this, 'msg' ),
|
|
|
|
$error
|
|
|
|
)->parseAsBlock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
2015-03-26 19:32:01 +00:00
|
|
|
$article = new Article( $title ); // Deliberately omitting ,0 so oldid comes from request
|
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
|
|
|
$ep = new EditPage( $article );
|
2013-08-02 18:37:30 +00:00
|
|
|
$req = $this->getRequest();
|
2014-01-09 21:16:55 +00:00
|
|
|
$req->setVal( 'format', 'text/x-wiki' );
|
2013-08-02 18:37:30 +00:00
|
|
|
$ep->importFormData( $req ); // By reference for some reason (bug 52466)
|
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
|
|
|
$tabindex = 0;
|
|
|
|
$states = array( 'minor' => false, 'watch' => false );
|
|
|
|
$checkboxes = $ep->getCheckboxes( $tabindex, $states );
|
|
|
|
|
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.
|
|
|
|
$links = array();
|
2015-03-26 19:32:01 +00:00
|
|
|
$wikipage = WikiPage::factory( $title );
|
2014-03-11 00:46:26 +00:00
|
|
|
$popts = $wikipage->makeParserOptions( 'canonical' );
|
|
|
|
$cached = ParserCache::singleton()->get( $article, $popts, true );
|
2015-02-03 04:30:00 +00:00
|
|
|
$links = array(
|
|
|
|
// Array of linked pages that are missing
|
|
|
|
'missing' => array(),
|
2015-07-03 13:19:41 +00:00
|
|
|
// For current revisions: 1 (treat all non-missing pages as known)
|
|
|
|
// For old revisions: array of linked pages that are known
|
|
|
|
'known' => $restoring || !$cached ? array() : 1,
|
2015-02-03 04:30:00 +00:00
|
|
|
);
|
2014-03-11 00:46:26 +00:00
|
|
|
if ( $cached ) {
|
2015-07-03 13:19:41 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-02-03 04:30:00 +00:00
|
|
|
// Add information about current page
|
2015-07-03 13:19:41 +00:00
|
|
|
if ( !$title->isKnown() ) {
|
2015-03-26 19:32:01 +00:00
|
|
|
$links['missing'][] = $title->getPrefixedText();
|
2015-07-03 13:19:41 +00:00
|
|
|
} 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
|
|
|
|
|
2015-03-13 22:15:17 +00:00
|
|
|
$result = array(
|
|
|
|
'result' => 'success',
|
|
|
|
'notices' => $notices,
|
|
|
|
'checkboxes' => $checkboxes,
|
|
|
|
'links' => $links,
|
|
|
|
'protectedClasses' => implode( ' ', $protectedClasses ),
|
|
|
|
'watched' => $user->isWatched( $title ),
|
|
|
|
'basetimestamp' => $baseTimestamp,
|
|
|
|
'starttimestamp' => wfTimestampNow(),
|
|
|
|
'oldid' => $oldid,
|
|
|
|
|
|
|
|
);
|
|
|
|
if ( $params['paction'] === 'parse' ) {
|
|
|
|
$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 ) {
|
2015-09-14 16:13:31 +00:00
|
|
|
$this->dieUsage( 'Error contacting the document server', 'docserver' );
|
2013-05-15 23:51:11 +00:00
|
|
|
} else {
|
|
|
|
$result = array(
|
|
|
|
'result' => 'success',
|
|
|
|
'content' => $content
|
|
|
|
);
|
|
|
|
}
|
|
|
|
break;
|
2013-12-04 15:30:21 +00:00
|
|
|
|
2013-05-15 21:17:06 +00:00
|
|
|
case 'serialize':
|
2013-11-01 21:30:22 +00:00
|
|
|
if ( $params['cachekey'] !== null ) {
|
|
|
|
$content = $this->trySerializationCache( $params['cachekey'] );
|
|
|
|
if ( !is_string( $content ) ) {
|
|
|
|
$this->dieUsage( 'No cached serialization found with that key', 'badcachekey' );
|
|
|
|
}
|
2012-06-01 23:26:03 +00:00
|
|
|
} else {
|
2013-11-01 21:30:22 +00:00
|
|
|
if ( $params['html'] === null ) {
|
|
|
|
$this->dieUsageMsg( 'missingparam', 'html' );
|
|
|
|
}
|
2015-10-08 22:16:56 +00:00
|
|
|
$content = $this->postHTML( $title, $html, $parserParams, $params['etag'] );
|
2013-11-01 21:30:22 +00:00
|
|
|
if ( $content === false ) {
|
2015-09-14 16:13:31 +00:00
|
|
|
$this->dieUsage( 'Error contacting the document server', 'docserver' );
|
2013-11-01 21:30:22 +00:00
|
|
|
}
|
2013-05-15 21:17:06 +00:00
|
|
|
}
|
2013-11-01 21:30:22 +00:00
|
|
|
$result = array( 'result' => 'success', 'content' => $content );
|
2013-05-15 21:17:06 +00:00
|
|
|
break;
|
2013-12-04 15:30:21 +00:00
|
|
|
|
2013-06-28 22:46:15 +00:00
|
|
|
case 'diff':
|
2013-11-01 21:30:22 +00:00
|
|
|
if ( $params['cachekey'] !== null ) {
|
|
|
|
$wikitext = $this->trySerializationCache( $params['cachekey'] );
|
|
|
|
if ( !is_string( $wikitext ) ) {
|
|
|
|
$this->dieUsage( 'No cached serialization found with that key', 'badcachekey' );
|
|
|
|
}
|
|
|
|
} else {
|
2015-10-08 22:16:56 +00:00
|
|
|
$wikitext = $this->postHTML( $title, $html, $parserParams, $params['etag'] );
|
2013-11-01 21:30:22 +00:00
|
|
|
if ( $wikitext === false ) {
|
2015-09-14 16:13:31 +00:00
|
|
|
$this->dieUsage( 'Error contacting the document server', 'docserver' );
|
2013-11-01 21:30:22 +00:00
|
|
|
}
|
2013-06-28 22:46:15 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 19:32:01 +00:00
|
|
|
$diff = $this->diffWikitext( $title, $wikitext );
|
2013-06-28 22:46:15 +00:00
|
|
|
if ( $diff['result'] === 'fail' ) {
|
|
|
|
$this->dieUsage( 'Diff failed', 'difffailed' );
|
|
|
|
}
|
|
|
|
$result = $diff;
|
|
|
|
|
2013-11-01 21:30:22 +00:00
|
|
|
break;
|
2013-12-04 15:30:21 +00:00
|
|
|
|
2013-11-01 21:30:22 +00:00
|
|
|
case 'serializeforcache':
|
2015-04-03 18:58:11 +00:00
|
|
|
if ( !isset( $parserParams['oldid'] ) ) {
|
|
|
|
$parserParams['oldid'] = Revision::newFromTitle( $title )->getId();
|
|
|
|
}
|
2015-10-08 22:16:56 +00:00
|
|
|
$key = $this->storeInSerializationCache(
|
|
|
|
$title,
|
|
|
|
$parserParams['oldid'],
|
|
|
|
$html,
|
|
|
|
$params['etag']
|
|
|
|
);
|
2013-11-01 21:30:22 +00:00
|
|
|
$result = array( 'result' => 'success', 'cachekey' => $key );
|
2013-05-15 21:17:06 +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 ) {
|
2015-09-14 16:13:31 +00:00
|
|
|
$this->dieUsage( 'Error querying MediaWiki API', 'api-langlinks-error' );
|
2013-12-04 15:30:21 +00:00
|
|
|
} else {
|
|
|
|
$result = array( 'result' => 'success', 'langlinks' => $langlinks );
|
|
|
|
}
|
|
|
|
break;
|
2012-05-25 19:50:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->getResult()->addValue( null, $this->getModuleName(), $result );
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
return $lp->getBody() . Linker::link(
|
|
|
|
SpecialPage::getTitleFor( 'Log' ),
|
|
|
|
$this->msg( 'log-fulllog' )->escaped(),
|
|
|
|
array(),
|
|
|
|
array(
|
|
|
|
'page' => $title->getPrefixedDBkey(),
|
|
|
|
'type' => is_string( $types ) ? $types : null
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-05-25 19:50:48 +00:00
|
|
|
public function getAllowedParams() {
|
|
|
|
return array(
|
|
|
|
'page' => array(
|
|
|
|
ApiBase::PARAM_REQUIRED => true,
|
|
|
|
),
|
2014-03-21 00:44:30 +00:00
|
|
|
'format' => array(
|
2015-02-03 18:24:51 +00:00
|
|
|
ApiBase::PARAM_DFLT => 'jsonfm',
|
2014-03-21 00:44:30 +00:00
|
|
|
ApiBase::PARAM_TYPE => array( 'json', 'jsonfm' ),
|
|
|
|
),
|
2012-05-25 19:50:48 +00:00
|
|
|
'paction' => array(
|
|
|
|
ApiBase::PARAM_REQUIRED => true,
|
2013-11-01 21:30:22 +00:00
|
|
|
ApiBase::PARAM_TYPE => array(
|
2014-03-21 00:44:30 +00:00
|
|
|
'parse',
|
2015-03-13 22:15:17 +00:00
|
|
|
'metadata',
|
2014-03-21 00:44:30 +00:00
|
|
|
'parsefragment',
|
|
|
|
'serialize',
|
|
|
|
'serializeforcache',
|
|
|
|
'diff',
|
|
|
|
'getlanglinks',
|
2013-11-01 21:30:22 +00:00
|
|
|
),
|
2012-05-25 22:23:40 +00:00
|
|
|
),
|
2013-05-15 23:51:11 +00:00
|
|
|
'wikitext' => null,
|
|
|
|
'oldid' => null,
|
2012-11-28 23:57:00 +00:00
|
|
|
'html' => null,
|
2015-10-08 22:16:56 +00:00
|
|
|
'etag' => null,
|
2013-11-01 21:30:22 +00:00
|
|
|
'cachekey' => null,
|
2014-10-22 22:47:21 +00:00
|
|
|
'pst' => false,
|
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() {
|
|
|
|
return true;
|
2012-05-25 19:50:48 +00:00
|
|
|
}
|
|
|
|
|
2014-10-29 20:02:11 +00:00
|
|
|
/**
|
|
|
|
* @deprecated since MediaWiki core 1.25
|
|
|
|
*/
|
2012-05-25 19:50:48 +00:00
|
|
|
public function getParamDescription() {
|
|
|
|
return array(
|
2012-05-31 00:09:06 +00:00
|
|
|
'page' => 'The page to perform actions on.',
|
2012-11-14 18:33:57 +00:00
|
|
|
'paction' => 'Action to perform',
|
2013-07-11 17:09:28 +00:00
|
|
|
'oldid' => 'The revision number to use (defaults to latest version).',
|
2014-10-22 22:47:21 +00:00
|
|
|
'html' => 'HTML to send to Parsoid to convert to wikitext',
|
|
|
|
'wikitext' => 'Wikitext to send to Parsoid to convert to HTML (paction=parsefragment)',
|
|
|
|
'pst' => 'Pre-save transform wikitext before sending it to Parsoid (paction=parsefragment)',
|
2013-11-01 21:30:22 +00:00
|
|
|
'cachekey' => 'For serialize or diff, use the result of a previous serializeforcache'
|
|
|
|
. ' request with this key. Overrides html.',
|
2012-05-25 19:50:48 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-10-29 20:02:11 +00:00
|
|
|
/**
|
|
|
|
* @deprecated since MediaWiki core 1.25
|
|
|
|
*/
|
2012-05-25 19:50:48 +00:00
|
|
|
public function getDescription() {
|
2015-09-14 16:13:31 +00:00
|
|
|
return 'Returns HTML5 for a page from RESTBase or the Parsoid service.';
|
2012-05-25 19:50:48 +00:00
|
|
|
}
|
|
|
|
}
|