jenkins-bot has submitted this change and it was merged.
Change subject: Use factory class to construct SpecialEntitiesWithoutPage
instances
......................................................................
Use factory class to construct SpecialEntitiesWithoutPage instances
This is a first step using the new mediawiki special page registration
process with callback functions. It moves the global state access from
the special page classes into the factory class.
Change-Id: I470687f38573af85494371b8f5f12da32e82b6eb
---
M repo/Wikibase.php
D repo/includes/specials/SpecialEntitiesWithoutDescription.php
D repo/includes/specials/SpecialEntitiesWithoutLabel.php
M repo/includes/specials/SpecialEntitiesWithoutPage.php
A repo/includes/specials/SpecialEntitiesWithoutPageFactory.php
D repo/tests/phpunit/includes/specials/SpecialEntitiesWithoutLabelTest.php
R repo/tests/phpunit/includes/specials/SpecialEntitiesWithoutPageTest.php
7 files changed, 138 insertions(+), 168 deletions(-)
Approvals:
Hoo man: Looks good to me, approved
jenkins-bot: Verified
diff --git a/repo/Wikibase.php b/repo/Wikibase.php
index b919734..c67d8db 100644
--- a/repo/Wikibase.php
+++ b/repo/Wikibase.php
@@ -151,8 +151,8 @@
$wgSpecialPages['SetDescription']
= 'Wikibase\Repo\Specials\SpecialSetDescription';
$wgSpecialPages['SetAliases']
= 'Wikibase\Repo\Specials\SpecialSetAliases';
$wgSpecialPages['SetSiteLink']
= 'Wikibase\Repo\Specials\SpecialSetSiteLink';
- $wgSpecialPages['EntitiesWithoutLabel'] =
'Wikibase\Repo\Specials\SpecialEntitiesWithoutLabel';
- $wgSpecialPages['EntitiesWithoutDescription'] =
'Wikibase\Repo\Specials\SpecialEntitiesWithoutDescription';
+ $wgSpecialPages['EntitiesWithoutLabel'] =
array( 'Wikibase\Repo\Specials\SpecialEntitiesWithoutPageFactory',
'newSpecialEntitiesWithoutLabel' );
+ $wgSpecialPages['EntitiesWithoutDescription'] = array(
'Wikibase\Repo\Specials\SpecialEntitiesWithoutPageFactory',
'newSpecialEntitiesWithoutDescription' );
$wgSpecialPages['ListDatatypes']
= 'Wikibase\Repo\Specials\SpecialListDatatypes';
$wgSpecialPages['DispatchStats']
= 'Wikibase\Repo\Specials\SpecialDispatchStats';
$wgSpecialPages['EntityData']
= 'Wikibase\Repo\Specials\SpecialEntityData';
diff --git a/repo/includes/specials/SpecialEntitiesWithoutDescription.php
b/repo/includes/specials/SpecialEntitiesWithoutDescription.php
deleted file mode 100644
index c04f62d..0000000
--- a/repo/includes/specials/SpecialEntitiesWithoutDescription.php
+++ /dev/null
@@ -1,42 +0,0 @@
-<?php
-
-namespace Wikibase\Repo\Specials;
-
-use Wikibase\Term;
-
-/**
- * Page for listing entities without description.
- *
- * @since 0.4
- * @licence GNU GPL v2+
- * @author Bene*
- */
-class SpecialEntitiesWithoutDescription extends SpecialEntitiesWithoutPage {
-
- public function __construct() {
- parent::__construct( 'EntitiesWithoutDescription' );
- }
-
- /**
- * @see SpecialEntitiesWithoutPage::getTermType
- *
- * @since 0.4
- *
- * @return string
- */
- protected function getTermType() {
- return Term::TYPE_DESCRIPTION;
- }
-
- /**
- * @see SpecialEntitiesWithoutPage::getLegend
- *
- * @since 0.4
- *
- * @return string
- */
- protected function getLegend() {
- return $this->msg( 'wikibase-entitieswithoutdescription-legend'
)->text();
- }
-
-}
diff --git a/repo/includes/specials/SpecialEntitiesWithoutLabel.php
b/repo/includes/specials/SpecialEntitiesWithoutLabel.php
deleted file mode 100644
index 3b346bd..0000000
--- a/repo/includes/specials/SpecialEntitiesWithoutLabel.php
+++ /dev/null
@@ -1,42 +0,0 @@
-<?php
-
-namespace Wikibase\Repo\Specials;
-
-use Wikibase\Term;
-
-/**
- * Page for listing entities without label.
- *
- * @since 0.2
- * @licence GNU GPL v2+
- * @author Bene*
- */
-class SpecialEntitiesWithoutLabel extends SpecialEntitiesWithoutPage {
-
- public function __construct() {
- parent::__construct( 'EntitiesWithoutLabel' );
- }
-
- /**
- * @see SpecialEntitiesWithoutPage::getTermType
- *
- * @since 0.4
- *
- * @return string
- */
- protected function getTermType() {
- return Term::TYPE_LABEL;
- }
-
- /**
- * @see SpecialEntitiesWithoutPage::getLegend
- *
- * @since 0.4
- *
- * @return string
- */
- protected function getLegend() {
- return $this->msg( 'wikibase-entitieswithoutlabel-legend'
)->text();
- }
-
-}
diff --git a/repo/includes/specials/SpecialEntitiesWithoutPage.php
b/repo/includes/specials/SpecialEntitiesWithoutPage.php
index 0592822..e66e0ba 100644
--- a/repo/includes/specials/SpecialEntitiesWithoutPage.php
+++ b/repo/includes/specials/SpecialEntitiesWithoutPage.php
@@ -4,7 +4,7 @@
use Html;
use Wikibase\EntityFactory;
-use Wikibase\Repo\WikibaseRepo;
+use Wikibase\Repo\Store\EntityPerPage;
use Wikibase\Utils;
use XmlSelect;
@@ -12,38 +12,64 @@
* Base page for pages listing entities without a specific value.
*
* @since 0.4
+ *
* @licence GNU GPL v2+
* @author Thomas Pellissier Tanon
- * @author Bene*
+ * @author Bene* < [email protected] >
*/
-abstract class SpecialEntitiesWithoutPage extends SpecialWikibaseQueryPage {
+class SpecialEntitiesWithoutPage extends SpecialWikibaseQueryPage {
/**
* The language used
*
- * @since 0.4
- *
* @var string
*/
- protected $language = '';
+ private $language = '';
/**
* The type used
*
- * @since 0.4
- *
* @var string
*/
- protected $type = null;
+ private $type = null;
/**
* Map entity types to objects representing the corresponding entity
*
- * @since 0.4
- *
* @var array
*/
- protected $possibleTypes;
+ private $possibleTypes;
+
+ /**
+ * @var string
+ */
+ private $termType;
+
+ /**
+ * @var string
+ */
+ private $legendMsg;
+
+ /**
+ * @var EntityPerPage
+ */
+ private $entityPerPage;
+
+ /**
+ * @var EntityFactory
+ */
+ private $entityFactory;
+
+ public function __construct( $name, $termType, $legendMsg,
+ EntityPerPage $entityPerPage, EntityFactory $entityFactory
+ ) {
+ parent::__construct( $name );
+
+ $this->termType = $termType;
+ $this->legendMsg = $legendMsg;
+ $this->entityPerPage = $entityPerPage;
+ $this->entityFactory = $entityFactory;
+ }
/**
* @see SpecialWikibasePage::execute
@@ -92,7 +118,7 @@
}
$this->type = $request->getText( 'type', $this->type );
- $this->possibleTypes =
EntityFactory::singleton()->getEntityTypes();
+ $this->possibleTypes = $this->entityFactory->getEntityTypes();
if ( $this->type === '' ) {
$this->type = null;
}
@@ -136,7 +162,7 @@
Html::element(
'legend',
array(),
- $this->getLegend()
+ $this->msg( $this->legendMsg )->text()
) .
Html::openElement( 'p' ) .
Html::element(
@@ -183,8 +209,7 @@
* @since 0.4
*/
protected function getResult( $offset = 0, $limit = 0 ) {
- $entityPerPage =
WikibaseRepo::getDefaultInstance()->getStore()->newEntityPerPage();
- return $entityPerPage->getEntitiesWithoutTerm(
$this->getTermType(), $this->language, $this->type, $limit, $offset );
+ return $this->entityPerPage->getEntitiesWithoutTerm(
$this->termType, $this->language, $this->type, $limit, $offset );
}
@@ -196,19 +221,5 @@
protected function getTitleForNavigation() {
return $this->getPageTitle( $this->language . '/' . $this->type
);
}
-
- /**
- * Get the term type (member of Term::TYPE_ enum)
- *
- * @since 0.4
- */
- protected abstract function getTermType();
-
- /**
- * Get the legend in HTML format
- *
- * @since 0.4
- */
- protected abstract function getLegend();
}
diff --git a/repo/includes/specials/SpecialEntitiesWithoutPageFactory.php
b/repo/includes/specials/SpecialEntitiesWithoutPageFactory.php
new file mode 100644
index 0000000..92f0efd
--- /dev/null
+++ b/repo/includes/specials/SpecialEntitiesWithoutPageFactory.php
@@ -0,0 +1,82 @@
+<?php
+
+namespace Wikibase\Repo\Specials;
+
+use Wikibase\EntityFactory;
+use Wikibase\EntityPerPage;
+use Wikibase\Repo\WikibaseRepo;
+use Wikibase\Term;
+
+/**
+ * Factory to create special pages.
+ *
+ * @since 0.5
+ *
+ * @license GNU GPL v2+
+ * @author Bene* < [email protected] >
+ */
+class SpecialEntitiesWithoutPageFactory {
+
+ private static function newFromGlobalState() {
+ $wikibaseRepo = WikibaseRepo::getDefaultInstance();
+
+ return new self(
+ $wikibaseRepo->getStore()->newEntityPerPage(),
+ $wikibaseRepo->getEntityFactory()
+ );
+ }
+
+ public static function newSpecialEntitiesWithoutLabel() {
+ return
self::newFromGlobalState()->createSpecialEntitiesWithoutLabel();
+ }
+
+ public static function newSpecialEntitiesWithoutDescription() {
+ return
self::newFromGlobalState()->createSpecialEntitiesWithoutDescription();
+ }
+
+ /**
+ * @var EntityPerPage
+ */
+ private $entityPerPage;
+
+ /**
+ * @var EntityFactory
+ */
+ private $entityFactory;
+
+ public function __construct( EntityPerPage $entityPerPage,
EntityFactory $entityFactory ) {
+ $this->entityPerPage = $entityPerPage;
+ $this->entityFactory = $entityFactory;
+ }
+
+ /**
+ * @since 0.5
+ *
+ * @return SpecialEntitiesWithoutPage
+ */
+ public function createSpecialEntitiesWithoutLabel() {
+ return new SpecialEntitiesWithoutPage(
+ 'EntitiesWithoutLabel',
+ Term::TYPE_LABEL,
+ 'wikibase-entitieswithoutlabel-legend',
+ $this->entityPerPage,
+ $this->entityFactory
+ );
+ }
+
+ /**
+ * @since 0.5
+ *
+ * @return SpecialEntitiesWithoutPage
+ */
+ public function createSpecialEntitiesWithoutDescription() {
+ return new SpecialEntitiesWithoutPage(
+ 'EntitiesWithoutDescription',
+ Term::TYPE_DESCRIPTION,
+ 'wikibase-entitieswithoutdescription-legend',
+ $this->entityPerPage,
+ $this->entityFactory
+ );
+ }
+
+}
diff --git
a/repo/tests/phpunit/includes/specials/SpecialEntitiesWithoutLabelTest.php
b/repo/tests/phpunit/includes/specials/SpecialEntitiesWithoutLabelTest.php
deleted file mode 100644
index 08433f8..0000000
--- a/repo/tests/phpunit/includes/specials/SpecialEntitiesWithoutLabelTest.php
+++ /dev/null
@@ -1,48 +0,0 @@
-<?php
-
-namespace Wikibase\Test;
-
-use Wikibase\Repo\Specials\SpecialEntitiesWithoutLabel;
-
-/**
- * @covers Wikibase\Repo\Specials\SpecialEntitiesWithoutLabel
- *
- * @group Wikibase
- * @group WikibaseRepo
- * @group SpecialPage
- * @group WikibaseSpecialPage
- *
- * @licence GNU GPL v2+
- * @author Adam Shorland
- */
-class SpecialEntitiesWithoutLabelTest extends SpecialPageTestBase {
-
- protected function newSpecialPage() {
- return new SpecialEntitiesWithoutLabel();
- }
-
- public function testExecute() {
-
- $matchers['language'] = array(
- 'tag' => 'input',
- 'attributes' => array(
- 'id' => 'wb-entitieswithoutpage-language',
- 'name' => 'language',
- ) );
-
- $matchers['submit'] = array(
- 'tag' => 'input',
- 'attributes' => array(
- 'id' => 'wikibase-entitieswithoutpage-submit',
- 'class' => 'wb-input-button',
- 'type' => 'submit',
- 'name' => 'submit',
- ) );
-
- list( $output, ) = $this->executeSpecialPage( '' );
- foreach( $matchers as $key => $matcher ){
- $this->assertTag( $matcher, $output, "Failed to match
html output with tag '{$key}''" );
- }
- }
-
-}
diff --git
a/repo/tests/phpunit/includes/specials/SpecialEntitiesWithoutDescriptionTest.php
b/repo/tests/phpunit/includes/specials/SpecialEntitiesWithoutPageTest.php
similarity index 68%
rename from
repo/tests/phpunit/includes/specials/SpecialEntitiesWithoutDescriptionTest.php
rename to
repo/tests/phpunit/includes/specials/SpecialEntitiesWithoutPageTest.php
index 1d77234..a729f5d 100644
---
a/repo/tests/phpunit/includes/specials/SpecialEntitiesWithoutDescriptionTest.php
+++ b/repo/tests/phpunit/includes/specials/SpecialEntitiesWithoutPageTest.php
@@ -2,10 +2,12 @@
namespace Wikibase\Test;
-use Wikibase\Repo\Specials\SpecialEntitiesWithoutDescription;
+use Wikibase\Repo\Specials\SpecialEntitiesWithoutPage;
+use Wikibase\Repo\WikibaseRepo;
+use Wikibase\Term;
/**
- * @covers Wikibase\Repo\Specials\SpecialEntitiesWithoutDescription
+ * @covers Wikibase\Repo\Specials\SpecialEntitiesWithoutPage
*
* @group Wikibase
* @group WikibaseRepo
@@ -19,10 +21,17 @@
* @author Bene* < [email protected] >
* @author Adam Shorland
*/
-class SpecialEntitiesWithoutDescriptionTest extends SpecialPageTestBase {
+class SpecialEntitiesWithoutPageTest extends SpecialPageTestBase {
protected function newSpecialPage() {
- return new SpecialEntitiesWithoutDescription();
+ $wikibaseRepo = WikibaseRepo::getDefaultInstance();
+ return new SpecialEntitiesWithoutPage(
+ 'EntitiesWithoutLabel',
+ Term::TYPE_LABEL,
+ 'wikibase-entitieswithoutlabel-legend',
+ $wikibaseRepo->getStore()->newEntityPerPage(),
+ $wikibaseRepo->getEntityFactory()
+ );
}
public function testExecute() {
--
To view, visit https://gerrit.wikimedia.org/r/162903
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I470687f38573af85494371b8f5f12da32e82b6eb
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Bene <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: JanZerebecki <[email protected]>
Gerrit-Reviewer: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits