From 5924eb85f03b850017c66f01eed24855e31378db Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Sat, 2 May 2009 14:47:26 +0000 Subject: [PATCH] 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 --- api.php | 7 +++++++ includes/api/ApiEditPage.php | 7 +++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/api.php b/api.php index 546969f23f..8702ce15b3 100644 --- a/api.php +++ b/api.php @@ -69,6 +69,13 @@ if (!$wgEnableAPI) { die(1); } +// So extensions can check whether they're running in API mode +define('API', true); + +// Set a dummy $wgTitle, because $wgTitle == null breaks various things +// In a perfect world this wouldn't be necessary +$wgTitle = Title::newFromTitle('API'); + /* Construct an ApiMain with the arguments passed via the URL. What we get back * is some form of an ApiMain, possibly even one that produces an error message, * but we don't care here, as that is handled by the ctor. diff --git a/includes/api/ApiEditPage.php b/includes/api/ApiEditPage.php index 112083ec40..4fb21fbadd 100644 --- a/includes/api/ApiEditPage.php +++ b/includes/api/ApiEditPage.php @@ -58,6 +58,9 @@ class ApiEditPage extends ApiBase { $titleObj = Title::newFromText($params['title']); if(!$titleObj) $this->dieUsageMsg(array('invalidtitle', $params['title'])); + // Some functions depend on $wgTitle == $ep->mTitle + global $wgTitle; + $titleObj = $wgTitle; if($params['createonly'] && $titleObj->exists()) $this->dieUsageMsg(array('createonly-exists')); @@ -197,10 +200,6 @@ class ApiEditPage extends ApiBase { # Do the actual save $oldRevId = $articleObj->getRevIdFetched(); $result = null; - # *Something* is setting $wgTitle to a title corresponding to "Msg", - # but that breaks API mode detection through is_null($wgTitle) - global $wgTitle; - $wgTitle = null; # Fake $wgRequest for some hooks inside EditPage # FIXME: This interface SUCKS $oldRequest = $wgRequest; -- 2.20.1