Merge "Allow localized gallery widths; avoid spurious "double px" tracking category"

This commit is contained in:
jenkins-bot 2024-10-02 21:39:40 +00:00 committed by Gerrit Code Review
commit f4dc788b5c
3 changed files with 69 additions and 2 deletions

View file

@ -5430,7 +5430,8 @@ class Parser {
# Special case; width and height come in one variable together
if ( $type === 'handler' && $paramName === 'width' ) {
$parsedWidthParam = $this->parseWidthParam( $value );
// The 'px' suffix has already been localized by img_width
$parsedWidthParam = $this->parseWidthParam( $value, true, true );
// Parsoid applies data-(width|height) attributes to broken
// media spans, for client use. See T273013
$validateFunc = static function ( $name, $value ) use ( $handler ) {
@ -6368,17 +6369,27 @@ class Parser {
*
* @param string $value
* @param bool $parseHeight
* @param bool $localized Defaults to false; set to true if the $value
* has already been matched against `img_width` to localize the `px`
* suffix.
*
* @return array
* @since 1.20
* @internal
*/
public function parseWidthParam( $value, $parseHeight = true ) {
public function parseWidthParam( $value, $parseHeight = true, bool $localized = false ) {
$parsedWidthParam = [];
if ( $value === '' ) {
return $parsedWidthParam;
}
$m = [];
if ( !$localized ) {
// Strip a localized 'px' suffix (T374311)
$mwArray = $this->magicWordFactory->newArray( [ 'img_width' ] );
[ $magicWord, $newValue ] = $mwArray->matchVariableStartToEnd( $value );
$value = $magicWord ? $newValue : $value;
}
# (T15500) In both cases (width/height and width only),
# permit trailing "px" for backward compatibility.
if ( $parseHeight && preg_match( '/^([0-9]*)x([0-9]*)\s*(px)?\s*$/', $value, $m ) ) {

View file

@ -488,6 +488,34 @@ cat=Pages_with_image_sizes_containing_extra_px sort=
<p><span typeof="mw:File"><a href="./File:Foobar.jpg" class="mw-file-description"><img resource="./File:Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/20px-Foobar.jpg" decoding="async" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="2" width="20" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/30px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/40px-Foobar.jpg 2x" class="mw-file-element"/></a></span> <span typeof="mw:File"><a href="./File:Foobar.jpg" class="mw-file-description"><img resource="./File:Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/177px-Foobar.jpg" decoding="async" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="20" width="177" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/265px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/353px-Foobar.jpg 2x" class="mw-file-element"/></a></span></p>
!! end
!! test
T374311: Gallery with trailing px should not trigger double-px
!! config
wgParserEnableLegacyMediaDOM=true
!! options
parsoid=wt2html
cat
!! wikitext
<gallery widths="100px">
File:Foobar.jpg
</gallery>
!! metadata
!! html/php
<ul class="gallery mw-gallery-traditional">
<li class="gallerybox" style="width: 135px"><div style="width: 135px">
<div class="thumb" style="width: 130px;"><div style="margin:69.5px auto;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/100px-Foobar.jpg" decoding="async" width="100" height="11" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/150px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg 2x" /></a></div></div>
<div class="gallerytext"></div>
</div></li>
</ul>
!! html/parsoid
<ul class="gallery mw-gallery-traditional" typeof="mw:Extension/gallery" data-mw='{"name":"gallery","attrs":{"widths":"100px"},"body":{}}'>
<li class="gallerybox" style="width: 135px;">
<div class="thumb" style="width: 130px; height: 150px;"><span typeof="mw:File"><a href="./File:Foobar.jpg" class="mw-file-description"><img resource="./File:Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/100px-Foobar.jpg" decoding="async" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="11" width="100" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/150px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg 2x" class="mw-file-element"/></a></span></div>
<div class="gallerytext"></div>
</li>
</ul>
!! end
!! test
Image with link parameter, wiki target
!! config

View file

@ -519,6 +519,34 @@ cat=Pages_with_image_sizes_containing_extra_px sort=
<p><span typeof="mw:File"><a href="./File:Foobar.jpg" class="mw-file-description"><img resource="./File:Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/20px-Foobar.jpg" decoding="async" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="2" width="20" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/30px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/40px-Foobar.jpg 2x" class="mw-file-element"/></a></span> <span typeof="mw:File"><a href="./File:Foobar.jpg" class="mw-file-description"><img resource="./File:Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/177px-Foobar.jpg" decoding="async" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="20" width="177" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/265px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/353px-Foobar.jpg 2x" class="mw-file-element"/></a></span></p>
!! end
!! test
T374311: Gallery with trailing px should not trigger double-px
!! config
wgParserEnableLegacyMediaDOM=false
!! options
parsoid=wt2html
cat
!! wikitext
<gallery widths="100px">
File:Foobar.jpg
</gallery>
!! metadata
!! html/php
<ul class="gallery mw-gallery-traditional">
<li class="gallerybox" style="width: 135px">
<div class="thumb" style="width: 130px; height: 150px;"><span typeof="mw:File"><a href="/wiki/File:Foobar.jpg" class="mw-file-description"><img src="http://example.com/images/thumb/3/3a/Foobar.jpg/100px-Foobar.jpg" decoding="async" width="100" height="11" class="mw-file-element" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/150px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg 2x" /></a></span></div>
<div class="gallerytext"></div>
</li>
</ul>
!! html/parsoid
<ul class="gallery mw-gallery-traditional" typeof="mw:Extension/gallery" data-mw='{"name":"gallery","attrs":{"widths":"100px"},"body":{}}'>
<li class="gallerybox" style="width: 135px;">
<div class="thumb" style="width: 130px; height: 150px;"><span typeof="mw:File"><a href="./File:Foobar.jpg" class="mw-file-description"><img resource="./File:Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/100px-Foobar.jpg" decoding="async" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="11" width="100" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/150px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg 2x" class="mw-file-element"/></a></span></div>
<div class="gallerytext"></div>
</li>
</ul>
!! end
!! test
Image with link parameter, wiki target
!! config