jenkins-bot has submitted this change and it was merged.
Change subject: Bug 50989: Add view frontend to the JSON page.
......................................................................
Bug 50989: Add view frontend to the JSON page.
Instead of showing the raw JSON block when viewing the page
containing the JSON, format the metadata and contents into
sections and display them in a list. This is disabled by
default, but can be enabled by adding
$wgBookManagerv2JsonFrontend = true;
to LocalSettings.
Bug: 50989
Change-Id: Ic30a8012e21be61b1245cc4c1fe08aa77a826e5d
---
M BookManagerv2.hooks.php
M BookManagerv2.i18n.php
M BookManagerv2.php
M modules/ext.BookManagerv2.css
4 files changed, 73 insertions(+), 13 deletions(-)
Approvals:
Mollywhite: Verified; Looks good to me, approved
jenkins-bot: Verified
diff --git a/BookManagerv2.hooks.php b/BookManagerv2.hooks.php
index ee077a0..d38c12d 100644
--- a/BookManagerv2.hooks.php
+++ b/BookManagerv2.hooks.php
@@ -258,7 +258,7 @@
* @param string $currentPageTitle Title of the page that's being viewed
* @return string HTML ordered list element
*/
- public static function formatChapterList( $sections, $currentPageTitle
) {
+ public static function formatChapterList( $sections, $currentPageTitle
= null ) {
$html = Html::openElement( 'ol', array() );
foreach ( $sections as $key => $val ) {
if ( $val->link !== $currentPageTitle ) {
@@ -371,7 +371,7 @@
public static function onBeforePageDisplay( OutputPage &$out, Skin
&$skin ) {
global $wgContentNamespaces,
$wgBookManagerv2NavigationNamespaces,
$wgBookManagerv2Metadata, $wgBookManagerv2ChapterList,
- $wgBookManagerv2PrevNext;
+ $wgBookManagerv2PrevNext, $wgBookManagerv2JsonFrontend;
// Navbars will be added to namespaces in the
// $wgBookManagerv2NavigationNamespaces array if it's set,
otherwise
@@ -384,7 +384,7 @@
if ( $out->getTitle()->inNamespaces( $navigationNamespaces ) ) {
if ( $out->getRevisionId() !== null ) {
- global $wgContLang,
$wgBookManagerv2ExampleNavigation, $wgMemc;
+ global $wgContLang,
$wgBookManagerv2ExampleNavigation, $wgMemc;
$categories = $out->getCategories();
$namespace = $wgContLang->convertNamespace(
NS_BOOK ) . ":";
$out->addModuleStyles( "ext.BookManagerv2" );
@@ -425,8 +425,10 @@
if ( $wgBookManagerv2PrevNext ) {
$currentPageNumber = null;
foreach ( $jsonBook->sections as $key
=> $val ) {
+ // Find the entry that
corresponds to this page
if ( $val->link ===
$currentPageTitle ) {
$currentPageNumber =
$key;
+ // If this isn't the
first section, set previous link
if ( $key !== 0 ) {
$prev =
(object) array();
$prev->title =
@@ -434,6 +436,7 @@
$prev->link =
$jsonBook->sections[ $key - 1 ]->link;
}
+ // If this isn't the
last section, set the next link
if ( $key !== ( count(
$jsonBook->sections ) - 1 ) ) {
$next =
(object) array();
$next->title =
@@ -443,16 +446,10 @@
}
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;
}
+ // Couldn't find this page in the
section list; set the "next" link
+ // to the first section
if ( $currentPageNumber === null
&& count( $jsonBook->sections )
> 0
) {
@@ -481,6 +478,45 @@
$metadata );
$out->prependHtml( $navbar );
}
+ } else if ( $out->getTitle()->inNamespace( NS_BOOK ) &&
$wgBookManagerv2JsonFrontend ) {
+ self::formatJsonView( $out, $skin );
+ }
+ return true;
+ }
+
+ /**
+ * Formats the JSON page so that the metadata and chapter list are
nicely
+ * readable.
+ *
+ * @param OutputPage &$out OutputPage object
+ * @param Skin &$skin Skin object
+ * @return true
+ **/
+ public static function formatJsonView( OutputPage &$out, Skin &$skin ) {
+ if ( $out->getRevisionId() !== null ) {
+ $currentPageTitle = $out->getTitle();
+ $json = json_decode( $out->getWikiPage()->getText(
Revision::FOR_PUBLIC ) );
+ if ( $json ) {
+ $out->addModuleStyles( "ext.BookManagerv2" );
+ $out->clearHTML();
+ $metadata = Html::openElement( 'div',
+ array( 'class' =>
'mw-bookmanagerv2-json-data' ) )
+ . self::formatMetadata( $json )
+ . Html::closeElement( 'div' );
+ $chapterList = Html::openElement( 'div',
+ array( 'class' =>
'mw-bookmanagerv2-json-contents' ) )
+ . self::formatChapterList( $json->sections )
+ . Html::closeElement( 'div' );
+
+ $out->addWikiText( "==" .
+ wfMessage(
'bookmanagerv2-metadata-header' )->text()
+ . "==" );
+ $out->addHTML( $metadata );
+ $out->addWikiText( "==" .
+ wfMessage(
'bookmanagerv2-contents-header' )->text()
+ . "==" );
+ $out->addHTML( $chapterList );
+ }
}
return true;
}
diff --git a/BookManagerv2.i18n.php b/BookManagerv2.i18n.php
index b13aab8..ee62750 100644
--- a/BookManagerv2.i18n.php
+++ b/BookManagerv2.i18n.php
@@ -17,7 +17,9 @@
'bookmanagerv2-invalid-json' => 'Invalid JSON',
'bookmanagerv2-example-nav' => 'The navigation bar on this page is
appearing because <code>$wgBookManagerv2ExampleNavigation</code> is set to
<code>true</code> in <code>LocalSettings.php</code>.',
'bookmanagerv2-metadata' => 'Metadata of work',
+ 'bookmanagerv2-metadata-header' => 'Metadata',
'bookmanagerv2-contents' => 'Contents of work',
+ 'bookmanagerv2-contents-header' => 'Contents',
'bookmanagerv2-title' => 'Title: $1',
'bookmanagerv2-alternate-titles' => 'Alternate
{{PLURAL:$1|title|titles}}: $2',
'bookmanagerv2-authors' => '{{PLURAL:$1|Author|Authors}}: $2',
@@ -53,7 +55,9 @@
{{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 <code>$wgBookManagerv2ExampleNavigation</code> is set to
<code>true</code>; if it\'s disabled in <code>LocalSettings.php</code>, they
will disappear.',
'bookmanagerv2-metadata' => "Alternate text for the navigation bar's
metadata icon.",
+ 'bookmanagerv2-metadata-header' => 'Name of the section header for the
section holding the metadata. This is shown when viewing the JSON block.',
'bookmanagerv2-contents' => "Alternate text for the navigation bar's
table of contents icon.",
+ 'bookmanagerv2-contents-header' => 'Name of the section header for the
section holding the table of contents. This is shown when viewing the JSON
block.',
'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 dd4a5ea..57a1b90 100644
--- a/BookManagerv2.php
+++ b/BookManagerv2.php
@@ -127,7 +127,7 @@
$namespaces[NS_BOOK] = 'Book';
$namespaces[NS_BOOK_TALK] = 'Book_talk';
return true;
-};
+} ;
// Register hooks
$wgHooks['BeforePageDisplay'][] = 'BookManagerv2Hooks::onBeforePageDisplay';
@@ -180,3 +180,9 @@
* If set to false, this hides the previous/next links from the navigation bar.
*/
$wgBookManagerv2PrevNext = true;
+
+/**
+ * @var bool
+ * If set to true, a view frontend overrides the raw JSON.
+ */
+$wgBookManagerv2JsonFrontend = false;
diff --git a/modules/ext.BookManagerv2.css b/modules/ext.BookManagerv2.css
index 049aa0f..278267e 100644
--- a/modules/ext.BookManagerv2.css
+++ b/modules/ext.BookManagerv2.css
@@ -20,10 +20,12 @@
width: 100%;
text-align: center;
}
+
div.mw-bookmanagerv2-nav-constrain {
display:inline-block;
position: relative;
}
+
div.mw-bookmanagerv2-nav-bar {
display: inline-block;
background-color: #f5f5f5;
@@ -31,26 +33,38 @@
border-radius: 5px;
padding: 3px 5px;
}
-a.mw-bookmanagerv2-nav-icon, a.mw-bookmanagerv2-nav-icon img {
+
+a.mw-bookmanagerv2-nav-icon,
+a.mw-bookmanagerv2-nav-icon img {
display: inline;
cursor: pointer;
}
+
a.mw-bookmanagerv2-nav-icon {
float: left;
margin: 0 10px;
}
+
a.mw-bookmanagerv2-nav-prev {
float: left;
margin-right: 10px;
background: transparent url('../images/Angle_left_font_awesome.png')
no-repeat left center;
padding-left: 25px;
}
+
a.mw-bookmanagerv2-nav-next {
float: right;
margin-left: 10px;
background: transparent url('../images/Angle_right_font_awesome.png')
no-repeat right center;
padding-right: 25px;
}
+
div.mw-bookmanagerv2-nav-dropdown {
display: none;
}
+
+div.mw-bookmanagerv2-json-data ul,
+div.mw-bookmanagerv2-json-contents ol {
+ list-style: none;
+ margin: 0;
+}
--
To view, visit https://gerrit.wikimedia.org/r/76883
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ic30a8012e21be61b1245cc4c1fe08aa77a826e5d
Gerrit-PatchSet: 5
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: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits