From 24c9f458168ea8b34a433b8ad9a2c6feedeebbe0 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Fri, 27 Mar 2015 16:22:37 -0700 Subject: [PATCH] Stash edits alongside the html -> wikitext stashing step * The standard core method for page saving already checks the cache. By stashing the parser output as the user types, the final save step will be faster, just as with the wikitext editor. Bug: T90040 Change-Id: If10a79381c6301d52f4a68ca91d0e1d7fbc79bb5 --- ApiVisualEditor.php | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/ApiVisualEditor.php b/ApiVisualEditor.php index 31d8aad7c4..70e4a10f17 100644 --- a/ApiVisualEditor.php +++ b/ApiVisualEditor.php @@ -162,13 +162,28 @@ class ApiVisualEditor extends ApiBase { protected function storeInSerializationCache( $title, $oldid, $html ) { global $wgMemc; - $content = $this->postHTML( $title, $html, array( 'oldid' => $oldid ) ); - if ( $content === false ) { + + // Convert the VE HTML to wikitext + $text = $this->postHTML( $title, $html, array( 'oldid' => $oldid ) ); + if ( $text === false ) { return false; } - $hash = md5( $content ); + + // Store the corresponding wikitext, referenceable by a new key + $hash = md5( $text ); $key = wfMemcKey( 'visualeditor', 'serialization', $hash ); - $wgMemc->set( $key, $content, $this->veConfig->get( 'VisualEditorSerializationCacheTimeout' ) ); + $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'." ); + } + return $hash; }