From 9d1bb4f3e401786a86c12ae4b20b425c27ddcb91 Mon Sep 17 00:00:00 2001 From: Aaron Pramana Date: Sat, 9 Jun 2012 23:22:26 -0700 Subject: [PATCH] Watchlist grouping (not ready for review) My first change for the watchlist grouping project. Some of my code was written in a separate installation of MediaWiki and so I will be uploading more changes in the coming days. TODO: *add database table creation SQL *add/edit form message labels *clean up the UI (a lot) *more WatchlistGroup methods to come Change-Id: I645b924074cb179959a45d390f11f314184de368 --- includes/AutoLoader.php | 1 + includes/User.php | 4 +- includes/WatchedItem.php | 8 ++- includes/WatchlistGroup.php | 61 ++++++++++++++++++++++ includes/specials/SpecialEditWatchlist.php | 35 +++++++++++-- 5 files changed, 102 insertions(+), 7 deletions(-) create mode 100644 includes/WatchlistGroup.php diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index d29c4e35b6..4d76f976cf 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -258,6 +258,7 @@ $wgAutoloadLocalClasses = array( 'ViewCountUpdate' => 'includes/ViewCountUpdate.php', 'WantedQueryPage' => 'includes/QueryPage.php', 'WatchedItem' => 'includes/WatchedItem.php', + 'WatchlistGroup' => 'includes/WatchlistGroup.php', 'WebRequest' => 'includes/WebRequest.php', 'WebRequestUpload' => 'includes/WebRequest.php', 'WebResponse' => 'includes/WebResponse.php', diff --git a/includes/User.php b/includes/User.php index 01407b1d8e..0d3d14d47d 100644 --- a/includes/User.php +++ b/includes/User.php @@ -2627,8 +2627,8 @@ class User { * Watch an article. * @param $title Title of the article to look at */ - public function addWatch( $title ) { - $wl = WatchedItem::fromUserTitle( $this, $title ); + public function addWatch( $title, $group ) { + $wl = WatchedItem::fromUserTitle( $this, $title, $group ); $wl->addWatch(); $this->invalidateCache(); } diff --git a/includes/WatchedItem.php b/includes/WatchedItem.php index 932af1692e..cb27312264 100644 --- a/includes/WatchedItem.php +++ b/includes/WatchedItem.php @@ -27,7 +27,7 @@ * @ingroup Watchlist */ class WatchedItem { - var $mTitle, $mUser, $id, $ns, $ti; + var $mTitle, $mUser, $id, $gr, $ns, $ti; private $loaded = false, $watched, $timestamp; /** @@ -36,7 +36,7 @@ class WatchedItem { * @param $title Title: the title we're going to (un)watch * @return WatchedItem object */ - public static function fromUserTitle( $user, $title ) { + public static function fromUserTitle( $user, $title, $group = 0 ) { $wl = new WatchedItem; $wl->mUser = $user; $wl->mTitle = $title; @@ -48,6 +48,8 @@ class WatchedItem { $wl->ns = $title->getNamespace(); $wl->ti = $title->getDBkey(); + + $wl->gr = $group; return $wl; } @@ -145,6 +147,7 @@ class WatchedItem { $dbw->insert( 'watchlist', array( 'wl_user' => $this->id, + 'wl_group' => $this->gr, 'wl_namespace' => MWNamespace::getSubject($this->ns), 'wl_title' => $this->ti, 'wl_notificationtimestamp' => null @@ -155,6 +158,7 @@ class WatchedItem { $dbw->insert( 'watchlist', array( 'wl_user' => $this->id, + 'wl_group' => $this->gr, 'wl_namespace' => MWNamespace::getTalk($this->ns), 'wl_title' => $this->ti, 'wl_notificationtimestamp' => null diff --git a/includes/WatchlistGroup.php b/includes/WatchlistGroup.php new file mode 100644 index 0000000000..0a58958ff9 --- /dev/null +++ b/includes/WatchlistGroup.php @@ -0,0 +1,61 @@ +select( 'watchlist_groups', array( 'wg_id', 'wg_name' ), + array( 'wg_user' => $context->getUser()->getId()), __METHOD__ + ); + $groups = array(); + foreach ( $res as $s ) { + $groups[$s->wg_id] = $s->wg_name; + } + return $groups; + } + + public static function getGroupFromUserTitle( $title, $context ){ + $dbr = wfGetDB( DB_SLAVE ); + $res = $dbr->selectRow( 'watchlist', array( 'wl_group' ), + array( 'wl_title' => $title, 'wl_user' => $context->getUser()->getId()), __METHOD__ + ); + $gid = intval($res->wl_group); + + if($gid == 0){ + $gname = 'None'; + } else { + $res = $dbr->selectRow( 'watchlist_groups', array( 'wg_name' ), + array( 'wg_id' => $gid ), __METHOD__ + ); + $gname = $res->wg_name; + } + $group = array( $gname, $gid ); + return $group; + } + + public static function regroupTitles( $titles, $group, $context ){ + $dbw = wfGetDB( DB_MASTER ); + $res = $dbw->update( 'watchlist', array( 'wl_group' => $group ), + array( 'wl_title' => $titles), __METHOD__ ); + return $res; + } +} \ No newline at end of file diff --git a/includes/specials/SpecialEditWatchlist.php b/includes/specials/SpecialEditWatchlist.php index 67f6d688c2..55a15a47c7 100644 --- a/includes/specials/SpecialEditWatchlist.php +++ b/includes/specials/SpecialEditWatchlist.php @@ -275,7 +275,7 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { $res = $dbr->select( array( 'watchlist' ), - array( 'wl_namespace', 'wl_title' ), + array( 'wl_namespace', 'wl_group', 'wl_title' ), array( 'wl_user' => $this->getUser()->getId() ), __METHOD__, array( 'ORDER BY' => array( 'wl_namespace', 'wl_title' ) ) @@ -285,7 +285,7 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { foreach ( $res as $row ) { $lb->add( $row->wl_namespace, $row->wl_title ); if ( !MWNamespace::isTalk( $row->wl_namespace ) ) { - $titles[$row->wl_namespace][$row->wl_title] = 1; + $titles[$row->wl_namespace][$row->wl_title] = intval($row->wl_group); } } @@ -436,6 +436,17 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { public function submitNormal( $data ) { $removed = array(); + // Regrouping submission + $group = intval( $data['group'] ); + unset($data['group']); + if( $group > -1 ){ + foreach( $data as $titles ) { + WatchlistGroup::regroupTitles( $titles, $group, $this->getContext() ); + } + $this->successMessage = 'Titles were successfully regrouped!'; + return true; + } + foreach( $data as $titles ) { $this->unwatchTitles( $titles ); $removed = array_merge( $removed, $titles ); @@ -459,6 +470,8 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { protected function getNormalForm(){ global $wgContLang; + + $fields = array(); $count = 0; @@ -501,6 +514,19 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { $this->toc = false; } + $groups = WatchlistGroup::getGroups( $this->getContext() ); + foreach( $groups as &$g ){ + $g = 'Change group to "' . $g . '"'; + } + + $gsOptions = array_merge( array( 'Remove titles' => -1, 'Ungroup' => 0 ), array_flip( $groups ) ); + + $fields['group'] = array( + 'type' => 'select', + 'options' => $gsOptions, + 'label' => "Action:" + ); + $form = new EditWatchlistNormalHTMLForm( $fields, $this->getContext() ); $form->setTitle( $this->getTitle() ); $form->setSubmitTextMsg( 'watchlistedit-normal-submit' ); @@ -540,9 +566,12 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { ); } + $wgroup = WatchlistGroup::getGroupFromUserTitle( $title, $this->getContext() ); + $wgrouplink = $wgroup[0]; + wfRunHooks( 'WatchlistEditorBuildRemoveLine', array( &$tools, $title, $title->isRedirect(), $this->getSkin() ) ); - return $link . " (" . $this->getLanguage()->pipeList( $tools ) . ")"; + return $link . " (" . $this->getLanguage()->pipeList( $tools ) . ") (Group: " . $wgrouplink . ")"; } /** -- 2.20.1