MediaWiki  master
MergeHistoryPager.php
Go to the documentation of this file.
1 <?php
25 
30 
32  public $mForm;
33 
35  public $mConds;
36 
38  private $articleID;
39 
41  private $maxTimestamp;
42 
45 
47  private $revisionStore;
48 
58  public function __construct(
59  SpecialMergeHistory $form,
60  $conds,
61  Title $source,
62  Title $dest,
64  ILoadBalancer $loadBalancer,
66  ) {
67  $this->mForm = $form;
68  $this->mConds = $conds;
69  $this->articleID = $source->getArticleID();
70 
72  $maxtimestamp = $dbr->selectField(
73  'revision',
74  'MIN(rev_timestamp)',
75  [ 'rev_page' => $dest->getArticleID() ],
76  __METHOD__
77  );
78  $this->maxTimestamp = $maxtimestamp;
79 
80  // Set database before parent constructor to avoid setting it there with wfGetDB
81  $this->mDb = $dbr;
82  parent::__construct( $form->getContext() );
83  $this->linkBatchFactory = $linkBatchFactory;
84  $this->revisionStore = $revisionStore;
85  }
86 
87  protected function getStartBody() {
88  # Do a link batch query
89  $this->mResult->seek( 0 );
90  $batch = $this->linkBatchFactory->newLinkBatch();
91  # Give some pointers to make (last) links
92  $this->mForm->prevId = [];
93  $rev_id = null;
94  foreach ( $this->mResult as $row ) {
95  $batch->add( NS_USER, $row->user_name );
96  $batch->add( NS_USER_TALK, $row->user_name );
97 
98  if ( isset( $rev_id ) ) {
99  if ( $rev_id > $row->rev_id ) {
100  $this->mForm->prevId[$rev_id] = $row->rev_id;
101  } elseif ( $rev_id < $row->rev_id ) {
102  $this->mForm->prevId[$row->rev_id] = $rev_id;
103  }
104  }
105 
106  $rev_id = $row->rev_id;
107  }
108 
109  $batch->execute();
110  $this->mResult->seek( 0 );
111 
112  return '';
113  }
114 
115  public function formatRow( $row ) {
116  return $this->mForm->formatRevisionRow( $row );
117  }
118 
119  public function getQueryInfo() {
120  $dbr = $this->getDatabase();
121  $conds = $this->mConds;
122  $conds['rev_page'] = $this->articleID;
123  $conds[] = "rev_timestamp < " . $dbr->addQuotes( $this->maxTimestamp );
124 
125  $revQuery = $this->revisionStore->getQueryInfo( [ 'page', 'user' ] );
126  return [
127  'tables' => $revQuery['tables'],
128  'fields' => $revQuery['fields'],
129  'conds' => $conds,
130  'join_conds' => $revQuery['joins']
131  ];
132  }
133 
134  public function getIndexField() {
135  return 'rev_timestamp';
136  }
137 }
MergeHistoryPager\getIndexField
getIndexField()
Returns the name of the index field.
Definition: MergeHistoryPager.php:134
MergeHistoryPager\$mForm
SpecialMergeHistory $mForm
Definition: MergeHistoryPager.php:32
MergeHistoryPager\$linkBatchFactory
LinkBatchFactory $linkBatchFactory
Definition: MergeHistoryPager.php:44
Revision\RevisionStore
Service for looking up page revisions.
Definition: RevisionStore.php:80
IndexPager\getDatabase
getDatabase()
Get the Database object in use.
Definition: IndexPager.php:244
Title\getArticleID
getArticleID( $flags=0)
Get the article ID for this Title from the link cache, adding it if necessary.
Definition: Title.php:3140
Wikimedia\Rdbms\ILoadBalancer\getConnectionRef
getConnectionRef( $i, $groups=[], $domain=false, $flags=0)
Get a live database handle reference for a real or virtual (DB_MASTER/DB_REPLICA) server index.
$revQuery
$revQuery
Definition: testCompression.php:56
MergeHistoryPager\__construct
__construct(SpecialMergeHistory $form, $conds, Title $source, Title $dest, LinkBatchFactory $linkBatchFactory, ILoadBalancer $loadBalancer, RevisionStore $revisionStore)
Definition: MergeHistoryPager.php:58
$dbr
$dbr
Definition: testCompression.php:54
MergeHistoryPager\$articleID
int $articleID
Definition: MergeHistoryPager.php:38
MediaWiki\Cache\LinkBatchFactory
Definition: LinkBatchFactory.php:38
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
MergeHistoryPager\$revisionStore
RevisionStore $revisionStore
Definition: MergeHistoryPager.php:47
MergeHistoryPager\$maxTimestamp
int $maxTimestamp
Definition: MergeHistoryPager.php:41
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:762
MergeHistoryPager\getQueryInfo
getQueryInfo()
Provides all parameters needed for the main paged query.
Definition: MergeHistoryPager.php:119
MergeHistoryPager\getStartBody
getStartBody()
Hook into getBody(), allows text to be inserted at the start.
Definition: MergeHistoryPager.php:87
NS_USER_TALK
const NS_USER_TALK
Definition: Defines.php:72
MergeHistoryPager\formatRow
formatRow( $row)
Returns an HTML string representing the result row $row.
Definition: MergeHistoryPager.php:115
Title
Represents a title within MediaWiki.
Definition: Title.php:41
MergeHistoryPager\$mConds
array $mConds
Definition: MergeHistoryPager.php:35
NS_USER
const NS_USER
Definition: Defines.php:71
$source
$source
Definition: mwdoc-filter.php:34
ReverseChronologicalPager
Efficient paging for SQL queries.
Definition: ReverseChronologicalPager.php:29
MergeHistoryPager
Definition: MergeHistoryPager.php:29
SpecialMergeHistory
Special page allowing users with the appropriate permissions to merge article histories,...
Definition: SpecialMergeHistory.php:36
Wikimedia\Rdbms\ILoadBalancer
Database cluster connection, tracking, load balancing, and transaction manager interface.
Definition: ILoadBalancer.php:81