Index: trunk/extensions/WhosOnline/WhosOnlineSpecialPage.php |
— | — | @@ -1,31 +1,30 @@ |
2 | 2 | <?php |
3 | 3 | /** |
| 4 | + * @file |
4 | 5 | * @ingroup Extensions |
5 | | - * |
6 | 6 | * @author Maciej Brencz <macbre(at)-spam-wikia.com> |
7 | 7 | */ |
8 | 8 | |
9 | | -if (!defined('MEDIAWIKI')) { |
| 9 | +if ( !defined( 'MEDIAWIKI' ) ) { |
10 | 10 | exit( 1 ); |
11 | 11 | } |
12 | 12 | |
13 | 13 | class PagerWhosOnline extends IndexPager { |
14 | 14 | function __construct() { |
15 | 15 | parent::__construct(); |
16 | | - |
17 | 16 | $this->mLimit = $this->mDefaultLimit; |
18 | 17 | } |
19 | 18 | |
20 | 19 | function getQueryInfo() { |
21 | 20 | global $wgWhosOnlineShowAnons; |
22 | 21 | |
23 | | - return array ( |
24 | | - 'tables' => array('online'), |
25 | | - 'fields' => array('username'), |
26 | | - 'options' => array('ORDER BY' => 'timestamp DESC'), |
| 22 | + return array( |
| 23 | + 'tables' => array( 'online' ), |
| 24 | + 'fields' => array( 'username' ), |
| 25 | + 'options' => array( 'ORDER BY' => 'timestamp DESC' ), |
27 | 26 | 'conds' => $wgWhosOnlineShowAnons |
28 | 27 | ? array() |
29 | | - : array('userid != 0') |
| 28 | + : array( 'userid != 0' ) |
30 | 29 | ); |
31 | 30 | } |
32 | 31 | |
— | — | @@ -37,8 +36,8 @@ |
38 | 37 | $conds = isset( $info['conds'] ) ? $info['conds'] : array(); |
39 | 38 | $options = isset( $info['options'] ) ? $info['options'] : array(); |
40 | 39 | |
41 | | - $options['LIMIT'] = intval($limit); |
42 | | - $options['OFFSET'] = intval($offset); |
| 40 | + $options['LIMIT'] = intval( $limit ); |
| 41 | + $options['OFFSET'] = intval( $offset ); |
43 | 42 | |
44 | 43 | $res = $this->mDb->select( $tables, $fields, $conds, __METHOD__, $options ); |
45 | 44 | |
— | — | @@ -49,20 +48,26 @@ |
50 | 49 | return 'username'; // dummy |
51 | 50 | } |
52 | 51 | |
53 | | - function formatRow($row) { |
54 | | - $userPageLink = Title::makeTitle(NS_USER, $row->username)->getFullURL(); |
| 52 | + function formatRow( $row ) { |
| 53 | + $userPageLink = Title::makeTitle( NS_USER, $row->username )->getFullURL(); |
55 | 54 | |
56 | | - return '<li><a href="'.htmlspecialchars($userPageLink).'">' . htmlspecialchars($row->username) . '</a></li>'; |
| 55 | + return '<li><a href="' . htmlspecialchars( $userPageLink ) . '">' . |
| 56 | + htmlspecialchars( $row->username ) . '</a></li>'; |
57 | 57 | } |
58 | 58 | |
59 | 59 | // extra methods |
60 | 60 | function countUsersOnline() { |
61 | | - wfProfileIn(__METHOD__); |
| 61 | + wfProfileIn( __METHOD__ ); |
62 | 62 | |
63 | | - $row = $this->mDb->selectRow('online', 'count(*) as cnt', 'userid != 0', __METHOD__); |
| 63 | + $row = $this->mDb->selectRow( |
| 64 | + 'online', |
| 65 | + 'COUNT(*) AS cnt', |
| 66 | + 'userid != 0', |
| 67 | + __METHOD__ |
| 68 | + ); |
64 | 69 | $users = (int) $row->cnt; |
65 | 70 | |
66 | | - wfProfileOut(__METHOD__); |
| 71 | + wfProfileOut( __METHOD__ ); |
67 | 72 | |
68 | 73 | return $users; |
69 | 74 | } |
— | — | @@ -73,50 +78,73 @@ |
74 | 79 | return wfViewPrevNext( |
75 | 80 | $this->mOffset, |
76 | 81 | $this->mLimit, |
77 | | - $wgContLang->specialpage('WhosOnline'), |
| 82 | + $wgContLang->specialpage( 'WhosOnline' ), |
78 | 83 | '', |
79 | | - $this->countUsersOnline() < ($this->mLimit + $this->mOffset) // show next link |
| 84 | + $this->countUsersOnline() < ( $this->mLimit + $this->mOffset ) // show next link |
80 | 85 | ); |
81 | 86 | } |
82 | 87 | } |
83 | 88 | |
84 | | -class SpecialWhosOnline extends SpecialPage { |
85 | | - public function SpecialWhosOnline() { |
86 | | - parent::__construct('WhosOnline' ); |
| 89 | +class SpecialWhosOnline extends IncludableSpecialPage { |
| 90 | + public function __construct() { |
| 91 | + parent::__construct( 'WhosOnline' ); |
87 | 92 | } |
88 | 93 | |
89 | | - |
90 | 94 | // get list of logged-in users being online |
91 | 95 | protected function getAnonsOnline() { |
92 | | - wfProfileIn(__METHOD__); |
| 96 | + wfProfileIn( __METHOD__ ); |
93 | 97 | |
94 | | - $dbr = wfGetDB(DB_SLAVE); |
| 98 | + $dbr = wfGetDB( DB_SLAVE ); |
95 | 99 | |
96 | | - $row = $dbr->selectRow('online', 'count(*) as cnt', 'userid = 0', __METHOD__); |
| 100 | + $row = $dbr->selectRow( |
| 101 | + 'online', |
| 102 | + 'COUNT(*) AS cnt', |
| 103 | + 'userid = 0', |
| 104 | + __METHOD__ |
| 105 | + ); |
97 | 106 | $guests = (int) $row->cnt; |
98 | 107 | |
99 | | - wfProfileOut(__METHOD__); |
| 108 | + wfProfileOut( __METHOD__ ); |
100 | 109 | |
101 | 110 | return $guests; |
102 | 111 | } |
103 | 112 | |
104 | 113 | public function execute( $para ) { |
105 | | - global $wgRequest, $wgOut, $wgDBname; |
| 114 | + global $wgOut, $wgDBname; |
106 | 115 | |
107 | | - |
108 | | - |
109 | 116 | $db = wfGetDB( DB_MASTER ); |
110 | 117 | $db->selectDB( $wgDBname ); |
111 | | - $old = gmdate("YmdHis", time() - 3600); |
112 | | - $db->delete('online', array('timestamp < "'.$old.'"'), __METHOD__); |
| 118 | + $old = gmdate( 'YmdHis', time() - 3600 ); |
| 119 | + $db->delete( 'online', array( 'timestamp < "' . $old . '"' ), __METHOD__ ); |
113 | 120 | |
114 | 121 | $this->setHeaders(); |
115 | 122 | |
116 | 123 | $pager = new PagerWhosOnline(); |
117 | 124 | |
| 125 | + $showNavigation = !$this->including(); |
| 126 | + if ( $para ) { |
| 127 | + $bits = preg_split( '/\s*,\s*/', trim( $para ) ); |
| 128 | + foreach ( $bits as $bit ) { |
| 129 | + if ( $bit == 'shownav' ) { |
| 130 | + $showNavigation = true; |
| 131 | + } |
| 132 | + if ( is_numeric( $bit ) ) { |
| 133 | + $pager->mLimit = $bit; |
| 134 | + } |
| 135 | + |
| 136 | + $m = array(); |
| 137 | + if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) { |
| 138 | + $pager->mLimit = intval( $m[1] ); |
| 139 | + } |
| 140 | + } |
| 141 | + } |
| 142 | + |
118 | 143 | $body = $pager->getBody(); |
119 | 144 | |
120 | | - $wgOut->addHTML($pager->getNavigationBar()); |
121 | | - $wgOut->addHTML('<ul>'.$body.'</ul>'); |
| 145 | + if ( $showNavigation ) { |
| 146 | + $wgOut->addHTML( $pager->getNavigationBar() ); |
| 147 | + } |
| 148 | + |
| 149 | + $wgOut->addHTML( '<ul>' . $body . '</ul>' ); |
122 | 150 | } |
123 | 151 | } |
Index: trunk/extensions/WhosOnline/WhosOnline.php |
— | — | @@ -5,56 +5,65 @@ |
6 | 6 | * |
7 | 7 | * @file |
8 | 8 | * @ingroup Extensions |
9 | | - * |
10 | 9 | * @author Maciej Brencz <macbre(at)-spam-wikia.com> - minor fixes and improvements |
11 | 10 | * @author ChekMate Security Group - original code |
12 | 11 | * @see http://www.chekmate.org/wiki/index.php/MW:_Whos_Online_Extension |
13 | 12 | * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
14 | 13 | */ |
15 | 14 | |
16 | | -$wgWhosOnlineShowAnons = FALSE; // Showing anonymous users IP addresses can be a security threat! |
| 15 | +/** |
| 16 | + * Protect against arbitrary execution |
| 17 | + * This line must be present before any global variable is referenced. |
| 18 | + */ |
| 19 | +if ( !defined( 'MEDIAWIKI' ) ) { |
| 20 | + die( 'This is not a valid entry point.' ); |
| 21 | +} |
17 | 22 | |
18 | | -$wgHooks['BeforePageDisplay'][] = 'wfWhosOnline_update_data'; |
19 | | - |
| 23 | +// Extension credits that show up on Special:Version |
20 | 24 | $wgExtensionCredits['other'][] = array( |
21 | 25 | 'path' => __FILE__, |
22 | 26 | 'name' => 'WhosOnline', |
23 | | - 'version' => '1.3', |
| 27 | + 'version' => '1.3.1', |
24 | 28 | 'author' => 'Maciej Brencz', |
25 | 29 | 'descriptionmsg' => 'whosonline-desc', |
26 | 30 | 'url' => 'http://www.mediawiki.org/wiki/Extension:WhosOnline', |
27 | 31 | ); |
28 | 32 | |
29 | | -$dir = dirname(__FILE__) . '/'; |
| 33 | +// Showing anonymous users' IP addresses can be a security threat! |
| 34 | +$wgWhosOnlineShowAnons = false; |
| 35 | + |
| 36 | +// Set up the special page |
| 37 | +$dir = dirname( __FILE__ ) . '/'; |
30 | 38 | $wgAutoloadClasses['SpecialWhosOnline'] = $dir . 'WhosOnlineSpecialPage.php'; |
31 | 39 | $wgExtensionMessagesFiles['WhosOnline'] = $dir . 'WhosOnline.i18n.php'; |
32 | 40 | $wgExtensionAliasesFiles['WhosOnline'] = $dir . 'WhosOnline.alias.php'; |
33 | 41 | $wgSpecialPages['WhosOnline'] = 'SpecialWhosOnline'; |
34 | 42 | |
| 43 | +$wgHooks['BeforePageDisplay'][] = 'wfWhosOnline_update_data'; |
35 | 44 | // update online data |
36 | 45 | function wfWhosOnline_update_data() { |
37 | 46 | global $wgUser, $wgDBname; |
38 | 47 | |
39 | | - wfProfileIn(__METHOD__); |
| 48 | + wfProfileIn( __METHOD__ ); |
40 | 49 | |
41 | 50 | // write to DB (use master) |
42 | | - $db = wfGetDB(DB_MASTER); |
| 51 | + $db = wfGetDB( DB_MASTER ); |
43 | 52 | $db->selectDB( $wgDBname ); |
44 | 53 | |
45 | | - $now = gmdate("YmdHis", time()); |
| 54 | + $now = gmdate( 'YmdHis', time() ); |
46 | 55 | |
47 | 56 | // row to insert to table |
48 | | - $row = array ( |
| 57 | + $row = array( |
49 | 58 | 'userid' => $wgUser->getID(), |
50 | 59 | 'username' => $wgUser->getName(), |
51 | 60 | 'timestamp' => $now |
52 | 61 | ); |
53 | 62 | |
54 | 63 | $ignore = $db->ignoreErrors( true ); |
55 | | - $db->insert('online', $row, __METHOD__, 'DELAYED'); |
| 64 | + $db->insert( 'online', $row, __METHOD__, 'DELAYED' ); |
56 | 65 | $db->ignoreErrors( $ignore ); |
57 | 66 | |
58 | | - wfProfileOut(__METHOD__); |
| 67 | + wfProfileOut( __METHOD__ ); |
59 | 68 | |
60 | 69 | return true; |
61 | 70 | } |