-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOnlyRecentRecentChangesHooks.php
More file actions
80 lines (72 loc) · 2.13 KB
/
OnlyRecentRecentChangesHooks.php
File metadata and controls
80 lines (72 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
use MediaWiki\Context\RequestContext;
use MediaWiki\Html\FormOptions;
use MediaWiki\Preferences\Hook\GetPreferencesHook;
use MediaWiki\SpecialPage\Hook\ChangesListSpecialPageQueryHook;
use MediaWiki\User\Options\UserOptionsManager;
use Wikimedia\Rdbms\IConnectionProvider;
class OnlyRecentRecentChangesHooks implements
ChangesListSpecialPageQueryHook,
GetPreferencesHook
{
private IConnectionProvider $dbProvider;
private UserOptionsManager $userOptionsManager;
public function __construct(
IConnectionProvider $dbProvider,
UserOptionsManager $userOptionsManager
) {
$this->dbProvider = $dbProvider;
$this->userOptionsManager = $userOptionsManager;
}
/**
* @see https://www.mediawiki.org/wiki/Manual:Hooks/ChangesListSpecialPageQuery
* @param string $name name of the special page, e.g. 'Watchlist'
* @param array &$tables array of tables to be queried
* @param array &$fields array of columns to select
* @param array &$conds array of WHERE conditionals for query
* @param array &$query_options array of options for the database request
* @param array &$join_conds join conditions for the tables
* @param FormOptions $opts FormOptions for this request
*/
public function onChangesListSpecialPageQuery(
$name,
&$tables,
&$fields,
&$conds,
&$query_options,
&$join_conds,
$opts
) {
if ( $this->userOptionsManager->getOption(
RequestContext::getMain()->getUser(),
'onlyrecentrecentchanges-show-only-recent-change' )
) {
$dbr = $this->dbProvider->getReplicaDatabase();
if ( !in_array( 'page', $tables ) ) {
array_unshift( $tables, 'page' );
}
$conds[] = $dbr->makeList(
[
'page_latest = rc_this_oldid',
'rc_log_action != ' . $dbr->addQuotes( '' )
],
LIST_OR
);
$join_conds['page'] = [
'LEFT JOIN',
'page_latest = rc_this_oldid'
];
}
}
/**
* @param User $user
* @param array[] &$preferences
*/
public function onGetPreferences( $user, &$preferences ) {
$preferences['onlyrecentrecentchanges-show-only-recent-change'] = [
'section' => 'rc/advancedrc',
'type' => 'toggle',
'label-message' => 'onlyrecentrecentchanges-option'
];
}
}