From 4ac9fa081a7c045f6a9f1cfc529d82423f485b2e Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sun, 8 Dec 2013 09:55:49 +0100 Subject: Update to MediaWiki 1.22.0 --- includes/actions/CreditsAction.php | 15 +++++---- includes/actions/EditAction.php | 14 ++------ includes/actions/HistoryAction.php | 51 +++++++++++++--------------- includes/actions/InfoAction.php | 69 +++++++++++++++++++++++++++----------- includes/actions/PurgeAction.php | 4 +-- includes/actions/RawAction.php | 29 ++++++++-------- includes/actions/WatchAction.php | 62 ++++++++++++++++++++++++++++++---- 7 files changed, 155 insertions(+), 89 deletions(-) (limited to 'includes/actions') diff --git a/includes/actions/CreditsAction.php b/includes/actions/CreditsAction.php index 4d3c41be..0a2bf306 100644 --- a/includes/actions/CreditsAction.php +++ b/includes/actions/CreditsAction.php @@ -79,17 +79,17 @@ class CreditsAction extends FormlessAction { /** * Get the last author with the last modification time - * @param $article Article object + * @param Page $page * @return String HTML */ - protected function getAuthor( Page $article ) { - $user = User::newFromName( $article->getUserText(), false ); + protected function getAuthor( Page $page ) { + $user = User::newFromName( $page->getUserText(), false ); - $timestamp = $article->getTimestamp(); + $timestamp = $page->getTimestamp(); if ( $timestamp ) { $lang = $this->getLanguage(); - $d = $lang->date( $article->getTimestamp(), true ); - $t = $lang->time( $article->getTimestamp(), true ); + $d = $lang->date( $page->getTimestamp(), true ); + $t = $lang->time( $page->getTimestamp(), true ); } else { $d = ''; $t = ''; @@ -114,9 +114,10 @@ class CreditsAction extends FormlessAction { # Hmm... too many to fit! if ( $cnt > 0 && $contributors->count() > $cnt ) { $others_link = $this->othersLink(); - if ( !$showIfMax ) + if ( !$showIfMax ) { return $this->msg( 'othercontribs' )->rawParams( $others_link )->params( $contributors->count() )->escaped(); + } } $real_names = array(); diff --git a/includes/actions/EditAction.php b/includes/actions/EditAction.php index dec3d841..3dd4c483 100644 --- a/includes/actions/EditAction.php +++ b/includes/actions/EditAction.php @@ -43,21 +43,11 @@ class EditAction extends FormlessAction { public function show() { $page = $this->page; - $request = $this->getRequest(); $user = $this->getUser(); - $context = $this->getContext(); if ( wfRunHooks( 'CustomEditor', array( $page, $user ) ) ) { - if ( ExternalEdit::useExternalEngine( $context, 'edit' ) - && $this->getName() == 'edit' && !$request->getVal( 'section' ) - && !$request->getVal( 'oldid' ) ) - { - $extedit = new ExternalEdit( $context ); - $extedit->execute(); - } else { - $editor = new EditPage( $page ); - $editor->edit(); - } + $editor = new EditPage( $page ); + $editor->edit(); } } diff --git a/includes/actions/HistoryAction.php b/includes/actions/HistoryAction.php index 245a5bdc..e58791ea 100644 --- a/includes/actions/HistoryAction.php +++ b/includes/actions/HistoryAction.php @@ -115,7 +115,7 @@ class HistoryAction extends FormlessAction { // Setup page variables. $out->setFeedAppendQuery( 'action=history' ); - $out->addModules( array( 'mediawiki.legacy.history', 'mediawiki.action.history' ) ); + $out->addModules( 'mediawiki.action.history' ); // Handle atom/RSS feeds. $feedType = $request->getVal( 'feed' ); @@ -178,7 +178,7 @@ class HistoryAction extends FormlessAction { ) . Html::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) . "\n" . Html::hidden( 'action', 'history' ) . "\n" . - Xml::dateMenu( ( $year == null ? date( "Y" ) : $year ), $month ) . ' ' . + Xml::dateMenu( ( $year == null ? MWTimestamp::getLocalInstance()->format( 'Y' ) : $year ), $month ) . ' ' . ( $tagSelector ? ( implode( ' ', $tagSelector ) . ' ' ) : '' ) . $checkDeleted . Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ) . "\n" . @@ -211,7 +211,7 @@ class HistoryAction extends FormlessAction { */ function fetchRevisions( $limit, $offset, $direction ) { // Fail if article doesn't exist. - if( !$this->getTitle()->exists() ) { + if ( !$this->getTitle()->exists() ) { return new FakeResultWrapper( array() ); } @@ -256,15 +256,14 @@ class HistoryAction extends FormlessAction { $this->getTitle()->getPrefixedText() . ' - ' . $this->msg( 'history-feed-title' )->inContentLanguage()->text(), $this->msg( 'history-feed-description' )->inContentLanguage()->text(), - $this->getTitle()->getFullUrl( 'action=history' ) + $this->getTitle()->getFullURL( 'action=history' ) ); // Get a limit on number of feed entries. Provide a sane default // of 10 if none is defined (but limit to $wgFeedLimit max) $limit = $request->getInt( 'limit', 10 ); - if ( $limit > $wgFeedLimit || $limit < 1 ) { - $limit = 10; - } + $limit = min( max( $limit, 1 ), $wgFeedLimit ); + $items = $this->fetchRevisions( $limit, 0, HistoryPage::DIR_NEXT ); // Generate feed elements enclosed between header and footer. @@ -283,10 +282,10 @@ class HistoryAction extends FormlessAction { return new FeedItem( $this->msg( 'nohistory' )->inContentLanguage()->text(), $this->msg( 'history-feed-empty' )->inContentLanguage()->parseAsBlock(), - $this->getTitle()->getFullUrl(), + $this->getTitle()->getFullURL(), wfTimestamp( TS_MW ), '', - $this->getTitle()->getTalkPage()->getFullUrl() + $this->getTitle()->getTalkPage()->getFullURL() ); } @@ -323,10 +322,10 @@ class HistoryAction extends FormlessAction { return new FeedItem( $title, $text, - $this->getTitle()->getFullUrl( 'diff=' . $rev->getId() . '&oldid=prev' ), + $this->getTitle()->getFullURL( 'diff=' . $rev->getId() . '&oldid=prev' ), $rev->getTimestamp(), $rev->getUserText(), - $this->getTitle()->getTalkPage()->getFullUrl() + $this->getTitle()->getTalkPage()->getFullURL() ); } } @@ -367,15 +366,13 @@ class HistoryPager extends ReverseChronologicalPager { function getQueryInfo() { $queryInfo = array( - 'tables' => array( 'revision', 'user' ), - 'fields' => array_merge( Revision::selectFields(), Revision::selectUserFields() ), - 'conds' => array_merge( + 'tables' => array( 'revision', 'user' ), + 'fields' => array_merge( Revision::selectFields(), Revision::selectUserFields() ), + 'conds' => array_merge( array( 'rev_page' => $this->getWikiPage()->getId() ), $this->conds ), 'options' => array( 'USE INDEX' => array( 'revision' => 'page_timestamp' ) ), - 'join_conds' => array( - 'user' => Revision::userJoinCond(), - 'tag_summary' => array( 'LEFT JOIN', 'ts_rev_id=rev_id' ) ), + 'join_conds' => array( 'user' => Revision::userJoinCond() ), ); ChangeTags::modifyDisplayQuery( $queryInfo['tables'], @@ -413,10 +410,10 @@ class HistoryPager extends ReverseChronologicalPager { $batch = new LinkBatch(); $revIds = array(); foreach ( $this->mResult as $row ) { - if( $row->rev_parent_id ) { + if ( $row->rev_parent_id ) { $revIds[] = $row->rev_parent_id; } - if( !is_null( $row->user_name ) ) { + if ( !is_null( $row->user_name ) ) { $batch->add( NS_USER, $row->user_name ); $batch->add( NS_USER_TALK, $row->user_name ); } else { # for anons or usernames of imported revisions @@ -649,9 +646,9 @@ class HistoryPager extends ReverseChronologicalPager { $this->msg( 'editundo' )->escaped(), $undoTooltip, array( - 'action' => 'edit', + 'action' => 'edit', 'undoafter' => $prevRev->getId(), - 'undo' => $rev->getId() + 'undo' => $rev->getId() ) ); $tools[] = "{$undolink}"; @@ -661,7 +658,7 @@ class HistoryPager extends ReverseChronologicalPager { wfRunHooks( 'HistoryRevisionTools', array( $rev, &$tools ) ); if ( $tools ) { - $s2 .= ' '. $this->msg( 'parentheses' )->rawParams( $lang->pipeList( $tools ) )->escaped(); + $s2 .= ' ' . $this->msg( 'parentheses' )->rawParams( $lang->pipeList( $tools ) )->escaped(); } # Tags @@ -788,13 +785,13 @@ class HistoryPager extends ReverseChronologicalPager { function diffButtons( $rev, $firstInList ) { if ( $this->getNumRows() > 1 ) { $id = $rev->getId(); - $radio = array( 'type' => 'radio', 'value' => $id ); - /** @todo: move title texts to javascript */ + $radio = array( 'type' => 'radio', 'value' => $id ); + /** @todo Move title texts to javascript */ if ( $firstInList ) { $first = Xml::element( 'input', array_merge( $radio, array( 'style' => 'visibility:hidden', - 'name' => 'oldid', + 'name' => 'oldid', 'id' => 'mw-oldid-null' ) ) ); $checkmark = array( 'checked' => 'checked' ); @@ -811,13 +808,13 @@ class HistoryPager extends ReverseChronologicalPager { } $first = Xml::element( 'input', array_merge( $radio, $checkmark, array( - 'name' => 'oldid', + 'name' => 'oldid', 'id' => "mw-oldid-$id" ) ) ); $checkmark = array(); } $second = Xml::element( 'input', array_merge( $radio, $checkmark, array( - 'name' => 'diff', + 'name' => 'diff', 'id' => "mw-diff-$id" ) ) ); return $first . $second; } else { diff --git a/includes/actions/InfoAction.php b/includes/actions/InfoAction.php index 1e312d7a..7fc90339 100644 --- a/includes/actions/InfoAction.php +++ b/includes/actions/InfoAction.php @@ -28,6 +28,8 @@ * @ingroup Actions */ class InfoAction extends FormlessAction { + const CACHE_VERSION = '2013-03-17'; + /** * Returns the name of the action this object responds to. * @@ -55,6 +57,22 @@ class InfoAction extends FormlessAction { return false; } + /** + * Clear the info cache for a given Title. + * + * @since 1.22 + * @param Title $title Title to clear cache for + */ + public static function invalidateCache( Title $title ) { + global $wgMemc; + // Clear page info. + $revision = WikiPage::factory( $title )->getRevision(); + if ( $revision !== null ) { + $key = wfMemcKey( 'infoaction', sha1( $title->getPrefixedText() ), $revision->getId() ); + $wgMemc->delete( $key ); + } + } + /** * Shows page information on GET request. * @@ -100,12 +118,16 @@ class InfoAction extends FormlessAction { // Render page information foreach ( $pageInfo as $header => $infoTable ) { + // Messages: + // pageinfo-header-basic, pageinfo-header-edits, pageinfo-header-restrictions, + // pageinfo-header-properties, pageinfo-category-info $content .= $this->makeHeader( $this->msg( "pageinfo-${header}" )->escaped() ) . "\n"; $table = "\n"; foreach ( $infoTable as $infoRow ) { $name = ( $infoRow[0] instanceof Message ) ? $infoRow[0]->escaped() : $infoRow[0]; $value = ( $infoRow[1] instanceof Message ) ? $infoRow[1]->escaped() : $infoRow[1]; - $table = $this->addRow( $table, $name, $value ) . "\n"; + $id = ( $infoRow[0] instanceof Message ) ? $infoRow[0]->getKey() : null; + $table = $this->addRow( $table, $name, $value, $id ) . "\n"; } $content = $this->addTable( $content, $table ) . "\n"; } @@ -126,7 +148,7 @@ class InfoAction extends FormlessAction { /** * Creates a header that can be added to the output. * - * @param $header The header text. + * @param string $header The header text. * @return string The HTML. */ protected function makeHeader( $header ) { @@ -140,10 +162,11 @@ class InfoAction extends FormlessAction { * @param string $table The table that will be added to the content * @param string $name The name of the row * @param string $value The value of the row + * @param string $id The ID to use for the 'tr' element * @return string The table with the row added */ - protected function addRow( $table, $name, $value ) { - return $table . Html::rawElement( 'tr', array(), + protected function addRow( $table, $name, $value, $id ) { + return $table . Html::rawElement( 'tr', $id === null ? array() : array( 'id' => 'mw-' . $id ), Html::rawElement( 'td', array( 'style' => 'vertical-align: top;' ), $name ) . Html::rawElement( 'td', array(), $value ) ); @@ -169,18 +192,22 @@ class InfoAction extends FormlessAction { * @return array */ protected function pageInfo() { - global $wgContLang, $wgRCMaxAge, $wgMemc, $wgUnwatchedPageThreshold, $wgPageInfoTransclusionLimit; + global $wgContLang, $wgRCMaxAge, $wgMemc, + $wgUnwatchedPageThreshold, $wgPageInfoTransclusionLimit; $user = $this->getUser(); $lang = $this->getLanguage(); $title = $this->getTitle(); $id = $title->getArticleID(); - $memcKey = wfMemcKey( 'infoaction', sha1( $title->getPrefixedText() ), $this->page->getLatest() ); + $memcKey = wfMemcKey( 'infoaction', + sha1( $title->getPrefixedText() ), $this->page->getLatest() ); $pageCounts = $wgMemc->get( $memcKey ); - if ( $pageCounts === false ) { + $version = isset( $pageCounts['cacheversion'] ) ? $pageCounts['cacheversion'] : false; + if ( $pageCounts === false || $version !== self::CACHE_VERSION ) { // Get page information that would be too "expensive" to retrieve by normal means $pageCounts = self::pageCounts( $title ); + $pageCounts['cacheversion'] = self::CACHE_VERSION; $wgMemc->set( $memcKey, $pageCounts ); } @@ -229,7 +256,7 @@ class InfoAction extends FormlessAction { } // Default sort key - $sortKey = $title->getCategorySortKey(); + $sortKey = $title->getCategorySortkey(); if ( !empty( $pageProperties['defaultsort'] ) ) { $sortKey = $pageProperties['defaultsort']; } @@ -259,6 +286,7 @@ class InfoAction extends FormlessAction { // Use robot policy logic $policy = $this->page->getRobotPolicy( 'view', $pOutput ); $pageInfo['header-basic'][] = array( + // Messages: pageinfo-robot-index, pageinfo-robot-noindex $this->msg( 'pageinfo-robot-policy' ), $this->msg( "pageinfo-robot-${policy['index']}" ) ); @@ -373,6 +401,7 @@ class InfoAction extends FormlessAction { $message = $this->msg( 'protect-default' )->escaped(); } else { // Administrators only + // Messages: protect-level-autoconfirmed, protect-level-sysop $message = $this->msg( "protect-level-$protectionLevel" ); if ( $message->isDisabled() ) { // Require "$1" permission @@ -382,6 +411,8 @@ class InfoAction extends FormlessAction { } } + // Messages: restriction-edit, restriction-move, restriction-create, + // restriction-upload $pageInfo['header-restrictions'][] = array( $this->msg( "restriction-$restrictionType" ), $message ); @@ -587,7 +618,7 @@ class InfoAction extends FormlessAction { if ( !$wgDisableCounters ) { // Number of views - $views = (int) $dbr->selectField( + $views = (int)$dbr->selectField( 'page', 'page_counter', array( 'page_id' => $id ), @@ -597,19 +628,19 @@ class InfoAction extends FormlessAction { } // Number of page watchers - $watchers = (int) $dbr->selectField( + $watchers = (int)$dbr->selectField( 'watchlist', 'COUNT(*)', array( 'wl_namespace' => $title->getNamespace(), - 'wl_title' => $title->getDBkey(), + 'wl_title' => $title->getDBkey(), ), __METHOD__ ); $result['watchers'] = $watchers; // Total number of edits - $edits = (int) $dbr->selectField( + $edits = (int)$dbr->selectField( 'revision', 'COUNT(rev_page)', array( 'rev_page' => $id ), @@ -618,7 +649,7 @@ class InfoAction extends FormlessAction { $result['edits'] = $edits; // Total number of distinct authors - $authors = (int) $dbr->selectField( + $authors = (int)$dbr->selectField( 'revision', 'COUNT(DISTINCT rev_user_text)', array( 'rev_page' => $id ), @@ -630,7 +661,7 @@ class InfoAction extends FormlessAction { $threshold = $dbr->timestamp( time() - $wgRCMaxAge ); // Recent number of edits - $edits = (int) $dbr->selectField( + $edits = (int)$dbr->selectField( 'revision', 'COUNT(rev_page)', array( @@ -642,7 +673,7 @@ class InfoAction extends FormlessAction { $result['recent_edits'] = $edits; // Recent number of distinct authors - $authors = (int) $dbr->selectField( + $authors = (int)$dbr->selectField( 'revision', 'COUNT(DISTINCT rev_user_text)', array( @@ -660,7 +691,7 @@ class InfoAction extends FormlessAction { // Subpages of this page (redirects) $conds['page_is_redirect'] = 1; - $result['subpages']['redirects'] = (int) $dbr->selectField( + $result['subpages']['redirects'] = (int)$dbr->selectField( 'page', 'COUNT(page_id)', $conds, @@ -668,7 +699,7 @@ class InfoAction extends FormlessAction { // Subpages of this page (non-redirects) $conds['page_is_redirect'] = 0; - $result['subpages']['nonredirects'] = (int) $dbr->selectField( + $result['subpages']['nonredirects'] = (int)$dbr->selectField( 'page', 'COUNT(page_id)', $conds, @@ -681,7 +712,7 @@ class InfoAction extends FormlessAction { } // Counts for the number of transclusion links (to/from) - $result['transclusion']['to'] = (int) $dbr->selectField( + $result['transclusion']['to'] = (int)$dbr->selectField( 'templatelinks', 'COUNT(tl_from)', array( @@ -691,7 +722,7 @@ class InfoAction extends FormlessAction { __METHOD__ ); - $result['transclusion']['from'] = (int) $dbr->selectField( + $result['transclusion']['from'] = (int)$dbr->selectField( 'templatelinks', 'COUNT(*)', array( 'tl_from' => $title->getArticleID() ), diff --git a/includes/actions/PurgeAction.php b/includes/actions/PurgeAction.php index 00bb961d..ed0bff7b 100644 --- a/includes/actions/PurgeAction.php +++ b/includes/actions/PurgeAction.php @@ -71,7 +71,7 @@ class PurgeAction extends FormAction { $this->getRequest()->getQueryValues(), array( 'title' => null, 'action' => null ) ) ); - if( $this->onSubmit( array() ) ) { + if ( $this->onSubmit( array() ) ) { $this->onSuccess(); } } else { @@ -96,6 +96,6 @@ class PurgeAction extends FormAction { } public function onSuccess() { - $this->getOutput()->redirect( $this->getTitle()->getFullUrl( $this->redirectParams ) ); + $this->getOutput()->redirect( $this->getTitle()->getFullURL( $this->redirectParams ) ); } } diff --git a/includes/actions/RawAction.php b/includes/actions/RawAction.php index 12ce9f98..32751e45 100644 --- a/includes/actions/RawAction.php +++ b/includes/actions/RawAction.php @@ -48,7 +48,7 @@ class RawAction extends FormlessAction { } function onView() { - global $wgSquidMaxage, $wgForcedRawSMaxage, $wgJsMimeType; + global $wgSquidMaxage, $wgForcedRawSMaxage; $this->getOutput()->disable(); $request = $this->getRequest(); @@ -79,7 +79,7 @@ class RawAction extends FormlessAction { # Force caching for CSS and JS raw content, default: 5 minutes if ( $smaxage === null ) { - if ( $contentType == 'text/css' || $contentType == $wgJsMimeType ) { + if ( $contentType == 'text/css' || $contentType == 'text/javascript' ) { $smaxage = intval( $wgForcedRawSMaxage ); } else { $smaxage = 0; @@ -93,10 +93,7 @@ class RawAction extends FormlessAction { $response->header( 'Content-type: ' . $contentType . '; charset=UTF-8' ); # Output may contain user-specific data; # vary generated content for open sessions on private wikis - $privateCache = !User::groupHasPermission( '*', 'read' ) && ( $smaxage == 0 || session_id() != '' ); - // Bug 53032 - make this private if user is logged in, - // so we don't accidentally cache cookies - $privateCache = $privateCache ?: $this->getUser()->isLoggedIn(); + $privateCache = !User::isEveryoneAllowed( 'read' ) && ( $smaxage == 0 || session_id() != '' ); # allow the client to cache this for 24 hours $mode = $privateCache ? 'private' : 'public'; $response->header( 'Cache-Control: ' . $mode . ', s-maxage=' . $smaxage . ', max-age=' . $maxage ); @@ -128,7 +125,7 @@ class RawAction extends FormlessAction { global $wgParser; # No longer used - if( $this->mGen ) { + if ( $this->mGen ) { return ''; } @@ -197,18 +194,18 @@ class RawAction extends FormlessAction { switch ( $this->getRequest()->getText( 'direction' ) ) { case 'next': # output next revision, or nothing if there isn't one - if( $oldid ) { - $oldid = $this->getTitle()->getNextRevisionId( $oldid ); + if ( $oldid ) { + $oldid = $this->getTitle()->getNextRevisionID( $oldid ); } $oldid = $oldid ? $oldid : -1; break; case 'prev': # output previous revision, or nothing if there isn't one - if( !$oldid ) { + if ( !$oldid ) { # get the current revision so we can get the penultimate one $oldid = $this->page->getLatest(); } - $prev = $this->getTitle()->getPreviousRevisionId( $oldid ); + $prev = $this->getTitle()->getPreviousRevisionID( $oldid ); $oldid = $prev ? $prev : -1; break; case 'cur': @@ -224,20 +221,18 @@ class RawAction extends FormlessAction { * @return String */ public function getContentType() { - global $wgJsMimeType; - $ctype = $this->getRequest()->getVal( 'ctype' ); if ( $ctype == '' ) { $gen = $this->getRequest()->getVal( 'gen' ); if ( $gen == 'js' ) { - $ctype = $wgJsMimeType; + $ctype = 'text/javascript'; } elseif ( $gen == 'css' ) { $ctype = 'text/css'; } } - $allowedCTypes = array( 'text/x-wiki', $wgJsMimeType, 'text/css', 'application/x-zope-edit' ); + $allowedCTypes = array( 'text/x-wiki', 'text/javascript', 'text/css', 'application/x-zope-edit' ); if ( $ctype == '' || !in_array( $ctype, $allowedCTypes ) ) { $ctype = 'text/x-wiki'; } @@ -254,6 +249,10 @@ class RawAction extends FormlessAction { class RawPage extends RawAction { public $mOldId; + /** + * @param Page $page + * @param WebRequest|bool $request The WebRequest (default: false). + */ function __construct( Page $page, $request = false ) { wfDeprecated( __CLASS__, '1.19' ); parent::__construct( $page ); diff --git a/includes/actions/WatchAction.php b/includes/actions/WatchAction.php index ae5f76c6..929c1b5f 100644 --- a/includes/actions/WatchAction.php +++ b/includes/actions/WatchAction.php @@ -87,24 +87,72 @@ class WatchAction extends FormAction { return parent::checkCanExecute( $user ); } - public static function doWatch( Title $title, User $user ) { + /** + * Watch or unwatch a page + * @since 1.22 + * @param bool $watch Whether to watch or unwatch the page + * @param Title $title Page to watch/unwatch + * @param User $user User who is watching/unwatching + * @return Status + */ + public static function doWatchOrUnwatch( $watch, Title $title, User $user ) { + if ( $user->isLoggedIn() && $user->isWatched( $title, WatchedItem::IGNORE_USER_RIGHTS ) != $watch ) { + // If the user doesn't have 'editmywatchlist', we still want to + // allow them to add but not remove items via edits and such. + if ( $watch ) { + return self::doWatch( $title, $user, WatchedItem::IGNORE_USER_RIGHTS ); + } else { + return self::doUnwatch( $title, $user ); + } + } + return Status::newGood(); + } + + /** + * Watch a page + * @since 1.22 Returns Status, $checkRights parameter added + * @param Title $title Page to watch/unwatch + * @param User $user User who is watching/unwatching + * @param int $checkRights Passed through to $user->addWatch() + * @return Status + */ + public static function doWatch( Title $title, User $user, $checkRights = WatchedItem::CHECK_USER_RIGHTS ) { + if ( $checkRights !== WatchedItem::IGNORE_USER_RIGHTS && !$user->isAllowed( 'editmywatchlist' ) ) { + return User::newFatalPermissionDeniedStatus( 'editmywatchlist' ); + } + $page = WikiPage::factory( $title ); - if ( wfRunHooks( 'WatchArticle', array( &$user, &$page ) ) ) { - $user->addWatch( $title ); + $status = Status::newFatal( 'hookaborted' ); + if ( wfRunHooks( 'WatchArticle', array( &$user, &$page, &$status ) ) ) { + $status = Status::newGood(); + $user->addWatch( $title, $checkRights ); wfRunHooks( 'WatchArticleComplete', array( &$user, &$page ) ); } - return true; + return $status; } - public static function doUnwatch( Title $title, User $user ) { + /** + * Unwatch a page + * @since 1.22 Returns Status + * @param Title $title Page to watch/unwatch + * @param User $user User who is watching/unwatching + * @return Status + */ + public static function doUnwatch( Title $title, User $user ) { + if ( !$user->isAllowed( 'editmywatchlist' ) ) { + return User::newFatalPermissionDeniedStatus( 'editmywatchlist' ); + } + $page = WikiPage::factory( $title ); - if ( wfRunHooks( 'UnwatchArticle', array( &$user, &$page ) ) ) { + $status = Status::newFatal( 'hookaborted' ); + if ( wfRunHooks( 'UnwatchArticle', array( &$user, &$page, &$status ) ) ) { + $status = Status::newGood(); $user->removeWatch( $title ); wfRunHooks( 'UnwatchArticleComplete', array( &$user, &$page ) ); } - return true; + return $status; } /** -- cgit v1.2.2