X-Git-Url: https://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiQueryBase.php;h=059c438a37ea183ebdfbb94672643c173d0428d0;hb=a8525d7201dada88f3117142fe1919d0b9b80d4e;hp=50ca99a45dc089a253f0760089aa9dec350adbb6;hpb=8e338a10c044970fc0417bfa4fbd9d1bf8e10b8e;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiQueryBase.php b/includes/api/ApiQueryBase.php index 50ca99a45d..059c438a37 100644 --- a/includes/api/ApiQueryBase.php +++ b/includes/api/ApiQueryBase.php @@ -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 ); + } + /** @} */ }