jenkins-bot has submitted this change and it was merged.
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.i18n.php
M BookManagerv2.php
3 files changed, 74 insertions(+), 42 deletions(-)
Approvals:
Mwalker: Looks good to me, approved
jenkins-bot: Verified
diff --git a/BookManagerv2.hooks.php b/BookManagerv2.hooks.php
index 1e495f2..5fe15af 100644
--- a/BookManagerv2.hooks.php
+++ b/BookManagerv2.hooks.php
@@ -308,54 +308,75 @@
// 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 ) . ":";
+ $out->addModuleStyles( "ext.BookManagerv2" );
+ $out->addModules( "ext.BookManagerv2js" );
+ $currentPageTitle = $out->getTitle()->getText();
+ $prev = $next = $jsonBook = null;
foreach ( $categories as $cat ) {
if ( substr( $cat, 0, strlen(
$namespace ) ) === $namespace ) {
$jsonPageTitle =
Title::newFromText( $cat );
- $jsonBook = self::getJson(
$jsonPageTitle );
- if ( $jsonBook ) {
- $out->addModuleStyles(
"ext.BookManagerv2" );
- $out->addModules(
"ext.BookManagerv2js" );
- $currentPageTitle =
$out->getTitle()->getText();
- $prev = (object)
array();
- $next = (object)
array();
-
- // Get the
previous/next pages
- foreach (
$jsonBook->sections as $key => $val ) {
- if ( $val->link
=== $currentPageTitle ) {
- if (
$key !== 0 ) {
-
$prev->title =
-
$jsonBook->sections[ $key - 1 ]->name;
-
$prev->link =
-
$jsonBook->sections[ $key - 1 ]->link;
- } else {
-
$prev = null;
- }
- if (
$key !== count( $jsonBook->sections ) ) {
-
$next->title =
-
$jsonBook->sections[ $key + 1 ]->name;
-
$next->link =
-
$jsonBook->sections[ $key + 1 ]->link;
- } else {
-
$next = null;
- }
- break;
- }
- }
-
- $chapterList =
self::formatChapterList(
-
$jsonBook->sections, $currentPageTitle );
- $metadata =
self::formatMetadata( $jsonBook );
-
- $navbar =
self::readingInterfaceUX( $prev, $next,
- $chapterList,
$metadata );
- $out->prependHtml(
$navbar );
- return true;
+ if ( $jsonPageTitle->exists() )
{
+ $jsonBook =
self::getJson( $jsonPageTitle );
+ break;
}
}
}
+
+ if ( !$jsonBook &&
$wgBookManagerv2ExampleNavigation ) {
+ $jsonBook = json_decode(
+ file_get_contents( __DIR__ .
'/examples/book.json' ) );
+ $out->setSubtitle(
+ wfMessage(
'bookmanagerv2-example-nav' )->text() );
+ }
+
+ if ( !$jsonBook ) {
+ // No Category:Book on this page, and
the example
+ // navigation is disabled
+ return true;
+ }
+
+ // 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 ( $key !== count(
$jsonBook->sections ) ) {
+ $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;
+ }
+
+ $chapterList = self::formatChapterList(
$jsonBook->sections,
+ $currentPageTitle );
+ $metadata = self::formatMetadata( $jsonBook );
+ $navbar = self::readingInterfaceUX( $prev,
$next, $chapterList,
+ $metadata );
+ $out->prependHtml( $navbar );
}
}
return true;
diff --git a/BookManagerv2.i18n.php b/BookManagerv2.i18n.php
index 629ba18..fb6845a 100644
--- a/BookManagerv2.i18n.php
+++ b/BookManagerv2.i18n.php
@@ -15,6 +15,7 @@
$messages['en'] = array(
'bookmanagerv2-desc' => 'Adds functionality to enter and store book
metadata and structure',
'bookmanagerv2-invalid-json' => 'Invalid JSON',
+ 'bookmanagerv2-example-nav' => 'The navigation bar on this page is
appearing because $wgBookManagerv2ExampleNavigation is set to true in
LocalSettings.php.',
'bookmanagerv2-title' => 'Title: $1',
'bookmanagerv2-alternate-titles' => '{{PLURAL:$1|Alternate
title|Alternate titles}}: $2',
'bookmanagerv2-authors' => '{{PLURAL:$1|Author|Authors}}: $2',
@@ -46,7 +47,8 @@
$messages['qqq'] = array(
'bookmanagerv2-desc' =>
'{{desc|name=BookManagerv2|url=http://www.mediawiki.org/wiki/Extension:BookManagerv2}}',
'bookmanagerv2-invalid-json' => 'Error message shown when an editor
tries to save an invalid JSON block.
-{{Identical|Invalid JSON}}',
+ {{Identical|Invalid JSON}}',
+ 'bookmanagerv2-example-nav' => 'Message shown in the subtitle to
explain why example navigation bars are appearing. The navigation bars appear
on every page when $wgBookManagerv2ExampleNavigation is set to true; if it\'s
disabled in LocalSettings.php, they will disappear.',
'bookmanagerv2-title' => 'Label in the navigation bar metadata
dropdown. See screenshot for an example of this dropdown.
[[File:BookManagerv2 navigation bar metadata dropdown.png]]
{{Identical|Title}}',
diff --git a/BookManagerv2.php b/BookManagerv2.php
index f11cb9e..d212138 100644
--- a/BookManagerv2.php
+++ b/BookManagerv2.php
@@ -125,10 +125,19 @@
$wgResourceModules['ext.BookManagerv2js'] = array(
'scripts' => 'ext.BookManagerv2.js',
'styles' => 'ext.BookManagerv2js.css',
- 'localBasePath' => dirname(__FILE__) . '/modules',
+ 'localBasePath' => dirname( __FILE__ ) . '/modules',
'remoteExtPath' => 'BookManagerv2/modules'
);
// 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: merged
Gerrit-Change-Id: I6cf0ebc0b6b56e7c4af8a1eba12708af516fc404
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/BookManagerv2
Gerrit-Branch: master
Gerrit-Owner: Mollywhite <[email protected]>
Gerrit-Reviewer: Mwalker <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits