From 4c1c04dcae4e88b1ce698669b44ab343f41a3969 Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Thu, 10 Jan 2008 13:33:23 +0000 Subject: [PATCH] Fixing the mess that was r29539: * $wgRequest shouldn't be used in functions like Article::doEdit() that are also called by API modules * Moving code that decides whether the edit is bot out of DB logic and into UI logic: API and UI each decide indepentently from one another * Removing $bot==='default' behavior from RecentChange::notifyEdit() and notifyNew(): nobody uses it, and it shouldn't be used anyway; whether the edit is bot should've been decided long ago --- includes/Article.php | 10 +++++----- includes/EditPage.php | 10 +++++----- includes/RecentChange.php | 19 ++----------------- 3 files changed, 12 insertions(+), 27 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index bca4461392..e5f0bc7048 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -1201,7 +1201,7 @@ class Article { /** * @deprecated use Article::doEdit() */ - function insertNewArticle( $text, $summary, $isminor, $watchthis, $suppressRC=false, $comment=false ) { + function insertNewArticle( $text, $summary, $isminor, $watchthis, $suppressRC=false, $comment=false, $bot=false ) { $flags = EDIT_NEW | EDIT_DEFER_UPDATES | EDIT_AUTOSUMMARY | ( $isminor ? EDIT_MINOR : 0 ) | ( $suppressRC ? EDIT_SUPPRESS_RC : 0 ); @@ -1298,7 +1298,7 @@ class Article { * @return bool success */ function doEdit( $text, $summary, $flags = 0 ) { - global $wgUser, $wgDBtransactions, $wgRequest; + global $wgUser, $wgDBtransactions; wfProfileIn( __METHOD__ ); $good = true; @@ -1323,7 +1323,7 @@ class Article { # Silently ignore EDIT_MINOR if not allowed $isminor = ( $flags & EDIT_MINOR ) && $wgUser->isAllowed('minoredit'); - $bot = ( $wgUser->isAllowed( 'bot' ) ? $wgRequest->getBool( 'bot' , true ) : 0 ) || ( $flags & EDIT_FORCE_BOT ); + $bot = $flags & EDIT_FORCE_BOT; $oldtext = $this->getContent(); $oldsize = strlen( $oldtext ); @@ -2280,7 +2280,7 @@ class Article { * @return self::SUCCESS on succes, self::* on failure */ public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails ) { - global $wgUser, $wgUseRCPatrol, $wgRequest; + global $wgUser, $wgUseRCPatrol; $resultDetails = null; # Just in case it's being called from elsewhere @@ -2368,7 +2368,7 @@ class Article { if ($wgUser->isAllowed('minoredit')) $flags |= EDIT_MINOR; - if( $bot && $wgRequest->getBool( 'bot' , true ) ) + if( $bot ) $flags |= EDIT_FORCE_BOT; $this->doEdit( $target->getText(), $summary, $flags ); diff --git a/includes/EditPage.php b/includes/EditPage.php index 5172300725..f9764563a8 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -681,7 +681,7 @@ class EditPage { * Attempt submission (no UI) * @return one of the constants describing the result */ - function internalAttemptSave( &$result ) { + function internalAttemptSave( &$result, $bot = false ) { global $wgSpamRegex, $wgFilterCallback, $wgUser, $wgOut, $wgParser; global $wgMaxArticleSize, $wgTitle; @@ -800,7 +800,7 @@ class EditPage { $isComment = ( $this->section == 'new' ); $this->mArticle->insertNewArticle( $this->textbox1, $this->summary, - $this->minoredit, $this->watchthis, false, $isComment); + $this->minoredit, $this->watchthis, false, $isComment, $bot); wfProfileOut( $fname ); return self::AS_SUCCESS_NEW_ARTICLE; @@ -944,7 +944,7 @@ class EditPage { # update the article here if( $this->mArticle->updateArticle( $text, $this->summary, $this->minoredit, - $this->watchthis, '', $sectionanchor ) ) { + $this->watchthis, $bot, $sectionanchor ) ) { wfProfileOut( $fname ); return self::AS_SUCCESS_UPDATE; } else { @@ -2158,10 +2158,10 @@ END * @return bool false if output is done, true if the rest of the form should be displayed */ function attemptSave() { - global $wgUser, $wgOut, $wgTitle; + global $wgUser, $wgOut, $wgTitle, $wgRequest; $resultDetails = false; - $value = $this->internalAttemptSave( $resultDetails ); + $value = $this->internalAttemptSave( $resultDetails, $wgUser->isAllowed('bot') && $wgRequest->getBool('bot', true) ); if( $value == self::AS_SUCCESS_UPDATE || $value == self::AS_SUCCESS_NEW_ARTICLE ) { $this->didSave = true; diff --git a/includes/RecentChange.php b/includes/RecentChange.php index 2db82ca362..56dc91a2ae 100644 --- a/includes/RecentChange.php +++ b/includes/RecentChange.php @@ -258,19 +258,12 @@ class RecentChange # Makes an entry in the database corresponding to an edit public static function notifyEdit( $timestamp, &$title, $minor, &$user, $comment, - $oldId, $lastTimestamp, $bot = "default", $ip = '', $oldSize = 0, $newSize = 0, + $oldId, $lastTimestamp, $bot, $ip = '', $oldSize = 0, $newSize = 0, $newId = 0) { global $wgRequest; - if ( $bot === 'default' ) { - $bot = $user->isAllowed( 'bot' ); - if ( $bot ) { - $bot = $wgRequest->getBool( 'bot' , true ); - } - } - if ( !$ip ) { $ip = wfGetIP(); if ( !$ip ) { @@ -317,23 +310,15 @@ class RecentChange * Note: the title object must be loaded with the new id using resetArticleID() * @todo Document parameters and return */ - public static function notifyNew( $timestamp, &$title, $minor, &$user, $comment, $bot = 'default', + public static function notifyNew( $timestamp, &$title, $minor, &$user, $comment, $bot, $ip='', $size = 0, $newId = 0 ) { - global $wgRequest; - if ( !$ip ) { $ip = wfGetIP(); if ( !$ip ) { $ip = ''; } } - if ( $bot === 'default' ) { - $bot = $user->isAllowed( 'bot' ); - if ( $bot ) { - $bot = $wgRequest->getBool( 'bot' , true ); - } - } $rc = new RecentChange; $rc->mAttribs = array( -- 2.20.1