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 );
require_once ( "ApiBase.php" );
}
-
/**
* API module that facilitates deleting pages. The API eqivalent of action=delete.
* Requires API write mode to be enabled.
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();
require_once ( "ApiBase.php" );
}
-
/**
* API module that dies with an error immediately.
*
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' ) );
$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' ) );
}
# 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
'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'] );
$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 ) ) )
{
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:
$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
require_once ( "ApiBase.php" );
}
-
/**
* @ingroup API
*/
$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 ) )
// Parse text
global $wgParser;
$options = new ParserOptions();
+
if ( $params['generatexml'] )
{
$wgParser->startExternalParse( $title_obj, $options, OT_PREPROCESS );
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'];
}
$this->mErrorFallback->execute();
return;
}
+
if ( !isset( $data['text'] ) )
ApiBase::dieDebug( __METHOD__, "No text given for raw formatter" );
$this->printText( $data['text'] );
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</array>$nl" );
strpos( $value, "\n" ) ||
preg_match( "/[#:]/", $value ) ||
preg_match( "/^[-?,[\]{}!*&|>'\"%@`]/", $value ) ) );
-
}
/**
$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 );
if ( !$fromTitle )
$this->dieUsageMsg( array( 'nosuchpageid', $params['fromid'] ) );
}
+
if ( !$fromTitle->exists() )
$this->dieUsageMsg( array( 'notanarticle' ) );
$fromTalk = $fromTitle->getTalkPage();
if ( $forceNameTitleIndex )
$this->addOption( 'USE INDEX', 'name_title' );
-
-
$limit = $params['limit'];
$this->addOption( 'LIMIT', $limit + 1 );
$res = $this->select( __METHOD__ );
}
$this->addWhereFld( 'cl_to', $cats );
}
+
if ( !is_null( $params['continue'] ) ) {
$cont = explode( '|', $params['continue'] );
if ( count( $cont ) != 2 )
"(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'] ) )
'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'] );
$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;
'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'] );
"(i1.img_name = '$orig' AND " .
"i2.img_name >= '$dup')" );
}
+
$this->addOption( 'ORDER BY', 'i1.img_name' );
$this->addOption( 'LIMIT', $params['limit'] + 1 );
$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'] );
"(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' );
"(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' );
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' );
$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();
*
* @ingroup API
*/
-
class ApiQueryUsers extends ApiQueryBase {
public function __construct( $query, $moduleName ) {
else
$goodNames[] = $n;
}
+
if ( count( $goodNames ) )
{
$db = $this->getDb();
$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'] );
"(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' );
break;
}
$t = Title::makeTitle( $row->wl_namespace, $row->wl_title );
+
if ( is_null( $resultPageSet ) )
{
$vals = array();
* @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 );
+ }
}
/**
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' ) );
if ( !$wgUser->matchEditToken( $this->mParams['token'] ) )
$this->dieUsageMsg( array( 'sessionfailure' ) );
-
// Add the uploaded file to the params array
$this->mParams['file'] = $request->getFileName( 'file' );
$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
if ( ! $wgUser->isAllowed( 'upload_by_url' ) )
$this->dieUsageMsg( array( 'badaccess-groups' ) );
-
$this->mUpload = new UploadFromUrl();
$this->mUpload->initialize( $this->mParams['filename'],
$this->mParams['url'] );
require_once ( "ApiBase.php" );
}
-
/**
* @ingroup API
*/
$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' ) );
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'] = '';