forked from wikimedia/mediawiki-extensions-GlobalUsage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpecialMostGloballyLinkedFiles.php
103 lines (93 loc) · 2.66 KB
/
SpecialMostGloballyLinkedFiles.php
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
/**
* Special page to list files with most global usages
*
* @file
* @ingroup SpecialPage
* @author Brian Wolff <[email protected]>
*/
class MostGloballyLinkedFilesPage extends MostimagesPage {
function __construct( $name = 'MostGloballyLinkedFiles' ) {
parent::__construct( $name );
}
/**
* Main execution function. Use the parent if we're on the right wiki.
* If we're not on a shared repo, try to redirect there.
*/
function execute( $par ) {
global $wgGlobalUsageSharedRepoWiki;
if ( GlobalUsage::onSharedRepo() ) {
parent::execute( $par );
} else {
GlobalUsage::redirectSpecialPageToSharedRepo( $this->getContext() );
}
}
/**
* Don't want to do cached handling on non-shared repo, since we only redirect.
* @return boolean
*/
function isCacheable() {
return GlobalUsage::onSharedRepo();
}
/**
* What query to do.
* @return array
*/
function getQueryInfo() {
$this->assertOnSharedRepo();
return array(
'tables' => array( 'globalimagelinks' ),
'fields' => array(
'namespace' => NS_FILE,
'title' => 'gil_to',
'value' => 'COUNT(*)'
),
'options' => array(
'GROUP BY' => 'gil_to',
'HAVING' => 'COUNT(*) > 1'
)
);
}
/**
* Make sure we are on the shared repo.
*
* This function should only be used as a paranoia check, and should never actually be hit.
* There should be actual error handling for any code path a user could hit.
*/
protected function assertOnSharedRepo() {
if ( !GlobalUsage::onSharedRepo() ) {
throw new Exception( "Special:MostGloballyLinkedFiles should only be processed on the shared repo" );
}
}
/**
* Only list this special page on the wiki that is the shared repo.
*
* @return boolean Should this be listed in Special:SpecialPages
*/
function isListed() {
return GlobalUsage::onSharedRepo();
}
/**
* In most common configs (including WMF's), this wouldn't be needed. However
* for completeness support having the shared repo db be separate from the
* globalimagelinks db.
*/
function getRecacheDB() {
global $wgGlobalUsageDatabase;
// There's no reason why we couldn't make this special page work on all wikis,
// it just doesn't really make sense to. We should be prevented from getting
// to this point by $this->isCachable(), but just to be safe:
$this->assertOnSharedRepo();
if ( $wgGlobalUsageDatabase === false || $wgGlobalUsageDatabase === wfWikiID() ) {
// We are using the local wiki
return parent::getRecacheDB();
} else {
// The global usage db could be on a different db
return wfGetDB(
DB_SLAVE,
array( $this->getName(), 'QueryPage::recache', 'vslow' ),
$wgGlobalUsageDatabase
);
}
}
}