SpecialEditWatchlist: Avoid empty namespace sections
authorumherirrender <umherirrender_de.wp@web.de>
Tue, 1 Jul 2014 18:22:38 +0000 (20:22 +0200)
committerUmherirrender <umherirrender_de.wp@web.de>
Fri, 25 Jul 2014 18:12:58 +0000 (18:12 +0000)
When the database contains a title for a positive namespace which is no
longer active, a table of contents item and a empty section is shown on
Special:EditWatchlist. After reload the section is gone, because the
database was cleaned up and the invalid namespace can no longer produce
the section. Refactor a bit to avoid the empty section on the first
view as well to get a stable output of that special page.

Change-Id: I41426bde71b21a4abddb12af0b3a84931f51ac97

includes/specials/SpecialEditWatchlist.php

index 0896929..6c258e0 100644 (file)
@@ -538,23 +538,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();