'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',
* 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();
}
* @ingroup Watchlist
*/
class WatchedItem {
- var $mTitle, $mUser, $id, $ns, $ti;
+ var $mTitle, $mUser, $id, $gr, $ns, $ti;
private $loaded = false, $watched, $timestamp;
/**
* @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;
$wl->ns = $title->getNamespace();
$wl->ti = $title->getDBkey();
+
+ $wl->gr = $group;
return $wl;
}
$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
$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
--- /dev/null
+<?php
+/**
+ * Accessor and mutator for watchlist groups.
+ *
+ * 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.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+class WatchlistGroup {
+ public static function getGroups( $context ){
+ $dbr = wfGetDB( DB_SLAVE );
+ $res = $dbr->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
$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' ) )
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);
}
}
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 );
protected function getNormalForm(){
global $wgContLang;
+
+
$fields = array();
$count = 0;
$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' );
);
}
+ $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 . ")";
}
/**