Gallery: Handle invalid titles

Items which are invalid titles will still get discarded if
the gallery is edited, but this is better than crashing.

Bug: T260584
Change-Id: I5dc20c233fd9ab41bdf48531829bddca2c5b25df
This commit is contained in:
Ed Sanders 2020-08-17 19:13:42 +01:00 committed by Jforrester
parent 7d366a3f6a
commit 42c7096dbf
2 changed files with 10 additions and 4 deletions

View file

@ -18,7 +18,7 @@
ve.ce.MWGalleryImageNode = function VeCeMWGalleryImageNode( model ) {
var attributes, galleryMwAttrs, mode, imagePadding,
outerDivWidth, imageHeight, innerDivHeight, innerDivMargin, innerDivWidth,
$thumbDiv, $innerDiv, $a, $img,
$thumbDiv, $innerDiv, $a, $img, resourceTitle,
defaults = mw.config.get( 'wgVisualEditorConfig' ).galleryOptions;
// Parent constructor
@ -60,6 +60,8 @@ ve.ce.MWGalleryImageNode = function VeCeMWGalleryImageNode( model ) {
outerDivWidth = innerDivWidth + 4;
}
resourceTitle = mw.Title.newFromText( attributes.resource );
this.$element
.addClass( 'gallerybox' )
.css( 'width', outerDivWidth + 'px' );
@ -79,7 +81,7 @@ ve.ce.MWGalleryImageNode = function VeCeMWGalleryImageNode( model ) {
.attr( 'width', attributes.width );
this.$filenameA = $( '<a>' )
.attr( 'href', '#' ) // Just to make it look like a link
.text( mw.Title.newFromText( attributes.resource ).getMainText() )
.text( resourceTitle ? resourceTitle.getMainText() : attributes.resource )
.toggleClass( 'oo-ui-element-hidden', galleryMwAttrs.showfilename !== 'yes' );
this.$element.prepend(

View file

@ -400,7 +400,7 @@ ve.ui.MWGalleryDialog.prototype.initialize = function () {
ve.ui.MWGalleryDialog.prototype.getSetupProcess = function ( data ) {
return ve.ui.MWGalleryDialog.super.prototype.getSetupProcess.call( this, data )
.next( function () {
var i, ilen, resource, imageTitles,
var i, ilen, resourceTitle, resource, imageTitles,
image, imageCaptionNode,
mode, widths, heights, perrow,
showFilename, classes, styles,
@ -421,7 +421,11 @@ ve.ui.MWGalleryDialog.prototype.getSetupProcess = function ( data ) {
for ( i = 0, ilen = imageNodes.length; i < ilen; i++ ) {
image = imageNodes[ i ];
resource = mw.Title.newFromText( image.getAttribute( 'resource' ), namespaceIds.file ).getPrefixedText();
resourceTitle = mw.Title.newFromText( image.getAttribute( 'resource' ), namespaceIds.file );
if ( !resourceTitle ) {
continue;
}
resource = resourceTitle.getPrefixedText();
imageCaptionNode = image.getCaptionNode();
imageTitles.push( resource );
this.initialImageData.push( {