Jack Phoenix has submitted this change and it was merged. Change subject: Version 1.5.0: extension.json file added, miscellaneous tweaks & cleanup ......................................................................
Version 1.5.0: extension.json file added, miscellaneous tweaks & cleanup * Moved hooks into a separate file & class & renamed 'em * Removed wfProfile(In|Out) calls * Swapped $wgOut to $this->getOutput() in the SpecialPage class * Copied comments from the setup file to the main body file because the PHP entry point will eventually go away * Swapped extension type from other to specialpage, since this is a special page Change-Id: If20181790f166c5eff010e0b0eccca8244b8657b --- M WhosOnline.php A WhosOnlineHooks.php M WhosOnlineSpecialPage.php A extension.json 4 files changed, 105 insertions(+), 69 deletions(-) Approvals: Jack Phoenix: Looks good to me, approved jenkins-bot: Verified diff --git a/WhosOnline.php b/WhosOnline.php index 20350cf..5b93b07 100644 --- a/WhosOnline.php +++ b/WhosOnline.php @@ -11,19 +11,11 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later */ -/** - * Protect against arbitrary execution - * This line must be present before any global variable is referenced. - */ -if ( !defined( 'MEDIAWIKI' ) ) { - die( 'This is not a valid entry point.' ); -} - // Extension credits that show up on Special:Version -$wgExtensionCredits['other'][] = array( +$wgExtensionCredits['specialpage'][] = array( 'path' => __FILE__, 'name' => 'WhosOnline', - 'version' => '1.4.0', + 'version' => '1.5.0', 'author' => 'Maciej Brencz', 'descriptionmsg' => 'whosonline-desc', 'url' => 'https://www.mediawiki.org/wiki/Extension:WhosOnline', @@ -33,48 +25,14 @@ // Showing anonymous users' IP addresses can be a security threat! $wgWhosOnlineShowAnons = false; +$wgMessagesDirs['WhosOnline'] = __DIR__ . '/i18n'; +$wgExtensionMessagesFiles['WhosOnlineAlias'] = __DIR__ . '/WhosOnline.alias.php'; + // Set up the special page $wgAutoloadClasses['SpecialWhosOnline'] = __DIR__ . '/WhosOnlineSpecialPage.php'; $wgAutoloadClasses['PagerWhosOnline'] = __DIR__ . '/WhosOnlineSpecialPage.php'; -$wgMessagesDirs['WhosOnline'] = __DIR__ . '/i18n'; -$wgExtensionMessagesFiles['WhosOnlineAlias'] = __DIR__ . '/WhosOnline.alias.php'; $wgSpecialPages['WhosOnline'] = 'SpecialWhosOnline'; -$wgHooks['BeforePageDisplay'][] = 'wfWhosOnline_update_data'; - -// update online data -function wfWhosOnline_update_data() { - global $wgUser; - - // write to DB (use master) - $dbw = wfGetDB( DB_MASTER ); - $now = gmdate( 'YmdHis', time() ); - - // row to insert to table - $row = array( - 'userid' => $wgUser->getId(), - 'username' => $wgUser->getName(), - 'timestamp' => $now - ); - - $method = __METHOD__; - $dbw->onTransactionIdle( function() use ( $dbw, $method, $row ) { - $dbw->upsert( 'online', - $row, - array( array( 'userid', 'username' ) ), - array( 'timestamp' => $row['timestamp'] ), - $method - ); - } ); - - return true; -} - -// Register database operations -$wgHooks['LoadExtensionSchemaUpdates'][] = 'wfWhosOnlineCheckSchema'; - -function wfWhosOnlineCheckSchema( $updater ) { - $updater->addExtensionUpdate( array( 'addTable', 'online', - __DIR__ . '/whosonline.sql', true ) ); - return true; -} +$wgAutoloadClasses['WhosOnlineHooks'] = __DIR__ . '/WhosOnlineHooks.php'; +$wgHooks['BeforePageDisplay'][] = 'WhosOnlineHooks::onBeforePageDisplay'; +$wgHooks['LoadExtensionSchemaUpdates'][] = 'WhosOnlineHooks::onLoadExtensionSchemaUpdates'; \ No newline at end of file diff --git a/WhosOnlineHooks.php b/WhosOnlineHooks.php new file mode 100644 index 0000000..fccc40d --- /dev/null +++ b/WhosOnlineHooks.php @@ -0,0 +1,42 @@ +<?php +/** + * @file + */ +class WhosOnlineHooks { + + // update online data + public static function onBeforePageDisplay() { + global $wgUser; + + // write to DB (use master) + $dbw = wfGetDB( DB_MASTER ); + $now = gmdate( 'YmdHis', time() ); + + // row to insert to table + $row = array( + 'userid' => $wgUser->getId(), + 'username' => $wgUser->getName(), + 'timestamp' => $now + ); + + $method = __METHOD__; + $dbw->onTransactionIdle( function() use ( $dbw, $method, $row ) { + $dbw->upsert( + 'online', + $row, + array( array( 'userid', 'username' ) ), + array( 'timestamp' => $row['timestamp'] ), + $method + ); + } ); + + return true; + } + + public static function onLoadExtensionSchemaUpdates( $updater ) { + $updater->addExtensionUpdate( array( 'addTable', 'online', + __DIR__ . '/whosonline.sql', true ) ); + return true; + } + +} \ No newline at end of file diff --git a/WhosOnlineSpecialPage.php b/WhosOnlineSpecialPage.php index 423e962..ef5f7e3 100644 --- a/WhosOnlineSpecialPage.php +++ b/WhosOnlineSpecialPage.php @@ -1,13 +1,15 @@ <?php /** + * WhosOnline extension - creates a list of logged-in users & anons currently online + * The list can be viewed at Special:WhosOnline + * * @file * @ingroup Extensions - * @author Maciej Brencz <macbre(at)-spam-wikia.com> + * @author Maciej Brencz <macbre(at)-spam-wikia.com> - minor fixes and improvements + * @author ChekMate Security Group - original code + * @see http://www.chekmate.org/wiki/index.php/MW:_Whos_Online_Extension + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later */ - -if ( !defined( 'MEDIAWIKI' ) ) { - exit( 1 ); -} class PagerWhosOnline extends IndexPager { function __construct() { @@ -21,7 +23,10 @@ return array( 'tables' => array( 'online' ), 'fields' => array( 'username' ), - 'options' => array( 'ORDER BY' => 'timestamp DESC', 'GROUP BY' => 'username' ), + 'options' => array( + 'ORDER BY' => 'timestamp DESC', + 'GROUP BY' => 'username' + ), 'conds' => $wgWhosOnlineShowAnons ? array() : array( 'userid != 0' ) @@ -51,14 +56,12 @@ function formatRow( $row ) { $userPageLink = Title::makeTitle( NS_USER, $row->username )->getFullURL(); - return '<li><a href="' . htmlspecialchars( $userPageLink ) . '">' . - htmlspecialchars( $row->username ) . '</a></li>'; + return '<li><a href="' . htmlspecialchars( $userPageLink, ENT_QUOTES ) . '">' . + htmlspecialchars( $row->username, ENT_QUOTES ) . '</a></li>'; } // extra methods function countUsersOnline() { - wfProfileIn( __METHOD__ ); - $row = $this->mDb->selectRow( 'online', 'COUNT(*) AS cnt', @@ -67,8 +70,6 @@ 'GROUP BY username' ); $users = (int) $row->cnt; - - wfProfileOut( __METHOD__ ); return $users; } @@ -93,8 +94,6 @@ // get list of logged-in users being online protected function getAnonsOnline() { - wfProfileIn( __METHOD__ ); - $dbr = wfGetDB( DB_SLAVE ); $row = $dbr->selectRow( @@ -106,13 +105,11 @@ ); $guests = (int) $row->cnt; - wfProfileOut( __METHOD__ ); - return $guests; } public function execute( $para ) { - global $wgOut, $wgDBname; + global $wgDBname; $db = wfGetDB( DB_MASTER ); $db->selectDB( $wgDBname ); @@ -144,9 +141,9 @@ $body = $pager->getBody(); if ( $showNavigation ) { - $wgOut->addHTML( $pager->getNavigationBar() ); + $this->getOutput()->addHTML( $pager->getNavigationBar() ); } - $wgOut->addHTML( '<ul>' . $body . '</ul>' ); + $this->getOutput()->addHTML( '<ul>' . $body . '</ul>' ); } } diff --git a/extension.json b/extension.json new file mode 100644 index 0000000..7badf00 --- /dev/null +++ b/extension.json @@ -0,0 +1,39 @@ +{ + "name": "WhosOnline", + "version": "1.5.0", + "author": [ + "Maciej Brencz" + ], + "license-name": "GPL-2.0+", + "url": "https://www.mediawiki.org/wiki/Extension:WhosOnline", + "descriptionmsg": "whosonline-desc", + "type": "specialpage", + "config": { + "WhosOnlineShowAnons": false + }, + "MessagesDirs": { + "WhosOnline": [ + "i18n" + ] + }, + "SpecialPages": { + "WhosOnline": "SpecialWhosOnline" + }, + "ExtensionMessagesFiles": { + "WhosOnlineAlias": "WhosOnline.alias.php" + }, + "AutoloadClasses": { + "WhosOnlineHooks": "WhosOnlineHooks.php", + "SpecialWhosOnline": "WhosOnlineSpecialPage.php", + "PagerWhosOnline": "WhosOnlineSpecialPage.php" + }, + "Hooks": { + "BeforePageDisplay": [ + "WhosOnlineHooks::onBeforePageDisplay" + ], + "LoadExtensionSchemaUpdates": [ + "WhosOnlineHooks::onLoadExtensionSchemaUpdates" + ] + }, + "manifest_version": 1 +} -- To view, visit https://gerrit.wikimedia.org/r/233324 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: If20181790f166c5eff010e0b0eccca8244b8657b Gerrit-PatchSet: 2 Gerrit-Project: mediawiki/extensions/WhosOnline Gerrit-Branch: master Gerrit-Owner: Jack Phoenix <j...@countervandalism.net> Gerrit-Reviewer: Jack Phoenix <j...@countervandalism.net> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits