Update displaytitle on save (try #3)

Parse the wikitext we already have.

This is mostly a revert of commit f84b880a54.

Bug: 50341
Change-Id: I312bafb0e7d61b0abd42d6ca7ea2e4b5dcdc61be
This commit is contained in:
Alex Monk 2014-06-21 01:37:30 +00:00
parent f84b880a54
commit dc6840c3a0
3 changed files with 27 additions and 5 deletions

View file

@ -116,6 +116,14 @@ class ApiVisualEditorEdit extends ApiVisualEditor {
}
$result['isRedirect'] = $page->isRedirect();
$content = new WikitextContent( $wikitext );
$parserOutput = $content->getParserOutput( $page );
if ( $parserOutput ) {
$result['displayTitleHtml'] = $parserOutput->getDisplayTitle();
} else {
wfDebug( '[VE] ApiVisualEditorEdit - parserOutput was false' );
}
if ( isset( $saveresult['edit']['newrevid'] ) ) {
$result['newrevid'] = intval( $saveresult['edit']['newrevid'] );
}

View file

@ -421,9 +421,11 @@ ve.init.mw.ViewPageTarget.prototype.onSurfaceReady = function () {
* @method
* @param {string} html Rendered page HTML from server
* @param {string} categoriesHtml Rendered categories HTML from server
* @param {number} [newid] New revision id, undefined if unchanged
* @param {number} newid New revision id, undefined if unchanged
* @param {boolean} isRedirect Whether this page is a redirect or not
* @param {string} displayTitle What HTML to show as the page title
*/
ve.init.mw.ViewPageTarget.prototype.onSave = function ( html, categoriesHtml, newid, isRedirect ) {
ve.init.mw.ViewPageTarget.prototype.onSave = function ( html, categoriesHtml, newid, isRedirect, displayTitle ) {
var newUrlParams, watchChecked;
if ( !this.pageExists || this.restoring ) {
// This is a page creation or restoration, refresh the page
@ -466,7 +468,7 @@ ve.init.mw.ViewPageTarget.prototype.onSave = function ( html, categoriesHtml, ne
}
this.saveDialog.close();
this.saveDialog.reset();
this.replacePageContent( html, categoriesHtml, isRedirect );
this.replacePageContent( html, categoriesHtml, isRedirect, displayTitle );
this.setupSectionEditLinks();
this.tearDownBeforeUnloadHandler();
this.deactivate( true );
@ -1534,8 +1536,10 @@ ve.init.mw.ViewPageTarget.prototype.onWindowPopState = function ( e ) {
* @method
* @param {string} html Rendered HTML from server
* @param {string} categoriesHtml Rendered categories HTML from server
* @param {boolean} isRedirect Whether this page is a redirect or not
* @param {string} displayTitle What HTML to show as the page title
*/
ve.init.mw.ViewPageTarget.prototype.replacePageContent = function ( html, categoriesHtml, isRedirect ) {
ve.init.mw.ViewPageTarget.prototype.replacePageContent = function ( html, categoriesHtml, isRedirect, displayTitle ) {
var $content = $( $.parseHTML( html ) ), $editableContent;
if ( $( '#mw-imagepage-content' ).length ) {
@ -1555,6 +1559,9 @@ ve.init.mw.ViewPageTarget.prototype.replacePageContent = function ( html, catego
}
mw.hook( 'wikipage.content' ).fire( $editableContent.empty().append( $content ) );
if ( displayTitle ) {
$( '#content > #firstHeading > span' ).html( displayTitle );
}
$( '#catlinks' ).replaceWith( categoriesHtml );
if ( isRedirect ) {
$( '#contentSub' ).text( ve.msg( 'redirectpagesub' ) );

View file

@ -543,7 +543,14 @@ ve.init.mw.Target.onSave = function ( doc, saveData, response ) {
} else if ( typeof data.content !== 'string' ) {
this.onSaveError( doc, saveData, null, 'Invalid HTML content in response from server', response );
} else {
this.emit( 'save', data.content, data.categorieshtml, data.newrevid, data.isRedirect );
this.emit(
'save',
data.content,
data.categorieshtml,
data.newrevid,
data.isRedirect,
data.displayTitleHtml
);
}
};