canonical language variant.
* Fixed "link" parameter in image links with "thumb" parameter.
* (bug 23936) Add "displaytitle" to query/info API
-* (bug 24485) Make iwbacklinks a generator, display iwprefix and iwtitle optional
+* (bug 24485) Make iwbacklinks a generator, optionally display iwprefix and iwtitle
=== Languages updated in 1.17 ===
* Return true if we're to watch the page, false if not, null if no change.
* @param $watchlist String Valid values: 'watch', 'unwatch', 'preferences', 'nochange'
* @param $titleObj Title the page under consideration
- * @param $userOption The user option to consider when $watchlist=preferences.
+ * @param $userOption The user option to consider when $watchlist=preferences.
* If not set will magically default to either watchdefault or watchcreations
* @returns mixed
*/
}
$value[$key] = $title->getText();
}
-
+
if ( !$multi ) {
$value = $value[0];
}
/**
* Gets the user for whom to get the watchlist
- *
+ *
* @returns User
*/
public function getWatchlistUser( $params ) {
public function getDescription() {
return 'Block a user';
}
-
+
public function getPossibleErrors() {
return array_merge( parent::getPossibleErrors(), array(
array( 'missingparam', 'user' ),
array( 'ipbnounblockself' ),
) );
}
-
+
public function getTokenSalt() {
return '';
}
$newArticle->getTimestamp() );
}
break;
-
+
case EditPage::AS_SUMMARY_NEEDED:
$this->dieUsageMsg( array( 'summaryrequired' ) );
case EditPage::AS_END:
// This usually means some kind of race condition
- // or DB weirdness occurred.
+ // or DB weirdness occurred.
if ( is_array( $result ) && count( $result ) > 0 ) {
$this->dieUsageMsg( array( 'unknownerror', $result[0][0] ) );
}
-
+
// Unknown error, but no specific error message
// Fall through
default:
public function disable() {
$this->mDisabled = true;
}
-
+
public function isDisabled() {
return $this->mDisabled;
}
} else {
if ( $key == '*' ) // bug 21922 - Quote asterix used as keys
$key = "'*'";
-
+
// It's mapped
if ( $value !== '' && !is_null( $value ) )
$string = $spaces . $key . ': ' . $value . "\n";
public function execute() {
// Get parameters
$params = $this->extractRequestParams();
-
+
if ( !isset( $params['modules'] ) && !isset( $params['querymodules'] ) ) {
$this->dieUsage( '', 'help' );
}
-
+
$this->getMain()->setHelp();
-
+
$result = $this->getResult();
$queryObj = new ApiQuery( $this->getMain(), 'query' );
$r = array();
}
$module = new $qmodArr[$qm]( $this, $qm );
$type = $queryObj->getModuleType( $qm );
-
+
if ( $type === null ) {
$r[] = array( 'name' => $qm, 'missing' => '' );
continue;
}
-
+
$r[] = $this->buildModuleHelp( $module, $type );
}
}
$result->setIndexedTagName( $r, 'module' );
$result->addValue( null, $this->getModuleName(), $r );
}
-
+
private function buildModuleHelp( $module, $type ) {
$msg = ApiMain::makeHelpMsgHeader( $module, $type );
-
+
$msg2 = $module->makeHelpMsg();
if ( $msg2 !== false ) {
$msg .= $msg2;
}
-
+
return $msg;
}
public function isReadMode() {
return false;
}
-
+
public function getAllowedParams() {
return array(
'modules' => array(
public function getDescription() {
return 'Display this help screen. Or the help screen for the specified module';
}
-
+
protected function getExamples() {
return array(
'Whole help page:',
$result['cookieprefix'] = $wgCookiePrefix;
$result['sessionid'] = session_id();
break;
-
+
case LoginForm::NEED_TOKEN:
global $wgCookiePrefix;
$result['result'] = 'NeedToken';
$result['cookieprefix'] = $wgCookiePrefix;
$result['sessionid'] = session_id();
break;
-
+
case LoginForm::WRONG_TOKEN:
$result['result'] = 'WrongToken';
break;
public function getModule() {
return $this->mModule;
}
-
+
/**
* Get the result formatter object. Only works after setupExecuteAction()
*/
* Set the type of caching headers which will be sent.
*
* @param $mode One of:
- * - 'public': Cache this object in public caches, if the maxage or smaxage
+ * - 'public': Cache this object in public caches, if the maxage or smaxage
* parameter is set, or if setCacheMaxAge() was called. If a maximum age is
* not provided by any of these means, the object will be private.
* - 'private': Cache this object only in private client-side caches.
* - 'anon-public-user-private': Make this object cacheable for logged-out
- * users, but private for logged-in users. IMPORTANT: If this is set, it must be
- * set consistently for a given URL, it cannot be set differently depending on
+ * users, but private for logged-in users. IMPORTANT: If this is set, it must be
+ * set consistently for a given URL, it cannot be set differently depending on
* things like the contents of the database, or whether the user is logged in.
*
* If the wiki does not allow anonymous users to read it, the mode set here
- * will be ignored, and private caching headers will always be sent. In other words,
+ * will be ignored, and private caching headers will always be sent. In other words,
* the "public" mode is equivalent to saying that the data sent is as public as a page
* view.
*
- * For user-dependent data, the private mode should generally be used. The
- * anon-public-user-private mode should only be used where there is a particularly
+ * For user-dependent data, the private mode should generally be used. The
+ * anon-public-user-private mode should only be used where there is a particularly
* good performance reason for caching the anonymous response, but where the
- * response to logged-in users may differ, or may contain private data.
+ * response to logged-in users may differ, or may contain private data.
*
* If this function is never called, then the default will be the private mode.
*/
public function setCacheMode( $mode ) {
if ( !in_array( $mode, array( 'private', 'public', 'anon-public-user-private' ) ) ) {
- wfDebug( __METHOD__.": unrecognised cache mode \"$mode\"\n" );
+ wfDebug( __METHOD__ . ": unrecognised cache mode \"$mode\"\n" );
// Ignore for forwards-compatibility
return;
}
if ( !in_array( 'read', User::getGroupPermissions( array( '*' ) ), true ) ) {
// Private wiki, only private headers
if ( $mode !== 'private' ) {
- wfDebug( __METHOD__.": ignoring request for $mode cache mode, private wiki\n" );
+ wfDebug( __METHOD__ . ": ignoring request for $mode cache mode, private wiki\n" );
return;
}
}
- wfDebug( __METHOD__.": setting cache mode $mode\n" );
+ wfDebug( __METHOD__ . ": setting cache mode $mode\n" );
$this->mCacheMode = $mode;
}
-
+
/**
- * @deprecated Private caching is now the default, so there is usually no
- * need to call this function. If there is a need, you can use
+ * @deprecated Private caching is now the default, so there is usually no
+ * need to call this function. If there is a need, you can use
* $this->setCacheMode('private')
*/
public function setCachePrivate() {
* Boolean values will be formatted as such, by including or omitting
* without an equals sign.
*
- * Cache control values set here will only be used if the cache mode is not
+ * Cache control values set here will only be used if the cache mode is not
* private, see setCacheMode().
*/
public function setCacheControl( $directives ) {
$this->mCacheControl = $directives + $this->mCacheControl;
}
-
+
/**
* Make sure Vary: Cookie and friends are set. Use this when the output of a request
* may be cached for anons but may not be cached for logged-in users.
$this->printResult( true );
}
- // Send cache headers after any code which might generate an error, to
+ // Send cache headers after any code which might generate an error, to
// avoid sending public cache headers for errors.
$this->sendCacheHeaders();
// Give a debugging message if the user object is unstubbed on a public request
global $wgUser;
if ( !( $wgUser instanceof StubUser ) ) {
- wfDebug( __METHOD__." \$wgUser is unstubbed on a public request!\n" );
+ wfDebug( __METHOD__ . " \$wgUser is unstubbed on a public request!\n" );
}
}
$this->getResult()->addValue( null, 'requestid', $requestid );
}
$servedby = $this->getParameter( 'servedby' );
- if( $servedby ) {
+ if ( $servedby ) {
$this->getResult()->addValue( null, 'servedby', wfHostName() );
}
if ( $resolveRedirects ) {
$this->mPendingRedirectIDs = array();
}
-
+
$this->mConvertTitles = $convertTitles;
$this->mConvertedTitles = array();
public function getNormalizedTitles() {
return $this->mNormalizedTitles;
}
-
+
/**
* Get a list of title conversions - maps a title to its converted
* version.
* @return array raw_prefixed_title (string) => prefixed_title (string)
- */
+ */
public function getConvertedTitles() {
return $this->mConvertedTitles;
}
public function getMissingRevisionIDs() {
return $this->mMissingRevIDs;
}
-
+
/**
* Get the list of titles with negative namespace
* @return array Title
continue; // There's nothing else we can do
}
$unconvertedTitle = $titleObj->getPrefixedText();
- $titleWasConverted = false;
+ $titleWasConverted = false;
$iw = $titleObj->getInterwiki();
if ( strval( $iw ) !== '' ) {
// This title is an interwiki link.
$wgContLang->findVariantLink( $title, $titleObj );
$titleWasConverted = $unconvertedTitle !== $titleObj->getPrefixedText();
}
-
-
+
+
if ( $titleObj->getNamespace() < 0 ) {
// Handle Special and Media pages
$titleObj = $titleObj->fixSpecialName();
$result_array['headhtml'] = array();
$result->setContent( $result_array['headhtml'], $out->headElement( $userSkin ) );
}
-
+
if ( isset( $prop['iwlinks'] ) ) {
$result_array['iwlinks'] = $this->formatIWLinks( $p_result->getInterwikiLinks() );
}
foreach ( $titles as $title => $id ) {
$entry = array();
$entry['prefix'] = $prefix;
-
+
$title = Title::newFromText( "{$prefix}:{$title}" );
if ( $title ) {
$entry['url'] = $title->getFullURL();
}
-
+
$this->getResult()->setContent( $entry, $title->getFullText() );
$result[] = $entry;
}
function getModules() {
return array_merge( $this->mQueryPropModules, $this->mQueryListModules, $this->mQueryMetaModules );
}
-
+
/**
* Get whether the specified module is a prop, list or a meta query module
* @param $moduleName string Name of the module to find type for
if ( array_key_exists ( $moduleName, $this->mQueryPropModules ) ) {
return 'prop';
}
-
+
if ( array_key_exists ( $moduleName, $this->mQueryListModules ) ) {
return 'list';
}
-
+
if ( array_key_exists ( $moduleName, $this->mQueryMetaModules ) ) {
return 'meta';
}
-
+
return null;
}
if ( isset( $this->params['generator'] ) ) {
$generator = $this->newGenerator( $this->params['generator'] );
$params = $generator->extractRequestParams();
- $cacheMode = $this->mergeCacheMode( $cacheMode,
+ $cacheMode = $this->mergeCacheMode( $cacheMode,
$generator->getCacheMode( $params ) );
$this->executeGeneratorModule( $generator, $modules );
} else {
// Execute all requested modules.
foreach ( $modules as $module ) {
$params = $module->extractRequestParams();
- $cacheMode = $this->mergeCacheMode(
+ $cacheMode = $this->mergeCacheMode(
$cacheMode, $module->getCacheMode( $params ) );
$module->profileIn();
$module->execute();
/**
* Update a cache mode string, applying the cache mode of a new module to it.
- * The cache mode may increase in the level of privacy, but public modules
+ * The cache mode may increase in the level of privacy, but public modules
* added to private data do not decrease the level of privacy.
*/
protected function mergeCacheMode( $cacheMode, $modCacheMode ) {
$result->setIndexedTagName( $normValues, 'n' );
$result->addValue( 'query', 'normalized', $normValues );
}
-
+
// Title conversions
$convValues = array();
foreach ( $pageSet->getConvertedTitles() as $rawTitleStr => $titleStr ) {
if ( count( $convValues ) ) {
$result->setIndexedTagName( $convValues, 'c' );
$result->addValue( 'query', 'converted', $convValues );
- }
+ }
// Interwiki titles
$intrwValues = array();
$vals = array();
ApiQueryBase::addTitleInfo( $vals, $title );
$vals['special'] = '';
- if ( $title->getNamespace() == NS_SPECIAL &&
+ if ( $title->getNamespace() == NS_SPECIAL &&
!SpecialPage::exists( $title->getText() ) ) {
- $vals['missing'] = '';
+ $vals['missing'] = '';
} elseif ( $title->getNamespace() == NS_MEDIA &&
!wfFindFile( $title ) ) {
$vals['missing'] = '';
$params = $this->extractRequestParams();
global $wgLang;
-
+
$oldLang = null;
if ( !is_null( $params['lang'] ) ) {
$oldLang = $wgLang; // Keep $wgLang for restore later
}
}
$result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'message' );
-
+
if ( !is_null( $oldLang ) ) {
$wgLang = $oldLang; // Restore $oldLang
}
}
/**
- * Get the cache mode for the data generated by this module. Override this
+ * Get the cache mode for the data generated by this module. Override this
* in the module subclass.
*
- * Public caching will only be allowed if *all* the modules that supply
+ * Public caching will only be allowed if *all* the modules that supply
* data for a given request return a cache mode of public.
*/
public function getCacheMode( $params ) {
'ipb_auto' => 0
) );
}
-
+
if ( !$wgUser->isAllowed( 'hideuser' ) ) {
$this->addWhereFld( 'ipb_deleted', 0 );
}
public function getDescription() {
return 'List all categories the page(s) belong to';
}
-
+
public function getPossibleErrors() {
return array_merge( parent::getPossibleErrors(), array(
array( 'show' ),
if ( !$wgUser->isAllowed( 'deletedhistory' ) ) {
$this->dieUsage( 'You don\'t have permission to view deleted file information', 'permissiondenied' );
}
-
+
$db = $this->getDB();
$params = $this->extractRequestParams();
-
+
$prop = array_flip( $params['prop'] );
$fld_sha1 = isset( $prop['sha1'] );
$fld_timestamp = isset( $prop['timestamp'] );
$fld_mime = isset( $prop['mime'] );
$fld_metadata = isset( $prop['metadata'] );
$fld_bitdepth = isset( $prop['bitdepth'] );
-
+
$this->addTables( 'filearchive' );
-
+
$this->addFields( 'fa_name' );
$this->addFieldsIf( 'fa_storage_key', $fld_sha1 );
$this->addFieldsIf( 'fa_timestamp', $fld_timestamp );
$this->setContinueEnumParameter( 'from', $this->keyToTitle( $row->fa_name ) );
break;
}
-
+
$file = array();
$file['name'] = $row->fa_name;
if ( $fld_mime ) {
$file['mime'] = "$row->fa_major_mime/$row->fa_minor_mime";
}
-
+
$fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $file );
if ( !$fit ) {
$this->setContinueEnumParameter( 'from', $this->keyToTitle( $row->fa_name ) );
public function __construct( $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'iwbl' );
}
-
+
public function execute() {
$this->run();
}
public function run( $resultPageSet = null ) {
$params = $this->extractRequestParams();
-
+
if ( isset( $params['title'] ) && !isset( $params['prefix'] ) ) {
$this->dieUsageMsg( array( 'missingparam', 'prefix' ) );
}
"iwl_from >= $from)))"
);
}
-
+
$prop = array_flip( $params['prop'] );
$iwprefix = isset( $prop['iwprefix'] );
$iwtitle = isset( $prop['iwtitle'] );
$this->addOption( 'LIMIT', $params['limit'] + 1 );
$res = $this->select( __METHOD__ );
-
+
$pages = array();
$count = 0;
$this->setContinueEnumParameter( 'continue', "{$row->iwl_prefix}|{$row->iwl_title}|{$row->iwl_from}" );
break;
}
-
+
if ( !is_null( $resultPageSet ) ) {
$pages[] = Title::makeTitle( $row->page_namespace, $row->page_title )->getPrefixedText();
} else {
$entry = array();
-
+
$entry['pageid'] = intval( $row->page_id );
$entry['ns'] = $row->page_namespace;
$entry['title'] = $row->page_title;
-
+
if ( $row->page_is_redirect ) {
$entry['redirect'] = '';
}
-
+
if ( $iwprefix ) {
$entry['iwprefix'] = $row->iwl_prefix;
}
-
+
if ( $iwtitle ) {
$entry['iwtitle'] = $row->iwl_title;
}
}
}
}
-
+
if ( is_null( $resultPageSet ) ) {
$result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'iw' );
} else {
$vals['thumbwidth'] = intval( $file->getWidth() );
$vals['thumbheight'] = intval( $file->getHeight() );
}
-
+
if ( isset( $prop['thumbmime'] ) ) {
$thumbFile = UnregisteredLocalFile::newFromPath( $mto->getPath(), false );
$vals['thumbmime'] = $thumbFile->getMimeType();
if ( $this->fld_talkid || $this->fld_subjectid ) {
$this->getTSIDs();
}
-
+
if ( $this->fld_displaytitle ) {
$this->getDisplayTitle();
}
$pageInfo['preload'] = $text;
}
}
-
+
if ( $this->fld_displaytitle ) {
if ( isset( $this->displaytitles[$title->getArticleId()] ) ) {
$pageInfo['displaytitle'] = $this->displaytitles[$title->getArticleId()];
if ( !count( $getTitles ) ) {
return;
}
-
+
$db = $this->getDB();
// Construct a custom WHERE clause that matches
}
}
}
-
+
private function getDisplayTitle() {
$this->displaytitles = array();
-
+
$pageIds = array_keys( $this->titles );
-
+
if ( !count( $pageIds ) ) {
return;
}
$this->addWhereFld( 'pp_page', $pageIds );
$this->addWhereFld( 'pp_propname', 'displaytitle' );
$res = $this->select( __METHOD__ );
-
+
foreach ( $res as $row ) {
$this->displaytitles[$row->pp_page] = $row->pp_value;
}
'readable', # private
'preload',
'displaytitle',
- // If you add more properties here, please consider whether they
+ // If you add more properties here, please consider whether they
// need to be added to getCacheMode()
) ),
'token' => array(
$this->addTables( $this->table );
$this->addWhereFld( $this->prefix . '_from', array_keys( $this->getPageSet()->getGoodTitles() ) );
$this->addWhereFld( $this->prefix . '_namespace', $params['namespace'] );
-
+
if ( !is_null( $params[$this->titlesParam] ) ) {
$lb = new LinkBatch;
foreach ( $params[$this->titlesParam] as $t ) {
case 'block':
$vals2 = array();
list( $vals2['duration'], $vals2['flags'] ) = $params;
-
+
// Indefinite blocks have no expiry time
if ( Block::parseExpiryInput( $params[0] ) !== Block::infinity() ) {
$vals2['expiry'] = wfTimestamp( TS_ISO_8601,
ApiQueryBase::addTitleInfo( $vals, $title );
}
}
-
+
if ( $this->fld_type || $this->fld_action ) {
$vals['type'] = $row->log_type;
$vals['action'] = $row->log_action;
$vals['commenthidden'] = '';
} else {
$comment = $revision->getComment();
-
+
if ( $this->fld_comment ) {
$vals['comment'] = $comment;
}
if ( !is_null( $params['prop'] ) && in_array( 'parsedcomment', $params['prop'] ) ) {
// formatComment() calls wfMsg() among other things
return 'anon-public-user-private';
- }
+ }
return 'public';
}
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
if ( isset( $this->prop['groups'] ) ) {
$autolist = ApiQueryUsers::getAutoGroups( $wgUser );
-
+
$vals['groups'] = array_merge( $autolist, $wgUser->getGroups() );
$result->setIndexedTagName( $vals['groups'], 'g' ); // even if empty
}
$vals['emailauthenticated'] = wfTimestamp( TS_ISO_8601, $auth );
}
}
-
+
if ( isset( $this->prop['acceptlang'] ) ) {
$langs = $wgRequest->getAcceptLang();
$acceptLang = array();
} else {
if ( isset( $this->prop['groups'] ) && isset( $data[$u]['groups'] ) ) {
$autolist = ApiQueryUsers::getAutoGroups( User::newFromName( $u ) );
-
+
$data[$u]['groups'] = array_merge( $autolist, $data[$u]['groups'] );
-
+
$this->getResult()->setIndexedTagName( $data[$u]['groups'], 'g' );
}
}
}
return $this->getResult()->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'user' );
}
-
+
/**
* Gets all the groups that a user is automatically a member of
* @return array
$this->selectNamedDB( 'watchlist', DB_SLAVE, 'watchlist' );
$params = $this->extractRequestParams();
-
+
$user = $this->getWatchlistUser( $params );
if ( !is_null( $params['prop'] ) && is_null( $resultPageSet ) ) {
private function run( $resultPageSet = null ) {
$this->selectNamedDB( 'watchlist', DB_SLAVE, 'watchlist' );
-
+
$params = $this->extractRequestParams();
$user = $this->getWatchlistUser( $params );
if ( !isset( $params['user'] ) ) {
$this->dieUsageMsg( array( 'missingparam', 'user' ) );
}
-
+
// We need to be able to revert IPs, but getCanonicalName rejects them
$this->mUser = User::isIP( $params['user'] )
? $params['user']
if ( !$this->mTitleObj->exists() ) {
$this->dieUsageMsg( array( 'notanarticle' ) );
}
-
+
return $this->mTitleObj;
}
$warnings = $this->checkForWarnings();
if ( isset( $warnings ) ) {
- return $warnings;
- }
+ return $warnings;
+ }
// Use comment as initial page text by default
if ( is_null( $this->mParams['text'] ) ) {
$this->getResult()->setIndexedTagName( $r['removed'], 'group' );
$this->getResult()->addValue( null, $this->getModuleName(), $r );
}
-
+
private function getUser() {
if ( $this->mUser !== null ) {
return $this->mUser;