Allow hook subscribers to also overwrite link to title
[lhc/web/wiklou.git] / includes / specials / SpecialEditWatchlist.php
index 369f11f..73438d9 100644 (file)
@@ -70,9 +70,7 @@ class SpecialEditWatchlist extends UnlistedSpecialPage {
                $this->checkReadOnly();
 
                $this->outputHeader();
-
-               $out->addSubtitle( $this->msg( 'watchlistfor2', $this->getUser()->getName() )
-                       ->rawParams( SpecialEditWatchlist::buildTools( null ) ) );
+               $this->outputSubtitle();
 
                # B/C: $mode used to be waaay down the parameter list, and the first parameter
                # was $wgUser
@@ -104,24 +102,42 @@ class SpecialEditWatchlist extends UnlistedSpecialPage {
 
                        case self::EDIT_NORMAL:
                        default:
-                               $out->setPageTitle( $this->msg( 'watchlistedit-normal-title' ) );
-                               $form = $this->getNormalForm();
-                               if ( $form->show() ) {
-                                       $out->addHTML( $this->successMessage );
-                                       $out->addReturnTo( SpecialPage::getTitleFor( 'Watchlist' ) );
-                               } elseif ( $this->toc !== false ) {
-                                       $out->prependHTML( $this->toc );
-                                       $out->addModules( 'mediawiki.toc' );
-                               }
+                       $this->executeViewEditWatchlist();
                                break;
                }
        }
 
+       /**
+        * Renders a subheader on the watchlist page.
+        */
+       protected function outputSubtitle() {
+               $out = $this->getOutput();
+               $out->addSubtitle( $this->msg( 'watchlistfor2', $this->getUser()->getName() )
+                       ->rawParams( SpecialEditWatchlist::buildTools( null ) ) );
+       }
+
+       /**
+        * Executes an edit mode for the watchlist view, from which you can manage your watchlist
+        *
+        */
+       protected function executeViewEditWatchlist() {
+               $out = $this->getOutput();
+               $out->setPageTitle( $this->msg( 'watchlistedit-normal-title' ) );
+               $form = $this->getNormalForm();
+               if ( $form->show() ) {
+                       $out->addHTML( $this->successMessage );
+                       $out->addReturnTo( SpecialPage::getTitleFor( 'Watchlist' ) );
+               } elseif ( $this->toc !== false ) {
+                       $out->prependHTML( $this->toc );
+                       $out->addModules( 'mediawiki.toc' );
+               }
+       }
+
        /**
         * Return an array of subpages beginning with $search that this special page will accept.
         *
         * @param string $search Prefix to search for
-        * @param integer $limit Maximum number of results to return
+        * @param int $limit Maximum number of results to return
         * @return string[] Matching subpages
         */
        public function prefixSearchSubpages( $search, $limit = 10 ) {
@@ -244,7 +260,7 @@ class SpecialEditWatchlist extends UnlistedSpecialPage {
                $talk = $this->msg( 'talkpagelinktext' )->escaped();
                // Do a batch existence check
                $batch = new LinkBatch();
-               if (count($titles) >= 100) {
+               if ( count( $titles ) >= 100 ) {
                        $output = wfMessage( 'watchlistedit-too-many' )->parse();
                        return;
                }
@@ -331,7 +347,7 @@ class SpecialEditWatchlist extends UnlistedSpecialPage {
         *
         * @return array
         */
-       private function getWatchlistInfo() {
+       protected function getWatchlistInfo() {
                $titles = array();
                $dbr = wfGetDB( DB_MASTER );
 
@@ -538,23 +554,26 @@ class SpecialEditWatchlist extends UnlistedSpecialPage {
                $count = 0;
 
                foreach ( $this->getWatchlistInfo() as $namespace => $pages ) {
-                       if ( $namespace >= 0 ) {
-                               $fields['TitlesNs' . $namespace] = array(
-                                       'class' => 'EditWatchlistCheckboxSeriesField',
-                                       'options' => array(),
-                                       'section' => "ns$namespace",
-                               );
-                       }
+                       $options = array();
 
                        foreach ( array_keys( $pages ) as $dbkey ) {
                                $title = Title::makeTitleSafe( $namespace, $dbkey );
 
                                if ( $this->checkTitle( $title, $namespace, $dbkey ) ) {
                                        $text = $this->buildRemoveLine( $title );
-                                       $fields['TitlesNs' . $namespace]['options'][$text] = $title->getPrefixedText();
+                                       $options[$text] = $title->getPrefixedText();
                                        $count++;
                                }
                        }
+
+                       // checkTitle can filter some options out, avoid empty sections
+                       if ( count( $options ) > 0 ) {
+                               $fields['TitlesNs' . $namespace] = array(
+                                       'class' => 'EditWatchlistCheckboxSeriesField',
+                                       'options' => $options,
+                                       'section' => "ns$namespace",
+                               );
+                       }
                }
                $this->cleanupWatchlist();
 
@@ -601,11 +620,6 @@ class SpecialEditWatchlist extends UnlistedSpecialPage {
        private function buildRemoveLine( $title ) {
                $link = Linker::link( $title );
 
-               if ( $title->isRedirect() ) {
-                       // Linker already makes class mw-redirect, so this is redundant
-                       $link = '<span class="watchlistredir">' . $link . '</span>';
-               }
-
                $tools[] = Linker::link( $title->getTalkPage(), $this->msg( 'talkpagelinktext' )->escaped() );
 
                if ( $title->exists() ) {
@@ -626,9 +640,14 @@ class SpecialEditWatchlist extends UnlistedSpecialPage {
 
                wfRunHooks(
                        'WatchlistEditorBuildRemoveLine',
-                       array( &$tools, $title, $title->isRedirect(), $this->getSkin() )
+                       array( &$tools, $title, $title->isRedirect(), $this->getSkin(), &$link )
                );
 
+               if ( $title->isRedirect() ) {
+                       // Linker already makes class mw-redirect, so this is redundant
+                       $link = '<span class="watchlistredir">' . $link . '</span>';
+               }
+
                return $link . " (" . $this->getLanguage()->pipeList( $tools ) . ")";
        }
 
@@ -763,8 +782,8 @@ class EditWatchlistCheckboxSeriesField extends HTMLMultiSelectField {
         * form is open (bug 32126), but we know that invalid items will
         * be harmless so we can override it here.
         *
-        * @param string $value the value the field was submitted with
-        * @param array $alldata the data collected from the form
+        * @param string $value The value the field was submitted with
+        * @param array $alldata The data collected from the form
         * @return bool|string Bool true on success, or String error to display.
         */
        function validate( $value, $alldata ) {