Updating license choices for installer. CC public domain dedication is deprecated...
[mediawiki.git] / trackback.php
blobf673c50877acc910282198dd63108e85d8e3fdf4
1 <?php
2 /**
3 * Provide functions to handle article trackbacks.
4 * @file
5 * @ingroup SpecialPage
6 */
8 require_once( './includes/WebStart.php' );
10 class TrackBack {
12 private $r, $url, $title = null;
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;
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;
38 public function __construct() {
39 global $wgUseTrackbacks, $wgRequest;
41 if( !$wgUseTrackbacks )
42 $this->XMLerror( "Trackbacks are disabled" );
44 $this->r = $wgRequest;
46 if( !$this->r->wasPosted() ) {
47 $this->XMLerror( "Must be posted" );
50 $this->url = $wgRequest->getText( 'url' );
51 $article = $wgRequest->getText( 'article' );
53 if( !$this->url || !$article ) {
54 $this->XMLerror( "Required field not specified" );
57 $this->title = Title::newFromText( $article );
58 if( !$this->title || !$this->title->exists() ) {
59 $this->XMLerror( "Specified article does not exist." );
63 public function write() {
64 $dbw = wfGetDB( DB_MASTER );
66 $tbtitle = $this->r->getText( 'title' );
67 $tbex = $this->r->getText( 'excerpt' );
68 $tbname = $this->r->getText( 'blog_name' );
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 ));
78 $dbw->commit();
80 $this->XMLsuccess();
84 $tb = new TrackBack();
85 $tb->write();