Merge "Convert Special:DeletedContributions to use OOUI."
[lhc/web/wiklou.git] / includes / specials / pagers / MergeHistoryPager.php
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.
7 *
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.
12 *
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
17 *
18 * @file
19 * @ingroup Pager
20 */
21
22 /**
23 * @ingroup Pager
24 */
25 class MergeHistoryPager extends ReverseChronologicalPager {
26
27 /** @var SpecialMergeHistory */
28 public $mForm;
29
30 /** @var array */
31 public $mConds;
32
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();
38
39 $dbr = wfGetDB( DB_REPLICA );
40 $maxtimestamp = $dbr->selectField(
41 'revision',
42 'MIN(rev_timestamp)',
43 [ 'rev_page' => $dest->getArticleID() ],
44 __METHOD__
45 );
46 $this->maxTimestamp = $maxtimestamp;
47
48 parent::__construct( $form->getContext() );
49 }
50
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 foreach ( $this->mResult as $row ) {
58 $batch->addObj( Title::makeTitleSafe( NS_USER, $row->user_name ) );
59 $batch->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->user_name ) );
60
61 $rev_id = isset( $rev_id ) ? $rev_id : $row->rev_id;
62 if ( $rev_id > $row->rev_id ) {
63 $this->mForm->prevId[$rev_id] = $row->rev_id;
64 } elseif ( $rev_id < $row->rev_id ) {
65 $this->mForm->prevId[$row->rev_id] = $rev_id;
66 }
67
68 $rev_id = $row->rev_id;
69 }
70
71 $batch->execute();
72 $this->mResult->seek( 0 );
73
74 return '';
75 }
76
77 function formatRow( $row ) {
78 return $this->mForm->formatRevisionRow( $row );
79 }
80
81 function getQueryInfo() {
82 $conds = $this->mConds;
83 $conds['rev_page'] = $this->articleID;
84 $conds[] = "rev_timestamp < " . $this->mDb->addQuotes( $this->maxTimestamp );
85
86 return [
87 'tables' => [ 'revision', 'page', 'user' ],
88 'fields' => array_merge( Revision::selectFields(), Revision::selectUserFields() ),
89 'conds' => $conds,
90 'join_conds' => [
91 'page' => Revision::pageJoinCond(),
92 'user' => Revision::userJoinCond() ]
93 ];
94 }
95
96 function getIndexField() {
97 return 'rev_timestamp';
98 }
99 }