Move rewRevisionFromEditComplete call down till after page rows set
[lhc/web/wiklou.git] / includes / WatchlistEditor.php
index e43289e..4f64b78 100644 (file)
@@ -4,7 +4,7 @@
  * Provides the UI through which users can perform editing
  * operations on their watchlist
  *
- * @addtogroup Watchlist
+ * @ingroup Watchlist
  * @author Rob Church <robchur@gmail.com>
  */
 class WatchlistEditor {
@@ -32,15 +32,8 @@ class WatchlistEditor {
                }
                switch( $mode ) {
                        case self::EDIT_CLEAR:
-                               $output->setPageTitle( wfMsg( 'watchlistedit-clear-title' ) );
-                               if( $request->wasPosted() && $this->checkToken( $request, $wgUser ) ) {
-                                       $this->clearWatchlist( $user );
-                                       $user->invalidateCache();
-                                       $output->addHtml( wfMsgExt( 'watchlistedit-clear-done', 'parse' ) );
-                               } else {
-                                       $this->showClearForm( $output, $user );
-                               }
-                               break;
+                               // The "Clear" link scared people too much.
+                               // Pass on to the raw editor, from which it's very easy to clear.
                        case self::EDIT_RAW:
                                $output->setPageTitle( wfMsg( 'watchlistedit-raw-title' ) );
                                if( $request->wasPosted() && $this->checkToken( $request, $wgUser ) ) {
@@ -84,7 +77,7 @@ class WatchlistEditor {
                                $this->showNormalForm( $output, $user );
                }
        }
-       
+
        /**
         * Check the edit token from a form submission
         *
@@ -93,9 +86,9 @@ class WatchlistEditor {
         * @return bool
         */
        private function checkToken( $request, $user ) {
-               return $user->matchEditToken( $request->getVal( 'token' ), 'watchlistedit' );   
+               return $user->matchEditToken( $request->getVal( 'token' ), 'watchlistedit' );
        }
-       
+
        /**
         * Extract a list of titles from a blob of text, returning
         * (prefixed) strings; unwatchable titles are ignored
@@ -120,7 +113,7 @@ class WatchlistEditor {
                }
                return array_unique( $titles );
        }
-       
+
        /**
         * Print out a list of linked titles
         *
@@ -133,7 +126,7 @@ class WatchlistEditor {
         */
        private function showTitles( $titles, $output, $skin ) {
                $talk = wfMsgHtml( 'talkpagelinktext' );
-               // Do a batch existence check           
+               // Do a batch existence check
                $batch = new LinkBatch();
                foreach( $titles as $title ) {
                        if( !$title instanceof Title )
@@ -156,7 +149,7 @@ class WatchlistEditor {
                }
                $output->addHtml( "</ul>\n" );
        }
-       
+
        /**
         * Count the number of titles on a user's watchlist, excluding talk pages
         *
@@ -169,7 +162,7 @@ class WatchlistEditor {
                $row = $dbr->fetchObject( $res );
                return ceil( $row->count / 2 ); // Paranoia
        }
-       
+
        /**
         * Prepare a list of titles on a user's watchlist (excluding talk pages)
         * and return an array of (prefixed) strings
@@ -178,7 +171,7 @@ class WatchlistEditor {
         * @return array
         */
        private function getWatchlist( $user ) {
-               $list = array();        
+               $list = array();
                $dbr = wfGetDB( DB_MASTER );
                $res = $dbr->select(
                        'watchlist',
@@ -194,11 +187,11 @@ class WatchlistEditor {
                                if( $title instanceof Title && !$title->isTalkPage() )
                                        $list[] = $title->getPrefixedText();
                        }
-                       $res->free();           
+                       $res->free();
                }
                return $list;
        }
-       
+
        /**
         * Get a list of titles on a user's watchlist, excluding talk pages,
         * and return as a two-dimensional array with namespace, title and
@@ -212,7 +205,7 @@ class WatchlistEditor {
                $dbr = wfGetDB( DB_MASTER );
                $uid = intval( $user->getId() );
                list( $watchlist, $page ) = $dbr->tableNamesN( 'watchlist', 'page' );
-               $sql = "SELECT wl_namespace, wl_title, page_id, page_is_redirect
+               $sql = "SELECT wl_namespace, wl_title, page_id, page_len, page_is_redirect
                        FROM {$watchlist} LEFT JOIN {$page} ON ( wl_namespace = page_namespace
                        AND wl_title = page_title ) WHERE wl_user = {$uid}";
                $res = $dbr->query( $sql, __METHOD__ );
@@ -223,7 +216,7 @@ class WatchlistEditor {
                                if( $title instanceof Title ) {
                                        // Update the link cache while we're at it
                                        if( $row->page_id ) {
-                                               $cache->addGoodLinkObj( $row->page_id, $title );
+                                               $cache->addGoodLinkObj( $row->page_id, $title, $row->page_len, $row->page_is_redirect );
                                        } else {
                                                $cache->addBadLinkObj( $title );
                                        }
@@ -235,7 +228,7 @@ class WatchlistEditor {
                }
                return $titles;
        }
-       
+
        /**
         * Show a message indicating the number of items on the user's watchlist,
         * and return this count for additional checking
@@ -253,7 +246,7 @@ class WatchlistEditor {
                }
                return $count;
        }
-       
+
        /**
         * Remove all titles from a user's watchlist
         *
@@ -334,27 +327,6 @@ class WatchlistEditor {
                }
        }
 
-       /**
-        * Show a confirmation form for users wishing to clear their watchlist
-        *
-        * @param OutputPage $output
-        * @param User $user
-        */
-       private function showClearForm( $output, $user ) {
-               global $wgUser;
-               if( ( $count = $this->showItemCount( $output, $user ) ) > 0 ) {
-                       $self = SpecialPage::getTitleFor( 'Watchlist' );
-                       $form  = Xml::openElement( 'form', array( 'method' => 'post',
-                               'action' => $self->getLocalUrl( 'action=clear' ) ) );
-                       $form .= Xml::hidden( 'token', $wgUser->editToken( 'watchlistedit' ) );
-                       $form .= '<fieldset><legend>' . wfMsgHtml( 'watchlistedit-clear-legend' ) . '</legend>';
-                       $form .= wfMsgExt( 'watchlistedit-clear-confirm', 'parse' );
-                       $form .= '<p>' . Xml::submitButton( wfMsg( 'watchlistedit-clear-submit' ) ) . '</p>';
-                       $form .= '</fieldset></form>';
-                       $output->addHtml( $form );
-               }
-       }
-       
        /**
         * Show the standard watchlist editing form
         *
@@ -384,7 +356,7 @@ class WatchlistEditor {
                        $output->addHtml( $form );
                }
        }
-       
+
        /**
         * Get the correct "heading" for a namespace
         *
@@ -396,7 +368,7 @@ class WatchlistEditor {
                        ? wfMsgHtml( 'blanknamespace' )
                        : htmlspecialchars( $GLOBALS['wgContLang']->getFormattedNsText( $namespace ) );
        }
-       
+
        /**
         * Build a single list item containing a check box selecting a title
         * and a link to that title, with various additional bits
@@ -414,14 +386,14 @@ class WatchlistEditor {
                if( $title->exists() ) {
                        $tools[] = $skin->makeKnownLinkObj( $title, wfMsgHtml( 'history_short' ), 'action=history' );
                }
-               if( $title->getNamespace() == NS_USER ) {
-                       $tools[] = $skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Contributions' ), wfMsgHtml( 'contributions' ), 'target=' . $title->getPartialUrl() );
+               if( $title->getNamespace() == NS_USER && !$title->isSubpage() ) {
+                       $tools[] = $skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Contributions', $title->getText() ), wfMsgHtml( 'contributions' ) );
                }
                return '<li>'
                        . Xml::check( 'titles[]', false, array( 'value' => $title->getPrefixedText() ) )
                        . $link . ' (' . implode( ' | ', $tools ) . ')' . '</li>';
                }
-       
+
        /**
         * Show a form for editing the watchlist in "raw" mode
         *
@@ -449,7 +421,7 @@ class WatchlistEditor {
                $form .= '</fieldset></form>';
                $output->addHtml( $form );
        }
-       
+
        /**
         * Determine whether we are editing the watchlist, and if so, what
         * kind of editing operation
@@ -471,7 +443,7 @@ class WatchlistEditor {
                                return false;
                }
        }
-       
+
        /**
         * Build a set of links for convenient navigation
         * between watchlist viewing and editing modes
@@ -481,13 +453,10 @@ class WatchlistEditor {
         */
        public static function buildTools( $skin ) {
                $tools = array();
-               $self = SpecialPage::getTitleFor( 'Watchlist' );
-               $modes = array( 'view' => '', 'edit' => 'edit', 'raw' => 'raw', 'clear' => 'clear' );
-               foreach( $modes as $mode => $action ) {
-                       $action = $action ? "action={$action}" : '';
-                       $tools[] = $skin->makeKnownLinkObj( $self, wfMsgHtml( "watchlisttools-{$mode}" ), $action );
+               $modes = array( 'view' => false, 'edit' => 'edit', 'raw' => 'raw' );
+               foreach( $modes as $mode => $subpage ) {
+                       $tools[] = $skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Watchlist', $subpage ), wfMsgHtml( "watchlisttools-{$mode}" ) );
                }
                return implode( ' | ', $tools );
        }
-
 }