jenkins-bot has submitted this change and it was merged.
Change subject: Add paging to ListProperties
......................................................................
Add paging to ListProperties
Bug: T98437
Change-Id: Iee8af979efae7ad527096257545aedb88670f934
---
M repo/includes/specials/SpecialListProperties.php
M repo/tests/phpunit/includes/specials/SpecialListPropertiesTest.php
2 files changed, 67 insertions(+), 27 deletions(-)
Approvals:
Daniel Kinzler: Looks good to me, approved
Thiemo Mättig (WMDE): Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git a/repo/includes/specials/SpecialListProperties.php
b/repo/includes/specials/SpecialListProperties.php
index 2d55c3c..4ee3492 100644
--- a/repo/includes/specials/SpecialListProperties.php
+++ b/repo/includes/specials/SpecialListProperties.php
@@ -5,6 +5,7 @@
use DataTypes\DataTypeFactory;
use Html;
use Wikibase\DataModel\Entity\PropertyId;
+use Wikibase\DataModel\Services\EntityId\EntityIdFormatter;
use Wikibase\DataTypeSelector;
use Wikibase\PropertyInfoStore;
use Wikibase\Lib\Store\LanguageFallbackLabelDescriptionLookupFactory;
@@ -51,6 +52,16 @@
* @var string
*/
private $dataType;
+
+ /**
+ * @var PropertyId[]
+ */
+ private $propertyIds = array();
+
+ /**
+ * @var EntityIdFormatter
+ */
+ private $entityIdFormatter;
public function __construct() {
parent::__construct( 'ListProperties' );
@@ -173,29 +184,29 @@
);
}
- protected function showQuery( array $query = array() ) {
- $propertyIds = $this->getResult();
+ /**
+ * Formats a row for display.
+ *
+ * @param PropertyId $propertyId
+ *
+ * @return string
+ */
+ protected function formatRow( $propertyId ) {
+ $entityIdFormatter = $this->getEntityIdFormatter();
+ return $entityIdFormatter->formatEntityId( $propertyId );
+ }
- if ( empty( $propertyIds ) ) {
- $this->getOutput()->addWikiMsg( 'specialpage-empty' );
- return;
+ private function getEntityIdFormatter() {
+ if ( !isset( $this->entityIdFormatter ) ) {
+ $labelDescriptionLookup =
$this->labelDescriptionLookupFactory->newLabelDescriptionLookup(
+ $this->getLanguage(),
+ $this->propertyIds
+ );
+ $this->entityIdFormatter =
$this->entityIdFormatterFactory->getEntityIdFormater(
+ $labelDescriptionLookup
+ );
}
-
- $labelDescriptionLookup =
$this->labelDescriptionLookupFactory->newLabelDescriptionLookup(
- $this->getLanguage(),
- $propertyIds
- );
-
- $formatter =
$this->entityIdFormatterFactory->getEntityIdFormater( $labelDescriptionLookup );
-
- $html = Html::openElement( 'ul' );
-
- foreach ( $propertyIds as $propertyId ) {
- $html .= Html::rawElement( 'li', array(),
$formatter->formatEntityId( $propertyId ) );
- }
-
- $html .= Html::closeElement( 'ul' );
- $this->getOutput()->addHTML( $html );
+ return $this->entityIdFormatter;
}
/**
@@ -205,19 +216,27 @@
* @return PropertyId[]
*/
protected function getResult( $offset = 0, $limit = 0 ) {
- if ( $this->dataType === '' ) {
- $propertyInfoForDataType =
$this->propertyInfoStore->getAllPropertyInfo();
- } else {
- $propertyInfoForDataType =
$this->propertyInfoStore->getPropertyInfoForDataType( $this->dataType );
- }
+ $propertyInfo = array_slice( $this->getPropertyInfo(), $offset,
$limit, true );
$propertyIds = array();
- foreach ( $propertyInfoForDataType as $numericId => $info ) {
+ foreach ( $propertyInfo as $numericId => $info ) {
$propertyIds[] = PropertyId::newFromNumber( $numericId
);
}
+ $this->propertyIds = $propertyIds;
+
return $propertyIds;
}
+ private function getPropertyInfo() {
+ if ( $this->dataType === '' ) {
+ return $this->propertyInfoStore->getAllPropertyInfo();
+ } else {
+ return
$this->propertyInfoStore->getPropertyInfoForDataType(
+ $this->dataType
+ );
+ }
+ }
+
}
diff --git a/repo/tests/phpunit/includes/specials/SpecialListPropertiesTest.php
b/repo/tests/phpunit/includes/specials/SpecialListPropertiesTest.php
index 288b294..af68701 100644
--- a/repo/tests/phpunit/includes/specials/SpecialListPropertiesTest.php
+++ b/repo/tests/phpunit/includes/specials/SpecialListPropertiesTest.php
@@ -8,8 +8,10 @@
use Title;
use Wikibase\DataModel\Entity\EntityId;
use Wikibase\DataModel\Entity\PropertyId;
+use Wikibase\DataModel\Services\Lookup\TermLookup;
use Wikibase\LanguageFallbackChainFactory;
use Wikibase\Lib\LanguageNameLookup;
+use Wikibase\Lib\Store\EntityTitleLookup;
use Wikibase\PropertyInfoStore;
use Wikibase\Repo\EntityIdHtmlLinkFormatterFactory;
use Wikibase\Lib\Store\LanguageFallbackLabelDescriptionLookupFactory;
@@ -25,6 +27,7 @@
*
* @licence GNU GPL v2+
* @author Bene* < [email protected] >
+ * @author Adam Shorland
*/
class SpecialListPropertiesTest extends SpecialPageTestBase {
@@ -67,6 +70,9 @@
return $propertyInfoStore;
}
+ /**
+ * @return TermLookup
+ */
private function getTermLookup() {
$termLookup = $this->getMock(
'Wikibase\DataModel\Services\Lookup\TermLookup' );
$termLookup->expects( $this->any() )
@@ -86,6 +92,9 @@
return $termBuffer;
}
+ /**
+ * @return EntityTitleLookup
+ */
private function getEntityTitleLookup() {
$entityTitleLookup = $this->getMock(
'Wikibase\Lib\Store\EntityTitleLookup' );
$entityTitleLookup->expects( $this->any() )
@@ -125,6 +134,18 @@
$this->assertContains( 'wikibase-listproperties-summary',
$output );
$this->assertContains( 'wikibase-listproperties-legend',
$output );
$this->assertNotContains(
'wikibase-listproperties-invalid-datatype', $output );
+ $this->assertContains( 'P123', $output );
+ $this->assertContains( 'P456', $output );
+ $this->assertContains( 'P789', $output );
+ }
+
+ public function testOffsetAndLimit() {
+ $request = new \FauxRequest( array( 'limit' => '1', 'offset' =>
'1' ) );
+ list( $output, ) = $this->executeSpecialPage( '', $request );
+
+ $this->assertNotContains( 'P123', $output );
+ $this->assertContains( 'P456', $output );
+ $this->assertNotContains( 'P789', $output );
}
public function testExecute_empty() {
--
To view, visit https://gerrit.wikimedia.org/r/230063
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Iee8af979efae7ad527096257545aedb88670f934
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Bene <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: Jonas Kress (WMDE) <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits