Merge "Special:Upload should not crash on failing previews"
[mediawiki.git] / includes / specials / pagers / MergeHistoryPager.php
blobbbf97e13cb64b64a0768523ac45ad29adf98b213
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
18 * @file
19 * @ingroup Pager
22 /**
23 * @ingroup Pager
25 class MergeHistoryPager extends ReverseChronologicalPager {
27 /** @var SpecialMergeHistory */
28 public $mForm;
30 /** @var array */
31 public $mConds;
33 function __construct( SpecialMergeHistory $form, $conds, Title $source, Title $dest ) {
34 $this->mForm = $form;
35 $this->mConds = $conds;
36 $this->title = $source;
37 $this->articleID = $source->getArticleID();
39 $dbr = wfGetDB( DB_REPLICA );
40 $maxtimestamp = $dbr->selectField(
41 'revision',
42 'MIN(rev_timestamp)',
43 [ 'rev_page' => $dest->getArticleID() ],
44 __METHOD__
46 $this->maxTimestamp = $maxtimestamp;
48 parent::__construct( $form->getContext() );
51 function getStartBody() {
52 # Do a link batch query
53 $this->mResult->seek( 0 );
54 $batch = new LinkBatch();
55 # Give some pointers to make (last) links
56 $this->mForm->prevId = [];
57 $rev_id = null;
58 foreach ( $this->mResult as $row ) {
59 $batch->addObj( Title::makeTitleSafe( NS_USER, $row->user_name ) );
60 $batch->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->user_name ) );
62 if ( isset( $rev_id ) ) {
63 if ( $rev_id > $row->rev_id ) {
64 $this->mForm->prevId[$rev_id] = $row->rev_id;
65 } elseif ( $rev_id < $row->rev_id ) {
66 $this->mForm->prevId[$row->rev_id] = $rev_id;
70 $rev_id = $row->rev_id;
73 $batch->execute();
74 $this->mResult->seek( 0 );
76 return '';
79 function formatRow( $row ) {
80 return $this->mForm->formatRevisionRow( $row );
83 function getQueryInfo() {
84 $conds = $this->mConds;
85 $conds['rev_page'] = $this->articleID;
86 $conds[] = "rev_timestamp < " . $this->mDb->addQuotes( $this->maxTimestamp );
88 return [
89 'tables' => [ 'revision', 'page', 'user' ],
90 'fields' => array_merge( Revision::selectFields(), Revision::selectUserFields() ),
91 'conds' => $conds,
92 'join_conds' => [
93 'page' => Revision::pageJoinCond(),
94 'user' => Revision::userJoinCond() ]
98 function getIndexField() {
99 return 'rev_timestamp';