3 * Special page which uses a ChangesList to show query results.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @ingroup SpecialPage
25 * Special page which uses a ChangesList to show query results.
26 * @todo Way too many public functions, most of them should be protected
28 * @ingroup SpecialPage
30 abstract class ChangesListSpecialPage
extends SpecialPage
{
34 /** @var FormOptions */
38 protected $customFilters;
41 * Main execution point
43 * @param string $subpage
45 public function execute( $subpage ) {
46 $this->rcSubpage
= $subpage;
49 $this->outputHeader();
52 $rows = $this->getRows();
53 $opts = $this->getOptions();
54 if ( $rows === false ) {
55 if ( !$this->including() ) {
56 $this->doHeader( $opts );
62 $batch = new LinkBatch
;
63 foreach ( $rows as $row ) {
64 $batch->add( NS_USER
, $row->rc_user_text
);
65 $batch->add( NS_USER_TALK
, $row->rc_user_text
);
66 $batch->add( $row->rc_namespace
, $row->rc_title
);
70 $this->webOutput( $rows, $opts );
76 * Get the database result for this special page instance. Used by ApiFeedRecentChanges.
78 * @return bool|ResultWrapper Result or false
80 public function getRows() {
81 $opts = $this->getOptions();
82 $conds = $this->buildMainQueryConds( $opts );
83 return $this->doMainQuery( $conds, $opts );
87 * Get the current FormOptions for this request
91 public function getOptions() {
92 if ( $this->rcOptions
=== null ) {
93 $this->rcOptions
= $this->setup( $this->rcSubpage
);
96 return $this->rcOptions
;
100 * Create a FormOptions object with options as specified by the user
102 * @param array $parameters
104 * @return FormOptions
106 public function setup( $parameters ) {
107 $opts = $this->getDefaultOptions();
108 foreach ( $this->getCustomFilters() as $key => $params ) {
109 $opts->add( $key, $params['default'] );
112 $opts = $this->fetchOptionsFromRequest( $opts );
114 // Give precedence to subpage syntax
115 if ( $parameters !== null ) {
116 $this->parseParameters( $parameters, $opts );
119 $this->validateOptions( $opts );
125 * Get a FormOptions object containing the default options. By default returns some basic options,
126 * you might want to not call parent method and discard them, or to override default values.
128 * @return FormOptions
130 public function getDefaultOptions() {
131 $opts = new FormOptions();
133 $opts->add( 'hideminor', false );
134 $opts->add( 'hidebots', false );
135 $opts->add( 'hideanons', false );
136 $opts->add( 'hideliu', false );
137 $opts->add( 'hidepatrolled', false );
138 $opts->add( 'hidemyself', false );
140 $opts->add( 'namespace', '', FormOptions
::INTNULL
);
141 $opts->add( 'invert', false );
142 $opts->add( 'associated', false );
148 * Get custom show/hide filters
150 * @return array Map of filter URL param names to properties (msg/default)
152 protected function getCustomFilters() {
153 // @todo Fire a Special{$this->getName()}Filters hook here
158 * Fetch values for a FormOptions object from the WebRequest associated with this instance.
160 * Intended for subclassing, e.g. to add a backwards-compatibility layer.
162 * @param FormOptions $parameters
163 * @return FormOptions
165 protected function fetchOptionsFromRequest( $opts ) {
166 $opts->fetchValuesFromRequest( $this->getRequest() );
171 * Process $par and put options found in $opts. Used when including the page.
174 * @param FormOptions $opts
176 public function parseParameters( $par, FormOptions
$opts ) {
177 // nothing by default
181 * Validate a FormOptions object generated by getDefaultOptions() with values already populated.
183 * @param FormOptions $opts
185 public function validateOptions( FormOptions
$opts ) {
186 // nothing by default
190 * Return an array of conditions depending of options set in $opts
192 * @param FormOptions $opts
195 public function buildMainQueryConds( FormOptions
$opts ) {
196 $dbr = $this->getDB();
197 $user = $this->getUser();
200 // It makes no sense to hide both anons and logged-in users. When this occurs, try a guess on
201 // what the user meant and either show only bots or force anons to be shown.
203 $hideanons = $opts['hideanons'];
204 if ( $opts['hideanons'] && $opts['hideliu'] ) {
205 if ( $opts['hidebots'] ) {
213 if ( $opts['hideminor'] ) {
214 $conds['rc_minor'] = 0;
216 if ( $opts['hidebots'] ) {
217 $conds['rc_bot'] = 0;
219 if ( $user->useRCPatrol() && $opts['hidepatrolled'] ) {
220 $conds['rc_patrolled'] = 0;
223 $conds['rc_bot'] = 1;
225 if ( $opts['hideliu'] ) {
226 $conds[] = 'rc_user = 0';
229 $conds[] = 'rc_user != 0';
232 if ( $opts['hidemyself'] ) {
233 if ( $user->getId() ) {
234 $conds[] = 'rc_user != ' . $dbr->addQuotes( $user->getId() );
236 $conds[] = 'rc_user_text != ' . $dbr->addQuotes( $user->getName() );
240 // Namespace filtering
241 if ( $opts['namespace'] !== '' ) {
242 $selectedNS = $dbr->addQuotes( $opts['namespace'] );
243 $operator = $opts['invert'] ?
'!=' : '=';
244 $boolean = $opts['invert'] ?
'AND' : 'OR';
246 // Namespace association (bug 2429)
247 if ( !$opts['associated'] ) {
248 $condition = "rc_namespace $operator $selectedNS";
250 // Also add the associated namespace
251 $associatedNS = $dbr->addQuotes(
252 MWNamespace
::getAssociated( $opts['namespace'] )
254 $condition = "(rc_namespace $operator $selectedNS "
256 . " rc_namespace $operator $associatedNS)";
259 $conds[] = $condition;
268 * @param array $conds
269 * @param FormOptions $opts
270 * @return bool|ResultWrapper Result or false
272 public function doMainQuery( $conds, $opts ) {
273 $tables = array( 'recentchanges' );
274 $fields = RecentChange
::selectFields();
275 $query_options = array();
276 $join_conds = array();
278 ChangeTags
::modifyDisplayQuery(
287 // @todo Fire a Special{$this->getName()}Query hook here
288 // @todo Uncomment and document
289 // if ( !wfRunHooks( 'ChangesListSpecialPageQuery',
290 // array( &$tables, &$fields, &$conds, &$query_options, &$join_conds, $opts ) )
295 $dbr = $this->getDB();
307 * Return a DatabaseBase object for reading
309 * @return DatabaseBase
311 protected function getDB() {
312 return wfGetDB( DB_SLAVE
);
316 * Send output to the OutputPage object, only called if not used feeds
318 * @param ResultWrapper $rows Database rows
319 * @param FormOptions $opts
321 public function webOutput( $rows, $opts ) {
322 if ( !$this->including() ) {
323 $this->outputFeedLinks();
324 $this->doHeader( $opts );
327 $this->outputChangesList( $rows, $opts );
333 public function outputFeedLinks() {
334 // nothing by default
338 * Build and output the actual changes list.
340 * @param array $rows Database rows
341 * @param FormOptions $opts
343 abstract public function outputChangesList( $rows, $opts );
346 * Return the text to be displayed above the changes
348 * @param FormOptions $opts
349 * @return string XHTML
351 public function doHeader( $opts ) {
352 $this->setTopText( $opts );
354 // @todo Lots of stuff should be done here.
356 $this->setBottomText( $opts );
360 * Send the text to be displayed before the options. Should use $this->getOutput()->addWikiText()
361 * or similar methods to print the text.
363 * @param FormOptions $opts
365 function setTopText( FormOptions
$opts ) {
366 // nothing by default
370 * Send the text to be displayed after the options. Should use $this->getOutput()->addWikiText()
371 * or similar methods to print the text.
373 * @param FormOptions $opts
375 function setBottomText( FormOptions
$opts ) {
376 // nothing by default
380 * Get options to be displayed in a form
381 * @todo This should handle options returned by getDefaultOptions().
382 * @todo Not called by anything, should be called by something… doHeader() maybe?
384 * @param FormOptions $opts
387 function getExtraOptions( $opts ) {
392 * Return the legend displayed within the fieldset
393 * @todo This should not be static, then we can drop the parameter
394 * @todo Not called by anything, should be called by doHeader()
396 * @param $context the object available as $this in non-static functions
399 public static function makeLegend( IContextSource
$context ) {
400 global $wgRecentChangesFlags;
401 $user = $context->getUser();
402 # The legend showing what the letters and stuff mean
403 $legend = Xml
::openElement( 'dl' ) . "\n";
404 # Iterates through them and gets the messages for both letter and tooltip
405 $legendItems = $wgRecentChangesFlags;
406 if ( !$user->useRCPatrol() ) {
407 unset( $legendItems['unpatrolled'] );
409 foreach ( $legendItems as $key => $legendInfo ) { # generate items of the legend
410 $label = $legendInfo['title'];
411 $letter = $legendInfo['letter'];
412 $cssClass = isset( $legendInfo['class'] ) ?
$legendInfo['class'] : $key;
414 $legend .= Xml
::element( 'dt',
415 array( 'class' => $cssClass ), $context->msg( $letter )->text()
417 if ( $key === 'newpage' ) {
418 $legend .= Xml
::openElement( 'dd' );
419 $legend .= $context->msg( $label )->escaped();
420 $legend .= ' ' . $context->msg( 'recentchanges-legend-newpage' )->parse();
421 $legend .= Xml
::closeElement( 'dd' ) . "\n";
423 $legend .= Xml
::element( 'dd', array(),
424 $context->msg( $label )->text()
429 $legend .= Xml
::tags( 'dt',
430 array( 'class' => 'mw-plusminus-pos' ),
431 $context->msg( 'recentchanges-legend-plusminus' )->parse()
433 $legend .= Xml
::element(
435 array( 'class' => 'mw-changeslist-legend-plusminus' ),
436 $context->msg( 'recentchanges-label-plusminus' )->text()
438 $legend .= Xml
::closeElement( 'dl' ) . "\n";
442 '<div class="mw-changeslist-legend">' .
443 $context->msg( 'recentchanges-legend-heading' )->parse() .
444 '<div class="mw-collapsible-content">' . $legend . '</div>' .
451 * Add page-specific modules.
453 protected function addModules() {
454 $out = $this->getOutput();
455 // Styles and behavior for the legend box (see makeLegend())
456 $out->addModuleStyles( 'mediawiki.special.changeslist.legend' );
457 $out->addModules( 'mediawiki.special.changeslist.legend.js' );
460 protected function getGroupName() {