]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blobdiff - includes/api/ApiQueryProtectedTitles.php
MediaWiki 1.17.4
[autoinstalls/mediawiki.git] / includes / api / ApiQueryProtectedTitles.php
index ab79480522d83ae452995d5f6a1fc9a8e282274f..d2d2b869b85b036d6d54567d484e61f53fb0b354 100644 (file)
@@ -1,11 +1,10 @@
 <?php
-
-/*
- * Created on Feb 13, 2009
- *
+/**
  * API for MediaWiki 1.8+
  *
- * Copyright (C) 2009 Roan Kattouw <Firstname>.<Lastname>@home.nl
+ * Created on Feb 13, 2009
+ *
+ * Copyright © 2009 Roan Kattouw <Firstname>.<Lastname>@home.nl
  *
  * 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' );
+       require_once( 'ApiQueryBase.php' );
 }
 
 /**
@@ -36,7 +37,7 @@ if ( !defined( 'MEDIAWIKI' ) ) {
 class ApiQueryProtectedTitles extends ApiQueryGeneratorBase {
 
        public function __construct( $query, $moduleName ) {
-               parent :: __construct( $query, $moduleName, 'pt' );
+               parent::__construct( $query, $moduleName, 'pt' );
        }
 
        public function execute() {
@@ -48,14 +49,13 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase {
        }
 
        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'] ) );
@@ -63,9 +63,8 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase {
                $this->addWhereRange( 'pt_timestamp', $params['dir'], $params['start'], $params['end'] );
                $this->addWhereFld( 'pt_namespace', $params['namespace'] );
                $this->addWhereFld( 'pt_create_perm', $params['level'] );
-               
-               if ( isset( $prop['user'] ) )
-               {
+
+               if ( isset( $prop['user'] ) ) {
                        $this->addTables( 'user' );
                        $this->addFields( 'user_name' );
                        $this->addJoinConds( array( 'user' => array( 'LEFT JOIN',
@@ -78,7 +77,7 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase {
 
                $count = 0;
                $result = $this->getResult();
-               while ( $row = $db->fetchObject( $res ) ) {
+               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 ) );
@@ -89,26 +88,35 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase {
                        if ( is_null( $resultPageSet ) ) {
                                $vals = array();
                                ApiQueryBase::addTitleInfo( $vals, $title );
-                               if ( isset( $prop['timestamp'] ) )
+                               if ( isset( $prop['timestamp'] ) ) {
                                        $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $row->pt_timestamp );
-                                       
-                               if ( isset( $prop['user'] ) && !is_null( $row->user_name ) )
+                               }
+
+                               if ( isset( $prop['user'] ) && !is_null( $row->user_name ) ) {
                                        $vals['user'] = $row->user_name;
-                                       
-                               if ( isset( $prop['comment'] ) )
+                               }
+
+                               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 );
                                }
-                                       
-                               if ( isset( $prop['expiry'] ) )
+
+                               if ( isset( $prop['expiry'] ) ) {
                                        $vals['expiry'] = Block::decodeExpiry( $row->pt_expiry, TS_ISO_8601 );
-                                       
-                               if ( isset( $prop['level'] ) )
+                               }
+
+                               if ( isset( $prop['level'] ) ) {
                                        $vals['level'] = $row->pt_create_perm;
-                               
+                               }
+
                                $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals );
                                if ( !$fit ) {
                                        $this->setContinueEnumParameter( 'start',
@@ -119,11 +127,12 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase {
                                $titles[] = $title;
                        }
                }
-               $db->freeResult( $res );
-               if ( is_null( $resultPageSet ) )
+
+               if ( is_null( $resultPageSet ) ) {
                        $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), $this->getModulePrefix() );
-               else
+               } else {
                        $resultPageSet->populateFromTitles( $titles );
+               }
        }
 
        public function getCacheMode( $params ) {
@@ -137,41 +146,42 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase {
 
        public function getAllowedParams() {
                global $wgRestrictionLevels;
-               return array (
-                       'namespace' => array (
-                               ApiBase :: PARAM_ISMULTI => true,
-                               ApiBase :: PARAM_TYPE => 'namespace',
+               return array(
+                       'namespace' => array(
+                               ApiBase::PARAM_ISMULTI => true,
+                               ApiBase::PARAM_TYPE => 'namespace',
                        ),
                        'level' => array(
-                               ApiBase :: PARAM_ISMULTI => true,
-                               ApiBase :: PARAM_TYPE => array_diff( $wgRestrictionLevels, array( '' ) )
+                               ApiBase::PARAM_ISMULTI => true,
+                               ApiBase::PARAM_TYPE => array_diff( $wgRestrictionLevels, array( '' ) )
                        ),
                        'limit' => array (
-                               ApiBase :: PARAM_DFLT => 10,
-                               ApiBase :: PARAM_TYPE => 'limit',
-                               ApiBase :: PARAM_MIN => 1,
-                               ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1,
-                               ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
+                               ApiBase::PARAM_DFLT => 10,
+                               ApiBase::PARAM_TYPE => 'limit',
+                               ApiBase::PARAM_MIN => 1,
+                               ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
+                               ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
                        ),
-                       'dir' => array (
-                               ApiBase :: PARAM_DFLT => 'older',
-                               ApiBase :: PARAM_TYPE => array (
+                       'dir' => array(
+                               ApiBase::PARAM_DFLT => 'older',
+                               ApiBase::PARAM_TYPE => array(
                                        'older',
                                        'newer'
                                )
                        ),
                        'start' => array(
-                               ApiBase :: PARAM_TYPE => 'timestamp'
+                               ApiBase::PARAM_TYPE => 'timestamp'
                        ),
                        'end' => array(
-                               ApiBase :: PARAM_TYPE => 'timestamp'
+                               ApiBase::PARAM_TYPE => 'timestamp'
                        ),
                        'prop' => array(
-                               ApiBase :: PARAM_ISMULTI => true,
-                               ApiBase :: PARAM_DFLT => 'timestamp|level',
-                               ApiBase :: PARAM_TYPE => array(
+                               ApiBase::PARAM_ISMULTI => true,
+                               ApiBase::PARAM_DFLT => 'timestamp|level',
+                               ApiBase::PARAM_TYPE => array(
                                        'timestamp',
                                        'user',
+                                       'userid',
                                        'comment',
                                        'parsedcomment',
                                        'expiry',
@@ -182,13 +192,22 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase {
        }
 
        public function getParamDescription() {
-               return array (
+               return array(
                        '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',
-                       'limit' => 'How many total pages to return.',
-                       'prop' => 'Which properties to get',
+                       'limit' => 'How many total pages to return',
+                       'prop' => array(
+                               'Which properties to get',
+                               ' timestamp      - Adds the timestamp of when protection was added',
+                               ' user           - Adds the user to add the protection',
+                               ' userid         - Adds the user id to add 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',
                );
        }
@@ -198,12 +217,12 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase {
        }
 
        protected function getExamples() {
-               return array (
+               return array(
                        'api.php?action=query&list=protectedtitles',
                );
        }
 
        public function getVersion() {
-               return __CLASS__ . ': $Id: ApiQueryProtectedTitles.php 69932 2010-07-26 08:03:21Z tstarling $';
+               return __CLASS__ . ': $Id$';
        }
 }