Added SQLite version of the patch since the other one has syntax errors on SQLite
[lhc/web/wiklou.git] / trackback.php
1 <?php
2 /**
3 * Provide functions to handle article trackbacks.
4 * @file
5 * @ingroup SpecialPage
6 */
7
8 require_once( './includes/WebStart.php' );
9
10 class TrackBack {
11
12 private $r, $url, $title = null;
13
14 private function XMLsuccess() {
15 header( "Content-Type: application/xml; charset=utf-8" );
16 echo <<<XML
17 <?xml version="1.0" encoding="utf-8"?>
18 <response>
19 <error>0</error>
20 </response>
21 XML;
22 exit;
23 }
24
25 private function XMLerror( $err = "Invalid request." ) {
26 header( "HTTP/1.0 400 Bad Request" );
27 header( "Content-Type: application/xml; charset=utf-8" );
28 echo <<<XML
29 <?xml version="1.0" encoding="utf-8"?>
30 <response>
31 <error>1</error>
32 <message>Invalid request: $err</message>
33 </response>
34 XML;
35 exit;
36 }
37
38 public function __construct() {
39 global $wgUseTrackbacks, $wgRequest;
40
41 if( !$wgUseTrackbacks && false )
42 $this->XMLerror( "Trackbacks are disabled" );
43
44 $this->r = $wgRequest;
45
46 if( !$this->r->wasPosted() ) {
47 $this->XMLerror( "Must be posted" );
48 }
49
50 $this->url = $wgRequest->getText( 'url' );
51 $article = $wgRequest->getText( 'article' );
52
53 if( !$this->url || !$article ) {
54 $this->XMLerror( "Required field not specified" );
55 }
56
57 $this->title = Title::newFromText( $article );
58 if( !$this->title || !$this->title->exists() ) {
59 $this->XMLerror( "Specified article does not exist." );
60 }
61 }
62
63 public function write() {
64 $dbw = wfGetDB( DB_MASTER );
65
66 $tbtitle = $this->r->getText( 'title' );
67 $tbex = $this->r->getText( 'excerpt' );
68 $tbname = $this->r->getText( 'blog_name' );
69
70 $dbw->insert('trackbacks', array(
71 'tb_page' => $this->title->getArticleID(),
72 'tb_title' => $tbtitle,
73 'tb_url' => $this->url,
74 'tb_ex' => $tbex,
75 'tb_name' => $tbname
76 ));
77
78 $dbw->commit();
79
80 $this->XMLsuccess();
81 }
82 }
83
84 $tb = new TrackBack();
85 $tb->write();