- function removeWatch()
- {
- $sql = "DELETE FROM watchlist WHERE wl_user=$this->id AND wl_namespace=$this->ns AND wl_title='$this->eti' LIMIT 1";
- $res = wfQuery( $sql, DB_WRITE );
- if( $res === false ) return false;
-
- global $wgMemc;
- $wgMemc->set( $this->watchkey(), 0 );
- return true;
+ /**
+ * Same as addWatch, only the opposite.
+ * @return bool
+ */
+ public function removeWatch() {
+ $success = false;
+ $dbw = wfGetDB( DB_MASTER );
+ $dbw->delete( 'watchlist',
+ array(
+ 'wl_user' => $this->id,
+ 'wl_namespace' => MWNamespace::getSubject($this->ns),
+ 'wl_title' => $this->ti
+ ), __METHOD__
+ );
+ if ( $dbw->affectedRows() ) {
+ $success = true;
+ }
+
+ # the following code compensates the new behaviour, introduced by the
+ # enotif patch, that every single watched page needs now to be listed
+ # in watchlist namespace:page and namespace_talk:page had separate
+ # entries: clear them
+ $dbw->delete( 'watchlist',
+ array(
+ 'wl_user' => $this->id,
+ 'wl_namespace' => MWNamespace::getTalk($this->ns),
+ 'wl_title' => $this->ti
+ ), __METHOD__
+ );
+
+ if ( $dbw->affectedRows() ) {
+ $success = true;
+ }
+ return $success;
+ }
+
+ /**
+ * Check if the given title already is watched by the user, and if so
+ * add watches on a new title. To be used for page renames and such.
+ *
+ * @param $ot Title: page title to duplicate entries from, if present
+ * @param $nt Title: page title to add watches on
+ */
+ public static function duplicateEntries( $ot, $nt ) {
+ WatchedItem::doDuplicateEntries( $ot->getSubjectPage(), $nt->getSubjectPage() );
+ WatchedItem::doDuplicateEntries( $ot->getTalkPage(), $nt->getTalkPage() );