Wikia code/includes/WatchlistEditor.php

From mediawiki.org
--- D:\Programming\SVN\mediawiki\branches\REL1_16\phase3\includes\WatchlistEditor.php	2011-07-18 22:31:28.095703100 +0100
+++ D:\Programming\SVN\wikia\trunk\includes\WatchlistEditor.php	2011-08-17 15:28:46.459960900 +0100
@@ -255,6 +255,8 @@
 	private function clearWatchlist( $user ) {
 		$dbw = wfGetDB( DB_MASTER );
 		$dbw->delete( 'watchlist', array( 'wl_user' => $user->getId() ), __METHOD__ );
+		
+		wfRunHooks( 'WatchlistEditor::clearWatchlist', array ( $user ) );		
 	}
 
 	/**
@@ -273,21 +275,11 @@
 			if( !$title instanceof Title )
 				$title = Title::newFromText( $title );
 			if( $title instanceof Title ) {
-				$rows[] = array(
-					'wl_user' => $user->getId(),
-					'wl_namespace' => ( $title->getNamespace() & ~1 ),
-					'wl_title' => $title->getDBkey(),
-					'wl_notificationtimestamp' => null,
-				);
-				$rows[] = array(
-					'wl_user' => $user->getId(),
-					'wl_namespace' => ( $title->getNamespace() | 1 ),
-					'wl_title' => $title->getDBkey(),
-					'wl_notificationtimestamp' => null,
-				);
+				$wl = WatchedItem::fromUserTitle( $user, $title );
+				$wl->addWatch();
+				unset($wl);		
 			}
 		}
-		$dbw->insert( 'watchlist', $rows, __METHOD__, 'IGNORE' );
 	}
 
 	/**
@@ -302,32 +294,19 @@
 	private function unwatchTitles( $titles, $user ) {
 		$dbw = wfGetDB( DB_MASTER );
 		foreach( $titles as $title ) {
-			if( !$title instanceof Title )
+			if ( !$title instanceof Title ) {
 				$title = Title::newFromText( $title );
+			}
+			
 			if( $title instanceof Title ) {
-				$dbw->delete(
-					'watchlist',
-					array(
-						'wl_user' => $user->getId(),
-						'wl_namespace' => ( $title->getNamespace() & ~1 ),
-						'wl_title' => $title->getDBkey(),
-					),
-					__METHOD__
-				);
-				$dbw->delete(
-					'watchlist',
-					array(
-						'wl_user' => $user->getId(),
-						'wl_namespace' => ( $title->getNamespace() | 1 ),
-						'wl_title' => $title->getDBkey(),
-					),
-					__METHOD__
-				);
 				$article = new Article($title);
+				if ( wfRunHooks( 'UnwatchArticle', array( &$user, &$article ) ) ) {
+					$user->removeWatch( $title );
 				wfRunHooks('UnwatchArticleComplete',array(&$user,&$article));
 			}
 		}
 	}
+	}
 
 	/**
 	 * Show the standard watchlist editing form