Aude has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/204079

Change subject: [DO NOT MERGE] - split SpecialListProperties code into separate 
class
......................................................................

[DO NOT MERGE] - split SpecialListProperties code into separate class

this is just an ugly example and proof of concept that
the special page code can be split.

this would help with testability.

Change-Id: Id8d63ae1428c62128bf598dee394783cb87721be
---
A repo/includes/specials/PropertyLister.php
M repo/includes/specials/SpecialListProperties.php
2 files changed, 157 insertions(+), 88 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/79/204079/1

diff --git a/repo/includes/specials/PropertyLister.php 
b/repo/includes/specials/PropertyLister.php
new file mode 100644
index 0000000..4857d97
--- /dev/null
+++ b/repo/includes/specials/PropertyLister.php
@@ -0,0 +1,152 @@
+<?php
+
+namespace Wikibase\Repo\Specials;
+
+use DataTypes\DataTypeFactory;
+use Html;
+use Linker;
+use MWException;
+use Wikibase\DataModel\Entity\PropertyId;
+use Wikibase\DataTypeSelector;
+use Wikibase\PropertyInfoStore;
+use Wikibase\Repo\Content\EntityContentFactory;
+use Wikibase\Repo\WikibaseRepo;
+
+/**
+ * Special page to list properties by data type
+ *
+ * @since 0.5
+ * @licence GNU GPL v2+
+ * @author Bene* < benestar.wikime...@gmail.com >
+ */
+class PropertyLister {
+
+       /**
+        * @var DataTypeFactory
+        */
+       private $dataTypeFactory;
+
+       /**
+        * @var PropertyInfoStore
+        */
+       private $propertyInfoStore;
+
+       /**
+        * @var EntityContentFactory
+        */
+       private $entityContentFactory;
+
+       /**
+        * @var string
+        */
+       private $dataType;
+
+       /**
+        * @since 0.5
+        */
+       public function __construct() {
+               $this->dataTypeFactory = 
WikibaseRepo::getDefaultInstance()->getDataTypeFactory();
+               $this->propertyInfoStore = 
WikibaseRepo::getDefaultInstance()->getStore()->getPropertyInfoStore();
+               $this->entityContentFactory = 
WikibaseRepo::getDefaultInstance()->getEntityContentFactory();
+       }
+
+       /**
+        * @see SpecialWikibasePage::execute
+        *
+        * @since 0.5
+        *
+        * @param string|null $subPage
+        */
+       public function doExecute( &$output, $request, $title, $languageCode, 
$subPage ) {
+               $this->prepareArguments( $request, $subPage );
+               $this->showForm( $output, $title, $languageCode );
+
+               if ( $this->dataType !== null ) {
+                       $this->showQuery( $output );
+               }
+       }
+
+       private function prepareArguments( $request, $subPage ) {
+               $this->dataType = $request->getText( 'datatype', $subPage );
+               if ( !in_array( $this->dataType, 
$this->dataTypeFactory->getTypeIds() ) ) {
+                       $this->dataType = null;
+               }
+       }
+
+       private function showForm( &$output, $title, $languageCode ) {
+               $dataTypeSelect = new DataTypeSelector(
+                       $this->dataTypeFactory->getTypes(),
+                       $languageCode
+               );
+
+               $output->addHTML(
+                       Html::openElement(
+                               'form',
+                               array(
+                                       'action' => $title->getLocalURL(),
+                                       'name' => 'listproperties',
+                                       'id' => 'wb-listproperties-form'
+                               )
+                       ) .
+                       Html::input (
+                               'title',
+                               $title->getPrefixedText(),
+                               'hidden',
+                               array()
+                       ) .
+                       Html::openElement( 'fieldset' ) .
+                       Html::element(
+                               'legend',
+                               array(),
+                               wfMessage( 'wikibase-listproperties-legend' 
)->text()
+                       ) .
+                       Html::openElement( 'p' ) .
+                       Html::element(
+                               'label',
+                               array(
+                                       'for' => 'wb-listproperties-datatype'
+                               ),
+                               wfMessage( 
'wikibase-listproperties-label-datatype' )->text()
+                       ) . ' ' .
+                       $dataTypeSelect->getHTML( 'wb-listproperties-datatype', 
'datatype', $this->dataType ) . ' ' .
+                       Html::input(
+                               'submit',
+                               wfMessage( 'wikibase-listproperties-submit' 
)->text(),
+                               'submit',
+                               array(
+                                       'id' => 
'wikibase-listproperties-submit',
+                                       'class' => 'wb-input-button'
+                               )
+                       ) .
+                       Html::closeElement( 'p' ) .
+                       Html::closeElement( 'fieldset' ) .
+                       Html::closeElement( 'form' )
+               );
+       }
+
+       private function showQuery( &$output ) {
+               $propertyInfoForDataType = 
$this->propertyInfoStore->getPropertyInfoForDataType( $this->dataType );
+
+               if ( empty( $propertyInfoForDataType ) ) {
+                       $output->addWikiMsg( 'specialpage-empty' );
+                       return;
+               }
+
+               $html = Html::openElement( 'ul' );
+
+               foreach ( $propertyInfoForDataType as $numericId => $info ) {
+                       $row = $this->formatRow( PropertyId::newFromNumber( 
$numericId ) );
+                       $html .= Html::rawElement( 'li', array(), $row );
+               }
+
+               $html .= Html::closeElement( 'ul' );
+               $output->addHTML( $html );
+       }
+
+       private function formatRow( PropertyId $propertyId ) {
+               $title = $this->entityContentFactory->getTitleForId( 
$propertyId );
+               return Linker::linkKnown( $title );
+       }
+
+}
+
diff --git a/repo/includes/specials/SpecialListProperties.php 
b/repo/includes/specials/SpecialListProperties.php
index 8239333..d7e8e4f 100644
--- a/repo/includes/specials/SpecialListProperties.php
+++ b/repo/includes/specials/SpecialListProperties.php
@@ -62,97 +62,14 @@
        public function execute( $subPage ) {
                parent::execute( $subPage );
 
-               $this->prepareArguments( $subPage );
-               $this->showForm();
+               $propertyLister = new PropertyLister();
 
-               if ( $this->dataType !== null ) {
-                       $this->showQuery();
-               }
-       }
-
-       private function prepareArguments( $subPage ) {
+               $output = $this->getOutput();
                $request = $this->getRequest();
+               $title = $this->getPageTitle();
+               $languageCode = $this->getLanguage()->getCode();
 
-               $this->dataType = $request->getText( 'datatype', $subPage );
-               if ( !in_array( $this->dataType, 
$this->dataTypeFactory->getTypeIds() ) ) {
-                       $this->dataType = null;
-               }
-       }
-
-       private function showForm() {
-               $dataTypeSelect = new DataTypeSelector(
-                       $this->dataTypeFactory->getTypes(),
-                       $this->getLanguage()->getCode()
-               );
-
-               $this->getOutput()->addHTML(
-                       Html::openElement(
-                               'form',
-                               array(
-                                       'action' => 
$this->getPageTitle()->getLocalURL(),
-                                       'name' => 'listproperties',
-                                       'id' => 'wb-listproperties-form'
-                               )
-                       ) .
-                       Html::input (
-                               'title',
-                               $this->getPageTitle()->getPrefixedText(),
-                               'hidden',
-                               array()
-                       ) .
-                       Html::openElement( 'fieldset' ) .
-                       Html::element(
-                               'legend',
-                               array(),
-                               $this->msg( 'wikibase-listproperties-legend' 
)->text()
-                       ) .
-                       Html::openElement( 'p' ) .
-                       Html::element(
-                               'label',
-                               array(
-                                       'for' => 'wb-listproperties-datatype'
-                               ),
-                               $this->msg( 
'wikibase-listproperties-label-datatype' )->text()
-                       ) . ' ' .
-                       $dataTypeSelect->getHTML( 'wb-listproperties-datatype', 
'datatype', $this->dataType ) . ' ' .
-                       Html::input(
-                               'submit',
-                               $this->msg( 'wikibase-listproperties-submit' 
)->text(),
-                               'submit',
-                               array(
-                                       'id' => 
'wikibase-listproperties-submit',
-                                       'class' => 'wb-input-button'
-                               )
-                       ) .
-                       Html::closeElement( 'p' ) .
-                       Html::closeElement( 'fieldset' ) .
-                       Html::closeElement( 'form' )
-               );
-       }
-
-       private function showQuery() {
-               $propertyInfoForDataType = 
$this->propertyInfoStore->getPropertyInfoForDataType( $this->dataType );
-
-               if ( empty( $propertyInfoForDataType ) ) {
-                       $this->getOutput()->addWikiMsg( 'specialpage-empty' );
-                       return;
-               }
-
-               $html = Html::openElement( 'ul' );
-
-               foreach ( $propertyInfoForDataType as $numericId => $info ) {
-                       $row = $this->formatRow( PropertyId::newFromNumber( 
$numericId ) );
-                       $html .= Html::rawElement( 'li', array(), $row );
-               }
-
-               $html .= Html::closeElement( 'ul' );
-               $this->getOutput()->addHTML( $html );
-       }
-
-       private function formatRow( PropertyId $propertyId ) {
-               $title = $this->entityContentFactory->getTitleForId( 
$propertyId );
-               return Linker::linkKnown( $title );
+               $propertyLister->doExecute( $output, $request, $title, 
$languageCode, $subPage );
        }
 
 }
-

-- 
To view, visit https://gerrit.wikimedia.org/r/204079
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id8d63ae1428c62128bf598dee394783cb87721be
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Aude <aude.w...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to