Skip to content

Commit 8313361

Browse files
authored
Merge pull request #6308 from BOINC/dpa_web25
web: Remove some globals. No functional change.
2 parents a20d695 + 2d2e78d commit 8313361

25 files changed

+65
-84
lines changed

html/inc/account.inc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ function toggle_passwd() {
5858
}
5959

6060
function create_account_form($teamid, $next_url) {
61-
global $recaptcha_public_key;
6261
form_input_hidden('next_url', $next_url);
6362

6463
if ($teamid) {

html/inc/akismet.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
1818

1919
function akismet_check($user, $post) {
20-
global $master_url;
20+
$master_url = master_url();
2121
$config = get_config();
2222
$key = parse_config($config, "<akismet_key>");
2323
if (!$key) {

html/inc/bootstrap.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ function sample_navbar(
149149
$inverse=false
150150
// white on black?
151151
) {
152-
global $master_url;
152+
$master_url = master_url();
153153

154154
$brand = "<a class=\"navbar-brand\" href=$master_url>".PROJECT."</a>";
155155
navbar_start($brand, $fixed, $inverse);

html/inc/forum_email.inc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function mail_report_list($forum, $subject, $body, $must_send=false) {
6363
//////////////////// post hidden/unhidden ///////////
6464
//
6565
function send_moderation_email($forum, $post, $thread, $explanation, $action) {
66-
global $master_url;
66+
$master_url = master_url();
6767

6868
$moderator=get_logged_in_user();
6969
$body = "";
@@ -102,7 +102,7 @@ $body
102102
function send_thread_moderation_email(
103103
$forum, $thread, $message, $action_name, $explanation
104104
) {
105-
global $master_url;
105+
$master_url = master_url();
106106

107107
$moderator = get_logged_in_user();
108108
$user = BoincUser::lookup_id($thread->owner);
@@ -162,7 +162,7 @@ Do not reply to this message.
162162
//////////////////// a user clicks the red "x" to report a post ///////////
163163
//
164164
function send_report_post_email($user, $forum, $thread, $post, $message) {
165-
global $master_url;
165+
$master_url = master_url();
166166

167167
$body = "";
168168
$owner = BoincUser::lookup_id($post->user);
@@ -218,7 +218,7 @@ because your postings have not followed our guidelines.
218218
//////////////////// a banishment vote has been started ///////////
219219
//
220220
function send_banish_vote_email($user, $duration, $reason, $end_time) {
221-
global $master_url;
221+
$master_url = master_url();
222222
$now=time();
223223
$subject = PROJECT." banishment vote underway";
224224
$vote_url = $master_url."forum_banishment_vote.php";

html/inc/host.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ function cross_project_links($host) {
8181
// and the logged in user (so show some extra fields)
8282
//
8383
function show_host($host, $user, $ipprivate) {
84-
global $config;
84+
$config = get_config();
8585
start_table();
8686
row1(tra("Computer information"));
8787
$anonymous = false;

html/inc/prefs.inc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,6 @@ global $venue_name;
288288
// in config.xml so the right default is set for minimum free disk space
289289
//
290290
function get_disk_space_config() {
291-
global $config;
292291
$config = get_config();
293292
$dp = new StdClass;
294293
$dp->disk_max_used_gb = parse_config($config, "<default_disk_max_used_gb>");

html/inc/submit_util.inc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,9 @@ function get_batch_params($batch, $wus) {
170170
// make list of WU IDs with an in-progress result
171171
$res_in_prog = BoincResult::enum_fields(
172172
'workunitid',
173-
sprintf('batch=%d and server_state=%d',
174-
$batch->id, RESULT_SERVER_STATE_IN_PROGRESS
173+
sprintf('batch=%d and server_state in (%d, %d)',
174+
$batch->id,
175+
RESULT_SERVER_STATE_IN_PROGRESS, RESULT_SERVER_STATE_OVER
175176
)
176177
);
177178
$wus_in_prog = [];

html/inc/user_util.inc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ function is_valid_user_name($name, &$reason) {
9898
}
9999

100100
function default_show_hosts() {
101-
global $config;
101+
$config = get_config();
102102
// If enable privacy by default is TRUE, then show_hosts' default
103103
// is FALSE.
104104
return parse_bool($config, "enable_privacy_by_default") ? 0 : 1;
@@ -175,16 +175,15 @@ function show_error($str) {
175175
// Else return user object
176176
//
177177
function validate_post_make_user() {
178-
global $recaptcha_private_key;
179178
$config = get_config();
180179
if (parse_bool($config, "disable_account_creation")
181180
|| parse_bool($config, "no_web_account_creation")
182181
) {
183182
error_page("Account creation is disabled");
184183
}
185184

186-
if ($recaptcha_private_key) {
187-
if (!boinc_recaptcha_isValidated($recaptcha_private_key)) {
185+
if (recaptcha_private_key()) {
186+
if (!boinc_recaptcha_isValidated(recaptcha_private_key())) {
188187
show_error(
189188
tra("Your reCAPTCHA response was not correct. Please try again.")
190189
);

html/inc/util.inc

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,22 @@ require_once("../inc/translation.inc");
2929
require_once("../inc/profile.inc");
3030
require_once("../inc/bootstrap.inc");
3131

32-
// parse config.xml (do it here for efficiency)
33-
//
34-
global $config;
35-
$config = get_config();
36-
37-
global $master_url;
38-
$master_url = parse_config($config , "<master_url>");
39-
40-
// the above 'globals' are solely for Drupal; see
41-
// https://stackoverflow.com/questions/29216392/scope-of-a-global-variable-in-drupal-module
42-
43-
$recaptcha_public_key = parse_config($config, "<recaptcha_public_key>");
44-
$recaptcha_private_key = parse_config($config, "<recaptcha_private_key>");
32+
function master_url() {
33+
return parse_config(get_config() , "<master_url>");
34+
}
35+
function recaptcha_public_key() {
36+
return parse_config(get_config(), "<recaptcha_public_key>");
37+
}
38+
function recaptcha_private_key() {
39+
return parse_config(get_config(), "<recaptcha_private_key>");
40+
}
4541

4642
// Set parameters to defaults if not defined in config.xml
4743

48-
$x = parse_config($config, "<user_country>");
44+
$x = parse_config(get_config(), "<user_country>");
4945
define('USER_COUNTRY', ($x===null)?1:(int)$x);
5046

51-
$x = parse_config($config, "<user_url>");
47+
$x = parse_config(get_config(), "<user_url>");
5248
define('USER_URL', ($x===null)?1:(int)$x);
5349

5450
// Set parameters to defaults if not defined in project.inc
@@ -163,11 +159,9 @@ function url_base() {
163159
}
164160

165161
function send_cookie($name, $value, $permanent, $ops=false) {
166-
global $master_url;
167-
168162
// the following allows independent login for projects on the same server
169163
//
170-
$url = parse_url($master_url);
164+
$url = parse_url(master_url());
171165
$path = $url['path'];
172166
if ($ops) {
173167
$path = substr($path, 0, -1);
@@ -182,8 +176,7 @@ function send_cookie($name, $value, $permanent, $ops=false) {
182176
}
183177

184178
function clear_cookie($name, $ops=false) {
185-
global $master_url;
186-
$url = parse_url($master_url);
179+
$url = parse_url(master_url());
187180
$path = $url['path'];
188181
if ($ops) {
189182
$path = substr($path, 0, -1);

html/inc/util_basic.inc

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,13 @@ function xml_error($num=-1, $msg=null, $file=null, $line=null) {
9191
exit();
9292
}
9393

94-
$g_config = null;
9594
function get_config() {
96-
global $g_config;
97-
if ($g_config == null) {
95+
static $config;
96+
if ($config == null) {
9897
$d = project_dir();
99-
$g_config = file_get_contents("$d/config.xml");
98+
$config = file_get_contents("$d/config.xml");
10099
}
101-
return $g_config;
100+
return $config;
102101
}
103102

104103
// Look for an element in a line of XML text

0 commit comments

Comments
 (0)