summaryrefslogtreecommitdiff
path: root/includes/specials/SpecialRecentchanges.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/specials/SpecialRecentchanges.php')
-rw-r--r--includes/specials/SpecialRecentchanges.php263
1 files changed, 128 insertions, 135 deletions
diff --git a/includes/specials/SpecialRecentchanges.php b/includes/specials/SpecialRecentchanges.php
index cb718bdc..8c14e1fc 100644
--- a/includes/specials/SpecialRecentchanges.php
+++ b/includes/specials/SpecialRecentchanges.php
@@ -6,7 +6,7 @@
*/
class SpecialRecentChanges extends SpecialPage {
public function __construct() {
- SpecialPage::SpecialPage( 'Recentchanges' );
+ parent::__construct( 'Recentchanges' );
$this->includable( true );
}
@@ -16,13 +16,14 @@ class SpecialRecentChanges extends SpecialPage {
* @return FormOptions
*/
public function getDefaultOptions() {
+ global $wgUser;
$opts = new FormOptions();
- $opts->add( 'days', (int)User::getDefaultOption( 'rcdays' ) );
- $opts->add( 'limit', (int)User::getDefaultOption( 'rclimit' ) );
+ $opts->add( 'days', (int)$wgUser->getOption( 'rcdays' ) );
+ $opts->add( 'limit', (int)$wgUser->getOption( 'rclimit' ) );
$opts->add( 'from', '' );
- $opts->add( 'hideminor', false );
+ $opts->add( 'hideminor', (bool)$wgUser->getOption( 'hideminor' ) );
$opts->add( 'hidebots', true );
$opts->add( 'hideanons', false );
$opts->add( 'hideliu', false );
@@ -34,7 +35,6 @@ class SpecialRecentChanges extends SpecialPage {
$opts->add( 'categories', '' );
$opts->add( 'categories_any', false );
-
return $opts;
}
@@ -44,16 +44,13 @@ class SpecialRecentChanges extends SpecialPage {
* @return FormOptions
*/
public function setup( $parameters ) {
- global $wgUser, $wgRequest;
+ global $wgRequest;
$opts = $this->getDefaultOptions();
- $opts['days'] = (int)$wgUser->getOption( 'rcdays', $opts['days'] );
- $opts['limit'] = (int)$wgUser->getOption( 'rclimit', $opts['limit'] );
- $opts['hideminor'] = $wgUser->getOption( 'hideminor', $opts['hideminor'] );
$opts->fetchValuesFromRequest( $wgRequest );
// Give precedence to subpage syntax
- if ( $parameters !== null ) {
+ if( $parameters !== null ) {
$this->parseParameters( $parameters, $opts );
}
@@ -85,9 +82,9 @@ class SpecialRecentChanges extends SpecialPage {
# 10 seconds server-side caching max
$wgOut->setSquidMaxage( 10 );
-
+ # Check if the client has a cached version
$lastmod = $this->checkLastModified( $feedFormat );
- if( $lastmod === false ){
+ if( $lastmod === false ) {
return;
}
@@ -97,33 +94,32 @@ class SpecialRecentChanges extends SpecialPage {
// Fetch results, prepare a batch link existence check query
$rows = array();
- $batch = new LinkBatch;
$conds = $this->buildMainQueryConds( $opts );
- $res = $this->doMainQuery( $conds, $opts );
- if( $res === false ){
- $this->doHeader( $opts );
+ $rows = $this->doMainQuery( $conds, $opts );
+ if( $rows === false ){
+ if( !$this->including() ) {
+ $this->doHeader( $opts );
+ }
return;
}
- $dbr = wfGetDB( DB_SLAVE );
- while( $row = $dbr->fetchObject( $res ) ){
- $rows[] = $row;
- if ( !$feedFormat ) {
- // User page and talk links
+
+ if( !$feedFormat ) {
+ $batch = new LinkBatch;
+ foreach( $rows as $row ) {
$batch->add( NS_USER, $row->rc_user_text );
$batch->add( NS_USER_TALK, $row->rc_user_text );
}
-
+ $batch->execute();
}
- $dbr->freeResult( $res );
- if ( $feedFormat ) {
+ if( $feedFormat ) {
list( $feed, $feedObj ) = $this->getFeedObject( $feedFormat );
$feed->execute( $feedObj, $rows, $opts['limit'], $opts['hideminor'], $lastmod );
} else {
- $batch->execute();
$this->webOutput( $rows, $opts );
}
-
+
+ $rows->free();
}
/**
@@ -149,21 +145,21 @@ class SpecialRecentChanges extends SpecialPage {
*/
public function parseParameters( $par, FormOptions $opts ) {
$bits = preg_split( '/\s*,\s*/', trim( $par ) );
- foreach ( $bits as $bit ) {
- if ( 'hidebots' === $bit ) $opts['hidebots'] = true;
- if ( 'bots' === $bit ) $opts['hidebots'] = false;
- if ( 'hideminor' === $bit ) $opts['hideminor'] = true;
- if ( 'minor' === $bit ) $opts['hideminor'] = false;
- if ( 'hideliu' === $bit ) $opts['hideliu'] = true;
- if ( 'hidepatrolled' === $bit ) $opts['hidepatrolled'] = true;
- if ( 'hideanons' === $bit ) $opts['hideanons'] = true;
- if ( 'hidemyself' === $bit ) $opts['hidemyself'] = true;
-
- if ( is_numeric( $bit ) ) $opts['limit'] = $bit;
+ foreach( $bits as $bit ) {
+ if( 'hidebots' === $bit ) $opts['hidebots'] = true;
+ if( 'bots' === $bit ) $opts['hidebots'] = false;
+ if( 'hideminor' === $bit ) $opts['hideminor'] = true;
+ if( 'minor' === $bit ) $opts['hideminor'] = false;
+ if( 'hideliu' === $bit ) $opts['hideliu'] = true;
+ if( 'hidepatrolled' === $bit ) $opts['hidepatrolled'] = true;
+ if( 'hideanons' === $bit ) $opts['hideanons'] = true;
+ if( 'hidemyself' === $bit ) $opts['hidemyself'] = true;
+
+ if( is_numeric( $bit ) ) $opts['limit'] = $bit;
$m = array();
- if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) $opts['limit'] = $m[1];
- if ( preg_match( '/^days=(\d+)$/', $bit, $m ) ) $opts['days'] = $m[1];
+ if( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) $opts['limit'] = $m[1];
+ if( preg_match( '/^days=(\d+)$/', $bit, $m ) ) $opts['days'] = $m[1];
}
}
@@ -173,14 +169,14 @@ class SpecialRecentChanges extends SpecialPage {
* update the timestamp
*
* @param $feedFormat String
- * @return int or false
+ * @return string or false
*/
public function checkLastModified( $feedFormat ) {
global $wgUseRCPatrol, $wgOut;
$dbr = wfGetDB( DB_SLAVE );
$lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, __FUNCTION__ );
- if ( $feedFormat || !$wgUseRCPatrol ) {
- if( $lastmod && $wgOut->checkLastModified( $lastmod ) ){
+ if( $feedFormat || !$wgUseRCPatrol ) {
+ if( $lastmod && $wgOut->checkLastModified( $lastmod ) ) {
# Client cache fresh and headers sent, nothing more to do.
return false;
}
@@ -232,12 +228,12 @@ class SpecialRecentChanges extends SpecialPage {
$hideLoggedInUsers = $opts['hideliu'] && !$forcebot;
$hideAnonymousUsers = $opts['hideanons'] && !$forcebot;
- if ( $opts['hideminor'] ) $conds['rc_minor'] = 0;
- if ( $opts['hidebots'] ) $conds['rc_bot'] = 0;
- if ( $hidePatrol ) $conds['rc_patrolled'] = 0;
- if ( $forcebot ) $conds['rc_bot'] = 1;
- if ( $hideLoggedInUsers ) $conds[] = 'rc_user = 0';
- if ( $hideAnonymousUsers ) $conds[] = 'rc_user != 0';
+ if( $opts['hideminor'] ) $conds['rc_minor'] = 0;
+ if( $opts['hidebots'] ) $conds['rc_bot'] = 0;
+ if( $hidePatrol ) $conds['rc_patrolled'] = 0;
+ if( $forcebot ) $conds['rc_bot'] = 1;
+ if( $hideLoggedInUsers ) $conds[] = 'rc_user = 0';
+ if( $hideAnonymousUsers ) $conds[] = 'rc_user != 0';
if( $opts['hidemyself'] ) {
if( $wgUser->getId() ) {
@@ -248,8 +244,8 @@ class SpecialRecentChanges extends SpecialPage {
}
# Namespace filtering
- if ( $opts['namespace'] !== '' ) {
- if ( !$opts['invert'] ) {
+ if( $opts['namespace'] !== '' ) {
+ if( !$opts['invert'] ) {
$conds[] = 'rc_namespace = ' . $dbr->addQuotes( $opts['namespace'] );
} else {
$conds[] = 'rc_namespace != ' . $dbr->addQuotes( $opts['namespace'] );
@@ -281,7 +277,8 @@ class SpecialRecentChanges extends SpecialPage {
// JOIN on watchlist for users
if( $uid ) {
$tables[] = 'watchlist';
- $join_conds = array( 'watchlist' => array('LEFT JOIN',"wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace") );
+ $join_conds = array( 'watchlist' => array('LEFT JOIN',
+ "wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace") );
}
wfRunHooks('SpecialRecentChangesQuery', array( &$conds, &$tables, &$join_conds, $opts ) );
@@ -329,7 +326,7 @@ class SpecialRecentChanges extends SpecialPage {
$limit = $opts['limit'];
- if ( !$this->including() ) {
+ if( !$this->including() ) {
// Output options box
$this->doHeader( $opts );
}
@@ -337,55 +334,46 @@ class SpecialRecentChanges extends SpecialPage {
// And now for the content
$wgOut->setSyndicated( true );
- $list = ChangesList::newFromUser( $wgUser );
-
- if ( $wgAllowCategorizedRecentChanges ) {
+ if( $wgAllowCategorizedRecentChanges ) {
$this->filterByCategories( $rows, $opts );
}
- $s = $list->beginRecentChangesList();
- $counter = 1;
-
$showWatcherCount = $wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' );
$watcherCache = array();
$dbr = wfGetDB( DB_SLAVE );
- foreach( $rows as $obj ){
- if( $limit == 0) {
- break;
- }
-
- if ( ! ( $opts['hideminor'] && $obj->rc_minor ) &&
- ! ( $opts['hidepatrolled'] && $obj->rc_patrolled ) ) {
- $rc = RecentChange::newFromRow( $obj );
- $rc->counter = $counter++;
-
- if ($wgShowUpdatedMarker
- && !empty( $obj->wl_notificationtimestamp )
- && ($obj->rc_timestamp >= $obj->wl_notificationtimestamp)) {
- $rc->notificationtimestamp = true;
- } else {
- $rc->notificationtimestamp = false;
- }
+ $counter = 1;
+ $list = ChangesList::newFromUser( $wgUser );
- $rc->numberofWatchingusers = 0; // Default
- if ($showWatcherCount && $obj->rc_namespace >= 0) {
- if (!isset($watcherCache[$obj->rc_namespace][$obj->rc_title])) {
- $watcherCache[$obj->rc_namespace][$obj->rc_title] =
- $dbr->selectField( 'watchlist',
- 'COUNT(*)',
- array(
- 'wl_namespace' => $obj->rc_namespace,
- 'wl_title' => $obj->rc_title,
- ),
- __METHOD__ . '-watchers' );
- }
- $rc->numberofWatchingusers = $watcherCache[$obj->rc_namespace][$obj->rc_title];
+ $s = $list->beginRecentChangesList();
+ foreach( $rows as $obj ) {
+ if( $limit == 0 ) break;
+ $rc = RecentChange::newFromRow( $obj );
+ $rc->counter = $counter++;
+ # Check if the page has been updated since the last visit
+ if( $wgShowUpdatedMarker && !empty($obj->wl_notificationtimestamp) ) {
+ $rc->notificationtimestamp = ($obj->rc_timestamp >= $obj->wl_notificationtimestamp);
+ } else {
+ $rc->notificationtimestamp = false; // Default
+ }
+ # Check the number of users watching the page
+ $rc->numberofWatchingusers = 0; // Default
+ if( $showWatcherCount && $obj->rc_namespace >= 0 ) {
+ if( !isset($watcherCache[$obj->rc_namespace][$obj->rc_title]) ) {
+ $watcherCache[$obj->rc_namespace][$obj->rc_title] =
+ $dbr->selectField( 'watchlist',
+ 'COUNT(*)',
+ array(
+ 'wl_namespace' => $obj->rc_namespace,
+ 'wl_title' => $obj->rc_title,
+ ),
+ __METHOD__ . '-watchers' );
}
- $s .= $list->recentChangesLine( $rc, !empty( $obj->wl_user ) );
- --$limit;
+ $rc->numberofWatchingusers = $watcherCache[$obj->rc_namespace][$obj->rc_title];
}
+ $s .= $list->recentChangesLine( $rc, !empty( $obj->wl_user ) );
+ --$limit;
}
$s .= $list->endRecentChangesList();
$wgOut->addHTML( $s );
@@ -411,22 +399,29 @@ class SpecialRecentChanges extends SpecialPage {
$panel[] = '<hr />';
$extraOpts = $this->getExtraOptions( $opts );
+ $extraOptsCount = count( $extraOpts );
+ $count = 0;
+ $submit = ' ' . Xml::submitbutton( wfMsg( 'allpagessubmit' ) );
+
+ $out = Xml::openElement( 'table', array( 'class' => 'mw-recentchanges-table' ) );
+ foreach( $extraOpts as $optionRow ) {
+ # Add submit button to the last row only
+ ++$count;
+ $addSubmit = $count === $extraOptsCount ? $submit : '';
- $out = Xml::openElement( 'table' );
- foreach ( $extraOpts as $optionRow ) {
$out .= Xml::openElement( 'tr' );
- if ( is_array($optionRow) ) {
- $out .= Xml::tags( 'td', null, $optionRow[0] );
- $out .= Xml::tags( 'td', null, $optionRow[1] );
+ if( is_array( $optionRow ) ) {
+ $out .= Xml::tags( 'td', array( 'class' => 'mw-label' ), $optionRow[0] );
+ $out .= Xml::tags( 'td', array( 'class' => 'mw-input' ), $optionRow[1] . $addSubmit );
} else {
- $out .= Xml::tags( 'td', array( 'colspan' => 2 ), $optionRow );
+ $out .= Xml::tags( 'td', array( 'class' => 'mw-input', 'colspan' => 2 ), $optionRow . $addSubmit );
}
$out .= Xml::closeElement( 'tr' );
}
$out .= Xml::closeElement( 'table' );
$unconsumed = $opts->getUnconsumedValues();
- foreach ( $unconsumed as $key => $value ) {
+ foreach( $unconsumed as $key => $value ) {
$out .= Xml::hidden( $key, $value );
}
@@ -437,7 +432,7 @@ class SpecialRecentChanges extends SpecialPage {
$panelString = implode( "\n", $panel );
$wgOut->addHTML(
- Xml::fieldset( wfMsg( strtolower( $this->mName ) ), $panelString, array( 'class' => 'rcoptions' ) )
+ Xml::fieldset( wfMsg( 'recentchanges-legend' ), $panelString, array( 'class' => 'rcoptions' ) )
);
$this->setBottomText( $wgOut, $opts );
@@ -454,12 +449,11 @@ class SpecialRecentChanges extends SpecialPage {
$extraOpts['namespace'] = $this->namespaceFilterForm( $opts );
global $wgAllowCategorizedRecentChanges;
- if ( $wgAllowCategorizedRecentChanges ) {
+ if( $wgAllowCategorizedRecentChanges ) {
$extraOpts['category'] = $this->categoryFilterForm( $opts );
}
wfRunHooks( 'SpecialRecentChangesPanel', array( &$extraOpts, $opts ) );
- $extraOpts['submit'] = Xml::submitbutton( wfMsg('allpagessubmit') );
return $extraOpts;
}
@@ -469,7 +463,7 @@ class SpecialRecentChanges extends SpecialPage {
* @param $out OutputPage
* @param $opts FormOptions
*/
- function setTopText( &$out, $opts ){
+ function setTopText( OutputPage $out, FormOptions $opts ){
$out->addWikiText( wfMsgForContentNoTrans( 'recentchangestext' ) );
}
@@ -480,7 +474,7 @@ class SpecialRecentChanges extends SpecialPage {
* @param $out OutputPage
* @param $opts FormOptions
*/
- function setBottomText( &$out, $opts ){}
+ function setBottomText( OutputPage $out, FormOptions $opts ){}
/**
* Creates the choose namespace selection
@@ -489,7 +483,7 @@ class SpecialRecentChanges extends SpecialPage {
* @return string
*/
protected function namespaceFilterForm( FormOptions $opts ) {
- $nsSelect = HTMLnamespaceselector( $opts['namespace'], '' );
+ $nsSelect = Xml::namespaceSelector( $opts['namespace'], '' );
$nsLabel = Xml::label( wfMsg('namespace'), 'namespace' );
$invert = Xml::checkLabel( wfMsg('invert'), 'invert', 'nsinvert', $opts['invert'] );
return array( $nsLabel, "$nsSelect $invert" );
@@ -526,30 +520,30 @@ class SpecialRecentChanges extends SpecialPage {
# Filter categories
$cats = array();
- foreach ( $categories as $cat ) {
+ foreach( $categories as $cat ) {
$cat = trim( $cat );
- if ( $cat == "" ) continue;
+ if( $cat == "" ) continue;
$cats[] = $cat;
}
# Filter articles
$articles = array();
$a2r = array();
- foreach ( $rows AS $k => $r ) {
+ foreach( $rows AS $k => $r ) {
$nt = Title::makeTitle( $r->rc_namespace, $r->rc_title );
$id = $nt->getArticleID();
- if ( $id == 0 ) continue; # Page might have been deleted...
- if ( !in_array($id, $articles) ) {
+ if( $id == 0 ) continue; # Page might have been deleted...
+ if( !in_array($id, $articles) ) {
$articles[] = $id;
}
- if ( !isset($a2r[$id]) ) {
+ if( !isset($a2r[$id]) ) {
$a2r[$id] = array();
}
$a2r[$id][] = $k;
}
# Shortcut?
- if ( !count($articles) || !count($cats) )
+ if( !count($articles) || !count($cats) )
return ;
# Look up
@@ -559,8 +553,8 @@ class SpecialRecentChanges extends SpecialPage {
# Filter
$newrows = array();
- foreach ( $match AS $id ) {
- foreach ( $a2r[$id] AS $rev ) {
+ foreach( $match AS $id ) {
+ foreach( $a2r[$id] AS $rev ) {
$k = $rev;
$newrows[$k] = $rows[$k];
}
@@ -577,8 +571,9 @@ class SpecialRecentChanges extends SpecialPage {
function makeOptionsLink( $title, $override, $options, $active = false ) {
global $wgUser;
$sk = $wgUser->getSkin();
- return $sk->makeKnownLinkObj( $this->getTitle(), htmlspecialchars( $title ),
- wfArrayToCGI( $override, $options ), '', '', $active ? 'style="font-weight: bold;"' : '' );
+ $params = $override + $options;
+ return $sk->link( $this->getTitle(), htmlspecialchars( $title ),
+ ( $active ? array( 'style'=>'font-weight: bold;' ) : array() ), $params, array( 'known' ) );
}
/**
@@ -591,43 +586,41 @@ class SpecialRecentChanges extends SpecialPage {
$options = $nondefaults + $defaults;
- if( $options['from'] )
- $note = wfMsgExt( 'rcnotefrom', array( 'parseinline' ),
+ $note = '';
+ if( $options['from'] ) {
+ $note .= wfMsgExt( 'rcnotefrom', array( 'parseinline' ),
$wgLang->formatNum( $options['limit'] ),
- $wgLang->timeanddate( $options['from'], true ) );
- else
- $note = wfMsgExt( 'rcnote', array( 'parseinline' ),
- $wgLang->formatNum( $options['limit'] ),
- $wgLang->formatNum( $options['days'] ),
- $wgLang->timeAndDate( wfTimestampNow(), true ),
- $wgLang->date( wfTimestampNow(), true ),
- $wgLang->time( wfTimestampNow(), true ) );
+ $wgLang->timeanddate( $options['from'], true ) ) . '<br />';
+ }
+ if( !wfEmptyMsg( 'rclegend', wfMsg('rclegend') ) ) {
+ $note .= wfMsgExt( 'rclegend', array('parseinline') ) . '<br />';
+ }
# Sort data for display and make sure it's unique after we've added user data.
$wgRCLinkLimits[] = $options['limit'];
$wgRCLinkDays[] = $options['days'];
- sort($wgRCLinkLimits);
- sort($wgRCLinkDays);
- $wgRCLinkLimits = array_unique($wgRCLinkLimits);
- $wgRCLinkDays = array_unique($wgRCLinkDays);
+ sort( $wgRCLinkLimits );
+ sort( $wgRCLinkDays );
+ $wgRCLinkLimits = array_unique( $wgRCLinkLimits );
+ $wgRCLinkDays = array_unique( $wgRCLinkDays );
// limit links
foreach( $wgRCLinkLimits as $value ) {
$cl[] = $this->makeOptionsLink( $wgLang->formatNum( $value ),
array( 'limit' => $value ), $nondefaults, $value == $options['limit'] ) ;
}
- $cl = implode( ' | ', $cl);
+ $cl = implode( ' | ', $cl );
// day links, reset 'from' to none
foreach( $wgRCLinkDays as $value ) {
$dl[] = $this->makeOptionsLink( $wgLang->formatNum( $value ),
array( 'days' => $value, 'from' => '' ), $nondefaults, $value == $options['days'] ) ;
}
- $dl = implode( ' | ', $dl);
+ $dl = implode( ' | ', $dl );
// show/hide links
- $showhide = array( wfMsg( 'show' ), wfMsg( 'hide' ));
+ $showhide = array( wfMsg( 'show' ), wfMsg( 'hide' ) );
$minorLink = $this->makeOptionsLink( $showhide[1-$options['hideminor']],
array( 'hideminor' => 1-$options['hideminor'] ), $nondefaults);
$botLink = $this->makeOptionsLink( $showhide[1-$options['hidebots']],
@@ -652,11 +645,11 @@ class SpecialRecentChanges extends SpecialPage {
// show from this onward link
$now = $wgLang->timeanddate( wfTimestampNow(), true );
- $tl = $this->makeOptionsLink( $now, array( 'from' => wfTimestampNow()), $nondefaults );
+ $tl = $this->makeOptionsLink( $now, array( 'from' => wfTimestampNow() ), $nondefaults );
- $rclinks = wfMsgExt( 'rclinks', array( 'parseinline', 'replaceafter'),
+ $rclinks = wfMsgExt( 'rclinks', array( 'parseinline', 'replaceafter' ),
$cl, $dl, $hl );
- $rclistfrom = wfMsgExt( 'rclistfrom', array( 'parseinline', 'replaceafter'), $tl );
- return "$note<br />$rclinks<br />$rclistfrom";
+ $rclistfrom = wfMsgExt( 'rclistfrom', array( 'parseinline', 'replaceafter' ), $tl );
+ return "{$note}$rclinks<br />$rclistfrom";
}
}