r50132 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r50131‎ | r50132 | r50133 >
Date:14:47, 2 May 2009
Author:catrope
Status:ok (Comments)
Tags:
Comment:
API: Set $wgTitle to a dummy title in api.php, and introduce defined('API') as a check for API mode. This should fix errors about $wgTitle being null
Modified paths:
  • /trunk/phase3/api.php (modified) (history)
  • /trunk/phase3/includes/api/ApiEditPage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiEditPage.php
@@ -58,6 +58,9 @@
5959 $titleObj = Title::newFromText($params['title']);
6060 if(!$titleObj)
6161 $this->dieUsageMsg(array('invalidtitle', $params['title']));
 62+ // Some functions depend on $wgTitle == $ep->mTitle
 63+ global $wgTitle;
 64+ $titleObj = $wgTitle;
6265
6366 if($params['createonly'] && $titleObj->exists())
6467 $this->dieUsageMsg(array('createonly-exists'));
@@ -197,10 +200,6 @@
198201 # Do the actual save
199202 $oldRevId = $articleObj->getRevIdFetched();
200203 $result = null;
201 - # *Something* is setting $wgTitle to a title corresponding to "Msg",
202 - # but that breaks API mode detection through is_null($wgTitle)
203 - global $wgTitle;
204 - $wgTitle = null;
205204 # Fake $wgRequest for some hooks inside EditPage
206205 # FIXME: This interface SUCKS
207206 $oldRequest = $wgRequest;
Index: trunk/phase3/api.php
@@ -69,6 +69,13 @@
7070 die(1);
7171 }
7272
 73+// So extensions can check whether they're running in API mode
 74+define('API', true);
 75+
 76+// Set a dummy $wgTitle, because $wgTitle == null breaks various things
 77+// In a perfect world this wouldn't be necessary
 78+$wgTitle = Title::newFromTitle('API');
 79+
7380 /* Construct an ApiMain with the arguments passed via the URL. What we get back
7481 * is some form of an ApiMain, possibly even one that produces an error message,
7582 * but we don't care here, as that is handled by the ctor.

Follow-up revisions

RevisionCommit summaryAuthorDate
r50133Update ConfirmEdit for r50132catrope14:47, 2 May 2009
r50134Followup to r50132: I guess I was smoking some pretty good stuff therecatrope15:03, 2 May 2009
r50218Followup to r50132: rename API define constant to MW_API, per comment on CRcatrope13:22, 5 May 2009
r50220API backports:...tstarling14:07, 5 May 2009

Comments

#Comment by Tim Starling (talk | contribs)   13:07, 5 May 2009

Defines are global and should be prefixed to avoid conflicts with PHP modules. I'll let it pass for unlikely names but "API" is a bit generic.

Status & tagging log