Merge "Type hint against LinkTarget in WatchedItemStore"
[lhc/web/wiklou.git] / includes / revisiondelete / RevDelLogList.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 RevisionDelete
20 */
21
22 use MediaWiki\Storage\RevisionRecord;
23 use Wikimedia\Rdbms\IDatabase;
24
25 /**
26 * List for logging table items
27 */
28 class RevDelLogList extends RevDelList {
29 public function getType() {
30 return 'logging';
31 }
32
33 public static function getRelationType() {
34 return 'log_id';
35 }
36
37 public static function getRestriction() {
38 return 'deletelogentry';
39 }
40
41 public static function getRevdelConstant() {
42 return LogPage::DELETED_ACTION;
43 }
44
45 public static function suggestTarget( $target, array $ids ) {
46 $result = wfGetDB( DB_REPLICA )->select( 'logging',
47 'log_type',
48 [ 'log_id' => $ids ],
49 __METHOD__,
50 [ 'DISTINCT' ]
51 );
52 if ( $result->numRows() == 1 ) {
53 // If there's only one type, the target can be set to include it.
54 return SpecialPage::getTitleFor( 'Log', $result->current()->log_type );
55 }
56
57 return SpecialPage::getTitleFor( 'Log' );
58 }
59
60 /**
61 * @param IDatabase $db
62 * @return mixed
63 */
64 public function doQuery( $db ) {
65 $ids = array_map( 'intval', $this->ids );
66
67 $commentQuery = CommentStore::getStore()->getJoin( 'log_comment' );
68 $actorQuery = ActorMigration::newMigration()->getJoin( 'log_user' );
69
70 return $db->select(
71 [ 'logging' ] + $commentQuery['tables'] + $actorQuery['tables'],
72 [
73 'log_id',
74 'log_type',
75 'log_action',
76 'log_timestamp',
77 'log_namespace',
78 'log_title',
79 'log_page',
80 'log_params',
81 'log_deleted'
82 ] + $commentQuery['fields'] + $actorQuery['fields'],
83 [ 'log_id' => $ids ],
84 __METHOD__,
85 [ 'ORDER BY' => 'log_id DESC' ],
86 $commentQuery['joins'] + $actorQuery['joins']
87 );
88 }
89
90 public function newItem( $row ) {
91 return new RevDelLogItem( $this, $row );
92 }
93
94 public function getSuppressBit() {
95 return RevisionRecord::DELETED_RESTRICTED;
96 }
97
98 public function getLogAction() {
99 return 'event';
100 }
101
102 public function getLogParams( $params ) {
103 return [
104 '4::ids' => $params['ids'],
105 '5::ofield' => $params['oldBits'],
106 '6::nfield' => $params['newBits'],
107 ];
108 }
109 }