+ wfProfileOut( __METHOD__ );
+ 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() );
+ }
+
+ /**
+ * Handle duplicate entries. Backend for duplicateEntries().
+ *
+ * @param $ot Title
+ * @param $nt Title
+ *
+ * @return bool
+ */
+ private static function doDuplicateEntries( $ot, $nt ) {
+ $oldnamespace = $ot->getNamespace();
+ $newnamespace = $nt->getNamespace();
+ $oldtitle = $ot->getDBkey();
+ $newtitle = $nt->getDBkey();
+
+ $dbw = wfGetDB( DB_MASTER );
+ $res = $dbw->select( 'watchlist', 'wl_user',
+ array( 'wl_namespace' => $oldnamespace, 'wl_title' => $oldtitle ),
+ __METHOD__, 'FOR UPDATE'
+ );
+ # Construct array to replace into the watchlist
+ $values = array();
+ foreach ( $res as $s ) {
+ $values[] = array(
+ 'wl_user' => $s->wl_user,
+ 'wl_namespace' => $newnamespace,
+ 'wl_title' => $newtitle
+ );
+ }
+
+ if( empty( $values ) ) {
+ // Nothing to do
+ return true;
+ }
+
+ # Perform replace
+ # Note that multi-row replace is very efficient for MySQL but may be inefficient for
+ # some other DBMSes, mostly due to poor simulation by us
+ $dbw->replace( 'watchlist', array( array( 'wl_user', 'wl_namespace', 'wl_title' ) ), $values, __METHOD__ );
+ return true;
+ }
+}