From 0c097b01eb02a5f9c88e3f550c57eadbc1692174 Mon Sep 17 00:00:00 2001 From: Max Semenik Date: Sat, 15 Oct 2011 21:06:34 +0000 Subject: [PATCH] (bug 31674) Can't edit watchlist if it contains special pages --- RELEASE-NOTES-1.18 | 7 ++++--- includes/User.php | 8 ++++++++ includes/api/ApiWatch.php | 2 +- includes/specials/SpecialEditWatchlist.php | 11 ++++++++++- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/RELEASE-NOTES-1.18 b/RELEASE-NOTES-1.18 index 074ff90d0a..1976626f96 100644 --- a/RELEASE-NOTES-1.18 +++ b/RELEASE-NOTES-1.18 @@ -469,6 +469,7 @@ production. really small, and somewhat inconsistent with each other. * (bug 30466) Entries in iwlinks table are now cleared when moving a page over redirect +* (bug 31674) Can't edit watchlist if it contains special pages === API changes in 1.18 === * BREAKING CHANGE: action=watch now requires POST and token. @@ -697,17 +698,17 @@ Documentation for both end-users and site administrators is available on MediaWiki.org, and is covered under the GNU Free Documentation License (except for pages that explicitly state that their contents are in the public domain): - http://www.mediawiki.org/wiki/Documentation + http://www.mediawiki.org/wiki/Documentation == Mailing list == A mailing list is available for MediaWiki user support and discussion: - http://lists.wikimedia.org/mailman/listinfo/mediawiki-l + http://lists.wikimedia.org/mailman/listinfo/mediawiki-l A low-traffic announcements-only list is also available: - http://lists.wikimedia.org/mailman/listinfo/mediawiki-announce + http://lists.wikimedia.org/mailman/listinfo/mediawiki-announce It's highly recommended that you sign up for one of these lists if you're going to run a public MediaWiki, so you can be notified of security fixes. diff --git a/includes/User.php b/includes/User.php index 37106941e7..ad3ba03fb9 100644 --- a/includes/User.php +++ b/includes/User.php @@ -2605,6 +2605,14 @@ class User { $this->invalidateCache(); } + /** + * Cleans up watchlist by removing invalid entries from it + */ + public function cleanupWatchlist() { + $dbw = wfGetDB( DB_MASTER ); + $dbw->delete( 'watchlist', array( 'wl_namespace < 0', 'wl_user' => $this->getId() ), __METHOD__ ); + } + /** * Clear the user's notification timestamp for the given title. * If e-notif e-mails are on, they will receive notification mails on diff --git a/includes/api/ApiWatch.php b/includes/api/ApiWatch.php index 13220cb359..9eee4956cd 100644 --- a/includes/api/ApiWatch.php +++ b/includes/api/ApiWatch.php @@ -49,7 +49,7 @@ class ApiWatch extends ApiBase { $params = $this->extractRequestParams(); $title = Title::newFromText( $params['title'] ); - if ( !$title ) { + if ( !$title || $titile->getNamespace() < 0 ) { $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) ); } diff --git a/includes/specials/SpecialEditWatchlist.php b/includes/specials/SpecialEditWatchlist.php index 5b9dd7ca83..f0314a7ce3 100644 --- a/includes/specials/SpecialEditWatchlist.php +++ b/includes/specials/SpecialEditWatchlist.php @@ -376,8 +376,13 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { $fields = array(); + $haveInvalidNamespaces = false; foreach( $this->getWatchlistInfo() as $namespace => $pages ){ - + if ( $namespace < 0 ) { + $haveInvalidNamespaces = true; + continue; + } + $namespace == NS_MAIN ? wfMsgHtml( 'blanknamespace' ) : htmlspecialchars( $wgContLang->getFormattedNsText( $namespace ) ); @@ -394,6 +399,10 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { $fields['TitlesNs'.$namespace]['options'][$text] = $title->getEscapedText(); } } + if ( $haveInvalidNamespaces ) { + wfDebug( "User {$this->getContext()->getUser()->getId()} has invalid watchlist entries, clening up...\n" ); + $this->getContext()->getUser()->cleanupWatchlist(); + } $form = new EditWatchlistNormalHTMLForm( $fields, $this->getContext() ); $form->setTitle( $this->getTitle() ); -- 2.20.1