private function getWatchlist() {
$list = [];
- $index = $this->getRequest()->wasPosted() ? DB_MASTER : DB_SLAVE;
- $dbr = wfGetDB( $index );
-
- $res = $dbr->select(
- 'watchlist',
- [
- 'wl_namespace', 'wl_title'
- ], [
- 'wl_user' => $this->getUser()->getId(),
- ],
- __METHOD__
+ $watchedItems = WatchedItemStore::getDefaultInstance()->getWatchedItemsForUser(
+ $this->getUser(),
+ [ 'forWrite' => $this->getRequest()->wasPosted() ]
);
- if ( $res->numRows() > 0 ) {
+ if ( $watchedItems ) {
/** @var Title[] $titles */
$titles = [];
- foreach ( $res as $row ) {
- $title = Title::makeTitleSafe( $row->wl_namespace, $row->wl_title );
+ foreach ( $watchedItems as $watchedItem ) {
+ $namespace = $watchedItem->getLinkTarget()->getNamespace();
+ $dbKey = $watchedItem->getLinkTarget()->getDBkey();
+ $title = Title::makeTitleSafe( $namespace, $dbKey );
- if ( $this->checkTitle( $title, $row->wl_namespace, $row->wl_title )
+ if ( $this->checkTitle( $title, $namespace, $dbKey )
&& !$title->isTalkPage()
) {
$titles[] = $title;
}
}
- $res->free();
GenderCache::singleton()->doTitlesArray( $titles );
return; // nothing to do
}
- $dbw = wfGetDB( DB_MASTER );
$user = $this->getUser();
+ $store = WatchedItemStore::getDefaultInstance();
foreach ( $this->badItems as $row ) {
list( $title, $namespace, $dbKey ) = $row;
$action = $title ? 'cleaning up' : 'deleting';
wfDebug( "User {$user->getName()} has broken watchlist item ns($namespace):$dbKey, $action.\n" );
- $dbw->delete( 'watchlist',
- [
- 'wl_user' => $user->getId(),
- 'wl_namespace' => $namespace,
- 'wl_title' => $dbKey,
- ],
- __METHOD__
- );
+ $store->removeWatch( $user, new TitleValue( $namespace, $dbKey ) );
// Can't just do an UPDATE instead of DELETE/INSERT due to unique index
if ( $title ) {
* @param array $titles Array of strings, or Title objects
*/
private function unwatchTitles( $titles ) {
- $dbw = wfGetDB( DB_MASTER );
+ $store = WatchedItemStore::getDefaultInstance();
foreach ( $titles as $title ) {
if ( !$title instanceof Title ) {
}
if ( $title instanceof Title ) {
- $dbw->delete(
- 'watchlist',
- [
- 'wl_user' => $this->getUser()->getId(),
- 'wl_namespace' => MWNamespace::getSubject( $title->getNamespace() ),
- 'wl_title' => $title->getDBkey(),
- ],
- __METHOD__
- );
-
- $dbw->delete(
- 'watchlist',
- [
- 'wl_user' => $this->getUser()->getId(),
- 'wl_namespace' => MWNamespace::getTalk( $title->getNamespace() ),
- 'wl_title' => $title->getDBkey(),
- ],
- __METHOD__
- );
+ $store->removeWatch( $this->getUser(), $title->getSubjectPage() );
+ $store->removeWatch( $this->getUser(), $title->getTalkPage() );
$page = WikiPage::factory( $title );
Hooks::run( 'UnwatchArticleComplete', [ $this->getUser(), &$page ] );