Merge "Rewrite pref cleanup script"
[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 Wikimedia\Rdbms\IDatabase;
23
24 /**
25 * List for logging table items
26 */
27 class RevDelLogList extends RevDelList {
28 public function getType() {
29 return 'logging';
30 }
31
32 public static function getRelationType() {
33 return 'log_id';
34 }
35
36 public static function getRestriction() {
37 return 'deletelogentry';
38 }
39
40 public static function getRevdelConstant() {
41 return LogPage::DELETED_ACTION;
42 }
43
44 public static function suggestTarget( $target, array $ids ) {
45 $result = wfGetDB( DB_REPLICA )->select( 'logging',
46 'log_type',
47 [ 'log_id' => $ids ],
48 __METHOD__,
49 [ 'DISTINCT' ]
50 );
51 if ( $result->numRows() == 1 ) {
52 // If there's only one type, the target can be set to include it.
53 return SpecialPage::getTitleFor( 'Log', $result->current()->log_type );
54 }
55
56 return SpecialPage::getTitleFor( 'Log' );
57 }
58
59 /**
60 * @param IDatabase $db
61 * @return mixed
62 */
63 public function doQuery( $db ) {
64 $ids = array_map( 'intval', $this->ids );
65
66 $commentQuery = CommentStore::newKey( 'log_comment' )->getJoin();
67
68 return $db->select(
69 [ 'logging' ] + $commentQuery['tables'],
70 [
71 'log_id',
72 'log_type',
73 'log_action',
74 'log_timestamp',
75 'log_user',
76 'log_user_text',
77 'log_namespace',
78 'log_title',
79 'log_page',
80 'log_params',
81 'log_deleted'
82 ] + $commentQuery['fields'],
83 [ 'log_id' => $ids ],
84 __METHOD__,
85 [ 'ORDER BY' => 'log_id DESC' ],
86 $commentQuery['joins']
87 );
88 }
89
90 public function newItem( $row ) {
91 return new RevDelLogItem( $this, $row );
92 }
93
94 public function getSuppressBit() {
95 return Revision::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 }