Mollywhite has submitted this change and it was merged.
Change subject: Bug 50762: Add variables to show/hide items in the navbar.
......................................................................
Bug 50762: Add variables to show/hide items in the navbar.
This allows people to hide the metadata, table of contents,
prev/next links, or some combination of these.
Change-Id: I72e087be683493d8bdcf3afd5bb802e1566572e0
---
M BookManagerv2.hooks.php
M BookManagerv2.php
M modules/ext.BookManagerv2.js
3 files changed, 103 insertions(+), 49 deletions(-)
Approvals:
Mollywhite: Verified; Looks good to me, approved
jenkins-bot: Checked
diff --git a/BookManagerv2.hooks.php b/BookManagerv2.hooks.php
index 55017f0..4407f73 100644
--- a/BookManagerv2.hooks.php
+++ b/BookManagerv2.hooks.php
@@ -52,10 +52,10 @@
}
if ( $blockIsValid ) {
- //Add to cache
+ // Add to cache
$cacheKey = wfMemcKey( 'BookManagerv2',
$pageTitle->getArticleID(), 'json' );
$wgMemc->set( $cacheKey,
- FormatJson::decode( $content->getNativeData(),
false ));
+ FormatJson::decode( $content->getNativeData(),
false ) );
}
return true;
@@ -73,38 +73,47 @@
* @return string HTML string
*/
public static function readingInterfaceUX( $prev, $next, $chapterList,
$metadata ) {
+ if ( $prev === null && $next === null && $chapterList === null
+ && $metadata === null ) {
+ return '';
+ }
+
global $wgExtensionAssetsPath;
$imagePath = $wgExtensionAssetsPath . "/BookManagerv2/images/";
$html = Html::openElement( 'div', array( 'class' =>
'mw-bookmanagerv2-nav-wrap' ) )
. Html::openElement( 'div', array( 'class' =>
'mw-bookmanagerv2-nav-constrain' ) )
- . Html::openElement( 'div', array( 'class' =>
'mw-bookmanagerv2-nav-bar' ) )
- . Html::openElement( 'a', array(
- 'class' => array(
- 'mw-bookmanagerv2-nav-icon',
- 'mw-bookmanagerv2-nav-data' )
+ . Html::openElement( 'div', array( 'class' =>
'mw-bookmanagerv2-nav-bar' ) );
+ if ( $metadata ) {
+ $html .= Html::openElement( 'a', array(
+ 'class' => array(
+ 'mw-bookmanagerv2-nav-icon',
+ 'mw-bookmanagerv2-nav-data' )
+ )
)
- )
- . Html::element( 'img', array(
- 'class' => 'mw-bookmanagerv2-nav-data',
- 'src' => $imagePath .
'Info_sign_font_awesome.png',
- 'alt' => wfMessage( 'bookmanagerv2-metadata'
)->text(),
- 'title' => wfMessage( 'bookmanagerv2-metadata'
)->text()
- ), '' )
- . Html::closeElement( 'a' )
- . Html::openElement( 'a', array(
- 'class' => array(
- 'mw-bookmanagerv2-nav-icon',
- 'mw-bookmanagerv2-nav-toc' )
+ . Html::element( 'img', array(
+ 'class' => 'mw-bookmanagerv2-nav-data',
+ 'src' => $imagePath .
'Info_sign_font_awesome.png',
+ 'alt' => wfMessage(
'bookmanagerv2-metadata' )->text(),
+ 'title' => wfMessage(
'bookmanagerv2-metadata' )->text()
+ ), '' );
+ }
+ if ( $chapterList ) {
+ $html .= Html::closeElement( 'a' )
+ . Html::openElement( 'a', array(
+ 'class' => array(
+ 'mw-bookmanagerv2-nav-icon',
+ 'mw-bookmanagerv2-nav-toc' )
+ )
)
- )
- . Html::element( 'img', array(
- 'class' => 'mw-bookmanagerv2-nav-toc',
- 'src' => $imagePath . 'Ul_font_awesome.png',
- 'alt' => wfMessage( 'bookmanagerv2-contents'
)->text(),
- 'title' => wfMessage( 'bookmanagerv2-contents'
)->text()
- ), '' )
- . Html::closeElement( 'a' );
+ . Html::element( 'img', array(
+ 'class' => 'mw-bookmanagerv2-nav-toc',
+ 'src' => $imagePath .
'Ul_font_awesome.png',
+ 'alt' => wfMessage(
'bookmanagerv2-contents' )->text(),
+ 'title' => wfMessage(
'bookmanagerv2-contents' )->text()
+ ), '' )
+ . Html::closeElement( 'a' );
+ }
if ( $prev ) {
$html .= Linker::link(
Title::newFromText( $prev->link ),
@@ -383,16 +392,26 @@
}
// Get the previous/next pages
- $currentPageNumber = null;
- foreach ( $jsonBook->sections as $key => $val )
{
- if ( $val->link === $currentPageTitle )
{
- $currentPageNumber = $key;
- if ( $key !== 0 ) {
- $prev = (object)
array();
- $prev->title =
-
$jsonBook->sections[ $key - 1 ]->name;
- $prev->link =
-
$jsonBook->sections[ $key - 1 ]->link;
+ if ( $wgBookManagerv2PrevNext ) {
+ $currentPageNumber = null;
+ foreach ( $jsonBook->sections as $key
=> $val ) {
+ if ( $val->link ===
$currentPageTitle ) {
+ $currentPageNumber =
$key;
+ if ( $key !== 0 ) {
+ $prev =
(object) array();
+ $prev->title =
+
$jsonBook->sections[ $key - 1 ]->name;
+ $prev->link =
+
$jsonBook->sections[ $key - 1 ]->link;
+ }
+ if ( $key !== ( count(
$jsonBook->sections ) - 1 ) ) {
+ $next =
(object) array();
+ $next->title =
+
$jsonBook->sections[ $key + 1 ]->name;
+ $next->link =
+
$jsonBook->sections[ $key + 1 ]->link;
+ }
+ break;
}
if ( $key !== ( count(
$jsonBook->sections ) - 1 ) ) {
$next = (object)
array();
@@ -403,21 +422,31 @@
}
break;
}
+
+ if ( $currentPageNumber === null
+ && count( $jsonBook->sections )
> 0
+ ) {
+ $next = (object) array();
+ $next->title =
+ $jsonBook->sections[ 0
]->name;
+ $next->link =
+ $jsonBook->sections[ 0
]->link;
+ }
+ } else {
+ $prev = $next = null;
}
- if ( $currentPageNumber === null
- && count( $jsonBook->sections ) > 0
- ) {
- $next = (object) array();
- $next->title =
- $jsonBook->sections[ 0 ]->name;
- $next->link =
- $jsonBook->sections[ 0 ]->link;
+ if ( $wgBookManagerv2ChapterList ) {
+ $chapterList = self::formatChapterList(
$jsonBook->sections,
+ $currentPageTitle );
+ } else {
+ $chapterList = null;
}
-
- $chapterList = self::formatChapterList(
$jsonBook->sections,
- $currentPageTitle );
- $metadata = self::formatMetadata( $jsonBook );
+ if ( $wgBookManagerv2Metadata ) {
+ $metadata = self::formatMetadata(
$jsonBook );
+ } else {
+ $metadata = null;
+ }
$navbar = self::readingInterfaceUX( $prev,
$next, $chapterList,
$metadata );
$out->prependHtml( $navbar );
diff --git a/BookManagerv2.php b/BookManagerv2.php
index 1fc728c..dd4a5ea 100644
--- a/BookManagerv2.php
+++ b/BookManagerv2.php
@@ -162,3 +162,21 @@
* namespaces in this array.
*/
$wgBookManagerv2NavigationNamespaces = null;
+
+/**
+ * @var bool
+ * If set to false, this hides the metadata from the navigation bar.
+ */
+$wgBookManagerv2Metadata = true;
+
+/**
+ * @var bool
+ * If set to false, this hides the chapter list from the navigation bar.
+ */
+$wgBookManagerv2ChapterList = true;
+
+/**
+ * @var bool
+ * If set to false, this hides the previous/next links from the navigation bar.
+ */
+$wgBookManagerv2PrevNext = true;
diff --git a/modules/ext.BookManagerv2.js b/modules/ext.BookManagerv2.js
index aca32d8..54b9ca0 100644
--- a/modules/ext.BookManagerv2.js
+++ b/modules/ext.BookManagerv2.js
@@ -18,6 +18,13 @@
(function ( $ ) {
+ // If the metadata dropdown doesn't exist and the table of
+ // contents one does, shift the TOC one left
+ if ( $( 'a.mw-bookmanagerv2-nav-data' ).length === 0
+ && $( 'a.mw-bookmanagerv2-nav-toc' ).length !== 0 ) {
+ $( 'div.mw-bookmanagerv2-nav-toc' ).css( 'margin-left', '0px' );
+ }
+
// When the metadata icon is clicked, hide the table
// of contents dropdown and toggle the metadata one
$( 'a.mw-bookmanagerv2-nav-data' ).click( function () {
--
To view, visit https://gerrit.wikimedia.org/r/76463
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I72e087be683493d8bdcf3afd5bb802e1566572e0
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/BookManagerv2
Gerrit-Branch: master
Gerrit-Owner: Mollywhite <[email protected]>
Gerrit-Reviewer: Mollywhite <[email protected]>
Gerrit-Reviewer: Mwalker <[email protected]>
Gerrit-Reviewer: Raylton P. Sousa <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits