From 47c24175d3125584517c76349503b4ecb74141a3 Mon Sep 17 00:00:00 2001 From: Sam Reed Date: Sat, 23 Jan 2010 22:26:40 +0000 Subject: [PATCH] Add/remove whitelines to increase readability in API code files --- includes/api/ApiBase.php | 3 ++ includes/api/ApiDelete.php | 7 ++--- includes/api/ApiDisabled.php | 1 - includes/api/ApiEditPage.php | 39 +++++++++++++++++++++---- includes/api/ApiEmailUser.php | 4 +-- includes/api/ApiExpandTemplates.php | 1 + includes/api/ApiFormatRaw.php | 4 +++ includes/api/ApiFormatWddx.php | 3 +- includes/api/ApiFormatYaml_spyc.php | 1 - includes/api/ApiImport.php | 4 +-- includes/api/ApiMove.php | 1 + includes/api/ApiQueryAllpages.php | 2 -- includes/api/ApiQueryCategories.php | 2 ++ includes/api/ApiQueryCategoryInfo.php | 2 ++ includes/api/ApiQueryDeletedrevs.php | 3 +- includes/api/ApiQueryDuplicateFiles.php | 3 ++ includes/api/ApiQueryExternalLinks.php | 2 ++ includes/api/ApiQueryImages.php | 1 + includes/api/ApiQueryLangLinks.php | 1 + includes/api/ApiQueryUserInfo.php | 10 +++++++ includes/api/ApiQueryUsers.php | 2 +- includes/api/ApiQueryWatchlistRaw.php | 3 ++ includes/api/ApiResult.php | 21 +++++++------ includes/api/ApiUndelete.php | 2 ++ includes/api/ApiUpload.php | 4 +-- includes/api/ApiUserrights.php | 5 ++-- includes/api/ApiWatch.php | 4 +++ 27 files changed, 94 insertions(+), 41 deletions(-) diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index 785715c67b..2ad41065ae 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -657,13 +657,16 @@ abstract class ApiBase { return array(); $sizeLimit = $this->mMainModule->canApiHighLimits() ? self::LIMIT_SML2 : self::LIMIT_SML1; $valuesList = explode( '|', $value, $sizeLimit + 1 ); + if ( self::truncateArray( $valuesList, $sizeLimit ) ) { $this->setWarning( "Too many values supplied for parameter '$valueName': the limit is $sizeLimit" ); } + if ( !$allowMultiple && count( $valuesList ) != 1 ) { $possibleValues = is_array( $allowedValues ) ? "of '" . implode( "', '", $allowedValues ) . "'" : ''; $this->dieUsage( "Only one $possibleValues is allowed for parameter '$valueName'", "multival_$valueName" ); } + if ( is_array( $allowedValues ) ) { # Check for unknown values $unknown = array_diff( $valuesList, $allowedValues ); diff --git a/includes/api/ApiDelete.php b/includes/api/ApiDelete.php index bffbfc8278..35365fafd2 100644 --- a/includes/api/ApiDelete.php +++ b/includes/api/ApiDelete.php @@ -27,7 +27,6 @@ if ( !defined( 'MEDIAWIKI' ) ) { require_once ( "ApiBase.php" ); } - /** * API module that facilitates deleting pages. The API eqivalent of action=delete. * Requires API write mode to be enabled. @@ -74,15 +73,13 @@ class ApiDelete extends ApiBase { if ( $titleObj->getNamespace() == NS_FILE ) { $retval = self::deleteFile( $params['token'], $titleObj, $params['oldimage'], $reason, false ); if ( count( $retval ) ) - // We don't care about multiple errors, just report one of them - $this->dieUsageMsg( reset( $retval ) ); + $this->dieUsageMsg( reset( $retval ) ); // We don't care about multiple errors, just report one of them } else { $articleObj = new Article( $titleObj ); $retval = self::delete( $articleObj, $params['token'], $reason ); if ( count( $retval ) ) - // We don't care about multiple errors, just report one of them - $this->dieUsageMsg( reset( $retval ) ); + $this->dieUsageMsg( reset( $retval ) ); // We don't care about multiple errors, just report one of them if ( $params['watch'] || $wgUser->getOption( 'watchdeletion' ) ) $articleObj->doWatch(); diff --git a/includes/api/ApiDisabled.php b/includes/api/ApiDisabled.php index 21e8f97a60..a19a6d4f38 100644 --- a/includes/api/ApiDisabled.php +++ b/includes/api/ApiDisabled.php @@ -27,7 +27,6 @@ if ( !defined( 'MEDIAWIKI' ) ) { require_once ( "ApiBase.php" ); } - /** * API module that dies with an error immediately. * diff --git a/includes/api/ApiEditPage.php b/includes/api/ApiEditPage.php index 8c71bd62de..27d07c2214 100644 --- a/includes/api/ApiEditPage.php +++ b/includes/api/ApiEditPage.php @@ -44,14 +44,18 @@ class ApiEditPage extends ApiBase { public function execute() { global $wgUser; $params = $this->extractRequestParams(); + if ( is_null( $params['title'] ) ) $this->dieUsageMsg( array( 'missingparam', 'title' ) ); + if ( is_null( $params['text'] ) && is_null( $params['appendtext'] ) && is_null( $params['prependtext'] ) && $params['undo'] == 0 ) $this->dieUsageMsg( array( 'missingtext' ) ); + if ( is_null( $params['token'] ) ) $this->dieUsageMsg( array( 'missingparam', 'token' ) ); + if ( !$wgUser->matchEditToken( $params['token'] ) ) $this->dieUsageMsg( array( 'sessionfailure' ) ); @@ -113,14 +117,17 @@ class ApiEditPage extends ApiBase { $undoRev = Revision::newFromID( $params['undo'] ); if ( is_null( $undoRev ) || $undoRev->isDeleted( Revision::DELETED_TEXT ) ) $this->dieUsageMsg( array( 'nosuchrevid', $params['undo'] ) ); + if ( $params['undoafter'] == 0 ) $undoafterRev = $undoRev->getPrevious(); if ( is_null( $undoafterRev ) || $undoafterRev->isDeleted( Revision::DELETED_TEXT ) ) $this->dieUsageMsg( array( 'nosuchrevid', $params['undoafter'] ) ); + if ( $undoRev->getPage() != $articleObj->getID() ) $this->dieUsageMsg( array( 'revwrongpage', $undoRev->getID(), $titleObj->getPrefixedText() ) ); if ( $undoafterRev->getPage() != $articleObj->getID() ) $this->dieUsageMsg( array( 'revwrongpage', $undoafterRev->getID(), $titleObj->getPrefixedText() ) ); + $newtext = $articleObj->getUndoText( $undoRev, $undoafterRev ); if ( $newtext === false ) $this->dieUsageMsg( array( 'undo-failure' ) ); @@ -132,9 +139,8 @@ class ApiEditPage extends ApiBase { } # See if the MD5 hash checks out - if ( !is_null( $params['md5'] ) ) - if ( md5( $toMD5 ) !== $params['md5'] ) - $this->dieUsageMsg( array( 'hashcheckfailed' ) ); + if ( !is_null( $params['md5'] ) && md5( $toMD5 ) !== $params['md5'] ) + $this->dieUsageMsg( array( 'hashcheckfailed' ) ); $ep = new EditPage( $articleObj ); // EditPage wants to parse its stuff from a WebRequest @@ -143,23 +149,28 @@ class ApiEditPage extends ApiBase { 'wpEditToken' => $params['token'], 'wpIgnoreBlankSummary' => '' ); + if ( !is_null( $params['summary'] ) ) $reqArr['wpSummary'] = $params['summary']; + # Watch out for basetimestamp == '' # wfTimestamp() treats it as NOW, almost certainly causing an edit conflict if ( !is_null( $params['basetimestamp'] ) && $params['basetimestamp'] != '' ) $reqArr['wpEdittime'] = wfTimestamp( TS_MW, $params['basetimestamp'] ); else $reqArr['wpEdittime'] = $articleObj->getTimestamp(); + if ( !is_null( $params['starttimestamp'] ) && $params['starttimestamp'] != '' ) $reqArr['wpStarttime'] = wfTimestamp( TS_MW, $params['starttimestamp'] ); else - # Fake wpStartime - $reqArr['wpStarttime'] = $reqArr['wpEdittime']; + $reqArr['wpStarttime'] = $reqArr['wpEdittime']; # Fake wpStartime + if ( $params['minor'] || ( !$params['notminor'] && $wgUser->getOption( 'minordefault' ) ) ) $reqArr['wpMinoredit'] = ''; + if ( $params['recreate'] ) $reqArr['wpRecreate'] = ''; + if ( !is_null( $params['section'] ) ) { $section = intval( $params['section'] ); @@ -208,6 +219,7 @@ class ApiEditPage extends ApiBase { $wgRequest->setVal( 'wpCaptchaId', $params['captchaid'] ); if ( !is_null( $params['captchaword'] ) ) $wgRequest->setVal( 'wpCaptchaWord', $params['captchaword'] ); + $r = array(); if ( !wfRunHooks( 'APIEditBeforeSave', array( $ep, $ep->textbox1, &$r ) ) ) { @@ -236,39 +248,55 @@ class ApiEditPage extends ApiBase { case EditPage::AS_HOOK_ERROR: case EditPage::AS_HOOK_ERROR_EXPECTED: $this->dieUsageMsg( array( 'hookaborted' ) ); + case EditPage::AS_IMAGE_REDIRECT_ANON: $this->dieUsageMsg( array( 'noimageredirect-anon' ) ); + case EditPage::AS_IMAGE_REDIRECT_LOGGED: $this->dieUsageMsg( array( 'noimageredirect-logged' ) ); + case EditPage::AS_SPAM_ERROR: $this->dieUsageMsg( array( 'spamdetected', $result['spam'] ) ); + case EditPage::AS_FILTERING: $this->dieUsageMsg( array( 'filtered' ) ); + case EditPage::AS_BLOCKED_PAGE_FOR_USER: $this->dieUsageMsg( array( 'blockedtext' ) ); + case EditPage::AS_MAX_ARTICLE_SIZE_EXCEEDED: case EditPage::AS_CONTENT_TOO_BIG: global $wgMaxArticleSize; $this->dieUsageMsg( array( 'contenttoobig', $wgMaxArticleSize ) ); + case EditPage::AS_READ_ONLY_PAGE_ANON: $this->dieUsageMsg( array( 'noedit-anon' ) ); + case EditPage::AS_READ_ONLY_PAGE_LOGGED: $this->dieUsageMsg( array( 'noedit' ) ); + case EditPage::AS_READ_ONLY_PAGE: $this->dieReadOnly(); + case EditPage::AS_RATE_LIMITED: $this->dieUsageMsg( array( 'actionthrottledtext' ) ); + case EditPage::AS_ARTICLE_WAS_DELETED: $this->dieUsageMsg( array( 'wasdeleted' ) ); + case EditPage::AS_NO_CREATE_PERMISSION: $this->dieUsageMsg( array( 'nocreate-loggedin' ) ); + case EditPage::AS_BLANK_ARTICLE: $this->dieUsageMsg( array( 'blankpage' ) ); + case EditPage::AS_CONFLICT_DETECTED: $this->dieUsageMsg( array( 'editconflict' ) ); + # case EditPage::AS_SUMMARY_NEEDED: Can't happen since we set wpIgnoreBlankSummary case EditPage::AS_TEXTBOX_EMPTY: $this->dieUsageMsg( array( 'emptynewsection' ) ); + case EditPage::AS_SUCCESS_NEW_ARTICLE: $r['new'] = ''; case EditPage::AS_SUCCESS_UPDATE: @@ -291,6 +319,7 @@ class ApiEditPage extends ApiBase { $newArticle->getTimestamp() ); } break; + case EditPage::AS_END: # This usually means some kind of race condition # or DB weirdness occurred. Fall through to throw an unknown diff --git a/includes/api/ApiEmailUser.php b/includes/api/ApiEmailUser.php index cf56c5e880..469fe37b82 100644 --- a/includes/api/ApiEmailUser.php +++ b/includes/api/ApiEmailUser.php @@ -27,7 +27,6 @@ if ( !defined( 'MEDIAWIKI' ) ) { require_once ( "ApiBase.php" ); } - /** * @ingroup API */ @@ -61,8 +60,7 @@ class ApiEmailUser extends ApiBase { $error = EmailUserForm::getPermissionsError( $wgUser, $params['token'] ); if ( $error ) $this->dieUsageMsg( array( $error ) ); - - + $form = new EmailUserForm( $targetUser, $params['text'], $params['subject'], $params['ccme'] ); $retval = $form->doSubmit(); if ( is_null( $retval ) ) diff --git a/includes/api/ApiExpandTemplates.php b/includes/api/ApiExpandTemplates.php index 0ddd62a78a..587664570c 100644 --- a/includes/api/ApiExpandTemplates.php +++ b/includes/api/ApiExpandTemplates.php @@ -55,6 +55,7 @@ class ApiExpandTemplates extends ApiBase { // Parse text global $wgParser; $options = new ParserOptions(); + if ( $params['generatexml'] ) { $wgParser->startExternalParse( $title_obj, $options, OT_PREPROCESS ); diff --git a/includes/api/ApiFormatRaw.php b/includes/api/ApiFormatRaw.php index be646df01f..ee8f573cd0 100644 --- a/includes/api/ApiFormatRaw.php +++ b/includes/api/ApiFormatRaw.php @@ -46,10 +46,13 @@ class ApiFormatRaw extends ApiFormatBase { public function getMimeType() { $data = $this->getResultData(); + if ( isset( $data['error'] ) ) return $this->mErrorFallback->getMimeType(); + if ( !isset( $data['mime'] ) ) ApiBase::dieDebug( __METHOD__, "No MIME type set for raw formatter" ); + return $data['mime']; } @@ -60,6 +63,7 @@ class ApiFormatRaw extends ApiFormatBase { $this->mErrorFallback->execute(); return; } + if ( !isset( $data['text'] ) ) ApiBase::dieDebug( __METHOD__, "No text given for raw formatter" ); $this->printText( $data['text'] ); diff --git a/includes/api/ApiFormatWddx.php b/includes/api/ApiFormatWddx.php index 117f2225d7..9b382081e3 100644 --- a/includes/api/ApiFormatWddx.php +++ b/includes/api/ApiFormatWddx.php @@ -80,8 +80,7 @@ class ApiFormatWddx extends ApiFormatBase { if ( $cnt == 0 || array_keys( $elemValue ) === range( 0, $cnt - 1 ) ) { // Regular array $this->printText( $indstr . Xml::element( 'array', array( - 'length' => $cnt - ), null ) . $nl ); + 'length' => $cnt ), null ) . $nl ); foreach ( $elemValue as $subElemValue ) $this->slowWddxPrinter( $subElemValue, $indent + 2 ); $this->printText( "$indstr$nl" ); diff --git a/includes/api/ApiFormatYaml_spyc.php b/includes/api/ApiFormatYaml_spyc.php index 47c84807b7..3f375eb5c2 100644 --- a/includes/api/ApiFormatYaml_spyc.php +++ b/includes/api/ApiFormatYaml_spyc.php @@ -159,7 +159,6 @@ class Spyc { strpos( $value, "\n" ) || preg_match( "/[#:]/", $value ) || preg_match( "/^[-?,[\]{}!*&|>'\"%@`]/", $value ) ) ); - } /** diff --git a/includes/api/ApiImport.php b/includes/api/ApiImport.php index 2633bbe542..a57217f521 100644 --- a/includes/api/ApiImport.php +++ b/includes/api/ApiImport.php @@ -91,8 +91,8 @@ class ApiImport extends ApiBase { $result->mByte . $result->mContext, xml_error_string( $result->mXmlError ) ) ); else if ( WikiError::isError( $result ) ) - // This shouldn't happen - $this->dieUsageMsg( array( 'import-unknownerror', $result->getMessage() ) ); + $this->dieUsageMsg( array( 'import-unknownerror', $result->getMessage() ) ); // This shouldn't happen + $resultData = $reporter->getData(); $this->getResult()->setIndexedTagName( $resultData, 'page' ); $this->getResult()->addValue( null, $this->getModuleName(), $resultData ); diff --git a/includes/api/ApiMove.php b/includes/api/ApiMove.php index 6512e903c8..8d0f94b8f0 100644 --- a/includes/api/ApiMove.php +++ b/includes/api/ApiMove.php @@ -63,6 +63,7 @@ class ApiMove extends ApiBase { if ( !$fromTitle ) $this->dieUsageMsg( array( 'nosuchpageid', $params['fromid'] ) ); } + if ( !$fromTitle->exists() ) $this->dieUsageMsg( array( 'notanarticle' ) ); $fromTalk = $fromTitle->getTalkPage(); diff --git a/includes/api/ApiQueryAllpages.php b/includes/api/ApiQueryAllpages.php index 0d3572adce..e2da777eb8 100644 --- a/includes/api/ApiQueryAllpages.php +++ b/includes/api/ApiQueryAllpages.php @@ -137,8 +137,6 @@ class ApiQueryAllpages extends ApiQueryGeneratorBase { if ( $forceNameTitleIndex ) $this->addOption( 'USE INDEX', 'name_title' ); - - $limit = $params['limit']; $this->addOption( 'LIMIT', $limit + 1 ); $res = $this->select( __METHOD__ ); diff --git a/includes/api/ApiQueryCategories.php b/includes/api/ApiQueryCategories.php index 71d5a6fcf9..ca0d6d9fca 100644 --- a/includes/api/ApiQueryCategories.php +++ b/includes/api/ApiQueryCategories.php @@ -79,6 +79,7 @@ class ApiQueryCategories extends ApiQueryGeneratorBase { } $this->addWhereFld( 'cl_to', $cats ); } + if ( !is_null( $params['continue'] ) ) { $cont = explode( '|', $params['continue'] ); if ( count( $cont ) != 2 ) @@ -90,6 +91,7 @@ class ApiQueryCategories extends ApiQueryGeneratorBase { "(cl_from = $clfrom AND " . "cl_to >= '$clto')" ); } + if ( isset( $show['hidden'] ) && isset( $show['!hidden'] ) ) $this->dieUsage( "Incorrect parameter - mutually exclusive values may not be supplied", 'show' ); if ( isset( $show['hidden'] ) || isset( $show['!hidden'] ) || isset( $prop['hidden'] ) ) diff --git a/includes/api/ApiQueryCategoryInfo.php b/includes/api/ApiQueryCategoryInfo.php index 47cb3f2bac..2a21fc2c45 100644 --- a/includes/api/ApiQueryCategoryInfo.php +++ b/includes/api/ApiQueryCategoryInfo.php @@ -65,8 +65,10 @@ class ApiQueryCategoryInfo extends ApiQueryBase { 'pp_page=page_id', 'pp_propname' => 'hiddencat' ) ), ) ); + $this->addFields( array( 'cat_title', 'cat_pages', 'cat_subcats', 'cat_files', 'pp_propname AS cat_hidden' ) ); $this->addWhere( array( 'cat_title' => $cattitles ) ); + if ( !is_null( $params['continue'] ) ) { $title = $this->getDB()->addQuotes( $params['continue'] ); diff --git a/includes/api/ApiQueryDeletedrevs.php b/includes/api/ApiQueryDeletedrevs.php index 10f068ae9e..11bfba2fdb 100644 --- a/includes/api/ApiQueryDeletedrevs.php +++ b/includes/api/ApiQueryDeletedrevs.php @@ -202,8 +202,7 @@ class ApiQueryDeletedrevs extends ApiQueryBase { $rev['user'] = $row->ar_user_text; if ( $fld_comment ) $rev['comment'] = $row->ar_comment; - if ( $fld_minor ) - if ( $row->ar_minor_edit == 1 ) + if ( $fld_minor && $row->ar_minor_edit == 1) $rev['minor'] = ''; if ( $fld_len ) $rev['len'] = $row->ar_len; diff --git a/includes/api/ApiQueryDuplicateFiles.php b/includes/api/ApiQueryDuplicateFiles.php index 11b8ac68c6..9d5484b77d 100644 --- a/includes/api/ApiQueryDuplicateFiles.php +++ b/includes/api/ApiQueryDuplicateFiles.php @@ -63,11 +63,13 @@ class ApiQueryDuplicateFiles extends ApiQueryGeneratorBase { 'i2.img_user_text AS dup_user_text', 'i2.img_timestamp AS dup_timestamp' ) ); + $this->addWhere( array( 'i1.img_name' => array_keys( $images ), 'i1.img_sha1 = i2.img_sha1', 'i1.img_name != i2.img_name', ) ); + if ( isset( $params['continue'] ) ) { $cont = explode( '|', $params['continue'] ); @@ -80,6 +82,7 @@ class ApiQueryDuplicateFiles extends ApiQueryGeneratorBase { "(i1.img_name = '$orig' AND " . "i2.img_name >= '$dup')" ); } + $this->addOption( 'ORDER BY', 'i1.img_name' ); $this->addOption( 'LIMIT', $params['limit'] + 1 ); diff --git a/includes/api/ApiQueryExternalLinks.php b/includes/api/ApiQueryExternalLinks.php index 25c3077d21..b2410c3afb 100644 --- a/includes/api/ApiQueryExternalLinks.php +++ b/includes/api/ApiQueryExternalLinks.php @@ -51,9 +51,11 @@ class ApiQueryExternalLinks extends ApiQueryBase { $this->addTables( 'externallinks' ); $this->addWhereFld( 'el_from', array_keys( $this->getPageSet()->getGoodTitles() ) ); + # Don't order by el_from if it's constant in the WHERE clause if ( count( $this->getPageSet()->getGoodTitles() ) != 1 ) $this->addOption( 'ORDER BY', 'el_from' ); + $this->addOption( 'LIMIT', $params['limit'] + 1 ); if ( !is_null( $params['offset'] ) ) $this->addOption( 'OFFSET', $params['offset'] ); diff --git a/includes/api/ApiQueryImages.php b/includes/api/ApiQueryImages.php index 84bfe2c348..3f403305df 100644 --- a/includes/api/ApiQueryImages.php +++ b/includes/api/ApiQueryImages.php @@ -71,6 +71,7 @@ class ApiQueryImages extends ApiQueryGeneratorBase { "(il_from = $ilfrom AND " . "il_to >= '$ilto')" ); } + # Don't order by il_from if it's constant in the WHERE clause if ( count( $this->getPageSet()->getGoodTitles() ) == 1 ) $this->addOption( 'ORDER BY', 'il_to' ); diff --git a/includes/api/ApiQueryLangLinks.php b/includes/api/ApiQueryLangLinks.php index 0e7c8b52b5..9180c00f4f 100644 --- a/includes/api/ApiQueryLangLinks.php +++ b/includes/api/ApiQueryLangLinks.php @@ -63,6 +63,7 @@ class ApiQueryLangLinks extends ApiQueryBase { "(ll_from = $llfrom AND " . "ll_lang >= '$lllang')" ); } + # Don't order by ll_from if it's constant in the WHERE clause if ( count( $this->getPageSet()->getGoodTitles() ) == 1 ) $this->addOption( 'ORDER BY', 'll_lang' ); diff --git a/includes/api/ApiQueryUserInfo.php b/includes/api/ApiQueryUserInfo.php index afb0c0898c..62ee76d55f 100644 --- a/includes/api/ApiQueryUserInfo.php +++ b/includes/api/ApiQueryUserInfo.php @@ -62,24 +62,29 @@ class ApiQueryUserInfo extends ApiQueryBase { if ( $wgUser->isAnon() ) $vals['anon'] = ''; + if ( isset( $this->prop['blockinfo'] ) ) { if ( $wgUser->isBlocked() ) { $vals['blockedby'] = User::whoIs( $wgUser->blockedBy() ); $vals['blockreason'] = $wgUser->blockedFor(); } } + if ( isset( $this->prop['hasmsg'] ) && $wgUser->getNewtalk() ) { $vals['messages'] = ''; } + if ( isset( $this->prop['groups'] ) ) { $vals['groups'] = $wgUser->getGroups(); $result->setIndexedTagName( $vals['groups'], 'g' ); // even if empty } + if ( isset( $this->prop['rights'] ) ) { // User::getRights() may return duplicate values, strip them $vals['rights'] = array_values( array_unique( $wgUser->getRights() ) ); $result->setIndexedTagName( $vals['rights'], 'r' ); // even if empty } + if ( isset( $this->prop['changeablegroups'] ) ) { $vals['changeablegroups'] = $wgUser->changeableGroups(); $result->setIndexedTagName( $vals['changeablegroups']['add'], 'g' ); @@ -87,18 +92,23 @@ class ApiQueryUserInfo extends ApiQueryBase { $result->setIndexedTagName( $vals['changeablegroups']['add-self'], 'g' ); $result->setIndexedTagName( $vals['changeablegroups']['remove-self'], 'g' ); } + if ( isset( $this->prop['options'] ) ) { $vals['options'] = $wgUser->getOptions(); } + if ( isset( $this->prop['preferencestoken'] ) && is_null( $this->getMain()->getRequest()->getVal( 'callback' ) ) ) { $vals['preferencestoken'] = $wgUser->editToken(); } + if ( isset( $this->prop['editcount'] ) ) { $vals['editcount'] = intval( $wgUser->getEditCount() ); } + if ( isset( $this->prop['ratelimits'] ) ) { $vals['ratelimits'] = $this->getRateLimits(); } + if ( isset( $this->prop['email'] ) ) { $vals['email'] = $wgUser->getEmail(); $auth = $wgUser->getEmailAuthenticationTimestamp(); diff --git a/includes/api/ApiQueryUsers.php b/includes/api/ApiQueryUsers.php index fcab4a9a92..929ff33039 100644 --- a/includes/api/ApiQueryUsers.php +++ b/includes/api/ApiQueryUsers.php @@ -33,7 +33,6 @@ if ( !defined( 'MEDIAWIKI' ) ) { * * @ingroup API */ - class ApiQueryUsers extends ApiQueryBase { public function __construct( $query, $moduleName ) { @@ -104,6 +103,7 @@ if ( !defined( 'MEDIAWIKI' ) ) { else $goodNames[] = $n; } + if ( count( $goodNames ) ) { $db = $this->getDb(); diff --git a/includes/api/ApiQueryWatchlistRaw.php b/includes/api/ApiQueryWatchlistRaw.php index 1d3af83643..ab0957268b 100644 --- a/includes/api/ApiQueryWatchlistRaw.php +++ b/includes/api/ApiQueryWatchlistRaw.php @@ -68,6 +68,7 @@ class ApiQueryWatchlistRaw extends ApiQueryGeneratorBase { $this->addWhereFld( 'wl_namespace', $params['namespace'] ); $this->addWhereIf( 'wl_notificationtimestamp IS NOT NULL', isset( $show['changed'] ) ); $this->addWhereIf( 'wl_notificationtimestamp IS NULL', isset( $show['!changed'] ) ); + if ( isset( $params['continue'] ) ) { $cont = explode( '|', $params['continue'] ); @@ -80,6 +81,7 @@ class ApiQueryWatchlistRaw extends ApiQueryGeneratorBase { "(wl_namespace = '$ns' AND " . "wl_title >= '$title')" ); } + // Don't ORDER BY wl_namespace if it's constant in the WHERE clause if ( count( $params['namespace'] ) == 1 ) $this->addOption( 'ORDER BY', 'wl_title' ); @@ -101,6 +103,7 @@ class ApiQueryWatchlistRaw extends ApiQueryGeneratorBase { break; } $t = Title::makeTitle( $row->wl_namespace, $row->wl_title ); + if ( is_null( $resultPageSet ) ) { $vals = array(); diff --git a/includes/api/ApiResult.php b/includes/api/ApiResult.php index 25b8c77478..58cfd7d27d 100644 --- a/includes/api/ApiResult.php +++ b/includes/api/ApiResult.php @@ -199,17 +199,16 @@ class ApiResult extends ApiBase { * @param $arr array * @param $tag string Tag name */ - public function setIndexedTagName_recursive( &$arr, $tag ) - { - if ( !is_array( $arr ) ) - return; - foreach ( $arr as &$a ) - { - if ( !is_array( $a ) ) - continue; - $this->setIndexedTagName( $a, $tag ); - $this->setIndexedTagName_recursive( $a, $tag ); - } + public function setIndexedTagName_recursive( &$arr, $tag ) { + if ( !is_array( $arr ) ) + return; + foreach ( $arr as &$a ) + { + if ( !is_array( $a ) ) + continue; + $this->setIndexedTagName( $a, $tag ); + $this->setIndexedTagName_recursive( $a, $tag ); + } } /** diff --git a/includes/api/ApiUndelete.php b/includes/api/ApiUndelete.php index 8a8513d367..a0e6e9b5a2 100644 --- a/includes/api/ApiUndelete.php +++ b/includes/api/ApiUndelete.php @@ -48,8 +48,10 @@ class ApiUndelete extends ApiBase { if ( !$wgUser->isAllowed( 'undelete' ) ) $this->dieUsageMsg( array( 'permdenied-undelete' ) ); + if ( $wgUser->isBlocked() ) $this->dieUsageMsg( array( 'blockedtext' ) ); + if ( !$wgUser->matchEditToken( $params['token'] ) ) $this->dieUsageMsg( array( 'sessionfailure' ) ); diff --git a/includes/api/ApiUpload.php b/includes/api/ApiUpload.php index e0b01c2c0f..8bebedb7a0 100644 --- a/includes/api/ApiUpload.php +++ b/includes/api/ApiUpload.php @@ -50,7 +50,6 @@ class ApiUpload extends ApiBase { if ( !$wgUser->matchEditToken( $this->mParams['token'] ) ) $this->dieUsageMsg( array( 'sessionfailure' ) ); - // Add the uploaded file to the params array $this->mParams['file'] = $request->getFileName( 'file' ); @@ -72,7 +71,7 @@ class ApiUpload extends ApiBase { $this->mUpload = new UploadFromStash(); $this->mUpload->initialize( $this->mParams['filename'], - $_SESSION['wsUploadData'][$this->mParams['sessionkey']] ); + $_SESSION['wsUploadData'][$this->mParams['sessionkey']] ); } else { /** * Upload from url, etc @@ -113,7 +112,6 @@ class ApiUpload extends ApiBase { if ( ! $wgUser->isAllowed( 'upload_by_url' ) ) $this->dieUsageMsg( array( 'badaccess-groups' ) ); - $this->mUpload = new UploadFromUrl(); $this->mUpload->initialize( $this->mParams['filename'], $this->mParams['url'] ); diff --git a/includes/api/ApiUserrights.php b/includes/api/ApiUserrights.php index ea607d32e6..a8ccb3224c 100644 --- a/includes/api/ApiUserrights.php +++ b/includes/api/ApiUserrights.php @@ -27,7 +27,6 @@ if ( !defined( 'MEDIAWIKI' ) ) { require_once ( "ApiBase.php" ); } - /** * @ingroup API */ @@ -49,8 +48,8 @@ class ApiUserrights extends ApiBase { $user = $form->fetchUser( $params['user'] ); if ( $user instanceof WikiErrorMsg ) $this->dieUsageMsg( array_merge( - (array)$user->getMessageKey(), - $user->getMessageArgs() ) ); + (array)$user->getMessageKey(), $user->getMessageArgs() ) ); + if ( !$wgUser->matchEditToken( $params['token'], $user->getName() ) ) $this->dieUsageMsg( array( 'sessionfailure' ) ); diff --git a/includes/api/ApiWatch.php b/includes/api/ApiWatch.php index 87c9a5683c..06d4a0128e 100644 --- a/includes/api/ApiWatch.php +++ b/includes/api/ApiWatch.php @@ -43,12 +43,16 @@ class ApiWatch extends ApiBase { global $wgUser; if ( !$wgUser->isLoggedIn() ) $this->dieUsage( 'You must be logged-in to have a watchlist', 'notloggedin' ); + $params = $this->extractRequestParams(); $title = Title::newFromText( $params['title'] ); + if ( !$title ) $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) ); + $article = new Article( $title ); $res = array( 'title' => $title->getPrefixedText() ); + if ( $params['unwatch'] ) { $res['unwatched'] = ''; -- 2.20.1