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