<?php
-/*
+/**
* Created on Sep 25, 2006
*
* API for MediaWiki 1.8+
*
- * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
+ * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
*
* 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
class ApiQuerySiteinfo extends ApiQueryBase {
public function __construct( $query, $moduleName ) {
- parent :: __construct( $query, $moduleName, 'si' );
+ parent::__construct( $query, $moduleName, 'si' );
}
public function execute() {
$params = $this->extractRequestParams();
$done = array();
- foreach ( $params['prop'] as $p )
- {
- switch ( $p )
- {
+ foreach ( $params['prop'] as $p ) {
+ switch ( $p ) {
case 'general':
$fit = $this->appendGeneralInfo( $p );
break;
case 'languages':
$fit = $this->appendLanguages( $p );
break;
- default :
- ApiBase :: dieDebug( __METHOD__, "Unknown prop=$p" );
+ default:
+ ApiBase::dieDebug( __METHOD__, "Unknown prop=$p" );
}
- if ( !$fit )
- {
+ if ( !$fit ) {
// Abuse siprop as a query-continue parameter
// and set it to all unprocessed props
$this->setContinueEnumParameter( 'prop', implode( '|',
}
protected function appendGeneralInfo( $property ) {
- global $wgContLang;
- global $wgLang;
+ global $wgContLang, $wgLang;
$data = array();
- $mainPage = Title :: newFromText( wfMsgForContent( 'mainpage' ) );
+ $mainPage = Title::newFromText( wfMsgForContent( 'mainpage' ) );
$data['mainpage'] = $mainPage->getPrefixedText();
$data['base'] = $mainPage->getFullUrl();
$data['sitename'] = $GLOBALS['wgSitename'];
$data['dbversion'] = $this->getDB()->getServerVersion();
$svn = SpecialVersion::getSvnRevision( $GLOBALS['IP'] );
- if ( $svn )
+ if ( $svn ) {
$data['rev'] = $svn;
+ }
// 'case-insensitive' option is reserved for future
$data['case'] = $GLOBALS['wgCapitalLinks'] ? 'first-letter' : 'case-sensitive';
- if ( isset( $GLOBALS['wgRightsCode'] ) )
+ if ( isset( $GLOBALS['wgRightsCode'] ) ) {
$data['rightscode'] = $GLOBALS['wgRightsCode'];
+ }
$data['rights'] = $GLOBALS['wgRightsText'];
$data['lang'] = $GLOBALS['wgLanguageCode'];
- if ( $wgContLang->isRTL() )
+ if ( $wgContLang->isRTL() ) {
$data['rtl'] = '';
+ }
$data['fallback8bitEncoding'] = $wgLang->fallback8bitEncoding();
-
+
if ( wfReadOnly() ) {
$data['readonly'] = '';
$data['readonlyreason'] = wfReadOnlyReason();
}
- if ( $GLOBALS['wgEnableWriteAPI'] )
+ if ( $GLOBALS['wgEnableWriteAPI'] ) {
$data['writeapi'] = '';
+ }
$tz = $GLOBALS['wgLocaltimezone'];
$offset = $GLOBALS['wgLocalTZoffset'];
protected function appendNamespaces( $property ) {
global $wgContLang;
$data = array();
- foreach ( $wgContLang->getFormattedNamespaces() as $ns => $title )
- {
+ foreach ( $wgContLang->getFormattedNamespaces() as $ns => $title ) {
$data[$ns] = array(
'id' => intval( $ns ),
'case' => MWNamespace::isCapitalized( $ns ) ? 'first-letter' : 'case-sensitive',
);
- ApiResult :: setContent( $data[$ns], $title );
+ ApiResult::setContent( $data[$ns], $title );
$canonical = MWNamespace::getCanonicalName( $ns );
-
- if ( MWNamespace::hasSubpages( $ns ) )
+
+ if ( MWNamespace::hasSubpages( $ns ) ) {
$data[$ns]['subpages'] = '';
-
- if ( $canonical )
+ }
+
+ if ( $canonical ) {
$data[$ns]['canonical'] = strtr( $canonical, '_', ' ' );
-
- if ( MWNamespace::isContent( $ns ) )
+ }
+
+ if ( MWNamespace::isContent( $ns ) ) {
$data[$ns]['content'] = '';
+ }
}
$this->getResult()->setIndexedTagName( $data, 'ns' );
$item = array(
'id' => intval( $ns )
);
- ApiResult :: setContent( $item, strtr( $title, '_', ' ' ) );
+ ApiResult::setContent( $item, strtr( $title, '_', ' ' ) );
$data[] = $item;
}
$this->getResult()->setIndexedTagName( $data, 'specialpage' );
return $this->getResult()->addValue( 'query', $property, $data );
}
-
+
protected function appendMagicWords( $property ) {
global $wgContLang;
$data = array();
- foreach ( $wgContLang->getMagicWords() as $magicword => $aliases )
- {
+ foreach ( $wgContLang->getMagicWords() as $magicword => $aliases ) {
$caseSensitive = array_shift( $aliases );
$arr = array( 'name' => $magicword, 'aliases' => $aliases );
- if ( $caseSensitive )
+ if ( $caseSensitive ) {
$arr['case-sensitive'] = '';
+ }
$this->getResult()->setIndexedTagName( $arr['aliases'], 'alias' );
$data[] = $arr;
}
$this->addTables( 'interwiki' );
$this->addFields( array( 'iw_prefix', 'iw_local', 'iw_url' ) );
- if ( $filter === 'local' )
+ if ( $filter === 'local' ) {
$this->addWhere( 'iw_local = 1' );
- elseif ( $filter === '!local' )
+ } elseif ( $filter === '!local' ) {
$this->addWhere( 'iw_local = 0' );
- elseif ( $filter )
- ApiBase :: dieDebug( __METHOD__, "Unknown filter=$filter" );
+ } elseif ( $filter ) {
+ ApiBase::dieDebug( __METHOD__, "Unknown filter=$filter" );
+ }
$this->addOption( 'ORDER BY', 'iw_prefix' );
$data = array();
$langNames = Language::getLanguageNames();
- while ( $row = $db->fetchObject( $res ) )
- {
+ while ( $row = $db->fetchObject( $res ) ) {
$val = array();
$val['prefix'] = $row->iw_prefix;
- if ( $row->iw_local == '1' )
+ if ( $row->iw_local == '1' ) {
$val['local'] = '';
-// $val['trans'] = intval($row->iw_trans); // should this be exposed?
- if ( isset( $langNames[$row->iw_prefix] ) )
+ }
+// $val['trans'] = intval( $row->iw_trans ); // should this be exposed?
+ if ( isset( $langNames[$row->iw_prefix] ) ) {
$val['language'] = $langNames[$row->iw_prefix];
+ }
$val['url'] = $row->iw_url;
$data[] = $val;
global $wgShowHostnames;
$data = array();
if ( $includeAll ) {
- if ( !$wgShowHostnames )
+ if ( !$wgShowHostnames ) {
$this->dieUsage( 'Cannot view all servers info unless $wgShowHostnames is true', 'includeAllDenied' );
+ }
$lb = wfGetLB();
$lags = $lb->getLagTimes();
'name' => $group,
'rights' => array_keys( $permissions, true ),
);
- if ( $numberInGroup )
+ if ( $numberInGroup ) {
$arr['number'] = SiteStats::numberInGroup( $group );
-
+ }
+
$this->getResult()->setIndexedTagName( $arr['rights'], 'permission' );
$data[] = $arr;
}
$this->getResult()->setIndexedTagName( $data, 'group' );
return $this->getResult()->addValue( 'query', $property, $data );
}
-
+
protected function appendFileExtensions( $property ) {
global $wgFileExtensions;
-
+
$data = array();
foreach ( $wgFileExtensions as $ext ) {
$data[] = array( 'ext' => $ext );
foreach ( $extensions as $ext ) {
$ret = array();
$ret['type'] = $type;
- if ( isset( $ext['name'] ) )
+ if ( isset( $ext['name'] ) ) {
$ret['name'] = $ext['name'];
- if ( isset( $ext['description'] ) )
+ }
+ if ( isset( $ext['description'] ) ) {
$ret['description'] = $ext['description'];
+ }
if ( isset( $ext['descriptionmsg'] ) ) {
// Can be a string or array( key, param1, param2, ... )
if ( is_array( $ext['descriptionmsg'] ) ) {
return $this->getResult()->addValue( 'query', $property, $data );
}
-
public function getAllowedParams() {
return array(
'prop' => array(
- ApiBase :: PARAM_DFLT => 'general',
- ApiBase :: PARAM_ISMULTI => true,
- ApiBase :: PARAM_TYPE => array(
+ ApiBase::PARAM_DFLT => 'general',
+ ApiBase::PARAM_ISMULTI => true,
+ ApiBase::PARAM_TYPE => array(
'general',
'namespaces',
'namespacealiases',
)
),
'filteriw' => array(
- ApiBase :: PARAM_TYPE => array(
+ ApiBase::PARAM_TYPE => array(
'local',
'!local',
)
'api.php?action=query&meta=siteinfo&siprop=general|namespaces|namespacealiases|statistics',
'api.php?action=query&meta=siteinfo&siprop=interwikimap&sifilteriw=local',
'api.php?action=query&meta=siteinfo&siprop=dbrepllag&sishowalldb',
- );
+ );
}
public function getVersion() {
<?php
-/*
+/**
* Created on Jul 9, 2009
*
* API for MediaWiki 1.8+
*
- * Copyright (C) 2009
+ * Copyright © 2009
*
* 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
if ( !defined( 'MEDIAWIKI' ) ) {
// Eclipse helper - will be ignored in production
- require_once ( 'ApiQueryBase.php' );
+ require_once( 'ApiQueryBase.php' );
}
/**
* @ingroup API
*/
class ApiQueryTags extends ApiQueryBase {
-
+
private $limit, $result;
private $fld_displayname = false, $fld_description = false,
$fld_hitcount = false;
-
+
public function __construct( $query, $moduleName ) {
- parent :: __construct( $query, $moduleName, 'tg' );
+ parent::__construct( $query, $moduleName, 'tg' );
}
public function execute() {
$params = $this->extractRequestParams();
-
+
$prop = array_flip( $params['prop'] );
-
+
$this->fld_displayname = isset( $prop['displayname'] );
$this->fld_description = isset( $prop['description'] );
$this->fld_hitcount = isset( $prop['hitcount'] );
-
+
$this->limit = $params['limit'];
$this->result = $this->getResult();
-
+
$pageSet = $this->getPageSet();
$titles = $pageSet->getTitles();
$data = array();
-
+
$this->addTables( 'change_tag' );
$this->addFields( 'ct_tag' );
-
- if ( $this->fld_hitcount )
+
+ if ( $this->fld_hitcount ) {
$this->addFields( 'count(*) AS hitcount' );
-
+ }
+
$this->addOption( 'LIMIT', $this->limit + 1 );
$this->addOption( 'GROUP BY', 'ct_tag' );
$this->addWhereRange( 'ct_tag', 'newer', $params['continue'], null );
-
+
$res = $this->select( __METHOD__ );
-
+
$ok = true;
-
+
while ( $row = $res->fetchObject() ) {
- if ( !$ok ) break;
+ if ( !$ok ) {
+ break;
+ }
$ok = $this->doTag( $row->ct_tag, $row->hitcount );
}
-
+
// include tags with no hits yet
foreach ( ChangeTags::listDefinedTags() as $tag ) {
- if ( !$ok ) break;
+ if ( !$ok ) {
+ break;
+ }
$ok = $this->doTag( $tag, 0 );
}
-
+
$this->result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'tag' );
}
-
+
private function doTag( $tagName, $hitcount ) {
static $count = 0;
static $doneTags = array();
-
+
if ( in_array( $tagName, $doneTags ) ) {
return true;
}
-
- if ( ++$count > $this->limit )
- {
+
+ if ( ++$count > $this->limit ) {
$this->setContinueEnumParameter( 'continue', $tagName );
return false;
}
-
+
$tag = array();
$tag['name'] = $tagName;
-
- if ( $this->fld_displayname )
+
+ if ( $this->fld_displayname ) {
$tag['displayname'] = ChangeTags::tagDescription( $tagName );
-
- if ( $this->fld_description )
- {
+ }
+
+ if ( $this->fld_description ) {
$msg = wfMsg( "tag-$tagName-description" );
$msg = wfEmptyMsg( "tag-$tagName-description", $msg ) ? '' : $msg;
$tag['description'] = $msg;
}
-
- if ( $this->fld_hitcount )
+
+ if ( $this->fld_hitcount ) {
$tag['hitcount'] = $hitcount;
-
+ }
+
$doneTags[] = $tagName;
-
+
$fit = $this->result->addValue( array( 'query', $this->getModuleName() ), null, $tag );
- if ( !$fit )
- {
+ if ( !$fit ) {
$this->setContinueEnumParameter( 'continue', $tagName );
return false;
}
-
+
return true;
}
-
+
public function getAllowedParams() {
- return array (
+ return array(
'continue' => array(
),
'limit' => array(
- ApiBase :: PARAM_DFLT => 10,
- ApiBase :: PARAM_TYPE => 'limit',
- ApiBase :: PARAM_MIN => 1,
- ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1,
- ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
+ ApiBase::PARAM_DFLT => 10,
+ ApiBase::PARAM_TYPE => 'limit',
+ ApiBase::PARAM_MIN => 1,
+ ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
+ ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
),
'prop' => array(
- ApiBase :: PARAM_DFLT => 'name',
- ApiBase :: PARAM_TYPE => array(
- 'name',
- 'displayname',
- 'description',
- 'hitcount'
- ),
- ApiBase :: PARAM_ISMULTI => true
+ ApiBase::PARAM_DFLT => 'name',
+ ApiBase::PARAM_TYPE => array(
+ 'name',
+ 'displayname',
+ 'description',
+ 'hitcount'
+ ),
+ ApiBase::PARAM_ISMULTI => true
)
);
}
public function getParamDescription() {
- return array (
+ return array(
'continue' => 'When more results are available, use this to continue',
'limit' => 'The maximum number of tags to list',
'prop' => 'Which properties to get',
}
protected function getExamples() {
- return array (
+ return array(
'api.php?action=query&list=tags&tgprop=displayname|description|hitcount'
);
}
<?php
-/*
+/**
* Created on Oct 16, 2006
*
* API for MediaWiki 1.8+
*
- * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
+ * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
*
* 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
if ( !defined( 'MEDIAWIKI' ) ) {
// Eclipse helper - will be ignored in production
- require_once ( 'ApiQueryBase.php' );
+ require_once( 'ApiQueryBase.php' );
}
/**
class ApiQueryContributions extends ApiQueryBase {
public function __construct( $query, $moduleName ) {
- parent :: __construct( $query, $moduleName, 'uc' );
+ parent::__construct( $query, $moduleName, 'uc' );
}
private $params, $username;
$this->selectNamedDB( 'contributions', DB_SLAVE, 'contributions' );
$db = $this->getDB();
- if ( isset( $this->params['userprefix'] ) )
- {
+ if ( isset( $this->params['userprefix'] ) ) {
$this->prefixMode = true;
$this->multiUserMode = true;
$this->userprefix = $this->params['userprefix'];
- }
- else
- {
+ } else {
$this->usernames = array();
- if ( !is_array( $this->params['user'] ) )
+ if ( !is_array( $this->params['user'] ) ) {
$this->params['user'] = array( $this->params['user'] );
- if ( !count( $this->params['user'] ) )
+ }
+ if ( !count( $this->params['user'] ) ) {
$this->dieUsage( 'User parameter may not be empty.', 'param_user' );
- foreach ( $this->params['user'] as $u )
+ }
+ foreach ( $this->params['user'] as $u ) {
$this->prepareUsername( $u );
+ }
$this->prefixMode = false;
$this->multiUserMode = ( count( $this->params['user'] ) > 1 );
}
while ( $row = $db->fetchObject( $res ) ) {
if ( ++ $count > $limit ) {
// We've reached the one extra which shows that there are additional pages to be had. Stop here...
- if ( $this->multiUserMode )
+ if ( $this->multiUserMode ) {
$this->setContinueEnumParameter( 'continue', $this->continueStr( $row ) );
- else
+ } else {
$this->setContinueEnumParameter( 'start', wfTimestamp( TS_ISO_8601, $row->rev_timestamp ) );
+ }
break;
}
$vals = $this->extractRowInfo( $row );
$fit = $this->getResult()->addValue( array( 'query', $this->getModuleName() ), null, $vals );
- if ( !$fit )
- {
- if ( $this->multiUserMode )
+ if ( !$fit ) {
+ if ( $this->multiUserMode ) {
$this->setContinueEnumParameter( 'continue', $this->continueStr( $row ) );
- else
+ } else {
$this->setContinueEnumParameter( 'start', wfTimestamp( TS_ISO_8601, $row->rev_timestamp ) );
+ }
break;
}
}
$this->addWhere( 'page_id=rev_page' );
// Handle continue parameter
- if ( $this->multiUserMode && !is_null( $this->params['continue'] ) )
- {
+ if ( $this->multiUserMode && !is_null( $this->params['continue'] ) ) {
$continue = explode( '|', $this->params['continue'] );
- if ( count( $continue ) != 2 )
- $this->dieUsage( "Invalid continue param. You should pass the original " .
- "value returned by the previous query", "_badcontinue" );
+ if ( count( $continue ) != 2 ) {
+ $this->dieUsage( 'Invalid continue param. You should pass the original ' .
+ 'value returned by the previous query', '_badcontinue' );
+ }
$encUser = $this->getDB()->strencode( $continue[0] );
$encTS = wfTimestamp( TS_MW, $continue[1] );
$op = ( $this->params['dir'] == 'older' ? '<' : '>' );
- $this->addWhere( "rev_user_text $op '$encUser' OR " .
- "(rev_user_text = '$encUser' AND " .
- "rev_timestamp $op= '$encTS')" );
+ $this->addWhere(
+ "rev_user_text $op '$encUser' OR " .
+ "(rev_user_text = '$encUser' AND " .
+ "rev_timestamp $op= '$encTS')"
+ );
}
- if ( !$wgUser->isAllowed( 'hideuser' ) )
+ if ( !$wgUser->isAllowed( 'hideuser' ) ) {
$this->addWhere( $this->getDB()->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ' = 0' );
+ }
// We only want pages by the specified users.
- if ( $this->prefixMode )
+ if ( $this->prefixMode ) {
$this->addWhere( 'rev_user_text' . $this->getDB()->buildLike( $this->userprefix, $this->getDB()->anyString() ) );
- else
+ } else {
$this->addWhereFld( 'rev_user_text', $this->usernames );
+ }
// ... and in the specified timeframe.
// Ensure the same sort order for rev_user_text and rev_timestamp
// so our query is indexed
- if ( $this->multiUserMode )
+ if ( $this->multiUserMode ) {
$this->addWhereRange( 'rev_user_text', $this->params['dir'], null, null );
+ }
$this->addWhereRange( 'rev_timestamp',
$this->params['dir'], $this->params['start'], $this->params['end'] );
$this->addWhereFld( 'page_namespace', $this->params['namespace'] );
$show = array_flip( $show );
if ( ( isset( $show['minor'] ) && isset( $show['!minor'] ) )
|| ( isset( $show['patrolled'] ) && isset( $show['!patrolled'] ) ) )
+ {
$this->dieUsageMsg( array( 'show' ) );
+ }
$this->addWhereIf( 'rev_minor_edit = 0', isset( $show['!minor'] ) );
$this->addWhereIf( 'rev_minor_edit != 0', isset( $show['minor'] ) );
'rev_user_text',
'rev_deleted'
) );
-
+
if ( isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) ||
$this->fld_patrolled )
{
global $wgUser;
- if ( !$wgUser->useRCPatrol() && !$wgUser->useNPPatrol() )
- $this->dieUsage( "You need the patrol right to request the patrolled flag", 'permissiondenied' );
+ if ( !$wgUser->useRCPatrol() && !$wgUser->useNPPatrol() ) {
+ $this->dieUsage( 'You need the patrol right to request the patrolled flag', 'permissiondenied' );
+ }
// Use a redundant join condition on both
// timestamp and ID so we can use the timestamp
// index
$index['recentchanges'] = 'rc_user_text';
- if ( isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) )
- {
+ if ( isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) ) {
// Put the tables in the right order for
// STRAIGHT_JOIN
$tables = array( 'revision', 'recentchanges', 'page' );
$this->addWhere( 'rc_user_text=rev_user_text' );
$this->addWhere( 'rc_timestamp=rev_timestamp' );
$this->addWhere( 'rc_this_oldid=rev_id' );
- }
- else
- {
+ } else {
$tables[] = 'recentchanges';
$this->addJoinConds( array( 'recentchanges' => array(
'LEFT JOIN', array(
$this->addFieldsIf( 'rev_page', $this->fld_ids );
$this->addFieldsIf( 'rev_id', $this->fld_ids || $this->fld_flags );
$this->addFieldsIf( 'page_latest', $this->fld_flags );
- // $this->addFieldsIf('rev_text_id', $this->fld_ids); // Should this field be exposed?
+ // $this->addFieldsIf( 'rev_text_id', $this->fld_ids ); // Should this field be exposed?
$this->addFieldsIf( 'rev_comment', $this->fld_comment || $this->fld_parsedcomment );
$this->addFieldsIf( 'rev_len', $this->fld_size );
$this->addFieldsIf( 'rev_minor_edit', $this->fld_flags );
$this->addFieldsIf( 'rev_parent_id', $this->fld_flags );
$this->addFieldsIf( 'rc_patrolled', $this->fld_patrolled );
-
- if ( $this->fld_tags )
- {
+
+ if ( $this->fld_tags ) {
$this->addTables( 'tag_summary' );
$this->addJoinConds( array( 'tag_summary' => array( 'LEFT JOIN', array( 'rev_id=ts_rev_id' ) ) ) );
$this->addFields( 'ts_tags' );
}
-
+
if ( isset( $this->params['tag'] ) ) {
$this->addTables( 'change_tag' );
$this->addJoinConds( array( 'change_tag' => array( 'INNER JOIN', array( 'rev_id=ct_rev_id' ) ) ) );
$this->addWhereFld( 'ct_tag', $this->params['tag'] );
global $wgOldChangeTagsIndex;
- $index['change_tag'] = $wgOldChangeTagsIndex ? 'ct_tag' : 'change_tag_tag_id';
+ $index['change_tag'] = $wgOldChangeTagsIndex ? 'ct_tag' : 'change_tag_tag_id';
}
-
+
$this->addOption( 'USE INDEX', $index );
}
* Extract fields from the database row and append them to a result array
*/
private function extractRowInfo( $row ) {
-
$vals = array();
$vals['user'] = $row->rev_user_text;
- if ( $row->rev_deleted & Revision::DELETED_USER )
+ if ( $row->rev_deleted & Revision::DELETED_USER ) {
$vals['userhidden'] = '';
+ }
if ( $this->fld_ids ) {
$vals['pageid'] = intval( $row->rev_page );
$vals['revid'] = intval( $row->rev_id );
- // $vals['textid'] = intval($row->rev_text_id); // todo: Should this field be exposed?
+ // $vals['textid'] = intval( $row->rev_text_id ); // todo: Should this field be exposed?
}
$title = Title::makeTitle( $row->page_namespace, $row->page_title );
- if ( $this->fld_title )
+ if ( $this->fld_title ) {
ApiQueryBase::addTitleInfo( $vals, $title );
+ }
- if ( $this->fld_timestamp )
+ if ( $this->fld_timestamp ) {
$vals['timestamp'] = wfTimestamp( TS_ISO_8601, $row->rev_timestamp );
+ }
if ( $this->fld_flags ) {
- if ( $row->rev_parent_id == 0 && !is_null( $row->rev_parent_id ) )
+ if ( $row->rev_parent_id == 0 && !is_null( $row->rev_parent_id ) ) {
$vals['new'] = '';
- if ( $row->rev_minor_edit )
+ }
+ if ( $row->rev_minor_edit ) {
$vals['minor'] = '';
- if ( $row->page_latest == $row->rev_id )
+ }
+ if ( $row->page_latest == $row->rev_id ) {
$vals['top'] = '';
+ }
}
if ( ( $this->fld_comment || $this->fld_parsedcomment ) && isset( $row->rev_comment ) ) {
- if ( $row->rev_deleted & Revision::DELETED_COMMENT )
+ if ( $row->rev_deleted & Revision::DELETED_COMMENT ) {
$vals['commenthidden'] = '';
- else {
- if ( $this->fld_comment )
+ } else {
+ if ( $this->fld_comment ) {
$vals['comment'] = $row->rev_comment;
-
+ }
+
if ( $this->fld_parsedcomment ) {
global $wgUser;
$vals['parsedcomment'] = $wgUser->getSkin()->formatComment( $row->rev_comment, $title );
}
}
- if ( $this->fld_patrolled && $row->rc_patrolled )
+ if ( $this->fld_patrolled && $row->rc_patrolled ) {
$vals['patrolled'] = '';
-
- if ( $this->fld_size && !is_null( $row->rev_len ) )
+ }
+
+ if ( $this->fld_size && !is_null( $row->rev_len ) ) {
$vals['size'] = intval( $row->rev_len );
+ }
if ( $this->fld_tags ) {
if ( $row->ts_tags ) {
$vals['tags'] = array();
}
}
-
+
return $vals;
}
-
- private function continueStr( $row )
- {
+
+ private function continueStr( $row ) {
return $row->rev_user_text . '|' .
wfTimestamp( TS_ISO_8601, $row->rev_timestamp );
}
public function getAllowedParams() {
- return array (
- 'limit' => array (
- ApiBase :: PARAM_DFLT => 10,
- ApiBase :: PARAM_TYPE => 'limit',
- ApiBase :: PARAM_MIN => 1,
- ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1,
- ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
+ return array(
+ 'limit' => array(
+ ApiBase::PARAM_DFLT => 10,
+ ApiBase::PARAM_TYPE => 'limit',
+ ApiBase::PARAM_MIN => 1,
+ ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
+ ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
),
- 'start' => array (
- ApiBase :: PARAM_TYPE => 'timestamp'
+ 'start' => array(
+ ApiBase::PARAM_TYPE => 'timestamp'
),
- 'end' => array (
- ApiBase :: PARAM_TYPE => 'timestamp'
+ 'end' => array(
+ ApiBase::PARAM_TYPE => 'timestamp'
),
'continue' => null,
- 'user' => array (
- ApiBase :: PARAM_ISMULTI => true
+ 'user' => array(
+ ApiBase::PARAM_ISMULTI => true
),
'userprefix' => null,
- 'dir' => array (
- ApiBase :: PARAM_DFLT => 'older',
- ApiBase :: PARAM_TYPE => array (
+ 'dir' => array(
+ ApiBase::PARAM_DFLT => 'older',
+ ApiBase::PARAM_TYPE => array(
'newer',
'older'
)
),
- 'namespace' => array (
- ApiBase :: PARAM_ISMULTI => true,
- ApiBase :: PARAM_TYPE => 'namespace'
+ 'namespace' => array(
+ ApiBase::PARAM_ISMULTI => true,
+ ApiBase::PARAM_TYPE => 'namespace'
),
- 'prop' => array (
- ApiBase :: PARAM_ISMULTI => true,
- ApiBase :: PARAM_DFLT => 'ids|title|timestamp|comment|size|flags',
- ApiBase :: PARAM_TYPE => array (
+ 'prop' => array(
+ ApiBase::PARAM_ISMULTI => true,
+ ApiBase::PARAM_DFLT => 'ids|title|timestamp|comment|size|flags',
+ ApiBase::PARAM_TYPE => array(
'ids',
'title',
'timestamp',
'tags'
)
),
- 'show' => array (
- ApiBase :: PARAM_ISMULTI => true,
- ApiBase :: PARAM_TYPE => array (
+ 'show' => array(
+ ApiBase::PARAM_ISMULTI => true,
+ ApiBase::PARAM_TYPE => array(
'minor',
'!minor',
'patrolled',
}
public function getParamDescription() {
- return array (
+ return array(
'limit' => 'The maximum number of contributions to return.',
'start' => 'The start timestamp to return from.',
'end' => 'The end timestamp to return to.',
public function getDescription() {
return 'Get all edits by a user';
}
-
+
public function getPossibleErrors() {
return array_merge( parent::getPossibleErrors(), array(
array( 'code' => 'param_user', 'info' => 'User parameter may not be empty.' ),
}
protected function getExamples() {
- return array (
+ return array(
'api.php?action=query&list=usercontribs&ucuser=YurikBot',
'api.php?action=query&list=usercontribs&ucuserprefix=217.121.114.',
);
<?php
-/*
+/**
* Created on July 30, 2007
*
* API for MediaWiki 1.8+
*
- * Copyright (C) 2007 Yuri Astrakhan <Firstname><Lastname>@gmail.com
+ * Copyright © 2007 Yuri Astrakhan <Firstname><Lastname>@gmail.com
*
* 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
if ( !defined( 'MEDIAWIKI' ) ) {
// Eclipse helper - will be ignored in production
- require_once ( 'ApiQueryBase.php' );
+ require_once( 'ApiQueryBase.php' );
}
/**
class ApiQueryUserInfo extends ApiQueryBase {
public function __construct( $query, $moduleName ) {
- parent :: __construct( $query, $moduleName, 'ui' );
+ parent::__construct( $query, $moduleName, 'ui' );
}
public function execute() {
$this->prop = array();
}
$r = $this->getCurrentUserInfo();
- $result->addValue( "query", $this->getModuleName(), $r );
+ $result->addValue( 'query', $this->getModuleName(), $r );
}
protected function getCurrentUserInfo() {
$vals['id'] = intval( $wgUser->getId() );
$vals['name'] = $wgUser->getName();
- if ( $wgUser->isAnon() )
+ if ( $wgUser->isAnon() ) {
$vals['anon'] = '';
+ }
if ( isset( $this->prop['blockinfo'] ) ) {
if ( $wgUser->isBlocked() ) {
$vals['options'] = $wgUser->getOptions();
}
- if ( isset( $this->prop['preferencestoken'] ) && is_null( $this->getMain()->getRequest()->getVal( 'callback' ) ) ) {
+ if (
+ isset( $this->prop['preferencestoken'] ) &&
+ is_null( $this->getMain()->getRequest()->getVal( 'callback' ) )
+ )
+ {
$vals['preferencestoken'] = $wgUser->editToken();
}
if ( isset( $this->prop['email'] ) ) {
$vals['email'] = $wgUser->getEmail();
$auth = $wgUser->getEmailAuthenticationTimestamp();
- if ( !is_null( $auth ) )
+ if ( !is_null( $auth ) ) {
$vals['emailauthenticated'] = wfTimestamp( TS_ISO_8601, $auth );
+ }
}
return $vals;
}
- protected function getRateLimits()
- {
+ protected function getRateLimits() {
global $wgUser, $wgRateLimits;
- if ( !$wgUser->isPingLimitable() )
+ if ( !$wgUser->isPingLimitable() ) {
return array(); // No limits
+ }
// Find out which categories we belong to
$categories = array();
- if ( $wgUser->isAnon() )
+ if ( $wgUser->isAnon() ) {
$categories[] = 'anon';
- else
+ } else {
$categories[] = 'user';
- if ( $wgUser->isNewBie() )
- {
+ }
+ if ( $wgUser->isNewbie() ) {
$categories[] = 'ip';
$categories[] = 'subnet';
if ( !$wgUser->isAnon() )
// Now get the actual limits
$retval = array();
- foreach ( $wgRateLimits as $action => $limits )
- foreach ( $categories as $cat )
- if ( isset( $limits[$cat] ) && !is_null( $limits[$cat] ) )
- {
+ foreach ( $wgRateLimits as $action => $limits ) {
+ foreach ( $categories as $cat ) {
+ if ( isset( $limits[$cat] ) && !is_null( $limits[$cat] ) ) {
$retval[$action][$cat]['hits'] = intval( $limits[$cat][0] );
$retval[$action][$cat]['seconds'] = intval( $limits[$cat][1] );
}
+ }
+ }
return $retval;
}
public function getAllowedParams() {
- return array (
- 'prop' => array (
- ApiBase :: PARAM_DFLT => null,
- ApiBase :: PARAM_ISMULTI => true,
- ApiBase :: PARAM_TYPE => array (
+ return array(
+ 'prop' => array(
+ ApiBase::PARAM_DFLT => null,
+ ApiBase::PARAM_ISMULTI => true,
+ ApiBase::PARAM_TYPE => array(
'blockinfo',
'hasmsg',
'groups',
}
public function getParamDescription() {
- return array (
+ return array(
'prop' => array(
'What pieces of information to include',
' blockinfo - tags if the current user is blocked, by whom, and for what reason',
}
protected function getExamples() {
- return array (
+ return array(
'api.php?action=query&meta=userinfo',
'api.php?action=query&meta=userinfo&uiprop=blockinfo|groups|rights|hasmsg',
);
<?php
-/*
+/**
* Created on July 30, 2007
*
* API for MediaWiki 1.8+
*
- * Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl
+ * Copyright © 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl
*
* 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
if ( !defined( 'MEDIAWIKI' ) ) {
// Eclipse helper - will be ignored in production
- require_once ( 'ApiQueryBase.php' );
+ require_once( 'ApiQueryBase.php' );
}
/**
class ApiQueryUsers extends ApiQueryBase {
public function __construct( $query, $moduleName ) {
- parent :: __construct( $query, $moduleName, 'us' );
+ parent::__construct( $query, $moduleName, 'us' );
}
-
+
/**
* Get an array mapping token names to their handler functions.
* The prototype for a token function is func($user)
*/
protected function getTokenFunctions() {
// Don't call the hooks twice
- if ( isset( $this->tokenFunctions ) )
+ if ( isset( $this->tokenFunctions ) ) {
return $this->tokenFunctions;
+ }
// If we're in JSON callback mode, no tokens can be obtained
- if ( !is_null( $this->getMain()->getRequest()->getVal( 'callback' ) ) )
+ if ( !is_null( $this->getMain()->getRequest()->getVal( 'callback' ) ) ) {
return array();
+ }
$this->tokenFunctions = array(
'userrights' => array( 'ApiQueryUsers', 'getUserrightsToken' ),
wfRunHooks( 'APIQueryUsersTokens', array( &$this->tokenFunctions ) );
return $this->tokenFunctions;
}
-
- public static function getUserrightsToken( $user )
- {
+
+ public static function getUserrightsToken( $user ) {
global $wgUser;
// Since the permissions check for userrights is non-trivial,
// don't bother with it here
// Canonicalize user names
foreach ( $users as $u ) {
$n = User::getCanonicalName( $u );
- if ( $n === false || $n === '' )
- {
+ if ( $n === false || $n === '' ) {
$vals = array( 'name' => $u, 'invalid' => '' );
$fit = $result->addValue( array( 'query', $this->getModuleName() ),
null, $vals );
- if ( !$fit )
- {
+ if ( !$fit ) {
$this->setContinueEnumParameter( 'users',
implode( '|', array_diff( $users, $done ) ) );
$goodNames = array();
break;
}
$done[] = $u;
- }
- else
+ } else {
$goodNames[] = $n;
+ }
}
- if ( count( $goodNames ) )
- {
+ if ( count( $goodNames ) ) {
$db = $this->getDb();
$this->addTables( 'user', 'u1' );
$this->addFields( 'u1.*' );
$user = User::newFromRow( $r );
$name = $user->getName();
$data[$name]['name'] = $name;
- if ( isset( $this->prop['editcount'] ) )
+ if ( isset( $this->prop['editcount'] ) ) {
$data[$name]['editcount'] = intval( $user->getEditCount() );
- if ( isset( $this->prop['registration'] ) )
+ }
+ if ( isset( $this->prop['registration'] ) ) {
$data[$name]['registration'] = wfTimestampOrNull( TS_ISO_8601, $user->getRegistration() );
- if ( isset( $this->prop['groups'] ) && !is_null( $r->ug_group ) )
+ }
+ if ( isset( $this->prop['groups'] ) && !is_null( $r->ug_group ) ) {
// This row contains only one group, others will be added from other rows
$data[$name]['groups'][] = $r->ug_group;
+ }
if ( isset( $this->prop['blockinfo'] ) && !is_null( $r->blocker_name ) ) {
$data[$name]['blockedby'] = $r->blocker_name;
$data[$name]['blockreason'] = $r->ipb_reason;
}
- if ( isset( $this->prop['emailable'] ) && $user->canReceiveEmail() )
+ if ( isset( $this->prop['emailable'] ) && $user->canReceiveEmail() ) {
$data[$name]['emailable'] = '';
+ }
if ( isset( $this->prop['gender'] ) ) {
$gender = $user->getOption( 'gender' );
$data[$name]['gender'] = $gender;
}
- if ( !is_null( $params['token'] ) )
- {
+ if ( !is_null( $params['token'] ) ) {
$tokenFunctions = $this->getTokenFunctions();
- foreach ( $params['token'] as $t )
- {
+ foreach ( $params['token'] as $t ) {
$val = call_user_func( $tokenFunctions[$t], $user );
- if ( $val === false )
+ if ( $val === false ) {
$this->setWarning( "Action '$t' is not allowed for the current user" );
- else
+ } else {
$data[$name][$t . 'token'] = $val;
+ }
}
}
}
$iwUser = $urPage->fetchUser( $u );
if ( $iwUser instanceof UserRightsProxy ) {
$data[$u]['interwiki'] = '';
- if ( !is_null( $params['token'] ) )
- {
+ if ( !is_null( $params['token'] ) ) {
$tokenFunctions = $this->getTokenFunctions();
- foreach ( $params['token'] as $t )
- {
+ foreach ( $params['token'] as $t ) {
$val = call_user_func( $tokenFunctions[$t], $iwUser );
- if ( $val === false )
+ if ( $val === false ) {
$this->setWarning( "Action '$t' is not allowed for the current user" );
- else
+ } else {
$data[$u][$t . 'token'] = $val;
+ }
}
}
- } else
+ } else {
$data[$u]['missing'] = '';
+ }
} else {
if ( isset( $this->prop['groups'] ) && isset( $data[$u]['groups'] ) )
+ {
$this->getResult()->setIndexedTagName( $data[$u]['groups'], 'g' );
+ }
}
$fit = $result->addValue( array( 'query', $this->getModuleName() ),
null, $data[$u] );
- if ( !$fit )
- {
+ if ( !$fit ) {
$this->setContinueEnumParameter( 'users',
implode( '|', array_diff( $users, $done ) ) );
break;
}
public function getAllowedParams() {
- return array (
- 'prop' => array (
- ApiBase :: PARAM_DFLT => null,
- ApiBase :: PARAM_ISMULTI => true,
- ApiBase :: PARAM_TYPE => array (
+ return array(
+ 'prop' => array(
+ ApiBase::PARAM_DFLT => null,
+ ApiBase::PARAM_ISMULTI => true,
+ ApiBase::PARAM_TYPE => array(
'blockinfo',
'groups',
'editcount',
)
),
'users' => array(
- ApiBase :: PARAM_ISMULTI => true
+ ApiBase::PARAM_ISMULTI => true
),
'token' => array(
- ApiBase :: PARAM_TYPE => array_keys( $this->getTokenFunctions() ),
- ApiBase :: PARAM_ISMULTI => true
+ ApiBase::PARAM_TYPE => array_keys( $this->getTokenFunctions() ),
+ ApiBase::PARAM_ISMULTI => true
),
);
}
public function getParamDescription() {
- return array (
+ return array(
'prop' => array(
'What pieces of information to include',
' blockinfo - tags if the user is blocked, by whom, and for what reason',
<?php
-/*
+/**
* Created on Sep 25, 2006
*
* API for MediaWiki 1.8+
*
- * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
+ * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
*
* 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
if ( !defined( 'MEDIAWIKI' ) ) {
// Eclipse helper - will be ignored in production
- require_once ( 'ApiQueryBase.php' );
+ require_once( 'ApiQueryBase.php' );
}
/**
class ApiQueryWatchlist extends ApiQueryGeneratorBase {
public function __construct( $query, $moduleName ) {
- parent :: __construct( $query, $moduleName, 'wl' );
+ parent::__construct( $query, $moduleName, 'wl' );
}
public function execute() {
}
if ( !is_null( $params['prop'] ) && is_null( $resultPageSet ) ) {
-
$prop = array_flip( $params['prop'] );
$this->fld_ids = isset( $prop['ids'] );
$this->fld_notificationtimestamp = isset( $prop['notificationtimestamp'] );
if ( $this->fld_patrol ) {
- if ( !$user->useRCPatrol() && !$user->useNPPatrol() )
+ if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
$this->dieUsage( 'patrol property is not available', 'patrol' );
+ }
}
}
-
- $this->addFields( array (
+
+ $this->addFields( array(
'rc_namespace',
'rc_title',
'rc_timestamp'
) );
if ( is_null( $resultPageSet ) ) {
- $this->addFields( array (
+ $this->addFields( array(
'rc_cur_id',
'rc_this_oldid'
) );
$this->addFields( 'rc_cur_id' );
}
- $this->addTables( array (
+ $this->addTables( array(
'watchlist',
'page',
'recentchanges'
) );
$userId = $user->getId();
- $this->addWhere( array (
+ $this->addWhere( array(
'wl_namespace = rc_namespace',
'wl_title = rc_title',
'rc_cur_id = page_id',
if ( ( isset ( $show['minor'] ) && isset ( $show['!minor'] ) )
|| ( isset ( $show['bot'] ) && isset ( $show['!bot'] ) )
|| ( isset ( $show['anon'] ) && isset ( $show['!anon'] ) )
- || ( isset ( $show['patrolled'] ) && isset ( $show['!patrolled'] ) ) ) {
-
+ || ( isset ( $show['patrolled'] ) && isset ( $show['!patrolled'] ) )
+ )
+ {
$this->dieUsageMsg( array( 'show' ) );
}
-
+
// Check permissions. FIXME: should this check $user instead of $wgUser?
if ( ( isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) ) && !$wgUser->useRCPatrol() && !$wgUser->useNPPatrol() )
- $this->dieUsage( "You need the patrol right to request the patrolled flag", 'permissiondenied' );
+ {
+ $this->dieUsage( 'You need the patrol right to request the patrolled flag', 'permissiondenied' );
+ }
/* Add additional conditions to query depending upon parameters. */
- $this->addWhereIf( 'rc_minor = 0', isset ( $show['!minor'] ) );
- $this->addWhereIf( 'rc_minor != 0', isset ( $show['minor'] ) );
- $this->addWhereIf( 'rc_bot = 0', isset ( $show['!bot'] ) );
- $this->addWhereIf( 'rc_bot != 0', isset ( $show['bot'] ) );
- $this->addWhereIf( 'rc_user = 0', isset ( $show['anon'] ) );
- $this->addWhereIf( 'rc_user != 0', isset ( $show['!anon'] ) );
+ $this->addWhereIf( 'rc_minor = 0', isset( $show['!minor'] ) );
+ $this->addWhereIf( 'rc_minor != 0', isset( $show['minor'] ) );
+ $this->addWhereIf( 'rc_bot = 0', isset( $show['!bot'] ) );
+ $this->addWhereIf( 'rc_bot != 0', isset( $show['bot'] ) );
+ $this->addWhereIf( 'rc_user = 0', isset( $show['anon'] ) );
+ $this->addWhereIf( 'rc_user != 0', isset( $show['!anon'] ) );
$this->addWhereIf( 'rc_patrolled = 0', isset( $show['!patrolled'] ) );
$this->addWhereIf( 'rc_patrolled != 0', isset( $show['patrolled'] ) );
}
- if ( !is_null( $params['user'] ) && !is_null( $params['excludeuser'] ) )
+ if ( !is_null( $params['user'] ) && !is_null( $params['excludeuser'] ) ) {
$this->dieUsage( 'user and excludeuser cannot be used together', 'user-excludeuser' );
- if ( !is_null( $params['user'] ) )
+ }
+ if ( !is_null( $params['user'] ) ) {
$this->addWhereFld( 'rc_user_text', $params['user'] );
- if ( !is_null( $params['excludeuser'] ) )
+ }
+ if ( !is_null( $params['excludeuser'] ) ) {
$this->addWhere( 'rc_user_text != ' . $this->getDB()->addQuotes( $params['excludeuser'] ) );
+ }
$db = $this->getDB();
-
+
// This is an index optimization for mysql, as done in the Special:Watchlist page
- $this->addWhereIf( "rc_timestamp > ''", !isset ( $params['start'] ) && !isset ( $params['end'] ) && $db->getType() == 'mysql' );
+ $this->addWhereIf( "rc_timestamp > ''", !isset( $params['start'] ) && !isset( $params['end'] ) && $db->getType() == 'mysql' );
$this->addOption( 'LIMIT', $params['limit'] + 1 );
- $ids = array ();
+ $ids = array();
$count = 0;
$res = $this->select( __METHOD__ );
if ( is_null( $resultPageSet ) ) {
$vals = $this->extractRowInfo( $row );
$fit = $this->getResult()->addValue( array( 'query', $this->getModuleName() ), null, $vals );
- if ( !$fit )
- {
+ if ( !$fit ) {
$this->setContinueEnumParameter( 'start',
wfTimestamp( TS_ISO_8601, $row->rc_timestamp ) );
break;
if ( is_null( $resultPageSet ) ) {
$this->getResult()->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'item' );
- }
- elseif ( $params['allrev'] ) {
+ } elseif ( $params['allrev'] ) {
$resultPageSet->populateFromRevisionIDs( $ids );
} else {
$resultPageSet->populateFromPageIDs( $ids );
}
private function extractRowInfo( $row ) {
-
- $vals = array ();
+ $vals = array();
if ( $this->fld_ids ) {
$vals['pageid'] = intval( $row->rc_cur_id );
$title = Title::makeTitle( $row->rc_namespace, $row->rc_title );
- if ( $this->fld_title )
+ if ( $this->fld_title ) {
ApiQueryBase::addTitleInfo( $vals, $title );
+ }
if ( $this->fld_user ) {
$vals['user'] = $row->rc_user_text;
- if ( !$row->rc_user )
+ if ( !$row->rc_user ) {
$vals['anon'] = '';
+ }
}
if ( $this->fld_flags ) {
- if ( $row->rc_new )
+ if ( $row->rc_new ) {
$vals['new'] = '';
- if ( $row->rc_minor )
+ }
+ if ( $row->rc_minor ) {
$vals['minor'] = '';
- if ( $row->rc_bot )
+ }
+ if ( $row->rc_bot ) {
$vals['bot'] = '';
+ }
}
- if ( $this->fld_patrol && isset( $row->rc_patrolled ) )
+ if ( $this->fld_patrol && isset( $row->rc_patrolled ) ) {
$vals['patrolled'] = '';
+ }
- if ( $this->fld_timestamp )
+ if ( $this->fld_timestamp ) {
$vals['timestamp'] = wfTimestamp( TS_ISO_8601, $row->rc_timestamp );
+ }
if ( $this->fld_sizes ) {
$vals['oldlen'] = intval( $row->rc_old_len );
$vals['newlen'] = intval( $row->rc_new_len );
}
-
- if ( $this->fld_notificationtimestamp )
+
+ if ( $this->fld_notificationtimestamp ) {
$vals['notificationtimestamp'] = ( $row->wl_notificationtimestamp == null ) ? '' : wfTimestamp( TS_ISO_8601, $row->wl_notificationtimestamp );
+ }
- if ( $this->fld_comment && isset( $row->rc_comment ) )
+ if ( $this->fld_comment && isset( $row->rc_comment ) ) {
$vals['comment'] = $row->rc_comment;
-
+ }
+
if ( $this->fld_parsedcomment && isset( $row->rc_comment ) ) {
global $wgUser;
$vals['parsedcomment'] = $wgUser->getSkin()->formatComment( $row->rc_comment, $title );
}
public function getAllowedParams() {
- return array (
+ return array(
'allrev' => false,
- 'start' => array (
- ApiBase :: PARAM_TYPE => 'timestamp'
+ 'start' => array(
+ ApiBase::PARAM_TYPE => 'timestamp'
),
- 'end' => array (
- ApiBase :: PARAM_TYPE => 'timestamp'
+ 'end' => array(
+ ApiBase::PARAM_TYPE => 'timestamp'
),
'namespace' => array (
- ApiBase :: PARAM_ISMULTI => true,
- ApiBase :: PARAM_TYPE => 'namespace'
+ ApiBase::PARAM_ISMULTI => true,
+ ApiBase::PARAM_TYPE => 'namespace'
),
'user' => array(
- ApiBase :: PARAM_TYPE => 'user',
+ ApiBase::PARAM_TYPE => 'user',
),
'excludeuser' => array(
- ApiBase :: PARAM_TYPE => 'user',
+ ApiBase::PARAM_TYPE => 'user',
),
- 'dir' => array (
- ApiBase :: PARAM_DFLT => 'older',
- ApiBase :: PARAM_TYPE => array (
+ 'dir' => array(
+ ApiBase::PARAM_DFLT => 'older',
+ ApiBase::PARAM_TYPE => array(
'newer',
'older'
)
),
- 'limit' => array (
- ApiBase :: PARAM_DFLT => 10,
- ApiBase :: PARAM_TYPE => 'limit',
- ApiBase :: PARAM_MIN => 1,
- ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1,
- ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
+ 'limit' => array(
+ ApiBase::PARAM_DFLT => 10,
+ ApiBase::PARAM_TYPE => 'limit',
+ ApiBase::PARAM_MIN => 1,
+ ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
+ ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
),
- 'prop' => array (
- APIBase :: PARAM_ISMULTI => true,
- APIBase :: PARAM_DFLT => 'ids|title|flags',
- APIBase :: PARAM_TYPE => array (
+ 'prop' => array(
+ APIBase::PARAM_ISMULTI => true,
+ APIBase::PARAM_DFLT => 'ids|title|flags',
+ APIBase::PARAM_TYPE => array(
'ids',
'title',
'flags',
'notificationtimestamp'
)
),
- 'show' => array (
- ApiBase :: PARAM_ISMULTI => true,
- ApiBase :: PARAM_TYPE => array (
+ 'show' => array(
+ ApiBase::PARAM_ISMULTI => true,
+ ApiBase::PARAM_TYPE => array(
'minor',
'!minor',
'bot',
'!patrolled',
)
),
- 'owner' => array (
- ApiBase :: PARAM_TYPE => 'user'
+ 'owner' => array(
+ ApiBase::PARAM_TYPE => 'user'
),
- 'token' => array (
- ApiBase :: PARAM_TYPE => 'string'
+ 'token' => array(
+ ApiBase::PARAM_TYPE => 'string'
)
);
}
public function getParamDescription() {
- return array (
+ return array(
'allrev' => 'Include multiple revisions of the same page within given timeframe.',
'start' => 'The timestamp to start enumerating from.',
'end' => 'The timestamp to end enumerating.',
'dir' => 'In which direction to enumerate pages.',
'limit' => 'How many total results to return per request.',
'prop' => 'Which additional items to get (non-generator mode only).',
- 'show' => array (
+ 'show' => array(
'Show only items that meet this criteria.',
'For example, to see only minor edits done by logged-in users, set show=minor|!anon'
),
public function getDescription() {
return "Get all recent changes to pages in the logged in user's watchlist";
}
-
+
public function getPossibleErrors() {
return array_merge( parent::getPossibleErrors(), array(
array( 'code' => 'bad_wlowner', 'info' => 'Specified user does not exist' ),
}
protected function getExamples() {
- return array (
+ return array(
'api.php?action=query&list=watchlist',
'api.php?action=query&list=watchlist&wlprop=ids|title|timestamp|user|comment',
'api.php?action=query&list=watchlist&wlallrev&wlprop=ids|title|timestamp|user|comment',
<?php
-/*
+/**
* Created on Oct 4, 2008
*
* API for MediaWiki 1.8+
*
- * Copyright (C) 2008 Roan Kattouw <Firstname>.<Lastname>@home.nl
+ * Copyright © 2008 Roan Kattouw <Firstname>.<Lastname>@home.nl
*
* 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
if ( !defined( 'MEDIAWIKI' ) ) {
// Eclipse helper - will be ignored in production
- require_once ( 'ApiQueryBase.php' );
+ require_once( 'ApiQueryBase.php' );
}
/**
class ApiQueryWatchlistRaw extends ApiQueryGeneratorBase {
public function __construct( $query, $moduleName ) {
- parent :: __construct( $query, $moduleName, 'wr' );
+ parent::__construct( $query, $moduleName, 'wr' );
}
public function execute() {
$this->selectNamedDB( 'watchlist', DB_SLAVE, 'watchlist' );
- if ( !$wgUser->isLoggedIn() )
+ if ( !$wgUser->isLoggedIn() ) {
$this->dieUsage( 'You must be logged-in to have a watchlist', 'notloggedin' );
+ }
$params = $this->extractRequestParams();
$prop = array_flip( (array)$params['prop'] );
$show = array_flip( (array)$params['show'] );
- if ( isset( $show['changed'] ) && isset( $show['!changed'] ) )
+ if ( isset( $show['changed'] ) && isset( $show['!changed'] ) ) {
$this->dieUsageMsg( array( 'show' ) );
+ }
$this->addTables( 'watchlist' );
$this->addFields( array( 'wl_namespace', 'wl_title' ) );
$this->addWhereIf( 'wl_notificationtimestamp IS NOT NULL', isset( $show['changed'] ) );
$this->addWhereIf( 'wl_notificationtimestamp IS NULL', isset( $show['!changed'] ) );
- if ( isset( $params['continue'] ) )
- {
+ if ( isset( $params['continue'] ) ) {
$cont = explode( '|', $params['continue'] );
- if ( count( $cont ) != 2 )
+ if ( count( $cont ) != 2 ) {
$this->dieUsage( "Invalid continue param. You should pass the " .
"original value returned by the previous query", "_badcontinue" );
+ }
$ns = intval( $cont[0] );
$title = $this->getDB()->strencode( $this->titleToKey( $cont[1] ) );
- $this->addWhere( "wl_namespace > '$ns' OR " .
- "(wl_namespace = '$ns' AND " .
- "wl_title >= '$title')" );
+ $this->addWhere(
+ "wl_namespace > '$ns' OR " .
+ "(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 )
+ if ( count( $params['namespace'] ) == 1 ) {
$this->addOption( 'ORDER BY', 'wl_title' );
- else
+ } else {
$this->addOption( 'ORDER BY', 'wl_namespace, wl_title' );
+ }
$this->addOption( 'LIMIT', $params['limit'] + 1 );
$res = $this->select( __METHOD__ );
-
+
$db = $this->getDB();
$titles = array();
$count = 0;
- while ( $row = $db->fetchObject( $res ) )
- {
- if ( ++$count > $params['limit'] )
- {
+ while ( $row = $db->fetchObject( $res ) ) {
+ if ( ++$count > $params['limit'] ) {
// We've reached the one extra which shows that there are additional pages to be had. Stop here...
$this->setContinueEnumParameter( 'continue', $row->wl_namespace . '|' .
$this->keyToTitle( $row->wl_title ) );
}
$t = Title::makeTitle( $row->wl_namespace, $row->wl_title );
- if ( is_null( $resultPageSet ) )
- {
+ if ( is_null( $resultPageSet ) ) {
$vals = array();
ApiQueryBase::addTitleInfo( $vals, $t );
if ( isset( $prop['changed'] ) && !is_null( $row->wl_notificationtimestamp ) )
+ {
$vals['changed'] = wfTimestamp( TS_ISO_8601, $row->wl_notificationtimestamp );
+ }
$fit = $this->getResult()->addValue( $this->getModuleName(), null, $vals );
- if ( !$fit )
- {
+ if ( !$fit ) {
$this->setContinueEnumParameter( 'continue', $row->wl_namespace . '|' .
$this->keyToTitle( $row->wl_title ) );
break;
}
- }
- else
+ } else {
$titles[] = $t;
+ }
}
- if ( is_null( $resultPageSet ) )
+ if ( is_null( $resultPageSet ) ) {
$this->getResult()->setIndexedTagName_internal( $this->getModuleName(), 'wr' );
- else
+ } else {
$resultPageSet->populateFromTitles( $titles );
+ }
}
public function getAllowedParams() {
- return array (
+ return array(
'continue' => null,
- 'namespace' => array (
- ApiBase :: PARAM_ISMULTI => true,
- ApiBase :: PARAM_TYPE => 'namespace'
+ 'namespace' => array(
+ ApiBase::PARAM_ISMULTI => true,
+ ApiBase::PARAM_TYPE => 'namespace'
),
- 'limit' => array (
- ApiBase :: PARAM_DFLT => 10,
- ApiBase :: PARAM_TYPE => 'limit',
- ApiBase :: PARAM_MIN => 1,
- ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1,
- ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
+ 'limit' => array(
+ ApiBase::PARAM_DFLT => 10,
+ ApiBase::PARAM_TYPE => 'limit',
+ ApiBase::PARAM_MIN => 1,
+ ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
+ ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
),
- 'prop' => array (
- ApiBase :: PARAM_ISMULTI => true,
- ApiBase :: PARAM_TYPE => array (
+ 'prop' => array(
+ ApiBase::PARAM_ISMULTI => true,
+ ApiBase::PARAM_TYPE => array(
'changed',
)
),
- 'show' => array (
- ApiBase :: PARAM_ISMULTI => true,
- ApiBase :: PARAM_TYPE => array (
+ 'show' => array(
+ ApiBase::PARAM_ISMULTI => true,
+ ApiBase::PARAM_TYPE => array(
'changed',
'!changed',
)
}
public function getParamDescription() {
- return array (
+ return array(
'continue' => 'When more results are available, use this to continue',
'namespace' => 'Only list pages in the given namespace(s).',
'limit' => 'How many total results to return per request.',
public function getDescription() {
return "Get all pages on the logged in user's watchlist";
}
-
+
public function getPossibleErrors() {
return array_merge( parent::getPossibleErrors(), array(
array( 'code' => 'notloggedin', 'info' => 'You must be logged-in to have a watchlist' ),
}
protected function getExamples() {
- return array (
+ return array(
'api.php?action=query&list=watchlistraw',
'api.php?action=query&generator=watchlistraw&gwrshow=changed&prop=revisions',
);
<?php
-/*
+/**
* Created on Sep 4, 2006
*
* API for MediaWiki 1.8+
*
- * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
+ * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
*
* 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
if ( !defined( 'MEDIAWIKI' ) ) {
// Eclipse helper - will be ignored in production
- require_once ( 'ApiBase.php' );
+ require_once( 'ApiBase.php' );
}
/**
* @param $main ApiMain object
*/
public function __construct( $main ) {
- parent :: __construct( $main, 'result' );
+ parent::__construct( $main, 'result' );
$this->mIsRawMode = false;
$this->mCheckingSize = true;
$this->reset();
* Clear the current result data.
*/
public function reset() {
- $this->mData = array ();
+ $this->mData = array();
$this->mSize = 0;
}
*/
public static function size( $value ) {
$s = 0;
- if ( is_array( $value ) )
- foreach ( $value as $v )
+ if ( is_array( $value ) ) {
+ foreach ( $value as $v ) {
$s += self::size( $v );
- else if ( !is_object( $value ) )
+ }
+ } elseif ( !is_object( $value ) ) {
// Objects can't always be cast to string
$s = strlen( $value );
+ }
return $s;
}
* @param $name string Index of $arr to add $value at
* @param $value mixed
*/
- public static function setElement( & $arr, $name, $value ) {
- if ( $arr === null || $name === null || $value === null || !is_array( $arr ) || is_array( $name ) )
- ApiBase :: dieDebug( __METHOD__, 'Bad parameter' );
+ public static function setElement( &$arr, $name, $value ) {
+ if ( $arr === null || $name === null || $value === null || !is_array( $arr ) || is_array( $name ) ) {
+ ApiBase::dieDebug( __METHOD__, 'Bad parameter' );
+ }
if ( !isset ( $arr[$name] ) ) {
$arr[$name] = $value;
- }
- elseif ( is_array( $arr[$name] ) && is_array( $value ) ) {
+ } elseif ( is_array( $arr[$name] ) && is_array( $value ) ) {
$merged = array_intersect_key( $arr[$name], $value );
- if ( !count( $merged ) )
+ if ( !count( $merged ) ) {
$arr[$name] += $value;
- else
- ApiBase :: dieDebug( __METHOD__, "Attempting to merge element $name" );
- } else
- ApiBase :: dieDebug( __METHOD__, "Attempting to add element $name=$value, existing value is {$arr[$name]}" );
+ } else {
+ ApiBase::dieDebug( __METHOD__, "Attempting to merge element $name" );
+ }
+ } else {
+ ApiBase::dieDebug( __METHOD__, "Attempting to add element $name=$value, existing value is {$arr[$name]}" );
+ }
}
/**
* as a sub item of $arr. Use this parameter to create elements in
* format <elem>text</elem> without attributes
*/
- public static function setContent( & $arr, $value, $subElemName = null ) {
- if ( is_array( $value ) )
- ApiBase :: dieDebug( __METHOD__, 'Bad parameter' );
+ public static function setContent( &$arr, $value, $subElemName = null ) {
+ if ( is_array( $value ) ) {
+ ApiBase::dieDebug( __METHOD__, 'Bad parameter' );
+ }
if ( is_null( $subElemName ) ) {
- ApiResult :: setElement( $arr, '*', $value );
+ ApiResult::setElement( $arr, '*', $value );
} else {
- if ( !isset ( $arr[$subElemName] ) )
- $arr[$subElemName] = array ();
- ApiResult :: setElement( $arr[$subElemName], '*', $value );
+ if ( !isset( $arr[$subElemName] ) ) {
+ $arr[$subElemName] = array();
+ }
+ ApiResult::setElement( $arr[$subElemName], '*', $value );
}
}
* @param $arr array
* @param $tag string Tag name
*/
- public function setIndexedTagName( & $arr, $tag ) {
+ public function setIndexedTagName( &$arr, $tag ) {
// In raw mode, add the '_element', otherwise just ignore
- if ( !$this->getIsRawMode() )
+ if ( !$this->getIsRawMode() ) {
return;
+ }
if ( $arr === null || $tag === null || !is_array( $arr ) || is_array( $tag ) )
- ApiBase :: dieDebug( __METHOD__, 'Bad parameter' );
+ {
+ ApiBase::dieDebug( __METHOD__, 'Bad parameter' );
+ }
// Do not use setElement() as it is ok to call this more than once
$arr['_element'] = $tag;
}
* @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 );
+ if ( !is_array( $arr ) ) {
+ return;
+ }
+ foreach ( $arr as &$a ) {
+ if ( !is_array( $a ) ) {
+ continue;
+ }
+ $this->setIndexedTagName( $a, $tag );
+ $this->setIndexedTagName_recursive( $a, $tag );
}
}
* @param $tag string
*/
public function setIndexedTagName_internal( $path, $tag ) {
- $data = & $this->mData;
+ $data = &$this->mData;
foreach ( (array)$path as $p ) {
if ( !isset( $data[$p] ) ) {
$data[$p] = array();
}
- $data = & $data[$p];
+ $data = &$data[$p];
}
- if ( is_null( $data ) )
+ if ( is_null( $data ) ) {
return;
+ }
$this->setIndexedTagName( $data, $tag );
}
*/
public function addValue( $path, $name, $value ) {
global $wgAPIMaxResultSize;
- $data = & $this->mData;
+ $data = &$this->mData;
if ( $this->mCheckingSize ) {
$newsize = $this->mSize + self::size( $value );
- if ( $newsize > $wgAPIMaxResultSize )
+ if ( $newsize > $wgAPIMaxResultSize ) {
return false;
+ }
$this->mSize = $newsize;
}
if ( !is_null( $path ) ) {
if ( is_array( $path ) ) {
foreach ( $path as $p ) {
- if ( !isset ( $data[$p] ) )
- $data[$p] = array ();
- $data = & $data[$p];
+ if ( !isset( $data[$p] ) ) {
+ $data[$p] = array();
+ }
+ $data = &$data[$p];
}
} else {
- if ( !isset ( $data[$path] ) )
- $data[$path] = array ();
- $data = & $data[$path];
+ if ( !isset( $data[$path] ) ) {
+ $data[$path] = array();
+ }
+ $data = &$data[$path];
}
}
- if ( !$name )
- $data[] = $value; // Add list element
- else
- ApiResult :: setElement( $data, $name, $value ); // Add named element
+ if ( !$name ) {
+ $data[] = $value; // Add list element
+ } else {
+ ApiResult::setElement( $data, $name, $value ); // Add named element
+ }
return true;
}
* @param $name string
*/
public function unsetValue( $path, $name ) {
- $data = & $this->mData;
- if ( !is_null( $path ) )
+ $data = &$this->mData;
+ if ( !is_null( $path ) ) {
foreach ( (array)$path as $p ) {
- if ( !isset( $data[$p] ) )
+ if ( !isset( $data[$p] ) ) {
return;
- $data = & $data[$p];
+ }
+ $data = &$data[$p];
}
+ }
$this->mSize -= self::size( $data[$name] );
unset( $data[$name] );
}
/**
* Ensure all values in this result are valid UTF-8.
*/
- public function cleanUpUTF8()
- {
+ public function cleanUpUTF8() {
array_walk_recursive( $this->mData, array( 'ApiResult', 'cleanUp_helper' ) );
}
/**
* Callback function for cleanUpUTF8()
*/
- private static function cleanUp_helper( &$s )
- {
- if ( !is_string( $s ) )
+ private static function cleanUp_helper( &$s ) {
+ if ( !is_string( $s ) ) {
return;
+ }
global $wgContLang;
$s = $wgContLang->normalize( $s );
}
public function execute() {
- ApiBase :: dieDebug( __METHOD__, 'execute() is not supported on Result object' );
+ ApiBase::dieDebug( __METHOD__, 'execute() is not supported on Result object' );
}
public function getVersion() {
if ( !defined( 'MEDIAWIKI' ) ) {
// Eclipse helper - will be ignored in production
- require_once ( "ApiBase.php" );
+ require_once( "ApiBase.php" );
}
/**
class ApiRollback extends ApiBase {
public function __construct( $main, $action ) {
- parent :: __construct( $main, $action );
+ parent::__construct( $main, $action );
}
public function execute() {
$params = $this->extractRequestParams();
$titleObj = null;
- if ( !isset( $params['title'] ) )
+ if ( !isset( $params['title'] ) ) {
$this->dieUsageMsg( array( 'missingparam', 'title' ) );
- if ( !isset( $params['user'] ) )
+ }
+ if ( !isset( $params['user'] ) ) {
$this->dieUsageMsg( array( 'missingparam', 'user' ) );
+ }
$titleObj = Title::newFromText( $params['title'] );
- if ( !$titleObj )
+ if ( !$titleObj ) {
$this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
- if ( !$titleObj->exists() )
+ }
+ if ( !$titleObj->exists() ) {
$this->dieUsageMsg( array( 'notanarticle' ) );
+ }
// We need to be able to revert IPs, but getCanonicalName rejects them
$username = User::isIP( $params['user'] )
? $params['user']
: User::getCanonicalName( $params['user'] );
- if ( !$username )
+ if ( !$username ) {
$this->dieUsageMsg( array( 'invaliduser', $params['user'] ) );
+ }
$articleObj = new Article( $titleObj );
- $summary = ( isset( $params['summary'] ) ? $params['summary'] : "" );
+ $summary = ( isset( $params['summary'] ) ? $params['summary'] : '' );
$details = null;
$retval = $articleObj->doRollback( $username, $summary, $params['token'], $params['markbot'], $details );
- if ( $retval )
+ if ( $retval ) {
// We don't care about multiple errors, just report one of them
$this->dieUsageMsg( reset( $retval ) );
+ }
$info = array(
'title' => $titleObj->getPrefixedText(),
$this->getResult()->addValue( null, $this->getModuleName(), $info );
}
- public function mustBePosted() { return true; }
+ public function mustBePosted() {
+ return true;
+ }
public function isWriteMode() {
return true;
}
public function getAllowedParams() {
- return array (
+ return array(
'title' => null,
'user' => null,
'token' => null,
}
public function getParamDescription() {
- return array (
+ return array(
'title' => 'Title of the page you want to rollback.',
'user' => 'Name of the user whose edits are to be rolled back. If set incorrectly, you\'ll get a badtoken error.',
'token' => 'A rollback token previously retrieved through prop=revisions',
public function getDescription() {
return array(
- 'Undo the last edit to the page. If the last user who edited the page made multiple edits in a row,',
- 'they will all be rolled back.'
- );
+ 'Undo the last edit to the page. If the last user who edited the page made multiple edits in a row,',
+ 'they will all be rolled back.'
+ );
}
-
+
public function getPossibleErrors() {
return array_merge( parent::getPossibleErrors(), array(
array( 'missingparam', 'title' ),
array( 'invaliduser', 'user' ),
) );
}
-
+
public function getTokenSalt() {
return '';
}
protected function getExamples() {
- return array (
+ return array(
'api.php?action=rollback&title=Main%20Page&user=Catrope&token=123ABC',
'api.php?action=rollback&title=Main%20Page&user=217.121.114.116&token=123ABC&summary=Reverting%20vandalism&markbot=1'
);
<?php
-/*
+/**
* Created on Sep 7, 2007
* API for MediaWiki 1.8+
*
- * Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl
+ * Copyright © 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl
*
* 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
if ( !defined( 'MEDIAWIKI' ) ) {
// Eclipse helper - will be ignored in production
- require_once ( "ApiBase.php" );
+ require_once( "ApiBase.php" );
}
/**
class ApiUnblock extends ApiBase {
public function __construct( $main, $action ) {
- parent :: __construct( $main, $action );
+ parent::__construct( $main, $action );
}
/**
global $wgUser;
$params = $this->extractRequestParams();
- if ( $params['gettoken'] )
- {
+ if ( $params['gettoken'] ) {
$res['unblocktoken'] = $wgUser->editToken();
$this->getResult()->addValue( null, $this->getModuleName(), $res );
return;
}
- if ( is_null( $params['id'] ) && is_null( $params['user'] ) )
+ if ( is_null( $params['id'] ) && is_null( $params['user'] ) ) {
$this->dieUsageMsg( array( 'unblock-notarget' ) );
- if ( !is_null( $params['id'] ) && !is_null( $params['user'] ) )
+ }
+ if ( !is_null( $params['id'] ) && !is_null( $params['user'] ) ) {
$this->dieUsageMsg( array( 'unblock-idanduser' ) );
+ }
- if ( !$wgUser->isAllowed( 'block' ) )
+ if ( !$wgUser->isAllowed( 'block' ) ) {
$this->dieUsageMsg( array( 'cantunblock' ) );
+ }
$id = $params['id'];
$user = $params['user'];
$reason = ( is_null( $params['reason'] ) ? '' : $params['reason'] );
$retval = IPUnblockForm::doUnblock( $id, $user, $reason, $range );
- if ( $retval )
+ if ( $retval ) {
$this->dieUsageMsg( $retval );
+ }
$res['id'] = intval( $id );
$res['user'] = $user;
}
public function getAllowedParams() {
- return array (
+ return array(
'id' => null,
'user' => null,
'token' => null,
}
public function getParamDescription() {
- return array (
+ return array(
'id' => 'ID of the block you want to unblock (obtained through list=blocks). Cannot be used together with user',
'user' => 'Username, IP address or IP range you want to unblock. Cannot be used together with id',
'token' => 'An unblock token previously obtained through the gettoken parameter or prop=info',
'Unblock a user.'
);
}
-
- public function getPossibleErrors() {
+
+ public function getPossibleErrors() {
return array_merge( parent::getPossibleErrors(), array(
array( 'unblock-notarget' ),
array( 'unblock-idanduser' ),
array( 'cantunblock' ),
- ) );
+ ) );
}
-
+
public function getTokenSalt() {
return '';
}
protected function getExamples() {
- return array (
+ return array(
'api.php?action=unblock&id=105',
'api.php?action=unblock&user=Bob&reason=Sorry%20Bob'
);
if ( !defined( 'MEDIAWIKI' ) ) {
// Eclipse helper - will be ignored in production
- require_once ( "ApiBase.php" );
+ require_once( "ApiBase.php" );
}
/**
class ApiUndelete extends ApiBase {
public function __construct( $main, $action ) {
- parent :: __construct( $main, $action );
+ parent::__construct( $main, $action );
}
public function execute() {
$params = $this->extractRequestParams();
$titleObj = null;
- if ( !isset( $params['title'] ) )
+ if ( !isset( $params['title'] ) ) {
$this->dieUsageMsg( array( 'missingparam', 'title' ) );
+ }
- if ( !$wgUser->isAllowed( 'undelete' ) )
+ if ( !$wgUser->isAllowed( 'undelete' ) ) {
$this->dieUsageMsg( array( 'permdenied-undelete' ) );
+ }
- if ( $wgUser->isBlocked() )
+ if ( $wgUser->isBlocked() ) {
$this->dieUsageMsg( array( 'blockedtext' ) );
+ }
$titleObj = Title::newFromText( $params['title'] );
- if ( !$titleObj )
+ if ( !$titleObj ) {
$this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
+ }
// Convert timestamps
- if ( !isset( $params['timestamps'] ) )
+ if ( !isset( $params['timestamps'] ) ) {
$params['timestamps'] = array();
- if ( !is_array( $params['timestamps'] ) )
+ }
+ if ( !is_array( $params['timestamps'] ) ) {
$params['timestamps'] = array( $params['timestamps'] );
- foreach ( $params['timestamps'] as $i => $ts )
+ }
+ foreach ( $params['timestamps'] as $i => $ts ) {
$params['timestamps'][$i] = wfTimestamp( TS_MW, $ts );
+ }
$pa = new PageArchive( $titleObj );
$dbw = wfGetDB( DB_MASTER );
$dbw->begin();
$retval = $pa->undelete( ( isset( $params['timestamps'] ) ? $params['timestamps'] : array() ), $params['reason'] );
- if ( !is_array( $retval ) )
+ if ( !is_array( $retval ) ) {
$this->dieUsageMsg( array( 'cannotundelete' ) );
+ }
- if ( $retval[1] )
+ if ( $retval[1] ) {
wfRunHooks( 'FileUndeleteComplete',
array( $titleObj, array(), $wgUser, $params['reason'] ) );
+ }
$info['title'] = $titleObj->getPrefixedText();
$info['revisions'] = intval( $retval[0] );
}
public function getAllowedParams() {
- return array (
+ return array(
'title' => null,
'token' => null,
- 'reason' => "",
+ 'reason' => '',
'timestamps' => array(
- ApiBase :: PARAM_ISMULTI => true
+ ApiBase::PARAM_ISMULTI => true
)
);
}
public function getParamDescription() {
- return array (
+ return array(
'title' => 'Title of the page you want to restore.',
'token' => 'An undelete token previously retrieved through list=deletedrevs',
'reason' => 'Reason for restoring (optional)',
'retrieved through list=deletedrevs'
);
}
-
+
public function getPossibleErrors() {
return array_merge( parent::getPossibleErrors(), array(
array( 'missingparam', 'title' ),
array( 'cannotundelete' ),
) );
}
-
+
public function getTokenSalt() {
return '';
}
protected function getExamples() {
- return array (
+ return array(
'api.php?action=undelete&title=Main%20Page&token=123ABC&reason=Restoring%20main%20page',
'api.php?action=undelete&title=Main%20Page&token=123ABC×tamps=20070703220045|20070702194856'
);
<?php
-/*
+/**
* Created on Aug 21, 2008
* API for MediaWiki 1.8+
*
- * Copyright (C) 2008 - 2010 Bryan Tong Minh <Bryan.TongMinh@Gmail.com>
+ * Copyright © 2008 - 2010 Bryan Tong Minh <Bryan.TongMinh@Gmail.com>
*
* 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
global $wgUser, $wgAllowCopyUploads;
// Check whether upload is enabled
- if ( !UploadBase::isEnabled() )
+ if ( !UploadBase::isEnabled() ) {
$this->dieUsageMsg( array( 'uploaddisabled' ) );
+ }
$this->mParams = $this->extractRequestParams();
$request = $this->getMain()->getRequest();
* Upload stashed in a previous request
*/
// Check the session key
- if ( !isset( $_SESSION['wsUploadData'][$this->mParams['sessionkey']] ) )
+ if ( !isset( $_SESSION['wsUploadData'][$this->mParams['sessionkey']] ) ) {
$this->dieUsageMsg( array( 'invalid-session-key' ) );
+ }
$this->mUpload = new UploadFromStash();
$this->mUpload->initialize( $this->mParams['filename'],
$_SESSION['wsUploadData'][$this->mParams['sessionkey']] );
} elseif ( isset( $this->mParams['filename'] ) ) {
/**
- * Upload from url, etc
+ * Upload from URL, etc.
* Parameter filename is required
*/
-
if ( isset( $this->mParams['file'] ) ) {
$this->mUpload = new UploadFromFile();
$this->mUpload->initialize(
$request->getFileSize( 'file' )
);
} elseif ( isset( $this->mParams['url'] ) ) {
- // make sure upload by url is enabled:
- if ( !$wgAllowCopyUploads )
+ // make sure upload by URL is enabled:
+ if ( !$wgAllowCopyUploads ) {
$this->dieUsageMsg( array( 'uploaddisabled' ) );
+ }
// make sure the current user can upload
- if ( ! $wgUser->isAllowed( 'upload_by_url' ) )
+ if ( !$wgUser->isAllowed( 'upload_by_url' ) ) {
$this->dieUsageMsg( array( 'badaccess-groups' ) );
+ }
$this->mUpload = new UploadFromUrl();
$this->mUpload->initialize( $this->mParams['filename'],
$this->dieUsage( $status->getWikiText(), 'fetchfileerror' );
}
}
- } else $this->dieUsageMsg( array( 'missingparam', 'filename' ) );
+ } else {
+ $this->dieUsageMsg( array( 'missingparam', 'filename' ) );
+ }
- if ( !isset( $this->mUpload ) )
+ if ( !isset( $this->mUpload ) ) {
$this->dieUsage( 'No upload module set', 'nomodule' );
+ }
// Check whether the user has the appropriate permissions to upload anyway
$permission = $this->mUpload->isAllowed( $wgUser );
if ( $permission !== true ) {
- if ( !$wgUser->isLoggedIn() )
+ if ( !$wgUser->isLoggedIn() ) {
$this->dieUsageMsg( array( 'mustbeloggedin', 'upload' ) );
- else
+ } else {
$this->dieUsageMsg( array( 'badaccess-groups' ) );
+ }
}
// Perform the upload
$result = $this->performUpload();
if ( isset( $result['chunked-output'] ) ) {
foreach ( $result['chunked-output'] as $key => $value ) {
- if ( $value === null ) $value = "";
+ if ( $value === null ) {
+ $value = '';
+ }
$this->getResult()->addValue( null, $key, $value );
}
} else {
$warnings['duplicate'] = $dupes;
}
-
if ( isset( $warnings['exists'] ) ) {
$warning = $warnings['exists'];
unset( $warnings['exists'] );
$result['warnings'] = $warnings;
$sessionKey = $this->mUpload->stashSession();
- if ( !$sessionKey )
+ if ( !$sessionKey ) {
$this->dieUsage( 'Stashing temporary file failed', 'stashfailed' );
+ }
$result['sessionkey'] = $sessionKey;
}
// Use comment as initial page text by default
- if ( is_null( $this->mParams['text'] ) )
+ if ( is_null( $this->mParams['text'] ) ) {
$this->mParams['text'] = $this->mParams['comment'];
+ }
// No errors, no warnings: do the upload
$status = $this->mUpload->performUpload( $this->mParams['comment'],
$this->dieUsage( 'An internal error occurred', 'internal-error', 0, $error );
} elseif ( $this->mParams['enablechunks'] ) {
- return array( "chunked-output" => $status->value );
+ return array( 'chunked-output' => $status->value );
}
$file = $this->mUpload->getLocalFile();
'sessionkey' => null,
);
- if ( $this->getMain()->isInternalMode() )
+ if ( $this->getMain()->isInternalMode() ) {
$params['internalhttpsession'] = null;
+ }
return $params;
-
}
public function getParamDescription() {
'log out and then log back in). Also you must get and send an edit token before doing any upload stuff.'
);
}
-
- public function getPossibleErrors() {
+
+ public function getPossibleErrors() {
return array_merge( parent::getPossibleErrors(), array(
array( 'uploaddisabled' ),
array( 'invalid-session-key' ),
array( 'code' => 'overwrite', 'info' => 'Overwriting an existing file is not allowed' ),
array( 'code' => 'stashfailed', 'info' => 'Stashing temporary file failed' ),
array( 'code' => 'internal-error', 'info' => 'An internal error occurred' ),
- ) );
+ ) );
}
-
+
public function getTokenSalt() {
return '';
}
<?php
-/*
+/**
* Created on Mar 24, 2009
* API for MediaWiki 1.8+
*
- * Copyright (C) 2009 Roan Kattouw <Firstname>.<Lastname>@home.nl
+ * Copyright © 2009 Roan Kattouw <Firstname>.<Lastname>@home.nl
*
* 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
if ( !defined( 'MEDIAWIKI' ) ) {
// Eclipse helper - will be ignored in production
- require_once ( "ApiBase.php" );
+ require_once( "ApiBase.php" );
}
/**
class ApiUserrights extends ApiBase {
public function __construct( $main, $action ) {
- parent :: __construct( $main, $action );
+ parent::__construct( $main, $action );
}
public function execute() {
$params = $this->extractRequestParams();
-
+
// User already validated in call to getTokenSalt from Main
$form = new UserrightsPage;
$user = $form->fetchUser( $params['user'] );
-
+
$r['user'] = $user->getName();
list( $r['added'], $r['removed'] ) =
$form->doSaveUserGroups(
return array (
'user' => null,
'add' => array(
- ApiBase :: PARAM_TYPE => User::getAllGroups(),
- ApiBase :: PARAM_ISMULTI => true
+ ApiBase::PARAM_TYPE => User::getAllGroups(),
+ ApiBase::PARAM_ISMULTI => true
),
'remove' => array(
- ApiBase :: PARAM_TYPE => User::getAllGroups(),
- ApiBase :: PARAM_ISMULTI => true
+ ApiBase::PARAM_TYPE => User::getAllGroups(),
+ ApiBase::PARAM_ISMULTI => true
),
'token' => null,
'reason' => array(
- ApiBase :: PARAM_DFLT => ''
+ ApiBase::PARAM_DFLT => ''
)
);
}
public function getParamDescription() {
- return array (
+ return array(
'user' => 'User name',
'add' => 'Add the user to these groups',
'remove' => 'Remove the user from these groups',
'Add/remove a user to/from groups',
);
}
-
- public function getPossibleErrors() {
+
+ public function getPossibleErrors() {
return array_merge( parent::getPossibleErrors(), array(
array( 'missingparam', 'user' ),
- ) );
+ ) );
}
-
+
public function getTokenSalt() {
$params = $this->extractRequestParams();
- if ( is_null( $params['user'] ) )
+ if ( is_null( $params['user'] ) ) {
$this->dieUsageMsg( array( 'missingparam', 'user' ) );
+ }
$form = new UserrightsPage;
$user = $form->fetchUser( $params['user'] );
- if ( $user instanceof WikiErrorMsg )
+ if ( $user instanceof WikiErrorMsg ) {
$this->dieUsageMsg( array_merge(
(array)$user->getMessageKey(), $user->getMessageArgs() ) );
+ }
return $user->getName();
}
protected function getExamples() {
- return array (
+ return array(
'api.php?action=userrights&user=FooBot&add=bot&remove=sysop|bureaucrat&token=123ABC'
);
}
<?php
-/*
+/**
* Created on Jan 4, 2008
*
* API for MediaWiki 1.8+
*
- * Copyright (C) 2008 Yuri Astrakhan <Firstname><Lastname>@gmail.com,
+ * Copyright © 2008 Yuri Astrakhan <Firstname><Lastname>@gmail.com,
*
* 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
if ( !defined( 'MEDIAWIKI' ) ) {
// Eclipse helper - will be ignored in production
- require_once ( 'ApiBase.php' );
+ require_once( 'ApiBase.php' );
}
/**
class ApiWatch extends ApiBase {
public function __construct( $main, $action ) {
- parent :: __construct( $main, $action );
+ parent::__construct( $main, $action );
}
public function execute() {
global $wgUser;
- if ( !$wgUser->isLoggedIn() )
+ 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 )
+ if ( !$title ) {
$this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
+ }
$article = new Article( $title );
$res = array( 'title' => $title->getPrefixedText() );
- if ( $params['unwatch'] )
- {
+ if ( $params['unwatch'] ) {
$res['unwatched'] = '';
$success = $article->doUnwatch();
- }
- else
- {
+ } else {
$res['watched'] = '';
$success = $article->doWatch();
}
- if ( !$success )
+ if ( !$success ) {
$this->dieUsageMsg( array( 'hookaborted' ) );
+ }
$this->getResult()->addValue( null, $this->getModuleName(), $res );
}
}
public function getAllowedParams() {
- return array (
+ return array(
'title' => null,
'unwatch' => false,
);
}
public function getParamDescription() {
- return array (
+ return array(
'title' => 'The page to (un)watch',
'unwatch' => 'If set the page will be unwatched rather than watched',
);
}
public function getDescription() {
- return array (
+ return array(
'Add or remove a page from/to the current user\'s watchlist'
);
}
-
+
public function getPossibleErrors() {
return array_merge( parent::getPossibleErrors(), array(
array( 'code' => 'notloggedin', 'info' => 'You must be logged-in to have a watchlist' ),