]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - includes/specials/SpecialRecentchangeslinked.php
MediaWiki 1.17.0
[autoinstallsdev/mediawiki.git] / includes / specials / SpecialRecentchangeslinked.php
index c58ffff076def3d76ae73d9b88d2287030f92edf..db0f554d0289d1e5809789e8206afc2954745948 100644 (file)
@@ -1,14 +1,36 @@
 <?php
+/**
+ * Implements Special:Recentchangeslinked
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup SpecialPage
+ */
 
 /**
  * This is to display changes made to all articles linked in an article.
+ *
  * @ingroup SpecialPage
  */
-class SpecialRecentchangeslinked extends SpecialRecentchanges {
+class SpecialRecentchangeslinked extends SpecialRecentChanges {
+       var $rclTargetTitle;
 
        function __construct(){
-               SpecialPage::SpecialPage( 'Recentchangeslinked' );
-               $this->includable( true );
+               parent::__construct( 'Recentchangeslinked' );
        }
 
        public function getDefaultOptions() {
@@ -26,7 +48,6 @@ class SpecialRecentchangeslinked extends SpecialRecentchanges {
        public function feedSetup() {
                global $wgRequest;
                $opts = parent::feedSetup();
-               # Feed is cached on limit,hideminor,target; other params would randomly not work
                $opts['target'] = $wgRequest->getVal( 'target' );
                return $opts;
        }
@@ -34,8 +55,8 @@ class SpecialRecentchangeslinked extends SpecialRecentchanges {
        public function getFeedObject( $feedFormat ){
                $feed = new ChangesFeed( $feedFormat, false );
                $feedObj = $feed->getFeedObject(
-                       wfMsgForContent( 'recentchangeslinked-title', $this->mTargetTitle->getPrefixedText() ),
-                       wfMsgForContent( 'recentchangeslinked' )
+                       wfMsgForContent( 'recentchangeslinked-title', $this->getTargetTitle()->getPrefixedText() ),
+                       wfMsgForContent( 'recentchangeslinked-feed' )
                );
                return array( $feed, $feedObj );
        }
@@ -52,10 +73,9 @@ class SpecialRecentchangeslinked extends SpecialRecentchanges {
                }
                $title = Title::newFromURL( $target );
                if( !$title || $title->getInterwiki() != '' ){
-                       $wgOut->wrapWikiMsg( '<div class="errorbox">$1</div><br clear="both" />', 'allpagesbadtitle' );
+                       $wgOut->wrapWikiMsg( "<div class=\"errorbox\">\n$1\n</div><br style=\"clear: both\" />", 'allpagesbadtitle' );
                        return false;
                }
-               $this->mTargetTitle = $title;
 
                $wgOut->setPageTitle( wfMsg( 'recentchangeslinked-title', $title->getPrefixedText() ) );
 
@@ -79,17 +99,24 @@ class SpecialRecentchangeslinked extends SpecialRecentchanges {
                $query_options = array();
 
                // left join with watchlist table to highlight watched rows
-               if( $uid = $wgUser->getId() ) {
+               $uid = $wgUser->getId();
+               if( $uid ) {
                        $tables[] = 'watchlist';
                        $select[] = 'wl_user';
                        $join_conds['watchlist'] = array( 'LEFT JOIN', "wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace" );
                }
+               if ( $wgUser->isAllowed( 'rollback' ) ) {
+                       $tables[] = 'page';
+                       $join_conds['page'] = array('LEFT JOIN', 'rc_cur_id=page_id');
+                       $select[] = 'page_latest';
+               }
+               if ( !$this->including() ) { // bug 23293
+                       ChangeTags::modifyDisplayQuery( $tables, $select, $conds, $join_conds,
+                               $query_options, $opts['tagfilter'] );
+               }
 
-               ChangeTags::modifyDisplayQuery( $tables, $select, $conds, $join_conds,
-                       $query_options, $opts['tagfilter'] );
-
-               // XXX: parent class does this, should we too?
-               // wfRunHooks('SpecialRecentChangesQuery', array( &$conds, &$tables, &$join_conds, $opts ) );
+               if ( !wfRunHooks( 'SpecialRecentChangesQuery', array( &$conds, &$tables, &$join_conds, $opts, &$query_options, &$select ) ) )
+                       return false;
 
                if( $ns == NS_CATEGORY && !$showlinkedto ) {
                        // special handling for categories
@@ -139,25 +166,37 @@ class SpecialRecentchangeslinked extends SpecialRecentchanges {
                                }
                        }
 
-                       $subsql[] = $dbr->selectSQLText( 
+                       if( $dbr->unionSupportsOrderAndLimit())
+                               $order = array( 'ORDER BY' => 'rc_timestamp DESC' );
+                       else
+                               $order = array();
+
+                       
+                       $query = $dbr->selectSQLText( 
                                array_merge( $tables, array( $link_table ) ), 
                                $select, 
                                $conds + $subconds,
                                __METHOD__, 
-                               array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $limit ) + $query_options,
+                               $order + $query_options,
                                $join_conds + array( $link_table => array( 'INNER JOIN', $subjoin ) )
                        );
+                       
+                       if( $dbr->unionSupportsOrderAndLimit())
+                               $query = $dbr->limitResult( $query, $limit );
+
+                       $subsql[] = $query;
                }
 
                if( count($subsql) == 0 )
                        return false; // should never happen
-               if( count($subsql) == 1 )
+               if( count($subsql) == 1 && $dbr->unionSupportsOrderAndLimit() )
                        $sql = $subsql[0];
                else {
                        // need to resort and relimit after union
-                       $sql = "(" . implode( ") UNION (", $subsql ) . ") ORDER BY rc_timestamp DESC LIMIT {$limit}";
+                       $sql = $dbr->unionQueries($subsql, false).' ORDER BY rc_timestamp DESC';
+                       $sql = $dbr->limitResult($sql, $limit, false);
                }
-
+               
                $res = $dbr->query( $sql, __METHOD__ );
 
                if( $res->numRows() == 0 )
@@ -167,10 +206,10 @@ class SpecialRecentchangeslinked extends SpecialRecentchanges {
        }
        
        function getExtraOptions( $opts ){
-               $opts->consumeValues( array( 'showlinkedto', 'target' ) );
+               $opts->consumeValues( array( 'showlinkedto', 'target', 'tagfilter' ) );
                $extraOpts = array();
                $extraOpts['namespace'] = $this->namespaceFilterForm( $opts );
-               $extraOpts['target'] = array( wfMsg( 'recentchangeslinked-page' ),
+               $extraOpts['target'] = array( wfMsgHtml( 'recentchangeslinked-page' ),
                        Xml::input( 'target', 40, str_replace('_',' ',$opts['target']) ) .
                        Xml::check( 'showlinkedto', $opts['showlinkedto'], array('id' => 'showlinkedto') ) . ' ' .
                        Xml::label( wfMsg("recentchangeslinked-to"), 'showlinkedto' ) );
@@ -180,19 +219,37 @@ class SpecialRecentchangeslinked extends SpecialRecentchanges {
                return $extraOpts;
        }
 
+       function getTargetTitle() {
+               if ( $this->rclTargetTitle === null ) {
+                       $opts = $this->getOptions();
+                       if ( isset( $opts['target'] ) && $opts['target'] !== '' ) {
+                               $this->rclTargetTitle = Title::newFromText( $opts['target'] );
+                       } else {
+                               $this->rclTargetTitle = false;
+                       }
+               }
+               return $this->rclTargetTitle;
+       }
+
        function setTopText( OutputPage $out, FormOptions $opts ) {
                global $wgUser;
                $skin = $wgUser->getSkin();
-               if( isset( $this->mTargetTitle ) && is_object( $this->mTargetTitle ) )
-                       $out->setSubtitle( wfMsg( 'recentchangeslinked-backlink', $skin->link( $this->mTargetTitle,
-                               $this->mTargetTitle->getPrefixedText(), array(), array( 'redirect' => 'no'  ) ) ) );
+               $target = $this->getTargetTitle();
+               if( $target )
+                       $out->setSubtitle( wfMsg( 'recentchangeslinked-backlink', $skin->link( $target,
+                               $target->getPrefixedText(), array(), array( 'redirect' => 'no'  ) ) ) );
        }
 
-       function setBottomText( OutputPage $out, FormOptions $opts ){
-               if( isset( $this->mTargetTitle ) && is_object( $this->mTargetTitle ) ){
-                       global $wgUser;
-                       $out->setFeedAppendQuery( "target=" . urlencode( $this->mTargetTitle->getPrefixedDBkey() ) );
+       public function getFeedQuery() {
+               $target = $this->getTargetTitle();
+               if( $target ) {
+                       return "target=" . urlencode( $target->getPrefixedDBkey() );
+               } else {
+                       return false;
                }
+       }
+
+       function setBottomText( OutputPage $out, FormOptions $opts ) {
                if( isset( $this->mResultEmpty ) && $this->mResultEmpty ){
                        $out->addWikiMsg( 'recentchangeslinked-noresult' );     
                }