Merge "Fix sessionfailure i18n message during authentication"
[lhc/web/wiklou.git] / includes / api / ApiQueryProtectedTitles.php
index 5ef2f70..f526685 100644 (file)
@@ -1,9 +1,5 @@
 <?php
 /**
- *
- *
- * 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
@@ -51,14 +47,21 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase {
                $params = $this->extractRequestParams();
 
                $this->addTables( 'protected_titles' );
-               $this->addFields( array( 'pt_namespace', 'pt_title', 'pt_timestamp' ) );
+               $this->addFields( [ 'pt_namespace', 'pt_title', 'pt_timestamp' ] );
 
                $prop = array_flip( $params['prop'] );
                $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'] ) );
 
+               if ( isset( $prop['comment'] ) || isset( $prop['parsedcomment'] ) ) {
+                       $commentStore = CommentStore::getStore();
+                       $commentQuery = $commentStore->getJoin( 'pt_reason' );
+                       $this->addTables( $commentQuery['tables'] );
+                       $this->addFields( $commentQuery['fields'] );
+                       $this->addJoinConds( $commentQuery['joins'] );
+               }
+
                $this->addTimestampWhereRange( 'pt_timestamp', $params['dir'], $params['start'], $params['end'] );
                $this->addWhereFld( 'pt_namespace', $params['namespace'] );
                $this->addWhereFld( 'pt_create_perm', $params['level'] );
@@ -87,9 +90,9 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase {
                if ( isset( $prop['user'] ) ) {
                        $this->addTables( 'user' );
                        $this->addFields( 'user_name' );
-                       $this->addJoinConds( array( 'user' => array( 'LEFT JOIN',
+                       $this->addJoinConds( [ 'user' => [ 'LEFT JOIN',
                                'user_id=pt_user'
-                       ) ) );
+                       ] ] );
                }
 
                $this->addOption( 'LIMIT', $params['limit'] + 1 );
@@ -98,7 +101,7 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase {
                $count = 0;
                $result = $this->getResult();
 
-               $titles = array();
+               $titles = [];
 
                foreach ( $res as $row ) {
                        if ( ++$count > $params['limit'] ) {
@@ -112,7 +115,7 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase {
 
                        $title = Title::makeTitle( $row->pt_namespace, $row->pt_title );
                        if ( is_null( $resultPageSet ) ) {
-                               $vals = array();
+                               $vals = [];
                                ApiQueryBase::addTitleInfo( $vals, $title );
                                if ( isset( $prop['timestamp'] ) ) {
                                        $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $row->pt_timestamp );
@@ -127,23 +130,24 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase {
                                }
 
                                if ( isset( $prop['comment'] ) ) {
-                                       $vals['comment'] = $row->pt_reason;
+                                       $vals['comment'] = $commentStore->getComment( 'pt_reason', $row )->text;
                                }
 
                                if ( isset( $prop['parsedcomment'] ) ) {
-                                       $vals['parsedcomment'] = Linker::formatComment( $row->pt_reason, $title );
+                                       $vals['parsedcomment'] = Linker::formatComment(
+                                               $commentStore->getComment( 'pt_reason', $row )->text, $titles
+                                       );
                                }
 
                                if ( isset( $prop['expiry'] ) ) {
-                                       global $wgContLang;
-                                       $vals['expiry'] = $wgContLang->formatExpiry( $row->pt_expiry, TS_ISO_8601 );
+                                       $vals['expiry'] = ApiResult::formatExpiry( $row->pt_expiry );
                                }
 
                                if ( isset( $prop['level'] ) ) {
                                        $vals['level'] = $row->pt_create_perm;
                                }
 
-                               $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals );
+                               $fit = $result->addValue( [ 'query', $this->getModuleName() ], null, $vals );
                                if ( !$fit ) {
                                        $this->setContinueEnumParameter( 'continue',
                                                "$row->pt_timestamp|$row->pt_namespace|$row->pt_title"
@@ -157,7 +161,7 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase {
 
                if ( is_null( $resultPageSet ) ) {
                        $result->addIndexedTagName(
-                               array( 'query', $this->getModuleName() ),
+                               [ 'query', $this->getModuleName() ],
                                $this->getModulePrefix()
                        );
                } else {
@@ -175,40 +179,40 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase {
        }
 
        public function getAllowedParams() {
-               return array(
-                       'namespace' => array(
+               return [
+                       'namespace' => [
                                ApiBase::PARAM_ISMULTI => true,
                                ApiBase::PARAM_TYPE => 'namespace',
-                       ),
-                       'level' => array(
+                       ],
+                       'level' => [
                                ApiBase::PARAM_ISMULTI => true,
-                               ApiBase::PARAM_TYPE => array_diff( $this->getConfig()->get( 'RestrictionLevels' ), array( '' ) )
-                       ),
-                       'limit' => array(
+                               ApiBase::PARAM_TYPE => array_diff( $this->getConfig()->get( 'RestrictionLevels' ), [ '' ] )
+                       ],
+                       'limit' => [
                                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(
+                       ],
+                       'dir' => [
                                ApiBase::PARAM_DFLT => 'older',
-                               ApiBase::PARAM_TYPE => array(
+                               ApiBase::PARAM_TYPE => [
                                        'newer',
                                        'older'
-                               ),
+                               ],
                                ApiBase::PARAM_HELP_MSG => 'api-help-param-direction',
-                       ),
-                       'start' => array(
+                       ],
+                       'start' => [
                                ApiBase::PARAM_TYPE => 'timestamp'
-                       ),
-                       'end' => array(
+                       ],
+                       'end' => [
                                ApiBase::PARAM_TYPE => 'timestamp'
-                       ),
-                       'prop' => array(
+                       ],
+                       'prop' => [
                                ApiBase::PARAM_ISMULTI => true,
                                ApiBase::PARAM_DFLT => 'timestamp|level',
-                               ApiBase::PARAM_TYPE => array(
+                               ApiBase::PARAM_TYPE => [
                                        'timestamp',
                                        'user',
                                        'userid',
@@ -216,25 +220,25 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase {
                                        'parsedcomment',
                                        'expiry',
                                        'level'
-                               ),
-                               ApiBase::PARAM_HELP_MSG_PER_VALUE => array(),
-                       ),
-                       'continue' => array(
+                               ],
+                               ApiBase::PARAM_HELP_MSG_PER_VALUE => [],
+                       ],
+                       'continue' => [
                                ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
-                       ),
-               );
+                       ],
+               ];
        }
 
        protected function getExamplesMessages() {
-               return array(
+               return [
                        'action=query&list=protectedtitles'
                                => 'apihelp-query+protectedtitles-example-simple',
                        'action=query&generator=protectedtitles&gptnamespace=0&prop=linkshere'
                                => 'apihelp-query+protectedtitles-example-generator',
-               );
+               ];
        }
 
        public function getHelpUrls() {
-               return 'https://www.mediawiki.org/wiki/API:Protectedtitles';
+               return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Protectedtitles';
        }
 }