r70835 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70834‎ | r70835 | r70836 >
Date:18:50, 10 August 2010
Author:demon
Status:ok (Comments)
Tags:
Comment:
Rewrite trackback.php so it looks like it was written sometime in the last 5 years. Use cool things like WebRequest too!
Modified paths:
  • /trunk/phase3/trackback.php (modified) (history)

Diff [purge]

Index: trunk/phase3/trackback.php
@@ -7,55 +7,79 @@
88
99 require_once( './includes/WebStart.php' );
1010
11 -function XMLsuccess() {
12 - header( "Content-Type: application/xml; charset=utf-8" );
13 - echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>
 11+class TrackBack {
 12+
 13+ private $r, $url, $title = null;
 14+
 15+ private function XMLsuccess() {
 16+ header( "Content-Type: application/xml; charset=utf-8" );
 17+ echo <<<XML
 18+<?xml version="1.0" encoding="utf-8"?>
1419 <response>
15 -<error>0</error>
 20+ <error>0</error>
1621 </response>
17 - ";
18 - exit;
19 -}
 22+XML;
 23+ exit;
 24+ }
2025
21 -function XMLerror( $err = "Invalid request." ) {
22 - header( "HTTP/1.0 400 Bad Request" );
23 - header( "Content-Type: application/xml; charset=utf-8" );
24 - echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>
 26+ private function XMLerror( $err = "Invalid request." ) {
 27+ header( "HTTP/1.0 400 Bad Request" );
 28+ header( "Content-Type: application/xml; charset=utf-8" );
 29+ echo <<<XML
 30+<?xml version="1.0" encoding="utf-8"?>
2531 <response>
26 -<error>1</error>
27 -<message>Invalid request: $err</message>
 32+ <error>1</error>
 33+ <message>Invalid request: $err</message>
2834 </response>
29 -";
30 - exit;
31 -}
 35+XML;
 36+ exit;
 37+ }
3238
33 -if( !$wgUseTrackbacks )
34 - XMLerror("Trackbacks are disabled.");
 39+ public function __construct() {
 40+ global $wgUseTrackbacks, $wgRequest;
3541
36 -if( !isset( $_POST['url'] )
37 - || !isset( $_REQUEST['article'] ) )
38 - XMLerror("Required field not specified");
 42+ if( !$wgUseTrackbacks && false )
 43+ $this->XMLerror( "Trackbacks are disabled" );
3944
40 -$dbw = wfGetDB( DB_MASTER );
 45+ $this->r = $wgRequest;
4146
42 -$tbtitle = strval( @$_POST['title'] );
43 -$tbex = strval( @$_POST['excerpt'] );
44 -$tburl = strval( $_POST['url'] );
45 -$tbname = strval( @$_POST['blog_name'] );
46 -$tbarticle = strval( $_REQUEST['article'] );
 47+ if( !$this->r->wasPosted() ) {
 48+ $this->XMLerror( "Must be posted" );
 49+ }
4750
48 -$title = Title::newFromText($tbarticle);
49 -if( !$title || !$title->exists() )
50 - XMLerror( "Specified article does not exist." );
 51+ $this->url = $wgRequest->getText( 'url' );
 52+ $article = $wgRequest->getText( 'article' );
5153
52 -$dbw->insert('trackbacks', array(
53 - 'tb_page' => $title->getArticleID(),
54 - 'tb_title' => $tbtitle,
55 - 'tb_url' => $tburl,
56 - 'tb_ex' => $tbex,
57 - 'tb_name' => $tbname
58 -));
 54+ if( !$this->url || !$article ) {
 55+ $this->XMLerror( "Required field not specified" );
 56+ }
5957
60 -$dbw->commit();
 58+ $this->title = Title::newFromText( $article );
 59+ if( !$this->title || !$this->title->exists() ) {
 60+ $this->XMLerror( "Specified article does not exist." );
 61+ }
 62+ }
6163
62 -XMLsuccess();
 64+ public function write() {
 65+ $dbw = wfGetDB( DB_MASTER );
 66+
 67+ $tbtitle = $this->r->getText( 'title' );
 68+ $tbex = $this->r->getText( 'excerpt' );
 69+ $tbname = $this->r->getText( 'blog_name' );
 70+
 71+ $dbw->insert('trackbacks', array(
 72+ 'tb_page' => $this->title->getArticleID(),
 73+ 'tb_title' => $tbtitle,
 74+ 'tb_url' => $this->url,
 75+ 'tb_ex' => $tbex,
 76+ 'tb_name' => $tbname
 77+ ));
 78+
 79+ $dbw->commit();
 80+
 81+ $this->XMLsuccess();
 82+ }
 83+}
 84+
 85+$tb = new TrackBack();
 86+$tb->write();

Follow-up revisions

RevisionCommit summaryAuthorDate
r78007Per CR, fix debugging code from r70835demon20:13, 7 December 2010

Comments

#Comment by Hashar (talk | contribs)   13:19, 13 November 2010

IIRC it was implemented by river to use MediaWiki as a blog platform.

I think we should just get ride of it or make it an extension.

#Comment by Nikerabbit (talk | contribs)   17:08, 13 November 2010

It's a good spam collector. Of course that's not useful feature for most people.

#Comment by 😂 (talk | contribs)   17:09, 13 November 2010

I'm in favor of moving it out to an extension.

#Comment by Bryan (talk | contribs)   10:52, 14 November 2010

In any case it does not need its own entry point. It's XML, so can be moved to an API module. (The same applies to opensearch_desc)

#Comment by 😂 (talk | contribs)   18:33, 14 November 2010

Entry points are very hard to get rid of...who knows who might still be linking to the old URL? Should remain as a dummy wrapper in either case (see for example, wiki.phtml, which is absolutely ancient)

#Comment by Catrope (talk | contribs)   20:10, 7 December 2010
-if( !$wgUseTrackbacks )
+		if( !$wgUseTrackbacks && false )

Debugging code?

#Comment by 😂 (talk | contribs)   20:14, 7 December 2010

Yeah. And this code is so unloved that nobody noticed it was broken :p

#Comment by Catrope (talk | contribs)   20:16, 7 December 2010

Looks good, marking OK.

Still think it'd be nice to separate the class file and the entry point though.

Status & tagging log