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
{
31 var $rcSubpage, $rcOptions; // @todo Rename these, make protected
32 protected $customFilters;
35 * Main execution point
37 * @param string $subpage
39 public function execute( $subpage ) {
40 $this->rcSubpage
= $subpage;
43 $this->outputHeader();
46 $rows = $this->getRows();
47 $opts = $this->getOptions();
48 if ( $rows === false ) {
49 if ( !$this->including() ) {
50 $this->doHeader( $opts );
56 $batch = new LinkBatch
;
57 foreach ( $rows as $row ) {
58 $batch->add( NS_USER
, $row->rc_user_text
);
59 $batch->add( NS_USER_TALK
, $row->rc_user_text
);
60 $batch->add( $row->rc_namespace
, $row->rc_title
);
64 $this->webOutput( $rows, $opts );
70 * Get the database result for this special page instance. Used by ApiFeedRecentChanges.
72 * @return bool|ResultWrapper Result or false
74 public function getRows() {
75 $opts = $this->getOptions();
76 $conds = $this->buildMainQueryConds( $opts );
77 return $this->doMainQuery( $conds, $opts );
81 * Get the current FormOptions for this request
85 public function getOptions() {
86 if ( $this->rcOptions
=== null ) {
87 $this->rcOptions
= $this->setup( $this->rcSubpage
);
90 return $this->rcOptions
;
94 * Create a FormOptions object with options as specified by the user
96 * @param array $parameters
100 public function setup( $parameters ) {
101 $opts = $this->getDefaultOptions();
102 foreach ( $this->getCustomFilters() as $key => $params ) {
103 $opts->add( $key, $params['default'] );
106 $opts = $this->fetchOptionsFromRequest( $opts );
108 // Give precedence to subpage syntax
109 if ( $parameters !== null ) {
110 $this->parseParameters( $parameters, $opts );
113 $this->validateOptions( $opts );
119 * Get a FormOptions object containing the default options. By default returns some basic options,
120 * you might want to not call parent method and discard them, or to override default values.
122 * @return FormOptions
124 public function getDefaultOptions() {
125 $opts = new FormOptions();
127 $opts->add( 'hideminor', false );
128 $opts->add( 'hidebots', false );
129 $opts->add( 'hideanons', false );
130 $opts->add( 'hideliu', false );
131 $opts->add( 'hidepatrolled', false );
132 $opts->add( 'hidemyself', false );
134 $opts->add( 'namespace', '', FormOptions
::INTNULL
);
135 $opts->add( 'invert', false );
136 $opts->add( 'associated', false );
142 * Get custom show/hide filters
144 * @return array Map of filter URL param names to properties (msg/default)
146 protected function getCustomFilters() {
147 // @todo Fire a Special{$this->getName()}Filters hook here
152 * Fetch values for a FormOptions object from the WebRequest associated with this instance.
154 * Intended for subclassing, e.g. to add a backwards-compatibility layer.
156 * @param FormOptions $parameters
157 * @return FormOptions
159 protected function fetchOptionsFromRequest( $opts ) {
160 $opts->fetchValuesFromRequest( $this->getRequest() );
165 * Process $par and put options found in $opts. Used when including the page.
168 * @param FormOptions $opts
170 public function parseParameters( $par, FormOptions
$opts ) {
171 // nothing by default
175 * Validate a FormOptions object generated by getDefaultOptions() with values already populated.
177 * @param FormOptions $opts
179 public function validateOptions( FormOptions
$opts ) {
180 // nothing by default
184 * Return an array of conditions depending of options set in $opts
186 * @param FormOptions $opts
189 public function buildMainQueryConds( FormOptions
$opts ) {
190 $dbr = $this->getDB();
191 $user = $this->getUser();
194 // It makes no sense to hide both anons and logged-in users. When this occurs, try a guess on
195 // what the user meant and either show only bots or force anons to be shown.
197 $hideanons = $opts['hideanons'];
198 if ( $opts['hideanons'] && $opts['hideliu'] ) {
199 if ( $opts['hidebots'] ) {
207 if ( $opts['hideminor'] ) {
208 $conds['rc_minor'] = 0;
210 if ( $opts['hidebots'] ) {
211 $conds['rc_bot'] = 0;
213 if ( $user->useRCPatrol() && $opts['hidepatrolled'] ) {
214 $conds['rc_patrolled'] = 0;
217 $conds['rc_bot'] = 1;
219 if ( $opts['hideliu'] ) {
220 $conds[] = 'rc_user = 0';
223 $conds[] = 'rc_user != 0';
226 if ( $opts['hidemyself'] ) {
227 if ( $user->getId() ) {
228 $conds[] = 'rc_user != ' . $dbr->addQuotes( $user->getId() );
230 $conds[] = 'rc_user_text != ' . $dbr->addQuotes( $user->getName() );
234 // Namespace filtering
235 if ( $opts['namespace'] !== '' ) {
236 $selectedNS = $dbr->addQuotes( $opts['namespace'] );
237 $operator = $opts['invert'] ?
'!=' : '=';
238 $boolean = $opts['invert'] ?
'AND' : 'OR';
240 // Namespace association (bug 2429)
241 if ( !$opts['associated'] ) {
242 $condition = "rc_namespace $operator $selectedNS";
244 // Also add the associated namespace
245 $associatedNS = $dbr->addQuotes(
246 MWNamespace
::getAssociated( $opts['namespace'] )
248 $condition = "(rc_namespace $operator $selectedNS "
250 . " rc_namespace $operator $associatedNS)";
253 $conds[] = $condition;
262 * @param array $conds
263 * @param FormOptions $opts
264 * @return bool|ResultWrapper Result or false
266 public function doMainQuery( $conds, $opts ) {
267 $tables = array( 'recentchanges' );
268 $fields = RecentChange
::selectFields();
269 $query_options = array();
270 $join_conds = array();
272 ChangeTags
::modifyDisplayQuery(
281 // @todo Fire a Special{$this->getName()}Query hook here
282 // @todo Uncomment and document
283 // if ( !wfRunHooks( 'ChangesListSpecialPageQuery',
284 // array( &$tables, &$fields, &$conds, &$query_options, &$join_conds, $opts ) )
289 $dbr = $this->getDB();
301 * Return a DatabaseBase object for reading
303 * @return DatabaseBase
305 protected function getDB() {
306 return wfGetDB( DB_SLAVE
);
310 * Send output to the OutputPage object, only called if not used feeds
312 * @param ResultWrapper $rows Database rows
313 * @param FormOptions $opts
315 public function webOutput( $rows, $opts ) {
316 if ( !$this->including() ) {
317 $this->outputFeedLinks();
318 $this->doHeader( $opts );
321 $this->outputChangesList( $rows, $opts );
327 public function outputFeedLinks() {
328 // nothing by default
332 * Build and output the actual changes list.
334 * @param array $rows Database rows
335 * @param FormOptions $opts
337 abstract public function outputChangesList( $rows, $opts );
340 * Return the text to be displayed above the changes
342 * @param FormOptions $opts
343 * @return string XHTML
345 public function doHeader( $opts ) {
346 $this->setTopText( $opts );
348 // @todo Lots of stuff should be done here.
350 $this->setBottomText( $opts );
354 * Send the text to be displayed before the options. Should use $this->getOutput()->addWikiText()
355 * or similar methods to print the text.
357 * @param FormOptions $opts
359 function setTopText( FormOptions
$opts ) {
360 // nothing by default
364 * Send the text to be displayed after the options. Should use $this->getOutput()->addWikiText()
365 * or similar methods to print the text.
367 * @param FormOptions $opts
369 function setBottomText( FormOptions
$opts ) {
370 // nothing by default
374 * Get options to be displayed in a form
375 * @todo This should handle options returned by getDefaultOptions().
376 * @todo Not called by anything, should be called by something… doHeader() maybe?
378 * @param FormOptions $opts
381 function getExtraOptions( $opts ) {
386 * Return the legend displayed within the fieldset
387 * @todo This should not be static, then we can drop the parameter
388 * @todo Not called by anything, should be called by doHeader()
390 * @param $context the object available as $this in non-static functions
393 public static function makeLegend( IContextSource
$context ) {
394 global $wgRecentChangesFlags;
395 $user = $context->getUser();
396 # The legend showing what the letters and stuff mean
397 $legend = Xml
::openElement( 'dl' ) . "\n";
398 # Iterates through them and gets the messages for both letter and tooltip
399 $legendItems = $wgRecentChangesFlags;
400 if ( !$user->useRCPatrol() ) {
401 unset( $legendItems['unpatrolled'] );
403 foreach ( $legendItems as $key => $legendInfo ) { # generate items of the legend
404 $label = $legendInfo['title'];
405 $letter = $legendInfo['letter'];
406 $cssClass = isset( $legendInfo['class'] ) ?
$legendInfo['class'] : $key;
408 $legend .= Xml
::element( 'dt',
409 array( 'class' => $cssClass ), $context->msg( $letter )->text()
411 if ( $key === 'newpage' ) {
412 $legend .= Xml
::openElement( 'dd' );
413 $legend .= $context->msg( $label )->escaped();
414 $legend .= ' ' . $context->msg( 'recentchanges-legend-newpage' )->parse();
415 $legend .= Xml
::closeElement( 'dd' ) . "\n";
417 $legend .= Xml
::element( 'dd', array(),
418 $context->msg( $label )->text()
423 $legend .= Xml
::tags( 'dt',
424 array( 'class' => 'mw-plusminus-pos' ),
425 $context->msg( 'recentchanges-legend-plusminus' )->parse()
427 $legend .= Xml
::element(
429 array( 'class' => 'mw-changeslist-legend-plusminus' ),
430 $context->msg( 'recentchanges-label-plusminus' )->text()
432 $legend .= Xml
::closeElement( 'dl' ) . "\n";
436 '<div class="mw-changeslist-legend">' .
437 $context->msg( 'recentchanges-legend-heading' )->parse() .
438 '<div class="mw-collapsible-content">' . $legend . '</div>' .
445 * Add page-specific modules.
447 protected function addModules() {
448 $out = $this->getOutput();
449 // Styles and behavior for the legend box (see makeLegend())
450 $out->addModuleStyles( 'mediawiki.special.changeslist.legend' );
451 $out->addModules( 'mediawiki.special.changeslist.legend.js' );
454 protected function getGroupName() {