Merge "filebackend: avoid use of wfWikiId() in FileBackendGroup"
[lhc/web/wiklou.git] / includes / api / ApiQueryBase.php
index 50ca99a..059c438 100644 (file)
@@ -20,6 +20,7 @@
  * @file
  */
 
+use MediaWiki\MediaWikiServices;
 use Wikimedia\Rdbms\IDatabase;
 use Wikimedia\Rdbms\IResultWrapper;
 
@@ -31,6 +32,7 @@ use Wikimedia\Rdbms\IResultWrapper;
  * @ingroup API
  */
 abstract class ApiQueryBase extends ApiBase {
+       use ApiQueryBlockInfoTrait;
 
        private $mQueryModule, $mDb, $tables, $where, $fields, $options, $join_conds;
 
@@ -424,47 +426,6 @@ abstract class ApiQueryBase extends ApiBase {
                return Hooks::run( 'ApiQueryBaseProcessRow', [ $this, $row, &$data, &$hookData ] );
        }
 
-       /**
-        * Filters hidden users (where the user doesn't have the right to view them)
-        * Also adds relevant block information
-        *
-        * @param bool $showBlockInfo
-        * @return void
-        */
-       public function showHiddenUsersAddBlockInfo( $showBlockInfo ) {
-               $db = $this->getDB();
-
-               $tables = [ 'ipblocks' ];
-               $fields = [ 'ipb_deleted' ];
-               $joinConds = [
-                       'blk' => [ 'LEFT JOIN', [
-                               'ipb_user=user_id',
-                               'ipb_expiry > ' . $db->addQuotes( $db->timestamp() ),
-                       ] ],
-               ];
-
-               if ( $showBlockInfo ) {
-                       $actorQuery = ActorMigration::newMigration()->getJoin( 'ipb_by' );
-                       $commentQuery = CommentStore::getStore()->getJoin( 'ipb_reason' );
-                       $tables += $actorQuery['tables'] + $commentQuery['tables'];
-                       $joinConds += $actorQuery['joins'] + $commentQuery['joins'];
-                       $fields = array_merge( $fields, [
-                               'ipb_id',
-                               'ipb_expiry',
-                               'ipb_timestamp'
-                       ], $actorQuery['fields'], $commentQuery['fields'] );
-               }
-
-               $this->addTables( [ 'blk' => $tables ] );
-               $this->addFields( $fields );
-               $this->addJoinConds( $joinConds );
-
-               // Don't show hidden names
-               if ( !$this->getUser()->isAllowed( 'hideuser' ) ) {
-                       $this->addWhere( 'ipb_deleted = 0 OR ipb_deleted IS NULL' );
-               }
-       }
-
        /** @} */
 
        /************************************************************************//**
@@ -600,7 +561,8 @@ abstract class ApiQueryBase extends ApiBase {
         * @return bool
         */
        public function userCanSeeRevDel() {
-               return $this->getUser()->isAllowedAny(
+               return $this->getPermissionManager()->userHasAnyRight(
+                       $this->getUser(),
                        'deletedhistory',
                        'deletedtext',
                        'suppressrevision',
@@ -608,5 +570,61 @@ abstract class ApiQueryBase extends ApiBase {
                );
        }
 
+       /**
+        * Preprocess the result set to fill the GenderCache with the necessary information
+        * before using self::addTitleInfo
+        *
+        * @param IResultWrapper $res Result set to work on.
+        *  The result set must have _namespace and _title fields with the provided field prefix
+        * @param string $fname The caller function name, always use __METHOD__
+        * @param string $fieldPrefix Prefix for fields to check gender for
+        */
+       protected function executeGenderCacheFromResultWrapper(
+               IResultWrapper $res, $fname = __METHOD__, $fieldPrefix = 'page'
+       ) {
+               if ( !$res->numRows() ) {
+                       return;
+               }
+
+               $services = MediaWikiServices::getInstance();
+               $nsInfo = $services->getNamespaceInfo();
+               $namespaceField = $fieldPrefix . '_namespace';
+               $titleField = $fieldPrefix . '_title';
+
+               $usernames = [];
+               foreach ( $res as $row ) {
+                       if ( $nsInfo->hasGenderDistinction( $row->$namespaceField ) ) {
+                               $usernames[] = $row->$titleField;
+                       }
+               }
+
+               if ( $usernames === [] ) {
+                       return;
+               }
+
+               $genderCache = $services->getGenderCache();
+               $genderCache->doQuery( $usernames, $fname );
+       }
+
+       /** @} */
+
+       /************************************************************************//**
+        * @name   Deprecated methods
+        * @{
+        */
+
+       /**
+        * Filters hidden users (where the user doesn't have the right to view them)
+        * Also adds relevant block information
+        *
+        * @deprecated since 1.34, use ApiQueryBlockInfoTrait instead
+        * @param bool $showBlockInfo
+        * @return void
+        */
+       public function showHiddenUsersAddBlockInfo( $showBlockInfo ) {
+               wfDeprecated( __METHOD__, '1.34' );
+               return $this->addBlockInfoToQuery( $showBlockInfo );
+       }
+
        /** @} */
 }