mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-29 16:44:51 +00:00
Merge "Api: include preload content when section=new"
This commit is contained in:
commit
69092c4b6c
|
@ -142,6 +142,37 @@ class ApiVisualEditor extends ApiBase {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getPreloadContent( $preload, $params, $contextTitle, $parse = false ) {
|
||||||
|
$content = '';
|
||||||
|
$preloadTitle = Title::newFromText( $preload );
|
||||||
|
// Check for existence to avoid getting MediaWiki:Noarticletext
|
||||||
|
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( $this->getUser() );
|
||||||
|
|
||||||
|
$content = $content->preloadTransform(
|
||||||
|
$preloadTitle,
|
||||||
|
$parserOptions,
|
||||||
|
$params['preloadparams']
|
||||||
|
)->serialize();
|
||||||
|
|
||||||
|
if ( $parse ) {
|
||||||
|
// We need to turn this transformed wikitext into parsoid html
|
||||||
|
$content = $this->parseWikitextFragment( $contextTitle, $content );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
|
|
||||||
protected function getLangLinks( $title ) {
|
protected function getLangLinks( $title ) {
|
||||||
$apiParams = [
|
$apiParams = [
|
||||||
'action' => 'query',
|
'action' => 'query',
|
||||||
|
@ -251,6 +282,12 @@ class ApiVisualEditor extends ApiBase {
|
||||||
|
|
||||||
if ( $section === 'new' ) {
|
if ( $section === 'new' ) {
|
||||||
$content = '';
|
$content = '';
|
||||||
|
if ( $params['preload'] ) {
|
||||||
|
$content = $this->getPreloadContent(
|
||||||
|
$params['preload'], $params['preloadparams'], $title,
|
||||||
|
$params['paction'] !== 'wikitext'
|
||||||
|
);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$apiParams['rvsection'] = $section;
|
$apiParams['rvsection'] = $section;
|
||||||
|
|
||||||
|
@ -286,32 +323,10 @@ class ApiVisualEditor extends ApiBase {
|
||||||
$content = $this->parseWikitextFragment( $title, $content );
|
$content = $this->parseWikitextFragment( $title, $content );
|
||||||
}
|
}
|
||||||
if ( $content === '' && $params['preload'] ) {
|
if ( $content === '' && $params['preload'] ) {
|
||||||
$preloadTitle = Title::newFromText( $params['preload'] );
|
$content = $this->getPreloadContent(
|
||||||
// Check for existence to avoid getting MediaWiki:Noarticletext
|
$params['preload'], $params['preloadparams'], $title,
|
||||||
if ( $preloadTitle instanceof Title &&
|
$params['paction'] !== 'wikitext'
|
||||||
$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( $user );
|
|
||||||
|
|
||||||
$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 );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$baseTimestamp = wfTimestampNow();
|
$baseTimestamp = wfTimestampNow();
|
||||||
$oldid = 0;
|
$oldid = 0;
|
||||||
|
|
Loading…
Reference in a new issue