-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
99 lines (96 loc) · 3.82 KB
/
index.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
/**
* @author Steinsplitter / https://commons.wikimedia.org/wiki/User:Steinsplitter
* @copyright 2016 GlobalUsageCount authors
* @license http://unlicense.org/ Unlicense
*/
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>GlobalUsageCount</title>
<link rel="stylesheet" href="//tools-static.wmflabs.org/cdnjs/ajax/libs/twitter-bootstrap/2.3.2/css/bootstrap.min.css">
<style>
body {
padding-top: 60px;
}
</style>
</head>
<body>
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<?php
function i18nheader($hname) {
echo " <a class=\"brand\" href=\"#\">$hname</a>
<div class=\"nav-collapse collapse\">
<ul id=\"toolbar-right\" class=\"nav pull-right\">
</ul>
</div>
</div>
</div>
</div>
<div class=\"container\"> ";
}
function i18nparser($url) {
$con = curl_init();
$to = 4;
curl_setopt($con, CURLOPT_URL, $url);
curl_setopt($con, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($con, CURLOPT_CONNECTTIMEOUT, $to);
curl_setopt($con,CURLOPT_USERAGENT,'GlobalUsageCount interface parser, running on toollabs / tools.wmflabs.org/globalusagecount');
$data = curl_exec($con);
curl_close($con);
return $data;
}
$getd2 = $_GET['lang'];
if(preg_match("/^[a-z]{1,4}(-[a-z]{1,4}|)+$/",$getd2)) {
$lang = htmlspecialchars($getd2);
} else {
$lang = "en";
}
$i18n = i18nparser('https://commons.wikimedia.org/w/index.php?title=Commons:User_scripts/GlobalUsageCount_i18n/'. $lang . '&action=raw&ctype=text');
if (strpos($i18n, 'a') === false)
{
i18nheader("GlobalUsageCount");
echo "Ooop :-(. No interface translation available for ". $lang .". <a href=\"https://commons.wikimedia.org/w/index.php?title=Special:Translate&group=page-Commons%3AUser+scripts%2FGlobalUsageCount+i18n&language=". $lang ."&action=page&filter=\">Please help with the translation!</a>";
}
else
{
$i18nhe = preg_replace("/(.+\n*<!--header:|-->(.+[.\n]*)*)/", "", $i18n);
i18nheader(htmlspecialchars($i18nhe));
$i18ntr = preg_replace("/\<noinclude\>.+\n*\<\/noinclude\>/", "", $i18n);
$esc= htmlspecialchars($i18ntr);
echo preg_replace("/\n/", "<br>", $esc);
}
echo "<br><br>\n <form class=\"input-prepend input-append\">";
echo "<span class=\"add-on\">File:</span>";
echo " <input type=\"text\" value=\"" . $lang . "\" name=\"lang\" id=\"lang\" class=\"hidden\" type=\"hidden\" style = \"display:none; visibility:hidden;\" />";
?>
<input type="text" value="" name="file" id="fast" class="input-medium appendedPrependedInput appendedInputButton"/>
<button type="submit" class="btn">🔍</button>
</form>
<br/>
<?php
$getd = $_GET['file'];
if (isset($getd)) {
$tools_pw = posix_getpwuid(posix_getuid());
$tools_mycnf = parse_ini_file($tools_pw['dir'] . "/replica.my.cnf");
$db = new mysqli('commonswiki.labsdb', $tools_mycnf['user'], $tools_mycnf['password'],
'commonswiki_p');
if ($db->connect_errno)
die("Failed to connect to the database: (" . $db->connect_errno . ") " . $db->connect_error);
$r = $db->query('SELECT COUNT(gil_page) AS count FROM globalimagelinks WHERE gil_to = "' . str_replace(" ", "_", $db->real_escape_string($getd)) . '" LIMIT 1;');
unset($tools_mycnf, $tools_pw);
}
echo "<p><big>". htmlspecialchars($getd) ."</big></p>";
$row = $r->fetch_assoc();
echo "<div style = \"text-align:center; font-size: 150px; padding: 0.5em; border-color:Black; border-style:solid; border-width:1pt\">" . $row['count'] ."</div>";
$r->close();
$db->close();
?>
</div>
</div>
</body>
</html>