Index: trunk/extensions/CategoryWatch/CategoryWatch.php |
— | — | @@ -1,4 +1,5 @@ |
2 | 2 | <?php |
| 3 | +if ( !defined( 'MEDIAWIKI' ) ) die( 'Not an entry point.' ); |
3 | 4 | /** |
4 | 5 | * CategoryWatch extension |
5 | 6 | * - Extends watchlist functionality to include notification about membership changes of watched categories |
— | — | @@ -13,13 +14,18 @@ |
14 | 15 | * @licence GNU General Public Licence 2.0 or later |
15 | 16 | */ |
16 | 17 | |
17 | | -if ( !defined( 'MEDIAWIKI' ) ) die( 'Not an entry point.' ); |
| 18 | +define( 'CATEGORYWATCH_VERSION', '1.2.0, 2010-07-15' ); |
18 | 19 | |
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 |
21 | 21 | $wgCategoryWatchNotifyEditor = true; |
22 | | -$wgCategoryWatchUseAutoCat = false; |
23 | 22 | |
| 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 | + |
24 | 30 | $wgExtensionFunctions[] = 'wfSetupCategoryWatch'; |
25 | 31 | $wgExtensionCredits['other'][] = array( |
26 | 32 | 'path' => __FILE__, |
— | — | @@ -43,7 +49,7 @@ |
44 | 50 | * Get a list of categories before article updated |
45 | 51 | */ |
46 | 52 | function onArticleSave( &$article, &$user, &$text ) { |
47 | | - global $wgCategoryWatchUseAutoCat; |
| 53 | + global $wgCategoryWatchUseAutoCat, $wgCategoryWatchUseAutoCatRealName; |
48 | 54 | |
49 | 55 | $this->before = array(); |
50 | 56 | $dbr = wfGetDB( DB_SLAVE ); |
— | — | @@ -66,8 +72,9 @@ |
67 | 73 | |
68 | 74 | # Insert an entry into watchlist for each |
69 | 75 | 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 ) ); |
72 | 79 | $dbr->insert( $wtbl, array( 'wl_user' => $row[0], 'wl_namespace' => NS_CATEGORY, 'wl_title' => $wl_title ) ); |
73 | 80 | } |
74 | 81 | $dbr->freeResult( $res ); |
— | — | @@ -80,6 +87,7 @@ |
81 | 88 | * Find changes in categorisation and send messages to watching users |
82 | 89 | */ |
83 | 90 | function onArticleSaveComplete( &$article, &$user, &$text, &$summary, &$medit ) { |
| 91 | + |
84 | 92 | # Get cats after update |
85 | 93 | $this->after = array(); |
86 | 94 | $dbr = wfGetDB( DB_SLAVE ); |
— | — | @@ -101,6 +109,7 @@ |
102 | 110 | $page = "$pagename ($pageurl)"; |
103 | 111 | |
104 | 112 | if ( count( $add ) == 1 && count( $sub ) == 1 ) { |
| 113 | + |
105 | 114 | $add = array_shift( $add ); |
106 | 115 | $sub = array_shift( $sub ); |
107 | 116 | |
— | — | @@ -108,21 +117,14 @@ |
109 | 118 | $message = wfMsg( 'categorywatch-catmovein', $page, $this->friendlyCat( $add ), $this->friendlyCat( $sub ) ); |
110 | 119 | $this->notifyWatchers( $title, $user, $message, $summary, $medit ); |
111 | 120 | |
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 ); |
115 | 121 | } else { |
| 122 | + |
116 | 123 | foreach ( $add as $cat ) { |
117 | 124 | $title = Title::newFromText( $cat, NS_CATEGORY ); |
118 | 125 | $message = wfMsg( 'categorywatch-catadd', $page, $this->friendlyCat( $cat ) ); |
119 | 126 | $this->notifyWatchers( $title, $user, $message, $summary, $medit ); |
120 | 127 | } |
121 | 128 | |
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 | | - # } |
127 | 129 | } |
128 | 130 | } |
129 | 131 | |