forked from emijrp/wlm-maps
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ajaxrecentlyuploaded.php
90 lines (79 loc) · 2.81 KB
/
ajaxrecentlyuploaded.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
<?php
/* Original code: https://github.com/chillly/plaques/blob/master/ajax/ajxplaques.php
*
* Created by Chris Hill <[email protected]> and contributors.
* Adapted for Wiki Loves Monuments by Emijrp <[email protected]>
*
* This software and associated documentation files (the "Software") is
* released under the CC0 Public Domain Dedication, version 1.0, as
* published by Creative Commons. To the extent possible under law, the
* author(s) have dedicated all copyright and related and neighboring
* rights to the Software to the public domain worldwide. The Software is
* distributed WITHOUT ANY WARRANTY.
*
* If you did not receive a copy of the CC0 Public Domain Dedication
* along with the Software, see
* <http://creativecommons.org/publicdomain/zero/1.0/>
*/
ini_set('display_errors', 1);
error_reporting(E_ALL);
/*
* ajaxrecentlyuploaded.php
* returns recently uploaded images info
*/
// open the database
$dbmycnf = parse_ini_file("../replica.my.cnf");
$dbuser = $dbmycnf['user'];
$dbpass = $dbmycnf['password'];
unset($dbmycnf);
$dbhost = "s4.labsdb";
$dbname = "commonswiki_p";
try {
$db = new PDO('mysql:host='.$dbhost.';dbname='.$dbname.';charset=utf8', $dbuser, $dbpass);
} catch(PDOException $e) {
// send the PDOException message
$ajaxres=array();
$ajaxres['resp']=40;
$ajaxres['dberror']=$e->getCode();
$ajaxres['msg']=$e->getMessage();
sendajax($ajaxres);
}
try {
$limit = 4;
$sql="SELECT page_title, page_latest, rev_user_text, rev_timestamp FROM page, categorylinks, revision WHERE page_id=cl_from AND page_latest=rev_id AND page_namespace=6 AND cl_to='Images_from_Wiki_Loves_Monuments_2015' GROUP BY rev_user_text ORDER BY rev_timestamp DESC LIMIT ".$limit;
$stmt = $db->prepare($sql);
$stmt->execute();
} catch(PDOException $e) {
// send the PDOException message
$ajaxres=array();
$ajaxres['resp']=40;
$ajaxres['dberror']=$e->getCode();
$ajaxres['msg']=$e->getMessage();
sendajax($ajaxres);
}
$ajaxres=array(); // place to store the geojson result
$images=array(); // array to build up the images collection
$ajaxres['type']='ImageCollection';
// go through the list adding each one to the array to be returned
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$prop=array();
$prop['img_title']=$row['page_title'];
$prop['uploader']=$row['rev_user_text'];
$prop['upload_date']=$row['rev_timestamp'];
$prop['md5']=substr(md5($prop['img_title']),0,2);
$i=array();
$i['type']='Image';
$i['properties']=$prop;
$images[]=$i;
}
// add the features array to the end of the ajxres array
$ajaxres['images']=$images;
// tidy up the DB
$db = null;
sendajax($ajaxres); // no return from there
function sendajax($ajax) {
// encode the ajx array as json and return it.
$encoded = json_encode($ajax);
exit($encoded);
}
?>