MediaWiki  1.23.12
ApiQueryWatchlistRaw.php
Go to the documentation of this file.
1 <?php
34 
35  public function __construct( $query, $moduleName ) {
36  parent::__construct( $query, $moduleName, 'wr' );
37  }
38 
39  public function execute() {
40  $this->run();
41  }
42 
43  public function executeGenerator( $resultPageSet ) {
44  $this->run( $resultPageSet );
45  }
46 
51  private function run( $resultPageSet = null ) {
52  $this->selectNamedDB( 'watchlist', DB_SLAVE, 'watchlist' );
53 
54  $params = $this->extractRequestParams();
55 
56  $user = $this->getWatchlistUser( $params );
57 
58  $prop = array_flip( (array)$params['prop'] );
59  $show = array_flip( (array)$params['show'] );
60  if ( isset( $show['changed'] ) && isset( $show['!changed'] ) ) {
61  $this->dieUsageMsg( 'show' );
62  }
63 
64  $this->addTables( 'watchlist' );
65  $this->addFields( array( 'wl_namespace', 'wl_title' ) );
66  $this->addFieldsIf( 'wl_notificationtimestamp', isset( $prop['changed'] ) );
67  $this->addWhereFld( 'wl_user', $user->getId() );
68  $this->addWhereFld( 'wl_namespace', $params['namespace'] );
69  $this->addWhereIf( 'wl_notificationtimestamp IS NOT NULL', isset( $show['changed'] ) );
70  $this->addWhereIf( 'wl_notificationtimestamp IS NULL', isset( $show['!changed'] ) );
71 
72  if ( isset( $params['continue'] ) ) {
73  $cont = explode( '|', $params['continue'] );
74  $this->dieContinueUsageIf( count( $cont ) != 2 );
75  $ns = intval( $cont[0] );
76  $this->dieContinueUsageIf( strval( $ns ) !== $cont[0] );
77  $title = $this->getDB()->addQuotes( $cont[1] );
78  $op = $params['dir'] == 'ascending' ? '>' : '<';
79  $this->addWhere(
80  "wl_namespace $op $ns OR " .
81  "(wl_namespace = $ns AND " .
82  "wl_title $op= $title)"
83  );
84  }
85 
86  $sort = ( $params['dir'] == 'descending' ? ' DESC' : '' );
87  // Don't ORDER BY wl_namespace if it's constant in the WHERE clause
88  if ( count( $params['namespace'] ) == 1 ) {
89  $this->addOption( 'ORDER BY', 'wl_title' . $sort );
90  } else {
91  $this->addOption( 'ORDER BY', array(
92  'wl_namespace' . $sort,
93  'wl_title' . $sort
94  ) );
95  }
96  $this->addOption( 'LIMIT', $params['limit'] + 1 );
97  $res = $this->select( __METHOD__ );
98 
99  $titles = array();
100  $count = 0;
101  foreach ( $res as $row ) {
102  if ( ++$count > $params['limit'] ) {
103  // We've reached the one extra which shows that there are
104  // additional pages to be had. Stop here...
105  $this->setContinueEnumParameter( 'continue', $row->wl_namespace . '|' . $row->wl_title );
106  break;
107  }
108  $t = Title::makeTitle( $row->wl_namespace, $row->wl_title );
109 
110  if ( is_null( $resultPageSet ) ) {
111  $vals = array();
112  ApiQueryBase::addTitleInfo( $vals, $t );
113  if ( isset( $prop['changed'] ) && !is_null( $row->wl_notificationtimestamp ) ) {
114  $vals['changed'] = wfTimestamp( TS_ISO_8601, $row->wl_notificationtimestamp );
115  }
116  $fit = $this->getResult()->addValue( $this->getModuleName(), null, $vals );
117  if ( !$fit ) {
118  $this->setContinueEnumParameter( 'continue', $row->wl_namespace . '|' . $row->wl_title );
119  break;
120  }
121  } else {
122  $titles[] = $t;
123  }
124  }
125  if ( is_null( $resultPageSet ) ) {
126  $this->getResult()->setIndexedTagName_internal( $this->getModuleName(), 'wr' );
127  } else {
128  $resultPageSet->populateFromTitles( $titles );
129  }
130  }
131 
132  public function getAllowedParams() {
133  return array(
134  'continue' => null,
135  'namespace' => array(
136  ApiBase::PARAM_ISMULTI => true,
137  ApiBase::PARAM_TYPE => 'namespace'
138  ),
139  'limit' => array(
140  ApiBase::PARAM_DFLT => 10,
141  ApiBase::PARAM_TYPE => 'limit',
142  ApiBase::PARAM_MIN => 1,
145  ),
146  'prop' => array(
147  ApiBase::PARAM_ISMULTI => true,
149  'changed',
150  )
151  ),
152  'show' => array(
153  ApiBase::PARAM_ISMULTI => true,
155  'changed',
156  '!changed',
157  )
158  ),
159  'owner' => array(
160  ApiBase::PARAM_TYPE => 'user'
161  ),
162  'token' => array(
163  ApiBase::PARAM_TYPE => 'string'
164  ),
165  'dir' => array(
166  ApiBase::PARAM_DFLT => 'ascending',
168  'ascending',
169  'descending'
170  ),
171  ),
172  );
173  }
174 
175  public function getParamDescription() {
176  return array(
177  'continue' => 'When more results are available, use this to continue',
178  'namespace' => 'Only list pages in the given namespace(s)',
179  'limit' => 'How many total results to return per request',
180  'prop' => array(
181  'Which additional properties to get (non-generator mode only)',
182  ' changed - Adds timestamp of when the user was last notified about the edit',
183  ),
184  'show' => 'Only list items that meet these criteria',
185  'owner' => 'The name of the user whose watchlist you\'d like to access',
186  'token' => 'Give a security token (settable in preferences) to allow ' .
187  'access to another user\'s watchlist',
188  'dir' => 'Direction to sort the titles and namespaces in',
189  );
190  }
191 
192  public function getResultProperties() {
193  return array(
194  '' => array(
195  'ns' => 'namespace',
196  'title' => 'string'
197  ),
198  'changed' => array(
199  'changed' => array(
200  ApiBase::PROP_TYPE => 'timestamp',
201  ApiBase::PROP_NULLABLE => true
202  )
203  )
204  );
205  }
206 
207  public function getDescription() {
208  return "Get all pages on the logged in user's watchlist.";
209  }
210 
211  public function getPossibleErrors() {
212  return array_merge( parent::getPossibleErrors(), array(
213  array( 'code' => 'notloggedin', 'info' => 'You must be logged-in to have a watchlist' ),
214  array( 'show' ),
215  array( 'code' => 'bad_wlowner', 'info' => 'Specified user does not exist' ),
216  array(
217  'code' => 'bad_wltoken',
218  'info' => 'Incorrect watchlist token provided -- ' .
219  'please set a correct token in Special:Preferences'
220  ),
221  ) );
222  }
223 
224  public function getExamples() {
225  return array(
226  'api.php?action=query&list=watchlistraw',
227  'api.php?action=query&generator=watchlistraw&gwrshow=changed&prop=revisions',
228  );
229  }
230 
231  public function getHelpUrls() {
232  return 'https://www.mediawiki.org/wiki/API:Watchlistraw';
233  }
234 }
Title\makeTitle
static & makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:398
ApiQueryBase\addFields
addFields( $value)
Add a set of fields to select to the internal array.
Definition: ApiQueryBase.php:117
ApiQueryWatchlistRaw\getAllowedParams
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
Definition: ApiQueryWatchlistRaw.php:132
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
ApiQueryWatchlistRaw\executeGenerator
executeGenerator( $resultPageSet)
Execute this module as a generator.
Definition: ApiQueryWatchlistRaw.php:43
ApiBase\dieUsageMsg
dieUsageMsg( $error)
Output the error message related to a certain array.
Definition: ApiBase.php:1933
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:2530
ApiBase\PARAM_TYPE
const PARAM_TYPE
Definition: ApiBase.php:50
ApiBase\getResult
getResult()
Get the result object.
Definition: ApiBase.php:205
ApiQueryBase\select
select( $method, $extraQuery=array())
Execute a SELECT query based on the values in the internal arrays.
Definition: ApiQueryBase.php:274
$params
$params
Definition: styleTest.css.php:40
ApiQueryWatchlistRaw\execute
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Definition: ApiQueryWatchlistRaw.php:39
ApiQueryBase\addOption
addOption( $name, $value=null)
Add an option such as LIMIT or USE INDEX.
Definition: ApiQueryBase.php:252
ApiQueryWatchlistRaw
This query action allows clients to retrieve a list of pages on the logged-in user's watchlist.
Definition: ApiQueryWatchlistRaw.php:33
ApiQueryBase\addFieldsIf
addFieldsIf( $value, $condition)
Same as addFields(), but add the fields only if a condition is met.
Definition: ApiQueryBase.php:131
ApiQueryGeneratorBase\setContinueEnumParameter
setContinueEnumParameter( $paramName, $paramValue)
Overrides base in case of generator & smart continue to notify ApiQueryMain instead of adding them to...
Definition: ApiQueryBase.php:676
ApiQueryWatchlistRaw\getResultProperties
getResultProperties()
Returns possible properties in the result, grouped by the value of the prop parameter that shows them...
Definition: ApiQueryWatchlistRaw.php:192
ApiBase\PARAM_MIN
const PARAM_MIN
Definition: ApiBase.php:56
$titles
linkcache txt The LinkCache class maintains a list of article titles and the information about whether or not the article exists in the database This is used to mark up links when displaying a page If the same link appears more than once on any page then it only has to be looked up once In most cases link lookups are done in batches with the LinkBatch class or the equivalent in so the link cache is mostly useful for short snippets of parsed and for links in the navigation areas of the skin The link cache was formerly used to track links used in a document for the purposes of updating the link tables This application is now deprecated To create a you can use the following $titles
Definition: linkcache.txt:17
ApiBase\LIMIT_BIG1
const LIMIT_BIG1
Definition: ApiBase.php:78
TS_ISO_8601
const TS_ISO_8601
ISO 8601 format with no timezone: 1986-02-09T20:00:00Z.
Definition: GlobalFunctions.php:2495
ApiQueryBase\getDB
getDB()
Get the Query database connection (read-only)
Definition: ApiQueryBase.php:417
ApiBase\PARAM_MAX
const PARAM_MAX
Definition: ApiBase.php:52
ApiQueryBase\addTables
addTables( $tables, $alias=null)
Add a set of tables to the internal array.
Definition: ApiQueryBase.php:82
ApiQueryWatchlistRaw\run
run( $resultPageSet=null)
Definition: ApiQueryWatchlistRaw.php:51
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
ApiQueryWatchlistRaw\__construct
__construct( $query, $moduleName)
Definition: ApiQueryWatchlistRaw.php:35
ApiQueryWatchlistRaw\getExamples
getExamples()
Returns usage examples for this module.
Definition: ApiQueryWatchlistRaw.php:224
ApiQueryWatchlistRaw\getParamDescription
getParamDescription()
Returns an array of parameter descriptions.
Definition: ApiQueryWatchlistRaw.php:175
ApiBase\PROP_TYPE
const PROP_TYPE
Definition: ApiBase.php:74
$sort
$sort
Definition: profileinfo.php:301
ApiBase\extractRequestParams
extractRequestParams( $parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition: ApiBase.php:687
$title
presenting them properly to the user as errors is done by the caller $title
Definition: hooks.txt:1324
ApiBase\getWatchlistUser
getWatchlistUser( $params)
Gets the user for whom to get the watchlist.
Definition: ApiBase.php:2074
ApiBase\dieContinueUsageIf
dieContinueUsageIf( $condition)
Die with the $prefix.
Definition: ApiBase.php:1969
ApiQueryWatchlistRaw\getHelpUrls
getHelpUrls()
Definition: ApiQueryWatchlistRaw.php:231
ApiBase\PROP_NULLABLE
const PROP_NULLABLE
Definition: ApiBase.php:76
ApiQueryBase\addWhereFld
addWhereFld( $field, $value)
Equivalent to addWhere(array($field => $value))
Definition: ApiQueryBase.php:185
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:237
$count
$count
Definition: UtfNormalTest2.php:96
ApiQueryGeneratorBase
Definition: ApiQueryBase.php:626
DB_SLAVE
const DB_SLAVE
Definition: Defines.php:55
ApiQueryBase\selectNamedDB
selectNamedDB( $name, $db, $groups)
Selects the query database connection with the given name.
Definition: ApiQueryBase.php:433
ApiBase\LIMIT_BIG2
const LIMIT_BIG2
Definition: ApiBase.php:79
ApiBase\PARAM_DFLT
const PARAM_DFLT
Definition: ApiBase.php:46
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
ApiBase\getModuleName
getModuleName()
Get the name of the module being executed by this instance.
Definition: ApiBase.php:148
ApiBase\PARAM_ISMULTI
const PARAM_ISMULTI
Definition: ApiBase.php:48
ApiBase\PARAM_MAX2
const PARAM_MAX2
Definition: ApiBase.php:54
ApiQueryWatchlistRaw\getPossibleErrors
getPossibleErrors()
Definition: ApiQueryWatchlistRaw.php:211
ApiQueryBase\addWhere
addWhere( $value)
Add a set of WHERE clauses to the internal array.
Definition: ApiQueryBase.php:152
$t
$t
Definition: testCompression.php:65
$query
return true to allow those checks to and false if checking is done use this to change the tables headers temp or archived zone change it to an object instance and return false override the list derivative used the name of the old file when set the default code will be skipped add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition: hooks.txt:1105
ApiQueryWatchlistRaw\getDescription
getDescription()
Returns the description string for this module.
Definition: ApiQueryWatchlistRaw.php:207
$res
$res
Definition: database.txt:21
ApiQueryBase\addWhereIf
addWhereIf( $value, $condition)
Same as addWhere(), but add the WHERE clauses only if a condition is met.
Definition: ApiQueryBase.php:170
ApiQueryBase\addTitleInfo
static addTitleInfo(&$arr, $title, $prefix='')
Add information (title and namespace) about a Title object to a result array.
Definition: ApiQueryBase.php:339