-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.php
106 lines (88 loc) · 3.2 KB
/
common.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
100
101
102
103
104
105
106
<?php
// common.php
//
//classes
require_once('logging.class.php');
// constants
define('OSM_HOST', 'sql-mapnik');
define('OSM_DB', 'osm_mapnik');
define('OSM_WP_TABLE', 'kentaur_osm_wp_links');
define('WP_LANG_TABLE', 'kentaur_wp_lang');
define('BLACKLIST_TABLE', 'kentaur_lang_blacklist');
define('DOWN_STATS_TABLE', 'kentaur_download_stats');
define('DOWNLOAD_OSC_FILE', 'get_osc_file.php');
//wikipedia article namespace
define('WP_ARTICLE_NS', 0);
# status in OSM_WP_TABLE
$status_arr = array(
'NOT_SET' => -1,
'OK' => 0,
'BAD_URL' => 1,
'SECTION_REF' => 2,
'DOUBLE_REF' => 3,
'NOT_FOUND' => 4,
'IS_REDIRECT' => 5,
'UNKNOWN_WIKI' => 6,
'URLDECODE_ERROR' => 7,
'COMMONS' => 8
);
# status in WP_LANG_TABLE
$st_lang = array(
'IS_IN_OSM' => 0,
'SAME_AS_OSM_NAME' => 1,
'TO_CHECK' => 2,
//'TO_UPDATE' => 3,
'UPDATED' => 4,
'ALREADY_SET' => 5,
'PERSONNAME' => 6
);
$osm_tables = array('planet_point', 'planet_line', 'planet_polygon');
// target languages to be added to OSM, array of language codes
$target_langs = array('af', 'am', 'an', 'ar', 'ast', 'az', 'ba', 'bat-smg', 'be', 'be-x-old', 'bg', 'bn', 'bpy', 'br', 'bs', 'bug', 'ca', 'ceb', 'cs', 'cv', 'cy', 'da', 'de', 'diq', 'el', 'en', 'eo', 'es', 'et', 'eu', 'fa', 'fi', 'fr', 'fy', 'ga', 'gl', 'gsw', 'gu', 'he', 'hi', 'hr', 'ht', 'hu', 'hy', 'ia', 'id', 'io', 'is', 'it', 'ja', 'jv', 'ka', 'kk', 'kn', 'ko', 'ku', 'la', 'lb', 'lmo', 'lt', 'lv', 'map-bms', 'mg', 'mk', 'ml', 'mr', 'ms', 'my', 'nap', 'nds', 'ne', 'new', 'nl', 'nn', 'no', 'oc', 'pl', 'pms', 'pnb', 'pt', 'qu', 'ro', 'roa-rup', 'ru', 'scn', 'sh', 'sk', 'sl', 'sq', 'sr', 'su', 'sv', 'sw', 'ta', 'te', 'th', 'tl', 'tr', 'tt', 'uk', 'ur', 'vi', 'vo', 'wa', 'war', 'yo', 'zh', 'zh-yue');
//functions
//
function shutdown() {
$log = new Logging();
$error_arr = error_get_last();
if($error_arr==null) {
//$log->lwrite( 'Normal shutdown.' );
} else {
$log->lwrite( 'Error: '. $error_arr['message'] );
print_r($error_arr);
}
}
//select Wikipedia db
function select_wiki_db($wiki) {
//connect to Wikipedia db in MySQL
$toolserver_mycnf = parse_ini_file("/home/".get_current_user()."/.my.cnf");
$w_db_host = $wiki. 'wiki-p.db.toolserver.org';
$w_db_name = $wiki. 'wiki_p';
$db = mysql_connect($w_db_host, $toolserver_mycnf['user'], $toolserver_mycnf['password']);
if (!$db) {
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db($w_db_name, $db);
unset($toolserver_mycnf);
return $db_selected;
} //func
/*
function strip_wp_name ($def) {
$name = '';
if (preg_match("/^'''(.+?)'''/", $def, $matches) ) {
$name = $matches[1];
}
return $name;
} //func
*/
function strip_wp_title ($title, $lang) {
$name = '';
$title = str_replace('_', ' ', $title);
//disambiguation part in titles ()
$title = preg_replace('/\s\(.+\)/', '', $title);
//in en.wp after comma
if (strcmp($lang, 'en') == 0) {
$title = preg_replace('/\,\s.+/', '', $title);
}
return $title;
} //func
?>