Move HtmlUtils from mmv.bootstrap to mmv module

HtmlUtils is used for stripping HTML code. This is the responsibility of the individual UI components.

More specifically, MultimediaViewerBootstrap.processParsoidThumb no longer strips HTML code. Various UI components were already calling HtmlUtils.htmlToTextWithLinks. Only the error case in MultimediaViewer.loadImage newly needs HTML stripping applied.

Bug: T65504
Change-Id: If24b9c220a6ec43f35251a4ec6a716fd4ba03df6
This commit is contained in:
Simon Legner 2024-10-17 22:53:49 +02:00 committed by Jdlrobson
parent fe5687b6ef
commit fb4e80a1b1
14 changed files with 21 additions and 20 deletions

View file

@ -2,7 +2,7 @@
"modules": [
{
"resourceModule": "mmv",
"maxSize": "24.6 kB"
"maxSize": "25.2 kB"
},
{
"resourceModule": "mmv.ui.restriction",
@ -18,7 +18,7 @@
},
{
"resourceModule": "mmv.bootstrap",
"maxSize": "5.3 kB"
"maxSize": "4.8 kB"
}
]
}

View file

@ -62,6 +62,7 @@
"mmv/provider/mmv.provider.ThumbnailInfo.js",
"mmv/provider/mmv.provider.GuessedThumbnailInfo.js",
"mmv/provider/mmv.provider.Image.js",
"mmv/mmv.HtmlUtils.js",
"mmv/mmv.ThumbnailWidthCalculator.js",
"mmv/ui/mmv.ui.js",
"mmv/ui/mmv.ui.dialog.js",
@ -281,8 +282,7 @@
"mmv.bootstrap/mmv.bootstrap.autostart.js",
"mmv.bootstrap/mmv.bootstrap.js",
"mmv.bootstrap/mmv.lightboximage.js",
"mmv.bootstrap/mmv.Config.js",
"mmv.bootstrap/mmv.HtmlUtils.js"
"mmv.bootstrap/mmv.Config.js"
],
"styles": [
"mmv.bootstrap/mmv.bootstrap.less"

View file

@ -21,10 +21,9 @@
const Config = require( './mmv.Config.js' );
const MultimediaViewerBootstrap = require( './mmv.bootstrap.js' );
const LightboxImage = require( './mmv.lightboximage.js' );
const HtmlUtils = require( './mmv.HtmlUtils.js' );
const bootstrap = new MultimediaViewerBootstrap();
$( bootstrap.setupEventHandlers.bind( bootstrap ) );
module.exports = { MultimediaViewerBootstrap, LightboxImage, Config, HtmlUtils };
module.exports = { MultimediaViewerBootstrap, LightboxImage, Config };

View file

@ -16,7 +16,6 @@
*/
const Config = require( './mmv.Config.js' );
const HtmlUtils = require( './mmv.HtmlUtils.js' );
const LightboxImage = require( './mmv.lightboximage.js' );
const { extensions } = require( './config.json' );
const mwRouter = require( 'mediawiki.router' );
@ -332,7 +331,6 @@ class MultimediaViewerBootstrap {
);
const title = mw.Title.newFromImg( $thumb );
let caption;
let $thumbCaption;
if ( !this.isValidExtension( title ) ) {
// Short-circuit event handler and interface setup, because
@ -349,8 +347,7 @@ class MultimediaViewerBootstrap {
}
if ( ( $thumbContainer.prop( 'tagName' ) || '' ).toLowerCase() === 'figure' ) {
$thumbCaption = $thumbContainer.find( 'figcaption' );
caption = HtmlUtils.htmlToTextWithTags( $thumbCaption.html() || '' );
caption = $thumbContainer.find( 'figcaption' ).html() || '';
} else {
caption = $link.prop( 'title' ) || undefined;
}
@ -482,7 +479,7 @@ class MultimediaViewerBootstrap {
$thumbCaption.find( '.magnify' ).remove();
}
return HtmlUtils.htmlToTextWithTags( $thumbCaption.html() || '' );
return $thumbCaption.html() || '';
}
/**

View file

@ -15,7 +15,8 @@
* along with MediaViewer. If not, see <http://www.gnu.org/licenses/>.
*/
const { Config, HtmlUtils } = require( 'mmv.bootstrap' );
const { Config } = require( 'mmv.bootstrap' );
const { HtmlUtils } = require( 'mmv' );
/**
* Converts data in various formats needed by the Embed sub-dialog

View file

@ -16,6 +16,7 @@
*/
const { Config } = require( 'mmv.bootstrap' );
const HtmlUtils = require( './mmv.HtmlUtils.js' );
const ViewLogger = require( './logging/mmv.logging.ViewLogger.js' );
const Api = require( './provider/mmv.provider.Api.js' );
const GuessedThumbnailInfo = require( './provider/mmv.provider.GuessedThumbnailInfo.js' );
@ -265,7 +266,9 @@ class MultimediaViewer {
if ( this.currentIndex === image.index ) {
// Set title to caption or file name if caption is not available;
// see setTitle() in mmv.ui.metadataPanel for extended caption fallback
this.ui.panel.showError( image.caption || image.filePageTitle.getNameText(), error );
this.ui.panel.showError( image.caption ?
HtmlUtils.htmlToTextWithTags( image.caption ) :
image.filePageTitle.getNameText(), error );
}
return $.Deferred().reject( error );
@ -871,6 +874,7 @@ module.exports = {
Description,
Dialog,
GuessedThumbnailInfo,
HtmlUtils,
ImageInfo,
ImageModel,
ImageProvider,

View file

@ -15,7 +15,7 @@
* along with MediaViewer. If not, see <http://www.gnu.org/licenses/>.
*/
const { HtmlUtils } = require( 'mmv.bootstrap' );
const HtmlUtils = require( '../mmv.HtmlUtils.js' );
/**
* Class for storing license information about an image. For available fields, see

View file

@ -15,7 +15,7 @@
* along with MediaViewer. If not, see <http://www.gnu.org/licenses/>.
*/
const { HtmlUtils } = require( 'mmv.bootstrap' );
const HtmlUtils = require( '../mmv.HtmlUtils.js' );
const ThumbnailWidthCalculator = require( '../mmv.ThumbnailWidthCalculator.js' );
const UiElement = require( './mmv.ui.js' );

View file

@ -15,7 +15,7 @@
* along with MultimediaViewer. If not, see <http://www.gnu.org/licenses/>.
*/
const { HtmlUtils } = require( 'mmv.bootstrap' );
const HtmlUtils = require( '../mmv.HtmlUtils.js' );
const UiElement = require( './mmv.ui.js' );
/**

View file

@ -15,7 +15,7 @@
* along with MultimediaViewer. If not, see <http://www.gnu.org/licenses/>.
*/
const { HtmlUtils } = require( 'mmv.bootstrap' );
const HtmlUtils = require( '../mmv.HtmlUtils.js' );
const Description = require( './mmv.ui.description.js' );
const UiElement = require( './mmv.ui.js' );
const MetadataPanelScroller = require( './mmv.ui.metadataPanelScroller.js' );

View file

@ -15,7 +15,7 @@
* along with MediaViewer. If not, see <http://www.gnu.org/licenses/>.
*/
const { HtmlUtils } = require( 'mmv.bootstrap' );
const HtmlUtils = require( '../mmv.HtmlUtils.js' );
const UiElement = require( './mmv.ui.js' );
const MetadataPanelScroller = require( './mmv.ui.metadataPanelScroller.js' );

View file

@ -15,7 +15,7 @@
* along with MultimediaViewer. If not, see <http://www.gnu.org/licenses/>.
*/
const { HtmlUtils } = require( 'mmv.bootstrap' );
const HtmlUtils = require( '../mmv.HtmlUtils.js' );
const UiElement = require( './mmv.ui.js' );
/**

View file

@ -15,7 +15,7 @@
* along with MediaViewer. If not, see <http://www.gnu.org/licenses/>.
*/
const { HtmlUtils } = require( 'mmv.bootstrap' );
const { HtmlUtils } = require( 'mmv' );
( function () {
/* eslint-disable no-jquery/no-parse-html-literal */