From: Bartosz Dziewoński Date: Sun, 22 Dec 2013 13:47:36 +0000 (+0100) Subject: ChangesListSpecialPage: Implement execute() X-Git-Tag: 1.31.0-rc.0~17136^2 X-Git-Url: http://git.cyclocoop.org/%40spipnet%40?a=commitdiff_plain;h=e61ff86ab1b3a018b14cb9451eaab33a2eed7759;p=lhc%2Fweb%2Fwiklou.git ChangesListSpecialPage: Implement execute() Merging common content from SpecialRecentChanges and SpecialWatchlist plus some cleanup. Change-Id: Ic4bbedf2015a9f20a6e63ec53a72df91f1e3a2fe --- diff --git a/includes/specialpage/ChangesListSpecialPage.php b/includes/specialpage/ChangesListSpecialPage.php index d5ec18c98b..1d17394d5d 100644 --- a/includes/specialpage/ChangesListSpecialPage.php +++ b/includes/specialpage/ChangesListSpecialPage.php @@ -31,20 +31,64 @@ abstract class ChangesListSpecialPage extends SpecialPage { var $rcSubpage, $rcOptions; // @todo Rename these, make protected protected $customFilters; + /** + * The feed format to output as (either 'rss' or 'atom'), or null if no + * feed output was requested + * + * @var string $feedFormat + */ + protected $feedFormat; + /** * Main execution point - * @todo This should totally do things * * @param string $subpage */ public function execute( $subpage ) { $this->rcSubpage = $subpage; - throw new MWException( "Not implemented" ); + $this->feedFormat = $this->including() ? null : $this->getRequest()->getVal( 'feed' ); + if ( $this->feedFormat !== 'atom' && $this->feedFormat !== 'rss' ) { + $this->feedFormat = null; + } + + $this->setHeaders(); + $this->outputHeader(); + $this->addModules(); + + $opts = $this->getOptions(); + // Fetch results, prepare a batch link existence check query + $conds = $this->buildMainQueryConds( $opts ); + $rows = $this->doMainQuery( $conds, $opts ); + if ( $rows === false ) { + if ( !$this->including() ) { + $this->doHeader( $opts ); + } + + return; + } + + if ( !$this->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->add( $row->rc_namespace, $row->rc_title ); + } + $batch->execute(); + } + if ( $this->feedFormat ) { + list( $changesFeed, $formatter ) = $this->getFeedObject( $this->feedFormat ); + /** @var ChangesFeed $changesFeed */ + $changesFeed->execute( $formatter, $rows, $this->checkLastModified( $this->feedFormat ), $opts ); + } else { + $this->webOutput( $rows, $opts ); + } + + $rows->free(); } /** * Get the current FormOptions for this request - * @todo Not called by anything, should be called by execute() * * @return FormOptions */ @@ -142,7 +186,6 @@ abstract class ChangesListSpecialPage extends SpecialPage { /** * Return an array of conditions depending of options set in $opts * @todo This should build some basic conditions here… - * @todo Not called by anything, should be called by execute() * * @param FormOptions $opts * @return array @@ -152,7 +195,6 @@ abstract class ChangesListSpecialPage extends SpecialPage { /** * Process the query * @todo This should build some basic processing here… - * @todo Not called by anything, should be called by execute() * * @param array $conds * @param FormOptions $opts @@ -163,9 +205,8 @@ abstract class ChangesListSpecialPage extends SpecialPage { /** * Send output to the OutputPage object, only called if not used feeds * @todo This should do most, if not all, of the outputting now done by subclasses - * @todo Not called by anything, should be called by execute() * - * @param array $rows Database rows + * @param ResultWrapper $rows Database rows * @param FormOptions $opts */ abstract public function webOutput( $rows, $opts ); @@ -278,7 +319,6 @@ abstract class ChangesListSpecialPage extends SpecialPage { /** * Add page-specific modules. - * @todo Not called by anything, should be called by execute() */ protected function addModules() { $out = $this->getOutput(); @@ -287,6 +327,30 @@ abstract class ChangesListSpecialPage extends SpecialPage { $out->addModules( 'mediawiki.special.changeslist.legend.js' ); } + /** + * Return an array with a ChangesFeed object and ChannelFeed object. + * + * This is intentionally not abstract not to require subclasses which don't + * use feeds functionality to implement it. + * + * @param string $feedFormat Feed's format (either 'rss' or 'atom') + * @return array + */ + public function getFeedObject( $feedFormat ) { + throw new MWException( "Not implemented" ); + } + + /** + * Get last-modified date, for client caching. Not implemented by default + * (returns current time). + * + * @param string $feedFormat + * @return string|bool + */ + public function checkLastModified( $feedFormat ) { + return wfTimestampNow(); + } + protected function getGroupName() { return 'changes'; } diff --git a/includes/specials/SpecialRecentchanges.php b/includes/specials/SpecialRecentchanges.php index 4f89c00b43..d0e6171faf 100644 --- a/includes/specials/SpecialRecentchanges.php +++ b/includes/specials/SpecialRecentchanges.php @@ -27,13 +27,6 @@ * @ingroup SpecialPage */ class SpecialRecentChanges extends ChangesListSpecialPage { - /** - * The feed format to output as (either 'rss' or 'atom'), or null if no - * feed output was requested - * - * @var string $feedFormat - */ - protected $feedFormat; public function __construct( $name = 'Recentchanges', $restriction = '' ) { parent::__construct( $name, $restriction ); @@ -45,51 +38,15 @@ class SpecialRecentChanges extends ChangesListSpecialPage { * @param string $subpage */ public function execute( $subpage ) { - $this->rcSubpage = $subpage; - $this->feedFormat = $this->including() ? null : $this->getRequest()->getVal( 'feed' ); - - # 10 seconds server-side caching max + // 10 seconds server-side caching max $this->getOutput()->setSquidMaxage( 10 ); - # Check if the client has a cached version + // Check if the client has a cached version $lastmod = $this->checkLastModified( $this->feedFormat ); if ( $lastmod === false ) { return; } - $opts = $this->getOptions(); - $this->setHeaders(); - $this->outputHeader(); - $this->addModules(); - - // Fetch results, prepare a batch link existence check query - $conds = $this->buildMainQueryConds( $opts ); - $rows = $this->doMainQuery( $conds, $opts ); - if ( $rows === false ) { - if ( !$this->including() ) { - $this->doHeader( $opts ); - } - - return; - } - - if ( !$this->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->add( $row->rc_namespace, $row->rc_title ); - } - $batch->execute(); - } - if ( $this->feedFormat ) { - list( $changesFeed, $formatter ) = $this->getFeedObject( $this->feedFormat ); - /** @var ChangesFeed $changesFeed */ - $changesFeed->execute( $formatter, $rows, $lastmod, $opts ); - } else { - $this->webOutput( $rows, $opts ); - } - - $rows->free(); + parent::execute( $subpage ); } /** @@ -593,7 +550,7 @@ class SpecialRecentChanges extends ChangesListSpecialPage { } /** - * Return an array with a ChangesFeed object and ChannelFeed object + * Return an array with a ChangesFeed object and ChannelFeed object. * * @param string $feedFormat Feed's format (either 'rss' or 'atom') * @return array @@ -676,7 +633,7 @@ class SpecialRecentChanges extends ChangesListSpecialPage { /** * Filter $rows by categories set in $opts * - * @param array $rows Database rows + * @param ResultWrapper $rows Database rows * @param FormOptions $opts */ function filterByCategories( &$rows, FormOptions $opts ) { diff --git a/includes/specials/SpecialWatchlist.php b/includes/specials/SpecialWatchlist.php index f19d2323b8..aef50c04dc 100644 --- a/includes/specials/SpecialWatchlist.php +++ b/includes/specials/SpecialWatchlist.php @@ -18,7 +18,14 @@ * http://www.gnu.org/copyleft/gpl.html * * @file - * @ingroup SpecialPage Watchlist + * @ingroup SpecialPage + */ + +/** + * A special page that lists last changes made to the wiki, + * limited to user-defined list of titles. + * + * @ingroup SpecialPage */ class SpecialWatchlist extends ChangesListSpecialPage { /** @@ -29,25 +36,20 @@ class SpecialWatchlist extends ChangesListSpecialPage { } /** - * Execute - * @param $par Parameter passed to the page + * Main execution point + * + * @param string $subpage */ - function execute( $par ) { + function execute( $subpage ) { global $wgRCShowWatchingUsers, $wgEnotifWatchlist, $wgShowUpdatedMarker; - $user = $this->getUser(); - $output = $this->getOutput(); - - # Anons don't get a watchlist + // Anons don't get a watchlist $this->requireLogin( 'watchlistanontext' ); - // Check permissions - $this->checkPermissions(); - + $output = $this->getOutput(); $request = $this->getRequest(); - $opts = $this->getOptions(); - $mode = SpecialEditWatchlist::getMode( $request, $par ); + $mode = SpecialEditWatchlist::getMode( $request, $subpage ); if ( $mode !== false ) { if ( $mode === SpecialEditWatchlist::EDIT_RAW ) { $title = SpecialPage::getTitleFor( 'EditWatchlist', 'raw' ); @@ -59,6 +61,11 @@ class SpecialWatchlist extends ChangesListSpecialPage { return; } + $this->checkPermissions(); + + $user = $this->getUser(); + $opts = $this->getOptions(); + if ( ( $wgEnotifWatchlist || $wgShowUpdatedMarker ) && $request->getVal( 'reset' ) && $request->wasPosted() ) { @@ -67,38 +74,7 @@ class SpecialWatchlist extends ChangesListSpecialPage { return; } - $this->setHeaders(); - $this->outputHeader(); - $this->addModules(); - - // Fetch results, prepare a batch link existence check query - $conds = $this->buildMainQueryConds( $opts ); - $rows = $this->doMainQuery( $conds, $opts ); - if ( $rows === false ) { - $this->doHeader( $opts ); - - return; - } - - $feedFormat = $this->getRequest()->getVal( 'feed' ); - 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->add( $row->rc_namespace, $row->rc_title ); - } - $batch->execute(); - } - if ( $feedFormat ) { - list( $changesFeed, $formatter ) = $this->getFeedObject( $feedFormat ); - /** @var ChangesFeed $changesFeed */ - $changesFeed->execute( $formatter, $rows, $lastmod, $opts ); - } else { - $this->webOutput( $rows, $opts ); - } - - $rows->free(); + parent::execute( $subpage ); } /** @@ -321,7 +297,7 @@ class SpecialWatchlist extends ChangesListSpecialPage { /** * Send output to the OutputPage object, only called if not used feeds * - * @param array $rows Database rows + * @param ResultWrapper $rows Database rows * @param FormOptions $opts */ public function webOutput( $rows, $opts ) {