wiki.techinc.nl/includes/actions/WatchAction.php
Happy-melon 08d460d384 Follow-up r 86041 per CR and IRC:
* Article constructor needs to be called with zero as second parameter
* Run stylize.php over new files
* Add Action::getLang() for consistency with other context accessors
* Fix declaration of FormAction::alterForm(), doesn't need to be passed by reference
* Fix inline use of Credits::getCredits() in SkinTemplate and SkinLegacy
2011-04-14 12:17:24 +00:00

86 lines
2.2 KiB
PHP

<?php
/**
* Performs the watch and unwatch actions on a page
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
* @file
* @ingroup Actions
*/
class WatchAction extends FormlessAction {
public function getName() {
return 'watch';
}
public function getRestriction() {
return 'read';
}
public function requiresUnblock() {
return false;
}
protected function getDescription() {
return wfMsg( 'addedwatch' );
}
protected function checkCanExecute( User $user ) {
if ( $user->isAnon() ) {
throw new ErrorPageError( 'watchnologin', 'watchnologintext' );
}
return parent::checkCanExecute( $user );
}
public function onView() {
wfProfileIn( __METHOD__ );
$user = $this->getUser();
if ( wfRunHooks( 'WatchArticle', array( &$user, &$this->page ) ) ) {
$this->getUser()->addWatch( $this->getTitle() );
wfRunHooks( 'WatchArticleComplete', array( &$user, &$this->page ) );
}
wfProfileOut( __METHOD__ );
return wfMessage( 'addedwatchtext', $this->getTitle()->getPrefixedText() )->parse();
}
}
class UnwatchAction extends WatchAction {
public function getName() {
return 'unwatch';
}
protected function getDescription() {
return wfMsg( 'removedwatch' );
}
public function onView() {
wfProfileIn( __METHOD__ );
$user = $this->getUser();
if ( wfRunHooks( 'UnwatchArticle', array( &$user, &$this->page ) ) ) {
$this->getUser()->removeWatch( $this->getTitle() );
wfRunHooks( 'UnwatchArticleComplete', array( &$user, &$this->page ) );
}
wfProfileOut( __METHOD__ );
return wfMessage( 'removedwatchtext', $this->getTitle()->getPrefixedText() )->parse();
}
}