Merge "De-duplicate replacePageContent methods between desktop and mobile"

This commit is contained in:
jenkins-bot 2022-09-29 14:00:00 +00:00 committed by Gerrit Code Review
commit 77565dabf3
3 changed files with 36 additions and 47 deletions

View file

@ -577,7 +577,6 @@ ve.init.mw.ArticleTarget.prototype.loadFail = function () {
* Replace the page content with new HTML.
*
* @method
* @abstract
* @param {string} html Rendered HTML from server
* @param {string} categoriesHtml Rendered categories HTML from server
* @param {string} displayTitle HTML to show as the page title
@ -586,7 +585,32 @@ ve.init.mw.ArticleTarget.prototype.loadFail = function () {
* @param {string} contentSub HTML to show as the content subtitle
* @param {Array} sections Section data to display in the TOC
*/
ve.init.mw.ArticleTarget.prototype.replacePageContent = null;
ve.init.mw.ArticleTarget.prototype.replacePageContent = function (
html, categoriesHtml, displayTitle, lastModified, contentSub, sections
) {
// eslint-disable-next-line no-jquery/no-append-html
this.$editableContent.find( '.mw-parser-output' ).first().replaceWith( html );
mw.hook( 'wikipage.content' ).fire( this.$editableContent );
if ( displayTitle ) {
// eslint-disable-next-line no-jquery/no-html
$( '#firstHeading' ).html( displayTitle );
}
// Categories are only shown in AMC on mobile
if ( $( '#catlinks' ).length ) {
var $categories = $( $.parseHTML( categoriesHtml ) );
mw.hook( 'wikipage.categories' ).fire( $categories );
$( '#catlinks' ).replaceWith( $categories );
}
// eslint-disable-next-line no-jquery/no-html
$( '#contentSub, .minerva__subtitle' ).html( contentSub );
this.setRealRedirectInterface();
mw.hook( 'wikipage.tableOfContents' ).fire( sections );
};
/**
* Handle successful DOM save event.

View file

@ -1231,8 +1231,11 @@ ve.init.mw.DesktopArticleTarget.prototype.onWindowPopState = function ( e ) {
* @inheritdoc
*/
ve.init.mw.DesktopArticleTarget.prototype.replacePageContent = function (
html, categoriesHtml, displayTitle, lastModified, contentSub, sections
html, categoriesHtml, displayTitle, lastModified /* , contentSub, sections */
) {
// Parent method
ve.init.mw.DesktopArticleTarget.super.prototype.replacePageContent.apply( this, arguments );
if ( lastModified ) {
// If we were not viewing the most recent revision before (a requirement
// for lastmod to have been added by MediaWiki), we will be now.
@ -1251,25 +1254,8 @@ ve.init.mw.DesktopArticleTarget.prototype.replacePageContent = function (
) );
}
// eslint-disable-next-line no-jquery/no-append-html
this.$editableContent.find( '.mw-parser-output' ).first().replaceWith( html );
mw.hook( 'wikipage.content' ).fire( this.$editableContent );
if ( displayTitle ) {
// eslint-disable-next-line no-jquery/no-html
$( '#firstHeading' ).html( displayTitle );
}
var $categories = $( $.parseHTML( categoriesHtml ) );
mw.hook( 'wikipage.categories' ).fire( $categories );
$( '#catlinks' ).replaceWith( $categories );
this.$originalCategories = null;
// eslint-disable-next-line no-jquery/no-html
$( '#contentSub' ).html( contentSub );
this.setRealRedirectInterface();
mw.hook( 'wikipage.tableOfContents' ).fire( sections );
// Re-set any edit section handlers now that the page content has been replaced
mw.libs.ve.setupEditLinks();
};

View file

@ -35,6 +35,9 @@ ve.init.mw.MobileArticleTarget = function VeInitMwMobileArticleTarget( overlay,
// Parent constructor
ve.init.mw.MobileArticleTarget.super.call( this, config );
// eslint-disable-next-line no-jquery/no-global-selector
this.$editableContent = $( '#mw-content-text' );
if ( config.section !== undefined ) {
this.section = config.section;
}
@ -402,40 +405,16 @@ ve.init.mw.MobileArticleTarget.prototype.showSaveDialog = function () {
* @inheritdoc
*/
ve.init.mw.MobileArticleTarget.prototype.replacePageContent = function (
html, categoriesHtml, displayTitle, lastModified, contentSub, sections
html, categoriesHtml, displayTitle, lastModified /* , contentSub, sections */
) {
var $content = $( $.parseHTML( html ) );
// Parent method
ve.init.mw.MobileArticleTarget.super.prototype.replacePageContent.apply( this, arguments );
if ( lastModified ) {
// TODO: Update the last-modified-bar with the correct info
// eslint-disable-next-line no-jquery/no-global-selector
$( '.last-modified-bar' ).remove();
}
// eslint-disable-next-line no-jquery/no-global-selector
var $editableContent = $( '#mw-content-text' );
$editableContent.find( '.mw-parser-output' ).replaceWith( $content );
mw.hook( 'wikipage.content' ).fire( $editableContent );
if ( displayTitle ) {
// eslint-disable-next-line no-jquery/no-html, no-jquery/no-global-selector
$( '#firstHeading' ).html( displayTitle );
}
// Categories are only shown in AMC
// eslint-disable-next-line no-jquery/no-global-selector
if ( $( '#catlinks' ).length ) {
var $categories = $( $.parseHTML( categoriesHtml ) );
mw.hook( 'wikipage.categories' ).fire( $categories );
// eslint-disable-next-line no-jquery/no-global-selector
$( '#catlinks' ).replaceWith( $categories );
}
// eslint-disable-next-line no-jquery/no-global-selector, no-jquery/no-html
$( '.minerva__subtitle' ).html( contentSub );
mw.hook( 'wikipage.tableOfContents' ).fire( sections );
this.setRealRedirectInterface();
};
/**