Merge "(bug 46059) giving #p-personal a higher z-index than #content in monobook"
[lhc/web/wiklou.git] / includes / api / ApiSetNotificationTimestamp.php
index 7a47a0c..58d5d9a 100644 (file)
@@ -31,6 +31,8 @@
  */
 class ApiSetNotificationTimestamp extends ApiBase {
 
+       private $mPageSet;
+
        public function execute() {
                $user = $this->getUser();
 
@@ -41,9 +43,10 @@ class ApiSetNotificationTimestamp extends ApiBase {
                $params = $this->extractRequestParams();
                $this->requireMaxOneParameter( $params, 'timestamp', 'torevid', 'newerthanrevid' );
 
-               $pageSet = new ApiPageSet( $this );
-               $args = array_merge( array( $params, 'entirewatchlist' ), array_keys( $pageSet->getAllowedParams() ) );
-               call_user_func_array( array( $this, 'requireOnlyOneParameter' ), $args );
+               $pageSet = $this->getPageSet();
+               if ( $params['entirewatchlist'] && $pageSet->getDataSource() !== null ) {
+                       $this->dieUsage( "Cannot use 'entirewatchlist' at the same time as '{$pageSet->getDataSource()}'", 'multisource' );
+               }
 
                $dbw = wfGetDB( DB_MASTER, 'api' );
 
@@ -92,20 +95,20 @@ class ApiSetNotificationTimestamp extends ApiBase {
                        $result['notificationtimestamp'] = ( is_null( $timestamp ) ? '' : wfTimestamp( TS_ISO_8601, $timestamp ) );
                } else {
                        // First, log the invalid titles
-                       foreach( $pageSet->getInvalidTitles() as $title ) {
+                       foreach ( $pageSet->getInvalidTitles() as $title ) {
                                $r = array();
                                $r['title'] = $title;
                                $r['invalid'] = '';
                                $result[] = $r;
                        }
-                       foreach( $pageSet->getMissingPageIDs() as $p ) {
+                       foreach ( $pageSet->getMissingPageIDs() as $p ) {
                                $page = array();
                                $page['pageid'] = $p;
                                $page['missing'] = '';
                                $page['notwatched'] = '';
                                $result[] = $page;
                        }
-                       foreach( $pageSet->getMissingRevisionIDs() as $r ) {
+                       foreach ( $pageSet->getMissingRevisionIDs() as $r ) {
                                $rev = array();
                                $rev['revid'] = $r;
                                $rev['missing'] = '';
@@ -131,6 +134,7 @@ class ApiSetNotificationTimestamp extends ApiBase {
                        }
 
                        // Now, put the valid titles into the result
+                       /** @var $title Title */
                        foreach ( $pageSet->getTitles() as $title ) {
                                $ns = $title->getNamespace();
                                $dbkey = $title->getDBkey();
@@ -157,6 +161,17 @@ class ApiSetNotificationTimestamp extends ApiBase {
                $apiResult->addValue( null, $this->getModuleName(), $result );
        }
 
+       /**
+        * Get a cached instance of an ApiPageSet object
+        * @return ApiPageSet
+        */
+       private function getPageSet() {
+               if ( !isset( $this->mPageSet ) ) {
+                       $this->mPageSet = new ApiPageSet( $this );
+               }
+               return $this->mPageSet;
+       }
+
        public function mustBePosted() {
                return true;
        }
@@ -173,9 +188,8 @@ class ApiSetNotificationTimestamp extends ApiBase {
                return '';
        }
 
-       public function getAllowedParams() {
-               $psModule = new ApiPageSet( $this );
-               return $psModule->getAllowedParams() + array(
+       public function getAllowedParams( $flags = 0 ) {
+               $result = array(
                        'entirewatchlist' => array(
                                ApiBase::PARAM_TYPE => 'boolean'
                        ),
@@ -190,11 +204,15 @@ class ApiSetNotificationTimestamp extends ApiBase {
                                ApiBase::PARAM_TYPE => 'integer'
                        ),
                );
+               if ( $flags ) {
+                       $result += $this->getPageSet()->getFinalParams( $flags );
+               }
+               return $result;
+
        }
 
        public function getParamDescription() {
-               $psModule = new ApiPageSet( $this );
-               return $psModule->getParamDescription() + array(
+               return $this->getPageSet()->getParamDescription() + array(
                        'entirewatchlist' => 'Work on all watched pages',
                        'timestamp' => 'Timestamp to which to set the notification timestamp',
                        'torevid' => 'Revision to set the notification timestamp to (one page only)',
@@ -243,18 +261,20 @@ class ApiSetNotificationTimestamp extends ApiBase {
        public function getDescription() {
                return array( 'Update the notification timestamp for watched pages.',
                        'This affects the highlighting of changed pages in the watchlist and history,',
-                       'and the sending of email when the "E-mail me when a page on my watchlist is',
+                       'and the sending of email when the "Email me when a page on my watchlist is',
                        'changed" preference is enabled.'
                );
        }
 
        public function getPossibleErrors() {
-               $psModule = new ApiPageSet( $this );
+               $ps = $this->getPageSet();
                return array_merge(
                        parent::getPossibleErrors(),
-                       $psModule->getPossibleErrors(),
-                       $this->getRequireMaxOneParameterErrorMessages( array( 'timestamp', 'torevid', 'newerthanrevid' ) ),
-                       $this->getRequireOnlyOneParameterErrorMessages( array_merge( array( 'entirewatchlist' ), array_keys( $psModule->getAllowedParams() ) ) ),
+                       $ps->getPossibleErrors(),
+                       $this->getRequireMaxOneParameterErrorMessages(
+                               array( 'timestamp', 'torevid', 'newerthanrevid' ) ),
+                       $this->getRequireOnlyOneParameterErrorMessages(
+                               array_merge( array( 'entirewatchlist' ), array_keys( $ps->getFinalParams() ) ) ),
                        array(
                                array( 'code' => 'notloggedin', 'info' => 'Anonymous users cannot use watchlist change notifications' ),
                                array( 'code' => 'multpages', 'info' => 'torevid may only be used with a single page' ),
@@ -265,9 +285,9 @@ class ApiSetNotificationTimestamp extends ApiBase {
 
        public function getExamples() {
                return array(
-                       'api.php?action=setnotificationtimestamp&entirewatchlist=&token=ABC123' => 'Reset the notification status for the entire watchlist',
-                       'api.php?action=setnotificationtimestamp&titles=Main_page&token=ABC123' => 'Reset the notification status for "Main page"',
-                       'api.php?action=setnotificationtimestamp&titles=Main_page&timestamp=2012-01-01T00:00:00Z&token=ABC123' => 'Set the notification timestamp for "Main page" so all edits since 1 January 2012 are unviewed',
+                       'api.php?action=setnotificationtimestamp&entirewatchlist=&token=123ABC' => 'Reset the notification status for the entire watchlist',
+                       'api.php?action=setnotificationtimestamp&titles=Main_page&token=123ABC' => 'Reset the notification status for "Main page"',
+                       'api.php?action=setnotificationtimestamp&titles=Main_page&timestamp=2012-01-01T00:00:00Z&token=123ABC' => 'Set the notification timestamp for "Main page" so all edits since 1 January 2012 are unviewed',
                );
        }