WARNING: HUGE COMMIT
[lhc/web/wiklou.git] / trackback.php
1 <?php
2 /**
3 * Provide functions to handle article trackbacks.
4 * @file
5 * @ingroup SpecialPage
6 */
7 require_once( './includes/WebStart.php' );
8 require_once( './includes/DatabaseFunctions.php' );
9
10 /**
11 *
12 */
13 function XMLsuccess() {
14 header("Content-Type: application/xml; charset=utf-8");
15 echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>
16 <response>
17 <error>0</error>
18 </response>
19 ";
20 exit;
21 }
22
23 function XMLerror($err = "Invalid request.") {
24 header("HTTP/1.0 400 Bad Request");
25 header("Content-Type: application/xml; charset=utf-8");
26 echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>
27 <response>
28 <error>1</error>
29 <message>Invalid request: $err</message>
30 </response>
31 ";
32 exit;
33 }
34
35 if (!$wgUseTrackbacks)
36 XMLerror("Trackbacks are disabled.");
37
38 if ( !isset($_POST['url'])
39 || !isset($_REQUEST['article']))
40 XMLerror("Required field not specified");
41
42 $dbw = wfGetDB(DB_MASTER);
43
44 $tbtitle = strval( @$_POST['title'] );
45 $tbex = strval( @$_POST['excerpt'] );
46 $tburl = strval( $_POST['url'] );
47 $tbname = strval( @$_POST['blog_name'] );
48 $tbarticle = strval( $_REQUEST['article'] );
49
50 $title = Title::newFromText($tbarticle);
51 if (!isset($title) || !$title->exists())
52 XMLerror("Specified article does not exist.");
53
54 $dbw->insert('trackbacks', array(
55 'tb_page' => $title->getArticleID(),
56 'tb_title' => $tbtitle,
57 'tb_url' => $tburl,
58 'tb_ex' => $tbex,
59 'tb_name' => $tbname
60 ));
61 $dbw->commit();
62
63 XMLsuccess();
64
65 ?>