Extension:SubpageWatchlist

From MediaWiki.org
Jump to: navigation, search


MediaWiki extensions manual
Crystal Clear action run.png
SubpageWatchlist

Release status: Experimental

Implementation Hook
Description Include subpages of watched pages on Special:Watchlist
Author(s) (Bawolfftalk)
License GPLv2
Download See below
Hooks used
SpecialWatchlistFilters

SpecialWatchlistQuery

Translate the SubpageWatchlist extension if it is available at translatewiki.net

Check usage and version matrix; code metrics

The SubpageWatchlist extension adds an option to the Special:Watchlist navigation, so that in addition to things on your watchlist that were recently edited appearing, it also adds any subpages of watched items that were recently edited.

This extension has not had its performance evaluated. It should be fine for a small wiki and probably even a medium sized wiki. Given that watchlists are already a somewhat scary query, I feel like this shouldn't make things that much worse (although it does make things not as good). One probably would definitely not want to install this on a Wikipedia sized wiki without doing some good performance analysis and testing.

Known issues: If you're watching Foo and Foo/bar, and someone edits Foo/bar, the extension will make it appear on the list twice (Once for itself, and once as subpage of Foo). This extension considers all pages with a / to be subpages, even if subpages aren't enabled in the relavent namespace.

Installation[edit | edit source]

Use patch or something to apply the following diff in your extension directory (Hey I did mark this as experimental). Too lazy to get a git repo.

--- /dev/null	2013-11-01 08:17:28.971443302 -0300
+++ SubpageWatchlist/SubpageWatchlist_body.php	2013-11-01 15:43:15.000000000 -0300
@@ -0,0 +1,77 @@
+<?php
+/**
+ * Copyright © Brian Wolff 2013.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ */
+
+class SubpageWatchlist {
+	/**
+	 * Add a new option to the special page.
+	 *
+	 * @param SpecialWatchlist $specialPage
+	 * @param Array $customOpts List of added options
+	 * @return boolean
+	 */
+	static public function onSpecialWatchlistFilters( $specialPage, $customOpts ) {
+		$customOpts['hidesubpage'] = array(
+			// FIXME: make this into a preference.
+			'default' => 1, //(int) $specialPage->getUser()->getBoolOption( 'watchlisthideminor' ),
+			'msg' => 'subpagewatchlist-rchidesubpage'
+		);
+		return false;
+	}
+
+	/**
+	 * Change query if showing subpages is set.
+	 *
+	 * @param Array $conds Where conditions for query
+	 * @param Array $tables Tables to use in query
+	 * @param Array $join_conds Join conditions
+	 * @param Array $fields Fields to select in the query
+	 * @param Array $values Option values for special pages
+	 * @throws MWException If core changes how it makes the query, and this doesn't work.
+	 * @return boolean
+	 */
+	static public function onSpecialWatchlistQuery( $conds, $tables, $join_conds, $fields, $values ) {
+		if ( !$values['hidesubpage'] ) {
+			// This is a tad fragile
+			if ( isset( $join_conds['watchlist'] )
+				&& $join_conds['watchlist'][1][1] === 'wl_title=rc_title'
+			) {
+				$dbr = wfGetDB( DB_SLAVE, "watchlist" );
+				$join_conds['watchlist'][1][1] = $dbr->makeList(
+					array(
+						'wl_title = rc_title',
+						$dbr->buildConcat( array( 'wl_title', $dbr->addQuotes( '/' ) ) ) . '=' .
+							'SUBSTR( rc_title, 1, CHAR_LENGTH( wl_title ) + 1 )',
+					),
+					LIST_OR
+				);
+				// BUG: This can introduce duplicates to the list. Ways of fixing this
+				// * Change it to a SELECT DISTINCT. Describe suggests worse efficiency issues
+				// * Add group by. In my limitted testing, group by rc_timestamp doesn't seem
+				// to change the DESCRIBE, however that will cause some non-duplicates to remove
+				// * Remove duplicates on PHP side after query. Kind of icky, as won't return
+				// the expected number of results anymore.
+				// On top of all that, no hooks in the right place to do any of those
+			} else {
+				throw new MWException( __METHOD__ . " Could not modify Watchlist query." );
+			}
+		}
+		return false;
+	}
+}
--- /dev/null	2013-11-01 08:17:28.971443302 -0300
+++ SubpageWatchlist/SubpageWatchlist.i18n.php	2013-11-01 15:16:29.000000000 -0300
@@ -0,0 +1,19 @@
+<?php
+/**
+ * Internationalisation file for extension SubpageWatchlist
+ *
+ * @file
+ * @ingroup Extensions
+ */
+
+$messages = array();
+
+$messages['en'] = array(
+	'subpagewatchlist-desc' => 'Adds option to include subpages of watched pages in Special:Watchlist.',
+	'subpagewatchlist-rchidesubpage' => '$1 subpages',
+);
+
+$messages['qqq'] = array(
+	'subpagewatchlist-desc' => 'Description for Special:Version',
+	'subpagewatchlist-rchidesubpage' => 'Message to trigger option in Special:Watchlist',
+);
--- /dev/null	2013-11-01 08:17:28.971443302 -0300
+++ SubpageWatchlist/SubpageWatchlist.php	2013-11-01 15:44:22.000000000 -0300
@@ -0,0 +1,48 @@
+<?php
+/**
+ * Extension to add option to watchlist to include subpages
+ * of watched page on Special:Watchlist.
+ *
+ * @author Brian Wolff <bawolff+sw@gmail.com>
+ *
+ * Copyright © Brian Wolff 2013.
+ * 
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ */
+
+if ( !defined( 'MEDIAWIKI' ) ) {
+	die( 'This file is a MediaWiki extension, it is not a valid entry point' );
+}
+
+
+// Technically not a "new" special page, but it does modify one.
+$wgExtensionCredits['specialpage'][] = array(
+	'path' => __FILE__,
+	'name' => 'SubpageWatchlist',
+	'descriptionmsg' => 'subpagewatchlist-desc',
+	'version' => 0.1,
+	'url' => 'https://mediawiki.org/wiki/Extension:SubpageWatchlist',
+	'author' => '[https://mediawiki.org/wiki/User:Bawolff Brian Wolff]',
+);
+
+$dir = dirname(__FILE__) . '/';
+
+$wgExtensionMessagesFiles['SubpageWatchlist'] = $dir . 'SubpageWatchlist.i18n.php';
+
+$wgAutoloadClasses['SubpageWatchlist'] = $dir . 'SubpageWatchlist_body.php';
+
+$wgHooks['SpecialWatchlistFilters'][] = 'SubpageWatchlist::onSpecialWatchlistFilters';
+$wgHooks['SpecialWatchlistQuery'][] = 'SubpageWatchlist::onSpecialWatchlistQuery';

Otherwise, standard install instructions - require_once( "$IP/extensions/SubpageWatchlist/SubpageWatchlist.php" )

See also[edit | edit source]