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