merging latest master
[lhc/web/wiklou.git] / includes / specials / SpecialWatchlist.php
index fb57baa..5dfc113 100644 (file)
@@ -40,42 +40,36 @@ class SpecialWatchlist extends SpecialPage {
                $user = $this->getUser();
                $output = $this->getOutput();
 
-               // Add feed links
-               $wlToken = $user->getOption( 'watchlisttoken' );
-               if ( !$wlToken ) {
-                       $wlToken = sha1( mt_rand() . microtime( true ) );
-                       $user->setOption( 'watchlisttoken', $wlToken );
-                       $user->saveSettings();
-               }
-
-               $this->addFeedLinks( array( 'action' => 'feedwatchlist', 'allrev' => 'allrev',
-                                                       'wlowner' => $user->getName(), 'wltoken' => $wlToken ) );
-
-               $output->setRobotPolicy( 'noindex,nofollow' );
-
                # Anons don't get a watchlist
                if( $user->isAnon() ) {
-                       $output->setPageTitle( wfMsg( 'watchnologin' ) );
+                       $output->setPageTitle( $this->msg( 'watchnologin' ) );
+                       $output->setRobotPolicy( 'noindex,nofollow' );
                        $llink = Linker::linkKnown(
                                SpecialPage::getTitleFor( 'Userlogin' ),
-                               wfMsgHtml( 'loginreqlink' ),
+                               $this->msg( 'loginreqlink' )->escaped(),
                                array(),
                                array( 'returnto' => $this->getTitle()->getPrefixedText() )
                        );
-                       $output->addHTML( wfMessage( 'watchlistanontext' )->rawParams( $llink )->parse() );
+                       $output->addHTML( $this->msg( 'watchlistanontext' )->rawParams( $llink )->parse() );
                        return;
                }
 
+               // Add feed links
+               $wlToken = $user->getOption( 'watchlisttoken' );
+               if ( !$wlToken ) {
+                       $wlToken = MWCryptRand::generateHex( 40 );
+                       $user->setOption( 'watchlisttoken', $wlToken );
+                       $user->saveSettings();
+               }
+
+               $this->addFeedLinks( array( 'action' => 'feedwatchlist', 'allrev' => 'allrev',
+                                                       'wlowner' => $user->getName(), 'wltoken' => $wlToken ) );
+
                $this->setHeaders();
                $this->outputHeader();
 
-               $sub = wfMsgExt(
-                       'watchlistfor2',
-                       array( 'parseinline', 'replaceafter' ),
-                       $user->getName(),
-                       SpecialEditWatchlist::buildTools( $this->getSkin() )
-               );
-               $output->setSubtitle( $sub );
+               $output->addSubtitle( $this->msg( 'watchlistfor2', $user->getName()
+                       )->rawParams( SpecialEditWatchlist::buildTools( null ) ) );
 
                $request = $this->getRequest();
 
@@ -97,14 +91,6 @@ class SpecialWatchlist extends SpecialPage {
                        return;
                }
 
-               if( ( $wgEnotifWatchlist || $wgShowUpdatedMarker ) && $request->getVal( 'reset' ) &&
-                       $request->wasPosted() )
-               {
-                       $user->clearAllNotifications();
-                       $output->redirect( $this->getTitle()->getFullUrl() );
-                       return;
-               }
-
                $nitems = $this->countItems();
                if ( $nitems == 0 ) {
                        $output->addWikiMsg( 'nowatchlist' );
@@ -122,6 +108,7 @@ class SpecialWatchlist extends SpecialPage {
                /* bool  */ 'hideOwn'   => (int)$user->getBoolOption( 'watchlisthideown' ),
                /* ?     */ 'namespace' => 'all',
                /* ?     */ 'invert'    => false,
+               /* bool  */ 'associated' => false,
                );
                $this->customFilters = array();
                wfRunHooks( 'SpecialWatchlistFilters', array( $this, &$this->customFilters ) );
@@ -154,13 +141,20 @@ class SpecialWatchlist extends SpecialPage {
 
                # Get namespace value, if supplied, and prepare a WHERE fragment
                $nameSpace = $request->getIntOrNull( 'namespace' );
-               $invert = $request->getIntOrNull( 'invert' );
+               $invert = $request->getBool( 'invert' );
+               $associated = $request->getBool( 'associated' );
                if ( !is_null( $nameSpace ) ) {
+                       $eq_op = $invert ? '!=' : '=';
+                       $bool_op = $invert ? 'AND' : 'OR';
                        $nameSpace = intval( $nameSpace ); // paranioa
-                       if ( $invert ) {
-                               $nameSpaceClause = "rc_namespace != $nameSpace";
+                       if ( !$associated ) {
+                               $nameSpaceClause = "rc_namespace $eq_op $nameSpace";
                        } else {
-                               $nameSpaceClause = "rc_namespace = $nameSpace";
+                               $associatedNS = MWNamespace::getAssociated( $nameSpace );
+                               $nameSpaceClause =
+                                       "rc_namespace $eq_op $nameSpace " .
+                                       $bool_op .
+                                       " rc_namespace $eq_op $associatedNS";
                        }
                } else {
                        $nameSpace = '';
@@ -168,6 +162,7 @@ class SpecialWatchlist extends SpecialPage {
                }
                $values['namespace'] = $nameSpace;
                $values['invert'] = $invert;
+               $values['associated'] = $associated;
 
                if( is_null( $values['days'] ) || !is_numeric( $values['days'] ) ) {
                        $big = 1000; /* The magical big */
@@ -187,6 +182,14 @@ class SpecialWatchlist extends SpecialPage {
                        wfAppendToArrayIfNotDefault( $name, $values[$name], $defaults, $nondefaults );
                }
 
+               if( ( $wgEnotifWatchlist || $wgShowUpdatedMarker ) && $request->getVal( 'reset' ) &&
+                       $request->wasPosted() )
+               {
+                       $user->clearAllNotifications();
+                       $output->redirect( $this->getTitle()->getFullUrl( $nondefaults ) );
+                       return;
+               }
+
                $dbr = wfGetDB( DB_SLAVE, 'watchlist' );
 
                # Possible where conditions
@@ -240,37 +243,45 @@ class SpecialWatchlist extends SpecialPage {
                }
 
                # Show a message about slave lag, if applicable
-               $lag = $dbr->getLag();
+               $lag = wfGetLB()->safeGetLag( $dbr );
                if( $lag > 0 ) {
                        $output->showLagWarning( $lag );
                }
 
-               $lang = $this->getLang();
-
                # Create output form
-               $form  = Xml::fieldset( wfMsg( 'watchlist-options' ), false, array( 'id' => 'mw-watchlist-options' ) );
+               $form  = Xml::fieldset( $this->msg( 'watchlist-options' )->text(), false, array( 'id' => 'mw-watchlist-options' ) );
 
                # Show watchlist header
-               $form .= wfMsgExt( 'watchlist-details', array( 'parseinline' ), $lang->formatNum( $nitems ) );
+               $form .= $this->msg( 'watchlist-details' )->numParams( $nitems )->parse();
 
                if( $user->getOption( 'enotifwatchlistpages' ) && $wgEnotifWatchlist) {
-                       $form .= wfMsgExt( 'wlheader-enotif', 'parse' ) . "\n";
+                       $form .= $this->msg( 'wlheader-enotif' )->parseAsBlock() . "\n";
                }
                if( $wgShowUpdatedMarker ) {
                        $form .= Xml::openElement( 'form', array( 'method' => 'post',
                                                'action' => $this->getTitle()->getLocalUrl(),
                                                'id' => 'mw-watchlist-resetbutton' ) ) .
-                                       wfMsgExt( 'wlheader-showupdated', array( 'parseinline' ) ) . ' ' .
-                                       Xml::submitButton( wfMsg( 'enotif_reset' ), array( 'name' => 'dummy' ) ) .
-                                       Html::hidden( 'reset', 'all' ) .
-                                       Xml::closeElement( 'form' );
+                                       $this->msg( 'wlheader-showupdated' )->parse() . ' ' .
+                                       Xml::submitButton( $this->msg( 'enotif_reset' )->text(), array( 'name' => 'dummy' ) ) .
+                                       Html::hidden( 'reset', 'all' );
+                                       foreach ( $nondefaults as $key => $value ) {
+                                               $form .= Html::hidden( $key, $value );
+                                       }
+                                       $form .= Xml::closeElement( 'form' );
                }
                $form .= '<hr />';
 
                $tables = array( 'recentchanges', 'watchlist' );
                $fields = array( $dbr->tableName( 'recentchanges' ) . '.*' );
                $join_conds = array(
-                       'watchlist' => array('INNER JOIN',"wl_user='{$user->getId()}' AND wl_namespace=rc_namespace AND wl_title=rc_title"),
+                       'watchlist' => array(
+                               'INNER JOIN',
+                               array(
+                                       'wl_user' => $user->getId(),
+                                       'wl_namespace=rc_namespace',
+                                       'wl_title=rc_title'
+                               ),
+                       ),
                );
                $options = array( 'ORDER BY' => 'rc_timestamp DESC' );
                if( $wgShowUpdatedMarker ) {
@@ -293,25 +304,16 @@ class SpecialWatchlist extends SpecialPage {
                wfRunHooks('SpecialWatchlistQuery', array(&$conds,&$tables,&$join_conds,&$fields) );
 
                $res = $dbr->select( $tables, $fields, $conds, __METHOD__, $options, $join_conds );
-               $numRows = $dbr->numRows( $res );
+               $numRows = $res->numRows();
 
                /* Start bottom header */
 
+               $lang = $this->getLanguage();
                $wlInfo = '';
-               if( $values['days'] >= 1 ) {
+               if( $values['days'] > 0 ) {
                        $timestamp = wfTimestampNow();
-                       $wlInfo = wfMsgExt( 'rcnote', 'parseinline',
-                                       $lang->formatNum( $numRows ),
-                                       $lang->formatNum( $values['days'] ),
-                                       $lang->timeAndDate( $timestamp, true ),
-                                       $lang->date( $timestamp, true ),
-                                       $lang->time( $timestamp, true )
-                               ) . '<br />';
-               } elseif( $values['days'] > 0 ) {
-                       $wlInfo = wfMsgExt( 'wlnote', 'parseinline',
-                                       $lang->formatNum( $numRows ),
-                                       $lang->formatNum( round( $values['days'] * 24 ) )
-                               ) . '<br />';
+                       $wlInfo = $this->msg( 'wlnote' )->numParams( $numRows, round( $values['days'] * 24 ) )->params(
+                               $lang->userDate( $timestamp, $user ), $lang->userTime( $timestamp, $user ) )->parse() . '<br />';
                }
 
                $cutofflinks = "\n" . $this->cutoffLinks( $values['days'], $nondefaults ) . "<br />\n";
@@ -344,10 +346,32 @@ class SpecialWatchlist extends SpecialPage {
                $form .= $lang->pipeList( $links );
                $form .= Xml::openElement( 'form', array( 'method' => 'post', 'action' => $this->getTitle()->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 .= Html::namespaceSelector(
+                       array(
+                               'selected' => $nameSpace,
+                               'all' => '',
+                               'label' => $this->msg( 'namespace' )->text()
+                       ), array(
+                               'name'  => 'namespace',
+                               'id'    => 'namespace',
+                               'class' => 'namespaceselector',
+                       )
+               ) . '&#160;';
+               $form .= Xml::checkLabel(
+                       $this->msg( 'invert' )->text(),
+                       'invert',
+                       'nsinvert',
+                       $invert,
+                       array( 'title' => $this->msg( 'tooltip-invert' )->text() )
+               ) . '&#160;';
+               $form .= Xml::checkLabel(
+                       $this->msg( 'namespace_association' )->text(),
+                       'associated',
+                       'associated',
+                       $associated,
+                       array( 'title' => $this->msg( 'tooltip-namespace_association' )->text() )
+               ) . '&#160;';
+               $form .= Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ) . '</p>';
                $form .= Html::hidden( 'days', $values['days'] );
                foreach ( $filters as $key => $msg ) {
                        if ( $values[$key] ) {
@@ -416,13 +440,10 @@ class SpecialWatchlist extends SpecialPage {
        }
 
        protected function showHideLink( $options, $message, $name, $value ) {
-               $showLinktext = wfMsgHtml( 'show' );
-               $hideLinktext = wfMsgHtml( 'hide' );
-
-               $label = $value ? $showLinktext : $hideLinktext;
+               $label = $this->msg( $value ? 'show' : 'hide' )->escaped();
                $options[$name] = 1 - (int) $value;
 
-               return wfMsgHtml( $message, Linker::linkKnown( $this->getTitle(), $label, array(), $options ) );
+               return $this->msg( $message )->rawParams( Linker::linkKnown( $this->getTitle(), $label, array(), $options ) )->escaped();
        }
 
        protected function hoursLink( $h, $options = array() ) {
@@ -430,7 +451,7 @@ class SpecialWatchlist extends SpecialPage {
 
                return Linker::linkKnown(
                        $this->getTitle(),
-                       $this->getLang()->formatNum( $h ),
+                       $this->getLanguage()->formatNum( $h ),
                        array(),
                        $options
                );
@@ -438,7 +459,7 @@ class SpecialWatchlist extends SpecialPage {
 
        protected function daysLink( $d, $options = array() ) {
                $options['days'] = $d;
-               $message = ( $d ? $this->getLang()->formatNum( $d ) : wfMsgHtml( 'watchlistall2' ) );
+               $message = ( $d ? $this->getLanguage()->formatNum( $d ) : $this->msg( 'watchlistall2' )->escaped() );
 
                return Linker::linkKnown(
                        $this->getTitle(),
@@ -464,11 +485,10 @@ class SpecialWatchlist extends SpecialPage {
                foreach( $days as $d ) {
                        $days[$i++] = $this->daysLink( $d, $options );
                }
-               return wfMsgExt('wlshowlast',
-                       array('parseinline', 'replaceafter'),
-                       $this->getLang()->pipeList( $hours ),
-                       $this->getLang()->pipeList( $days ),
-                       $this->daysLink( 0, $options ) );
+               return $this->msg( 'wlshowlast' )->rawParams(
+                       $this->getLanguage()->pipeList( $hours ),
+                       $this->getLanguage()->pipeList( $days ),
+                       $this->daysLink( 0, $options ) )->parse();
        }
 
        /**
@@ -480,7 +500,7 @@ class SpecialWatchlist extends SpecialPage {
                $dbr = wfGetDB( DB_SLAVE, 'watchlist' );
 
                # Fetch the raw count
-               $res = $dbr->select( 'watchlist', 'COUNT(*) AS count',
+               $res = $dbr->select( 'watchlist', array( 'count' => 'COUNT(*)' ),
                        array( 'wl_user' => $this->getUser()->getId() ), __METHOD__ );
                $row = $dbr->fetchObject( $res );
                $count = $row->count;