Thiemo Mättig (WMDE) has uploaded a new change for review. https://gerrit.wikimedia.org/r/155737
Change subject: Refactor duplicate code in EntityView and related ...................................................................... Refactor duplicate code in EntityView and related Change-Id: I9d181433b16c2e38ca59459aae249dd1e472b9d7 --- M repo/includes/EntityView.php M repo/includes/ItemView.php M repo/includes/PropertyView.php 3 files changed, 23 insertions(+), 51 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/37/155737/1 diff --git a/repo/includes/EntityView.php b/repo/includes/EntityView.php index 96b3468..05f0833 100644 --- a/repo/includes/EntityView.php +++ b/repo/includes/EntityView.php @@ -80,7 +80,7 @@ * * @since 0.2 * - * @var array + * @var string[] */ public static $typeMap = array( Item::ENTITY_TYPE => '\Wikibase\ItemView', @@ -166,7 +166,7 @@ * Returns the placeholder map build while generating HTML. * The map returned here may be used with TextInjector. * - * @return array string -> array + * @return array[] string -> array */ public function getPlaceholders() { return $this->textInjector->getMarkers(); @@ -237,10 +237,10 @@ * 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. * - * @string - * * @param EntityRevision $entityRevision * @param bool $editable + * + * @throws InvalidArgumentException * @return string */ public function getInnerHtml( EntityRevision $entityRevision, $editable = true ) { @@ -249,7 +249,6 @@ $entity = $entityRevision->getEntity(); $html = ''; - $html .= $this->getHtmlForFingerprint( $entity, $editable ); $html .= $this->getHtmlForToc(); $html .= $this->getHtmlForTermBox( $entityRevision, $editable ); @@ -267,16 +266,6 @@ */ protected function getHtmlForFingerprint( Entity $entity, $editable = true ) { return $this->fingerprintView->getHtml( $entity->getFingerprint(), $entity->getId(), $editable ); - } - - /** - * Builds and returns the HTML for the entity's claims. - * - * @param Enttiy $entity - * @return string - */ - protected function getHtmlForClaims( Entity $entity ) { - return $this->claimsView->getHtml( $entity->getClaims(), 'wikibase-claims' ); } /** @@ -320,7 +309,7 @@ /** * Returns the sections that should displayed in the toc. * - * @return array( link target => system message key ) + * @return string[] array( link target => system message key ) */ protected function getTocSections() { return array(); diff --git a/repo/includes/ItemView.php b/repo/includes/ItemView.php index f332e3b..b3b8e5e 100644 --- a/repo/includes/ItemView.php +++ b/repo/includes/ItemView.php @@ -2,6 +2,7 @@ namespace Wikibase; +use InvalidArgumentException; use Wikibase\Repo\View\SiteLinksView; use Wikibase\Repo\WikibaseRepo; @@ -21,19 +22,20 @@ * @see EntityView::getInnerHtml */ public function getInnerHtml( EntityRevision $entityRevision, $editable = true ) { + wfProfileIn( __METHOD__ ); + + $item = $entityRevision->getEntity(); + + if ( !( $item instanceof Item ) ) { + throw new InvalidArgumentException( '$entityRevision must contain an Item.' ); + } + $html = parent::getInnerHtml( $entityRevision, $editable ); + $html .= $this->claimsView->getHtml( $item->getClaims(), 'wikibase-statements' ); + $html .= $this->getHtmlForSiteLinks( $item, $editable ); - // add site-links to default entity stuff - $html .= $this->getHtmlForSiteLinks( $entityRevision->getEntity(), $editable ); - + wfProfileOut( __METHOD__ ); return $html; - } - - /** - * @see EntityView::getHtmlForClaims - */ - protected function getHtmlForClaims( Entity $entity ) { - return $this->claimsView->getHtml( $entity->getClaims(), 'wikibase-statements' ); } /** @@ -43,7 +45,7 @@ $array = parent::getTocSections(); $array['claims'] = 'wikibase-statements'; $groups = WikibaseRepo::getDefaultInstance()->getSettings()->getSetting( 'siteLinkGroups' ); - foreach( $groups as $group ) { + foreach ( $groups as $group ) { $id = htmlspecialchars( 'sitelinks-' . $group, ENT_QUOTES ); $array[$id] = 'wikibase-sitelinks-' . $group; } diff --git a/repo/includes/PropertyView.php b/repo/includes/PropertyView.php index 7d0dfec..24c3b43 100644 --- a/repo/includes/PropertyView.php +++ b/repo/includes/PropertyView.php @@ -3,6 +3,7 @@ namespace Wikibase; use DataTypes\DataType; +use InvalidArgumentException; use Wikibase\Repo\WikibaseRepo; /** @@ -18,35 +19,22 @@ class PropertyView extends EntityView { /** - * 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. - * - * @param EntityRevision $entityRevision - * @param bool $editable - * - * @throws \InvalidArgumentException - * @return string + * @see EntityView::getInnerHtml */ public function getInnerHtml( EntityRevision $entityRevision, $editable = true ) { wfProfileIn( __METHOD__ ); - /* @var Property $property */ $property = $entityRevision->getEntity(); if ( !( $property instanceof Property ) ) { - throw new \InvalidArgumentException( '$propertyRevision must contain a Property' ); + throw new InvalidArgumentException( '$entityRevision must contain a Property.' ); } - $html = ''; - - $html .= $this->getHtmlForFingerprint( $property, $editable ); - $html .= $this->getHtmlForToc(); - $html .= $this->getHtmlForTermBox( $entityRevision, $editable ); - + $html = parent::getInnerHtml( $entityRevision, $editable ); $html .= $this->getHtmlForDataType( $this->getDataType( $property ) ); if ( defined( 'WB_EXPERIMENTAL_FEATURES' ) && WB_EXPERIMENTAL_FEATURES ) { - $html .= $this->getHtmlForClaims( $property ); + $html .= $this->claimsView->getHtml( $property->getClaims(), 'wikibase-attributes' ); } $footer = $this->msg( 'wikibase-property-footer' ); @@ -57,13 +45,6 @@ wfProfileOut( __METHOD__ ); return $html; - } - - /** - * @see EntityView::getHtmlForClaims - */ - protected function getHtmlForClaims( Entity $entity ) { - return $this->claimsView->getHtml( $entity->getClaims(), 'wikibase-attributes' ); } private function getDataType( Property $property ) { -- To view, visit https://gerrit.wikimedia.org/r/155737 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I9d181433b16c2e38ca59459aae249dd1e472b9d7 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits