Jdlrobson has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/405812 )
Change subject: Other less common lead paragraph edge cases
......................................................................
Other less common lead paragraph edge cases
* Sometimes a collapsible class wraps the infobox e.g.
Ardrossan_Railway and
Edinburgh_and_Dalkeith_Railway
Change-Id: I82c099265c11612105ad3e790e66dd3e9d44b878
---
M includes/transforms/MoveLeadParagraphTransform.php
M tests/phpunit/transforms/MoveLeadParagraphTransformTest.php
2 files changed, 9 insertions(+), 3 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend
refs/changes/12/405812/1
diff --git a/includes/transforms/MoveLeadParagraphTransform.php
b/includes/transforms/MoveLeadParagraphTransform.php
index 08ef454..28d2f85 100644
--- a/includes/transforms/MoveLeadParagraphTransform.php
+++ b/includes/transforms/MoveLeadParagraphTransform.php
@@ -36,7 +36,7 @@
private static function matchElement( DOMElement $node,
$requiredNodeName, $requiredClass ) {
$classes = explode( ' ', $node->getAttribute( 'class' ) );
return strtolower( $node->nodeName ) === $requiredNodeName
- && in_array( $requiredClass, $classes );
+ && !empty( preg_grep( $requiredClass, $classes ) );
}
/**
@@ -45,12 +45,12 @@
* @param string $wrapperClass (optional) a required classname for
wrapper
* @return DomElement representing an unwrapped infobox or an element
that wraps the infobox
*/
- public static function getInfoboxContainer( $node, $wrapperClass =
'mw-stack' ) {
+ public static function getInfoboxContainer( $node, $wrapperClass =
'/(mw-stack|collapsible)/' ) {
$infobox = false;
// iterate to the top.
while ( $node->parentNode ) {
- if ( self::matchElement( $node, 'table', 'infobox' ) ||
+ if ( self::matchElement( $node, 'table', '/infobox/' )
||
self::matchElement( $node, 'div', $wrapperClass
) ) {
$infobox = $node;
}
diff --git a/tests/phpunit/transforms/MoveLeadParagraphTransformTest.php
b/tests/phpunit/transforms/MoveLeadParagraphTransformTest.php
index bfd8dc7..21b837f 100644
--- a/tests/phpunit/transforms/MoveLeadParagraphTransformTest.php
+++ b/tests/phpunit/transforms/MoveLeadParagraphTransformTest.php
@@ -88,9 +88,15 @@
$multiStackInfobox = "<div
class=\"mw-stack\">$infobox$anotherInfobox</div>";
$paragraph = '<p>first paragraph</p>';
$emptyP = '<p></p>';
+ $collapsibleInfobox = '<div class="collapsible"><table
class="mf-infobox"></table></div>';
return [
[
+ "$collapsibleInfobox<p>one</p>",
+ "<p>one</p>$collapsibleInfobox",
+ 'Collapsible infoboxes are moved.'
+ ],
+ [
'<div><table
class="mf-infobox"></table></div><p>one</p>',
'<div><table
class="mf-infobox"></table></div><p>one</p>'
],
--
To view, visit https://gerrit.wikimedia.org/r/405812
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I82c099265c11612105ad3e790e66dd3e9d44b878
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits