* @file
*/
+use MediaWiki\MediaWikiServices;
use Wikimedia\Rdbms\IDatabase;
use Wikimedia\Rdbms\IResultWrapper;
* @ingroup API
*/
abstract class ApiQueryBase extends ApiBase {
+ use ApiQueryBlockInfoTrait;
private $mQueryModule, $mDb, $tables, $where, $fields, $options, $join_conds;
public function requestExtraData( $pageSet ) {
}
- /**@}*/
+ /** @} */
/************************************************************************//**
* @name Data access
return $this->getQuery()->getPageSet();
}
- /**@}*/
+ /** @} */
/************************************************************************//**
* @name Querying
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' );
- }
- }
-
- /**@}*/
+ /** @} */
/************************************************************************//**
* @name Utility methods
* @return bool
*/
public function userCanSeeRevDel() {
- return $this->getUser()->isAllowedAny(
+ return $this->getPermissionManager()->userHasAnyRight(
+ $this->getUser(),
'deletedhistory',
'deletedtext',
'suppressrevision',
);
}
- /**@}*/
+ /**
+ * 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 );
+ }
+
+ /** @} */
}