Emit media structure as piloted in Parsoid
Gated behind the flag $wgParserEnableLegacyMediaDOM. The scattershot usage of it is a little unfortunate but isn't expected to live very long so maybe that's acceptable. Further details can be found at, https://www.mediawiki.org/wiki/Parsing/Media_structure Bug: T51097 Bug: T266148 Bug: T271129 Change-Id: I978187f9f6e9e0a105521ab3e26821e36a96b911
This commit is contained in:
parent
f3ecfead48
commit
fdd8f864b8
11 changed files with 4093 additions and 70 deletions
|
|
@ -4927,11 +4927,12 @@ $wgAllowImageTag = false;
|
|||
$wgTidyConfig = [];
|
||||
|
||||
/**
|
||||
* Emit using the new media structure described at,
|
||||
* Enable legacy media HTML structure in the output from the Parser. The one
|
||||
* that replaces it is described at,
|
||||
* https://www.mediawiki.org/wiki/Parsing/Media_structure
|
||||
* @since 1.36
|
||||
*/
|
||||
$wgUseNewMediaStructure = false;
|
||||
$wgParserEnableLegacyMediaDOM = true;
|
||||
|
||||
/**
|
||||
* Allow raw, unchecked HTML in "<html>...</html>" sections.
|
||||
|
|
|
|||
|
|
@ -331,13 +331,24 @@ class Linker {
|
|||
$frameParams['class'] = '';
|
||||
}
|
||||
|
||||
$services = MediaWikiServices::getInstance();
|
||||
$enableLegacyMediaDOM = $services->getMainConfig()->get( 'ParserEnableLegacyMediaDOM' );
|
||||
|
||||
$classes = [];
|
||||
if ( !isset( $handlerParams['width'] ) ) {
|
||||
$classes[] = 'mw-default-size';
|
||||
}
|
||||
|
||||
$prefix = $postfix = '';
|
||||
|
||||
if ( $frameParams['align'] == 'center' ) {
|
||||
$prefix = '<div class="center">';
|
||||
$postfix = '</div>';
|
||||
$frameParams['align'] = 'none';
|
||||
if ( $enableLegacyMediaDOM ) {
|
||||
if ( $frameParams['align'] == 'center' ) {
|
||||
$prefix = '<div class="center">';
|
||||
$postfix = '</div>';
|
||||
$frameParams['align'] = 'none';
|
||||
}
|
||||
}
|
||||
|
||||
if ( $file && !isset( $handlerParams['width'] ) ) {
|
||||
if ( isset( $handlerParams['height'] ) && $file->isVectorized() ) {
|
||||
// If its a vector image, and user only specifies height
|
||||
|
|
@ -385,20 +396,38 @@ class Linker {
|
|||
if ( isset( $frameParams['thumbnail'] ) || isset( $frameParams['manualthumb'] )
|
||||
|| isset( $frameParams['framed'] )
|
||||
) {
|
||||
# Create a thumbnail. Alignment depends on the writing direction of
|
||||
# the page content language (right-aligned for LTR languages,
|
||||
# left-aligned for RTL languages)
|
||||
# If a thumbnail width has not been provided, it is set
|
||||
# to the default user option as specified in Language*.php
|
||||
if ( $frameParams['align'] == '' ) {
|
||||
$frameParams['align'] = $parser->getTargetLanguage()->alignEnd();
|
||||
if ( $enableLegacyMediaDOM ) {
|
||||
// This is no longer needed in our new media output, since the
|
||||
// default styling in content.media.less takes care of it;
|
||||
// see T269704.
|
||||
|
||||
# Create a thumbnail. Alignment depends on the writing direction of
|
||||
# the page content language (right-aligned for LTR languages,
|
||||
# left-aligned for RTL languages)
|
||||
# If a thumbnail width has not been provided, it is set
|
||||
# to the default user option as specified in Language*.php
|
||||
if ( $frameParams['align'] == '' ) {
|
||||
$frameParams['align'] = $parser->getTargetLanguage()->alignEnd();
|
||||
}
|
||||
}
|
||||
return $prefix .
|
||||
self::makeThumbLink2( $title, $file, $frameParams, $handlerParams, $time, $query ) .
|
||||
self::makeThumbLink2( $title, $file, $frameParams, $handlerParams, $time, $query, $classes ) .
|
||||
$postfix;
|
||||
}
|
||||
|
||||
switch ( $file ? $file->getMediaType() : '' ) {
|
||||
case 'AUDIO':
|
||||
$rdfaType = 'mw:Audio';
|
||||
break;
|
||||
case 'VIDEO':
|
||||
$rdfaType = 'mw:Video';
|
||||
break;
|
||||
default:
|
||||
$rdfaType = 'mw:Image';
|
||||
}
|
||||
|
||||
if ( $file && isset( $frameParams['frameless'] ) ) {
|
||||
$rdfaType .= '/Frameless';
|
||||
$srcWidth = $file->getWidth( $page );
|
||||
# For "frameless" option: do not present an image bigger than the
|
||||
# source (for bitmap-style images). This is the same behavior as the
|
||||
|
|
@ -416,29 +445,79 @@ class Linker {
|
|||
}
|
||||
|
||||
if ( !$thumb ) {
|
||||
$s = self::makeBrokenImageLinkObj( $title, $frameParams['title'], '', '', '', $time == true );
|
||||
$rdfaType = 'mw:Error ' . $rdfaType;
|
||||
$label = '';
|
||||
if ( $enableLegacyMediaDOM ) {
|
||||
// This is the information for tooltips for inline images which
|
||||
// Parsoid stores in data-mw. See T273014
|
||||
$label = $frameParams['title'];
|
||||
}
|
||||
$s = self::makeBrokenImageLinkObj(
|
||||
$title, $label, '', '', '', $time == true, $handlerParams
|
||||
);
|
||||
} else {
|
||||
self::processResponsiveImages( $file, $thumb, $handlerParams );
|
||||
$params = [
|
||||
'alt' => $frameParams['alt'],
|
||||
'title' => $frameParams['title'],
|
||||
'valign' => $frameParams['valign'] ?? false,
|
||||
'img-class' => $frameParams['class'] ];
|
||||
if ( isset( $frameParams['border'] ) ) {
|
||||
$params['img-class'] .= ( $params['img-class'] !== '' ? ' ' : '' ) . 'thumbborder';
|
||||
];
|
||||
if ( $enableLegacyMediaDOM ) {
|
||||
$params += [
|
||||
'valign' => $frameParams['valign'] ?? false,
|
||||
'img-class' => $frameParams['class'],
|
||||
];
|
||||
if ( isset( $frameParams['border'] ) ) {
|
||||
$params['img-class'] .= ( $params['img-class'] !== '' ? ' ' : '' ) . 'thumbborder';
|
||||
}
|
||||
}
|
||||
$params = self::getImageLinkMTOParams( $frameParams, $query, $parser ) + $params;
|
||||
|
||||
$s = $thumb->toHtml( $params );
|
||||
}
|
||||
if ( $frameParams['align'] != '' ) {
|
||||
$s = Html::rawElement(
|
||||
'div',
|
||||
[ 'class' => 'float' . $frameParams['align'] ],
|
||||
$s
|
||||
);
|
||||
|
||||
if ( $enableLegacyMediaDOM ) {
|
||||
if ( $frameParams['align'] != '' ) {
|
||||
$s = Html::rawElement(
|
||||
'div',
|
||||
[ 'class' => 'float' . $frameParams['align'] ],
|
||||
$s
|
||||
);
|
||||
}
|
||||
return str_replace( "\n", ' ', $prefix . $s . $postfix );
|
||||
}
|
||||
return str_replace( "\n", ' ', $prefix . $s . $postfix );
|
||||
|
||||
$wrapper = 'span';
|
||||
$caption = '';
|
||||
|
||||
if ( $frameParams['align'] != '' ) {
|
||||
$wrapper = 'figure';
|
||||
// Possible values: mw-halign-left mw-halign-center mw-halign-right mw-halign-none
|
||||
$classes[] = "mw-halign-{$frameParams['align']}";
|
||||
$caption = Html::rawElement(
|
||||
'figcaption', [], $frameParams['caption'] ?? ''
|
||||
);
|
||||
} elseif ( isset( $frameParams['valign'] ) ) {
|
||||
// Possible values: mw-valign-middle mw-valign-baseline mw-valign-sub
|
||||
// mw-valign-super mw-valign-top mw-valign-text-top mw-valign-bottom
|
||||
// mw-valign-text-bottom
|
||||
$classes[] = "mw-valign-{$frameParams['valign']}";
|
||||
}
|
||||
|
||||
if ( isset( $frameParams['border'] ) ) {
|
||||
$classes[] = 'mw-image-border';
|
||||
}
|
||||
|
||||
if ( isset( $frameParams['class'] ) ) {
|
||||
$classes[] = $frameParams['class'];
|
||||
}
|
||||
|
||||
$attribs = [
|
||||
'class' => $classes,
|
||||
'typeof' => $rdfaType,
|
||||
];
|
||||
|
||||
$s = Html::rawElement( $wrapper, $attribs, $s . $caption );
|
||||
|
||||
return str_replace( "\n", ' ', $s );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -483,14 +562,15 @@ class Linker {
|
|||
* @param File|bool $file File object or false if it doesn't exist
|
||||
* @param string $label
|
||||
* @param string $alt
|
||||
* @param string $align
|
||||
* @param string|null $align
|
||||
* @param array $params
|
||||
* @param bool $framed
|
||||
* @param string $manualthumb
|
||||
* @return string
|
||||
*/
|
||||
public static function makeThumbLinkObj( LinkTarget $title, $file, $label = '', $alt = '',
|
||||
$align = 'right', $params = [], $framed = false, $manualthumb = ""
|
||||
public static function makeThumbLinkObj(
|
||||
LinkTarget $title, $file, $label = '', $alt = '', $align = null,
|
||||
$params = [], $framed = false, $manualthumb = ""
|
||||
) {
|
||||
$frameParams = [
|
||||
'alt' => $alt,
|
||||
|
|
@ -503,7 +583,10 @@ class Linker {
|
|||
if ( $manualthumb ) {
|
||||
$frameParams['manualthumb'] = $manualthumb;
|
||||
}
|
||||
return self::makeThumbLink2( $title, $file, $frameParams, $params );
|
||||
$classes = [ 'mw-default-size' ];
|
||||
return self::makeThumbLink2(
|
||||
$title, $file, $frameParams, $params, false, '', $classes
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -513,16 +596,24 @@ class Linker {
|
|||
* @param array $handlerParams
|
||||
* @param bool $time
|
||||
* @param string $query
|
||||
* @param string[] $classes @since 1.36
|
||||
* @return string
|
||||
*/
|
||||
public static function makeThumbLink2( LinkTarget $title, $file, $frameParams = [],
|
||||
$handlerParams = [], $time = false, $query = ""
|
||||
public static function makeThumbLink2(
|
||||
LinkTarget $title, $file, $frameParams = [], $handlerParams = [],
|
||||
$time = false, $query = "", array $classes = []
|
||||
) {
|
||||
$exists = $file && $file->exists();
|
||||
|
||||
$services = MediaWikiServices::getInstance();
|
||||
$enableLegacyMediaDOM = $services->getMainConfig()->get( 'ParserEnableLegacyMediaDOM' );
|
||||
|
||||
$page = $handlerParams['page'] ?? false;
|
||||
if ( !isset( $frameParams['align'] ) ) {
|
||||
$frameParams['align'] = 'right';
|
||||
$frameParams['align'] = '';
|
||||
if ( $enableLegacyMediaDOM ) {
|
||||
$frameParams['align'] = 'right';
|
||||
}
|
||||
}
|
||||
if ( !isset( $frameParams['alt'] ) ) {
|
||||
$frameParams['alt'] = '';
|
||||
|
|
@ -538,9 +629,11 @@ class Linker {
|
|||
// Reduce width for upright images when parameter 'upright' is used
|
||||
$handlerParams['width'] = isset( $frameParams['upright'] ) ? 130 : 180;
|
||||
}
|
||||
|
||||
$thumb = false;
|
||||
$noscale = false;
|
||||
$manualthumb = false;
|
||||
$rdfaType = null;
|
||||
|
||||
if ( !$exists ) {
|
||||
$outerWidth = $handlerParams['width'] + 2;
|
||||
|
|
@ -549,7 +642,7 @@ class Linker {
|
|||
# Use manually specified thumbnail
|
||||
$manual_title = Title::makeTitleSafe( NS_FILE, $frameParams['manualthumb'] );
|
||||
if ( $manual_title ) {
|
||||
$manual_img = MediaWikiServices::getInstance()->getRepoGroup()
|
||||
$manual_img = $services->getRepoGroup()
|
||||
->findFile( $manual_title );
|
||||
if ( $manual_img ) {
|
||||
$thumb = $manual_img->getUnscaledThumb( $handlerParams );
|
||||
|
|
@ -562,6 +655,7 @@ class Linker {
|
|||
// Use image dimensions, don't scale
|
||||
$thumb = $file->getUnscaledThumb( $handlerParams );
|
||||
$noscale = true;
|
||||
$rdfaType = '/Frame';
|
||||
} else {
|
||||
# Do not present an image bigger than the source, for bitmap-style images
|
||||
# This is a hack to maintain compatibility with arbitrary pre-1.10 behavior
|
||||
|
|
@ -579,13 +673,15 @@ class Linker {
|
|||
}
|
||||
}
|
||||
|
||||
# ThumbnailImage::toHtml() already adds page= onto the end of DjVu URLs
|
||||
# So we don't need to pass it here in $query. However, the URL for the
|
||||
# zoom icon still needs it, so we make a unique query for it. See T16771
|
||||
$url = Title::newFromLinkTarget( $title )->getLocalURL( $query );
|
||||
if ( $page ) {
|
||||
|
||||
if ( $enableLegacyMediaDOM && $page ) {
|
||||
# ThumbnailImage::toHtml() already adds page= onto the end of DjVu URLs
|
||||
# So we don't need to pass it here in $query. However, the URL for the
|
||||
# zoom icon still needs it, so we make a unique query for it. See T16771
|
||||
$url = wfAppendQuery( $url, [ 'page' => $page ] );
|
||||
}
|
||||
|
||||
if ( $manualthumb
|
||||
&& !isset( $frameParams['link-title'] )
|
||||
&& !isset( $frameParams['link-url'] )
|
||||
|
|
@ -593,13 +689,35 @@ class Linker {
|
|||
$frameParams['link-url'] = $url;
|
||||
}
|
||||
|
||||
$s = "<div class=\"thumb t{$frameParams['align']}\">"
|
||||
. "<div class=\"thumbinner\" style=\"width:{$outerWidth}px;\">";
|
||||
if ( $frameParams['align'] != '' ) {
|
||||
// Possible values: mw-halign-left mw-halign-center mw-halign-right mw-halign-none
|
||||
$classes[] = "mw-halign-{$frameParams['align']}";
|
||||
}
|
||||
|
||||
if ( isset( $frameParams['class'] ) ) {
|
||||
$classes[] = $frameParams['class'];
|
||||
}
|
||||
|
||||
$s = '';
|
||||
|
||||
if ( $enableLegacyMediaDOM ) {
|
||||
$s .= "<div class=\"thumb t{$frameParams['align']}\">"
|
||||
. "<div class=\"thumbinner\" style=\"width:{$outerWidth}px;\">";
|
||||
}
|
||||
|
||||
if ( !$exists ) {
|
||||
$s .= self::makeBrokenImageLinkObj( $title, $frameParams['title'], '', '', '', $time == true );
|
||||
$label = '';
|
||||
if ( $enableLegacyMediaDOM ) {
|
||||
// This is the information for tooltips for inline images which
|
||||
// Parsoid stores in data-mw. See T273014
|
||||
$label = $frameParams['title'];
|
||||
}
|
||||
$s .= self::makeBrokenImageLinkObj(
|
||||
$title, $label, '', '', '', $time == true, $handlerParams
|
||||
);
|
||||
$zoomIcon = '';
|
||||
} elseif ( !$thumb ) {
|
||||
// FIXME(T169975): Add "mw:Error"?
|
||||
$s .= wfMessage( 'thumbnail_error', '' )->escaped();
|
||||
$zoomIcon = '';
|
||||
} else {
|
||||
|
|
@ -609,10 +727,14 @@ class Linker {
|
|||
$params = [
|
||||
'alt' => $frameParams['alt'],
|
||||
'title' => $frameParams['title'],
|
||||
'img-class' => ( isset( $frameParams['class'] ) && $frameParams['class'] !== ''
|
||||
? $frameParams['class'] . ' '
|
||||
: '' ) . 'thumbimage'
|
||||
];
|
||||
if ( $enableLegacyMediaDOM ) {
|
||||
$params += [
|
||||
'img-class' => ( isset( $frameParams['class'] ) && $frameParams['class'] !== ''
|
||||
? $frameParams['class'] . ' '
|
||||
: '' ) . 'thumbimage'
|
||||
];
|
||||
}
|
||||
$params = self::getImageLinkMTOParams( $frameParams, $query ) + $params;
|
||||
$s .= $thumb->toHtml( $params );
|
||||
if ( isset( $frameParams['framed'] ) ) {
|
||||
|
|
@ -626,7 +748,40 @@ class Linker {
|
|||
"" ) );
|
||||
}
|
||||
}
|
||||
$s .= ' <div class="thumbcaption">' . $zoomIcon . $frameParams['caption'] . "</div></div></div>";
|
||||
|
||||
if ( $enableLegacyMediaDOM ) {
|
||||
$s .= ' <div class="thumbcaption">' . $zoomIcon . $frameParams['caption'] . "</div></div></div>";
|
||||
return str_replace( "\n", ' ', $s );
|
||||
}
|
||||
|
||||
$s .= Html::rawElement(
|
||||
'figcaption', [], $frameParams['caption'] ?? ''
|
||||
);
|
||||
|
||||
$rdfaType = $rdfaType ?: '/Thumb';
|
||||
|
||||
switch ( $file ? $file->getMediaType() : '' ) {
|
||||
case 'AUDIO':
|
||||
$rdfaType = 'mw:Audio' . $rdfaType;
|
||||
break;
|
||||
case 'VIDEO':
|
||||
$rdfaType = 'mw:Video' . $rdfaType;
|
||||
break;
|
||||
default:
|
||||
$rdfaType = 'mw:Image' . $rdfaType;
|
||||
}
|
||||
|
||||
if ( !$exists ) {
|
||||
$rdfaType = 'mw:Error ' . $rdfaType;
|
||||
}
|
||||
|
||||
$attribs = [
|
||||
'class' => $classes,
|
||||
'typeof' => $rdfaType,
|
||||
];
|
||||
|
||||
$s = Html::rawElement( 'figure', $attribs, $s );
|
||||
|
||||
return str_replace( "\n", ' ', $s );
|
||||
}
|
||||
|
||||
|
|
@ -671,10 +826,12 @@ class Linker {
|
|||
* @param string $unused1 Unused parameter kept for b/c
|
||||
* @param string $unused2 Unused parameter kept for b/c
|
||||
* @param bool $time A file of a certain timestamp was requested
|
||||
* @param array $handlerParams @since 1.36
|
||||
* @return string
|
||||
*/
|
||||
public static function makeBrokenImageLinkObj( $title, $label = '',
|
||||
$query = '', $unused1 = '', $unused2 = '', $time = false
|
||||
public static function makeBrokenImageLinkObj(
|
||||
$title, $label = '', $query = '', $unused1 = '', $unused2 = '',
|
||||
$time = false, array $handlerParams = []
|
||||
) {
|
||||
if ( !$title instanceof LinkTarget ) {
|
||||
wfWarn( __METHOD__ . ': Requires $title to be a LinkTarget object.' );
|
||||
|
|
@ -687,8 +844,19 @@ class Linker {
|
|||
if ( $label == '' ) {
|
||||
$label = $title->getPrefixedText();
|
||||
}
|
||||
$html = htmlspecialchars( $label );
|
||||
$repoGroup = MediaWikiServices::getInstance()->getRepoGroup();
|
||||
|
||||
$html = Html::element( 'span', [
|
||||
// These data attributes are used to dynamically size the span, see T273013
|
||||
'data-width' => $handlerParams['width'] ?? null,
|
||||
'data-height' => $handlerParams['height'] ?? null,
|
||||
], $label );
|
||||
|
||||
$services = MediaWikiServices::getInstance();
|
||||
if ( $services->getMainConfig()->get( 'ParserEnableLegacyMediaDOM' ) ) {
|
||||
$html = htmlspecialchars( $label );
|
||||
}
|
||||
|
||||
$repoGroup = $services->getRepoGroup();
|
||||
$currentExists = $time
|
||||
&& $repoGroup->findFile( $title ) !== false;
|
||||
|
||||
|
|
|
|||
|
|
@ -79,6 +79,8 @@ class TraditionalImageGallery extends ImageGalleryBase {
|
|||
}
|
||||
|
||||
$lang = $this->getRenderLang();
|
||||
$enableLegacyMediaDOM = $this->getConfig()->get( 'ParserEnableLegacyMediaDOM' );
|
||||
|
||||
# Output each image...
|
||||
foreach ( $this->mImages as [ $nt, $text, $alt, $link, $handlerOpts, $loading ] ) {
|
||||
// "text" means "caption" here
|
||||
|
|
@ -155,16 +157,39 @@ class TraditionalImageGallery extends ImageGalleryBase {
|
|||
|
||||
Linker::processResponsiveImages( $img, $thumb, $transformOptions );
|
||||
|
||||
# Set both fixed width and min-height.
|
||||
$thumbhtml = "\n\t\t\t"
|
||||
. '<div class="thumb" style="width: '
|
||||
. $this->getThumbDivWidth( $thumb->getWidth() ) . 'px;">'
|
||||
switch ( $img->getMediaType() ) {
|
||||
case 'AUDIO':
|
||||
$rdfaType = 'mw:Audio';
|
||||
break;
|
||||
case 'VIDEO':
|
||||
$rdfaType = 'mw:Video';
|
||||
break;
|
||||
default:
|
||||
$rdfaType = 'mw:Image';
|
||||
}
|
||||
|
||||
$thumbhtml = $thumb->toHtml( $imageParameters );
|
||||
|
||||
if ( !$enableLegacyMediaDOM ) {
|
||||
$thumbhtml = Html::rawElement(
|
||||
'span', [ 'typeof' => $rdfaType ], $thumbhtml
|
||||
);
|
||||
}
|
||||
|
||||
$thumbhtml = Html::rawElement( 'div', [
|
||||
# Auto-margin centering for block-level elements. Needed
|
||||
# now that we have video handlers since they may emit block-
|
||||
# level elements as opposed to simple <img> tags. ref
|
||||
# http://css-discuss.incutio.com/?page=CenteringBlockElement
|
||||
. '<div style="margin:' . $vpad . 'px auto;">'
|
||||
. $thumb->toHtml( $imageParameters ) . '</div></div>';
|
||||
'style' => "margin:{$vpad}px auto;",
|
||||
], $thumbhtml );
|
||||
|
||||
# Set both fixed width and min-height.
|
||||
$width = $this->getThumbDivWidth( $thumb->getWidth() );
|
||||
$thumbhtml = "\n\t\t\t" . Html::rawElement( 'div', [
|
||||
'class' => 'thumb',
|
||||
'style' => "width: {$width}px;",
|
||||
], $thumbhtml );
|
||||
|
||||
// Call parser transform hook
|
||||
/** @var MediaHandler $handler */
|
||||
|
|
|
|||
|
|
@ -232,6 +232,7 @@ abstract class MediaTransformOutput {
|
|||
|
||||
/**
|
||||
* Wrap some XHTML text in an anchor tag with the given attributes
|
||||
* or, fallback to a span in the absence thereof.
|
||||
*
|
||||
* @param array $linkAttribs
|
||||
* @param string $contents
|
||||
|
|
@ -241,7 +242,12 @@ abstract class MediaTransformOutput {
|
|||
if ( $linkAttribs ) {
|
||||
return Xml::tags( 'a', $linkAttribs, $contents );
|
||||
} else {
|
||||
return $contents;
|
||||
global $wgParserEnableLegacyMediaDOM;
|
||||
if ( $wgParserEnableLegacyMediaDOM ) {
|
||||
return $contents;
|
||||
} else {
|
||||
return Xml::tags( 'span', null, $contents );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -269,8 +275,13 @@ abstract class MediaTransformOutput {
|
|||
|
||||
$attribs = [
|
||||
'href' => $this->file->getTitle()->getLocalURL( $query ),
|
||||
'class' => 'image',
|
||||
];
|
||||
|
||||
global $wgParserEnableLegacyMediaDOM;
|
||||
if ( $wgParserEnableLegacyMediaDOM ) {
|
||||
$attribs['class'] = 'image';
|
||||
}
|
||||
|
||||
if ( $title ) {
|
||||
$attribs['title'] = $title;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5213,6 +5213,9 @@ class Parser {
|
|||
foreach ( $handlerParamMap as $magic => $paramName ) {
|
||||
$paramMap[$magic] = [ 'handler', $paramName ];
|
||||
}
|
||||
} else {
|
||||
// Parse the size for non-existent files. See T273013
|
||||
$paramMap[ 'img_width' ] = [ 'handler', 'width' ];
|
||||
}
|
||||
$this->mImageParams[$handlerClass] = $paramMap;
|
||||
$this->mImageParamsMagicArray[$handlerClass] =
|
||||
|
|
@ -5295,16 +5298,23 @@ class Parser {
|
|||
# Special case; width and height come in one variable together
|
||||
if ( $type === 'handler' && $paramName === 'width' ) {
|
||||
$parsedWidthParam = self::parseWidthParam( $value );
|
||||
// Parsoid applies data-(width|height) attributes to broken
|
||||
// media spans, for client use. See T273013
|
||||
$validateFunc = static function ( $name, $value ) use ( $handler ) {
|
||||
return $handler
|
||||
? $handler->validateParam( $name, $value )
|
||||
: $value > 0;
|
||||
};
|
||||
if ( isset( $parsedWidthParam['width'] ) ) {
|
||||
$width = $parsedWidthParam['width'];
|
||||
if ( $handler->validateParam( 'width', $width ) ) {
|
||||
if ( $validateFunc( 'width', $width ) ) {
|
||||
$params[$type]['width'] = $width;
|
||||
$validated = true;
|
||||
}
|
||||
}
|
||||
if ( isset( $parsedWidthParam['height'] ) ) {
|
||||
$height = $parsedWidthParam['height'];
|
||||
if ( $handler->validateParam( 'height', $height ) ) {
|
||||
if ( $validateFunc( 'height', $height ) ) {
|
||||
$params[$type]['height'] = $height;
|
||||
$validated = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ class ResourceLoaderSkinModule extends ResourceLoaderLessVarFileModule {
|
|||
*
|
||||
* "content-media":
|
||||
* Styles for thumbnails and floated elements.
|
||||
* Will add styles for the new media structure on wikis where $wgUseNewMediaStructure is enabled.
|
||||
* Will add styles for the new media structure on wikis where $wgParserEnableLegacyMediaDOM is disabled.
|
||||
* See https://www.mediawiki.org/wiki/Parsing/Media_structure
|
||||
*
|
||||
* "content-links":
|
||||
|
|
@ -339,7 +339,7 @@ class ResourceLoaderSkinModule extends ResourceLoaderLessVarFileModule {
|
|||
);
|
||||
}
|
||||
}
|
||||
if ( $feature === 'content-media' && $this->getConfig()->get( 'UseNewMediaStructure' ) ) {
|
||||
if ( $feature === 'content-media' && !$this->getConfig()->get( 'ParserEnableLegacyMediaDOM' ) ) {
|
||||
$featureFilePaths['screen'][] = new ResourceLoaderFilePath(
|
||||
'resources/src/mediawiki.skinning/content.media.less',
|
||||
$defaultLocalBasePath,
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@ class ParserTestRunner {
|
|||
'pfeqParserTests.txt',
|
||||
'extraParserTests.txt',
|
||||
'legacyMediaParserTests.txt',
|
||||
'mediaParserTests.txt',
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
|||
3797
tests/parser/mediaParserTests.txt
Normal file
3797
tests/parser/mediaParserTests.txt
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -8622,6 +8622,8 @@ Link containing double-single-quotes '' in text embedded in italics (T6598 sanit
|
|||
## FIXME: Title part of filename is interpreted in php
|
||||
!! test
|
||||
Link with double quotes in title part (literal) and alternate part (interpreted)
|
||||
!! config
|
||||
wgParserEnableLegacyMediaDOM=false
|
||||
!! wikitext
|
||||
[[File:Denys_Savchenko_''Pentecoste''.jpg]]
|
||||
|
||||
|
|
@ -8631,7 +8633,7 @@ Link with double quotes in title part (literal) and alternate part (interpreted)
|
|||
|
||||
[[''Pentecoste''|''Pentecoste'']]
|
||||
!! html/php
|
||||
<p><a href="/index.php?title=Special:Upload&wpDestFile=Denys_Savchenko_%27%27Pentecoste%27%27.jpg" class="new" title="File:Denys Savchenko ''Pentecoste''.jpg">File:Denys Savchenko <i>Pentecoste</i>.jpg</a>
|
||||
<p><span class="mw-default-size" typeof="mw:Error mw:Image"><a href="/index.php?title=Special:Upload&wpDestFile=Denys_Savchenko_%27%27Pentecoste%27%27.jpg" class="new" title="File:Denys Savchenko ''Pentecoste''.jpg"><span>File:Denys Savchenko <i>Pentecoste</i>.jpg</span></a></span>
|
||||
</p><p><a href="/index.php?title=%27%27Pentecoste%27%27&action=edit&redlink=1" class="new" title="''Pentecoste'' (page does not exist)">''Pentecoste''</a>
|
||||
</p><p><a href="/index.php?title=%27%27Pentecoste%27%27&action=edit&redlink=1" class="new" title="''Pentecoste'' (page does not exist)">Pentecoste</a>
|
||||
</p><p><a href="/index.php?title=%27%27Pentecoste%27%27&action=edit&redlink=1" class="new" title="''Pentecoste'' (page does not exist)"><i>Pentecoste</i></a>
|
||||
|
|
@ -18383,13 +18385,15 @@ all additional text is vanished
|
|||
Language converter glossary rules inside attributes (T119158)
|
||||
!! options
|
||||
language=sr variant=sr-el
|
||||
!! config
|
||||
wgParserEnableLegacyMediaDOM=false
|
||||
!! wikitext
|
||||
-{H|foAjrjvi=>sr-el:" onload="alert(1)" data-foo="}-
|
||||
|
||||
[[File:Foobar.jpg|alt=-{}-foAjrjvi-{}-]]
|
||||
!! html/php
|
||||
<p class="mw-empty-elt">
|
||||
</p><p><a href="/wiki/%D0%94%D0%B0%D1%82%D0%BE%D1%82%D0%B5%D0%BA%D0%B0:Foobar.jpg" class="image"><img alt="" onload="alert(1)" data-foo="" src="http://example.com/images/3/3a/Foobar.jpg" decoding="async" width="1941" height="220" /></a>
|
||||
</p><p><span class="mw-default-size" typeof="mw:Image"><a href="/wiki/%D0%94%D0%B0%D1%82%D0%BE%D1%82%D0%B5%D0%BA%D0%B0:Foobar.jpg"><img alt="" onload="alert(1)" data-foo="" src="http://example.com/images/3/3a/Foobar.jpg" decoding="async" width="1941" height="220" /></a></span>
|
||||
</p>
|
||||
!! html/parsoid
|
||||
<p><meta typeof="mw:LanguageVariant" data-mw-variant='{"add":true,"oneway":[{"f":"foAjrjvi","l":"sr-el","t":"\" onload=\"alert(1)\" data-foo=\""}]}'/></p>
|
||||
|
|
@ -22904,6 +22908,8 @@ name=
|
|||
Page status indicators: Torture test
|
||||
!! options
|
||||
showindicators
|
||||
!! config
|
||||
wgParserEnableLegacyMediaDOM=false
|
||||
!! wikitext
|
||||
<indicator name="01">hello world</indicator>
|
||||
<indicator name="02">[[Main Page]]</indicator>
|
||||
|
|
@ -22923,8 +22929,8 @@ paragraphs</indicator>
|
|||
!! html/php
|
||||
01=hello world
|
||||
02=<a href="/wiki/Main_Page" title="Main Page">Main Page</a>
|
||||
03=<img alt="Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/25px-Foobar.jpg" decoding="async" width="25" height="3" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/38px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/50px-Foobar.jpg 2x" />
|
||||
04=<a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/25px-Foobar.jpg" decoding="async" width="25" height="3" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/38px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/50px-Foobar.jpg 2x" /></a>
|
||||
03=<span typeof="mw:Image"><span><img alt="Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/25px-Foobar.jpg" decoding="async" width="25" height="3" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/38px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/50px-Foobar.jpg 2x" /></span></span>
|
||||
04=<span typeof="mw:Image"><a href="/wiki/File:Foobar.jpg"><img alt="Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/25px-Foobar.jpg" decoding="async" width="25" height="3" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/38px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/50px-Foobar.jpg 2x" /></a></span>
|
||||
05=<ul><li>foo</li>
|
||||
<li>bar</li></ul>
|
||||
06=foo
|
||||
|
|
@ -23067,6 +23073,8 @@ Strip reserved data attributes
|
|||
|
||||
!! test
|
||||
percent-encoding and + signs in internal links (T28410)
|
||||
!! config
|
||||
wgParserEnableLegacyMediaDOM=false
|
||||
!! wikitext
|
||||
[[User:+%]] [[Page+title%]]
|
||||
[[%+]] [[%+|%20]] [[%+ ]] [[%+r]]
|
||||
|
|
@ -23075,7 +23083,7 @@ percent-encoding and + signs in internal links (T28410)
|
|||
!! html/php
|
||||
<p><a href="/index.php?title=User:%2B%25&action=edit&redlink=1" class="new" title="User:+% (page does not exist)">User:+%</a> <a href="/index.php?title=Page%2Btitle%25&action=edit&redlink=1" class="new" title="Page+title% (page does not exist)">Page+title%</a>
|
||||
<a href="/index.php?title=%25%2B&action=edit&redlink=1" class="new" title="%+ (page does not exist)">%+</a> <a href="/index.php?title=%25%2B&action=edit&redlink=1" class="new" title="%+ (page does not exist)">%20</a> <a href="/index.php?title=%25%2B&action=edit&redlink=1" class="new" title="%+ (page does not exist)">%+ </a> <a href="/index.php?title=%25%2Br&action=edit&redlink=1" class="new" title="%+r (page does not exist)">%+r</a>
|
||||
<a href="/index.php?title=%25&action=edit&redlink=1" class="new" title="% (page does not exist)">%</a> <a href="/index.php?title=%2B&action=edit&redlink=1" class="new" title="+ (page does not exist)">+</a> <a href="/index.php?title=Special:Upload&wpDestFile=%25%2Babc9" class="new" title="File:%+abc9">bar</a>
|
||||
<a href="/index.php?title=%25&action=edit&redlink=1" class="new" title="% (page does not exist)">%</a> <a href="/index.php?title=%2B&action=edit&redlink=1" class="new" title="+ (page does not exist)">+</a> <span class="mw-default-size" typeof="mw:Error mw:Image"><a href="/index.php?title=Special:Upload&wpDestFile=%25%2Babc9" class="new" title="File:%+abc9"><span>File:%+abc9</span></a></span>
|
||||
<a href="/index.php?title=3E&action=edit&redlink=1" class="new" title="3E (page does not exist)">3E</a> <a href="/index.php?title=3E%2B&action=edit&redlink=1" class="new" title="3E+ (page does not exist)">3E+</a>
|
||||
</p>
|
||||
!! html/parsoid
|
||||
|
|
@ -23255,6 +23263,8 @@ __TOC__
|
|||
T35845: Headings become cursive in TOC when they contain an image
|
||||
!! options
|
||||
title=[[Main Page]]
|
||||
!! config
|
||||
wgParserEnableLegacyMediaDOM=false
|
||||
!! wikitext
|
||||
__TOC__
|
||||
==Image [[Image:foobar.jpg]]==
|
||||
|
|
@ -23265,7 +23275,7 @@ __TOC__
|
|||
</ul>
|
||||
</div>
|
||||
|
||||
<h2><span class="mw-headline" id="Image">Image <a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" decoding="async" width="1941" height="220" /></a></span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Main_Page&action=edit&section=1" title="Edit section: Image">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
|
||||
<h2><span class="mw-headline" id="Image">Image <span class="mw-default-size" typeof="mw:Image"><a href="/wiki/File:Foobar.jpg"><img alt="Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" decoding="async" width="1941" height="220" /></a></span></span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Main_Page&action=edit&section=1" title="Edit section: Image">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
|
||||
!! html/parsoid
|
||||
<meta property="mw:PageProp/toc" data-parsoid='{}'/>
|
||||
<h2 id="Image" data-parsoid='{}'>Image <span class="mw-default-size" typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941" data-parsoid='{"a":{"resource":"./File:Foobar.jpg","height":"220","width":"1941"},"sa":{"resource":"Image:foobar.jpg"}}'/></a></span></h2>
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ abstract class ResourceLoaderTestCase extends MediaWikiIntegrationTestCase {
|
|||
'Logos' => false,
|
||||
'Logo' => '/logo.png',
|
||||
'ResourceBasePath' => '/w',
|
||||
'UseNewMediaStructure' => false,
|
||||
'ParserEnableLegacyMediaDOM' => true,
|
||||
|
||||
// For ResourceLoaderStartUpModule and ResourceLoader::__construct()
|
||||
'ScriptPath' => '/w',
|
||||
|
|
|
|||
|
|
@ -199,7 +199,7 @@ CSS
|
|||
$module->expects( $this->once() )->method( 'getLogoData' )
|
||||
->willReturn( $logo );
|
||||
$module->setConfig( new HashConfig( [
|
||||
'UseNewMediaStructure' => true,
|
||||
'ParserEnableLegacyMediaDOM' => false,
|
||||
] + self::getSettings() ) );
|
||||
|
||||
$ctx = $this->getMockBuilder( ResourceLoaderContext::class )
|
||||
|
|
|
|||
Loading…
Reference in a new issue