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