Jeroen De Dauw has submitted this change and it was merged.

Change subject: Introduce SpecialPageLinker
......................................................................


Introduce SpecialPageLinker

Change-Id: I937a17873221a614bddeb4a81ca12eea610f1e43
---
M composer.json
M repo/includes/View/EntityViewFactory.php
A repo/includes/View/RepoSpecialPageLinker.php
M repo/includes/View/ToolbarEditSectionGenerator.php
A repo/tests/phpunit/includes/View/RepoSpecialPageLinkerTest.php
M repo/tests/phpunit/includes/View/ToolbarEditSectionGeneratorTest.php
A view/src/SpecialPageLinker.php
7 files changed, 106 insertions(+), 37 deletions(-)

Approvals:
  Jeroen De Dauw: Looks good to me, approved



diff --git a/composer.json b/composer.json
index 1989830..e8662c9 100644
--- a/composer.json
+++ b/composer.json
@@ -67,7 +67,8 @@
                        "repo/Wikibase.hooks.php"
                ],
                "psr-4": {
-                       "Wikibase\\Repo\\View\\": "repo/includes/View"
+                       "Wikibase\\Repo\\View\\": "repo/includes/View",
+                       "Wikibase\\View\\": "view/src"
                }
        }
 }
diff --git a/repo/includes/View/EntityViewFactory.php 
b/repo/includes/View/EntityViewFactory.php
index 8cb404c..1bee9db 100644
--- a/repo/includes/View/EntityViewFactory.php
+++ b/repo/includes/View/EntityViewFactory.php
@@ -148,6 +148,7 @@
                $editable = true
         ) {
                $editSectionGenerator = $editable ? new 
ToolbarEditSectionGenerator(
+                       new RepoSpecialPageLinker(),
                        $this->templateFactory
                ) : new EmptyEditSectionGenerator();
                $entityTermsView = $this->newEntityTermsView( $languageCode, 
$editSectionGenerator );
diff --git a/repo/includes/View/RepoSpecialPageLinker.php 
b/repo/includes/View/RepoSpecialPageLinker.php
new file mode 100644
index 0000000..5fe1941
--- /dev/null
+++ b/repo/includes/View/RepoSpecialPageLinker.php
@@ -0,0 +1,26 @@
+<?php
+
+namespace Wikibase\Repo\View;
+
+use SpecialPage;
+use Wikibase\View\SpecialPageLinker;
+
+/**
+ * A SpecialPageLinker implementation linking to special pages of the local 
MediaWiki installation.
+ *
+ * @author Adrian Heine < [email protected] >
+ */
+class RepoSpecialPageLinker implements SpecialPageLinker {
+
+       /**
+        * @param string $pageName
+        * @param string[] $subPageParams Parameters to be added as 
slash-separated sub pages
+        */
+       public function getLink( $pageName, array $subPageParams = array() ) {
+               $subPage = implode( '/', array_map( 'wfUrlencode', 
$subPageParams ) );
+               $specialPageTitle = SpecialPage::getTitleFor( $pageName, 
$subPage );
+
+               return $specialPageTitle->getLocalURL();
+       }
+
+}
diff --git a/repo/includes/View/ToolbarEditSectionGenerator.php 
b/repo/includes/View/ToolbarEditSectionGenerator.php
index 641d2b5..0f82c1f 100644
--- a/repo/includes/View/ToolbarEditSectionGenerator.php
+++ b/repo/includes/View/ToolbarEditSectionGenerator.php
@@ -2,12 +2,11 @@
 
 namespace Wikibase\Repo\View;
 
-use Message;
-use SpecialPage;
 use Wikibase\DataModel\Entity\EntityId;
 use Wikibase\DataModel\Entity\PropertyId;
 use Wikibase\DataModel\Statement\Statement;
 use Wikibase\Template\TemplateFactory;
+use Wikibase\View\SpecialPageLinker;
 
 /**
  * Generates HTML for a section edit link
@@ -23,15 +22,22 @@
 class ToolbarEditSectionGenerator implements EditSectionGenerator {
 
        /**
+        * @var SpecialPageLinker
+        */
+       private $specialPageLinker;
+
+       /**
         * @var TemplateFactory
         */
        private $templateFactory;
 
        /**
+        * @param SpecialPageLinker $specialPageLinker
         * @param TemplateFactory $templateFactory
         */
-       public function __construct( TemplateFactory $templateFactory ) {
+       public function __construct( SpecialPageLinker $specialPageLinker, 
TemplateFactory $templateFactory ) {
                $this->templateFactory = $templateFactory;
+               $this->specialPageLinker = $specialPageLinker;
        }
 
        public function getSiteLinksEditSection( EntityId $entityId = null ) {
@@ -102,10 +108,7 @@
                        return null;
                }
 
-               $subPage = implode( '/', array_map( 'wfUrlencode', 
$specialPageUrlParams ) );
-               $specialPageTitle = SpecialPage::getTitleFor( $specialPageName, 
$subPage );
-
-               return $specialPageTitle->getLocalURL();
+               return $this->specialPageLinker->getLink( $specialPageName, 
$specialPageUrlParams );
        }
 
        /**
diff --git a/repo/tests/phpunit/includes/View/RepoSpecialPageLinkerTest.php 
b/repo/tests/phpunit/includes/View/RepoSpecialPageLinkerTest.php
new file mode 100644
index 0000000..f890c79
--- /dev/null
+++ b/repo/tests/phpunit/includes/View/RepoSpecialPageLinkerTest.php
@@ -0,0 +1,39 @@
+<?php
+
+namespace Wikibase\Test;
+
+use MediaWikiLangTestCase;
+use Wikibase\Repo\View\RepoSpecialPageLinker;
+
+/**
+ * @covers Wikibase\Repo\View\RepoSpecialPageLinker
+ *
+ * @author Adrian Heine < [email protected] >
+ */
+class RepoSpecialPageLinkerTest extends MediaWikiLangTestCase {
+
+       /**
+        * @dataProvider getLinkProvider
+        *
+        * @param string $specialPageName
+        * @param string[] $subPageParams
+        * @param string $expectedMatch
+        */
+       public function testGetLink( $specialPageName, $subPageParams, 
$expectedMatch) {
+               $linker = new RepoSpecialPageLinker();
+
+               $link = $linker->getLink( $specialPageName, $subPageParams );
+
+               $this->assertRegExp( $expectedMatch, $link );
+       }
+
+       public function getLinkProvider() {
+               return array(
+                       array( 'SetLabel', array(), '/Special:SetLabel\/?$/' ),
+                       array( 'SetLabel', array( 'en' ), 
'/Special:SetLabel\/en\/?$/' ),
+                       array( 'SetLabel', array( 'en', 'Q5' ), 
'/Special:SetLabel\/en\/Q5\/?$/' )
+               );
+       }
+
+
+}
diff --git 
a/repo/tests/phpunit/includes/View/ToolbarEditSectionGeneratorTest.php 
b/repo/tests/phpunit/includes/View/ToolbarEditSectionGeneratorTest.php
index 8e4b041..6d0d14f 100644
--- a/repo/tests/phpunit/includes/View/ToolbarEditSectionGeneratorTest.php
+++ b/repo/tests/phpunit/includes/View/ToolbarEditSectionGeneratorTest.php
@@ -31,35 +31,6 @@
  */
 class ToolbarEditSectionGeneratorTest extends MediaWikiTestCase {
 
-       protected function setUp() {
-               // Make sure wgSpecialPages has the special pages this class 
uses
-               $this->setMwGlobals(
-                       'wgSpecialPages',
-                       array(
-                               'SetSiteLink' => new SpecialPage( 'SetSiteLink' 
),
-                               'SetLabelDescriptionAliases' => new 
SpecialPage( 'SetLabelDescriptionAliases' )
-                       )
-               );
-
-               SpecialPageFactory::resetList();
-               $doubleLanguage = $this->getMock( 'Language', array( 
'getSpecialPageAliases' ) );
-               $doubleLanguage->mCode = 'en';
-               $doubleLanguage->expects( $this->any() )
-                       ->method( 'getSpecialPageAliases' )
-                       ->will( $this->returnValue(
-                               array(
-                                       'SetSiteLink' => array( 'SetSiteLink' ),
-                                       'SetLabelDescriptionAliases' => array( 
'SetLabelDescriptionAliases' )
-                               )
-                       ) );
-
-               $this->setMwGlobals(
-                       'wgContLang',
-                       $doubleLanguage
-               );
-               parent::setUp();
-       }
-
        /**
         * @dataProvider getAddStatementToGroupSectionProvider
         */
@@ -137,7 +108,14 @@
        }
 
        private function newToolbarEditSectionGenerator() {
+               $specialPageLinker = $this->getMock( 
'Wikibase\View\SpecialPageLinker' );
+               $specialPageLinker->expects( $this->any() )
+                       ->method( 'getLink' )
+                       ->will( $this->returnCallback( function( $specialPage, 
$params = array() ) {
+                               return 'Special:' . $specialPage . '/' . 
implode( '/', $params );
+                       } ) );
                return new ToolbarEditSectionGenerator(
+                       $specialPageLinker,
                        new TemplateFactory( 
TemplateRegistry::getDefaultInstance() )
                );
        }
diff --git a/view/src/SpecialPageLinker.php b/view/src/SpecialPageLinker.php
new file mode 100644
index 0000000..8645d8c
--- /dev/null
+++ b/view/src/SpecialPageLinker.php
@@ -0,0 +1,21 @@
+<?php
+
+namespace Wikibase\View;
+
+/**
+ * A service returning a URL for a specific special page with optional 
parameters.
+ *
+ * @author Adrian Heine < [email protected] >
+ */
+interface SpecialPageLinker {
+
+       /**
+        * Returns the URL to a special page with optional params
+        *
+        * @since 0.5
+        * @param string $pageName
+        * @param string[] $subPageParams Parameters to be added as 
slash-separated sub pages
+        */
+       public function getLink( $pageName, array $subPageParams = array() );
+
+}

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I937a17873221a614bddeb4a81ca12eea610f1e43
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Adrian Lang <[email protected]>
Gerrit-Reviewer: Adrian Lang <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to