r69377 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r69376‎ | r69377 | r69378 >
Date:05:05, 15 July 2010
Author:nad
Status:deferred
Tags:
Comment:
add global for using realname instead of username
Modified paths:
  • /trunk/extensions/CategoryWatch/CategoryWatch.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CategoryWatch/CategoryWatch.php
@@ -1,4 +1,5 @@
22 <?php
 3+if ( !defined( 'MEDIAWIKI' ) ) die( 'Not an entry point.' );
34 /**
45 * CategoryWatch extension
56 * - Extends watchlist functionality to include notification about membership changes of watched categories
@@ -13,13 +14,18 @@
1415 * @licence GNU General Public Licence 2.0 or later
1516 */
1617
17 -if ( !defined( 'MEDIAWIKI' ) ) die( 'Not an entry point.' );
 18+define( 'CATEGORYWATCH_VERSION', '1.2.0, 2010-07-15' );
1819
19 -define( 'CATEGORYWATCH_VERSION', '1.1.1, 2010-04-21' );
20 -
 20+# Whether or not to also send notificaton to the person who made the change
2121 $wgCategoryWatchNotifyEditor = true;
22 -$wgCategoryWatchUseAutoCat = false;
2322
 23+# Set this to give every user a unique category that they're automatically watching
 24+# - the format of the category name is defined on the "categorywatch-autocat" localisation message
 25+$wgCategoryWatchUseAutoCat = false;
 26+
 27+# Set this to make the categorisation work by realname instead of username
 28+$wgCategoryWatchUseAutoCatRealName = false;
 29+
2430 $wgExtensionFunctions[] = 'wfSetupCategoryWatch';
2531 $wgExtensionCredits['other'][] = array(
2632 'path' => __FILE__,
@@ -43,7 +49,7 @@
4450 * Get a list of categories before article updated
4551 */
4652 function onArticleSave( &$article, &$user, &$text ) {
47 - global $wgCategoryWatchUseAutoCat;
 53+ global $wgCategoryWatchUseAutoCat, $wgCategoryWatchUseAutoCatRealName;
4854
4955 $this->before = array();
5056 $dbr = wfGetDB( DB_SLAVE );
@@ -66,8 +72,9 @@
6773
6874 # Insert an entry into watchlist for each
6975 while ( $row = $dbr->fetchRow( $res ) ) {
70 - $uname = User::newFromId( $row[0] )->getName();
71 - $wl_title = str_replace( ' ', '_', wfMsg( 'categorywatch-autocat', $uname ) );
 76+ $user = User::newFromId( $row[0] );
 77+ $name = $wgCategoryWatchUseAutoCatRealName ? $user->getRealName() : $user->getName();
 78+ $wl_title = str_replace( ' ', '_', wfMsg( 'categorywatch-autocat', $name ) );
7279 $dbr->insert( $wtbl, array( 'wl_user' => $row[0], 'wl_namespace' => NS_CATEGORY, 'wl_title' => $wl_title ) );
7380 }
7481 $dbr->freeResult( $res );
@@ -80,6 +87,7 @@
8188 * Find changes in categorisation and send messages to watching users
8289 */
8390 function onArticleSaveComplete( &$article, &$user, &$text, &$summary, &$medit ) {
 91+
8492 # Get cats after update
8593 $this->after = array();
8694 $dbr = wfGetDB( DB_SLAVE );
@@ -101,6 +109,7 @@
102110 $page = "$pagename ($pageurl)";
103111
104112 if ( count( $add ) == 1 && count( $sub ) == 1 ) {
 113+
105114 $add = array_shift( $add );
106115 $sub = array_shift( $sub );
107116
@@ -108,21 +117,14 @@
109118 $message = wfMsg( 'categorywatch-catmovein', $page, $this->friendlyCat( $add ), $this->friendlyCat( $sub ) );
110119 $this->notifyWatchers( $title, $user, $message, $summary, $medit );
111120
112 - # $title = Title::newFromText( $sub, NS_CATEGORY );
113 - # $message = wfMsg( 'categorywatch-catmoveout', $page, $this->friendlyCat( $sub ), $this->friendlyCat( $add ) );
114 - # $this->notifyWatchers( $title, $user, $message, $summary, $medit );
115121 } else {
 122+
116123 foreach ( $add as $cat ) {
117124 $title = Title::newFromText( $cat, NS_CATEGORY );
118125 $message = wfMsg( 'categorywatch-catadd', $page, $this->friendlyCat( $cat ) );
119126 $this->notifyWatchers( $title, $user, $message, $summary, $medit );
120127 }
121128
122 - # foreach ( $sub as $cat ) {
123 - # $title = Title::newFromText( $cat, NS_CATEGORY );
124 - # $message = wfMsg( 'categorywatch-catsub', $page, $this->friendlyCat( $cat ) );
125 - # $this->notifyWatchers( $title, $user, $message, $summary, $medit );
126 - # }
127129 }
128130 }
129131

Status & tagging log