forked from miraheze/CreateWiki
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDBListGenerator.php
More file actions
60 lines (46 loc) · 1.39 KB
/
DBListGenerator.php
File metadata and controls
60 lines (46 loc) · 1.39 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
<?php
require_once '/srv/mediawiki/w/maintenance/commandLine.inc';
if ( $wgDBname !== 'metawiki' ) {
throw new MWException( 'The DBname used for this script must be metawiki.' );
}
$dbw = wfGetDB( DB_MASTER );
$res = $dbw->select(
'cw_wikis',
'*',
array(),
__METHOD__
);
if ( !$res || !is_object( $res ) ) {
throw new MWException( '$res was not set to a valid array.' );
}
$DBlistPath = '/srv/mediawiki/dblist';
$allWikis = array();
$privateWikis = array();
$closedWikis = array();
foreach ( $res as $row ) {
$DBname = $row->wiki_dbname;
$siteName = $row->wiki_sitename;
$language = $row->wiki_language;
$private = $row->wiki_private;
$closed = $row->wiki_closed;
$allWikis[] = "$DBname|$siteName|$language|";
$cdb = \Cdb\Writer::open( '/srv/mediawiki/cdb-config/' . $DBname . '.cdb' );
$cdb->set( 'sitename', $siteName );
$cdb->set( 'language', $language );
if ( $private === "1" ) {
$privateWikis[] = $DBname;
$cdb->set( 'private', 1 );
} else {
$cdb->set( 'private', 0 );
}
if ( $closed === "1" ) {
$closedWikis[] = $DBname;
$cdb->set( 'closed', 1 );
} else {
$cdb->set( 'closed', 0 );
}
$cdb->close();
}
file_put_contents( "$DBlistPath/all.dblist", implode( "\n", $allWikis ), LOCK_EX );
file_put_contents( "$DBlistPath/private.dblist", implode( "\n", $privateWikis ), LOCK_EX );
file_put_contents( "$DBlistPath/closed.dblist", implode( "\n", $closedWikis ), LOCK_EX );