Moved read only check after permissions and block so that the user doesn't think...
[mediawiki.git] / trackback.php
blob1f88af7cda4590d32c28d06018bf0f5f5af4064c
1 <?php
2 /**
3 * Provide functions to handle article trackbacks.
4 * @file
5 * @ingroup SpecialPage
6 */
8 if ( isset( $_SERVER['MW_COMPILED'] ) ) {
9 require ( 'phase3/includes/WebStart.php' );
10 } else {
11 require ( dirname( __FILE__ ) . '/includes/WebStart.php' );
14 class TrackBack {
16 private $r, $url, $title = null;
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;
29 /**
30 * @param $err string
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;
45 public function __construct() {
46 global $wgUseTrackbacks, $wgRequest;
48 if( !$wgUseTrackbacks )
49 $this->XMLerror( "Trackbacks are disabled" );
51 $this->r = $wgRequest;
53 if( !$this->r->wasPosted() ) {
54 $this->XMLerror( "Must be posted" );
57 $this->url = $wgRequest->getText( 'url' );
58 $article = $wgRequest->getText( 'article' );
60 if( !$this->url || !$article ) {
61 $this->XMLerror( "Required field not specified" );
64 $this->title = Title::newFromText( $article );
65 if( !$this->title || !$this->title->exists() ) {
66 $this->XMLerror( "Specified article does not exist." );
70 public function write() {
71 $dbw = wfGetDB( DB_MASTER );
73 $tbtitle = $this->r->getText( 'title' );
74 $tbex = $this->r->getText( 'excerpt' );
75 $tbname = $this->r->getText( 'blog_name' );
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 ));
85 $dbw->commit();
87 $this->XMLsuccess();
91 $tb = new TrackBack();
92 $tb->write();