Index: trunk/phase3/maintenance/language/messages.inc |
— | — | @@ -1799,9 +1799,9 @@ |
1800 | 1800 | 'watchlistanontext', |
1801 | 1801 | 'watchnologin', |
1802 | 1802 | 'watchnologintext', |
1803 | | - 'addedwatch', |
| 1803 | + 'addwatch', |
1804 | 1804 | 'addedwatchtext', |
1805 | | - 'removedwatch', |
| 1805 | + 'removewatch', |
1806 | 1806 | 'removedwatchtext', |
1807 | 1807 | 'watch', |
1808 | 1808 | 'watchthispage', |
— | — | @@ -3246,6 +3246,9 @@ |
3247 | 3247 | 'lag-warn-normal', |
3248 | 3248 | 'lag-warn-high', |
3249 | 3249 | ), |
| 3250 | + 'watch' => array( |
| 3251 | + 'confirm-watch-button', |
| 3252 | + ), |
3250 | 3253 | 'watchlisteditor' => array( |
3251 | 3254 | 'watchlistedit-numitems', |
3252 | 3255 | 'watchlistedit-noitems', |
— | — | @@ -3450,6 +3453,9 @@ |
3451 | 3454 | 'sqlite-has-fts', |
3452 | 3455 | 'sqlite-no-fts', |
3453 | 3456 | ), |
| 3457 | + 'unwatch' => array( |
| 3458 | + 'confirm-unwatch-button', |
| 3459 | + ), |
3454 | 3460 | ); |
3455 | 3461 | |
3456 | 3462 | /** Comments for each block */ |
Index: trunk/phase3/includes/actions/WatchAction.php |
— | — | @@ -20,7 +20,7 @@ |
21 | 21 | * @ingroup Actions |
22 | 22 | */ |
23 | 23 | |
24 | | -class WatchAction extends FormlessAction { |
| 24 | +class WatchAction extends FormAction { |
25 | 25 | |
26 | 26 | public function getName() { |
27 | 27 | return 'watch'; |
— | — | @@ -35,35 +35,56 @@ |
36 | 36 | } |
37 | 37 | |
38 | 38 | protected function getDescription() { |
39 | | - return wfMsg( 'addedwatch' ); |
| 39 | + return wfMsg( 'addwatch' ); |
40 | 40 | } |
41 | 41 | |
42 | | - protected function checkCanExecute( User $user ) { |
| 42 | + /** |
| 43 | + * Just get an empty form with a single submit button |
| 44 | + * @return array |
| 45 | + */ |
| 46 | + protected function getFormFields() { |
| 47 | + return array(); |
| 48 | + } |
43 | 49 | |
44 | | - // Must be logged in |
45 | | - if ( $user->isAnon() ) { |
46 | | - throw new ErrorPageError( 'watchnologin', 'watchnologintext' ); |
47 | | - } |
| 50 | + public function onSubmit( $data ) { |
| 51 | + wfProfileIn( __METHOD__ ); |
| 52 | + self::doWatch( $this->getTitle(), $this->getUser() ); |
| 53 | + wfProfileOut( __METHOD__ ); |
| 54 | + return true; |
| 55 | + } |
48 | 56 | |
| 57 | + /** |
| 58 | + * purge is slightly weird because it can be either formed or formless depending |
| 59 | + * on user permissions |
| 60 | + */ |
| 61 | + public function show() { |
| 62 | + $this->setHeaders(); |
| 63 | + |
| 64 | + $user = $this->getUser(); |
| 65 | + // This will throw exceptions if there's a problem |
| 66 | + $this->checkCanExecute( $user ); |
| 67 | + |
49 | 68 | // Must have valid token for this action/title |
50 | 69 | $salt = array( $this->getName(), $this->getTitle()->getDBkey() ); |
51 | 70 | |
52 | | - if ( !$user->matchEditToken( $this->getRequest()->getVal( 'token' ), $salt ) ) { |
53 | | - throw new ErrorPageError( 'sessionfailure-title', 'sessionfailure' ); |
| 71 | + if ( $user->matchEditToken( $this->getRequest()->getVal( 'token' ), $salt ) ) { |
| 72 | + $this->onSubmit( array() ); |
| 73 | + $this->onSuccess(); |
| 74 | + } else { |
| 75 | + $form = $this->getForm(); |
| 76 | + if ( $form->show() ) { |
| 77 | + $this->onSuccess(); |
| 78 | + } |
54 | 79 | } |
55 | | - |
56 | | - return parent::checkCanExecute( $user ); |
57 | 80 | } |
58 | 81 | |
59 | | - public function onView() { |
60 | | - wfProfileIn( __METHOD__ ); |
| 82 | + protected function checkCanExecute( User $user ) { |
| 83 | + // Must be logged in |
| 84 | + if ( $user->isAnon() ) { |
| 85 | + throw new ErrorPageError( 'watchnologin', 'watchnologintext' ); |
| 86 | + } |
61 | 87 | |
62 | | - $user = $this->getUser(); |
63 | | - self::doWatch( $this->getTitle(), $user ); |
64 | | - |
65 | | - wfProfileOut( __METHOD__ ); |
66 | | - |
67 | | - return wfMessage( 'addedwatchtext', $this->getTitle()->getPrefixedText() )->parse(); |
| 88 | + return parent::checkCanExecute( $user ); |
68 | 89 | } |
69 | 90 | |
70 | 91 | public static function doWatch( Title $title, User $user ) { |
— | — | @@ -119,6 +140,17 @@ |
120 | 141 | return self::getWatchToken( $title, $user, $action ); |
121 | 142 | } |
122 | 143 | |
| 144 | + protected function alterForm( HTMLForm $form ) { |
| 145 | + $form->setSubmitText( wfMsg( 'confirm-watch-button' ) ); |
| 146 | + } |
| 147 | + |
| 148 | + protected function preText() { |
| 149 | + return wfMessage( 'confirm-watch-top' )->parse(); |
| 150 | + } |
| 151 | + |
| 152 | + public function onSuccess() { |
| 153 | + $this->getOutput()->addWikiMsg( 'addedwatchtext', $this->getTitle()->getPrefixedText() ); |
| 154 | + } |
123 | 155 | } |
124 | 156 | |
125 | 157 | class UnwatchAction extends WatchAction { |
— | — | @@ -128,17 +160,25 @@ |
129 | 161 | } |
130 | 162 | |
131 | 163 | protected function getDescription() { |
132 | | - return wfMsg( 'removedwatch' ); |
| 164 | + return wfMsg( 'removewatch' ); |
133 | 165 | } |
134 | 166 | |
135 | | - public function onView() { |
| 167 | + public function onSubmit( $data ) { |
136 | 168 | wfProfileIn( __METHOD__ ); |
| 169 | + self::doUnwatch( $this->getTitle(), $this->getUser() ); |
| 170 | + wfProfileOut( __METHOD__ ); |
| 171 | + return true; |
| 172 | + } |
137 | 173 | |
138 | | - $user = $this->getUser(); |
139 | | - self::doUnwatch( $this->getTitle(), $user ); |
| 174 | + protected function alterForm( HTMLForm $form ) { |
| 175 | + $form->setSubmitText( wfMsg( 'confirm-unwatch-button' ) ); |
| 176 | + } |
140 | 177 | |
141 | | - wfProfileOut( __METHOD__ ); |
| 178 | + protected function preText() { |
| 179 | + return wfMessage( 'confirm-unwatch-top' )->parse(); |
| 180 | + } |
142 | 181 | |
143 | | - return wfMessage( 'removedwatchtext', $this->getTitle()->getPrefixedText() )->parse(); |
| 182 | + public function onSuccess() { |
| 183 | + $this->getOutput()->addWikiMsg( 'removedwatchtext', $this->getTitle()->getPrefixedText() ); |
144 | 184 | } |
145 | 185 | } |
Index: trunk/phase3/languages/messages/MessagesEn.php |
— | — | @@ -2707,10 +2707,10 @@ |
2708 | 2708 | 'watchlistanontext' => 'Please $1 to view or edit items on your watchlist.', |
2709 | 2709 | 'watchnologin' => 'Not logged in', |
2710 | 2710 | 'watchnologintext' => 'You must be [[Special:UserLogin|logged in]] to modify your watchlist.', |
2711 | | -'addedwatch' => 'Added to watchlist', |
| 2711 | +'addwatch' => 'Add to watchlist', |
2712 | 2712 | 'addedwatchtext' => "The page \"[[:\$1]]\" has been added to your [[Special:Watchlist|watchlist]]. |
2713 | 2713 | Future changes to this page and its associated talk page will be listed there, and the page will appear '''bolded''' in the [[Special:RecentChanges|list of recent changes]] to make it easier to pick out.", |
2714 | | -'removedwatch' => 'Removed from watchlist', |
| 2714 | +'removewatch' => 'Remove from watchlist', |
2715 | 2715 | 'removedwatchtext' => 'The page "[[:$1]]" has been removed from [[Special:Watchlist|your watchlist]].', |
2716 | 2716 | 'watch' => 'Watch', |
2717 | 2717 | 'watchthispage' => 'Watch this page', |
— | — | @@ -4284,6 +4284,14 @@ |
4285 | 4285 | 'confirm-purge-top' => 'Clear the cache of this page?', |
4286 | 4286 | 'confirm-purge-bottom' => 'Purging a page clears the cache and forces the most current revision to appear.', |
4287 | 4287 | |
| 4288 | +# action=watch |
| 4289 | +'confirm-watch-button' => 'OK', |
| 4290 | +'confirm-watch-top' => 'Add this page to your watchlist?', |
| 4291 | + |
| 4292 | +# action=unwatch |
| 4293 | +'confirm-unwatch-button' => 'OK', |
| 4294 | +'confirm-unwatch-top' => 'Remove this page to your watchlist?', |
| 4295 | + |
4288 | 4296 | # Separators for various lists, etc. |
4289 | 4297 | 'catseparator' => '|', # only translate this message to other languages if you have to change it |
4290 | 4298 | 'semicolon-separator' => '; ', # only translate this message to other languages if you have to change it |