Index: trunk/extensions/Watchers/language/en.php |
— | — | @@ -0,0 +1,20 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * English language file for the 'Watchers' extension |
| 5 | + */ |
| 6 | + |
| 7 | +// We will add messages to the global cache |
| 8 | +global $wgMessageCache; |
| 9 | + |
| 10 | +// Add messages |
| 11 | +$wgMessageCache->addMessages( |
| 12 | + array( |
| 13 | + 'watchers_link_title' => "Who watches this page?", |
| 14 | + 'watchers_error_article' => "<b>Error:</b> Article does not exist.", |
| 15 | + 'watchers_header' => "People who are watching \"$1\"", |
| 16 | + 'watchers_noone_watches' => "Noone watches this page.", |
| 17 | + 'watchers_x_or_more' => "$1 or more people are watching this page.", |
| 18 | + 'watchers_less_than_x' => "Less than $1 people watch this page.", |
| 19 | + ) |
| 20 | +); |
| 21 | +?> |
Property changes on: trunk/extensions/Watchers/language/en.php |
___________________________________________________________________ |
Added: svn:keywords |
1 | 22 | + Author Date Id Revision |
Added: svn:eol-style |
2 | 23 | + native |
Index: trunk/extensions/Watchers/Watchers.php |
— | — | @@ -0,0 +1,186 @@ |
| 2 | +<?php |
| 3 | +/* |
| 4 | +Creates a link in the toolbox to a special page showing who watches that page |
| 5 | + |
| 6 | +Usage: |
| 7 | +Add |
| 8 | + include_once ( "extensions/Watchers/Watchers.php" ) ; |
| 9 | +to your LocalSettings.php. It should be (one of) the first extension(s) to include, as it adds to the toolbox in the sidebar. |
| 10 | +Otherextensions might add a new box there, putting the "Watchers" link in the wrong box. |
| 11 | + |
| 12 | +After inclusion in LocalSettings.php, you can set $wgWatchersLimit |
| 13 | +to a number to anonymize results ("X or more" / "Less that X" people watching this page) |
| 14 | +*/ |
| 15 | + |
| 16 | + |
| 17 | +if( !defined( 'MEDIAWIKI' ) ) die(); |
| 18 | + |
| 19 | +# Integrating into the MediaWiki environment |
| 20 | + |
| 21 | +$wgExtensionCredits['Watchers'][] = array( |
| 22 | + 'name' => 'Watchers', |
| 23 | + 'description' => 'An extension show who is watching a page.', |
| 24 | + 'author' => 'Magnus Manske' |
| 25 | +); |
| 26 | + |
| 27 | +$wgExtensionFunctions[] = 'wfWatchersExtension'; |
| 28 | + |
| 29 | + |
| 30 | +# Hooks |
| 31 | +$wgHooks['MonoBookTemplateToolboxEnd'][] = 'wfWatchersExtensionAfterToolbox'; |
| 32 | + |
| 33 | +# Global variables |
| 34 | + |
| 35 | +$wgWatchersLimit = NULL ; # Set this to a number to anonymize results ("X or more" / "Less that X" people watching this page) |
| 36 | +$wgWatchersAddCache = false ; # Internal use |
| 37 | + |
| 38 | + |
| 39 | +/** |
| 40 | + * Text adding function |
| 41 | +*/ |
| 42 | +function wfWatchersAddCache() { # Checked for HTML and MySQL insertion attacks |
| 43 | + global $wgWatchersAddCache , $wgUserTogglesEn, $wgDefaultUserOptions; |
| 44 | + if( $wgWatchersAddCache ) { |
| 45 | + return; |
| 46 | + } |
| 47 | + $wgWatchersAddCache = true; |
| 48 | + |
| 49 | + // Default language is english |
| 50 | + require_once('language/en.php'); |
| 51 | + |
| 52 | + global $wgLanguageCode; |
| 53 | + $filename = 'language/' . addslashes($wgLanguageCode) . '.php' ; |
| 54 | + // inclusion might fail :p |
| 55 | + include( $filename ); |
| 56 | +} |
| 57 | + |
| 58 | + |
| 59 | +/** |
| 60 | + * Display link in toolbox |
| 61 | +*/ |
| 62 | +function wfWatchersExtensionAfterToolbox( &$tpl ) { # Checked for HTML and MySQL insertion attacks |
| 63 | + global $wgTitle; |
| 64 | + if( $wgTitle->isTalkPage() ) { |
| 65 | + # No talk pages please |
| 66 | + return; |
| 67 | + } |
| 68 | + if( $wgTitle->getNamespace() < 0 ) { |
| 69 | + # No special pages please |
| 70 | + return; |
| 71 | + } |
| 72 | + |
| 73 | + wfWatchersAddCache(); |
| 74 | + |
| 75 | + |
| 76 | + echo '<li id="t-watchers"><a href="' ; |
| 77 | + $nt = Title::newFromText ( 'watchers' , NS_SPECIAL ) ; |
| 78 | + echo $nt->escapeLocalURL ( 'article=' . $wgTitle->getArticleID() ); |
| 79 | + echo '">' ; |
| 80 | + echo wfMsg('watchers_link_title'); |
| 81 | + echo "</a></li>\n" ; |
| 82 | + |
| 83 | +} |
| 84 | + |
| 85 | +/** |
| 86 | + * The special page |
| 87 | +*/ |
| 88 | +function wfWatchersExtension() { |
| 89 | + global $IP, $wgMessageCache; |
| 90 | + wfWatchersAddCache(); |
| 91 | + |
| 92 | + // FIXME : i18n |
| 93 | + $wgMessageCache->addMessage( 'watchers', 'Watchers' ); |
| 94 | + |
| 95 | + require_once $IP.'/includes/SpecialPage.php'; |
| 96 | + |
| 97 | + class SpecialWatchers extends SpecialPage { |
| 98 | + |
| 99 | + /** |
| 100 | + * Constructor |
| 101 | + */ |
| 102 | + function SpecialWatchers() { |
| 103 | + SpecialPage::SpecialPage( 'Watchers' ); |
| 104 | + $this->includable( true ); |
| 105 | + } |
| 106 | + |
| 107 | + /** |
| 108 | + * Renders the special page |
| 109 | + */ |
| 110 | + function execute( $par = null ) { |
| 111 | + global $wgOut , $wgRequest , $wgUser , $wgWatchersLimit ; |
| 112 | + |
| 113 | + $out = "" ; |
| 114 | + $fname = "wfWatchersExtension::execute" ; |
| 115 | + $sk =& $wgUser->getSkin() ; |
| 116 | + $id = $wgRequest->getInt ( 'article' , 0 ) ; |
| 117 | + $title = Title::newFromID ( $id ) ; |
| 118 | + |
| 119 | + # Check for valid title |
| 120 | + if ( $id == 0 || $title->getArticleID() <= 0 ) { |
| 121 | + $out = wfMsg ( 'watchers_error_article' ) ; |
| 122 | + $this->setHeaders(); |
| 123 | + $wgOut->addHtml( $out ); |
| 124 | + return ; |
| 125 | + } |
| 126 | + |
| 127 | + $link1 = $sk->makeLinkObj( $title ); |
| 128 | + $out .= "<h2>" . wfMsg ( 'watchers_header' , $link1 ) . "</h2>" ; |
| 129 | + |
| 130 | + $dbr =& wfGetDB( DB_SLAVE ); |
| 131 | + $conds = array ( |
| 132 | + 'wl_namespace' => $title->getNamespace() , |
| 133 | + 'wl_title' => $title->getDBkey() , |
| 134 | + ) ; |
| 135 | + if ( $wgWatchersLimit != NULL ) { |
| 136 | + $res = $dbr->select( |
| 137 | + /* FROM */ 'watchlist', |
| 138 | + /* SELECT */ 'count(wl_user) AS num', |
| 139 | + /* WHERE */ $conds, |
| 140 | + $fname |
| 141 | + ); |
| 142 | + $o = $dbr->fetchObject( $res ) ; |
| 143 | + if ( $o->num >= $wgWatchersLimit ) { |
| 144 | + $out .= "<p>" . wfMsg ( 'watchers_x_or_more' , $wgWatchersLimit ) . "</p>\n" ; |
| 145 | + } else { |
| 146 | + $out .= "<p>" . wfMsg ( 'watchers_less_than_x' , $wgWatchersLimit ) . "</p>\n" ; |
| 147 | + } |
| 148 | + } else { |
| 149 | + $res = $dbr->select( |
| 150 | + /* FROM */ 'watchlist', |
| 151 | + /* SELECT */ 'wl_user', |
| 152 | + /* WHERE */ $conds, |
| 153 | + $fname |
| 154 | + ); |
| 155 | + $user_ids = array () ; |
| 156 | + while ( $o = $dbr->fetchObject( $res ) ) { |
| 157 | + $user_ids[] = $o->wl_user ; |
| 158 | + } |
| 159 | + $dbr->freeResult( $res ); |
| 160 | + |
| 161 | + if ( count ( $user_ids ) == 0 ) { |
| 162 | + $out .= "<p>" . wfMsg ( 'watchers_noone_watches' ) . "</p>" ; |
| 163 | + } else { |
| 164 | + $out .= "<ol>" ; |
| 165 | + foreach ( $user_ids AS $uid ) { |
| 166 | + $u = new User ; |
| 167 | + $u->setID ( $uid ) ; |
| 168 | + $u->loadFromDatabase() ; |
| 169 | + $link = $sk->makeLinkObj ( $u->getUserPage() ) ; |
| 170 | + $out .= "<li>" . $link . "</li>\n" ; |
| 171 | + } |
| 172 | + $out .= "</ol>" ; |
| 173 | + } |
| 174 | + } |
| 175 | + |
| 176 | + $this->setHeaders(); |
| 177 | + $wgOut->addHtml( $out ); |
| 178 | + } |
| 179 | + |
| 180 | + |
| 181 | + } # end of class |
| 182 | + |
| 183 | + SpecialPage::addPage( new SpecialWatchers ); |
| 184 | +} |
| 185 | + |
| 186 | + |
| 187 | +?> |
\ No newline at end of file |
Property changes on: trunk/extensions/Watchers/Watchers.php |
___________________________________________________________________ |
Added: svn:keywords |
1 | 188 | + Author Date Id Revision |
Added: svn:eol-style |
2 | 189 | + native |