From 637322f5face9b033117fed7484cbc1423b8e288 Mon Sep 17 00:00:00 2001 From: Rob Church Date: Mon, 9 Jul 2007 11:08:32 +0000 Subject: [PATCH] Let's be a little bit clever here; faster code path for the case where users just blank the text box and submit to clear...skip all that pointless diffing and so forth --- includes/WatchlistEditor.php | 37 +++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/includes/WatchlistEditor.php b/includes/WatchlistEditor.php index caad4c479c..fe20f364f9 100644 --- a/includes/WatchlistEditor.php +++ b/includes/WatchlistEditor.php @@ -44,22 +44,29 @@ class WatchlistEditor { case self::EDIT_RAW: $output->setPageTitle( wfMsg( 'watchlistedit-raw-title' ) ); if( $request->wasPosted() && $this->checkToken( $request, $wgUser ) ) { - $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(); - 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, $wgUser->getSkin() ); - } - if( ( $count = count( $toUnwatch ) ) > 0 ) { - $output->addHtml( wfMsgExt( 'watchlistedit-raw-removed', 'parse', $count ) ); - $this->showTitles( $toUnwatch, $output, $wgUser->getSkin() ); + $current = $this->getWatchlist( $user ); + if( count( $wanted ) > 0 ) { + $toWatch = array_diff( $wanted, $current ); + $toUnwatch = array_diff( $current, $wanted ); + $this->watchTitles( $toWatch, $user ); + $this->unwatchTitles( $toUnwatch, $user ); + $user->invalidateCache(); + 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, $wgUser->getSkin() ); + } + if( ( $count = count( $toUnwatch ) ) > 0 ) { + $output->addHtml( wfMsgExt( 'watchlistedit-raw-removed', 'parse', $count ) ); + $this->showTitles( $toUnwatch, $output, $wgUser->getSkin() ); + } + } else { + $this->clearWatchlist( $user ); + $user->invalidateCache(); + $output->addHtml( wfMsgExt( 'watchlistedit-raw-removed', 'parse', count( $current ) ) ); + $this->showTitles( $current, $output, $wgUser->getSkin() ); } } $this->showRawForm( $output, $user ); -- 2.20.1