jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/396299 )
Change subject: Remove WatchedItem constants and methods deprecated in REL1_27
......................................................................
Remove WatchedItem constants and methods deprecated in REL1_27
Remove associated tests
Bug: T182381
Change-Id: I0214250a7cb81518074a14e35590370b13d4ba64
---
M RELEASE-NOTES-1.31
M includes/watcheditem/WatchedItem.php
D tests/phpunit/includes/watcheditem/WatchedItemIntegrationTest.php
D tests/phpunit/includes/watcheditem/WatchedItemUnitTest.php
4 files changed, 13 insertions(+), 412 deletions(-)
Approvals:
Legoktm: Looks good to me, approved
jenkins-bot: Verified
diff --git a/RELEASE-NOTES-1.31 b/RELEASE-NOTES-1.31
index 4a2876d..1a1a9f7 100644
--- a/RELEASE-NOTES-1.31
+++ b/RELEASE-NOTES-1.31
@@ -135,6 +135,17 @@
* OutputPage::enableSectionEditLinks()
* OutputPage::sectionEditLinksEnabled()
* The public ParserOutput state fields $mTOCEnabled and $mEditSectionTokens
are also deprecated.
+* The following methods and constants from the WatchedItem class were
deprecated in
+ 1.27 have been removed.
+ * WatchedItem::getTitle()
+ * WatchedItem::fromUserTitle()
+ * WatchedItem::addWatch()
+ * WatchedItem::removeWatch()
+ * WatchedItem::isWatched()
+ * WatchedItem::duplicateEntries()
+ * WatchedItem::IGNORE_USER_RIGHTS
+ * WatchedItem::CHECK_USER_RIGHTS
+ * WatchedItem::DEPRECATED_USAGE_TIMESTAMP
== Compatibility ==
MediaWiki 1.31 requires PHP 5.5.9 or later. There is experimental support for
diff --git a/includes/watcheditem/WatchedItem.php
b/includes/watcheditem/WatchedItem.php
index bfd1d61..43a9c4e 100644
--- a/includes/watcheditem/WatchedItem.php
+++ b/includes/watcheditem/WatchedItem.php
@@ -18,7 +18,7 @@
* @file
* @ingroup Watchlist
*/
-use MediaWiki\MediaWikiServices;
+
use MediaWiki\Linker\LinkTarget;
/**
@@ -30,34 +30,6 @@
* @ingroup Watchlist
*/
class WatchedItem {
-
- /**
- * @deprecated since 1.27, see User::IGNORE_USER_RIGHTS
- */
- const IGNORE_USER_RIGHTS = User::IGNORE_USER_RIGHTS;
-
- /**
- * @deprecated since 1.27, see User::CHECK_USER_RIGHTS
- */
- const CHECK_USER_RIGHTS = User::CHECK_USER_RIGHTS;
-
- /**
- * @deprecated Internal class use only
- */
- const DEPRECATED_USAGE_TIMESTAMP = -100;
-
- /**
- * @var bool
- * @deprecated Internal class use only
- */
- public $checkRights = User::CHECK_USER_RIGHTS;
-
- /**
- * @var Title
- * @deprecated Internal class use only
- */
- private $title;
-
/**
* @var LinkTarget
*/
@@ -77,20 +49,15 @@
* @param User $user
* @param LinkTarget $linkTarget
* @param null|string $notificationTimestamp the value of the
wl_notificationtimestamp field
- * @param bool|null $checkRights DO NOT USE - used internally for
backward compatibility
*/
public function __construct(
User $user,
LinkTarget $linkTarget,
- $notificationTimestamp,
- $checkRights = null
+ $notificationTimestamp
) {
$this->user = $user;
$this->linkTarget = $linkTarget;
$this->notificationTimestamp = $notificationTimestamp;
- if ( $checkRights !== null ) {
- $this->checkRights = $checkRights;
- }
}
/**
@@ -113,88 +80,6 @@
* @return bool|null|string
*/
public function getNotificationTimestamp() {
- // Back compat for objects constructed using self::fromUserTitle
- if ( $this->notificationTimestamp ===
self::DEPRECATED_USAGE_TIMESTAMP ) {
- // wfDeprecated( __METHOD__, '1.27' );
- if ( $this->checkRights && !$this->user->isAllowed(
'viewmywatchlist' ) ) {
- return false;
- }
- $item =
MediaWikiServices::getInstance()->getWatchedItemStore()
- ->loadWatchedItem( $this->user,
$this->linkTarget );
- if ( $item ) {
- $this->notificationTimestamp =
$item->getNotificationTimestamp();
- } else {
- $this->notificationTimestamp = false;
- }
- }
return $this->notificationTimestamp;
}
-
- /**
- * Back compat pre 1.27 with the WatchedItemStore introduction
- * @todo remove in 1.28/9
- * -------------------------------------------------
- */
-
- /**
- * @return Title
- * @deprecated Internal class use only
- */
- public function getTitle() {
- if ( !$this->title ) {
- $this->title = Title::newFromLinkTarget(
$this->linkTarget );
- }
- return $this->title;
- }
-
- /**
- * @deprecated since 1.27 Use the constructor,
WatchedItemStore::getWatchedItem()
- * or WatchedItemStore::loadWatchedItem()
- */
- public static function fromUserTitle( $user, $title, $checkRights =
User::CHECK_USER_RIGHTS ) {
- wfDeprecated( __METHOD__, '1.27' );
- return new self( $user, $title,
self::DEPRECATED_USAGE_TIMESTAMP, (bool)$checkRights );
- }
-
- /**
- * @deprecated since 1.27 Use User::addWatch()
- * @return bool
- */
- public function addWatch() {
- wfDeprecated( __METHOD__, '1.27' );
- $this->user->addWatch( $this->getTitle(), $this->checkRights );
- return true;
- }
-
- /**
- * @deprecated since 1.27 Use User::removeWatch()
- * @return bool
- */
- public function removeWatch() {
- wfDeprecated( __METHOD__, '1.27' );
- if ( $this->checkRights && !$this->user->isAllowed(
'editmywatchlist' ) ) {
- return false;
- }
- $this->user->removeWatch( $this->getTitle(), $this->checkRights
);
- return true;
- }
-
- /**
- * @deprecated since 1.27 Use User::isWatched()
- * @return bool
- */
- public function isWatched() {
- wfDeprecated( __METHOD__, '1.27' );
- return $this->user->isWatched( $this->getTitle(),
$this->checkRights );
- }
-
- /**
- * @deprecated since 1.27 Use
WatchedItemStore::duplicateAllAssociatedEntries()
- */
- public static function duplicateEntries( Title $oldTitle, Title
$newTitle ) {
- wfDeprecated( __METHOD__, '1.27' );
- $store =
MediaWikiServices::getInstance()->getWatchedItemStore();
- $store->duplicateAllAssociatedEntries( $oldTitle, $newTitle );
- }
-
}
diff --git a/tests/phpunit/includes/watcheditem/WatchedItemIntegrationTest.php
b/tests/phpunit/includes/watcheditem/WatchedItemIntegrationTest.php
deleted file mode 100644
index 01e7ecb..0000000
--- a/tests/phpunit/includes/watcheditem/WatchedItemIntegrationTest.php
+++ /dev/null
@@ -1,145 +0,0 @@
-<?php
-use MediaWiki\MediaWikiServices;
-
-/**
- * @author Addshore
- *
- * @group Database
- *
- * @covers WatchedItem
- */
-class WatchedItemIntegrationTest extends MediaWikiTestCase {
-
- public function setUp() {
- parent::setUp();
- self::$users['WatchedItemIntegrationTestUser']
- = new TestUser( 'WatchedItemIntegrationTestUser' );
-
- $this->hideDeprecated( 'WatchedItem::fromUserTitle' );
- $this->hideDeprecated( 'WatchedItem::addWatch' );
- $this->hideDeprecated( 'WatchedItem::removeWatch' );
- $this->hideDeprecated( 'WatchedItem::isWatched' );
- $this->hideDeprecated( 'WatchedItem::duplicateEntries' );
- $this->hideDeprecated( 'WatchedItem::batchAddWatch' );
- }
-
- private function getUser() {
- return
self::$users['WatchedItemIntegrationTestUser']->getUser();
- }
-
- public function testWatchAndUnWatchItem() {
- $user = $this->getUser();
- $title = Title::newFromText( 'WatchedItemIntegrationTestPage' );
- // Cleanup after previous tests
- WatchedItem::fromUserTitle( $user, $title )->removeWatch();
-
- $this->assertFalse(
- WatchedItem::fromUserTitle( $user, $title
)->isWatched(),
- 'Page should not initially be watched'
- );
- WatchedItem::fromUserTitle( $user, $title )->addWatch();
- $this->assertTrue(
- WatchedItem::fromUserTitle( $user, $title
)->isWatched(),
- 'Page should be watched'
- );
- WatchedItem::fromUserTitle( $user, $title )->removeWatch();
- $this->assertFalse(
- WatchedItem::fromUserTitle( $user, $title
)->isWatched(),
- 'Page should be unwatched'
- );
- }
-
- public function testUpdateAndResetNotificationTimestamp() {
- $user = $this->getUser();
- $otherUser = ( new TestUser(
'WatchedItemIntegrationTestUser_otherUser' ) )->getUser();
- $title = Title::newFromText( 'WatchedItemIntegrationTestPage' );
- WatchedItem::fromUserTitle( $user, $title )->addWatch();
- $this->assertNull( WatchedItem::fromUserTitle( $user, $title
)->getNotificationTimestamp() );
-
- EmailNotification::updateWatchlistTimestamp( $otherUser,
$title, '20150202010101' );
- $this->assertEquals(
- '20150202010101',
- WatchedItem::fromUserTitle( $user, $title
)->getNotificationTimestamp()
- );
-
-
MediaWikiServices::getInstance()->getWatchedItemStore()->resetNotificationTimestamp(
- $user, $title
- );
- $this->assertNull( WatchedItem::fromUserTitle( $user, $title
)->getNotificationTimestamp() );
- }
-
- public function testDuplicateAllAssociatedEntries() {
- $user = $this->getUser();
- $titleOld = Title::newFromText(
'WatchedItemIntegrationTestPageOld' );
- $titleNew = Title::newFromText(
'WatchedItemIntegrationTestPageNew' );
- WatchedItem::fromUserTitle( $user, $titleOld->getSubjectPage()
)->addWatch();
- WatchedItem::fromUserTitle( $user, $titleOld->getTalkPage()
)->addWatch();
- // Cleanup after previous tests
- WatchedItem::fromUserTitle( $user, $titleNew->getSubjectPage()
)->removeWatch();
- WatchedItem::fromUserTitle( $user, $titleNew->getTalkPage()
)->removeWatch();
-
- WatchedItem::duplicateEntries( $titleOld, $titleNew );
-
- $this->assertTrue(
- WatchedItem::fromUserTitle( $user,
$titleOld->getSubjectPage() )->isWatched()
- );
- $this->assertTrue(
- WatchedItem::fromUserTitle( $user,
$titleOld->getTalkPage() )->isWatched()
- );
- $this->assertTrue(
- WatchedItem::fromUserTitle( $user,
$titleNew->getSubjectPage() )->isWatched()
- );
- $this->assertTrue(
- WatchedItem::fromUserTitle( $user,
$titleNew->getTalkPage() )->isWatched()
- );
- }
-
- public function testIsWatched_falseOnNotAllowed() {
- $user = $this->getUser();
- $title = Title::newFromText( 'WatchedItemIntegrationTestPage' );
- WatchedItem::fromUserTitle( $user, $title )->addWatch();
-
- $this->assertTrue( WatchedItem::fromUserTitle( $user, $title
)->isWatched() );
- $user->mRights = [];
- $this->assertFalse( WatchedItem::fromUserTitle( $user, $title
)->isWatched() );
- }
-
- public function testGetNotificationTimestamp_falseOnNotAllowed() {
- $user = $this->getUser();
- $title = Title::newFromText( 'WatchedItemIntegrationTestPage' );
- WatchedItem::fromUserTitle( $user, $title )->addWatch();
-
MediaWikiServices::getInstance()->getWatchedItemStore()->resetNotificationTimestamp(
- $user, $title
- );
-
- $this->assertEquals(
- null,
- WatchedItem::fromUserTitle( $user, $title
)->getNotificationTimestamp()
- );
- $user->mRights = [];
- $this->assertFalse( WatchedItem::fromUserTitle( $user, $title
)->getNotificationTimestamp() );
- }
-
- public function testRemoveWatch_falseOnNotAllowed() {
- $user = $this->getUser();
- $title = Title::newFromText( 'WatchedItemIntegrationTestPage' );
- WatchedItem::fromUserTitle( $user, $title )->addWatch();
-
- $previousRights = $user->mRights;
- $user->mRights = [];
- $this->assertFalse( WatchedItem::fromUserTitle( $user, $title
)->removeWatch() );
- $user->mRights = $previousRights;
- $this->assertTrue( WatchedItem::fromUserTitle( $user, $title
)->removeWatch() );
- }
-
- public function testGetNotificationTimestamp_falseOnNotWatched() {
- $user = $this->getUser();
- $title = Title::newFromText( 'WatchedItemIntegrationTestPage' );
-
- WatchedItem::fromUserTitle( $user, $title )->removeWatch();
- $this->assertFalse( WatchedItem::fromUserTitle( $user, $title
)->isWatched() );
-
- $this->assertFalse( WatchedItem::fromUserTitle( $user, $title
)->getNotificationTimestamp() );
- }
-
-}
diff --git a/tests/phpunit/includes/watcheditem/WatchedItemUnitTest.php
b/tests/phpunit/includes/watcheditem/WatchedItemUnitTest.php
deleted file mode 100644
index 8897645..0000000
--- a/tests/phpunit/includes/watcheditem/WatchedItemUnitTest.php
+++ /dev/null
@@ -1,150 +0,0 @@
-<?php
-use MediaWiki\Linker\LinkTarget;
-
-/**
- * @author Addshore
- *
- * @covers WatchedItem
- */
-class WatchedItemUnitTest extends MediaWikiTestCase {
-
- /**
- * @param int $id
- *
- * @return PHPUnit_Framework_MockObject_MockObject|User
- */
- private function getMockUser( $id ) {
- $user = $this->createMock( User::class );
- $user->expects( $this->any() )
- ->method( 'getId' )
- ->will( $this->returnValue( $id ) );
- $user->expects( $this->any() )
- ->method( 'isAllowed' )
- ->will( $this->returnValue( true ) );
- return $user;
- }
-
- public function provideUserTitleTimestamp() {
- $user = $this->getMockUser( 111 );
- return [
- [ $user, Title::newFromText( 'SomeTitle' ), null ],
- [ $user, Title::newFromText( 'SomeTitle' ),
'20150101010101' ],
- [ $user, new TitleValue( 0, 'TVTitle', 'frag' ),
'20150101010101' ],
- ];
- }
-
- /**
- * @return PHPUnit_Framework_MockObject_MockObject|WatchedItemStore
- */
- private function getMockWatchedItemStore() {
- return $this->getMockBuilder( WatchedItemStore::class )
- ->disableOriginalConstructor()
- ->getMock();
- }
-
- /**
- * @dataProvider provideUserTitleTimestamp
- */
- public function testConstruction( $user, LinkTarget $linkTarget,
$notifTimestamp ) {
- $item = new WatchedItem( $user, $linkTarget, $notifTimestamp );
-
- $this->assertSame( $user, $item->getUser() );
- $this->assertSame( $linkTarget, $item->getLinkTarget() );
- $this->assertSame( $notifTimestamp,
$item->getNotificationTimestamp() );
-
- // The below tests the internal WatchedItem::getTitle method
- $this->assertInstanceOf( 'Title', $item->getTitle() );
- $this->assertSame( $linkTarget->getDBkey(),
$item->getTitle()->getDBkey() );
- $this->assertSame( $linkTarget->getFragment(),
$item->getTitle()->getFragment() );
- $this->assertSame( $linkTarget->getNamespace(),
$item->getTitle()->getNamespace() );
- $this->assertSame( $linkTarget->getText(),
$item->getTitle()->getText() );
- }
-
- /**
- * @dataProvider provideUserTitleTimestamp
- */
- public function testFromUserTitle( $user, $linkTarget, $timestamp ) {
- $store = $this->getMockWatchedItemStore();
- $store->expects( $this->once() )
- ->method( 'loadWatchedItem' )
- ->with( $user, $linkTarget )
- ->will( $this->returnValue( new WatchedItem( $user,
$linkTarget, $timestamp ) ) );
- $this->setService( 'WatchedItemStore', $store );
-
- $item = WatchedItem::fromUserTitle( $user, $linkTarget,
User::IGNORE_USER_RIGHTS );
-
- $this->assertEquals( $user, $item->getUser() );
- $this->assertEquals( $linkTarget, $item->getLinkTarget() );
- $this->assertEquals( $timestamp,
$item->getNotificationTimestamp() );
- }
-
- public function testAddWatch() {
- $title = Title::newFromText( 'SomeTitle' );
- $timestamp = null;
- $checkRights = 0;
-
- /** @var User|PHPUnit_Framework_MockObject_MockObject $user */
- $user = $this->createMock( User::class );
- $user->expects( $this->once() )
- ->method( 'addWatch' )
- ->with( $title, $checkRights );
-
- $item = new WatchedItem( $user, $title, $timestamp,
$checkRights );
- $this->assertTrue( $item->addWatch() );
- }
-
- public function testRemoveWatch() {
- $title = Title::newFromText( 'SomeTitle' );
- $timestamp = null;
- $checkRights = 0;
-
- /** @var User|PHPUnit_Framework_MockObject_MockObject $user */
- $user = $this->createMock( User::class );
- $user->expects( $this->once() )
- ->method( 'removeWatch' )
- ->with( $title, $checkRights );
-
- $item = new WatchedItem( $user, $title, $timestamp,
$checkRights );
- $this->assertTrue( $item->removeWatch() );
- }
-
- public function provideBooleans() {
- return [
- [ true ],
- [ false ],
- ];
- }
-
- /**
- * @dataProvider provideBooleans
- */
- public function testIsWatched( $returnValue ) {
- $title = Title::newFromText( 'SomeTitle' );
- $timestamp = null;
- $checkRights = 0;
-
- /** @var User|PHPUnit_Framework_MockObject_MockObject $user */
- $user = $this->createMock( User::class );
- $user->expects( $this->once() )
- ->method( 'isWatched' )
- ->with( $title, $checkRights )
- ->will( $this->returnValue( $returnValue ) );
-
- $item = new WatchedItem( $user, $title, $timestamp,
$checkRights );
- $this->assertEquals( $returnValue, $item->isWatched() );
- }
-
- public function testDuplicateEntries() {
- $oldTitle = Title::newFromText( 'OldTitle' );
- $newTitle = Title::newFromText( 'NewTitle' );
-
- $store = $this->getMockWatchedItemStore();
- $store->expects( $this->once() )
- ->method( 'duplicateAllAssociatedEntries' )
- ->with( $oldTitle, $newTitle );
- $this->setService( 'WatchedItemStore', $store );
-
- WatchedItem::duplicateEntries( $oldTitle, $newTitle );
- }
-
-}
--
To view, visit https://gerrit.wikimedia.org/r/396299
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I0214250a7cb81518074a14e35590370b13d4ba64
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Reedy <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Reedy <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits