-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql-queries.php
More file actions
324 lines (262 loc) · 9.72 KB
/
Copy pathsql-queries.php
File metadata and controls
324 lines (262 loc) · 9.72 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
<?php
//////////////////////// never_link_to table ////////////////////////////
/*
** @desc: records that a page has been visited into the database.
*/
function dbSaveNeverLinkTo($name) {
safeQuery ("INSERT INTO never_link_to (name) VALUES ('$name')");
}
/*
** @desc: returns a result set of the articles that we should never link to
*/
function dbResultSetNeverLinkToArticles() {
return safeQuery("SELECT name
FROM never_link_to");
}
//////////////////////// malformed_page table ////////////////////////////
/*
** @desc: saves a new malformed_page entry.
*/
function dbSaveMalformedPage($page_link, $page_title, $format, $context, $section = "") {
safeQuery ("INSERT INTO malformed_page (page_link,page_title,format,context,section) VALUES
('$page_link','$page_title','$format','$context','$section')");
}
//////////////////////// suggested_link table ////////////////////////////
/*
** @desc: saves a new suggested_link entry.
*/
function dbSaveSuggestedLink($source_link, $before_text, $dest_link, $dest_label, $after_text, $section = "") {
// add slashes to all args
$source_link = addslashes($source_link);
$before_text = addslashes($before_text);
$dest_link = addslashes($dest_link);
$dest_label = addslashes($dest_label);
$after_text = addslashes($after_text);
$section = addslashes($section);
// now save
safeQuery ("REPLACE INTO suggested_link (source_link,before_text,dest_link,dest_label,after_text,found,section) VALUES
('$source_link','$before_text','$dest_link','$dest_label','$after_text',now(),'$section')");
}
/*
** @desc: returns whether or not this link has been suggested before
*/
function linkHasBeenSuggestedBefore($source_link, $dest_link) {
return safeCountQuery ("SELECT count(*)
FROM suggested_link
WHERE source_link = '$source_link' AND
dest_link = '$dest_link'");
}
/*
** @desc: returns the most suggested links above a cutoff point
*/
function dbResultSetMostSuggestedLinks($cutoff) {
return safeQuery ("SELECT dest_link,
COUNT(*) AS count
FROM suggested_link
GROUP BY dest_link
ORDER BY count DESC
LIMIT $cutoff");
}
/*
** @desc: returns the suggestions that link to a page, up a certain limit.
*/
function dbResultSetGetSuggestedLinks($dest_link, $limit) {
return safeQuery ("SELECT source_link,
before_text,
dest_link,
dest_label,
after_text
FROM suggested_link
WHERE dest_link = '$dest_link'
LIMIT $limit");
}
/*
** @desc: returns all the suggestions that link from a page (i.e. the suggestions for that page).
*/
function dbResultSetGetArticleSuggestions($article) {
return safeQuery ("SELECT source_link,
before_text,
dest_link,
dest_label,
after_text,
section
FROM suggested_link
WHERE source_link = '$article' AND
save_to_source_time = '00000000000000'
ORDER BY suggested_link_id");
}
/*
** @desc: returns all the suggestions that link TO a page.
*/
function dbResultSetGetLinksToPage($article) {
return safeQuery ("SELECT source_link,
before_text,
dest_link,
dest_label,
after_text,
section
FROM suggested_link
WHERE dest_link = '$article' AND
save_to_dest_time = '00000000000000'
ORDER BY suggested_link_id");
}
/*
** @desc: deletes the suggested links to a page.
*/
function dbDeleteSuggestedLinksToPage($page_link) {
safeQuery ("DELETE from suggested_link
WHERE dest_link = '$page_link'");
}
/*
** @desc: deletes the suggested self-redirects.
*/
function dbDeleteSuggestedSelfRedirects() {
safeQuery ("DELETE from suggested_link
WHERE source_link = REPLACE(dest_link,' ','_')");
}
/*
** @desc: Records when the suggestions for links from this article were saved.
*/
function dbSaveEditHaveUploadedArticleSuggestionsFrom($page_link) {
safeQuery ("UPDATE suggested_link
SET found = found,
save_to_source_time = now()
WHERE source_link = '$page_link'");
}
/*
** @desc: Records when the suggestions for links to this article were saved.
*/
function dbSaveEditHaveUploadedArticleSuggestionsTo($page_link) {
safeQuery ("UPDATE suggested_link
SET found = found,
save_to_dest_time = now()
WHERE dest_link = '$page_link'");
}
/*
** @desc: Returns the different bits of text that point or redirect to the specified page title.
*/
function dbGetAllLabelsForDestLink($page_title) {
return safeQuery("SELECT DISTINCT(dest_label)
FROM suggested_link
WHERE dest_link = '$page_title'");
}
/////////////////////// cur table //////////////////////////////
/*
** @desc: returns the contents of the requested page.
*/
function dbGetCurContents($title) {
return safeCountQuery ("SELECT cur_text
FROM cur
WHERE cur_title = '$title' AND
cur_namespace = '0'");
}
/*
** @desc: returns the number of article titles starting with this string
*/
function dbCountNumSubstringMatchesOnName ($name) {
return safeCountQuery("SELECT count(*)
FROM cur
WHERE cur_title LIKE '$name%' AND
cur_namespace = '0'");
}
/*
** @desc: returns the number of exact article title matches
*/
function dbCountNumExactMatchesOnName ($name) {
return safeCountQuery("SELECT count(*)
FROM cur
WHERE cur_title = '$name' AND
cur_namespace = '0'");
}
/*
** @desc: returns a result set of all the article names.
*/
function dbGetAllArticleNames() {
return safeQuery ("SELECT cur_title
FROM cur
WHERE cur_namespace = '0' AND
cur_is_redirect = '0'");
}
/*
** @desc: returns a result set of all the article names and whether is disambig or not.
*/
function dbGetAllArticleNamesAndWhetherIsDisambig() {
return safeQuery ("SELECT cur_title,
cur_text LIKE '%{{disambig}}%'
FROM cur
WHERE cur_namespace = '0' AND
cur_is_redirect = '0'");
}
/*
** @desc: returns a result set of all the article names and their contents.
*/
function dbGetAllArticleNamesAndContents() {
return safeQuery ("SELECT cur_title,
cur_text
FROM cur
WHERE cur_namespace = '0' AND
cur_is_redirect = '0'
ORDER BY cur_title");
}
/*
** @desc: returns a result set of the titles of disambiguation pages.
*/
function dbResultSetDisambiguationPageTitles(){
return safeQuery ("SELECT cur_title
FROM cur
WHERE cur_namespace = '0' AND
cur_is_redirect = '0' AND
cur_text LIKE '%{{disambig}}%'");
}
/*
** @desc: returns the title & text of all redirects.
*/
function dbGetAllRedirectNamesAndContents(){
return safeQuery ("SELECT cur_title,
cur_text
FROM cur
WHERE cur_namespace = '0' AND
cur_is_redirect = '1'");
}
/*
** @desc: returns the total number of articles that we need to suggest links for.
*/
function dbCountNumArticles() {
return safeCountQuery ("SELECT COUNT(*)
FROM cur
WHERE cur_namespace = '0' AND
cur_is_redirect = '0'");
}
//////////////////////////// error_log table ////////////////////////////
/*
** @desc: saves a new entry into the error_log
*/
function dbSaveAddErrorLog ($page, $page_title_string, $type, $message, $file, $line ) {
safeQuery ("INSERT INTO error_log (script, article_title, type, message, file, line) VALUES
('$page',$page_title_string,'$type','$message','$file','$line')");
}
//////////////////////////// redirect_candidate table ////////////////////////////
/*
** @desc: saves a redirect candidate.
*/
function dbSaveAddRedirectCandidate($dest, $label, $found_on_page) {
safeQuery ("INSERT INTO redirect_candidate (dest, label, found_on_page) VALUES
('$dest','$label','$found_on_page')");
}
////////////////////////// uploaded_article_suggestions table ///////////////////
/*
** @desc: saves that the article suggestions have been uploaded.
*/
function dbSaveAddUploadedArticleSuggestions($article) {
safeQuery ("INSERT INTO uploaded_article_suggestions (article) VALUES
('$article')");
}
/*
** @desc: returns whether the article suggestions have already been uploaded.
*/
function dbCountHaveUploadedArticleSuggestions($article) {
return safeCountQuery("SELECT count(*)
FROM uploaded_article_suggestions
WHERE article = '$article'");
}
?>