- $tables = array( 'page', 'revision' );
- $opts = array( 'ORDER BY' => 'page_id ASC' );
- $opts['USE INDEX'] = array();
- $join = array();
+ $revOpts = [ 'page' ];
+ if ( $this->text != self::STUB ) {
+ $revOpts[] = 'text';
+ }
+ $revQuery = Revision::getQueryInfo( $revOpts );
+
+ // We want page primary rather than revision
+ $tables = array_merge( [ 'page' ], array_diff( $revQuery['tables'], [ 'page' ] ) );
+ $join = $revQuery['joins'] + [
+ 'revision' => $revQuery['joins']['page']
+ ];
+ unset( $join['page'] );
+
+ $fields = array_merge( $revQuery['fields'], [ 'page_restrictions' ] );
+
+ $conds = [];
+ if ( $cond !== '' ) {
+ $conds[] = $cond;
+ }
+ $opts = [ 'ORDER BY' => 'page_id ASC' ];
+ $opts['USE INDEX'] = [];