some useless calls / unitialized $matches arrays
[lhc/web/wiklou.git] / includes / SpecialWatchlist.php
index d254b33..4ab7c21 100644 (file)
@@ -15,14 +15,14 @@ require_once( 'WatchedItem.php' );
  * constructor
  */
 function wfSpecialWatchlist( $par ) {
-       global $wgUser, $wgOut, $wgLang, $wgTitle, $wgMemc, $wgRequest, $wgContLang;
+       global $wgUser, $wgOut, $wgLang, $wgMemc, $wgRequest, $wgContLang;
        global $wgUseWatchlistCache, $wgWLCacheTimeout, $wgDBname;
        global $wgRCShowWatchingUsers, $wgEnotifWatchlist, $wgShowUpdatedMarker;
-       global $wgEnotifWatchlist;
+       global $wgEnotifWatchlist, $wgFilterRobotsWL;
        $fname = 'wfSpecialWatchlist';
 
        $wgOut->setPagetitle( wfMsg( 'watchlist' ) );
-       $sub = wfMsg( 'watchlistsub', $wgUser->getName() );
+       $sub = htmlspecialchars( wfMsg( 'watchlistsub', $wgUser->getName() ) );
        $wgOut->setSubtitle( $sub );
        $wgOut->setRobotpolicy( 'noindex,nofollow' );
 
@@ -36,6 +36,7 @@ function wfSpecialWatchlist( $par ) {
        $defaults = array(
        /* float */ 'days' => 3.0, /* or 0.5, watch further below */
        /* bool  */ 'hideOwn' => false,
+       /* bool  */ 'hideBots' => false,
        );
 
        extract($defaults);
@@ -43,6 +44,7 @@ function wfSpecialWatchlist( $par ) {
        # Get query variables
        $days = $wgRequest->getVal( 'days' );
        $hideOwn = $wgRequest->getBool( 'hideOwn' );
+       $hideBots = $wgRequest->getBool( 'hideBots' );
 
        # Watchlist editing
        $action = $wgRequest->getVal( 'action' );
@@ -87,14 +89,14 @@ function wfSpecialWatchlist( $par ) {
        $dbr =& wfGetDB( DB_SLAVE );
        extract( $dbr->tableNames( 'page', 'revision', 'watchlist', 'recentchanges' ) );
 
-       $sql = "SELECT COUNT(*) AS n FROM $watchlist WHERE wl_user=$uid";
-       $res = $dbr->query( $sql, $fname );
-       $s = $dbr->fetchObject( $res );
+                       $sql = "SELECT COUNT(*) AS n FROM $watchlist WHERE wl_user=$uid";
+               $res = $dbr->query( $sql, $fname );
+               $s = $dbr->fetchObject( $res );
 
-#      Patch *** A1 *** (see A2 below)
+        #      Patch *** A1 *** (see A2 below)
 #      adjust for page X, talk:page X, which are both stored separately, but treated together
-#      $nitems = $s->n / 2;
-       $nitems = $s->n;
+       $nitems = floor($s->n / 2);
+#      $nitems = $s->n;
 
        if($nitems == 0) {
                $wgOut->addWikiText( wfMsg( 'nowatchlist' ) );
@@ -118,6 +120,7 @@ function wfSpecialWatchlist( $par ) {
 
        wfAppendToArrayIfNotDefault( 'days', $days, $defaults, $nondefaults);
        wfAppendToArrayIfNotDefault( 'hideOwn', $hideOwn, $defaults, $nondefaults);
+       wfAppendToArrayIfNotDefault( 'hideBots', $hideBots, $defaults, $nondefaults);
 
        if ( $days <= 0 ) {
                $docutoff = '';
@@ -127,10 +130,13 @@ function wfSpecialWatchlist( $par ) {
                $docutoff = "AND rev_timestamp > '" .
                  ( $cutoff = $dbr->timestamp( time() - intval( $days * 86400 ) ) )
                  . "'";
-               $sql = "SELECT COUNT(*) AS n FROM $page, $revision  WHERE rev_timestamp>'$cutoff' AND page_id=rev_page";
-               $res = $dbr->query( $sql, $fname );
-               $s = $dbr->fetchObject( $res );
-               $npages = $s->n;
+                  /* 
+                  $sql = "SELECT COUNT(*) AS n FROM $page, $revision  WHERE rev_timestamp>'$cutoff' AND page_id=rev_page";
+                  $res = $dbr->query( $sql, $fname );
+                  $s = $dbr->fetchObject( $res );
+                  $npages = $s->n;
+                  */
+                  $npages = 40000 * $days;
 
        }
 
@@ -197,24 +203,15 @@ function wfSpecialWatchlist( $par ) {
        # through the time-sorted page list checking for watched items.
 
        # Up estimate of watched items by 15% to compensate for talk pages...
-       if( $cutoff && ( $nitems*1.15 > $npages ) ) {
-               $x = 'rev_timestamp';
-               $y = wfMsg( 'watchmethod-recent' );
-               # TG patch: here we do not consider pages and their talk pages equivalent - why should we ?
-               # The change results in talk-pages not automatically included in watchlists, when their parent page is included
-               # $z = "wl_namespace=cur_namespace & ~1";
-               $z = 'wl_namespace=page_namespace';
+
+       $andHideOwn = $hideOwn ? "AND (rc_user <> $uid)" : '';
+       if( $wgFilterRobotsWL ) {
+               $andHideBotsOptional = $hideBots ? "AND (rc_bot = 0)" : '';
        } else {
-               $x = 'page_timestamp';
-               $y = wfMsg( 'watchmethod-list' );
-               # TG patch: here we do not consider pages and their talk pages equivalent - why should we ?
-               # The change results in talk-pages not automatically included in watchlists, when their parent page is included
-               # $z = "(wl_namespace=cur_namespace OR wl_namespace+1=cur_namespace)";
-               $z = 'wl_namespace=page_namespace';
+               $andHideBotsOptional = "AND rc_this_oldid=page_latest";
        }
-
-       $andHideOwn = $hideOwn ? "AND (rev_user <> $uid)" : '';
-
+               
+       
        # Show watchlist header
        $header = '';
        if( $wgUser->getOption( 'enotifwatchlistpages' ) && $wgEnotifWatchlist) {
@@ -224,8 +221,9 @@ function wfSpecialWatchlist( $par ) {
                $header .= wfMsg( 'wlheader-showupdated' ) . "\n";
        }
 
-       $header .= wfMsg( 'watchdetails', $wgLang->formatNum( $nitems / 2 ),
-               $wgLang->formatNum( $npages ), $y,
+       # TODO: Consider removing the third parameter
+       $header .= wfMsg( 'watchdetails', $wgLang->formatNum( $nitems ), 
+               $wgLang->formatNum( $npages ), '',
                $specialTitle->getFullUrl( 'edit=yes' ) );
        $wgOut->addWikiText( $header );
        
@@ -238,19 +236,23 @@ function wfSpecialWatchlist( $par ) {
                        "\n\n" );
        }
 
-       $use_index = $dbr->useIndexClause( $x );
-       $sql = "SELECT
-  page_namespace,page_title,rev_comment, page_id,
-  rev_user,rev_user_text,rev_timestamp,rev_minor_edit,rev_id,page_is_new,wl_notificationtimestamp
-  FROM $watchlist,$page,$revision  $use_index
-  WHERE wl_user=$uid
-  $andHideOwn
-  AND $z
-  AND wl_title=page_title
-  AND page_latest=rev_id
-  $docutoff
-  ORDER BY rev_timestamp DESC";
-
+        $sql = "SELECT
+          rc_namespace page_namespace,rc_title page_title,
+          rc_comment rev_comment, rc_cur_id page_id,
+          rc_user rev_user,rc_user_text rev_user_text,
+          rc_timestamp rev_timestamp,rc_minor rev_minor_edit,
+          rc_this_oldid rev_id,
+          rc_last_oldid,
+          rc_new page_is_new,wl_notificationtimestamp
+          FROM $watchlist,$recentchanges,$page
+          WHERE wl_user=$uid
+          AND wl_namespace=rc_namespace
+          AND wl_title=rc_title
+          AND rc_timestamp > '$cutoff'
+          AND rc_cur_id=page_id
+          $andHideOwn
+          $andHideBotsOptional
+          ORDER BY rc_timestamp DESC";
 
        $res = $dbr->query( $sql, $fname );
        $numRows = $dbr->numRows( $res );
@@ -272,8 +274,15 @@ function wfSpecialWatchlist( $par ) {
                $wgContLang->specialPage( 'Watchlist' ),
                (0 == $hideOwn) ? wfMsgHtml( 'wlhide' ) : wfMsgHtml( 'wlshow' ),
                wfArrayToCGI( array('hideOwn' => 1-$hideOwn ), $nondefaults ) );
-
        $wgOut->addHTML( wfMsgHtml( "wlhideshowown", $s ) );
+
+       if( $wgFilterRobotsWL ) {
+               $s = $sk->makeKnownLink(
+      $wgContLang->specialPage( 'Watchlist' ),
+                 (0 == $hideBots) ? wfMsgHtml( 'wlhide' ) : wfMsgHtml( 'wlshow' ),
+                 wfArrayToCGI( array('hideBots' => 1-$hideBots ), $nondefaults ) );
+         $wgOut->addHTML( wfMsgHtml( "wlhideshowbots", "  $s" ) );
+       }
        
        if ( $numRows == 0 ) {
                $wgOut->addWikitext( "<br />" . wfMsg( 'watchnochange' ), false );
@@ -284,13 +293,13 @@ function wfSpecialWatchlist( $par ) {
        $wgOut->addHTML( "</p>\n" );
        /* End bottom header */
 
-       $sk = $wgUser->getSkin();
-       $list =& new ChangesList( $sk );
+       $list = ChangesList::newFromUser( $wgUser );
+
        $s = $list->beginRecentChangesList();
        $counter = 1;
        while ( $obj = $dbr->fetchObject( $res ) ) {
                # Make fake RC entry
-               $rc = RecentChange::newFromCurRow( $obj );
+               $rc = RecentChange::newFromCurRow( $obj, $obj->rc_last_oldid );
                $rc->counter = $counter++;
 
                if ( $wgShowUpdatedMarker ) {