Legoktm has uploaded a new change for review. https://gerrit.wikimedia.org/r/284416
Change subject: Add LinkTarget::createFragmentTarget() function ...................................................................... Add LinkTarget::createFragmentTarget() function The createFragmentTarget function allows for switching the fragment on a target in an easier way. TitleValue already had a now-renamed createFragmentTitle function (no uses outside of tests), and an implementation was added for Title. This will also help with reducing the amount of public usage of Title::setFragment(), which is deprecated. Change-Id: I1e8ba2f85e748b1b4394fb2f2a1ccce69cf6e3c5 --- M includes/LinkTarget.php M includes/Title.php M includes/title/TitleValue.php M tests/phpunit/includes/title/TitleValueTest.php 4 files changed, 30 insertions(+), 2 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/16/284416/1 diff --git a/includes/LinkTarget.php b/includes/LinkTarget.php index 8246f7d..b7132a8 100644 --- a/includes/LinkTarget.php +++ b/includes/LinkTarget.php @@ -44,4 +44,14 @@ */ public function getText(); + /** + * Creates a new LinkTarget for a different fragment of the same page. + * It is expected that the same type of object will be returned, but the + * only requirement is that it is a LinkTarget. + * + * @param string $fragment The fragment name, or "" for the entire page. + * + * @return LinkTarget + */ + public function createFragmentTarget( $fragment ); } diff --git a/includes/Title.php b/includes/Title.php index 3fd4631..06195b3 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -1387,6 +1387,23 @@ } /** + * Creates a new TitleValue for a different fragment of the same page. + * Interwiki is intentionally not copied over. + * + * @since 1.27 + * @param string $fragment + * @return Title + */ + public function createFragmentTarget( $fragment ) { + return self::makeTitle( + $this->getNamespace(), + $this->getText(), + $fragment + ); + + } + + /** * Prefix some arbitrary text with the namespace or interwiki prefix * of this object * diff --git a/includes/title/TitleValue.php b/includes/title/TitleValue.php index 18a06ea..a0a7b1d 100644 --- a/includes/title/TitleValue.php +++ b/includes/title/TitleValue.php @@ -131,11 +131,12 @@ /** * Creates a new TitleValue for a different fragment of the same page. * + * @since 1.27 * @param string $fragment The fragment name, or "" for the entire page. * * @return TitleValue */ - public function createFragmentTitle( $fragment ) { + public function createFragmentTarget( $fragment ) { return new TitleValue( $this->namespace, $this->dbkey, $fragment ); } diff --git a/tests/phpunit/includes/title/TitleValueTest.php b/tests/phpunit/includes/title/TitleValueTest.php index af7b758..117722c 100644 --- a/tests/phpunit/includes/title/TitleValueTest.php +++ b/tests/phpunit/includes/title/TitleValueTest.php @@ -74,7 +74,7 @@ * @dataProvider fragmentTitleProvider */ public function testCreateFragmentTitle( TitleValue $title, $fragment ) { - $fragmentTitle = $title->createFragmentTitle( $fragment ); + $fragmentTitle = $title->createFragmentTarget( $fragment ); $this->assertEquals( $title->getNamespace(), $fragmentTitle->getNamespace() ); $this->assertEquals( $title->getText(), $fragmentTitle->getText() ); -- To view, visit https://gerrit.wikimedia.org/r/284416 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I1e8ba2f85e748b1b4394fb2f2a1ccce69cf6e3c5 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Legoktm <legoktm.wikipe...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits