Display 'editingold' as a notice when editing old version of a page

Bug: 47683
Change-Id: I216cdd68014173aa65cad42ddd3d870334be9ead
This commit is contained in:
Ed Sanders 2013-05-24 16:48:27 +02:00
parent 2e76271b4e
commit 7ab76291b9

View file

@ -12,6 +12,9 @@ class ApiVisualEditor extends ApiBase {
protected function getHTML( $title, $parserParams ) { protected function getHTML( $title, $parserParams ) {
global $wgVisualEditorParsoidURL, $wgVisualEditorParsoidPrefix, global $wgVisualEditorParsoidURL, $wgVisualEditorParsoidPrefix,
$wgVisualEditorParsoidTimeout; $wgVisualEditorParsoidTimeout;
$restoring = false;
if ( $title->exists() ) { if ( $title->exists() ) {
if ( $parserParams['oldid'] === 0 ) { if ( $parserParams['oldid'] === 0 ) {
$parserParams['oldid'] = ''; // Parsoid wants empty string rather than zero $parserParams['oldid'] = ''; // Parsoid wants empty string rather than zero
@ -20,6 +23,8 @@ class ApiVisualEditor extends ApiBase {
if ( $revision === null ) { if ( $revision === null ) {
return false; return false;
} }
$restoring = !$revision->isCurrent();
$parserParams['touched'] = $title->getTouched(); $parserParams['touched'] = $title->getTouched();
$parserParams['cache'] = 1; $parserParams['cache'] = 1;
@ -59,9 +64,12 @@ class ApiVisualEditor extends ApiBase {
$timestamp = wfTimestampNow(); $timestamp = wfTimestampNow();
} }
return array( return array(
'result' => array(
'content' => $content, 'content' => $content,
'basetimestamp' => $timestamp, 'basetimestamp' => $timestamp,
'starttimestamp' => wfTimestampNow() 'starttimestamp' => wfTimestampNow(),
),
'restoring' => $restoring,
); );
} }
@ -232,6 +240,9 @@ class ApiVisualEditor extends ApiBase {
if ( $user->isAnon() ) { if ( $user->isAnon() ) {
$wgVisualEditorEditNotices[] = 'anoneditwarning'; $wgVisualEditorEditNotices[] = 'anoneditwarning';
} }
if ( $parsed && $parsed['restoring'] ) {
$wgVisualEditorEditNotices[] = 'editingold';
}
if ( count( $wgVisualEditorEditNotices ) ) { if ( count( $wgVisualEditorEditNotices ) ) {
foreach ( $wgVisualEditorEditNotices as $key ) { foreach ( $wgVisualEditorEditNotices as $key ) {
$notices[] = wfMessage( $key )->parseAsBlock(); $notices[] = wfMessage( $key )->parseAsBlock();
@ -241,7 +252,7 @@ class ApiVisualEditor extends ApiBase {
$this->dieUsage( 'Error contacting the Parsoid server', 'parsoidserver' ); $this->dieUsage( 'Error contacting the Parsoid server', 'parsoidserver' );
} else { } else {
$result = array_merge( $result = array_merge(
array( 'result' => 'success', 'notices' => $notices ), $parsed array( 'result' => 'success', 'notices' => $notices ), $parsed['result']
); );
} }
break; break;