w/s diff. mostly eol w/s and using only tabs of width 4 to indent.
[lhc/web/wiklou.git] / includes / specials / SpecialWatchlist.php
index 9257c61..ecda239 100644 (file)
@@ -1,5 +1,22 @@
 <?php
 /**
+ * Implements Special:Watchlist
+ *
+ * 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 Watchlist
  */
 function wfSpecialWatchlist( $par ) {
        global $wgUser, $wgOut, $wgLang, $wgRequest;
        global $wgRCShowWatchingUsers, $wgEnotifWatchlist, $wgShowUpdatedMarker;
-       global $wgEnotifWatchlist;
-       $fname = 'wfSpecialWatchlist';
+
+       // Add feed links
+       $wlToken = $wgUser->getOption( 'watchlisttoken' );
+       if (!$wlToken) {
+               $wlToken = sha1( mt_rand() . microtime( true ) );
+               $wgUser->setOption( 'watchlisttoken', $wlToken );
+               $wgUser->saveSettings();
+       }
+
+       global $wgFeedClasses;
+       $apiParams = array( 'action' => 'feedwatchlist', 'allrev' => 'allrev',
+                                               'wlowner' => $wgUser->getName(), 'wltoken' => $wlToken );
+       $feedTemplate = wfScript('api').'?';
+
+       foreach( $wgFeedClasses as $format => $class ) {
+               $theseParams = $apiParams + array( 'feedformat' => $format );
+               $url = $feedTemplate . wfArrayToCGI( $theseParams );
+               $wgOut->addFeedLink( $format, $url );
+       }
 
        $skin = $wgUser->getSkin();
        $specialTitle = SpecialPage::getTitleFor( 'Watchlist' );
@@ -22,15 +56,19 @@ function wfSpecialWatchlist( $par ) {
        # Anons don't get a watchlist
        if( $wgUser->isAnon() ) {
                $wgOut->setPageTitle( wfMsg( 'watchnologin' ) );
-               $llink = $skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Userlogin' ), wfMsgHtml( 'loginreqlink' ), 'returnto=' . $specialTitle->getPrefixedUrl() );
-               $wgOut->addHtml( wfMsgWikiHtml( 'watchlistanontext', $llink ) );
+               $llink = $skin->linkKnown(
+                       SpecialPage::getTitleFor( 'Userlogin' ),
+                       wfMsgHtml( 'loginreqlink' ),
+                       array(),
+                       array( 'returnto' => $specialTitle->getPrefixedText() )
+               );
+               $wgOut->addWikiMsgArray( 'watchlistanontext', array( $llink ), array( 'replaceafter' ) );
                return;
        }
 
        $wgOut->setPageTitle( wfMsg( 'watchlist' ) );
 
-       $sub  = wfMsgExt( 'watchlistfor', 'parseinline', $wgUser->getName() );
-       $sub .= '<br />' . WatchlistEditor::buildTools( $wgUser->getSkin() );
+       $sub  = wfMsgExt( 'watchlistfor2', array( 'parseinline', 'replaceafter' ), $wgUser->getName(), WatchlistEditor::buildTools( $wgUser->getSkin() ) );
        $wgOut->setSubtitle( $sub );
 
        if( ( $mode = WatchlistEditor::getMode( $wgRequest, $par ) ) !== false ) {
@@ -40,7 +78,9 @@ function wfSpecialWatchlist( $par ) {
        }
 
        $uid = $wgUser->getId();
-       if( ($wgEnotifWatchlist || $wgShowUpdatedMarker) && $wgRequest->getVal( 'reset' ) && $wgRequest->wasPosted() ) {
+       if( ($wgEnotifWatchlist || $wgShowUpdatedMarker) && $wgRequest->getVal( 'reset' ) &&
+               $wgRequest->wasPosted() )
+       {
                $wgUser->clearAllNotifications( $uid );
                $wgOut->redirect( $specialTitle->getFullUrl() );
                return;
@@ -52,21 +92,21 @@ function wfSpecialWatchlist( $par ) {
        /* bool  */ 'hideBots'  => (int)$wgUser->getBoolOption( 'watchlisthidebots' ),
        /* bool  */ 'hideAnons' => (int)$wgUser->getBoolOption( 'watchlisthideanons' ),
        /* bool  */ 'hideLiu'   => (int)$wgUser->getBoolOption( 'watchlisthideliu' ),
+       /* bool  */ 'hidePatrolled' => (int)$wgUser->getBoolOption( 'watchlisthidepatrolled' ),
        /* bool  */ 'hideOwn'   => (int)$wgUser->getBoolOption( 'watchlisthideown' ),
        /* ?     */ 'namespace' => 'all',
        /* ?     */ 'invert'    => false,
        );
 
-       extract($defaults);
-
        # Extract variables from the request, falling back to user preferences or
        # other default values if these don't exist
        $prefs['days']      = floatval( $wgUser->getOption( 'watchlistdays' ) );
        $prefs['hideminor'] = $wgUser->getBoolOption( 'watchlisthideminor' );
        $prefs['hidebots']  = $wgUser->getBoolOption( 'watchlisthidebots' );
-       $prefs['hideanons'] = $wgUser->getBoolOption( 'watchlisthideanon' );
+       $prefs['hideanons'] = $wgUser->getBoolOption( 'watchlisthideanons' );
        $prefs['hideliu']   = $wgUser->getBoolOption( 'watchlisthideliu' );
        $prefs['hideown' ]  = $wgUser->getBoolOption( 'watchlisthideown' );
+       $prefs['hidepatrolled' ] = $wgUser->getBoolOption( 'watchlisthidepatrolled' );
 
        # Get query variables
        $days      = $wgRequest->getVal(  'days'     , $prefs['days'] );
@@ -75,6 +115,7 @@ function wfSpecialWatchlist( $par ) {
        $hideAnons = $wgRequest->getBool( 'hideAnons', $prefs['hideanons'] );
        $hideLiu   = $wgRequest->getBool( 'hideLiu'  , $prefs['hideliu'] );
        $hideOwn   = $wgRequest->getBool( 'hideOwn'  , $prefs['hideown'] );
+       $hidePatrolled   = $wgRequest->getBool( 'hidePatrolled'  , $prefs['hidepatrolled'] );
 
        # Get namespace value, if supplied, and prepare a WHERE fragment
        $nameSpace = $wgRequest->getIntOrNull( 'namespace' );
@@ -82,16 +123,16 @@ function wfSpecialWatchlist( $par ) {
        if( !is_null( $nameSpace ) ) {
                $nameSpace = intval( $nameSpace );
                if( $invert && $nameSpace !== 'all' )
-                       $nameSpaceClause = " AND rc_namespace != $nameSpace";
+                       $nameSpaceClause = "rc_namespace != $nameSpace";
                else
-                       $nameSpaceClause = " AND rc_namespace = $nameSpace";
+                       $nameSpaceClause = "rc_namespace = $nameSpace";
        } else {
                $nameSpace = '';
                $nameSpaceClause = '';
        }
 
        $dbr = wfGetDB( DB_SLAVE, 'watchlist' );
-       list($page,$watchlist,$recentchanges,$user) = $dbr->tableNamesN('page','watchlist','recentchanges','user');
+       $recentchanges = $dbr->tableName( 'recentchanges' );
 
        $watchlistCount = $dbr->selectField( 'watchlist', 'COUNT(*)',
                array( 'wl_user' => $uid ), __METHOD__ );
@@ -121,27 +162,18 @@ function wfSpecialWatchlist( $par ) {
        wfAppendToArrayIfNotDefault( 'hideLiu'  , (int)$hideLiu  , $defaults, $nondefaults );
        wfAppendToArrayIfNotDefault( 'hideOwn'  , (int)$hideOwn  , $defaults, $nondefaults);
        wfAppendToArrayIfNotDefault( 'namespace', $nameSpace     , $defaults, $nondefaults);
+       wfAppendToArrayIfNotDefault( 'hidePatrolled', (int)$hidePatrolled, $defaults, $nondefaults );
 
-       $hookSql = "";
-       if( ! wfRunHooks('BeforeWatchlist', array($nondefaults, $wgUser, &$hookSql)) ) {
-               return;
-       }
-
-       if($nitems == 0) {
+       if( $nitems == 0 ) {
                $wgOut->addWikiMsg( 'nowatchlist' );
                return;
        }
 
-       if ( $days <= 0 ) {
-               $andcutoff = '';
-       } else {
-               $andcutoff = "AND rc_timestamp > '".$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;
-               */
+       # Possible where conditions
+       $conds = array();
+
+       if( $days > 0 ) {
+               $conds[] = "rc_timestamp > '".$dbr->timestamp( time() - intval( $days * 86400 ) )."'";
        }
 
        # If the watchlist is relatively short, it's simplest to zip
@@ -153,20 +185,37 @@ function wfSpecialWatchlist( $par ) {
        # Up estimate of watched items by 15% to compensate for talk pages...
 
        # Toggles
-       $andHideOwn   = $hideOwn   ? "AND (rc_user <> $uid)" : '';
-       $andHideBots  = $hideBots  ? "AND (rc_bot = 0)" : '';
-       $andHideMinor = $hideMinor ? "AND (rc_minor = 0)" : '';
-       $andHideLiu   = $hideLiu   ? "AND (rc_user = 0)" : '';
-       $andHideAnons = $hideAnons ? "AND (rc_user != 0)" : '';
+       if( $hideOwn ) {
+               $conds[] = "rc_user != $uid";
+       }
+       if( $hideBots ) {
+               $conds[] = 'rc_bot = 0';
+       }
+       if( $hideMinor ) {
+               $conds[] = 'rc_minor = 0';
+       }
+       if( $hideLiu ) {
+               $conds[] = 'rc_user = 0';
+       }
+       if( $hideAnons ) {
+               $conds[] = 'rc_user != 0';
+       }
+       if ( $wgUser->useRCPatrol() && $hidePatrolled ) {
+               $conds[] = 'rc_patrolled != 1';
+       }
+       if( $nameSpaceClause ) {
+               $conds[] = $nameSpaceClause;
+       }
 
        # Toggle watchlist content (all recent edits or just the latest)
        if( $wgUser->getOption( 'extendwatchlist' )) {
-               $andLatest='';
-               $limitWatchlist = 'LIMIT ' . intval( $wgUser->getOption( 'wllimit' ) );
+               $limitWatchlist = intval( $wgUser->getOption( 'wllimit' ) );
+               $usePage = false;
        } else {
        # Top log Ids for a page are not stored
-               $andLatest = 'AND (rc_this_oldid=page_latest OR rc_type=' . RC_LOG . ') ';
-               $limitWatchlist = '';
+               $conds[] = 'rc_this_oldid=page_latest OR rc_type=' . RC_LOG;
+               $limitWatchlist = 0;
+               $usePage = true;
        }
 
        # Show a message about slave lag, if applicable
@@ -182,42 +231,42 @@ function wfSpecialWatchlist( $par ) {
        if( $wgUser->getOption( 'enotifwatchlistpages' ) && $wgEnotifWatchlist) {
                $form .= wfMsgExt( 'wlheader-enotif', 'parse' ) . "\n";
        }
-       if ( $wgShowUpdatedMarker ) {
+       if( $wgShowUpdatedMarker ) {
                $form .= Xml::openElement( 'form', array( 'method' => 'post',
                                        'action' => $specialTitle->getLocalUrl(),
                                        'id' => 'mw-watchlist-resetbutton' ) ) .
                                wfMsgExt( 'wlheader-showupdated', array( 'parseinline' ) ) . ' ' .
                                Xml::submitButton( wfMsg( 'enotif_reset' ), array( 'name' => 'dummy' ) ) .
-                               Xml::hidden( 'reset', 'all' ) .
+                               Html::hidden( 'reset', 'all' ) .
                                Xml::closeElement( 'form' );
        }
        $form .= '<hr />';
 
-       if ( $wgShowUpdatedMarker ) {
-               $wltsfield = ", ${watchlist}.wl_notificationtimestamp ";
-       } else {
-               $wltsfield = '';
+       $tables = array( 'recentchanges', 'watchlist' );
+       $fields = array( "{$recentchanges}.*" );
+       $join_conds = array(
+               'watchlist' => array('INNER JOIN',"wl_user='{$uid}' AND wl_namespace=rc_namespace AND wl_title=rc_title"),
+       );
+       $options = array( 'ORDER BY' => 'rc_timestamp DESC' );
+       if( $wgShowUpdatedMarker ) {
+               $fields[] = 'wl_notificationtimestamp';
+       }
+       if( $limitWatchlist ) {
+               $options['LIMIT'] = $limitWatchlist;
+       }
+
+       $rollbacker = $wgUser->isAllowed('rollback');
+       if ( $usePage || $rollbacker ) {
+               $tables[] = 'page';
+               $join_conds['page'] = array('LEFT JOIN','rc_cur_id=page_id');
+               if ($rollbacker)
+                       $fields[] = 'page_latest';
        }
-       $sql = "SELECT ${recentchanges}.* ${wltsfield}, {$user}.user_editcount, {$user}.user_registration
-         FROM $watchlist,$recentchanges
-         LEFT JOIN $page ON rc_cur_id=page_id
-         LEFT JOIN $user ON (rc_user !='0' AND rc_user = user_id)
-         WHERE wl_user=$uid
-         AND wl_namespace=rc_namespace
-         AND wl_title=rc_title
-         $andcutoff
-         $andLatest
-         $andHideOwn
-         $andHideBots
-         $andHideMinor
-         $andHideLiu
-         $andHideAnons
-         $nameSpaceClause
-         $hookSql
-         ORDER BY rc_timestamp DESC
-         $limitWatchlist";
-
-       $res = $dbr->query( $sql, $fname );
+
+       ChangeTags::modifyDisplayQuery( $tables, $fields, $conds, $join_conds, $options, '' );
+       wfRunHooks('SpecialWatchlistQuery', array(&$conds,&$tables,&$join_conds,&$fields) );
+
+       $res = $dbr->select( $tables, $fields, $conds, __METHOD__, $options, $join_conds );
        $numRows = $dbr->numRows( $res );
 
        /* Start bottom header */
@@ -240,59 +289,43 @@ function wfSpecialWatchlist( $par ) {
 
        $cutofflinks = "\n" . wlCutoffLinks( $days, 'Watchlist', $nondefaults ) . "<br />\n";
 
-       # Spit out some control panel links
        $thisTitle = SpecialPage::getTitleFor( 'Watchlist' );
-       $skin = $wgUser->getSkin();
-
-       # Hide/show minor edits
-       $label = $hideMinor ? wfMsgHtml( 'watchlist-show-minor' ) : wfMsgHtml( 'watchlist-hide-minor' );
-       $linkBits = wfArrayToCGI( array( 'hideMinor' => 1 - (int)$hideMinor ), $nondefaults );
-       $links[] = $skin->makeKnownLinkObj( $thisTitle, $label, $linkBits );
-
-       # Hide/show bot edits
-       $label = $hideBots ? wfMsgHtml( 'watchlist-show-bots' ) : wfMsgHtml( 'watchlist-hide-bots' );
-       $linkBits = wfArrayToCGI( array( 'hideBots' => 1 - (int)$hideBots ), $nondefaults );
-       $links[] = $skin->makeKnownLinkObj( $thisTitle, $label, $linkBits );
 
-       # Hide/show anonymous edits
-       $label = $hideAnons ? wfMsgHtml( 'watchlist-show-anons' ) : wfMsgHtml( 'watchlist-hide-anons' );
-       $linkBits = wfArrayToCGI( array( 'hideAnons' => 1 - (int)$hideAnons ), $nondefaults );
-       $links[] = $skin->makeKnownLinkObj( $thisTitle, $label, $linkBits );
-
-       # Hide/show logged in edits
-       $label = $hideLiu ? wfMsgHtml( 'watchlist-show-liu' ) : wfMsgHtml( 'watchlist-hide-liu' );
-       $linkBits = wfArrayToCGI( array( 'hideLiu' => 1 - (int)$hideLiu ), $nondefaults );
-       $links[] = $skin->makeKnownLinkObj( $thisTitle, $label, $linkBits );
-
-       # Hide/show own edits
-       $label = $hideOwn ? wfMsgHtml( 'watchlist-show-own' ) : wfMsgHtml( 'watchlist-hide-own' );
-       $linkBits = wfArrayToCGI( array( 'hideOwn' => 1 - (int)$hideOwn ), $nondefaults );
-       $links[] = $skin->makeKnownLinkObj( $thisTitle, $label, $linkBits );
+       # Spit out some control panel links
+       $links[] = wlShowHideLink( $nondefaults, 'rcshowhideminor', 'hideMinor', $hideMinor );
+       $links[] = wlShowHideLink( $nondefaults, 'rcshowhidebots', 'hideBots', $hideBots );
+       $links[] = wlShowHideLink( $nondefaults, 'rcshowhideanons', 'hideAnons', $hideAnons );
+       $links[] = wlShowHideLink( $nondefaults, 'rcshowhideliu', 'hideLiu', $hideLiu );
+       $links[] = wlShowHideLink( $nondefaults, 'rcshowhidemine', 'hideOwn', $hideOwn );
+
+       if( $wgUser->useRCPatrol() ) {
+               $links[] = wlShowHideLink( $nondefaults, 'rcshowhidepatr', 'hidePatrolled', $hidePatrolled );
+       }
 
        # Namespace filter and put the whole form together.
        $form .= $wlInfo;
        $form .= $cutofflinks;
-       $form .= implode( ' | ', $links );
-       $form .= Xml::openElement( 'form', array( 'method' => 'post', 'action' => $thisTitle->getLocalUrl() ) );
-       $form .= '<p>';
-       $form .= Xml::label( wfMsg( 'namespace' ), 'namespace' ) . '&nbsp;';
-       $form .= Xml::namespaceSelector( $nameSpace, '' ) . '&nbsp;';
-       $form .= Xml::checkLabel( wfMsg('invert'), 'invert', 'nsinvert', $invert ) . '&nbsp;';
+       $form .= $wgLang->pipeList( $links );
+       $form .= Xml::openElement( 'form', array( 'method' => 'post', 'action' => $thisTitle->getLocalUrl(), 'id' => 'mw-watchlist-form-namespaceselector' ) );
+       $form .= '<hr /><p>';
+       $form .= Xml::label( wfMsg( 'namespace' ), 'namespace' ) . '&#160;';
+       $form .= Xml::namespaceSelector( $nameSpace, '' ) . '&#160;';
+       $form .= Xml::checkLabel( wfMsg('invert'), 'invert', 'nsinvert', $invert ) . '&#160;';
        $form .= Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . '</p>';
-       $form .= Xml::hidden( 'days', $days );
+       $form .= Html::hidden( 'days', $days );
        if( $hideMinor )
-               $form .= Xml::hidden( 'hideMinor', 1 );
+               $form .= Html::hidden( 'hideMinor', 1 );
        if( $hideBots )
-               $form .= Xml::hidden( 'hideBots', 1 );
+               $form .= Html::hidden( 'hideBots', 1 );
        if( $hideAnons )
-               $form .= Xml::hidden( 'hideAnons', 1 );
+               $form .= Html::hidden( 'hideAnons', 1 );
        if( $hideLiu )
-               $form .= Xml::hidden( 'hideLiu', 1 );
+               $form .= Html::hidden( 'hideLiu', 1 );
        if( $hideOwn )
-               $form .= Xml::hidden( 'hideOwn', 1 );
+               $form .= Html::hidden( 'hideOwn', 1 );
        $form .= Xml::closeElement( 'form' );
        $form .= Xml::closeElement( 'fieldset' );
-       $wgOut->addHtml( $form );
+       $wgOut->addHTML( $form );
 
        # If there's nothing to show, stop here
        if( $numRows == 0 ) {
@@ -304,21 +337,24 @@ function wfSpecialWatchlist( $par ) {
 
        /* Do link batch query */
        $linkBatch = new LinkBatch;
-       while ( $row = $dbr->fetchObject( $res ) ) {
+       foreach ( $res as $row ) {
                $userNameUnderscored = str_replace( ' ', '_', $row->rc_user_text );
                if ( $row->rc_user != 0 ) {
                        $linkBatch->add( NS_USER, $userNameUnderscored );
                }
                $linkBatch->add( NS_USER_TALK, $userNameUnderscored );
+
+               $linkBatch->add( $row->rc_namespace, $row->rc_title );
        }
        $linkBatch->execute();
        $dbr->dataSeek( $res, 0 );
 
        $list = ChangesList::newFromUser( $wgUser );
+       $list->setWatchlistDivs();
 
        $s = $list->beginRecentChangesList();
        $counter = 1;
-       while ( $obj = $dbr->fetchObject( $res ) ) {
+       foreach ( $res as $obj ) {
                # Make RC entry
                $rc = RecentChange::newFromRow( $obj );
                $rc->counter = $counter++;
@@ -341,31 +377,60 @@ function wfSpecialWatchlist( $par ) {
                        $rc->numberofWatchingusers = 0;
                }
 
-               $s .= $list->recentChangesLine( $rc, $updated );
+               $s .= $list->recentChangesLine( $rc, $updated, $counter );
        }
        $s .= $list->endRecentChangesList();
 
-       $dbr->freeResult( $res );
        $wgOut->addHTML( $s );
 }
 
+function wlShowHideLink( $options, $message, $name, $value ) {
+       global $wgUser;
+
+       $showLinktext = wfMsgHtml( 'show' );
+       $hideLinktext = wfMsgHtml( 'hide' );
+       $title = SpecialPage::getTitleFor( 'Watchlist' );
+       $skin = $wgUser->getSkin();
+
+       $label = $value ? $showLinktext : $hideLinktext;
+       $options[$name] = 1 - (int) $value;
+
+       return wfMsgHtml( $message, $skin->linkKnown( $title, $label, array(), $options ) );
+}
+
+
 function wlHoursLink( $h, $page, $options = array() ) {
        global $wgUser, $wgLang, $wgContLang;
+
        $sk = $wgUser->getSkin();
-       $s = $sk->makeKnownLink(
-         $wgContLang->specialPage( $page ),
-         $wgLang->formatNum( $h ),
-         wfArrayToCGI( array('days' => ($h / 24.0)), $options ) );
+       $title = Title::newFromText( $wgContLang->specialPage( $page ) );
+       $options['days'] = ($h / 24.0);
+
+       $s = $sk->linkKnown(
+               $title,
+               $wgLang->formatNum( $h ),
+               array(),
+               $options
+       );
+
        return $s;
 }
 
 function wlDaysLink( $d, $page, $options = array() ) {
        global $wgUser, $wgLang, $wgContLang;
+
        $sk = $wgUser->getSkin();
-       $s = $sk->makeKnownLink(
-         $wgContLang->specialPage( $page ),
-         ($d ? $wgLang->formatNum( $d ) : wfMsgHtml( 'watchlistall2' ) ),
-         wfArrayToCGI( array('days' => $d), $options ) );
+       $title = Title::newFromText( $wgContLang->specialPage( $page ) );
+       $options['days'] = $d;
+       $message = ($d ? $wgLang->formatNum( $d ) : wfMsgHtml( 'watchlistall2' ) );
+
+       $s = $sk->linkKnown(
+               $title,
+               $message,
+               array(),
+               $options
+       );
+
        return $s;
 }
 
@@ -373,6 +438,8 @@ function wlDaysLink( $d, $page, $options = array() ) {
  * Returns html
  */
 function wlCutoffLinks( $days, $page = 'Watchlist', $options = array() ) {
+       global $wgLang;
+
        $hours = array( 1, 2, 6, 12 );
        $days = array( 1, 3, 7 );
        $i = 0;
@@ -385,25 +452,26 @@ function wlCutoffLinks( $days, $page = 'Watchlist', $options = array() ) {
        }
        return wfMsgExt('wlshowlast',
                array('parseinline', 'replaceafter'),
-               implode(' | ', $hours),
-               implode(' | ', $days),
+               $wgLang->pipeList( $hours ),
+               $wgLang->pipeList( $days ),
                wlDaysLink( 0, $page, $options ) );
 }
 
 /**
  * Count the number of items on a user's watchlist
  *
- * @param $talk Include talk pages
- * @return integer
+ * @param $user User object
+ * @param $talk Boolean: include talk pages
+ * @return Integer
  */
 function wlCountItems( &$user, $talk = true ) {
        $dbr = wfGetDB( DB_SLAVE, 'watchlist' );
 
        # Fetch the raw count
-       $res = $dbr->select( 'watchlist', 'COUNT(*) AS count', array( 'wl_user' => $user->mId ), 'wlCountItems' );
+       $res = $dbr->select( 'watchlist', 'COUNT(*) AS count',
+               array( 'wl_user' => $user->mId ), 'wlCountItems' );
        $row = $dbr->fetchObject( $res );
        $count = $row->count;
-       $dbr->freeResult( $res );
 
        # Halve to remove talk pages if needed
        if( !$talk )