Index: trunk/extensions/Watchers/Watchers_body.php |
— | — | @@ -21,82 +21,82 @@ |
22 | 22 | /** |
23 | 23 | * Renders the special page |
24 | 24 | */ |
25 | | - function execute( $parameters ) { |
26 | | - global $wgOut , $wgRequest , $wgUser , $wgWatchersLimit; |
| 25 | + function execute( $par ) { |
| 26 | + global $wgOut, $wgRequest, $wgUser, $wgWatchersLimit; |
27 | 27 | |
28 | 28 | wfLoadExtensionMessages( 'Watchers' ); |
29 | 29 | |
30 | | - $out = ""; |
31 | | - $fname = "wfWatchersExtension::execute"; |
32 | | - $sk =&$wgUser->getSkin(); |
33 | | - $id = $wgRequest->getInt ( 'article' , 0 ); |
34 | | - $title = Title::newFromID ( $id ); |
| 30 | + $this->setHeaders(); |
35 | 31 | |
36 | | - # Check for valid title |
37 | | - if ( $id == 0 || $title->getArticleID() <= 0 ) { |
38 | | - $out = wfMsg ( 'watchers_error_article' ); |
39 | | - $this->setHeaders(); |
40 | | - $wgOut->addHTML( $out ); |
41 | | - return; |
| 32 | + $page = $wgRequest->getVal( 'page', $par ); |
| 33 | + if ( $page !== null ) { |
| 34 | + $title = Title::newFromText( $page ); |
| 35 | + if ( !$title instanceof Title ) { |
| 36 | + $wgOut->addWikiMsg( 'watchers-error-invalid-page', $page ); |
| 37 | + return; |
| 38 | + } |
| 39 | + } else { |
| 40 | + # b/c |
| 41 | + $id = $wgRequest->getInt( 'article', 0 ); |
| 42 | + $title = Title::newFromID( $id ); |
| 43 | + |
| 44 | + # Check for valid title |
| 45 | + if ( $id == 0 || $title->getArticleID() <= 0 ) { |
| 46 | + $wgOut->addWikiMsg( 'watchers_error_article' ); |
| 47 | + return; |
| 48 | + } |
42 | 49 | } |
43 | 50 | |
44 | 51 | $dbr = wfGetDB( DB_SLAVE ); |
45 | | - $conds = array ( |
46 | | - 'wl_namespace' => $title->getNamespace() , |
47 | | - 'wl_title' => $title->getDBkey() , |
| 52 | + $conds = array( |
| 53 | + 'wl_namespace' => $title->getNamespace(), |
| 54 | + 'wl_title' => $title->getDBkey(), |
48 | 55 | ); |
49 | 56 | |
50 | | - $watcherscountquery = $dbr->select( |
| 57 | + $watcherscount = $dbr->selectField( |
51 | 58 | /* FROM */ 'watchlist', |
52 | 59 | /* SELECT */ 'count(wl_user) AS num', |
53 | 60 | /* WHERE */ $conds, |
54 | | - $fname |
| 61 | + __METHOD__ |
55 | 62 | ); |
56 | 63 | |
57 | | - $o = $dbr->fetchObject( $watcherscountquery ); |
58 | | - $watcherscount = $o->num; |
| 64 | + if ( $wgUser->isAllowed( 'watchers-list' ) ) { |
| 65 | + if ( $watcherscount == 0 ) { |
| 66 | + $wgOut->addWikiMsg( 'watchers_noone_watches', $title->getPrefixedText() ); |
| 67 | + } else { |
| 68 | + $wgOut->wrapWikiMsg( '<h2>$1</h2>', array( 'watchers_header', $title->getPrefixedText(), $watcherscount ) ); |
59 | 69 | |
60 | | - $link1 = $sk->makeLinkObj( $title ); |
61 | | - $out .= "<h2>" . wfMsgExt( 'watchers_header' , array( 'parsemag' ), $link1, $watcherscount ) . "</h2>"; |
| 70 | + $res = $dbr->select( |
| 71 | + /* FROM */ 'watchlist', |
| 72 | + /* SELECT */ 'wl_user', |
| 73 | + /* WHERE */ $conds, |
| 74 | + __METHOD__ |
| 75 | + ); |
62 | 76 | |
63 | | - if ( $wgWatchersLimit != null ) { |
| 77 | + $sk = $wgUser->getSkin(); |
64 | 78 | |
65 | | - if ( $watcherscount >= $wgWatchersLimit ) { |
66 | | - $out .= "<p>" . wfMsgExt( 'watchers_x_or_more', array( 'parsemag' ), $wgWatchersLimit ) . "</p>\n"; |
67 | | - } else { |
68 | | - $out .= "<p>" . wfMsgExt( 'watchers_less_than_x', array( 'parsemag' ), $wgWatchersLimit ) . "</p>\n"; |
| 79 | + $wgOut->addHTML( "<ol>\n" ); |
| 80 | + foreach ( $res AS $row ) { |
| 81 | + $u = User::newFromID( $row->wl_user ); |
| 82 | + $link = $sk->link( $u->getUserPage(), htmlspecialchars( $u->getName() ) ); |
| 83 | + $wgOut->addHTML( "<li>" . $link . "</li>\n" ); |
| 84 | + } |
| 85 | + $wgOut->addHTML( "</ol>\n" ); |
69 | 86 | } |
70 | 87 | } else { |
71 | | - $res = $dbr->select( |
72 | | - /* FROM */ 'watchlist', |
73 | | - /* SELECT */ 'wl_user', |
74 | | - /* WHERE */ $conds, |
75 | | - $fname |
76 | | - ); |
77 | | - $user_ids = array (); |
78 | | - while ( $o = $dbr->fetchObject( $res ) ) { |
79 | | - $user_ids[] = $o->wl_user; |
80 | | - } |
81 | | - $dbr->freeResult( $res ); |
82 | | - |
83 | | - if ( count ( $user_ids ) == 0 ) { |
84 | | - $out .= "<p>" . wfMsg ( 'watchers_noone_watches' ) . "</p>"; |
| 88 | + if ( $wgWatchersLimit === null ) { |
| 89 | + if ( $watcherscount == 0 ) { |
| 90 | + $wgOut->addWikiMsg( 'watchers_noone_watches', $title->getPrefixedText() ); |
| 91 | + } else { |
| 92 | + $wgOut->addWikiMsg( 'watchers-num', $watcherscount, $title->getPrefixedText() ); |
| 93 | + } |
85 | 94 | } else { |
86 | | - $out .= "<ol>"; |
87 | | - foreach ( $user_ids AS $uid ) { |
88 | | - $u = new User; |
89 | | - $u->setID ( $uid ); |
90 | | - $u->loadFromDatabase(); |
91 | | - $link = $sk->makeLinkObj ( $u->getUserPage() ); |
92 | | - $out .= "<li>" . $link . "</li>\n"; |
| 95 | + if ( $watcherscount >= $wgWatchersLimit ) { |
| 96 | + $wgOut->addWikiMsg( 'watchers_x_or_more', $wgWatchersLimit, $title->getPrefixedText() ); |
| 97 | + } else { |
| 98 | + $wgOut->addWikiMsg( 'watchers_less_than_x', $wgWatchersLimit, $title->getPrefixedText() ); |
93 | 99 | } |
94 | | - $out .= "</ol>"; |
95 | 100 | } |
96 | 101 | } |
97 | | - |
98 | | - $dbr->freeResult( $watcherscountquery ); |
99 | | - |
100 | | - $this->setHeaders(); |
101 | | - $wgOut->addHTML( $out ); |
102 | 102 | } |
103 | 103 | } |
Index: trunk/extensions/Watchers/Watchers.i18n.php |
— | — | @@ -2,8 +2,9 @@ |
3 | 3 | /** |
4 | 4 | * Internationalisation file for extension Watchers. |
5 | 5 | * |
6 | | - * @addtogroup Extensions |
7 | | -*/ |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
| 8 | + */ |
8 | 9 | |
9 | 10 | $messages = array(); |
10 | 11 | |
— | — | @@ -12,10 +13,13 @@ |
13 | 14 | 'watchers-desc' => 'Shows [[Special:Watchers|which users have a page on their watchlist]]', |
14 | 15 | 'watchers_link_title' => 'Who watches this page?', |
15 | 16 | 'watchers_error_article' => "'''Error:''' Page does not exist.", |
16 | | - 'watchers_header' => '{{PLURAL:$2|User who is|Users who are}} watching "$1"', |
17 | | - 'watchers_noone_watches' => 'No one watches this page.', |
18 | | - 'watchers_x_or_more' => '$1 or more {{PLURAL:$1|users|users}} have this page on their watchlist.', |
19 | | - 'watchers_less_than_x' => 'Fewer than $1 {{PLURAL:$1|users|users}} have this page on their watchlist.', |
| 17 | + 'watchers-error-invalid-page' => "'''Error:''' \"$1\" is an invald page title.", |
| 18 | + 'watchers_header' => '{{PLURAL:$2|User who is|Users who are}} watching "[[:$1]]"', |
| 19 | + 'watchers_noone_watches' => 'No one watches the page [[:$1]].', |
| 20 | + 'watchers_x_or_more' => '$1 or more {{PLURAL:$1|users|users}} have the page [[:$2]] on their watchlist.', |
| 21 | + 'watchers_less_than_x' => 'Fewer than $1 {{PLURAL:$1|users|users}} have the page [[:$2]] on their watchlist.', |
| 22 | + 'watchers-num' => '$1 {{PLURAL:$1|user has|users have}} the page [[:$2]] on {{PLURAL:$1|its|their}} watchlist.', |
| 23 | + 'right-watchers-list' => 'List users watching a specific page on [[Special:Watchers]]', |
20 | 24 | ); |
21 | 25 | |
22 | 26 | /** Message documentation (Message documentation) |
Index: trunk/extensions/Watchers/Watchers.php |
— | — | @@ -7,7 +7,7 @@ |
8 | 8 | Add |
9 | 9 | include_once ( "extensions/Watchers/Watchers.php" ) ; |
10 | 10 | to your LocalSettings.php. It should be (one of) the first extension(s) to include, as it adds to the toolbox in the sidebar. |
11 | | -Otherextensions might add a new box there, putting the "Watchers" link in the wrong box. |
| 11 | +Other extensions might add a new box there, putting the "Watchers" link in the wrong box. |
12 | 12 | |
13 | 13 | After inclusion in LocalSettings.php, you can set $wgWatchersLimit |
14 | 14 | to a number to anonymize results ("X or more" / "Fewer than X" people watching this page) |
— | — | @@ -16,7 +16,7 @@ |
17 | 17 | $wgExtensionCredits['other'][] = array( |
18 | 18 | 'path' => __FILE__, |
19 | 19 | 'name' => 'Watchers', |
20 | | - 'version' => '0.2', |
| 20 | + 'version' => '0.3', |
21 | 21 | 'author' => 'Magnus Manske', |
22 | 22 | 'url' => 'http://www.mediawiki.org/wiki/Extension:Watchers', |
23 | 23 | 'description' => 'An extension to show who is watching a page.', |
— | — | @@ -27,11 +27,19 @@ |
28 | 28 | $wgExtensionAliasesFiles['Watchers'] = $dir . 'Watchers.alias.php'; |
29 | 29 | $wgExtensionMessagesFiles['Watchers'] = $dir . 'Watchers.i18n.php'; |
30 | 30 | $wgAutoloadClasses['SpecialWatchers'] = $dir . 'Watchers_body.php'; |
| 31 | + |
| 32 | +$wgAvailableRights[] = 'watchers-list'; |
| 33 | +$wgGroupPermissions['sysop']['watchers-list'] = true; |
| 34 | + |
31 | 35 | $wgSpecialPages['Watchers'] = 'SpecialWatchers'; |
| 36 | + |
32 | 37 | $wgHooks['SkinTemplateToolboxEnd'][] = 'wfWatchersExtensionAfterToolbox'; |
33 | 38 | |
34 | | -$wgWatchersLimit = null; # Set this to a number to anonymize results ("X or more" / "Less that X" people watching this page) |
35 | | -$wgWatchersAddCache = false ; # Internal use |
| 39 | +/** |
| 40 | + * Set this to a number to anonymize results ("X or more" / "Less that X" people watching this page) |
| 41 | + * This does not affect users having watchers-list right |
| 42 | + */ |
| 43 | +$wgWatchersLimit = null; |
36 | 44 | |
37 | 45 | /** |
38 | 46 | * Display link in toolbox |
— | — | @@ -52,9 +60,9 @@ |
53 | 61 | |
54 | 62 | echo '<li id="t-watchers"><a href="' ; |
55 | 63 | $nt = SpecialPage::getTitleFor( 'Watchers' ); |
56 | | - echo $nt->escapeLocalURL ( 'article=' . $wgTitle->getArticleID() ); |
| 64 | + echo $nt->escapeLocalURL( 'page=' . $wgTitle->getPrefixedDBkey() ); |
57 | 65 | echo '">'; |
58 | | - echo wfMsg('watchers_link_title'); |
| 66 | + echo wfMsgHtml( 'watchers_link_title' ); |
59 | 67 | echo "</a></li>\n"; |
60 | 68 | |
61 | 69 | return true; |