Index: trunk/extensions/WhoIsWatching/SpecialWhoIsWatching_body.php |
— | — | @@ -0,0 +1,70 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class SpecialWhoIsWatching extends SpecialPage |
| 5 | +{ |
| 6 | + function SpecialWhoIsWatching() { |
| 7 | + SpecialPage::SpecialPage("SpecialWhoIsWatching"); |
| 8 | + self::loadMessages(); |
| 9 | + return true; |
| 10 | + } |
| 11 | + |
| 12 | + function loadMessages() { |
| 13 | + static $messagesLoaded = false; |
| 14 | + global $wgMessageCache; |
| 15 | + if ($messagesLoaded) return; |
| 16 | + $messagesLoaded = true; |
| 17 | + |
| 18 | + |
| 19 | + $allMessages = array( |
| 20 | + 'en' => array( |
| 21 | + 'specialwhoiswatching' => 'Who Is Watching a wiki page', |
| 22 | + 'specialwhoiswatchingthepage' => 'Who is watching %s', |
| 23 | + 'specialwhoiswatchingusage' => 'This special page cannot be used on its own. Please use the |
| 24 | +[[MediaWiki:Number_of_watching_users_pageview]] to define an entry point to this special page.', |
| 25 | + ) |
| 26 | + ); |
| 27 | + |
| 28 | + foreach ( $allMessages as $lang => $langMessages ) { |
| 29 | + $wgMessageCache->addMessages( $langMessages, $lang ); |
| 30 | + } |
| 31 | + return true; |
| 32 | + } |
| 33 | + |
| 34 | + function execute($par) { |
| 35 | + global $wgRequest, $wgOut, $wgCanonicalNamespaceNames; |
| 36 | + |
| 37 | + $this->setHeaders(); |
| 38 | + $wgOut->setPagetitle(wfMsg('specialwhoiswatching')); |
| 39 | + |
| 40 | + $title = $wgRequest->getVal('page'); |
| 41 | + if (!isset($title)) { |
| 42 | + $wgOut->addWikiText(wfMsg('specialwhoiswatchingusage')); |
| 43 | + return; |
| 44 | + } |
| 45 | + |
| 46 | + $ns = $wgRequest->getVal('ns'); |
| 47 | + $ns = str_replace(' ', '_', $ns); |
| 48 | + if ($ns == '') |
| 49 | + $ns = NS_MAIN; |
| 50 | + else { |
| 51 | + foreach ( $wgCanonicalNamespaceNames as $i => $text ) { |
| 52 | + if (preg_match("/$ns/i", $text)) { |
| 53 | + $ns = $i; |
| 54 | + break; |
| 55 | + } |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + $pageTitle = Title::makeTitle($ns, $title); |
| 60 | + $wiki_title = $pageTitle->getPrefixedText(); |
| 61 | + $wiki_path = $pageTitle->getPrefixedDBkey(); |
| 62 | + $wgOut->addWikiText("== ".sprintf(wfMsg('specialwhoiswatchingthepage'), "[[$wiki_path|$wiki_title]] ==")); |
| 63 | + |
| 64 | + $dbr = wfGetDB( DB_SLAVE ); |
| 65 | + $res = $dbr->select( 'watchlist', 'wl_user', array('wl_namespace'=>$ns, 'wl_title'=>$title), __METHOD__); |
| 66 | + for ( $row = $dbr->fetchObject($res); $row; $row = $dbr->fetchObject($res)) { |
| 67 | + $u = User::newFromID($row->wl_user); |
| 68 | + $wgOut->addWikiText("[[:user:" . $u->getName() . "|" . $u->getRealName() . "]]"); |
| 69 | + } |
| 70 | + } |
| 71 | +} |
Index: trunk/extensions/WhoIsWatching/SpecialWhoIsWatching.php |
— | — | @@ -0,0 +1,14 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +$wgExtensionCredits['specialpage'][] = array( |
| 5 | + 'version' => '0.1', |
| 6 | + 'name' => 'WhoIsWatching', |
| 7 | + 'author' => 'Paul Grinberg', |
| 8 | + 'email' => 'gri6507 at yahoo dot com', |
| 9 | + 'url' => 'http://www.mediawiki.org/wiki/Extension:WhoIsWatching', |
| 10 | + 'description' => 'Provides a listing of usernames watching a wiki page' |
| 11 | +); |
| 12 | + |
| 13 | +$wgAutoloadClasses['SpecialWhoIsWatching'] = dirname(__FILE__) . '/SpecialWhoIsWatching_body.php'; |
| 14 | +$wgSpecialPages['SpecialWhoIsWatching'] = 'SpecialWhoIsWatching'; |
| 15 | +$wgHooks['LoadAllMessages'][] = 'SpecialWhoIsWatching::loadMessages'; |