API: fix copyright symbol, coding style cleanup, more braces
[lhc/web/wiklou.git] / includes / WatchlistEditor.php
index 9e044a8..e9e79ee 100644 (file)
@@ -46,19 +46,19 @@ class WatchlistEditor {
                                                $this->unwatchTitles( $toUnwatch, $user );
                                                $user->invalidateCache();
                                                if( count( $toWatch ) > 0 || count( $toUnwatch ) > 0 )
-                                                       $output->addHtml( wfMsgExt( 'watchlistedit-raw-done', 'parse' ) );
+                                                       $output->addHTML( wfMsgExt( 'watchlistedit-raw-done', 'parse' ) );
                                                if( ( $count = count( $toWatch ) ) > 0 ) {
-                                                       $output->addHtml( wfMsgExt( 'watchlistedit-raw-added', 'parse', $count ) );
+                                                       $output->addHTML( wfMsgExt( 'watchlistedit-raw-added', 'parse', $count ) );
                                                        $this->showTitles( $toWatch, $output, $wgUser->getSkin() );
                                                }
                                                if( ( $count = count( $toUnwatch ) ) > 0 ) {
-                                                       $output->addHtml( wfMsgExt( 'watchlistedit-raw-removed', 'parse', $count ) );
+                                                       $output->addHTML( wfMsgExt( 'watchlistedit-raw-removed', 'parse', $count ) );
                                                        $this->showTitles( $toUnwatch, $output, $wgUser->getSkin() );
                                                }
                                        } else {
                                                $this->clearWatchlist( $user );
                                                $user->invalidateCache();
-                                               $output->addHtml( wfMsgExt( 'watchlistedit-raw-removed', 'parse', count( $current ) ) );
+                                               $output->addHTML( wfMsgExt( 'watchlistedit-raw-removed', 'parse', count( $current ) ) );
                                                $this->showTitles( $current, $output, $wgUser->getSkin() );
                                        }
                                }
