jenkins-bot has submitted this change and it was merged.
Change subject: Collapse references sections by default
......................................................................
Collapse references sections by default
* References sections now have data-is-reference-section attribute
set so they can be distinguished by others
* These are collapsed by default, even in tablet mode.
Bug: T135865
Change-Id: I5ebe531a897524872a05ab44f6e82985cd9ecd2b
---
M includes/MobileFormatter.php
M resources/mobile.toggle/toggle.js
M tests/phpunit/MobileFormatterTest.php
M tests/qunit/mobile.toggle/test_toggle.js
M tests/qunit/tests.mobilefrontend/section.hogan
5 files changed, 71 insertions(+), 39 deletions(-)
Approvals:
Jhobs: Looks good to me, but someone else must approve
Phuedx: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/MobileFormatter.php b/includes/MobileFormatter.php
index 2fbc0ed..6bda2ad 100644
--- a/includes/MobileFormatter.php
+++ b/includes/MobileFormatter.php
@@ -137,15 +137,11 @@
$this->remove( $removableClasses );
}
- if ( $removeReferences ) {
- $this->doRewriteReferencesForLazyLoading();
- }
-
if ( $this->removeMedia ) {
$this->doRemoveImages();
}
- $transformOptions = [ 'images' => $removeImages ];
+ $transformOptions = [ 'images' => $removeImages, 'references'
=> $removeReferences ];
// Sectionify the content and transform it if necessary per
section
if ( !$this->mainPage && $this->expandableSections ) {
list( $headings, $subheadings ) = $this->getHeadings(
$doc );
@@ -154,6 +150,9 @@
} else {
// Otherwise apply the per-section transformations to
the document as a whole
$this->filterContentInSection( $doc, $doc, 0,
$transformOptions );
+ }
+ if ( $transformOptions['references'] ) {
+ $this->doRewriteReferencesLinksForLazyLoading( $doc );
}
return parent::filterContent();
@@ -172,18 +171,46 @@
if ( !$this->removeMedia && $options['images'] &&
$sectionNumber > 0 ) {
$this->doRewriteImagesForLazyLoading( $el, $doc );
}
+ if ( $options['references'] ) {
+ $this->doRewriteReferencesListsForLazyLoading( $el,
$doc );
+ }
}
/**
- * Replaces any references list with a link to Special:References
+ * Replaces any references links with a link to Special:MobileCite
+ *
+ * @param DOMDocument $doc Document to create and replace elements in
*/
- private function doRewriteReferencesForLazyLoading() {
- $prefixedTitle = $this->title->getPrefixedText();
+ private function doRewriteReferencesLinksForLazyLoading( DOMDocument
$doc ) {
$citePath = "$this->revId";
- $doc = $this->getDoc();
+ $xPath = new DOMXPath( $doc );
+ $nodes = $xPath->query(
+ // sup.reference > a
+ '//sup[contains(concat(" ", normalize-space(./@class),
" "), " reference ")]/a[1]' );
+
+ foreach ( $nodes as $node ) {
+ $fragment = $node->getAttribute( 'href' );
+ $node->setAttribute(
+ 'href',
+ SpecialPage::getTitleFor( 'MobileCite',
$citePath )->getLocalUrl() . $fragment
+ );
+ }
+ }
+
+ /**
+ * Replaces any references list with a link to Special:MobileCite
+ *
+ * @param DOMElement|DOMDocument $el Element or document to rewrite
references in.
+ * @param DOMDocument $doc Document to create elements in
+ */
+ private function doRewriteReferencesListsForLazyLoading( $el,
DOMDocument $doc ) {
+ $prefixedTitle = $this->title->getPrefixedText();
+ $citePath = "$this->revId";
+ $isReferenceSection = false;
+
// Accessing by tag is cheaper than class
- $nodes = $doc->getElementsByTagName( 'ol' );
+ $nodes = $el->getElementsByTagName( 'ol' );
// PHP's DOM classes are recursive
// but since we are manipulating the DOMList we have to
// traverse it backwards
@@ -193,6 +220,7 @@
// Use class to decide it is a list of references
if ( strpos( $list->getAttribute( 'class' ),
'references' ) !== false ) {
+ $isReferenceSection = true;
$parent = $list->parentNode;
$placeholder = $doc->createElement( 'a',
wfMessage(
'mobile-frontend-references-list' ) );
@@ -206,19 +234,9 @@
}
}
- // rewrite refs
- $xPath = new DOMXPath( $doc );
- $nodes = $xPath->query(
- // sup.reference > a
- '//sup[contains(concat(" ", normalize-space(./@class),
" "), " reference ")]/a[1]'
- );
-
- foreach ( $nodes as $node ) {
- $fragment = $node->getAttribute( 'href' );
- $node->setAttribute(
- 'href',
- SpecialPage::getTitleFor( 'MobileCite',
$citePath )->getLocalUrl() . $fragment
- );
+ // Mark section as having references
+ if ( $isReferenceSection ) {
+ $el->setAttribute( 'data-is-reference-section', '1' );
}
}
diff --git a/resources/mobile.toggle/toggle.js
b/resources/mobile.toggle/toggle.js
index 72f02af..d098e3f 100644
--- a/resources/mobile.toggle/toggle.js
+++ b/resources/mobile.toggle/toggle.js
@@ -128,7 +128,7 @@
* @ignore
*/
Toggler.prototype.toggle = function ( $heading ) {
- var indicator,
+ var indicator, $content,
wasExpanded = $heading.is( '.open-block' ),
page = $heading.data( 'page' ),
sectionId = $heading.data( 'section-number' );
@@ -143,7 +143,8 @@
indicator = new Icon( arrowOptions ).prependTo( $heading );
$heading.data( 'indicator', indicator );
- $heading.next()
+ $content = $heading.next();
+ $content
.toggleClass( 'open-block' )
.attr( {
'aria-pressed': !wasExpanded,
@@ -215,7 +216,7 @@
* @constructor
*/
Toggler.prototype._enable = function ( $container, prefix, page,
isClosed ) {
- var tagName, expandSections, indicator,
+ var tagName, expandSections, indicator, $content,
$firstHeading,
self = this,
collapseSectionsByDefault = mw.config.get(
'wgMFCollapseSectionsByDefault' );
@@ -233,12 +234,15 @@
( context.isBetaGroupMember() && settings.get(
'expandSections', true ) === 'true' );
$container.children( tagName ).each( function ( i ) {
- var $heading = $( this ),
+ var isReferenceSection,
+ $heading = $( this ),
$indicator = $heading.find( '.indicator' ),
id = prefix + 'collapsible-block-' + i;
// Be sure there is a div wrapping the section content.
// Otherwise, collapsible sections for this page is not
enabled.
if ( $heading.next().is( 'div' ) ) {
+ $content = $heading.next( 'div' );
+ isReferenceSection = Boolean( $content.attr(
'data-is-reference-section' ) );
$heading
.addClass( 'collapsible-heading ' )
.data( 'section-number', i )
@@ -265,7 +269,7 @@
indicator.prependTo( $heading );
}
$heading.data( 'indicator', indicator.$el );
- $heading.next( 'div' )
+ $content
.addClass( 'collapsible-block' )
.eq( 0 )
.attr( {
@@ -278,7 +282,7 @@
} );
enableKeyboardActions( self, $heading );
- if ( !isClosed && browser.isWideScreen() ||
expandSections ) {
+ if ( !isReferenceSection && ( !isClosed &&
browser.isWideScreen() || expandSections ) ) {
// Expand sections by default on wide
screen devices or if the expand sections setting is set
self.toggle.call( self, $heading );
}
diff --git a/tests/phpunit/MobileFormatterTest.php
b/tests/phpunit/MobileFormatterTest.php
index 986a643..d7735ec 100644
--- a/tests/phpunit/MobileFormatterTest.php
+++ b/tests/phpunit/MobileFormatterTest.php
@@ -65,6 +65,10 @@
],
wfMessage( 'mobile-frontend-references-list' )
);
+ $refSectionHtml = '<h2 class="section-heading">' .
self::SECTION_INDICATOR
+ . 'references</h2>'
+ . '<div class="mf-section-1"
data-is-reference-section="1">'
+ . $refplaceholder . '</div>';
return [
// # Lazy loading images
@@ -129,9 +133,7 @@
$refText
. '<h2>references</h2>' . $refhtml,
'<div class="mf-section-0">' . $expectedReftext
. '</div>'
- . '<h2 class="section-heading">' .
self::SECTION_INDICATOR
- . 'references</h2>'
- . '<div class="mf-section-1">' .
$refplaceholder . '</div>',
+ . $refSectionHtml,
$enableSections,
false, true, false
],
@@ -143,9 +145,7 @@
'<div class="mf-section-0">'
. '<p>T135923 <sup class="reference">
<a href="' . $citeUrl
.
'#cite-note-1">[1]</a></sup></p></div>'
- . '<h2 class="section-heading">' .
self::SECTION_INDICATOR
- . 'references</h2>'
- . '<div class="mf-section-1">' .
$refplaceholder . '</div>',
+ . $refSectionHtml,
$enableSections,
false, true, false
],
@@ -155,9 +155,7 @@
. '<h2>references</h2>' . $refhtml,
'<div class="mf-section-0">'
. '<p>T135923 <sup
class="reference"></sup></p></div>'
- . '<h2 class="section-heading">' .
self::SECTION_INDICATOR
- . 'references</h2>'
- . '<div class="mf-section-1">' .
$refplaceholder . '</div>',
+ . $refSectionHtml,
$enableSections,
false, true, false
],
diff --git a/tests/qunit/mobile.toggle/test_toggle.js
b/tests/qunit/mobile.toggle/test_toggle.js
index 65f321d..52caaa3 100644
--- a/tests/qunit/mobile.toggle/test_toggle.js
+++ b/tests/qunit/mobile.toggle/test_toggle.js
@@ -109,9 +109,11 @@
}
} );
- QUnit.test( 'Open by default', 1, function ( assert ) {
+ QUnit.test( 'Open by default', 2, function ( assert ) {
assert.strictEqual( this.$container.find( '.collapsible-block'
).eq( 1 ).hasClass( 'open-block' ),
true, 'check section is visible at start' );
+ assert.strictEqual( this.$container.find( '.collapsible-block'
).eq( 2 ).hasClass( 'open-block' ),
+ false, 'check reference section is hidden at start' );
} );
/**
diff --git a/tests/qunit/tests.mobilefrontend/section.hogan
b/tests/qunit/tests.mobilefrontend/section.hogan
index dd4192f..6a3a3e7 100644
--- a/tests/qunit/tests.mobilefrontend/section.hogan
+++ b/tests/qunit/tests.mobilefrontend/section.hogan
@@ -8,3 +8,13 @@
<a href="#foo">Dummy Link</a>
</h2>
<div></div>
+<h2>References</h2>
+<div data-is-reference-section="1">
+ <ol class="references">
+ <li id="cite_note-1">
+ <span class="mw-cite-backlink">
+ <a href="#cite_ref-1">↑</a>
+ </span> <span class="reference-text">hello</span>
+ </li>
+ </ol>
+</div>
\ No newline at end of file
--
To view, visit https://gerrit.wikimedia.org/r/289344
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I5ebe531a897524872a05ab44f6e82985cd9ecd2b
Gerrit-PatchSet: 8
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: Jhobs <[email protected]>
Gerrit-Reviewer: Phuedx <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits