Merge "Add PreferencesFormPreSave hook"
[lhc/web/wiklou.git] / includes / specials / SpecialRecentchanges.php
index d0e6171..7352de7 100644 (file)
@@ -144,6 +144,7 @@ class SpecialRecentChanges extends ChangesListSpecialPage {
        public function validateOptions( FormOptions $opts ) {
                global $wgFeedLimit;
                $opts->validateIntBounds( 'limit', 0, $this->feedFormat ? $wgFeedLimit : 5000 );
+               parent::validateOptions( $opts );
        }
 
        /**
@@ -153,21 +154,8 @@ class SpecialRecentChanges extends ChangesListSpecialPage {
         * @return array
         */
        public function buildMainQueryConds( FormOptions $opts ) {
-               $dbr = wfGetDB( DB_SLAVE );
-               $conds = array();
-
-               # It makes no sense to hide both anons and logged-in users
-               # Where this occurs, force anons to be shown
-               $forcebot = false;
-               if ( $opts['hideanons'] && $opts['hideliu'] ) {
-                       # Check if the user wants to show bots only
-                       if ( $opts['hidebots'] ) {
-                               $opts['hideanons'] = false;
-                       } else {
-                               $forcebot = true;
-                               $opts['hidebots'] = false;
-                       }
-               }
+               $dbr = $this->getDB();
+               $conds = parent::buildMainQueryConds( $opts );
 
                // Calculate cutoff
                $cutoff_unixtime = time() - ( $opts['days'] * 86400 );
@@ -183,59 +171,6 @@ class SpecialRecentChanges extends ChangesListSpecialPage {
 
                $conds[] = 'rc_timestamp >= ' . $dbr->addQuotes( $cutoff );
 
-               $hidePatrol = $this->getUser()->useRCPatrol() && $opts['hidepatrolled'];
-               $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['hidemyself'] ) {
-                       if ( $this->getUser()->getId() ) {
-                               $conds[] = 'rc_user != ' . $dbr->addQuotes( $this->getUser()->getId() );
-                       } else {
-                               $conds[] = 'rc_user_text != ' . $dbr->addQuotes( $this->getUser()->getName() );
-                       }
-               }
-
-               # Namespace filtering
-               if ( $opts['namespace'] !== '' ) {
-                       $selectedNS = $dbr->addQuotes( $opts['namespace'] );
-                       $operator = $opts['invert'] ? '!=' : '=';
-                       $boolean = $opts['invert'] ? 'AND' : 'OR';
-
-                       # namespace association (bug 2429)
-                       if ( !$opts['associated'] ) {
-                               $condition = "rc_namespace $operator $selectedNS";
-                       } else {
-                               # Also add the associated namespace
-                               $associatedNS = $dbr->addQuotes(
-                                       MWNamespace::getAssociated( $opts['namespace'] )
-                               );
-                               $condition = "(rc_namespace $operator $selectedNS "
-                                       . $boolean
-                                       . " rc_namespace $operator $associatedNS)";
-                       }
-
-                       $conds[] = $condition;
-               }
-
                return $conds;
        }
 
@@ -247,35 +182,34 @@ class SpecialRecentChanges extends ChangesListSpecialPage {
         * @return bool|ResultWrapper Result or false (for Recentchangeslinked only)
         */
        public function doMainQuery( $conds, $opts ) {
-               $tables = array( 'recentchanges' );
-               $join_conds = array();
-               $query_options = array();
+               global $wgAllowCategorizedRecentChanges;
 
-               $uid = $this->getUser()->getId();
-               $dbr = wfGetDB( DB_SLAVE );
-               $limit = $opts['limit'];
-               $namespace = $opts['namespace'];
-               $invert = $opts['invert'];
-               $associated = $opts['associated'];
+               $dbr = $this->getDB();
+               $user = $this->getUser();
 
+               $tables = array( 'recentchanges' );
                $fields = RecentChange::selectFields();
+               $query_options = array();
+               $join_conds = array();
+
                // JOIN on watchlist for users
-               if ( $uid && $this->getUser()->isAllowed( 'viewmywatchlist' ) ) {
+               if ( $user->getId() && $user->isAllowed( 'viewmywatchlist' ) ) {
                        $tables[] = 'watchlist';
                        $fields[] = 'wl_user';
                        $fields[] = 'wl_notificationtimestamp';
                        $join_conds['watchlist'] = array( 'LEFT JOIN', array(
-                               'wl_user' => $uid,
+                               'wl_user' => $user->getId(),
                                'wl_title=rc_title',
                                'wl_namespace=rc_namespace'
                        ) );
                }
-               if ( $this->getUser()->isAllowed( 'rollback' ) ) {
+
+               if ( $user->isAllowed( 'rollback' ) ) {
                        $tables[] = 'page';
                        $fields[] = 'page_latest';
                        $join_conds['page'] = array( 'LEFT JOIN', 'rc_cur_id=page_id' );
                }
-               // Tag stuff.
+
                ChangeTags::modifyDisplayQuery(
                        $tables,
                        $fields,
@@ -293,37 +227,50 @@ class SpecialRecentChanges extends ChangesListSpecialPage {
 
                // rc_new is not an ENUM, but adding a redundant rc_new IN (0,1) gives mysql enough
                // knowledge to use an index merge if it wants (it may use some other index though).
-               return $dbr->select(
+               $rows = $dbr->select(
                        $tables,
                        $fields,
                        $conds + array( 'rc_new' => array( 0, 1 ) ),
                        __METHOD__,
-                       array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $limit ) + $query_options,
+                       array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $opts['limit'] ) + $query_options,
                        $join_conds
                );
+
+               // Build the final data
+               if ( $wgAllowCategorizedRecentChanges ) {
+                       $this->filterByCategories( $rows, $opts );
+               }
+
+               return $rows;
+       }
+
+       /**
+        * Output feed links.
+        */
+       public function outputFeedLinks() {
+               $feedQuery = $this->getFeedQuery();
+               if ( $feedQuery !== '' ) {
+                       $this->getOutput()->setFeedAppendQuery( $feedQuery );
+               } else {
+                       $this->getOutput()->setFeedAppendQuery( false );
+               }
        }
 
        /**
-        * Send output to the OutputPage object, only called if not used feeds
+        * Build and output the actual changes list.
         *
         * @param array $rows Database rows
         * @param FormOptions $opts
         */
-       public function webOutput( $rows, $opts ) {
-               global $wgRCShowWatchingUsers, $wgShowUpdatedMarker, $wgAllowCategorizedRecentChanges;
-
-               // Build the final data
-
-               if ( $wgAllowCategorizedRecentChanges ) {
-                       $this->filterByCategories( $rows, $opts );
-               }
+       public function outputChangesList( $rows, $opts ) {
+               global $wgRCShowWatchingUsers, $wgShowUpdatedMarker;
 
                $limit = $opts['limit'];
 
                $showWatcherCount = $wgRCShowWatchingUsers && $this->getUser()->getOption( 'shownumberswatching' );
                $watcherCache = array();
 
-               $dbr = wfGetDB( DB_SLAVE );
+               $dbr = $this->getDB();
 
                $counter = 1;
                $list = ChangesList::newFromContext( $this->getContext() );
@@ -367,21 +314,6 @@ class SpecialRecentChanges extends ChangesListSpecialPage {
                }
                $rclistOutput .= $list->endRecentChangesList();
 
-               // Print things out
-
-               if ( !$this->including() ) {
-                       // Output options box
-                       $this->doHeader( $opts );
-               }
-
-               // And now for the content
-               $feedQuery = $this->getFeedQuery();
-               if ( $feedQuery !== '' ) {
-                       $this->getOutput()->setFeedAppendQuery( $feedQuery );
-               } else {
-                       $this->getOutput()->setFeedAppendQuery( false );
-               }
-
                if ( $rows->numRows() === 0 ) {
                        $this->getOutput()->addHtml(
                                '<div class="mw-changeslist-empty">' . $this->msg( 'recentchanges-noresult' )->parse() . '</div>'
@@ -537,7 +469,7 @@ class SpecialRecentChanges extends ChangesListSpecialPage {
         * @return string|bool
         */
        public function checkLastModified( $feedFormat ) {
-               $dbr = wfGetDB( DB_SLAVE );
+               $dbr = $this->getDB();
                $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, __METHOD__ );
                if ( $feedFormat || !$this->getUser()->useRCPatrol() ) {
                        if ( $lastmod && $this->getOutput()->checkLastModified( $lastmod ) ) {