Mollywhite has uploaded a new change for review.

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


Change subject: Bug 50674: Allow display of example navbars.
......................................................................

Bug 50674: Allow display of example navbars.

If a user sets $wgBookManagerv2ExampleNavigation to true,
a navigation bar using the example JSON file in
examples/book.json will be added to each mainspace page
that doesn't already have a BookManagerv2 navbar.

Bug: 50674
Change-Id: I6cf0ebc0b6b56e7c4af8a1eba12708af516fc404
---
M BookManagerv2.hooks.php
M BookManagerv2.php
2 files changed, 32 insertions(+), 2 deletions(-)


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

diff --git a/BookManagerv2.hooks.php b/BookManagerv2.hooks.php
index 1e495f2..3554c6e 100644
--- a/BookManagerv2.hooks.php
+++ b/BookManagerv2.hooks.php
@@ -308,7 +308,7 @@
                // Check that the navigation bar is only added to mainspace 
pages.
                if ( $out->getTitle()->getNamespace() === NS_MAIN ) {
                        if ( $out->getRevisionId() !== null ) {
-                               global $wgContLang;
+                               global $wgContLang, 
$wgBookManagerv2ExampleNavigation;
                                $categories = $out->getCategories();
                                $namespace = $wgContLang->convertNamespace( 
NS_BOOK ) . ":";
                                foreach ( $categories as $cat ) {
@@ -348,7 +348,6 @@
                                                        $chapterList = 
self::formatChapterList(
                                                                
$jsonBook->sections, $currentPageTitle );
                                                        $metadata = 
self::formatMetadata( $jsonBook );
-
                                                        $navbar = 
self::readingInterfaceUX( $prev, $next,
                                                                $chapterList, 
$metadata );
                                                        $out->prependHtml( 
$navbar );
@@ -356,6 +355,28 @@
                                                }
                                        }
                                }
+                               if ( $wgBookManagerv2ExampleNavigation ) {
+                                       //Add an example navigation bar to 
every page.
+                                       $out->addModuleStyles( 
"ext.BookManagerv2" );
+                                       $out->addModules( "ext.BookManagerv2js" 
);
+                                       $currentPageTitle = 
$out->getTitle()->getText();
+                                       $jsonBook = json_decode(
+                                               file_get_contents( __DIR__ . 
'/examples/book.json' ) );
+                                       $prev = null;
+                                       $next = (object) array();
+                                       $next->title = $jsonBook->sections[ 1 
]->name;
+                                       $next->link = $jsonBook->sections[ 
1]->link;
+                                       $chapterList = self::formatChapterList(
+                                               $jsonBook->sections, 
$currentPageTitle );
+                                       $metadata = self::formatMetadata( 
$jsonBook );
+                                       $navbar = self::readingInterfaceUX( 
$prev, $next,
+                                               $chapterList, $metadata );
+                                       $out->prependHtml( $navbar );
+                                       $out->setSubtitle( 'This navigation bar 
on this page is appearing because'
+                                               . ' 
$wgBookManagerv2ExampleNavigation is set to true in LocalSettings.php. Disable 
this to'
+                                               . ' prevent the example 
navigation bars from appearing.' );
+                                       return true;
+                               } 
                        }
                }
                return true;
diff --git a/BookManagerv2.php b/BookManagerv2.php
index f11cb9e..79276f8 100644
--- a/BookManagerv2.php
+++ b/BookManagerv2.php
@@ -132,3 +132,12 @@
 // Register hook and content handlers for the JSON schema content iff
 // running on the MediaWiki instance housing the schemas.
 $wgExtensionFunctions[] = 'JsonHooks::registerHandlers';
+
+// User configuration
+
+/**
+ * @var bool
+ * If enabled, this adds an example navigation bar to every mainspace
+ * page, drawing the information from examples/book.json
+ */
+$wgBookManagerv2ExampleNavigation = false;

-- 
To view, visit https://gerrit.wikimedia.org/r/74289
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6cf0ebc0b6b56e7c4af8a1eba12708af516fc404
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