X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fspecials%2Fpagers%2FContribsPager.php;h=85faddc2e3e743e4127c90c9b0866b4824a2b933;hb=4bd87fba840a3fa2ba8c6dbcfa7f005f6708c0fa;hp=979460cf8aa5d09c0bc870625393f2c9aa50c5bb;hpb=72bd7a4decb46653dc7acbf22ac01bceee275a4e;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/specials/pagers/ContribsPager.php b/includes/specials/pagers/ContribsPager.php index 979460cf8a..85faddc2e3 100644 --- a/includes/specials/pagers/ContribsPager.php +++ b/includes/specials/pagers/ContribsPager.php @@ -175,79 +175,25 @@ class ContribsPager extends RangeChronologicalPager { } function getQueryInfo() { - list( $tables, $index, $userCond, $join_cond ) = $this->getUserCond(); - - $user = $this->getUser(); - $conds = array_merge( $userCond, $this->getNamespaceCond() ); - - // Paranoia: avoid brute force searches (T19342) - if ( !$user->isAllowed( 'deletedhistory' ) ) { - $conds[] = $this->mDb->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ' = 0'; - } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) { - $conds[] = $this->mDb->bitAnd( 'rev_deleted', Revision::SUPPRESSED_USER ) . - ' != ' . Revision::SUPPRESSED_USER; - } - - # Don't include orphaned revisions - $join_cond['page'] = Revision::pageJoinCond(); - # Get the current user name for accounts - $join_cond['user'] = Revision::userJoinCond(); - - $options = []; - if ( $index ) { - $options['USE INDEX'] = [ 'revision' => $index ]; - } - + $revQuery = Revision::getQueryInfo( [ 'page', 'user' ] ); $queryInfo = [ - 'tables' => $tables, - 'fields' => array_merge( - Revision::selectFields(), - Revision::selectUserFields(), - [ 'page_namespace', 'page_title', 'page_is_new', - 'page_latest', 'page_is_redirect', 'page_len' ] - ), - 'conds' => $conds, - 'options' => $options, - 'join_conds' => $join_cond + 'tables' => $revQuery['tables'], + 'fields' => array_merge( $revQuery['fields'], [ 'page_is_new' ] ), + 'conds' => [], + 'options' => [], + 'join_conds' => $revQuery['joins'], ]; - // For IPv6, we use ipc_rev_timestamp on ip_changes as the index field, - // which will be referenced when parsing the results of a query. - if ( self::isQueryableRange( $this->target ) ) { - $queryInfo['fields'][] = 'ipc_rev_timestamp'; - } - - ChangeTags::modifyDisplayQuery( - $queryInfo['tables'], - $queryInfo['fields'], - $queryInfo['conds'], - $queryInfo['join_conds'], - $queryInfo['options'], - $this->tagFilter - ); - - // Avoid PHP 7.1 warning from passing $this by reference - $pager = $this; - Hooks::run( 'ContribsPager::getQueryInfo', [ &$pager, &$queryInfo ] ); - - return $queryInfo; - } - - function getUserCond() { - $condition = []; - $join_conds = []; - $tables = [ 'revision', 'page', 'user' ]; - $index = false; if ( $this->contribs == 'newbie' ) { $max = $this->mDb->selectField( 'user', 'max(user_id)', false, __METHOD__ ); - $condition[] = 'rev_user >' . (int)( $max - $max / 100 ); + $queryInfo['conds'][] = 'rev_user >' . (int)( $max - $max / 100 ); # ignore local groups with the bot right # @todo FIXME: Global groups may have 'bot' rights $groupsWithBotPermission = User::getGroupsWithPermission( 'bot' ); if ( count( $groupsWithBotPermission ) ) { - $tables[] = 'user_groups'; - $condition[] = 'ug_group IS NULL'; - $join_conds['user_groups'] = [ + $queryInfo['tables'][] = 'user_groups'; + $queryInfo['conds'][] = 'ug_group IS NULL'; + $queryInfo['join_conds']['user_groups'] = [ 'LEFT JOIN', [ 'ug_user = rev_user', 'ug_group' => $groupsWithBotPermission, @@ -259,46 +205,76 @@ class ContribsPager extends RangeChronologicalPager { // (T140537) Disallow looking too far in the past for 'newbies' queries. If the user requested // a timestamp offset far in the past such that there are no edits by users with user_ids in // the range, we would end up scanning all revisions from that offset until start of time. - $condition[] = 'rev_timestamp > ' . + $queryInfo['conds'][] = 'rev_timestamp > ' . $this->mDb->addQuotes( $this->mDb->timestamp( wfTimestamp() - 30 * 24 * 60 * 60 ) ); } else { $uid = User::idFromName( $this->target ); if ( $uid ) { - $condition['rev_user'] = $uid; - $index = 'user_timestamp'; + $queryInfo['conds']['rev_user'] = $uid; + $queryInfo['options']['USE INDEX']['revision'] = 'user_timestamp'; } else { $ipRangeConds = $this->getIpRangeConds( $this->mDb, $this->target ); if ( $ipRangeConds ) { - $tables[] = 'ip_changes'; - $join_conds['ip_changes'] = [ + $queryInfo['tables'][] = 'ip_changes'; + $queryInfo['join_conds']['ip_changes'] = [ 'LEFT JOIN', [ 'ipc_rev_id = rev_id' ] ]; - $condition[] = $ipRangeConds; + $queryInfo['conds'][] = $ipRangeConds; } else { - $condition['rev_user_text'] = $this->target; - $index = 'usertext_timestamp'; + $queryInfo['conds']['rev_user_text'] = $this->target; + $queryInfo['options']['USE INDEX']['revision'] = 'usertext_timestamp'; } } } if ( $this->deletedOnly ) { - $condition[] = 'rev_deleted != 0'; + $queryInfo['conds'][] = 'rev_deleted != 0'; } if ( $this->topOnly ) { - $condition[] = 'rev_id = page_latest'; + $queryInfo['conds'][] = 'rev_id = page_latest'; } if ( $this->newOnly ) { - $condition[] = 'rev_parent_id = 0'; + $queryInfo['conds'][] = 'rev_parent_id = 0'; } if ( $this->hideMinor ) { - $condition[] = 'rev_minor_edit = 0'; + $queryInfo['conds'][] = 'rev_minor_edit = 0'; + } + + $user = $this->getUser(); + $queryInfo['conds'] = array_merge( $queryInfo['conds'], $this->getNamespaceCond() ); + + // Paranoia: avoid brute force searches (T19342) + if ( !$user->isAllowed( 'deletedhistory' ) ) { + $queryInfo['conds'][] = $this->mDb->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ' = 0'; + } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) { + $queryInfo['conds'][] = $this->mDb->bitAnd( 'rev_deleted', Revision::SUPPRESSED_USER ) . + ' != ' . Revision::SUPPRESSED_USER; } - return [ $tables, $index, $condition, $join_conds ]; + // For IPv6, we use ipc_rev_timestamp on ip_changes as the index field, + // which will be referenced when parsing the results of a query. + if ( self::isQueryableRange( $this->target ) ) { + $queryInfo['fields'][] = 'ipc_rev_timestamp'; + } + + ChangeTags::modifyDisplayQuery( + $queryInfo['tables'], + $queryInfo['fields'], + $queryInfo['conds'], + $queryInfo['join_conds'], + $queryInfo['options'], + $this->tagFilter + ); + + // Avoid PHP 7.1 warning from passing $this by reference + $pager = $this; + Hooks::run( 'ContribsPager::getQueryInfo', [ &$pager, &$queryInfo ] ); + + return $queryInfo; } function getNamespaceCond() {