Update to r32375 / bug 11874 -- !important may have whitespace between ! and important
[lhc/web/wiklou.git] / includes / SpecialRecentchanges.php
index 0c05104..5553c18 100644 (file)
@@ -1,22 +1,19 @@
 <?php
 /**
  *
- * @package MediaWiki
- * @subpackage SpecialPage
+ * @addtogroup SpecialPage
  */
 
 /**
  *
  */
-require_once( 'Feed.php' );
-require_once( 'ChangesList.php' );
-require_once( 'Revision.php' );
+require_once( dirname(__FILE__) . '/ChangesList.php' );
 
 /**
  * Constructor
  */
 function wfSpecialRecentchanges( $par, $specialPage ) {
-       global $wgUser, $wgOut, $wgRequest, $wgUseRCPatrol, $wgDBtype;
+       global $wgUser, $wgOut, $wgRequest, $wgUseRCPatrol;
        global $wgRCShowWatchingUsers, $wgShowUpdatedMarker;
        global $wgAllowCategorizedRecentChanges ;
        $fname = 'wfSpecialRecentchanges';
@@ -24,7 +21,7 @@ function wfSpecialRecentchanges( $par, $specialPage ) {
        # Get query parameters
        $feedFormat = $wgRequest->getVal( 'feed' );
 
-       /* Checkbox values can't be true be default, because
+       /* Checkbox values can't be true by default, because
         * we cannot differentiate between unset and not set at all
         */
        $defaults = array(
@@ -45,12 +42,10 @@ function wfSpecialRecentchanges( $par, $specialPage ) {
        extract($defaults);
 
 
-       $days = $wgUser->getOption( 'rcdays' );
-       if ( !$days ) { $days = $defaults['days']; }
+       $days = $wgUser->getOption( 'rcdays', $defaults['days']);
        $days = $wgRequest->getInt( 'days', $days );
 
-       $limit = $wgUser->getOption( 'rclimit' );
-       if ( !$limit ) { $limit = $defaults['limit']; }
+       $limit = $wgUser->getOption( 'rclimit', $defaults['limit'] );
 
        #       list( $limit, $offset ) = wfCheckLimits( 100, 'rclimit' );
        $limit = $wgRequest->getInt( 'limit', $limit );
@@ -62,7 +57,7 @@ function wfSpecialRecentchanges( $par, $specialPage ) {
        if( $feedFormat ) {
                global $wgFeedLimit;
                if( $limit > $wgFeedLimit ) {
-                       $options['limit'] = $wgFeedLimit;
+                       $limit = $wgFeedLimit;
                }
 
        } else {
@@ -92,7 +87,8 @@ function wfSpecialRecentchanges( $par, $specialPage ) {
                                if ( is_numeric( $bit ) ) {
                                        $limit = $bit;
                                }
-
+                               
+                               $m = array();
                                if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) {
                                        $limit = $m[1];
                                }
@@ -108,8 +104,8 @@ function wfSpecialRecentchanges( $par, $specialPage ) {
 
 
        # Database connection and caching
-       $dbr =& wfGetDB( DB_SLAVE );
-       extract( $dbr->tableNames( 'recentchanges', 'watchlist' ) );
+       $dbr = wfGetDB( DB_SLAVE );
+       list( $recentchanges, $watchlist ) = $dbr->tableNamesN( 'recentchanges', 'watchlist' );
 
 
        $cutoff_unixtime = time() - ( $days * 86400 );
@@ -176,13 +172,9 @@ function wfSpecialRecentchanges( $par, $specialPage ) {
        while( $row = $dbr->fetchObject( $res ) ){
                $rows[] = $row;
                if ( !$feedFormat ) {
-                       // User page link
-                       $title = Title::makeTitleSafe( NS_USER, $row->rc_user_text );
-                       $batch->addObj( $title );
-
-                       // User talk
-                       $title = Title::makeTitleSafe( NS_USER_TALK, $row->rc_user_text );
-                       $batch->addObj( $title );
+                       // User page and talk links
+                       $batch->add( NS_USER, $row->rc_user_text  );
+                       $batch->add( NS_USER_TALK, $row->rc_user_text  );
                }
 
        }
@@ -200,7 +192,7 @@ function wfSpecialRecentchanges( $par, $specialPage ) {
 
                // Output header
                if ( !$specialPage->including() ) {
-                       $wgOut->addWikiText( wfMsgForContent( "recentchangestext" ) );
+                       $wgOut->addWikiText( wfMsgForContentNoTrans( "recentchangestext" ) );
 
                        // Dump everything here
                        $nondefaults = array();
@@ -224,9 +216,8 @@ function wfSpecialRecentchanges( $par, $specialPage ) {
                }
 
                // And now for the content
-               $sk = $wgUser->getSkin();
                $wgOut->setSyndicated( true );
-
+               
                $list = ChangesList::newFromUser( $wgUser );
                
                if ( $wgAllowCategorizedRecentChanges ) {
@@ -238,6 +229,10 @@ function wfSpecialRecentchanges( $par, $specialPage ) {
 
                $s = $list->beginRecentChangesList();
                $counter = 1;
+
+               $showWatcherCount = $wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' );
+               $watcherCache = array();
+
                foreach( $rows as $obj ){
                        if( $limit == 0) {
                                break;
@@ -256,13 +251,19 @@ function wfSpecialRecentchanges( $par, $specialPage ) {
                                        $rc->notificationtimestamp = false;
                                }
 
-                               if ($wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
-                                       $sql3 = "SELECT COUNT(*) AS n FROM $watchlist WHERE wl_title='" . $dbr->strencode($obj->rc_title) ."' AND wl_namespace=$obj->rc_namespace" ;
-                                       $res3 = $dbr->query( $sql3, 'wfSpecialRecentChanges');
-                                       $x = $dbr->fetchObject( $res3 );
-                                       $rc->numberofWatchingusers = $x->n;
-                               } else {
-                                       $rc->numberofWatchingusers = 0;
+                               $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->recentChangesLine( $rc, !empty( $obj->wl_user ) );
                                --$limit;
@@ -274,7 +275,9 @@ function wfSpecialRecentchanges( $par, $specialPage ) {
 }
 
 function rcFilterByCategories ( &$rows , $categories , $any ) {
-       require_once ( 'Categoryfinder.php' ) ;
+       if( empty( $categories ) ) {
+               return;
+       }
        
        # Filter categories
        $cats = array () ;
@@ -288,7 +291,7 @@ function rcFilterByCategories ( &$rows , $categories , $any ) {
        $articles = array () ;
        $a2r = array () ;
        foreach ( $rows AS $k => $r ) {
-               $nt = Title::newFromText ( $r->rc_title , $r->rc_namespace ) ;
+               $nt = Title::makeTitle( $r->rc_title , $r->rc_namespace );
                $id = $nt->getArticleID() ;
                if ( $id == 0 ) continue ; # Page might have been deleted...
                if ( !in_array ( $id , $articles ) ) {
@@ -321,24 +324,39 @@ function rcFilterByCategories ( &$rows , $categories , $any ) {
 }
 
 function rcOutputFeed( $rows, $feedFormat, $limit, $hideminor, $lastmod ) {
-       global $messageMemc, $wgDBname, $wgFeedCacheTimeout;
+       global $messageMemc, $wgFeedCacheTimeout;
        global $wgFeedClasses, $wgTitle, $wgSitename, $wgContLanguageCode;
+       global $wgFeed;
+       
+       if ( !$wgFeed ) {
+               global $wgOut;
+               $wgOut->addWikiMsg( 'feed-unavailable' );
+               return;
+       }
 
        if( !isset( $wgFeedClasses[$feedFormat] ) ) {
                wfHttpError( 500, "Internal Server Error", "Unsupported feed type." );
                return false;
        }
 
-       $timekey = "$wgDBname:rcfeed:$feedFormat:timestamp";
-       $key = "$wgDBname:rcfeed:$feedFormat:limit:$limit:minor:$hideminor";
+       $timekey = wfMemcKey( 'rcfeed', $feedFormat, 'timestamp' );
+       $key = wfMemcKey( 'rcfeed', $feedFormat, 'limit', $limit, 'minor', $hideminor );
 
        $feedTitle = $wgSitename . ' - ' . wfMsgForContent( 'recentchanges' ) .
                ' [' . $wgContLanguageCode . ']';
        $feed = new $wgFeedClasses[$feedFormat](
                $feedTitle,
-               htmlspecialchars( wfMsgForContent( 'recentchangestext' ) ),
+               htmlspecialchars( wfMsgForContent( 'recentchanges-feed-description' ) ),
                $wgTitle->getFullUrl() );
 
+       //purge cache if requested
+       global $wgRequest, $wgUser;
+       $purge = $wgRequest->getVal( 'action' ) == 'purge';
+       if ( $purge && $wgUser->isAllowed('purge') ) {
+               $messageMemc->delete( $timekey );
+               $messageMemc->delete( $key );
+       }
+
        /**
         * Bumping around loading up diffs can be pretty slow, so where
         * possible we want to cache the feed output so the next visitor
@@ -380,9 +398,12 @@ function rcOutputFeed( $rows, $feedFormat, $limit, $hideminor, $lastmod ) {
        return true;
 }
 
+/**
+ * @todo document
+ * @param $rows Database resource with recentchanges rows
+ */
 function rcDoOutputFeed( $rows, &$feed ) {
-       $fname = 'rcDoOutputFeed';
-       wfProfileIn( $fname );
+       wfProfileIn( __METHOD__ );
 
        $feed->outHeader();
 
@@ -399,7 +420,6 @@ function rcDoOutputFeed( $rows, &$feed ) {
                        $sorted[$n] = $obj;
                        $n++;
                }
-               $first = false;
        }
 
        foreach( $sorted as $obj ) {
@@ -408,15 +428,15 @@ function rcDoOutputFeed( $rows, &$feed ) {
                $item = new FeedItem(
                        $title->getPrefixedText(),
                        rcFormatDiff( $obj ),
-                       $title->getFullURL(),
+                       $title->getFullURL( 'diff=' . $obj->rc_this_oldid . '&oldid=prev' ),
                        $obj->rc_timestamp,
-                       $obj->rc_user_text,
+                       ($obj->rc_deleted & Revision::DELETED_USER) ? wfMsgHtml('rev-deleted-user') : $obj->rc_user_text,
                        $talkpage->getFullURL()
                        );
                $feed->outItem( $item );
        }
        $feed->outFooter();
-       wfProfileOut( $fname );
+       wfProfileOut( __METHOD__ );
 }
 
 /**
@@ -475,7 +495,7 @@ function rcDayLimitLinks( $days, $limit, $page='Recentchanges', $more='', $doall
 
 /**
  * Makes change an option link which carries all the other options
- * @param $title @see Title
+ * @param $title see Title
  * @param $override
  * @param $options
  */
@@ -483,7 +503,7 @@ function makeOptionsLink( $title, $override, $options ) {
        global $wgUser, $wgContLang;
        $sk = $wgUser->getSkin();
        return $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchanges' ),
-               $title, wfArrayToCGI( $override, $options ) );
+               htmlspecialchars( $title ), wfArrayToCGI( $override, $options ) );
 }
 
 /**
@@ -573,7 +593,7 @@ function rcOptionsPanel( $defaults, $nondefaults ) {
  */
 function rcNamespaceForm( $namespace, $invert, $nondefaults, $categories_any ) {
        global $wgScript, $wgAllowCategorizedRecentChanges, $wgRequest;
-       $t = Title::makeTitle( NS_SPECIAL, 'Recentchanges' );
+       $t = SpecialPage::getTitleFor( 'Recentchanges' );
 
        $namespaceselect = HTMLnamespaceselector($namespace, '');
        $submitbutton = '<input type="submit" value="' . wfMsgHtml( 'allpagessubmit' ) . "\" />\n";
@@ -583,7 +603,7 @@ function rcNamespaceForm( $namespace, $invert, $nondefaults, $categories_any ) {
                $categories = trim ( $wgRequest->getVal ( 'categories' , "" ) ) ;
                $cb_arr = array( 'type' => 'checkbox', 'name' => 'categories_any', 'value' => "1" ) ;
                if ( $categories_any ) $cb_arr['checked'] = "checked" ;
-               $catbox = "<br/>" ;
+               $catbox = "<br />" ;
                $catbox .= wfMsgExt('rc_categories', array('parseinline')) . " ";
                $catbox .= wfElement('input', array( 'type' => 'text', 'name' => 'categories', 'value' => $categories));
                $catbox .= " &nbsp;" ;
@@ -614,27 +634,63 @@ function rcNamespaceForm( $namespace, $invert, $nondefaults, $categories_any ) {
  * Format a diff for the newsfeed
  */
 function rcFormatDiff( $row ) {
-       global $wgFeedDiffCutoff, $wgContLang;
+       global $wgUser;
+
+       $titleObj = Title::makeTitle( $row->rc_namespace, $row->rc_title );
+       $timestamp = wfTimestamp( TS_MW, $row->rc_timestamp );
+       $actiontext = '';
+       if( $row->rc_type == RC_LOG ) {
+               if( $row->rc_deleted & LogPage::DELETED_ACTION ) {
+                       $actiontext = wfMsgHtml('rev-deleted-event');
+               } else {
+                       $actiontext = LogPage::actionText( $row->rc_log_type, $row->rc_log_action, 
+                               $titleObj, $wgUser->getSkin(), LogPage::extractParams($row->rc_params,true,true) );
+               }
+       }
+       return rcFormatDiffRow( $titleObj,
+               $row->rc_last_oldid, $row->rc_this_oldid,
+               $timestamp,
+               ($row->rc_deleted & Revision::DELETED_COMMENT) ? wfMsgHtml('rev-deleted-comment') : $row->rc_comment,
+               $actiontext );
+}
+
+function rcFormatDiffRow( $title, $oldid, $newid, $timestamp, $comment, $actiontext='' ) {
+       global $wgFeedDiffCutoff, $wgContLang, $wgUser;
        $fname = 'rcFormatDiff';
        wfProfileIn( $fname );
 
-       require_once( 'DifferenceEngine.php' );
-       $completeText = '<p>' . htmlspecialchars( $row->rc_comment ) . "</p>\n";
+       $skin = $wgUser->getSkin();
+       # log enties
+       if( $actiontext ) {
+               $comment = "$actiontext $comment";
+       }
+       $completeText = '<p>' . $skin->formatComment( $comment ) . "</p>\n";
+
+       //NOTE: Check permissions for anonymous users, not current user.
+       //      No "privileged" version should end up in the cache.
+       //      Most feed readers will not log in anway.
+       $anon = new User();
+       $accErrors = $title->getUserPermissionsErrors( 'read', $anon, true );
 
-       if( $row->rc_namespace >= 0 ) {
-               if( $row->rc_last_oldid ) {
+       if( $title->getNamespace() >= 0 && !$accErrors ) {
+               if( $oldid ) {
                        wfProfileIn( "$fname-dodiff" );
 
-                       $titleObj = Title::makeTitle( $row->rc_namespace, $row->rc_title );
-                       $de = new DifferenceEngine( $titleObj, $row->rc_last_oldid, $row->rc_this_oldid );
-                       $diffText = $de->getDiff( wfMsg( 'revisionasof', $wgContLang->timeanddate( $row->rc_timestamp ) ),
-                               wfMsg( 'currentrev' ) );
+                       $de = new DifferenceEngine( $title, $oldid, $newid );
+                       #$diffText = $de->getDiff( wfMsg( 'revisionasof',
+                       #       $wgContLang->timeanddate( $timestamp ) ),
+                       #       wfMsg( 'currentrev' ) );
+                       $diffText = $de->getDiff(
+                               wfMsg( 'previousrevision' ), // hack
+                               wfMsg( 'revisionasof',
+                                       $wgContLang->timeanddate( $timestamp ) ) );
+                               
 
                        if ( strlen( $diffText ) > $wgFeedDiffCutoff ) {
                                // Omit large diffs
-                               $diffLink = $titleObj->escapeFullUrl(
-                                       'diff=' . $row->rc_this_oldid .
-                                       '&oldid=' . $row->rc_last_oldid );
+                               $diffLink = $title->escapeFullUrl(
+                                       'diff=' . $newid .
+                                       '&oldid=' . $oldid );
                                $diffText = '<a href="' .
                                        $diffLink .
                                        '">' .
@@ -642,7 +698,7 @@ function rcFormatDiff( $row ) {
                                        '</a>';
                        } elseif ( $diffText === false ) {
                                // Error in diff engine, probably a missing revision
-                               $diffText = "<p>Can't load revision $row->rc_this_oldid</p>";
+                               $diffText = "<p>Can't load revision $newid</p>";
                        } else {
                                // Diff output fine, clean up any illegal UTF-8
                                $diffText = UtfNormal::cleanUp( $diffText );
@@ -650,7 +706,7 @@ function rcFormatDiff( $row ) {
                        }
                        wfProfileOut( "$fname-dodiff" );
                } else {
-                       $rev = Revision::newFromId( $row->rc_this_oldid );
+                       $rev = Revision::newFromId( $newid );
                        if( is_null( $rev ) ) {
                                $newtext = '';
                        } else {
@@ -677,13 +733,13 @@ function rcFormatDiff( $row ) {
  */
 function rcApplyDiffStyle( $text ) {
        $styles = array(
-               'diff'             => 'background-color: white;',
-               'diff-otitle'      => 'background-color: white;',
-               'diff-ntitle'      => 'background-color: white;',
-               'diff-addedline'   => 'background: #cfc; font-size: smaller;',
-               'diff-deletedline' => 'background: #ffa; font-size: smaller;',
-               'diff-context'     => 'background: #eee; font-size: smaller;',
-               'diffchange'       => 'color: red; font-weight: bold;',
+               'diff'             => 'background-color: white; color:black;',
+               'diff-otitle'      => 'background-color: white; color:black;',
+               'diff-ntitle'      => 'background-color: white; color:black;',
+               'diff-addedline'   => 'background: #cfc; color:black; font-size: smaller;',
+               'diff-deletedline' => 'background: #ffa; color:black; font-size: smaller;',
+               'diff-context'     => 'background: #eee; color:black; font-size: smaller;',
+               'diffchange'       => 'color: red; font-weight: bold; text-decoration: none;',
        );
        
        foreach( $styles as $class => $style ) {
@@ -694,4 +750,4 @@ function rcApplyDiffStyle( $text ) {
        return $text;
 }
 
-?>
+