(bug 8701) Check database lock status when blocking/unblocking users
[lhc/web/wiklou.git] / includes / SpecialRecentchanges.php
index 5f5c81b..3b8d69f 100644 (file)
@@ -8,9 +8,7 @@
 /**
  *
  */
-require_once( 'Feed.php' );
 require_once( 'ChangesList.php' );
-require_once( 'Revision.php' );
 
 /**
  * Constructor
@@ -32,6 +30,7 @@ function wfSpecialRecentchanges( $par, $specialPage ) {
        /* int  */ 'limit' => $wgUser->getDefaultOption('rclimit'),
        /* bool */ 'hideminor' => false,
        /* bool */ 'hidebots' => true,
+       /* bool */ 'hideanons' => false,
        /* bool */ 'hideliu' => false,
        /* bool */ 'hidepatrolled' => false,
        /* bool */ 'hidemyself' => false,
@@ -44,12 +43,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 );
@@ -69,6 +66,7 @@ function wfSpecialRecentchanges( $par, $specialPage ) {
                $namespace = $wgRequest->getIntOrNull( 'namespace' );
                $invert = $wgRequest->getBool( 'invert', $defaults['invert'] );
                $hidebots = $wgRequest->getBool( 'hidebots', $defaults['hidebots'] );
+               $hideanons = $wgRequest->getBool( 'hideanons', $defaults['hideanons'] );
                $hideliu = $wgRequest->getBool( 'hideliu', $defaults['hideliu'] );
                $hidepatrolled = $wgRequest->getBool( 'hidepatrolled', $defaults['hidepatrolled'] );
                $hidemyself = $wgRequest->getBool ( 'hidemyself', $defaults['hidemyself'] );
@@ -84,12 +82,14 @@ function wfSpecialRecentchanges( $par, $specialPage ) {
                                if ( 'minor' == $bit ) $hideminor = 0;
                                if ( 'hideliu' == $bit ) $hideliu = 1;
                                if ( 'hidepatrolled' == $bit ) $hidepatrolled = 1;
+                               if ( 'hideanons' == $bit ) $hideanons = 1;
                                if ( 'hidemyself' == $bit ) $hidemyself = 1;
 
                                if ( is_numeric( $bit ) ) {
                                        $limit = $bit;
                                }
-
+                               
+                               $m = array();
                                if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) {
                                        $limit = $m[1];
                                }
@@ -106,7 +106,7 @@ function wfSpecialRecentchanges( $par, $specialPage ) {
 
        # Database connection and caching
        $dbr =& wfGetDB( DB_SLAVE );
-       extract( $dbr->tableNames( 'recentchanges', 'watchlist' ) );
+       list( $recentchanges, $watchlist ) = $dbr->tableNamesN( 'recentchanges', 'watchlist' );
 
 
        $cutoff_unixtime = time() - ( $days * 86400 );
@@ -131,17 +131,27 @@ function wfSpecialRecentchanges( $par, $specialPage ) {
                }
        }
 
-       $hidem  = $hideminor ? 'AND rc_minor=0' : '';
-       $hidem .= $hidebots ? ' AND rc_bot=0' : '';
-       $hidem .= ( $hideliu && !$hidemyself ) ? ' AND rc_user=0' : '';
-       $hidem .= $hidepatrolled ? ' AND rc_patrolled=0' : '';
-       if ( $hidemyself ) {
-               if ( $wgUser->getID() ) {
-                       $hidem .= ' AND rc_user <> '.$wgUser->getID();
+       # It makes no sense to hide both anons and logged-in users
+       # Where this occurs, force anons to be shown
+       if( $hideanons && $hideliu )
+               $hideanons = false;
+
+       # Form WHERE fragments for all the options
+       $hidem  = $hideminor ? 'AND rc_minor = 0' : '';
+       $hidem .= $hidebots ? ' AND rc_bot = 0' : '';
+       $hidem .= $hideliu ? ' AND rc_user = 0' : '';
+       $hidem .= ( $wgUseRCPatrol && $hidepatrolled ) ? ' AND rc_patrolled = 0' : '';
+       $hidem .= $hideanons ? ' AND rc_user != 0' : '';
+       
+       if( $hidemyself ) {
+               if( $wgUser->getID() ) {
+                       $hidem .= ' AND rc_user != ' . $wgUser->getID();
                } else {
-                       $hidem .= ' AND rc_user_text<>' . $dbr->addQuotes( $wgUser->getName() );
+                       $hidem .= ' AND rc_user_text != ' . $dbr->addQuotes( $wgUser->getName() );
                }
        }
+
+       # Namespace filtering
        $hidem .= is_null( $namespace ) ?  '' : ' AND rc_namespace' . ($invert ? '!=' : '=') . $namespace;
 
        // This is the big thing!
@@ -149,7 +159,8 @@ function wfSpecialRecentchanges( $par, $specialPage ) {
        $uid = $wgUser->getID();
 
        // Perform query
-       $sql2 = "SELECT * FROM $recentchanges FORCE INDEX (rc_timestamp) " .
+       $forceclause = $dbr->useIndexClause("rc_timestamp");
+       $sql2 = "SELECT * FROM $recentchanges $forceclause".
          ($uid ? "LEFT OUTER JOIN $watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace " : "") .
          "WHERE rc_timestamp >= '{$cutoff}' {$hidem} " .
          "ORDER BY rc_timestamp DESC";
@@ -186,7 +197,7 @@ function wfSpecialRecentchanges( $par, $specialPage ) {
 
                // Output header
                if ( !$specialPage->including() ) {
-                       $wgOut->addWikiText( wfMsgForContent( "recentchangestext" ) );
+                       $wgOut->addWikiText( wfMsgForContentNoTrans( "recentchangestext" ) );
 
                        // Dump everything here
                        $nondefaults = array();
@@ -195,6 +206,7 @@ function wfSpecialRecentchanges( $par, $specialPage ) {
                        wfAppendToArrayIfNotDefault( 'limit', $limit , $defaults, $nondefaults);
                        wfAppendToArrayIfNotDefault( 'hideminor', $hideminor, $defaults, $nondefaults);
                        wfAppendToArrayIfNotDefault( 'hidebots', $hidebots, $defaults, $nondefaults);
+                       wfAppendToArrayIfNotDefault( 'hideanons', $hideanons, $defaults, $nondefaults );
                        wfAppendToArrayIfNotDefault( 'hideliu', $hideliu, $defaults, $nondefaults);
                        wfAppendToArrayIfNotDefault( 'hidepatrolled', $hidepatrolled, $defaults, $nondefaults);
                        wfAppendToArrayIfNotDefault( 'hidemyself', $hidemyself, $defaults, $nondefaults);
@@ -209,7 +221,6 @@ function wfSpecialRecentchanges( $par, $specialPage ) {
                }
 
                // And now for the content
-               $sk = $wgUser->getSkin();
                $wgOut->setSyndicated( true );
 
                $list = ChangesList::newFromUser( $wgUser );
@@ -306,7 +317,7 @@ function rcFilterByCategories ( &$rows , $categories , $any ) {
 }
 
 function rcOutputFeed( $rows, $feedFormat, $limit, $hideminor, $lastmod ) {
-       global $messageMemc, $wgDBname, $wgFeedCacheTimeout;
+       global $messageMemc, $wgFeedCacheTimeout;
        global $wgFeedClasses, $wgTitle, $wgSitename, $wgContLanguageCode;
 
        if( !isset( $wgFeedClasses[$feedFormat] ) ) {
@@ -314,14 +325,14 @@ function rcOutputFeed( $rows, $feedFormat, $limit, $hideminor, $lastmod ) {
                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() );
 
        /**
@@ -384,7 +395,6 @@ function rcDoOutputFeed( $rows, &$feed ) {
                        $sorted[$n] = $obj;
                        $n++;
                }
-               $first = false;
        }
 
        foreach( $sorted as $obj ) {
@@ -445,7 +455,14 @@ function rcDayLimitLinks( $days, $limit, $page='Recentchanges', $more='', $doall
          rcDaysLink( $limit, 14, $page, $more  ) . ' | ' .
          rcDaysLink( $limit, 30, $page, $more  ) .
          ( $doall ? ( ' | ' . rcDaysLink( $limit, 0, $page, $more ) ) : '' );
-       $shm = wfMsg( 'showhideminor', $minorLink, $botLink, $liuLink, $patrLink, $myselfLink );
+       
+       $linkParts = array( 'minorLink' => 'minor', 'botLink' => 'bots', 'liuLink' => 'liu', 'patrLink' => 'patr', 'myselfLink' => 'mine' );
+       foreach( $linkParts as $linkVar => $linkMsg ) {
+               if( $$linkVar != '' )
+                       $links[] = wfMsgHtml( 'rcshowhide' . $linkMsg, $$linkVar );
+       }
+       
+       $shm = implode( ' | ', $links );
        $note = wfMsg( 'rclinks', $cl, $dl, $shm );
        return $note;
 }
@@ -453,46 +470,53 @@ function rcDayLimitLinks( $days, $limit, $page='Recentchanges', $more='', $doall
 
 /**
  * Makes change an option link which carries all the other options
+ * @param $title @see Title
+ * @param $override
+ * @param $options
  */
 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 ) );
 }
 
 /**
- * Creates the options panel
+ * Creates the options panel.
+ * @param $defaults
+ * @param $nondefaults
  */
 function rcOptionsPanel( $defaults, $nondefaults ) {
-       global $wgLang;
+       global $wgLang, $wgUseRCPatrol;
 
        $options = $nondefaults + $defaults;
 
        if( $options['from'] )
-               $note = wfMsg( 'rcnotefrom', $wgLang->formatNum( $options['limit'] ), $wgLang->timeanddate( $options['from'], true ) );
+               $note = wfMsgExt( 'rcnotefrom', array( 'parseinline' ),
+                       $wgLang->formatNum( $options['limit'] ),
+                       $wgLang->timeanddate( $options['from'], true ) );
        else
-               $note = wfMsg( 'rcnote', $wgLang->formatNum( $options['limit'] ), $wgLang->formatNum( $options['days'] ) );
+               $note = wfMsgExt( 'rcnote', array( 'parseinline' ),
+                       $wgLang->formatNum( $options['limit'] ),
+                       $wgLang->formatNum( $options['days'] ),
+                       $wgLang->timeAndDate( wfTimestampNow(), true ) );
 
        // limit links
-       $cl = '';
        $options_limit = array(50, 100, 250, 500);
-       $i = 0;
-       while ( $i+1 < count($options_limit) ) {
-               $cl .=  makeOptionsLink( $options_limit[$i], array( 'limit' => $options_limit[$i] ), $nondefaults) . ' | ' ;
-               $i++;
+       foreach( $options_limit as $value ) {
+               $cl[] = makeOptionsLink( $wgLang->formatNum( $value ),
+                       array( 'limit' => $value ), $nondefaults) ;
        }
-       $cl .=  makeOptionsLink( $options_limit[$i], array( 'limit' => $options_limit[$i] ), $nondefaults) ;
+       $cl = implode( ' | ', $cl);
 
        // day links, reset 'from' to none
-       $dl = '';
        $options_days = array(1, 3, 7, 14, 30);
-       $i = 0;
-       while ( $i+1 < count($options_days) ) {
-               $dl .=  makeOptionsLink( $options_days[$i], array( 'days' => $options_days[$i], 'from' => '' ), $nondefaults) . ' | ' ;
-               $i++;
+       foreach( $options_days as $value ) {
+               $dl[] = makeOptionsLink( $wgLang->formatNum( $value ),
+                       array( 'days' => $value, 'from' => ''  ), $nondefaults) ;
        }
-       $dl .=  makeOptionsLink( $options_days[$i], array( 'days' => $options_days[$i], 'from' => '' ), $nondefaults) ;
+       $dl = implode( ' | ', $dl);
+
 
        // show/hide links
        $showhide = array( wfMsg( 'show' ), wfMsg( 'hide' ));
@@ -500,40 +524,51 @@ function rcOptionsPanel( $defaults, $nondefaults ) {
                array( 'hideminor' => 1-$options['hideminor'] ), $nondefaults);
        $botLink = makeOptionsLink( $showhide[1-$options['hidebots']],
                array( 'hidebots' => 1-$options['hidebots'] ), $nondefaults);
+       $anonsLink = makeOptionsLink( $showhide[ 1 - $options['hideanons'] ],
+               array( 'hideanons' => 1 - $options['hideanons'] ), $nondefaults );
        $liuLink   = makeOptionsLink( $showhide[1-$options['hideliu']],
                array( 'hideliu' => 1-$options['hideliu'] ), $nondefaults);
        $patrLink  = makeOptionsLink( $showhide[1-$options['hidepatrolled']],
                array( 'hidepatrolled' => 1-$options['hidepatrolled'] ), $nondefaults);
        $myselfLink = makeOptionsLink( $showhide[1-$options['hidemyself']],
                array( 'hidemyself' => 1-$options['hidemyself'] ), $nondefaults);
-       $hl = wfMsg( 'showhideminor', $minorLink, $botLink, $liuLink, $patrLink, $myselfLink );
-       
+               
+       $links[] = wfMsgHtml( 'rcshowhideminor', $minorLink );
+       $links[] = wfMsgHtml( 'rcshowhidebots', $botLink );
+       $links[] = wfMsgHtml( 'rcshowhideanons', $anonsLink );
+       $links[] = wfMsgHtml( 'rcshowhideliu', $liuLink );
+       if( $wgUseRCPatrol )
+               $links[] = wfMsgHtml( 'rcshowhidepatr', $patrLink );
+       $links[] = wfMsgHtml( 'rcshowhidemine', $myselfLink );
+       $hl = implode( ' | ', $links );
+               
        // show from this onward link
        $now = $wgLang->timeanddate( wfTimestampNow(), true );
        $tl =  makeOptionsLink( $now, array( 'from' => wfTimestampNow()), $nondefaults );
 
-       $rclinks = wfMsg( 'rclinks', $cl, $dl, $hl );
-       $rclistfrom = wfMsg( 'rclistfrom', $tl );
+       $rclinks = wfMsgExt( 'rclinks', array( 'parseinline', 'replaceafter'),
+               $cl, $dl, $hl );
+       $rclistfrom = wfMsgExt( 'rclistfrom', array( 'parseinline', 'replaceafter'), $tl );
        return "$note<br />$rclinks<br />$rclistfrom";
 
 }
 
-/**<F2>
+/**
  * Creates the choose namespace selection
  *
- * @access private
+ * @private
  *
- * @param mixed $namespace The key of the currently selected namespace, empty string
+ * @param $namespace Mixed: the key of the currently selected namespace, empty string
  *              if there is none
- * @param bool $invert Whether to invert the namespace selection
- * @param array $nondefaults An array of non default options to be remembered
- * @param bool $categories_any Default value for the checkbox
+ * @param $invert Bool: whether to invert the namespace selection
+ * @param $nondefaults Array: an array of non default options to be remembered
+ * @param $categories_any Bool: Default value for the checkbox
  *
  * @return string
  */
 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";
@@ -543,12 +578,12 @@ 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 .= wfMsg('rc_categories') . " ";
+               $catbox = "<br />" ;
+               $catbox .= wfMsgExt('rc_categories', array('parseinline')) . " ";
                $catbox .= wfElement('input', array( 'type' => 'text', 'name' => 'categories', 'value' => $categories));
                $catbox .= " &nbsp;" ;
                $catbox .= wfElement('input', $cb_arr );
-               $catbox .= wfMsg('rc_categories_any');
+               $catbox .= wfMsgExt('rc_categories_any', array('parseinline'));
        } else {
                $catbox = "" ;
        }
@@ -574,27 +609,41 @@ function rcNamespaceForm( $namespace, $invert, $nondefaults, $categories_any ) {
  * Format a diff for the newsfeed
  */
 function rcFormatDiff( $row ) {
-       global $wgFeedDiffCutoff, $wgContLang;
+       $titleObj = Title::makeTitle( $row->rc_namespace, $row->rc_title );
+       $timestamp = wfTimestamp( TS_MW, $row->rc_timestamp );
+       return rcFormatDiffRow( $titleObj,
+               $row->rc_last_oldid, $row->rc_this_oldid,
+               $timestamp,
+               $row->rc_comment );
+}
+
+function rcFormatDiffRow( $title, $oldid, $newid, $timestamp, $comment ) {
+       global $wgFeedDiffCutoff, $wgContLang, $wgUser;
        $fname = 'rcFormatDiff';
        wfProfileIn( $fname );
 
-       require_once( 'DifferenceEngine.php' );
-       $completeText = '<p>' . htmlspecialchars( $row->rc_comment ) . "</p>\n";
+       $skin = $wgUser->getSkin();
+       $completeText = '<p>' . $skin->formatComment( $comment ) . "</p>\n";
 
-       if( $row->rc_namespace >= 0 ) {
-               if( $row->rc_last_oldid ) {
+       if( $title->getNamespace() >= 0 ) {
+               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 .
                                        '">' .
@@ -602,7 +651,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 );
@@ -610,7 +659,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 {
@@ -631,9 +680,9 @@ function rcFormatDiff( $row ) {
  * Might be 'cleaner' to use DOM or XSLT or something,
  * but *gack* it's a pain in the ass.
  *
- * @param string $text
+ * @param $text String:
  * @return string
- * @access private
+ * @private
  */
 function rcApplyDiffStyle( $text ) {
        $styles = array(