* (bug 6892, 7147) Trackback error handling, optional fields more robust
[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 "<?xml version=\"1.0\" encoding=\"utf-8\"?>
15 <response>
16 <error>0</error>
17 </response>
18 ";
19 exit;
20 }
21
22 function XMLerror($err = "Invalid request.") {
23 header("HTTP/1.0 400 Bad Request");
24 header("Content-Type: application/xml; charset=utf-8");
25 echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>
26 <response>
27 <error>1</error>
28 <message>Invalid request: $err</message>
29 </response>
30 ";
31 exit;
32 }
33
34 if (!$wgUseTrackbacks)
35 XMLerror("Trackbacks are disabled.");
36
37 if ( !isset($_POST['url'])
38 || !isset($_REQUEST['article']))
39 XMLerror("Required field not specified");
40
41 $dbw = wfGetDB(DB_MASTER);
42
43 $tbtitle = strval( @$_POST['title'] );
44 $tbex = strval( @$_POST['excerpt'] );
45 $tburl = strval( $_POST['url'] );
46 $tbname = strval( @$_POST['blog_name'] );
47 $tbarticle = strval( $_REQUEST['article'] );
48
49 $title = Title::newFromText($tbarticle);
50 if (!isset($title) || !$title->exists())
51 XMLerror("Specified article does not exist.");
52
53 $dbw->insert('trackbacks', array(
54 'tb_page' => $title->getArticleID(),
55 'tb_title' => $tbtitle,
56 'tb_url' => $tburl,
57 'tb_ex' => $tbex,
58 'tb_name' => $tbname
59 ));
60 $dbw->commit();
61
62 XMLsuccess();
63
64 ?>