case self::EDIT_RAW:
$output->setPageTitle( wfMsg( 'watchlistedit-raw-title' ) );
if( $request->wasPosted() && $this->checkToken( $request, $user ) ) {
- $titles = $this->extractTitles( $request->getText( 'titles' ) );
- $this->clearWatchlist( $user );
- $this->watchTitles( $titles, $user );
+ $current = $this->getWatchlist( $user );
+ $wanted = $this->extractTitles( $request->getText( 'titles' ) );
+ $toWatch = array_diff( $wanted, $current );
+ $toUnwatch = array_diff( $current, $wanted );
+ $this->watchTitles( $toWatch, $user );
+ $this->unwatchTitles( $toUnwatch, $user );
$user->invalidateCache();
- $output->addHtml( wfMsgExt( 'watchlistedit-raw-done', 'parse' ) );
+ if( count( $toWatch ) > 0 || count( $toUnwatch ) > 0 )
+ $output->addHtml( wfMsgExt( 'watchlistedit-raw-done', 'parse' ) );
+ if( ( $count = count( $toWatch ) ) > 0 ) {
+ $output->addHtml( wfMsgExt( 'watchlistedit-raw-added', 'parse', $count ) );
+ $this->showTitles( $toWatch, $output, $user->getSkin() );
+ }
+ if( ( $count = count( $toUnwatch ) ) > 0 ) {
+ $output->addHtml( wfMsgExt( 'watchlistedit-raw-removed', 'parse', $count ) );
+ $this->showTitles( $toUnwatch, $output, $user->getSkin() );
+ }
}
$this->showRawForm( $output, $user );
break;
/**
* Extract a list of titles from a text list; if we're given
- * an array, convert each item into a Title
+ * an array, convert each item into a Title (ignores unwatchable titles)
*
* @param mixed $list
* @return array
$text = trim( $text );
if( strlen( $text ) > 0 ) {
$title = Title::newFromText( $text );
- if( $title instanceof Title )
+ if( $title instanceof Title && $title->isWatchable() )
$titles[] = $title;
}
}
return ceil( $row->count / 2 ); // Paranoia
}
+ /**
+ * Get a list of titles on a user's watchlist, excluding talk pages
+ *
+ * @param User $user
+ * @return array
+ */
+ private function getWatchlist( $user ) {
+ $titles = array();
+ $dbr = wfGetDB( DB_SLAVE );
+ $res = $dbr->select( 'watchlist', '*', array( 'wl_user' => $user->getId() ), __METHOD__ );
+ if( $res && $dbr->numRows( $res ) > 0 ) {
+ while( $row = $dbr->fetchObject( $res ) ) {
+ $title = Title::makeTitleSafe( $row->wl_namespace, $row->wl_title );
+ if( $title instanceof Title && !$title->isTalkPage() )
+ $titles[] = $title;
+ }
+ $dbr->freeResult( $res );
+ }
+ return $titles;
+ }
+
/**
* Get a list of titles on a user's watchlist, excluding talk pages,
* and return as a two-dimensional array with namespace, title and
* @param User $user
* @return array
*/
- private function getWatchlist( $user ) {
+ private function getWatchlistInfo( $user ) {
$titles = array();
$dbr = wfGetDB( DB_SLAVE );
$uid = intval( $user->getId() );
$form .= Xml::hidden( 'token', $user->editToken( 'watchlistedit' ) );
$form .= '<fieldset><legend>' . wfMsgHtml( 'watchlistedit-normal-legend' ) . '</legend>';
$form .= wfMsgExt( 'watchlistedit-normal-explain', 'parse' );
- foreach( $this->getWatchlist( $user ) as $namespace => $pages ) {
+ foreach( $this->getWatchlistInfo( $user ) as $namespace => $pages ) {
$form .= '<h2>' . $this->getNamespaceHeading( $namespace ) . '</h2>';
$form .= '<ul>';
foreach( $pages as $dbkey => $redirect ) {
$form .= Xml::label( wfMsg( 'watchlistedit-raw-titles' ), 'titles' );
$form .= Xml::openElement( 'textarea', array( 'id' => 'titles', 'name' => 'titles',
'rows' => 6, 'cols' => 80 ) );
- foreach( $this->getWatchlist( $user ) as $namespace => $pages ) {
- foreach( $pages as $dbkey => $redirect ) {
- $title = Title::makeTitleSafe( $namespace, $dbkey );
- if( $title instanceof Title )
- $form .= htmlspecialchars( $title->getPrefixedText() ) . "\n";
- }
- }
+ foreach( $this->getWatchlist( $user ) as $title )
+ $form .= htmlspecialchars( $title->getPrefixedText() ) . "\n";
$form .= '</textarea>';
$form .= '<p>' . Xml::submitButton( wfMsg( 'watchlistedit-raw-submit' ) ) . '</p>';
$form .= '</fieldset></form>';