Bene has uploaded a new change for review. https://gerrit.wikimedia.org/r/90755
Change subject: (bug 44876) add a table of content to item pages ...................................................................... (bug 44876) add a table of content to item pages Change-Id: I5b86597571b6ba370bcfe5f480fe059c1fb67476 --- M lib/resources/templates.php M lib/resources/wikibase.css M repo/includes/EntityView.php M repo/includes/ItemView.php 4 files changed, 77 insertions(+), 4 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/55/90755/1 diff --git a/lib/resources/templates.php b/lib/resources/templates.php index 9eec58b..95e658a 100644 --- a/lib/resources/templates.php +++ b/lib/resources/templates.php @@ -25,7 +25,28 @@ // TODO: no point in inserting this here, is there? Should be generated in JS! <<<HTML <div id="wb-$1-$2" class="wb-entity wb-$1" lang="$3" dir="$4">$5</div> -<div id="wb-widget-container-$2" class="wb-widget-container"></div> +<div id="wb-widget-container-$2" class="wb-widget-container">$6</div> +HTML; + + + $templates['wb-entity-toc'] = +<<<HTML +<div id="toc" class="toc"> +<div id="toctitle"> +<h2>$1</h2> +</div> +<ul> +$2 +</ul> +</div> +HTML; + +// $1: Index of the section +// $2: Target of the link +// $3: Text of the link + $templates['wb-entity-toc-section'] = +<<<HTML +<li class="toclevel-1 tocsection-$1"><a href="#$2"><span class="tocnumber">$1</span> <span class="toctext">$3</span></a></li> HTML; diff --git a/lib/resources/wikibase.css b/lib/resources/wikibase.css index 16a6316..3cc80fb 100644 --- a/lib/resources/wikibase.css +++ b/lib/resources/wikibase.css @@ -96,7 +96,7 @@ } .wb-widget-container { - float: left; + float: right; } /* basically, a row in the grid layout */ diff --git a/repo/includes/EntityView.php b/repo/includes/EntityView.php index 04f5b3f..104ad7f 100644 --- a/repo/includes/EntityView.php +++ b/repo/includes/EntityView.php @@ -145,7 +145,8 @@ $entityId, $lang->getCode(), $lang->getDir(), - $this->getInnerHtml( $entityRevision, $lang, $editable ) + $this->getInnerHtml( $entityRevision, $lang, $editable ), + $this->getHtmlForToc() ); // show loading spinner as long as JavaScript is initialising; @@ -186,6 +187,43 @@ } /** + * Builds and returns the html for the toc. + * + * @return string + */ + protected function getHtmlForToc() { + $tocContent = ''; + $tocSections = $this->getTocSections(); + if( empty( $tocSections ) ) { + return ''; + } + $i = 1; + foreach( $tocSections as $id => $message ) { + $tocContent .= wfTemplate( 'wb-entity-toc-section', + $i++, + $id, + wfMessage( $message )->text() + ); + } + + $toc = wfTemplate( 'wb-entity-toc', + wfMessage( 'toc' )->text(), + $tocContent + ); + + return $toc; + } + + /** + * Returns the sections that should displayed in the toc. + * + * @return array( link target => system message key ) + */ + protected function getTocSections() { + return array(); + } + + /** * Builds and returns the inner HTML for representing a whole WikibaseEntity. The difference to getHtml() is that * this does not group all the HTMl within one parent node as one entity. * diff --git a/repo/includes/ItemView.php b/repo/includes/ItemView.php index e24d768..15226c7 100644 --- a/repo/includes/ItemView.php +++ b/repo/includes/ItemView.php @@ -34,6 +34,20 @@ } /** + * @see EntityView::getTocSections + */ + protected function getTocSections() { + $array = parent::getTocSections(); + $array['claims'] = 'wikibase-statements'; + $groups = WikibaseRepo::getDefaultInstance()->getSettings()->getSetting( 'siteLinkGroups' ); + foreach( $groups as $group ) { + $id = htmlspecialchars( 'sitelinks-' . $group, ENT_QUOTES ); + $array[$id] = 'wikibase-sitelinks-' . $group; + } + return $array; + } + + /** * Builds and returns the HTML representing a WikibaseEntity's site-links. * * @since 0.1 @@ -45,7 +59,7 @@ * @return string */ public function getHtmlForSiteLinks( Item $item, Language $lang, $editable = true ) { - $groups = WikibaseRepo::getDefaultInstance()->getSettings()->getSetting( "siteLinkGroups" ); + $groups = WikibaseRepo::getDefaultInstance()->getSettings()->getSetting( 'siteLinkGroups' ); $html = ''; foreach ( $groups as $group ) { -- To view, visit https://gerrit.wikimedia.org/r/90755 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I5b86597571b6ba370bcfe5f480fe059c1fb67476 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Bene <benestar.wikime...@googlemail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits