diff options
Diffstat (limited to 'includes/api')
-rw-r--r-- | includes/api/ApiDelete.php | 14 | ||||
-rw-r--r-- | includes/api/ApiMain.php | 8 | ||||
-rw-r--r-- | includes/api/ApiQuery.php | 6 | ||||
-rw-r--r-- | includes/api/ApiQueryAllCategories.php | 7 | ||||
-rw-r--r-- | includes/api/ApiQueryAllImages.php (renamed from includes/api/ApiQueryAllimages.php) | 4 | ||||
-rw-r--r-- | includes/api/ApiQueryAllMessages.php (renamed from includes/api/ApiQueryAllmessages.php) | 2 | ||||
-rw-r--r-- | includes/api/ApiQueryAllPages.php (renamed from includes/api/ApiQueryAllpages.php) | 2 | ||||
-rw-r--r-- | includes/api/ApiQueryBase.php | 2 | ||||
-rw-r--r-- | includes/api/ApiQueryCategories.php | 7 | ||||
-rw-r--r-- | includes/api/ApiQueryDuplicateFiles.php | 22 | ||||
-rw-r--r-- | includes/api/ApiQueryFilearchive.php | 2 | ||||
-rw-r--r-- | includes/api/ApiQueryIWLinks.php | 14 | ||||
-rw-r--r-- | includes/api/ApiQueryImages.php | 7 | ||||
-rw-r--r-- | includes/api/ApiQueryLangLinks.php | 7 | ||||
-rw-r--r-- | includes/api/ApiQueryLinks.php | 9 | ||||
-rw-r--r-- | includes/api/ApiTokens.php | 39 |
16 files changed, 97 insertions, 55 deletions
diff --git a/includes/api/ApiDelete.php b/includes/api/ApiDelete.php index 42f9737d4407..eb83432d9796 100644 --- a/includes/api/ApiDelete.php +++ b/includes/api/ApiDelete.php @@ -53,18 +53,20 @@ class ApiDelete extends ApiBase { if ( !$titleObj ) { $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) ); } + $pageObj = WikiPage::factory( $titleObj ); + $pageObj->loadPageData( 'fromdbmaster' ); + if ( !$pageObj->exists() ) { + $this->dieUsageMsg( 'notanarticle' ); + } } elseif ( isset( $params['pageid'] ) ) { - $titleObj = Title::newFromID( $params['pageid'] ); - if ( !$titleObj ) { + $pageObj = WikiPage::newFromID( $params['pageid'] ); + if ( !$pageObj ) { $this->dieUsageMsg( array( 'nosuchpageid', $params['pageid'] ) ); } - } - if ( !$titleObj->exists() ) { - $this->dieUsageMsg( 'notanarticle' ); + $titleObj = $pageObj->getTitle(); } $reason = ( isset( $params['reason'] ) ? $params['reason'] : null ); - $pageObj = WikiPage::factory( $titleObj ); $user = $this->getUser(); if ( $titleObj->getNamespace() == NS_FILE ) { diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index 60b61cd8297c..a1c317965d3b 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -596,8 +596,14 @@ class ApiMain extends ApiBase { $moduleParams = $module->extractRequestParams(); // Die if token required, but not provided (unless there is a gettoken parameter) + if ( isset( $moduleParams['gettoken'] ) ) { + $gettoken = $moduleParams['gettoken']; + } else { + $gettoken = false; + } + $salt = $module->getTokenSalt(); - if ( $salt !== false && isset( $moduleParams['gettoken'] ) && !$moduleParams['gettoken'] ) { + if ( $salt !== false && !$gettoken ) { if ( !isset( $moduleParams['token'] ) ) { $this->dieUsageMsg( array( 'missingparam', 'token' ) ); } else { diff --git a/includes/api/ApiQuery.php b/includes/api/ApiQuery.php index c172d24dc1ff..866b71c25fd3 100644 --- a/includes/api/ApiQuery.php +++ b/includes/api/ApiQuery.php @@ -64,8 +64,8 @@ class ApiQuery extends ApiBase { ); private $mQueryListModules = array( - 'allimages' => 'ApiQueryAllimages', - 'allpages' => 'ApiQueryAllpages', + 'allimages' => 'ApiQueryAllImages', + 'allpages' => 'ApiQueryAllPages', 'alllinks' => 'ApiQueryAllLinks', 'allcategories' => 'ApiQueryAllCategories', 'allusers' => 'ApiQueryAllUsers', @@ -95,7 +95,7 @@ class ApiQuery extends ApiBase { private $mQueryMetaModules = array( 'siteinfo' => 'ApiQuerySiteinfo', 'userinfo' => 'ApiQueryUserInfo', - 'allmessages' => 'ApiQueryAllmessages', + 'allmessages' => 'ApiQueryAllMessages', ); private $mSlaveDB = null; diff --git a/includes/api/ApiQueryAllCategories.php b/includes/api/ApiQueryAllCategories.php index 78367a45cd80..ce28d036739b 100644 --- a/includes/api/ApiQueryAllCategories.php +++ b/includes/api/ApiQueryAllCategories.php @@ -65,7 +65,12 @@ class ApiQueryAllCategories extends ApiQueryGeneratorBase { $min = $params['min']; $max = $params['max']; - $this->addWhereRange( 'cat_pages', $dir, $min, $max ); + if ( $dir == 'newer' ) { + $this->addWhereRange( 'cat_pages', 'newer', $min, $max ); + } else { + $this->addWhereRange( 'cat_pages', 'older', $max, $min); + } + if ( isset( $params['prefix'] ) ) { $this->addWhere( 'cat_title' . $db->buildLike( $this->titlePartToKey( $params['prefix'] ), $db->anyString() ) ); diff --git a/includes/api/ApiQueryAllimages.php b/includes/api/ApiQueryAllImages.php index ca344f733705..60a05a7e3ca6 100644 --- a/includes/api/ApiQueryAllimages.php +++ b/includes/api/ApiQueryAllImages.php @@ -6,7 +6,7 @@ * Created on Mar 16, 2008 * * Copyright © 2008 Vasiliev Victor vasilvv@gmail.com, - * based on ApiQueryAllpages.php + * based on ApiQueryAllPages.php * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -31,7 +31,7 @@ * * @ingroup API */ -class ApiQueryAllimages extends ApiQueryGeneratorBase { +class ApiQueryAllImages extends ApiQueryGeneratorBase { protected $mRepo; diff --git a/includes/api/ApiQueryAllmessages.php b/includes/api/ApiQueryAllMessages.php index 44774927eed2..dedd3e5c30e2 100644 --- a/includes/api/ApiQueryAllmessages.php +++ b/includes/api/ApiQueryAllMessages.php @@ -29,7 +29,7 @@ * * @ingroup API */ -class ApiQueryAllmessages extends ApiQueryBase { +class ApiQueryAllMessages extends ApiQueryBase { public function __construct( $query, $moduleName ) { parent::__construct( $query, $moduleName, 'am' ); diff --git a/includes/api/ApiQueryAllpages.php b/includes/api/ApiQueryAllPages.php index e003ee9115f0..f3254c5b5dab 100644 --- a/includes/api/ApiQueryAllpages.php +++ b/includes/api/ApiQueryAllPages.php @@ -29,7 +29,7 @@ * * @ingroup API */ -class ApiQueryAllpages extends ApiQueryGeneratorBase { +class ApiQueryAllPages extends ApiQueryGeneratorBase { public function __construct( $query, $moduleName ) { parent::__construct( $query, $moduleName, 'ap' ); diff --git a/includes/api/ApiQueryBase.php b/includes/api/ApiQueryBase.php index 2666045b233e..a63374847f70 100644 --- a/includes/api/ApiQueryBase.php +++ b/includes/api/ApiQueryBase.php @@ -233,7 +233,7 @@ abstract class ApiQueryBase extends ApiBase { */ protected function addTimestampWhereRange( $field, $dir, $start, $end, $sort = true ) { $db = $this->getDb(); - return $this->addWhereRange( $field, $dir, + $this->addWhereRange( $field, $dir, $db->timestampOrNull( $start ), $db->timestampOrNull( $end ), $sort ); } diff --git a/includes/api/ApiQueryCategories.php b/includes/api/ApiQueryCategories.php index 1c1f1550df10..243d1acf1281 100644 --- a/includes/api/ApiQueryCategories.php +++ b/includes/api/ApiQueryCategories.php @@ -89,12 +89,13 @@ class ApiQueryCategories extends ApiQueryGeneratorBase { $this->dieUsage( "Invalid continue param. You should pass the " . "original value returned by the previous query", "_badcontinue" ); } + $op = $params['dir'] == 'descending' ? '<' : '>'; $clfrom = intval( $cont[0] ); - $clto = $this->getDB()->strencode( $this->titleToKey( $cont[1] ) ); + $clto = $this->getDB()->addQuotes( $this->titleToKey( $cont[1] ) ); $this->addWhere( - "cl_from > $clfrom OR " . + "cl_from $op $clfrom OR " . "(cl_from = $clfrom AND " . - "cl_to >= '$clto')" + "cl_to $op= $clto)" ); } diff --git a/includes/api/ApiQueryDuplicateFiles.php b/includes/api/ApiQueryDuplicateFiles.php index beca58791572..0132d67c5dc6 100644 --- a/includes/api/ApiQueryDuplicateFiles.php +++ b/includes/api/ApiQueryDuplicateFiles.php @@ -80,17 +80,27 @@ class ApiQueryDuplicateFiles extends ApiQueryGeneratorBase { $this->dieUsage( 'Invalid continue param. You should pass the ' . 'original value returned by the previous query', '_badcontinue' ); } - $orig = $this->getDB()->strencode( $this->titleTokey( $cont[0] ) ); - $dup = $this->getDB()->strencode( $this->titleToKey( $cont[1] ) ); + $op = $params['dir'] == 'descending' ? '<' : '>'; + $db = $this->getDB(); + $orig = $db->addQuotes( $this->titleTokey( $cont[0] ) ); + $dup = $db->addQuotes( $this->titleToKey( $cont[1] ) ); $this->addWhere( - "i1.img_name > '$orig' OR " . - "(i1.img_name = '$orig' AND " . - "i2.img_name >= '$dup')" + "i1.img_name $op $orig OR " . + "(i1.img_name = $orig AND " . + "i2.img_name $op= $dup)" ); } $dir = ( $params['dir'] == 'descending' ? ' DESC' : '' ); - $this->addOption( 'ORDER BY', 'i1.img_name' . $dir ); + // Don't order by i1.img_name if it's constant in the WHERE clause + if ( count( $this->getPageSet()->getGoodTitles() ) == 1 ) { + $this->addOption( 'ORDER BY', 'i2.img_name' . $dir ); + } else { + $this->addOption( 'ORDER BY', array( + 'i1.img_name' . $dir, + 'i2.img_name' . $dir + )); + } $this->addOption( 'LIMIT', $params['limit'] + 1 ); $res = $this->select( __METHOD__ ); diff --git a/includes/api/ApiQueryFilearchive.php b/includes/api/ApiQueryFilearchive.php index be995f30863b..7bf97d3ec04f 100644 --- a/includes/api/ApiQueryFilearchive.php +++ b/includes/api/ApiQueryFilearchive.php @@ -6,7 +6,7 @@ * * Copyright © 2010 Sam Reed * Copyright © 2008 Vasiliev Victor vasilvv@gmail.com, - * based on ApiQueryAllpages.php + * based on ApiQueryAllPages.php * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/includes/api/ApiQueryIWLinks.php b/includes/api/ApiQueryIWLinks.php index 13256ad89fa4..bc42fe0fa8c7 100644 --- a/includes/api/ApiQueryIWLinks.php +++ b/includes/api/ApiQueryIWLinks.php @@ -62,15 +62,17 @@ class ApiQueryIWLinks extends ApiQueryBase { $this->dieUsage( 'Invalid continue param. You should pass the ' . 'original value returned by the previous query', '_badcontinue' ); } + $op = $params['dir'] == 'descending' ? '<' : '>'; + $db = $this->getDB(); $iwlfrom = intval( $cont[0] ); - $iwlprefix = $this->getDB()->strencode( $cont[1] ); - $iwltitle = $this->getDB()->strencode( $this->titleToKey( $cont[2] ) ); + $iwlprefix = $db->addQuotes( $cont[1] ); + $iwltitle = $db->addQuotes( $this->titleToKey( $cont[2] ) ); $this->addWhere( - "iwl_from > $iwlfrom OR " . + "iwl_from $op $iwlfrom OR " . "(iwl_from = $iwlfrom AND " . - "(iwl_prefix > '$iwlprefix' OR " . - "(iwl_prefix = '$iwlprefix' AND " . - "iwl_title >= '$iwltitle')))" + "(iwl_prefix $op $iwlprefix OR " . + "(iwl_prefix = $iwlprefix AND " . + "iwl_title $op= $iwltitle)))" ); } diff --git a/includes/api/ApiQueryImages.php b/includes/api/ApiQueryImages.php index f03b28744086..64d7ff42ce2a 100644 --- a/includes/api/ApiQueryImages.php +++ b/includes/api/ApiQueryImages.php @@ -65,12 +65,13 @@ class ApiQueryImages extends ApiQueryGeneratorBase { $this->dieUsage( 'Invalid continue param. You should pass the ' . 'original value returned by the previous query', '_badcontinue' ); } + $op = $params['dir'] == 'descending' ? '<' : '>'; $ilfrom = intval( $cont[0] ); - $ilto = $this->getDB()->strencode( $this->titleToKey( $cont[1] ) ); + $ilto = $this->getDB()->addQuotes( $this->titleToKey( $cont[1] ) ); $this->addWhere( - "il_from > $ilfrom OR " . + "il_from $op $ilfrom OR " . "(il_from = $ilfrom AND " . - "il_to >= '$ilto')" + "il_to $op= $ilto)" ); } diff --git a/includes/api/ApiQueryLangLinks.php b/includes/api/ApiQueryLangLinks.php index fdba8465e334..d505d726f16c 100644 --- a/includes/api/ApiQueryLangLinks.php +++ b/includes/api/ApiQueryLangLinks.php @@ -60,12 +60,13 @@ class ApiQueryLangLinks extends ApiQueryBase { $this->dieUsage( 'Invalid continue param. You should pass the ' . 'original value returned by the previous query', '_badcontinue' ); } + $op = $params['dir'] == 'descending' ? '<' : '>'; $llfrom = intval( $cont[0] ); - $lllang = $this->getDB()->strencode( $cont[1] ); + $lllang = $this->getDB()->addQuotes( $cont[1] ); $this->addWhere( - "ll_from > $llfrom OR " . + "ll_from $op $llfrom OR " . "(ll_from = $llfrom AND " . - "ll_lang >= '$lllang')" + "ll_lang $op= $lllang)" ); } diff --git a/includes/api/ApiQueryLinks.php b/includes/api/ApiQueryLinks.php index 0377eddb5088..6e6da53d3430 100644 --- a/includes/api/ApiQueryLinks.php +++ b/includes/api/ApiQueryLinks.php @@ -116,15 +116,16 @@ class ApiQueryLinks extends ApiQueryGeneratorBase { $this->dieUsage( 'Invalid continue param. You should pass the ' . 'original value returned by the previous query', '_badcontinue' ); } + $op = $params['dir'] == 'descending' ? '<' : '>'; $plfrom = intval( $cont[0] ); $plns = intval( $cont[1] ); - $pltitle = $this->getDB()->strencode( $this->titleToKey( $cont[2] ) ); + $pltitle = $this->getDB()->addQuotes( $this->titleToKey( $cont[2] ) ); $this->addWhere( - "{$this->prefix}_from > $plfrom OR " . + "{$this->prefix}_from $op $plfrom OR " . "({$this->prefix}_from = $plfrom AND " . - "({$this->prefix}_namespace > $plns OR " . + "({$this->prefix}_namespace $op $plns OR " . "({$this->prefix}_namespace = $plns AND " . - "{$this->prefix}_title >= '$pltitle')))" + "{$this->prefix}_title $op= $pltitle)))" ); } diff --git a/includes/api/ApiTokens.php b/includes/api/ApiTokens.php index 79640953e9a8..4a68826e1021 100644 --- a/includes/api/ApiTokens.php +++ b/includes/api/ApiTokens.php @@ -35,19 +35,16 @@ class ApiTokens extends ApiBase { } public function execute() { + wfProfileIn( __METHOD__ ); $params = $this->extractRequestParams(); $res = array(); + $types = $this->getTokenTypes(); foreach ( $params['type'] as $type ) { $type = strtolower( $type ); - $func = 'get' . - ucfirst( $type ) . - 'Token'; - if ( $type === 'patrol' ) { - $val = call_user_func( array( 'ApiQueryRecentChanges', $func ), null, null ); - } else { - $val = call_user_func( array( 'ApiQueryInfo', $func ), null, null ); - } + + $val = call_user_func( $types[$type], null, null ); + if ( $val === false ) { $this->setWarning( "Action '$type' is not allowed for the current user" ); } else { @@ -56,6 +53,25 @@ class ApiTokens extends ApiBase { } $this->getResult()->addValue( null, $this->getModuleName(), $res ); + wfProfileOut( __METHOD__ ); + } + + private function getTokenTypes() { + static $types = null; + if ( $types ) { + return $types; + } + wfProfileIn( __METHOD__ ); + $types = array( 'patrol' => 'ApiQueryRecentChanges::getPatrolToken' ); + $names = array( 'edit', 'delete', 'protect', 'move', 'block', 'unblock', + 'email', 'import', 'watch' ); + foreach ( $names as $name ) { + $types[$name] = 'ApiQUeryInfo::get' . ucfirst( $name ) . 'Token'; + } + wfRunHooks( 'ApiTokensGetTokenTypes', array( &$types ) ); + ksort( $types ); + wfProfileOut( __METHOD__ ); + return $types; } public function getAllowedParams() { @@ -63,11 +79,8 @@ class ApiTokens extends ApiBase { 'type' => array( ApiBase::PARAM_DFLT => 'edit', ApiBase::PARAM_ISMULTI => true, - ApiBase::PARAM_TYPE => array( - 'edit', 'delete', 'protect', 'move', 'block', 'unblock', - 'email', 'import', 'watch', 'patrol' - ) - ) + ApiBase::PARAM_TYPE => array_keys( $this->getTokenTypes() ), + ), ); } |