jenkins-bot has submitted this change and it was merged.
Change subject: Section blocks should have id attribute
......................................................................
Section blocks should have id attribute
An id attribute allows JavaScript to access the DOMElement
representing the section body via getElementById. Given the wider
support for this method in comparison to getElementsByClassName
and the fact that classes are not meant to be unique per element
the existing usages of mf-section- classes are discouraged.
Change-Id: I53cfd1f593405d73ff1e0c0630f3a05803a9d1c2
---
M includes/MobileFormatter.php
M tests/phpunit/MobileFormatterTest.php
M tests/phpunit/api/ApiParseExtenderTest.php
3 files changed, 25 insertions(+), 10 deletions(-)
Approvals:
Pmiazga: Looks good to me, but someone else must approve
Jdlrobson: Looks good to me, but someone else must approve
jenkins-bot: Verified
Phuedx: Looks good to me, approved
diff --git a/includes/MobileFormatter.php b/includes/MobileFormatter.php
index 32e5d9d..75fe6bf 100644
--- a/includes/MobileFormatter.php
+++ b/includes/MobileFormatter.php
@@ -531,8 +531,7 @@
$firstHeading = reset( $headings );
$sectionNumber = 0;
- $sectionBody = $doc->createElement( 'div' );
- $sectionBody->setAttribute( 'class', 'mf-section-' .
$sectionNumber );
+ $sectionBody = $this->createSectionBodyElement( $doc,
$sectionNumber );
// Mark the top level headings which will become collapsible
soon.
foreach ( $headings as $heading ) {
@@ -576,9 +575,7 @@
}
}
$sectionNumber += 1;
- $sectionBody = $doc->createElement( 'div' );
- $sectionBody->setAttribute( 'class',
'mf-section-' . $sectionNumber );
-
+ $sectionBody = $this->createSectionBodyElement(
$doc, $sectionNumber );
continue;
}
@@ -601,6 +598,23 @@
}
/**
+ * Creates a Section body element
+ *
+ * @param DOMDocument $doc
+ * @param int $sectionNumber
+ *
+ * @return DOMElement
+ */
+ private function createSectionBodyElement( DOMDocument $doc,
$sectionNumber ) {
+ // FIXME: The class `/mf\-section\-[0-9]+/` is kept for caching
reasons
+ // but given class is unique usage is discouraged. [T126825]
+ $sectionBody = $doc->createElement( 'div' );
+ $sectionBody->setAttribute( 'class', 'mf-section-' .
$sectionNumber );
+ $sectionBody->setAttribute( 'id', 'mf-section-' .
$sectionNumber );
+ return $sectionBody;
+ }
+
+ /**
* Marks the headings as editable by adding the <code>in-block</code>
* class to each of them, if it hasn't already been added.
*
diff --git a/tests/phpunit/MobileFormatterTest.php
b/tests/phpunit/MobileFormatterTest.php
index db443d7..2bd7aba 100644
--- a/tests/phpunit/MobileFormatterTest.php
+++ b/tests/phpunit/MobileFormatterTest.php
@@ -31,7 +31,8 @@
*/
private function makeSectionHtml( $sectionNumber, $contentHtml='',
$isReferenceSection=false ) {
$attrs = $isReferenceSection ? ' data-is-reference-section="1"'
: '';
- return "<div
class=\"mf-section-$sectionNumber\"$attrs>$contentHtml</div>";
+ return "<div class=\"mf-section-$sectionNumber\"
id=\"mf-section-$sectionNumber\""
+ . "$attrs>$contentHtml</div>";
}
/**
diff --git a/tests/phpunit/api/ApiParseExtenderTest.php
b/tests/phpunit/api/ApiParseExtenderTest.php
index 041ff45..5bdb1cf 100644
--- a/tests/phpunit/api/ApiParseExtenderTest.php
+++ b/tests/phpunit/api/ApiParseExtenderTest.php
@@ -48,21 +48,21 @@
'mobileformat' => '',
'text' => "I exist\n\n<span
class='nomobile'>I don't</span>"
],
- '<div class="mf-section-0"><p>I
exist</p><p></p></div>' ],
+ '<div class="mf-section-0"
id="mf-section-0"><p>I exist</p><p></p></div>' ],
[
[
'mobileformat' => 'html',
'text' =>
"Lede<h2>Section1</h2>Text<h2>Section2</h2>Text"
],
- '<div class="mf-section-0">Lede</div>' .
+ '<div class="mf-section-0"
id="mf-section-0">Lede</div>' .
'<h2 class="section-heading">' .
self::SECTION_INDICATOR .
'<span class="mw-headline"
id="Section1">Section1</span></h2>' .
- '<div class="mf-section-1">Text</div>' .
+ '<div class="mf-section-1"
id="mf-section-1">Text</div>' .
'<h2 class="section-heading">' .
self::SECTION_INDICATOR .
'<span class="mw-headline"
id="Section2">Section2</span></h2>' .
- '<div class="mf-section-2">Text</div>' ],
+ '<div class="mf-section-2"
id="mf-section-2">Text</div>' ],
];
}
}
--
To view, visit https://gerrit.wikimedia.org/r/319066
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I53cfd1f593405d73ff1e0c0630f3a05803a9d1c2
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>
Gerrit-Reviewer: Bmansurov <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: Phuedx <[email protected]>
Gerrit-Reviewer: Pmiazga <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits