Merge branch 'Wikidata' of ssh://gerrit.wikimedia.org:29418/mediawiki/core into Wikidata
[lhc/web/wiklou.git] / includes / api / ApiQueryProtectedTitles.php
index 0162b88..44cc1d3 100644 (file)
@@ -1,11 +1,10 @@
 <?php
-
 /**
- * Created on Feb 13, 2009
  *
- * API for MediaWiki 1.8+
  *
- * Copyright © 2009 Roan Kattouw <Firstname>.<Lastname>@home.nl
+ * Created on Feb 13, 2009
+ *
+ * Copyright © 2009 Roan Kattouw <Firstname>.<Lastname>@gmail.com
  *
  * 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
  *
  * 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.,
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
  */
 
-if ( !defined( 'MEDIAWIKI' ) ) {
-       // Eclipse helper - will be ignored in production
-       require_once( 'ApiQueryBase.php' );
-}
-
 /**
  * Query module to enumerate all create-protected pages.
  *
@@ -47,20 +43,23 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase {
                $this->run( $resultPageSet );
        }
 
+       /**
+        * @param $resultPageSet ApiPageSet
+        * @return void
+        */
        private function run( $resultPageSet = null ) {
-               $db = $this->getDB();
                $params = $this->extractRequestParams();
 
                $this->addTables( 'protected_titles' );
                $this->addFields( array( 'pt_namespace', 'pt_title', 'pt_timestamp' ) );
 
                $prop = array_flip( $params['prop'] );
-               $this->addFieldsIf( 'pt_user', isset( $prop['user'] ) );
+               $this->addFieldsIf( 'pt_user', isset( $prop['user'] ) || isset( $prop['userid'] ) );
                $this->addFieldsIf( 'pt_reason', isset( $prop['comment'] ) || isset( $prop['parsedcomment'] ) );
                $this->addFieldsIf( 'pt_expiry', isset( $prop['expiry'] ) );
                $this->addFieldsIf( 'pt_create_perm', isset( $prop['level'] ) );
 
-               $this->addWhereRange( 'pt_timestamp', $params['dir'], $params['start'], $params['end'] );
+               $this->addTimestampWhereRange( 'pt_timestamp', $params['dir'], $params['start'], $params['end'] );
                $this->addWhereFld( 'pt_namespace', $params['namespace'] );
                $this->addWhereFld( 'pt_create_perm', $params['level'] );
 
@@ -77,7 +76,10 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase {
 
                $count = 0;
                $result = $this->getResult();
-               while ( $row = $db->fetchObject( $res ) ) {
+
+               $titles = array();
+
+               foreach ( $res as $row ) {
                        if ( ++ $count > $params['limit'] ) {
                                // We've reached the one extra which shows that there are additional pages to be had. Stop here...
                                $this->setContinueEnumParameter( 'start', wfTimestamp( TS_ISO_8601, $row->pt_timestamp ) );
@@ -96,17 +98,21 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase {
                                        $vals['user'] = $row->user_name;
                                }
 
+                               if ( isset( $prop['user'] ) ) {
+                                       $vals['userid'] = $row->pt_user;
+                               }
+
                                if ( isset( $prop['comment'] ) ) {
                                        $vals['comment'] = $row->pt_reason;
                                }
 
                                if ( isset( $prop['parsedcomment'] ) ) {
-                                       global $wgUser;
-                                       $vals['parsedcomment'] = $wgUser->getSkin()->formatComment( $row->pt_reason, $title );
+                                       $vals['parsedcomment'] = Linker::formatComment( $row->pt_reason, $title );
                                }
 
                                if ( isset( $prop['expiry'] ) ) {
-                                       $vals['expiry'] = Block::decodeExpiry( $row->pt_expiry, TS_ISO_8601 );
+                                       global $wgContLang;
+                                       $vals['expiry'] = $wgContLang->formatExpiry( $row->pt_expiry, TS_ISO_8601 );
                                }
 
                                if ( isset( $prop['level'] ) ) {
@@ -131,6 +137,15 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase {
                }
        }
 
+       public function getCacheMode( $params ) {
+               if ( !is_null( $params['prop'] ) && in_array( 'parsedcomment', $params['prop'] ) ) {
+                       // formatComment() calls wfMsg() among other things
+                       return 'anon-public-user-private';
+               } else {
+                       return 'public';
+               }
+       }
+
        public function getAllowedParams() {
                global $wgRestrictionLevels;
                return array(
@@ -152,8 +167,8 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase {
                        'dir' => array(
                                ApiBase::PARAM_DFLT => 'older',
                                ApiBase::PARAM_TYPE => array(
-                                       'older',
-                                       'newer'
+                                       'newer',
+                                       'older'
                                )
                        ),
                        'start' => array(
@@ -168,6 +183,7 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase {
                                ApiBase::PARAM_TYPE => array(
                                        'timestamp',
                                        'user',
+                                       'userid',
                                        'comment',
                                        'parsedcomment',
                                        'expiry',
@@ -182,9 +198,18 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase {
                        'namespace' => 'Only list titles in these namespaces',
                        'start' => 'Start listing at this protection timestamp',
                        'end' => 'Stop listing at this protection timestamp',
-                       'dir' => 'The direction in which to list',
+                       'dir' => $this->getDirectionDescription( $this->getModulePrefix() ),
                        'limit' => 'How many total pages to return',
-                       'prop' => 'Which properties to get',
+                       'prop' => array(
+                               'Which properties to get',
+                               ' timestamp      - Adds the timestamp of when protection was added',
+                               ' user           - Adds the user that added the protection',
+                               ' userid         - Adds the user id that added the protection',
+                               ' comment        - Adds the comment for the protection',
+                               ' parsedcomment  - Adds the parsed comment for the protection',
+                               ' expiry         - Adds the timestamp of when the protection will be lifted',
+                               ' level          - Adds the protection level',
+                       ),
                        'level' => 'Only list titles with these protection levels',
                );
        }
@@ -193,13 +218,17 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase {
                return 'List all titles protected from creation';
        }
 
-       protected function getExamples() {
+       public function getExamples() {
                return array(
                        'api.php?action=query&list=protectedtitles',
                );
        }
 
+       public function getHelpUrls() {
+               return 'https://www.mediawiki.org/wiki/API:Protectedtitles';
+       }
+
        public function getVersion() {
                return __CLASS__ . ': $Id$';
        }
-}
\ No newline at end of file
+}