Merge "Added new MWTimestamp::getRelativeTimestamp for pure relative."
[lhc/web/wiklou.git] / includes / specials / SpecialWatchlist.php
index 2a28a11..59f0dfe 100644 (file)
@@ -26,8 +26,8 @@ class SpecialWatchlist extends SpecialPage {
        /**
         * Constructor
         */
-       public function __construct( $page = 'Watchlist' ) {
-               parent::__construct( $page );
+       public function __construct( $page = 'Watchlist', $restriction = 'viewmywatchlist' ) {
+               parent::__construct( $page, $restriction );
        }
 
        /**
@@ -54,17 +54,16 @@ class SpecialWatchlist extends SpecialPage {
                        return;
                }
 
+               // Check permissions
+               $this->checkPermissions();
+
                // Add feed links
-               $wlToken = $user->getOption( 'watchlisttoken' );
-               if ( !$wlToken ) {
-                       $wlToken = MWCryptRand::generateHex( 40 );
-                       $user->setOption( 'watchlisttoken', $wlToken );
-                       $user->saveSettings();
+               $wlToken = $user->getTokenFromOption( 'watchlisttoken' );
+               if ( $wlToken ) {
+                       $this->addFeedLinks( array( 'action' => 'feedwatchlist', 'allrev' => 'allrev',
+                                                               'wlowner' => $user->getName(), 'wltoken' => $wlToken ) );
                }
 
-               $this->addFeedLinks( array( 'action' => 'feedwatchlist', 'allrev' => 'allrev',
-                                                       'wlowner' => $user->getName(), 'wltoken' => $wlToken ) );
-
                $this->setHeaders();
                $this->outputHeader();
 
@@ -240,12 +239,8 @@ class SpecialWatchlist extends SpecialPage {
                        $output->showLagWarning( $lag );
                }
 
-               # Create output form
-               $form = Xml::fieldset(
-                       $this->msg( 'watchlist-options' )->text(),
-                       false,
-                       array( 'id' => 'mw-watchlist-options' )
-               );
+               # Create output
+               $form = '';
 
                # Show watchlist header
                $form .= "<p>";
@@ -270,7 +265,16 @@ class SpecialWatchlist extends SpecialPage {
                        $form .= Xml::closeElement( 'form' ) . "\n";
                }
 
-               $form .= "<hr />\n";
+               $form .= Xml::openElement( 'form', array(
+                       'method' => 'post',
+                       'action' => $this->getTitle()->getLocalURL(),
+                       'id' => 'mw-watchlist-form'
+               ) );
+               $form .= Xml::fieldset(
+                       $this->msg( 'watchlist-options' )->text(),
+                       false,
+                       array( 'id' => 'mw-watchlist-options' )
+               );
 
                $tables = array( 'recentchanges', 'watchlist' );
                $fields = RecentChange::selectFields();
@@ -350,7 +354,6 @@ class SpecialWatchlist extends SpecialPage {
                $form .= $wlInfo;
                $form .= $cutofflinks;
                $form .= $lang->pipeList( $links ) . "\n";
-               $form .= Xml::openElement( 'form', array( 'method' => 'post', 'action' => $this->getTitle()->getLocalURL(), 'id' => 'mw-watchlist-form-namespaceselector' ) ) . "\n";
                $form .= "<hr />\n<p>";
                $form .= Html::namespaceSelector(
                        array(
@@ -381,8 +384,8 @@ class SpecialWatchlist extends SpecialPage {
                foreach ( $hiddenFields as $key => $value ) {
                        $form .= Html::hidden( $key, $value ) . "\n";
                }
-               $form .= Xml::closeElement( 'form' ) . "\n";
                $form .= Xml::closeElement( 'fieldset' ) . "\n";
+               $form .= Xml::closeElement( 'form' ) . "\n";
                $output->addHTML( $form );
 
                # If there's nothing to show, stop here
@@ -449,7 +452,7 @@ class SpecialWatchlist extends SpecialPage {
 
        protected function showHideLink( $options, $message, $name, $value ) {
                $label = $this->msg( $value ? 'show' : 'hide' )->escaped();
-               $options[$name] = 1 - (int) $value;
+               $options[$name] = 1 - (int)$value;
 
                return $this->msg( $message )->rawParams( Linker::linkKnown( $this->getTitle(), $label, array(), $options ) )->escaped();
        }