Skip to content

Commit ec6d718

Browse files
authored
Merge pull request #174 from Mdwiki-TD/update_new
Update new
2 parents af1ef69 + a76f0a5 commit ec6d718

File tree

3 files changed

+123
-14
lines changed

3 files changed

+123
-14
lines changed

src/results/cats_api.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,21 @@ function fetch_category_members($cat)
6868
$cache_key = "Category_members_" . md5($cat);
6969
$cache_ttl = 3600 * 12;
7070

71-
$items = apcu_fetch($cache_key);
71+
$items = false;
72+
if (function_exists('apcu_fetch')) {
73+
$items = apcu_fetch($cache_key);
7274

73-
if (empty($items) || ($cat === "RTT" && is_array($items) && count($items) < 3000)) {
74-
apcu_delete($cache_key);
75-
$items = false;
75+
if (empty($items) || ($cat === "RTT" && is_array($items) && count($items) < 3000)) {
76+
apcu_delete($cache_key);
77+
$items = false;
78+
}
7679
}
7780
if ($items === false) {
7881
$items = fetch_category_members_api($cat);
7982
test_print("apcu_store() size:" . count($items) . " cat: $cat");
80-
apcu_store($cache_key, $items, $cache_ttl);
83+
if (function_exists('apcu_store')) {
84+
apcu_store($cache_key, $items, $cache_ttl);
85+
}
8186
} else {
8287
test_print("apcu_fetch() size:" . count($items) . " cat: $cat");
8388
}

src/results/tr_link.php

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,42 @@
55
/*
66
Usage:
77
8-
use function Results\TrLink\make_translate_link_medwiki;
8+
use function Results\TrLink\make_translate_link_medwiki; // make_translate_link_medwiki($title, $cod, $cat, $camp, $tra_type)
99
use function Results\TrLink\make_tr_link_medwiki;
1010
1111
*/
1212

1313
use Tables\SqlTables\TablesSql;
1414
use function SQLorAPI\GetDataTab\get_td_or_sql_settings;
1515

16-
$settings1 = get_td_or_sql_settings();
17-
$settings1 = array_column($settings1, 'value', 'title');
18-
// var_export($settings1);
19-
$use_mdwikicx = $settings1['use_mdwikicx'] ?? '0';
20-
21-
function make_translate_link_medwiki($title, $cod, $cat, $camp, $tra_type)
16+
function get_endpoint()
2217
{
2318
// ---
24-
global $use_mdwikicx;
19+
static $settings1 = [];
2520
// ---
26-
$campain = TablesSql::$s_cat_to_camp[$cat] ?? $cat;
21+
if (empty($settings1)) {
22+
$settings1 = get_td_or_sql_settings();
23+
$settings1 = array_column($settings1, 'value', 'title');
24+
}
25+
// ---
26+
$use_mdwikicx = $settings1['use_mdwikicx'] ?? '0';
2727
// ---
2828
$endpoint = "https://medwiki.toolforge.org/w/index.php";
2929
// ---
3030
if ($use_mdwikicx != '0') {
3131
$endpoint = "https://mdwikicx.toolforge.org/w/index.php";
3232
};
3333
// ---
34+
return $endpoint;
35+
}
36+
37+
function make_translate_link_medwiki($title, $cod, $cat, $camp, $tra_type)
38+
{
39+
// ---
40+
$endpoint = get_endpoint();
41+
// ---
42+
$campain = TablesSql::$s_cat_to_camp[$cat] ?? $cat;
43+
// ---
3444
// ?title=Special:ContentTranslation&from=mdwiki&to=ary&campaign=contributionsmenu&page=Dracunculiasis&targettitle=Dracunculiasis
3545
// ---
3646
$title = str_replace('%20', '_', $title);

src/td_tests/test_medwiki.php

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?PHP
2+
//---
3+
4+
ini_set('display_errors', 1);
5+
ini_set('display_startup_errors', 1);
6+
error_reporting(E_ALL);
7+
8+
include_once __DIR__ . '/../include_all.php';
9+
include_once __DIR__ . '/../header.php';
10+
//---
11+
use function Results\GetCats\get_mdwiki_cat_members;
12+
use function Results\TrLink\make_translate_link_medwiki; // make_translate_link_medwiki($title, $cod, $cat, $camp, $tra_type)
13+
use function TD\Render\TestPrint\test_print;
14+
//---
15+
$Category = htmlspecialchars($_GET['Category'] ?? 'World Health Organization essential medicines', ENT_QUOTES, 'UTF-8');
16+
$depth = $_GET['depth'] ?? 0;
17+
$lang = htmlspecialchars($_GET['lang'] ?? "ar", ENT_QUOTES, 'UTF-8');
18+
$tr_type = htmlspecialchars($_GET['tr_type'] ?? "lead", ENT_QUOTES, 'UTF-8');
19+
//---
20+
$members = get_mdwiki_cat_members($Category, $depth, true);
21+
//---
22+
test_print("members size:" . count($members));
23+
//---
24+
$rows = "";
25+
//---
26+
foreach ($members as $member) {
27+
$link = make_translate_link_medwiki($member, $lang, $Category, "", $tr_type);
28+
// ---
29+
$link = str_replace('/w/', '/mediawiki/', $link);
30+
// ---
31+
$rows .= <<<HTML
32+
<div class="list-group-item">
33+
<a href="$link" target="_blank">$member</a>
34+
</div>
35+
HTML;
36+
}
37+
//---
38+
//---
39+
echo <<<HTML
40+
<div class='container'>
41+
<div class='card'>
42+
<div class='card-header'>
43+
</div>
44+
<div class='card-body mb-0'>
45+
<div class='mainindex'>
46+
<form action="test_medwiki.php" method="GET">
47+
<div class="container">
48+
<div class="row">
49+
<div class="col">
50+
<div class="input-group mb-3">
51+
<div class="input-group-prepend">
52+
<span class="input-group-text">Category</span>
53+
</div>
54+
<input class="form-control" type="text" id="Category" name="Category"
55+
value="$Category" required>
56+
</div>
57+
</div>
58+
<div class="col">
59+
<div class="input-group mb-3">
60+
<div class="input-group-prepend">
61+
<span class="input-group-text">Lang</span>
62+
</div>
63+
<input class="form-control" type="text" id="lang" name="lang"
64+
value="$lang" required>
65+
</div>
66+
</div>
67+
<div class="col">
68+
<div class="input-group mb-3">
69+
<div class="input-group-prepend">
70+
<span class="input-group-text">Translation Type</span>
71+
</div>
72+
<input class="form-control" type="text" id="tr_type" name="tr_type"
73+
value="$tr_type" required>
74+
</div>
75+
</div>
76+
<div class="col">
77+
<h4 class="aligncenter">
78+
<input class="btn btn-outline-primary" type="submit" value="Start">
79+
</h4>
80+
</div>
81+
</div>
82+
</div>
83+
</form>
84+
</div>
85+
<hr>
86+
<div class="list-group list-group-numbered">
87+
$rows
88+
</div>
89+
</div>
90+
</div>
91+
</div>
92+
HTML;
93+
//---
94+
include_once __DIR__ . '/../footer.php';

0 commit comments

Comments
 (0)