-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.php
executable file
·76 lines (56 loc) · 1.66 KB
/
config.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
<?php
define('ROOT_DIR', __DIR__);
define('MAIN_URL', 'https://tools.wmflabs.org/dow');
require_once __DIR__.'/db.php';
require_once __DIR__.'/app/helper.php';
$_settings = $db->query('SELECT name, value FROM settings')->fetchAll();
foreach ($_settings as $row) {
$settings[$row['name']] = $row['value'];
}
unset($_settings);
$knownLangs = $settings['known_langs'] = array_unique(array_filter(explode('|', $settings['known_langs'])));
function getRuningTasks()
{
$s = `toolforge-jobs list`;
$rows = explode("\n", $s);
$tasks = [];
foreach ($rows as $row) {
$tasks[] = explode(' ', $row, 2)[0];
}
return $tasks;
}
function checkLimitTasks($prefix, $limit)
{
$tasks = getRuningTasks();
$tasks = array_filter($tasks, function($task) use ($prefix) {
return strpos($task, $prefix) === 0;
});
return count($tasks) < $limit;
}
class Widget
{
public $ident = '';
private $db = null;
private $settings = [];
function __construct($ident, $db)
{
$this->db = $db;
$this->ident = $ident;
$_settings = $db->query("SELECT name, value FROM {$this->ident}_settings")->fetchAll();
foreach ($_settings as $row) {
$this->settings[$row['name']] = $row['value'];
}
$this->settings['known_langs'] = $this->settings['known_langs'] = array_unique(array_filter(explode('|', $this->settings['known_langs'])));
}
public function getSetting($key)
{
return $this->settings[$key];
}
public function setSetting($key, $value)
{
if ($value != 'NOW()') {
$value = $this->db->quote($value);
}
$this->db->query("UPDATE {$this->ident}_settings SET value = {$value} WHERE name = {$this->db->quote($key)}");
}
}