Florianschmidtwelzow has uploaded a new change for review.
https://gerrit.wikimedia.org/r/141047
Change subject: Don't show toc if __NOTOC__ set
......................................................................
Don't show toc if __NOTOC__ set
If magic word __NOTOC__ is set in wikitext, don't show TOC on page,
like the behavior is on desktop.
Bug: 66861
Change-Id: I614d192afff6400a971f52cb90fa77923ccc1227
---
M includes/api/ApiMobileView.php
M includes/skins/SkinMinerva.php
M javascripts/common/Page.js
M javascripts/common/PageApi.js
M javascripts/modules/toc/toc.js
M tests/phpunit/api/ApiMobileViewTest.php
M tests/qunit/common/test_PageApi.js
7 files changed, 80 insertions(+), 1 deletion(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend
refs/changes/47/141047/1
diff --git a/includes/api/ApiMobileView.php b/includes/api/ApiMobileView.php
index 756f525..a60e91f 100644
--- a/includes/api/ApiMobileView.php
+++ b/includes/api/ApiMobileView.php
@@ -21,6 +21,8 @@
private $mainPage;
/** @var boolean Saves whether the output is formatted or not */
private $noTransform;
+ /** @var boolean Saves if __NOTOC__ magic word set from Parser (for
tablet mode) */
+ private $showTOC;
/** @var boolean Saves whether page images should be added or not */
private $usePageImages;
/** @var string Saves in which language the content should be output */
@@ -154,6 +156,11 @@
} else {
$requestedSections = array();
}
+ if ( $this->isTOCEnabled( $title, $this->getUser() ) ) {
+ $this->getResult()->addValue( null,
$this->getModuleName(),
+ array( 'showtoc' => '' )
+ );
+ }
if ( isset( $data['sections'] ) ) {
if ( isset( $prop['sections'] ) ) {
$sectionCount = count( $data['sections'] );
@@ -274,6 +281,30 @@
}
/**
+ * Check in original, not mobile view data, if TOC is disabled (e.g.
with __NOTOC__)
+ * using Parser.
+ * @param Title $title The Title object of page to check
+ * @param User $user The User object to use in Parser
+ */
+ protected function isTOCEnabled( $title, $user ) {
+ if ( $title->isContentPage() ) {
+ $wp = WikiPage::factory( $title );
+ $parserOptions = $wp->makeParserOptions( $user );
+ $content = $wp->getContent();
+ if ( $content ) {
+ $Parser = new Parser;
+ $Parser->parse( $content->getNativeData(),
$title, $parserOptions );
+ if ( isset(
$Parser->mDoubleUnderscores['notoc'] ) ) {
+ if (
!$Parser->mDoubleUnderscores['notoc'] ) {
+ return false;
+ }
+ }
+ }
+ }
+ return true;
+ }
+
+ /**
* Splits a string (using $offset and $maxlen)
* @param string $text The text to split
* @return string
diff --git a/includes/skins/SkinMinerva.php b/includes/skins/SkinMinerva.php
index 4b7622e..e8d07b8 100644
--- a/includes/skins/SkinMinerva.php
+++ b/includes/skins/SkinMinerva.php
@@ -11,6 +11,8 @@
class SkinMinerva extends SkinTemplate {
/** @var boolean $isMobileMode Describes whether reader is on a mobile
device */
protected $isMobileMode = false;
+ /** @var boolean $isTOCEnabled Whether the TOC display or not */
+ protected $isTOCEnabled = true;
/** @var string $skinname Name of this skin */
public $skinname = 'minerva';
/** @var string $template Name of this used template */
@@ -120,6 +122,27 @@
} else {
return false;
}
+ }
+
+ /**
+ * Check in original, not mobile view data, if TOC is disabled (e.g.
with __NOTOC__)
+ * using Parser.
+ * @param Title $title The Title object of page to check
+ * @param User $user The User object to use in Parser
+ */
+ protected function isTOCEnabled( $title, $user ) {
+ if ( $title->isContentPage() ) {
+ $wp = WikiPage::factory( $title );
+ $parserOptions = $wp->makeParserOptions( $user );
+ $Parser = new Parser;
+ $Parser->parse( $wp->getContent()->getNativeData(),
$title, $parserOptions );
+ if ( isset( $Parser->mDoubleUnderscores['notoc'] ) ) {
+ if ( !$Parser->mDoubleUnderscores['notoc'] ) {
+ return true;
+ }
+ }
+ }
+ return false;
}
/**
@@ -770,6 +793,8 @@
if ( $this->isAuthenticatedUser() ) {
$vars['wgMFIsLoggedInUserBlocked'] = $user->isBlocked()
&& $user->isBlockedFrom( $title );
}
+ // check if TOC is disabled
+ $vars['wgMFdisableTOC'] = $this->isTOCEnabled( $title, $user );
// mobile specific config variables
if ( $this->mobileContext->shouldDisplayMobileView() ) {
$vars['wgImagesDisabled'] =
$this->mobileContext->imagesDisabled();
diff --git a/javascripts/common/Page.js b/javascripts/common/Page.js
index dd3bf6a..b45dc63 100644
--- a/javascripts/common/Page.js
+++ b/javascripts/common/Page.js
@@ -27,6 +27,7 @@
},
inBetaOrAlpha: M.isBetaGroupMember(),
isMainPage: false,
+ showTOC: true,
talkLabel: mw.msg(
'mobile-frontend-talk-overlay-header' ),
editLabel: mw.msg( 'mobile-frontend-editor-edit' ),
languageLabel: mw.msg(
'mobile-frontend-language-article-heading' )
@@ -59,6 +60,14 @@
},
/**
+ * @method
+ * @return {Boolean}
+ */
+ showTOC: function() {
+ return this.options.showTOC;
+ },
+
+ /**
* Checks whether the given user can edit the page.
* @method
* @param {mw.user} Object representing a user
diff --git a/javascripts/common/PageApi.js b/javascripts/common/PageApi.js
index 3eafed9..3a8430c 100644
--- a/javascripts/common/PageApi.js
+++ b/javascripts/common/PageApi.js
@@ -112,6 +112,7 @@
lead: sections[0].text,
sections:
sections.slice( 1 ),
isMainPage:
mv.hasOwnProperty( 'mainpage' ) ? true : false,
+ showTOC:
mv.hasOwnProperty( 'showtoc' ) ? true : false,
historyUrl:
mw.util.getUrl( title, { action: 'history' } ),
lastModifiedTimestamp:
timestamp,
languageCount:
mv.languagecount,
diff --git a/javascripts/modules/toc/toc.js b/javascripts/modules/toc/toc.js
index 81b1a23..3e6cc0f 100644
--- a/javascripts/modules/toc/toc.js
+++ b/javascripts/modules/toc/toc.js
@@ -29,13 +29,18 @@
function init( page ) {
var toc, sections = page.getSubSections();
- if ( sections.length > 0 && !page.isMainPage() ) {
+ if ( sections.length > 0 && !page.isMainPage() &&
page.showTOC() && !mw.config.get( 'wgMFdisableTOC' ) ) {
toc = new TableOfContents( {
sections: sections
} );
toc.appendTo( M.getLeadSection() );
toggle.enable( toc.$el );
}
+ // workaround for lazyload: set wgMFdisableTOC to 0 after load
to ensure, that page.showTOC() is the only
+ // condition to control if toc is enabled or not on ajax load
of page
+ if ( mw.config.get( 'wgMFdisableTOC' ) ) {
+ mw.config.set( 'wgMFdisableTOC', false );
+ }
}
init( M.getCurrentPage() );
diff --git a/tests/phpunit/api/ApiMobileViewTest.php
b/tests/phpunit/api/ApiMobileViewTest.php
index 8cc9480..1b80650 100644
--- a/tests/phpunit/api/ApiMobileViewTest.php
+++ b/tests/phpunit/api/ApiMobileViewTest.php
@@ -159,6 +159,7 @@
'*' => '<p>Text 2</p>'
),
),
+ 'showtoc' => '',
);
return array(
@@ -179,6 +180,7 @@
'*' => '<p>Text 2</p>'
),
),
+ 'showtoc' => '',
),
),
array(
@@ -187,6 +189,7 @@
'sections' => array(
$baseOut['sections'][1],
),
+ 'showtoc' => '',
),
),
array(
@@ -198,6 +201,7 @@
array(
'mainpage' => '',
'sections' => array(),
+ 'showtoc' => '',
),
),
array(
@@ -208,6 +212,7 @@
array(
'redirected' => 'Special:BlankPage',
'viewable' => 'no',
+ 'showtoc' => '',
),
),
array(
@@ -218,6 +223,7 @@
array(
'sections' => array(),
'pageprops' => array( 'notoc' => '' ),
+ 'showtoc' => '',
),
),
);
diff --git a/tests/qunit/common/test_PageApi.js
b/tests/qunit/common/test_PageApi.js
index efb66e3..5931df2 100644
--- a/tests/qunit/common/test_PageApi.js
+++ b/tests/qunit/common/test_PageApi.js
@@ -43,6 +43,7 @@
edit: [ '*' ]
},
isMainPage: false,
+ showTOC: false,
languageCount: 10,
hasVariants: false,
lead: '',
@@ -138,6 +139,7 @@
displayTitle: 'Test',
id: -1,
isMainPage: false,
+ showTOC: false,
revId: 42,
languageCount: 10,
hasVariants: false,
--
To view, visit https://gerrit.wikimedia.org/r/141047
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I614d192afff6400a971f52cb90fa77923ccc1227
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Florianschmidtwelzow <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits