Skip to content

Commit a6281b0

Browse files
authored
Merge pull request #168 from Mdwiki-TD/update_new
Update users.php
2 parents 4fc5013 + 828cdfc commit a6281b0

File tree

9 files changed

+66
-54
lines changed

9 files changed

+66
-54
lines changed

actions/load_request.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@
2525
function load_request()
2626
{
2727
//---
28-
$code = $_GET['code'] ?? '';
28+
$code = htmlspecialchars($_GET['code'] ?? '', ENT_QUOTES, 'UTF-8');
2929
//---
3030
if ($code == 'undefined') $code = "";
3131
//---
3232
$code = LangsTables::$L_lang_to_code[$code] ?? $code;
3333
$code_lang_name = LangsTables::$L_code_to_lang[$code] ?? '';
3434
//---
35-
$cat = $_GET['cat'] ?? '';
35+
$cat = htmlspecialchars($_GET['cat'] ?? '', ENT_QUOTES, 'UTF-8');
3636
if ($cat == 'undefined') $cat = "";
3737
//---
38-
$camp = $_GET['camp'] ?? '';
38+
$camp = htmlspecialchars($_GET['camp'] ?? '', ENT_QUOTES, 'UTF-8');
3939
//---
4040
if (empty($cat) && !empty($camp)) {
4141
$cat = TablesSql::$s_camp_to_cat[$camp] ?? $cat;

index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
//---
3838
$code_lang_name = $req['code_lang_name'];
3939
//---
40-
$tra_type = $_GET['type'] ?? '';
40+
$tra_type = htmlspecialchars($_GET['type'] ?? '', ENT_QUOTES, 'UTF-8');
4141
if ($allow_whole_translate == '0') $tra_type = 'lead';
4242
//---
4343
$cat_ch = htmlspecialchars($cat, ENT_QUOTES);

leaderboard/index.php

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,31 @@
1111
use function Leaderboard\Users\users_html;
1212

1313
echo <<<HTML
14-
<style>
15-
.border_debugx {
16-
border: 1px solid;
17-
border-radius: 5px;
18-
}
19-
</style>
14+
<style>
15+
.border_debugx {
16+
border: 1px solid;
17+
border-radius: 5px;
18+
}
19+
</style>
2020
HTML;
21+
// ---
22+
$get = filter_input(INPUT_GET, 'get', FILTER_SANITIZE_FULL_SPECIAL_CHARS) ?? '';
23+
24+
$langcode = filter_input(INPUT_GET, 'langcode', FILTER_SANITIZE_FULL_SPECIAL_CHARS) ?? '';
25+
$mainlang = filter_input(INPUT_GET, 'lang', FILTER_SANITIZE_FULL_SPECIAL_CHARS) ?? 'All';
2126

22-
$get = $_GET['get'] ?? '';
23-
$users = $_GET['user'] ?? '';
24-
$langs = $_GET['langcode'] ?? '';
27+
$mainuser = filter_input(INPUT_GET, 'user', FILTER_SANITIZE_FULL_SPECIAL_CHARS) ?? '';
28+
$year_y = filter_input(INPUT_GET, 'year', FILTER_SANITIZE_FULL_SPECIAL_CHARS) ?? 'All';
29+
$camp = filter_input(INPUT_GET, 'camp', FILTER_SANITIZE_FULL_SPECIAL_CHARS) ?? 'All';
2530

26-
if ($get == 'users' || !empty($users)) {
31+
//---
32+
if ($get == 'users' || !empty($mainuser)) {
2733
// ---
28-
echo users_html();
34+
echo users_html($mainlang, $mainuser, $year_y, $camp);
2935
// ---
30-
} elseif ($get == 'langs' || !empty($langs)) {
36+
} elseif ($get == 'langs' || !empty($langcode)) {
3137
// ---
32-
echo langs_html();
38+
echo langs_html($langcode, $year_y, $camp);
3339
// ---
3440
} elseif (!empty($_GET['camps'] ?? '')) {
3541
// http://localhost:9001/Translation_Dashboard/leaderboard.php?camps=1&test=1
@@ -47,5 +53,10 @@
4753
echo print_graph_tab_2_new();
4854
// ---
4955
} else {
50-
echo main_leaderboard();
56+
//---
57+
$user_group = filter_input(INPUT_GET, 'project', FILTER_SANITIZE_FULL_SPECIAL_CHARS)
58+
?? filter_input(INPUT_GET, 'user_group', FILTER_SANITIZE_FULL_SPECIAL_CHARS)
59+
?? 'all';
60+
//---
61+
echo main_leaderboard($year_y, $camp, $user_group);
5162
}

leaderboard/langs.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,12 @@
1515
use function Leaderboard\SubGraph\graph_data_new;
1616
use function Leaderboard\Subs\FilterForm\lead_row;
1717

18-
function langs_html()
18+
function langs_html($mainlang, $year_y, $camp)
1919
{
2020
$output = '';
2121
//---
22-
$mainlang = $_GET['langcode'] ?? "";
2322
$mainlang = rawurldecode(str_replace('_', ' ', $mainlang));
2423
//---
25-
$year_y = $_GET['year'] ?? 'All';
26-
$camp = $_GET['camp'] ?? 'All';
27-
//---
2824
$langname = LangsTables::$L_code_to_lang_name[$mainlang] ?? $mainlang;
2925
//---
3026
$u_tables = get_langs_tables($mainlang, $year_y);

leaderboard/main.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,8 @@ function print_cat_table($year, $user_group, $camp, $cat): string
8787
HTML;
8888
}
8989

90-
function main_leaderboard()
90+
function main_leaderboard($year, $camp, $user_group)
9191
{
92-
//---
93-
$year = $_GET['year'] ?? 'all';
94-
$camp = $_GET['camp'] ?? 'all';
95-
$user_group = $_GET['project'] ?? $_GET['user_group'] ?? 'all';
9692
//---
9793
$filter_form = leaderboard_filter($year, $user_group, $camp);
9894
//---

leaderboard/users.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,12 @@
1515
use function Leaderboard\SubGraph\graph_data_new;
1616
use function Leaderboard\Subs\FilterForm\lead_row;
1717

18-
function users_html()
18+
function users_html($mainlang, $mainuser, $year_y, $camp)
1919
{
2020
$output = '';
2121
//---
22-
$mainlang = $_GET['lang'] ?? 'All';
2322
$mainlang = rawurldecode(str_replace('_', ' ', $mainlang));
2423
//---
25-
$mainuser = $_GET['user'] ?? "";
26-
//---
27-
$year_y = $_GET['year'] ?? 'All';
28-
$camp = $_GET['camp'] ?? 'All';
29-
//---
3024
$u_tables = get_users_tables($mainuser, $year_y, $mainlang);
3125
//---
3226
$dd = $u_tables['dd'];
@@ -43,7 +37,17 @@ function users_html()
4337
//---
4438
$filter_data = ["user" => $mainuser, "lang" => $mainlang, "year" => $year_y, "camp" => $camp];
4539
//---
46-
$output .= lead_row($table1, $graph, "<h4 class='text-center'>User: $man</h4>", $filter_data, "user");
40+
$xtools = <<<HTML
41+
<div class="d-flex align-items-center justify-content-between">
42+
<span class='h4'>User: $man </span>
43+
<a href='https://xtools.wmflabs.org/globalcontribs/$mainuser' target='_blank'>
44+
<span class='h4'>(XTools)</span>
45+
<!-- <img src='https://xtools.wmcloud.org/build/images/logo.svg' title='Xtools' width='80px'/> -->
46+
</a>
47+
</div>
48+
HTML;
49+
//---
50+
$output .= lead_row($table1, $graph, $xtools, $filter_data, "user");
4751
//---
4852
$output .= <<<HTML
4953
<div class='card mt-1'>

results/results.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
use function Actions\LoadRequest\load_request;
1212
//---
1313
$doit = isset($_GET['doit']);
14-
//---
15-
$tra_type = $_GET['type'] ?? '';
14+
$tra_type = filter_input(INPUT_GET, 'type', FILTER_SANITIZE_FULL_SPECIAL_CHARS) ?? '';
1615
//---
1716
$req = load_request();
1817
$code = $req['code'] ?? "";
@@ -26,9 +25,6 @@
2625
$translation_button = ($GLOBALS['user_in_coord'] === true) ? '1' : '0';
2726
};
2827
//---
29-
$depth = $_GET['depth'] ?? 1;
30-
$depth = $depth * 1;
31-
//---
3228
$depth = TablesSql::$s_camp_input_depth[$camp] ?? 1;
3329
//---
3430
if (empty($code_lang_name)) $doit = false;

sitelinks.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,15 @@
55
use function Tables\TablesDir\open_td_Tables_file;
66

77
// Get request parameters with defaults
8-
$site = $_GET["site"] ?? "all";
9-
$heads_limit = $_GET["heads_limit"] ?? 50;
10-
$title_limit = $_GET["title_limit"] ?? 150;
8+
$site = htmlspecialchars($_GET['site'] ?? 'all', ENT_QUOTES, 'UTF-8');
9+
$heads_limit = filter_input(INPUT_GET, 'heads_limit', FILTER_VALIDATE_INT, [
10+
'options' => ['default' => 50, 'min_range' => 1, 'max_range' => 1000]
11+
]);
12+
13+
$title_limit = filter_input(INPUT_GET, 'title_limit', FILTER_VALIDATE_INT, [
14+
'options' => ['default' => 150, 'min_range' => 10, 'max_range' => 1000]
15+
]);
16+
1117
$items_with_no_links = isset($_GET["items_with_no_links"]) ? "checked" : "";
1218

1319
// Generate form inputs
@@ -65,7 +71,7 @@ function generateFormInputs(array $params, string $items_with_no_links): string
6571
$qids_all = $data2['qids'] ?? [];
6672

6773
// Sort QIDs by sitelinks count
68-
uasort($qids_all, fn ($a, $b) => count($b['sitelinks']) <=> count($a['sitelinks']));
74+
uasort($qids_all, fn($a, $b) => count($b['sitelinks']) <=> count($a['sitelinks']));
6975

7076
test_print("$file2: qids_all: " . count($qids_all));
7177
test_print("$file2: heads_all: " . count($heads_all));
@@ -82,11 +88,11 @@ function generateFormInputs(array $params, string $items_with_no_links): string
8288
// Filter QIDs based on user selection
8389
if ($items_with_no_links) {
8490
$heads = [];
85-
$qids_o = array_filter($qids_all, fn ($tab) => count($tab['sitelinks']) == 0);
91+
$qids_o = array_filter($qids_all, fn($tab) => count($tab['sitelinks']) == 0);
8692
} elseif (!empty($site) && $site != "all") {
8793
$notitle = false;
8894
$heads = [$site];
89-
$len_items_with_site = count(array_filter($qids_all, fn ($tab) => $tab['sitelinks'][$site] ?? false));
95+
$len_items_with_site = count(array_filter($qids_all, fn($tab) => $tab['sitelinks'][$site] ?? false));
9096
$no_site_link = $len_qids_all - $len_items_with_site;
9197
$with_site_note = " (with site: $len_items_with_site, no site link: $no_site_link)";
9298
}

translate_med/index.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
use function TranslateMed\Inserter\insertPage_inprocess;
1616
use function SQLorAPI\GetDataTab\get_td_or_sql_users_no_inprocess;
1717

18-
$coden = strtolower($_GET['code']);
19-
$title_o = $_GET['title'] ?? "";
20-
$useree = ($GLOBALS['global_username'] != '') ? $GLOBALS['global_username'] : '';
18+
$coden = strtolower(filter_input(INPUT_GET, 'code', FILTER_SANITIZE_FULL_SPECIAL_CHARS) ?? '');
19+
$title_o = filter_input(INPUT_GET, 'title', FILTER_SANITIZE_FULL_SPECIAL_CHARS) ?? '';
20+
$useree = !empty($GLOBALS['global_username']) ? $GLOBALS['global_username'] : '';
2121

2222
$users_no_inprocess = get_td_or_sql_users_no_inprocess();
2323
$users_no_inprocess = array_column($users_no_inprocess, 'user');
@@ -62,10 +62,13 @@ function go_to_translate_url($title_o, $coden, $tr_type, $cat, $camp)
6262
$coden = trim($coden);
6363
$useree = trim($useree);
6464
// title=COVID-19&code=ady&cat=RTTCovid&camp=COVID&type=lead
65-
$cat = $_GET['cat'] ?? '';
66-
$camp = $_GET['camp'] ?? '';
67-
$tr_type = $_GET['type'] ?? 'lead';
68-
$word = $_GET['word'] ?? 0;
65+
// ---
66+
$cat = filter_input(INPUT_GET, 'cat', FILTER_SANITIZE_FULL_SPECIAL_CHARS) ?? '';
67+
$camp = filter_input(INPUT_GET, 'camp', FILTER_SANITIZE_FULL_SPECIAL_CHARS) ?? '';
68+
$tr_type = filter_input(INPUT_GET, 'type', FILTER_SANITIZE_FULL_SPECIAL_CHARS) ?? 'lead';
69+
$word = filter_input(INPUT_GET, 'word', FILTER_VALIDATE_INT, [
70+
'options' => ['default' => 0, 'min_range' => 0]
71+
]);
6972
// ---
7073
$user_decoded = rawurldecode($useree);
7174
$cat = rawurldecode($cat);

0 commit comments

Comments
 (0)