@@ -70,7 +70,7 @@ class WatchlistEditor {
                                        $titles = $this->extractTitles( $request->getArray( 'titles' ) );
                                        $this->unwatchTitles( $titles, $user );
                                        $user->invalidateCache();
-                                       $output->addHtml( wfMsgExt( 'watchlistedit-normal-done', 'parse',
+                                       $output->addHTML( wfMsgExt( 'watchlistedit-normal-done', 'parse',
                                                $GLOBALS['wgLang']->formatNum( count( $titles ) ) ) );
                                        $this->showTitles( $titles, $output, $wgUser->getSkin() );
                                }
@@ -138,16 +138,16 @@ class WatchlistEditor {
                }
                $batch->execute();
                // Print out the list
-               $output->addHtml( "<ul>\n" );
+               $output->addHTML( "<ul>\n" );
                foreach( $titles as $title ) {
                        if( !$title instanceof Title )
                                $title = Title::newFromText( $title );
                        if( $title instanceof Title ) {
-                               $output->addHtml( "<li>" . $skin->makeLinkObj( $title )
-                               . ' (' . $skin->makeLinkObj( $title->getTalkPage(), $talk ) . ")</li>\n" );
+                               $output->addHTML( "<li>" . $skin->link( $title )
+                               . ' (' . $skin->link( $title->getTalkPage(), $talk ) . ")</li>\n" );
                        }
                }
-               $output->addHtml( "</ul>\n" );
+               $output->addHTML( "</ul>\n" );
        }
 
        /**
@@ -239,10 +239,10 @@ class WatchlistEditor {
         */
        private function showItemCount( $output, $user ) {
                if( ( $count = $this->countWatchlist( $user ) ) > 0 ) {
-                       $output->addHtml( wfMsgExt( 'watchlistedit-numitems', 'parse',
+                       $output->addHTML( wfMsgExt( 'watchlistedit-numitems', 'parse',
                                $GLOBALS['wgLang']->formatNum( $count ) ) );
                } else {
-                       $output->addHtml( wfMsgExt( 'watchlistedit-noitems', 'parse' ) );
+                       $output->addHTML( wfMsgExt( 'watchlistedit-noitems', 'parse' ) );
                }
                return $count;
        }
@@ -269,18 +269,10 @@ class WatchlistEditor {
        private function watchTitles( $titles, $user ) {
                $dbw = wfGetDB( DB_MASTER );
                $rows = array();
-               $articles = array();
                foreach( $titles as $title ) {
                        if( !$title instanceof Title )
                                $title = Title::newFromText( $title );
                        if( $title instanceof Title ) {
-                               $article = new Article( $title );
-                               if ( !wfRunHooks('WatchArticle',array( &$user, &$article ) ) ){
-                                       continue;
-                               }
-                               // queue the ids rather than the objects, since the hook could potentially
-                               // load the entire object and  make  memory trouble 
-                               $articleIds[] = $article->getID();
                                $rows[] = array(
                                        'wl_user' => $user->getId(),
                                        'wl_namespace' => ( $title->getNamespace() & ~1 ),
@@ -296,10 +288,6 @@ class WatchlistEditor {
                        }
                }
                $dbw->insert( 'watchlist', $rows, __METHOD__, 'IGNORE' );
-               foreach( $articleIds as $articleId ){
-                       $article = Article::newFromID($articleId);
-                       wfRunHooks('WatchArticleComplete',array(&$user,&$article));
-               }
        }
 
        /**
@@ -317,10 +305,6 @@ class WatchlistEditor {
                        if( !$title instanceof Title )
                                $title = Title::newFromText( $title );
                        if( $title instanceof Title ) {
-                               $article = new Article($title);
-                               if(!wfRunHooks('UnwatchArticle',array(&$user,&$article))){
-                                       continue;
-                               }
                                $dbw->delete(
                                        'watchlist',
                                        array(
@@ -339,6 +323,7 @@ class WatchlistEditor {
                                        ),
                                        __METHOD__
                                );
+                               $article = new Article($title);
                                wfRunHooks('UnwatchArticleComplete',array(&$user,&$article));
                        }
                }
@@ -355,25 +340,51 @@ class WatchlistEditor {
                if( ( $count = $this->showItemCount( $output, $user ) ) > 0 ) {
                        $self = SpecialPage::getTitleFor( 'Watchlist' );
                        $form  = Xml::openElement( 'form', array( 'method' => 'post',
-                               'action' => $self->getLocalUrl( 'action=edit' ) ) );
+                               'action' => $self->getLocalUrl( array( 'action' => 'edit' ) ) ) );
                        $form .= Xml::hidden( 'token', $wgUser->editToken( 'watchlistedit' ) );
                        $form .= "<fieldset>\n<legend>" . wfMsgHtml( 'watchlistedit-normal-legend' ) . "</legend>";
                        $form .= wfMsgExt( 'watchlistedit-normal-explain', 'parse' );
-                       foreach( $this->getWatchlistInfo( $user ) as $namespace => $pages ) {
-                               $form .= "<h2>" . $this->getNamespaceHeading( $namespace ) . "</h2>\n";
-                               $form .= "<ul>\n";
-                               foreach( $pages as $dbkey => $redirect ) {
-                                       $title = Title::makeTitleSafe( $namespace, $dbkey );
-                                       $form .= $this->buildRemoveLine( $title, $redirect, $wgUser->getSkin() );
-                               }
-                               $form .= "</ul>\n";
-                       }
+                       $form .= $this->buildRemoveList( $user, $wgUser->getSkin() );
                        $form .= '<p>' . Xml::submitButton( wfMsg( 'watchlistedit-normal-submit' ) ) . '</p>';
                        $form .= '</fieldset></form>';
-                       $output->addHtml( $form );
+                       $output->addHTML( $form );
                }
        }
 
+       /**
+        * Build the part of the standard watchlist editing form with the actual
+        * title selection checkboxes and stuff.  Also generates a table of
+        * contents if there's more than one heading.
+        *
+        * @param $user User
+        * @param $skin Skin (really, Linker)
+        */
+       private function buildRemoveList( $user, $skin ) {
+               $list = "";
+               $toc = $skin->tocIndent();
+               $tocLength = 0;
+               foreach( $this->getWatchlistInfo( $user ) as $namespace => $pages ) {
+                       $tocLength++;
+                       $heading = htmlspecialchars( $this->getNamespaceHeading( $namespace ) );
+                       $anchor = "editwatchlist-ns" . $namespace;
+
+                       $list .= $skin->makeHeadLine( 2, ">", $anchor, $heading, "" );
+                       $toc .= $skin->tocLine( $anchor, $heading, $tocLength, 1 ) . $skin->tocLineEnd();
+
+                       $list .= "<ul>\n";
+                       foreach( $pages as $dbkey => $redirect ) {
+                               $title = Title::makeTitleSafe( $namespace, $dbkey );
+                               $list .= $this->buildRemoveLine( $title, $redirect, $skin );
+                       }
+                       $list .= "</ul>\n";
+               }
+               // ISSUE: omit the TOC if the total number of titles is low?
+               if( $tocLength > 1 ) {
+                       $list = $skin->tocList( $toc ) . $list;
+               }
+               return $list;
+       }
+
        /**
         * Get the correct "heading" for a namespace
         *
@@ -396,19 +407,33 @@ class WatchlistEditor {
         * @return string
         */
        private function buildRemoveLine( $title, $redirect, $skin ) {
-               $link = $skin->makeLinkObj( $title );
+               global $wgLang;
+
+               $link = $skin->link( $title );
                if( $redirect )
                        $link = '<span class="watchlistredir">' . $link . '</span>';
-               $tools[] = $skin->makeLinkObj( $title->getTalkPage(), wfMsgHtml( 'talkpagelinktext' ) );
+               $tools[] = $skin->link( $title->getTalkPage(), wfMsgHtml( 'talkpagelinktext' ) );
                if( $title->exists() ) {
-                       $tools[] = $skin->makeKnownLinkObj( $title, wfMsgHtml( 'history_short' ), 'action=history' );
+                       $tools[] = $skin->link(
+                               $title,
+                               wfMsgHtml( 'history_short' ),
+                               array(),
+                               array( 'action' => 'history' ),
+                               array( 'known', 'noclasses' )
+                       );
                }
                if( $title->getNamespace() == NS_USER && !$title->isSubpage() ) {
-                       $tools[] = $skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Contributions', $title->getText() ), wfMsgHtml( 'contributions' ) );
+                       $tools[] = $skin->link(
+                               SpecialPage::getTitleFor( 'Contributions', $title->getText() ),
+                               wfMsgHtml( 'contributions' ),
+                               array(),
+                               array(),
+                               array( 'known', 'noclasses' )
+                       );
                }
                return "<li>"
                        . Xml::check( 'titles[]', false, array( 'value' => $title->getPrefixedText() ) )
-                       . $link . " (" . implode( ' | ', $tools ) . ")" . "</li>\n";
+                       . $link . " (" . $wgLang->pipeList( $tools ) . ")" . "</li>\n";
                }
 
        /**
@@ -422,7 +447,7 @@ class WatchlistEditor {
                $this->showItemCount( $output, $user );
                $self = SpecialPage::getTitleFor( 'Watchlist' );
                $form  = Xml::openElement( 'form', array( 'method' => 'post',
-                       'action' => $self->getLocalUrl( 'action=raw' ) ) );
+                       'action' => $self->getLocalUrl( array( 'action' => 'raw' ) ) ) );
                $form .= Xml::hidden( 'token', $wgUser->editToken( 'watchlistedit' ) );
                $form .= '<fieldset><legend>' . wfMsgHtml( 'watchlistedit-raw-legend' ) . '</legend>';
                $form .= wfMsgExt( 'watchlistedit-raw-explain', 'parse' );
@@ -436,7 +461,7 @@ class WatchlistEditor {
                $form .= '</textarea>';
                $form .= '<p>' . Xml::submitButton( wfMsg( 'watchlistedit-raw-submit' ) ) . '</p>';
                $form .= '</fieldset></form>';
-               $output->addHtml( $form );
+               $output->addHTML( $form );
        }
 
        /**
@@ -469,11 +494,20 @@ class WatchlistEditor {
         * @return string
         */
        public static function buildTools( $skin ) {
+               global $wgLang;
+
                $tools = array();
                $modes = array( 'view' => false, 'edit' => 'edit', 'raw' => 'raw' );
                foreach( $modes as $mode => $subpage ) {
-                       $tools[] = $skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Watchlist', $subpage ), wfMsgHtml( "watchlisttools-{$mode}" ) );
+                       // can use messages 'watchlisttools-view', 'watchlisttools-edit', 'watchlisttools-raw'
+                       $tools[] = $skin->link(
+                               SpecialPage::getTitleFor( 'Watchlist', $subpage ),
+                               wfMsgHtml( "watchlisttools-{$mode}" ),
+                               array(),
+                               array(),
+                               array( 'known', 'noclasses' )
+                       );
                }
-               return implode( ' | ', $tools );
+               return $wgLang->pipeList( $tools );
        }
 }