r92012 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92011‎ | r92012 | r92013 >
Date:21:58, 12 July 2011
Author:aaron
Status:resolved (Comments)
Tags:
Comment:
* Made (un)watch action show a form if the token is bad/missing (this handles unwatch links given in emails)
* Changed misleading watch/unwatch subtitle msgs
Modified paths:
  • /trunk/phase3/includes/actions/WatchAction.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)
  • /trunk/phase3/maintenance/language/messages.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/language/messages.inc
@@ -1799,9 +1799,9 @@
18001800 'watchlistanontext',
18011801 'watchnologin',
18021802 'watchnologintext',
1803 - 'addedwatch',
 1803+ 'addwatch',
18041804 'addedwatchtext',
1805 - 'removedwatch',
 1805+ 'removewatch',
18061806 'removedwatchtext',
18071807 'watch',
18081808 'watchthispage',
@@ -3246,6 +3246,9 @@
32473247 'lag-warn-normal',
32483248 'lag-warn-high',
32493249 ),
 3250+ 'watch' => array(
 3251+ 'confirm-watch-button',
 3252+ ),
32503253 'watchlisteditor' => array(
32513254 'watchlistedit-numitems',
32523255 'watchlistedit-noitems',
@@ -3450,6 +3453,9 @@
34513454 'sqlite-has-fts',
34523455 'sqlite-no-fts',
34533456 ),
 3457+ 'unwatch' => array(
 3458+ 'confirm-unwatch-button',
 3459+ ),
34543460 );
34553461
34563462 /** Comments for each block */
Index: trunk/phase3/includes/actions/WatchAction.php
@@ -20,7 +20,7 @@
2121 * @ingroup Actions
2222 */
2323
24 -class WatchAction extends FormlessAction {
 24+class WatchAction extends FormAction {
2525
2626 public function getName() {
2727 return 'watch';
@@ -35,35 +35,56 @@
3636 }
3737
3838 protected function getDescription() {
39 - return wfMsg( 'addedwatch' );
 39+ return wfMsg( 'addwatch' );
4040 }
4141
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+ }
4349
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+ }
4856
 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+
4968 // Must have valid token for this action/title
5069 $salt = array( $this->getName(), $this->getTitle()->getDBkey() );
5170
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+ }
5479 }
55 -
56 - return parent::checkCanExecute( $user );
5780 }
5881
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+ }
6187
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 );
6889 }
6990
7091 public static function doWatch( Title $title, User $user ) {
@@ -119,6 +140,17 @@
120141 return self::getWatchToken( $title, $user, $action );
121142 }
122143
 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+ }
123155 }
124156
125157 class UnwatchAction extends WatchAction {
@@ -128,17 +160,25 @@
129161 }
130162
131163 protected function getDescription() {
132 - return wfMsg( 'removedwatch' );
 164+ return wfMsg( 'removewatch' );
133165 }
134166
135 - public function onView() {
 167+ public function onSubmit( $data ) {
136168 wfProfileIn( __METHOD__ );
 169+ self::doUnwatch( $this->getTitle(), $this->getUser() );
 170+ wfProfileOut( __METHOD__ );
 171+ return true;
 172+ }
137173
138 - $user = $this->getUser();
139 - self::doUnwatch( $this->getTitle(), $user );
 174+ protected function alterForm( HTMLForm $form ) {
 175+ $form->setSubmitText( wfMsg( 'confirm-unwatch-button' ) );
 176+ }
140177
141 - wfProfileOut( __METHOD__ );
 178+ protected function preText() {
 179+ return wfMessage( 'confirm-unwatch-top' )->parse();
 180+ }
142181
143 - return wfMessage( 'removedwatchtext', $this->getTitle()->getPrefixedText() )->parse();
 182+ public function onSuccess() {
 183+ $this->getOutput()->addWikiMsg( 'removedwatchtext', $this->getTitle()->getPrefixedText() );
144184 }
145185 }
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -2707,10 +2707,10 @@
27082708 'watchlistanontext' => 'Please $1 to view or edit items on your watchlist.',
27092709 'watchnologin' => 'Not logged in',
27102710 'watchnologintext' => 'You must be [[Special:UserLogin|logged in]] to modify your watchlist.',
2711 -'addedwatch' => 'Added to watchlist',
 2711+'addwatch' => 'Add to watchlist',
27122712 'addedwatchtext' => "The page \"[[:\$1]]\" has been added to your [[Special:Watchlist|watchlist]].
27132713 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',
27152715 'removedwatchtext' => 'The page "[[:$1]]" has been removed from [[Special:Watchlist|your watchlist]].',
27162716 'watch' => 'Watch',
27172717 'watchthispage' => 'Watch this page',
@@ -4284,6 +4284,14 @@
42854285 'confirm-purge-top' => 'Clear the cache of this page?',
42864286 'confirm-purge-bottom' => 'Purging a page clears the cache and forces the most current revision to appear.',
42874287
 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+
42884296 # Separators for various lists, etc.
42894297 'catseparator' => '|', # only translate this message to other languages if you have to change it
42904298 'semicolon-separator' => '; ', # only translate this message to other languages if you have to change it

Follow-up revisions

RevisionCommit summaryAuthorDate
r92014Fixed r92012 commentaaron22:04, 12 July 2011
r92061Followup r92012: Fix grammar, update meintenance scriptsraymond13:28, 13 July 2011

Comments

#Comment by Krinkle (talk | contribs)   22:02, 12 July 2011

+	/**
+	 * purge is slightly weird because it can be either formed or formless depending
+	 * on user permissions
+	 */

Purge is very weird ;-)

#Comment by Jack Phoenix (talk | contribs)   22:04, 12 July 2011
 	),
+    'watch' => array(
+        'confirm-watch-button',
+    ),
 	'watchlisteditor' => array(
 		'watchlistedit-numitems',
 		'watchlistedit-noitems',
@@ -3450,6 +3453,9 @@
 		'sqlite-has-fts',
 		'sqlite-no-fts',
 	),
+    'unwatch' => array(
+        'confirm-unwatch-button',
+    ),
 );

Should use tabs instead of spaces for indentation.

Status & tagging log