Aude has uploaded a new change for review.
https://gerrit.wikimedia.org/r/91601
Change subject: cleanup and improve RepoLinker
......................................................................
cleanup and improve RepoLinker
Change-Id: Id302c4b8dcc8204bb164122a8fee5191ebf1f178
---
M client/WikibaseClient.hooks.php
M client/includes/RepoItemLinkGenerator.php
M client/includes/RepoLinker.php
M client/includes/hooks/MovePageNotice.php
M client/includes/recentchanges/ExternalChangesLine.php
M client/tests/phpunit/includes/RepoItemLinkGeneratorTest.php
M client/tests/phpunit/includes/RepoLinkerTest.php
7 files changed, 183 insertions(+), 422 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/01/91601/1
diff --git a/client/WikibaseClient.hooks.php b/client/WikibaseClient.hooks.php
index d5ac7cb..cda2470 100644
--- a/client/WikibaseClient.hooks.php
+++ b/client/WikibaseClient.hooks.php
@@ -422,7 +422,7 @@
$entityId = $entityIdParser->parse( $prefixedId );
$repoLinker =
WikibaseClient::getDefaultInstance()->newRepoLinker();
- $itemLink = $repoLinker->repoItemUrl( $entityId );
+ $itemLink = $repoLinker->getEntityUrl( $entityId );
$toolbox['wikibase'] = array(
'text' => $sk->getMsg( 'wikibase-dataitem'
)->text(),
diff --git a/client/includes/RepoItemLinkGenerator.php
b/client/includes/RepoItemLinkGenerator.php
index 8fa69ee..4f5eb71 100644
--- a/client/includes/RepoItemLinkGenerator.php
+++ b/client/includes/RepoItemLinkGenerator.php
@@ -2,29 +2,12 @@
namespace Wikibase;
-use \Wikibase\Lib\EntityIdParser;
-use \ValueParsers\ParseException;
+use Title;
+use ValueParsers\ParseException;
+use Wikibase\Lib\EntityIdParser;
/**
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
* @since 0.4
- *
- * @file
- * @ingroup WikibaseClient
*
* @licence GNU GPL v2+
* @author Katie Filbert < [email protected] >
@@ -63,7 +46,7 @@
/**
* @since 0.4
*
- * @param \Title $title
+ * @param Title $title
* @param string $action
* @param boolean $isAnon
* @param array|null $noExternalLangLinks
@@ -71,7 +54,7 @@
*
* @return array|null
*/
- public function getLink( \Title $title, $action, $isAnon,
$noExternalLangLinks, $prefixedId ) {
+ public function getLink( Title $title, $action, $isAnon,
$noExternalLangLinks, $prefixedId ) {
$editLink = null;
if ( $this->canHaveLink( $title, $action, $noExternalLangLinks
) ) {
@@ -93,13 +76,13 @@
/**
* @since 0.4
*
- * @param \Title $title
+ * @param Title $title
* @param string $action
* @param mixed $noExternalLangLinks
*
* @return boolean
*/
- protected function canHaveLink( \Title $title, $action,
$noExternalLangLinks ) {
+ protected function canHaveLink( Title $title, $action,
$noExternalLangLinks ) {
if ( $action !== 'view' ) {
return false;
}
@@ -140,7 +123,7 @@
$fragment = '#sitelinks-' . htmlspecialchars( $this->siteGroup,
ENT_QUOTES );
$link = array(
- 'href' => $this->repoLinker->repoItemUrl( $entityId ) .
$fragment,
+ 'href' => $this->repoLinker->getEntityUrl( $entityId )
. $fragment,
'text' => wfMessage( 'wikibase-editlinks' )->text(),
'title' => wfMessage( 'wikibase-editlinkstitle'
)->text(),
'class' => 'wbc-editpage',
diff --git a/client/includes/RepoLinker.php b/client/includes/RepoLinker.php
index ab4fc11..c7b0b58 100644
--- a/client/includes/RepoLinker.php
+++ b/client/includes/RepoLinker.php
@@ -2,24 +2,10 @@
namespace Wikibase;
+use Html;
use Wikibase\Client\WikibaseClient;
/**
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
* @since 0.2
*
* @file
@@ -54,66 +40,6 @@
}
/**
- * @since 0.2
- *
- * @return string
- */
- public function baseUrl() {
- return rtrim( $this->baseUrl, '/' );
- }
-
- /**
- * @since 0.3
- *
- * @param string $target
- *
- * @return string
- */
- public function repoArticleUrl( $target ) {
- $encodedPage = $this->encodePage( $target );
- return $this->baseUrl() . str_replace( '$1', $encodedPage,
$this->articlePath );
- }
-
- /**
- * Encode a page title
- *
- * @since 0.4
- *
- * @param string $page
- *
- * @return string
- */
- protected function encodePage( $page ) {
- if ( !is_string( $page ) ) {
- trigger_error( __CLASS__ . ' : Trying to encode a page
but $page is not a string.', E_USER_WARNING );
- return '';
- }
- return is_string( $page ) ? wfUrlencode( str_replace( ' ', '_',
$page ) ) : '';
- }
-
- /**
- * Returns a url to the item page on the repo
- * @todo support all types of entities
- *
- * @since 0.4
- *
- * @param EntityId $entityId
- *
- * @return string
- */
- public function repoItemUrl( EntityId $entityId ) {
- $idFormatter =
WikibaseClient::getDefaultInstance()->getEntityIdFormatter();
- $prefixedId = $idFormatter->format( $entityId );
-
- $itemNamespace = $this->getNamespace( Item::ENTITY_TYPE );
-
- $formattedNamespace = is_string( $itemNamespace ) && !empty(
$itemNamespace ) ?
- $itemNamespace . ':' : $itemNamespace;
-
- return $this->repoArticleUrl( $formattedNamespace . strtoupper(
$prefixedId ) );
- }
-
- /**
* Get namespace of an entity in string format
*
* @since 0.2
@@ -139,60 +65,104 @@
/**
* @since 0.3
- * @todo could be made nicer
*
- * @param string|null $target - needed only for /wiki/$1 type links
- * @param string $text - what goes inside the <a> tag
- * @param array $attribs - optional, used only for query string urls,
and both
- * url formats to insert additional css classes; example:
- * $attribs = array(
- * 'query' =>
- * 'params' => array(
- * 'action' => 'query',
- * 'meta' => 'siteinfo
- * ),
- * 'type' => 'api' // or 'index' for index.php
- * ),
- * 'class' => 'wikibase-link item' // string
- * );
- *
- * @throws \MWException
+ * @param string $page
*
* @return string
*/
- public function repoLink( $target, $text, $attribs = array() ) {
- if ( array_key_exists( 'query', $attribs ) && is_array(
$attribs['query'] ) ) {
- if ( $attribs['query']['type'] === 'index' ) {
- $url = $this->baseUrl() . $this->scriptPath .
'/index.php';
- } else if ( $attribs['query']['type'] === 'api' ) {
- $url = $this->baseUrl() . $this->scriptPath .
'/api.php';
- } else {
- throw new \MWException( 'Invalid query type' );
- }
- $url = wfAppendQuery( $url, wfArrayToCgi(
$attribs['query']['params'] ) );
- unset( $attribs['query'] );
- } else {
- // should not happen, but just in case...
- if ( !is_string( $target ) ) {
- throw new \MWException( 'repoLink requires a
$target to contruct an article url.' );
- }
- $url = $this->repoArticleUrl( $target );
+ public function getPageUrl( $page ) {
+ if ( !is_string( $page ) ) {
+ throw new InvalidArgumentException( '$page must be a
string' );
}
- if ( $url === null ) {
- throw new \MWException( 'Could not build a repoLink
url.' );
- }
+ $encodedPage = $this->encodePage( $page );
+ return $this->getBaseUrl() . str_replace( '$1', $encodedPage,
$this->articlePath );
+ }
- $class = 'plainlinks';
- // @todo more validation and maybe accept array instead
- if ( array_key_exists( 'class', $attribs ) ) {
- $class .= ' ' . $attribs['class'];
- }
+ /**
+ * Encode a page title
+ *
+ * @since 0.4
+ *
+ * @param string $page
+ *
+ * @return string
+ */
+ protected function encodePage( $page ) {
+ return wfUrlencode( str_replace( ' ', '_', $page ) );
+ }
- $attribs['class'] = $class;
+ /**
+ * @since 0.3
+ *
+ * @param string $url
+ * @param string $text
+ * @param array $attribs
+ *
+ * @return string
+ */
+ public function formatLink( $url, $text, $attribs = array() ) {
+ $attribs['class'] = isset( $attribs['class'] ) ?
+ 'plainlinks ' . $attribs['class'] : 'plainlinks';
+
$attribs['href'] = $url;
- return \Html::element( 'a', $attribs, $text );
+ return Html::element( 'a', $attribs, $text );
+ }
+
+ /**
+ * @since 0.4
+ *
+ * @param ExternalChange $externalChange
+ *
+ * @return string
+ */
+ public function buildEntityLink( EntityId $entityId ) {
+ $prefixedId = $entityId->getPrefixedId();
+
+ return $this->formatLink(
+ $this->getEntityUrl( $entityId ),
+ $prefixedId,
+ array( 'class' => 'wb-entity-link' )
+ );
+ }
+
+ /**
+ * @param EntityId
+ *
+ * @return string
+ */
+ public function getEntityUrl( EntityId $entityId ) {
+ $prefixedId = $entityId->getPrefixedId();
+
+ return $this->getPageUrl( $prefixedId );
+ }
+
+ public function getBaseUrl() {
+ return rtrim( $this->baseUrl, '/' );
+ }
+
+ /**
+ * @return string;
+ */
+ public function getApiUrl() {
+ return $this->getBaseUrl() . $this->scriptPath . '/api.php';
+ }
+
+ /**
+ * @return string
+ */
+ public function getIndexUrl() {
+ return $this->getBaseUrl() . $this->scriptPath . '/index.php';
+ }
+
+ /**
+ * @param array $params
+ *
+ * @return string
+ */
+ public function addQueryParams( $url, array $params ) {
+ return wfAppendQuery( $url, wfArrayToCgi( $params ) );
}
}
diff --git a/client/includes/hooks/MovePageNotice.php
b/client/includes/hooks/MovePageNotice.php
index dae5864..ebc3020 100644
--- a/client/includes/hooks/MovePageNotice.php
+++ b/client/includes/hooks/MovePageNotice.php
@@ -3,7 +3,6 @@
namespace Wikibase\Client;
use Html;
-use OutputPage;
use Title;
use Wikibase\SiteLinkLookup;
use Wikibase\RepoLinker;
@@ -67,13 +66,12 @@
return null;
}
- return $this->repoLinker->repoItemUrl( $entityId );
+ return $this->repoLinker->getEntityUrl( $entityId );
}
/**
* Append the appropriate content to the page
*
- * @param OutputPage $output
* @param Title $oldTitle Title of the page before the move
* @param Title $newTitle Title of the page after the move
*/
@@ -99,10 +97,10 @@
}
protected function getPageMoveMessage( Title $newTitle ) {
- if ( isset( $newTitle->wikibasePushedMoveToRepo ) && (
$newTitle->wikibasePushedMoveToRepo === true ) ) {
- // We're going to update the item using the repo job queue \o/
+ if ( isset( $newTitle->wikibasePushedMoveToRepo ) ) {
+ // We're going to update the item using the repo job
queue \o/
return 'wikibase-after-page-move-queued';
- }
+ }
// The user has to update the item per hand for some reason
return 'wikibase-after-page-move';
diff --git a/client/includes/recentchanges/ExternalChangesLine.php
b/client/includes/recentchanges/ExternalChangesLine.php
index 988d5f5..f7dc0e4 100644
--- a/client/includes/recentchanges/ExternalChangesLine.php
+++ b/client/includes/recentchanges/ExternalChangesLine.php
@@ -2,7 +2,8 @@
namespace Wikibase;
-use \Wikibase\Client\WikibaseClient;
+use Wikibase\Client\WikibaseClient;
+use Wikibase\DataModel\Entity\BasicEntityIdParser;
/**
* @todo remove static stuff and refactor
@@ -76,7 +77,11 @@
if ( in_array( $changeType, array( 'remove', 'restore' ) ) ) {
$repoLinker =
WikibaseClient::getDefaultInstance()->newRepoLinker();
- $deletionLog = $repoLinker->repoLink(
'Special:Log/delete', wfMessage( 'dellogpage' )->text() );
+ $deletionLog = $repoLinker->formatLink(
+ $repoLinker->getPageUrl( 'Special:Log/delete' ),
+ wfMessage( 'dellogpage' )->text()
+ );
+
$line .= wfMessage( 'parentheses' )->rawParams(
$deletionLog );
} else if ( in_array( $changeType, array( 'add', 'update' ) ) )
{
@@ -106,11 +111,16 @@
$line .= \Linker::link( $title );
if ( in_array( $changeType, array( 'add', 'restore', 'update' )
) ) {
- $entityLink = self::entityLink( $entityData );
- if ( $entityLink !== false ) {
- $line .= wfMessage( 'word-separator' )->plain()
- . wfMessage( 'parentheses' )->rawParams(
self::entityLink( $entityData ) )->text();
+ $entityIdParser = new BasicEntityIdParser();
+
+ try {
+ $entityId = $entityIdParser->parse(
$entityData['object_id'] );
+ } catch ( \Exception $e ) {
+ // bail... (for now)
+ return false;
}
+
+ $line .= self::entityLink( $entityId );
}
$line .= self::getTimestamp( $cl, $rc );
@@ -175,7 +185,7 @@
*/
public static function getComment( $entityData ) {
//TODO: If $entityData['changes'] is set, this is a coalesced
change.
- // Combine all the comments! Up to some max length?
+ // Combine all the comments! Up to some max length?
if ( array_key_exists( 'composite-comment', $entityData ) ) {
$commentText = wfMessage( 'wikibase-comment-multi'
)->numParams( count( $entityData['composite-comment'] ) )->text();
} else if ( array_key_exists( 'comment', $entityData ) ) {
@@ -208,21 +218,21 @@
protected static function diffLink( $titleText, $entityData, $rc ) {
$repoLinker =
WikibaseClient::getDefaultInstance()->newRepoLinker();
- return $repoLinker->repoLink(
- null,
+ $params = array(
+ 'title' => $titleText,
+ 'curid' => $entityData['page_id'],
+ 'diff' => $entityData['rev_id'],
+ 'oldid' => $entityData['parent_id']
+ );
+
+ $url = $repoLinker->addQueryParams( $repoLinker->getIndexUrl(),
$params );
+
+ return $repoLinker->formatLink(
+ $url,
wfMessage( 'diff' )->text(),
array(
'class' => 'plainlinks',
- 'tabindex' => $rc->counter,
- 'query' => array(
- 'type' => 'index',
- 'params' => array(
- 'title' => $titleText,
- 'curid' =>
$entityData['page_id'],
- 'diff' => $entityData['rev_id'],
- 'oldid' =>
$entityData['parent_id']
- )
- )
+ 'tabindex' => $rc->counter
)
);
}
@@ -238,22 +248,21 @@
protected static function historyLink( $titleText, $entityData ) {
$repoLinker =
WikibaseClient::getDefaultInstance()->newRepoLinker();
- $link = $repoLinker->repoLink(
- null,
+ $params = array(
+ 'title' => $titleText,
+ 'curid' => $entityData['page_id'],
+ 'action' => 'history'
+ );
+
+ $url = $repoLinker->addQueryParams( $repoLinker->getIndexUrl(),
$params );
+
+ return $repoLinker->formatLink(
+ $url,
wfMessage( 'hist' )->text(),
array(
- 'class' => 'plainlinks',
- 'query' => array(
- 'type' => 'index',
- 'params' => array(
- 'title' => $titleText,
- 'curid' =>
$entityData['page_id'],
- 'action' => 'history'
- )
- )
+ 'class' => 'plainlinks'
)
);
- return $link;
}
/**
@@ -285,12 +294,14 @@
protected static function userLink( $userName ) {
$repoLinker =
WikibaseClient::getDefaultInstance()->newRepoLinker();
- // @todo: localise this once namespaces are localised on the
repo
- $link = "User:$userName";
- $attribs = array(
- 'class' => 'mw-userlink'
+ return $repoLinker->formatLink(
+ // @todo: localise this once namespaces are localised
on the repo
+ $repoLinker->getPageUrl( "User:$userName" ),
+ $userName,
+ array(
+ 'class' => 'mw-userlink'
+ )
);
- return $repoLinker->repoLink( $link, $userName, $attribs );
}
/**
@@ -304,14 +315,15 @@
protected static function userContribsLink( $userName, $text = null ) {
// @todo: know how the repo is localised. it's english now
// for namespaces and special pages
- $link = "Special:Contributions/$userName";
+ $repoLinker =
WikibaseClient::getDefaultInstance()->newRepoLinker();
+
+ $link = $repoLinker->getPageUrl(
"Special:Contributions/$userName" );
+
if ( $text === null ) {
$text = wfMessage( 'contribslink' );
}
- $repoLinker =
WikibaseClient::getDefaultInstance()->newRepoLinker();
-
- return $repoLinker->repoLink( $link, $text );
+ return $repoLinker->formatLink( $link, $text );
}
/**
@@ -325,9 +337,10 @@
$repoLinker =
WikibaseClient::getDefaultInstance()->newRepoLinker();
// @todo: localize this once we can localize namespaces on the
repo
- $link = "User_talk:$userName";
+ $link = $repoLinker->getPageUrl( "User_talk:$userName" );
$text = wfMessage( 'talkpagelinktext' )->text();
- return $repoLinker->repoLink( $link, $text );
+
+ return $repoLinker->formatLink( $link, $text );
}
/**
@@ -361,21 +374,16 @@
/**
* @since 0.2
*
- * @param array $entityData
+ * @param EntityId $entityId
*
* @return string
*/
- protected static function entityLink( $entityData ) {
- $entityText = self::titleTextFromEntityData( $entityData );
- $entityId = self::titleTextFromEntityData( $entityData, false );
-
- if ( $entityText === false ) {
- return false;
- }
-
+ protected static function entityLink( EntityId $entityId ) {
$repoLinker =
WikibaseClient::getDefaultInstance()->newRepoLinker();
+ $entityLink = $repoLinker->buildEntityLink( $entityId );
- return $repoLinker->repoLink( $entityText, $entityId, array(
'class' => 'wb-entity-link' ) );
+ return wfMessage( 'word-separator' )->plain()
+ . wfMessage( 'parentheses' )->rawParams( $entityLink
)->text();
}
/**
diff --git a/client/tests/phpunit/includes/RepoItemLinkGeneratorTest.php
b/client/tests/phpunit/includes/RepoItemLinkGeneratorTest.php
index bafc72c..7c384c4 100644
--- a/client/tests/phpunit/includes/RepoItemLinkGeneratorTest.php
+++ b/client/tests/phpunit/includes/RepoItemLinkGeneratorTest.php
@@ -2,35 +2,18 @@
namespace Wikibase\Test;
-use \Wikibase\RepoItemLinkGenerator;
-use \Wikibase\RepoLinker;
-use \Wikibase\NamespaceChecker;
-use \Wikibase\Lib\EntityIdParser;
-use \ValueParsers\ParserOptions;
+use Language;
+use Title;
+use ValueParsers\ParserOptions;
+use Wikibase\Lib\EntityIdParser;
+use Wikibase\NamespaceChecker;
+use Wikibase\RepoItemLinkGenerator;
+use Wikibase\RepoLinker;
/**
- * Tests for the Wikibase\RepoItemLinkGenerator class.
+ * @covers Wikibase\RepoItemLinkGenerator
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
- * @file
* @since 0.4
- *
- * @ingroup WikibaseClient
- * @ingroup Test
*
* @group WikibaseClient
* @group RepoItemLinkGenerator
@@ -41,11 +24,6 @@
class RepoItemLinkGeneratorTest extends \MediaWikiTestCase {
/**
- * @var RepoLinker
- */
- protected $repoLinker;
-
- /**
* @var NamespaceChecker
*/
protected $namespaceChecker;
@@ -53,7 +31,7 @@
protected function setUp() {
parent::setUp();
$this->setMwGlobals( array(
- 'wgLang' => \Language::factory( 'en' )
+ 'wgLang' => Language::factory( 'en' )
) );
}
@@ -74,14 +52,12 @@
}
protected function getEntityIdParser() {
- return new EntityIdParser( new \ValueParsers\ParserOptions() );
+ return new EntityIdParser( new ParserOptions() );
}
public function getLinksProvider() {
- $repoLinker = $this->getRepoLinker();
-
$prefixedId = 'q9000';
- $href = $repoLinker->repoArticleUrl( strtoupper( $prefixedId )
) . '#sitelinks-wikipedia';
+ $href = 'http://www.example.com/wiki/Q9000#sitelinks-wikipedia';
$addLinksLink = array(
'text' => '',
@@ -96,8 +72,8 @@
'class' => 'wbc-editpage'
);
- $title = \Title::newFromText( 'Tokyo', NS_MAIN );
- $nonExistingTitle = \Title::newFromText( 'pfuwdodx2', NS_MAIN );
+ $title = Title::newFromText( 'Tokyo', NS_MAIN );
+ $nonExistingTitle = Title::newFromText( 'pfuwdodx2', NS_MAIN );
$title->resetArticleID( 9638 );
@@ -123,7 +99,13 @@
$namespaceChecker = $this->getNamespaceChecker();
$entityIdParser = $this->getEntityIdParser();
- $repoItemLinkGenerator = new RepoItemLinkGenerator(
$namespaceChecker, $repoLinker, $entityIdParser, true, 'wikipedia' );
+ $repoItemLinkGenerator = new RepoItemLinkGenerator(
+ $namespaceChecker,
+ $repoLinker,
+ $entityIdParser,
+ true,
+ 'wikipedia'
+ );
$link = $repoItemLinkGenerator->getLink(
$title, $action, $isAnon, $noExternalLangLinks,
$prefixedId
diff --git a/client/tests/phpunit/includes/RepoLinkerTest.php
b/client/tests/phpunit/includes/RepoLinkerTest.php
index 9d1e1a6..d61b208 100644
--- a/client/tests/phpunit/includes/RepoLinkerTest.php
+++ b/client/tests/phpunit/includes/RepoLinkerTest.php
@@ -6,28 +6,9 @@
use Wikibase\Item;
/**
- * Tests for the Wikibase\RepoLinker class.
+ * @covers Wikibase\RepoLinker
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
- * @file
* @since 0.4
- *
- * @ingroup WikibaseClient
- * @ingroup Test
*
* @group WikibaseClient
* @group RepoLinkerTest
@@ -88,102 +69,6 @@
);
}
- /**
- * @dataProvider baseUrlProvider
- */
- public function testBaseUrl( $expected, array $settings ) {
- $repoLinker = new RepoLinker(
- $settings['baseUrl'],
- $settings['articlePath'],
- $settings['scriptPath'],
- $settings['repoNamespaces']
- );
-
- $baseUrl = $repoLinker->baseUrl();
- $this->assertEquals( $expected, $baseUrl );
- }
-
- public function repoArticleUrlProvider() {
- $settings = $this->getRepoSettings();
-
- return array(
- array(
- '//www.example.com/wiki/Rome',
- $settings[0],
- 'Rome'
- ),
- array(
- '//example.com/wiki/Rome',
- $settings[1],
- 'Rome'
- ),
- array(
- '//www.example.com/wiki/Hall_%26_Oates',
- $settings[0],
- 'Hall & Oates'
- ),
- array(
- 'http://www.example.com/wiki/Why%3F_(film)',
- $settings[2],
- 'Why? (film)'
- )
- );
- }
-
- /**
- * @dataProvider repoArticleUrlProvider
- */
- public function testRepoArticleUrl( $expected, array $settings, $page
) {
- $repoLinker = new RepoLinker(
- $settings['baseUrl'],
- $settings['articlePath'],
- $settings['scriptPath'],
- $settings['repoNamespaces']
- );
-
- $repoUrl = $repoLinker->repoArticleUrl( $page );
-
- $this->assertEquals( $expected, $repoUrl );
- }
-
- public function repoItemUrlProvider() {
- $settings = $this->getRepoSettings();
-
- return array(
- array(
- '//www.example.com/wiki/Q4',
- $settings[0],
- new EntityId( Item::ENTITY_TYPE, 4 )
- ),
- array(
- '//example.com/wiki/Q100',
- $settings[1],
- new EntityId( Item::ENTITY_TYPE, 100 )
- ),
- array(
- 'http://www.example.com/wiki/Item:Q100',
- $settings[2],
- new EntityId( Item::ENTITY_TYPE, 100 )
- )
- );
- }
-
- /**
- * @dataProvider repoItemUrlProvider
- */
- public function testRepoItemUrl( $expected, array $settings, EntityId
$entityId ) {
- $repoLinker = new RepoLinker(
- $settings['baseUrl'],
- $settings['articlePath'],
- $settings['scriptPath'],
- $settings['repoNamespaces']
- );
-
- $itemUrl = $repoLinker->repoItemUrl( $entityId );
-
- $this->assertEquals( $expected, $itemUrl );
- }
-
public function namespaceProvider() {
$settings = $this->getRepoSettings();
@@ -220,71 +105,6 @@
$namespace = $repoLinker->getNamespace( $entityType );
$this->assertEquals( $expected, $namespace );
- }
-
- public function repoLinkProvider() {
- $settings = $this->getRepoSettings();
-
- return array(
- array(
- '<a class="plainlinks"
href="//www.example.com/api.php?action=query&meta=siteinfo">api query</a>',
- $settings[0],
- array(
- 'target' => null,
- 'text' => 'api query',
- 'params' => array(
- 'query' => array(
- 'params' => array(
- 'action' =>
'query',
- 'meta' =>
'siteinfo'
- ),
- 'type' => 'api'
- )
- )
- )
- ),
- array(
- '<a class="plainlinks"
href="//example.com/index.php?title=Rome">Roma</a>',
- $settings[1],
- array(
- 'target' => 'Rome',
- 'text' => 'Roma',
- 'params' => array(
- 'query' => array(
- 'params' => array(
- 'title' =>
'Rome'
- ),
- 'type' => 'index'
- )
- )
- )
- ),
- array(
- '<a class="plainlinks"
href="http://www.example.com/wiki/Rome">Rome</a>',
- $settings[2],
- array(
- 'target' => 'Rome',
- 'text' => 'Rome',
- 'params' => array()
- )
- )
- );
- }
-
- /**
- * @dataProvider repoLinkProvider
- */
- public function testRepoLink( $expected, $settings, $params ) {
- $repoLinker = new RepoLinker(
- $settings['baseUrl'],
- $settings['articlePath'],
- $settings['scriptPath'],
- $settings['repoNamespaces']
- );
-
- $repoLink = $repoLinker->repoLink( $params['target'],
$params['text'], $params['params'] );
-
- $this->assertEquals( $expected, $repoLink );
}
}
--
To view, visit https://gerrit.wikimedia.org/r/91601
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Id302c4b8dcc8204bb164122a8fee5191ebf1f178
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Aude <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits