Mollywhite has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/76463


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 includes/JsonHooks.php
M modules/ext.BookManagerv2.js
4 files changed, 106 insertions(+), 59 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/BookManagerv2 
refs/changes/63/76463/1

diff --git a/BookManagerv2.hooks.php b/BookManagerv2.hooks.php
index bed3c27..046b3f7 100644
--- a/BookManagerv2.hooks.php
+++ b/BookManagerv2.hooks.php
@@ -37,6 +37,11 @@
         * @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/";
 
@@ -44,32 +49,36 @@
                $html[] = Html::openElement( 'div', array( 'class' => 
'mw-bookmanagerv2-nav-wrap' ) );
                $html[] = Html::openElement( 'div', array( 'class' => 
'mw-bookmanagerv2-nav-constrain' ) );
                $html[] = Html::openElement( 'div', array( 'class' => 
'mw-bookmanagerv2-nav-bar' ) );
-               $html[] = Html::openElement( 'a', array(
-                               'class' => array(
-                                       'mw-bookmanagerv2-nav-icon',
-                                       'mw-bookmanagerv2-nav-data' )
-                               )
-                       );
-               $html[] = 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[] = Html::closeElement( 'a' );
-               $html[] = Html::openElement( 'a', array(
-                               'class' => array(
-                                       'mw-bookmanagerv2-nav-icon',
-                                       'mw-bookmanagerv2-nav-toc' )
-                               )
-                       );
-               $html[] = 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[] = Html::closeElement( 'a' );
+               if ( $metadata ) {
+                       $html[] = Html::openElement( 'a', array(
+                                       'class' => array(
+                                               'mw-bookmanagerv2-nav-icon',
+                                               'mw-bookmanagerv2-nav-data' )
+                                       )
+                               );
+                       $html[] = 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[] = Html::openElement( 'a', array(
+                                       'class' => array(
+                                               'mw-bookmanagerv2-nav-icon',
+                                               'mw-bookmanagerv2-nav-toc' )
+                                       )
+                               );
+                       $html[] = 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[] = Html::closeElement( 'a' );
+               }
                if ( $prev ) {
                        $html[] = Linker::link(
                                Title::newFromText( $prev->link ),
@@ -303,7 +312,8 @@
         */
        public static function onBeforePageDisplay( OutputPage &$out, Skin 
&$skin ) {
                // Check that the navigation bar is only added to mainspace 
pages.
-               global $wgContentNamespaces;
+               global $wgContentNamespaces, $wgBookManagerv2Metadata,
+                       $wgBookManagerv2ChapterList, $wgBookManagerv2PrevNext;
                if ( in_array( $out->getTitle()->getNamespace(), 
$wgContentNamespaces ) ) {
                        if ( $out->getRevisionId() !== null ) {
                                global $wgContLang, 
$wgBookManagerv2ExampleNavigation, $wgMemc;
@@ -344,41 +354,53 @@
                                }
 
                                // 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();
-                                                       $next->title =
-                                                               
$jsonBook->sections[ $key + 1 ]->name;
-                                                       $next->link =
-                                                               
$jsonBook->sections[ $key + 1 ]->link;
-                                               }
-                                               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 8f56bb9..66fb824 100644
--- a/BookManagerv2.php
+++ b/BookManagerv2.php
@@ -144,3 +144,21 @@
  * page, drawing the information from examples/book.json
  */
 $wgBookManagerv2ExampleNavigation = false;
+
+/**
+ * @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/includes/JsonHooks.php b/includes/JsonHooks.php
index 308016b..e9ad64b 100644
--- a/includes/JsonHooks.php
+++ b/includes/JsonHooks.php
@@ -86,10 +86,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;
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: newchange
Gerrit-Change-Id: I72e087be683493d8bdcf3afd5bb802e1566572e0
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/BookManagerv2
Gerrit-Branch: master
Gerrit-Owner: Mollywhite <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to