From aac9e5198e0ff48d396951e49ce780a62f224e95 Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Wed, 28 May 2008 09:14:35 +0000 Subject: [PATCH] APIEditPage: * Moving $wgRequest faking down to below the APIEditBeforeSave hook call * Faking wpCaptcha{Id,Word} in $wgRequest for ConfirmEdit (should also be done better) Hopefully we'll be able to ditch this crappy EditPage::attemptInternalSave() interface shortly --- includes/api/ApiEditPage.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/includes/api/ApiEditPage.php b/includes/api/ApiEditPage.php index 3413ee2d29..63626abff1 100644 --- a/includes/api/ApiEditPage.php +++ b/includes/api/ApiEditPage.php @@ -93,10 +93,6 @@ class ApiEditPage extends ApiBase { $reqArr['wpMinoredit'] = ''; if($params['recreate']) $reqArr['wpRecreate'] = ''; - if(!is_null($params['captchaid'])) - $reqArr['wpCaptchaId'] = $params['captchaid']; - if(!is_null($params['captchaword'])) - $reqArr['wpCaptchaWord'] = $params['captchaword']; if(!is_null($params['section'])) { $section = intval($params['section']); @@ -124,10 +120,12 @@ class ApiEditPage extends ApiBase { $ep->importFormData($req); # Run hooks - # We need to fake $wgRequest for some of them + # Handle CAPTCHA parameters global $wgRequest; - $oldRequest = $wgRequest; - $wgRequest = $req; + if(isset($params['captchaid'])) + $wgRequest->data['wpCaptchaId'] = $params['captchaid']; + if(isset($params['captchaword'])) + $wgRequest->data['wpCaptchaWord'] = $params['captchaword']; $r = array(); if(!wfRunHooks('APIEditBeforeSave', array(&$ep, $ep->textbox1, &$r))) { @@ -140,7 +138,6 @@ class ApiEditPage extends ApiBase { else $this->dieUsageMsg(array('hookaborted')); } - $wgRequest = $oldRequest; # Do the actual save $oldRevId = $articleObj->getRevIdFetched(); @@ -149,7 +146,13 @@ class ApiEditPage extends ApiBase { # 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; + $wgRequest = $req; + $retval = $ep->internalAttemptSave($result, $wgUser->isAllowed('bot') && $params['bot']); + $wgRequest = $oldRequest; switch($retval) { case EditPage::AS_HOOK_ERROR: -- 2.20.1