Initial (tools and bot) commit
[andrew-tools.git] / tools / nth_page.php
blob6e2a3be403baaef0e213884853f1cb3cf278866d
1 <?php
2 if(!$_GET['num']){
3 echo "<form method=get action=nth_page.php>Article#:<input name=num />Wiki:<input name=db /><input type=submit /></form>";
4 exit();
6 if(!$_GET['db']){
7 echo "No DB!";
8 exit();
10 $nth = $_GET['num'];
11 $odb = $_GET['db'];
12 if(preg_match( '/^[a-z-]{1,10}\(wiktionary|wiki(|books|versity|species|source|quote))$/', $odb )){
13 echo "Invalid wiki<br/>";
14 echo "Wikis <a href='http://noc.wikimedia.org/conf/all.dblist'>here</a> will work";
15 exit();
17 $ts_pw = posix_getpwuid(posix_getuid());
18 $ts_mycnf = parse_ini_file($ts_pw['dir'] . "/.my.cnf");
19 $db = mysql_connect($odb.'-p.db.toolserver.org', $ts_mycnf['user'], $ts_mycnf['password']);
20 unset($ts_mycnf);
21 unset($ts_pw);
23 mysql_select_db($odb.'_p', $db);
25 echo "<pre>";
27 $nth=$nth-1; if($nth < 0){ $nth = 0; } // array-values are given with 1 as starting point (database counts 0 as first one)
29 /* Get the nth item */
31 $dbQuery = "
32 SELECT /* LIMIT:120 */ *
33 FROM page
34 WHERE page_namespace=0
35 AND page_is_redirect=0
36 ORDER BY page_id ASC
37 LIMIT ".$nth.",1";
39 $dbResult = mysql_query($dbQuery,$db);
41 if(!!$dbResult){
42 $a = mysql_fetch_assoc($dbResult);
43 $s =
44 "[["
45 . $a['page_title']
46 . "]]"
47 . " ("
48 . $a['page_id']
49 . ")";
50 echo htmlentities($s, ENT_NOQUOTES, "UTF-8");
51 } else {
52 echo "Can not select query: \n" . mysql_error();
55 echo "<br/><a href='nth_page.php'>back</a>";
56 echo "</pre>";