jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/331968 )
Change subject: Wrap the <siteactivity> hook code in a class ...................................................................... Wrap the <siteactivity> hook code in a class Because global state is considered evil. Also this helps with the eventual migration to extension.json in the future. Change-Id: Ib66da8d63d6c9808c5529824253c4a769167bc8b --- M UserActivity/SiteActivityHook.php M UserActivity/UserActivity.php 2 files changed, 60 insertions(+), 69 deletions(-) Approvals: Jack Phoenix: Looks good to me, approved jenkins-bot: Verified diff --git a/UserActivity/SiteActivityHook.php b/UserActivity/SiteActivityHook.php index 08fd934..3813154 100644 --- a/UserActivity/SiteActivityHook.php +++ b/UserActivity/SiteActivityHook.php @@ -1,67 +1,63 @@ <?php -/** - * Protect against register_globals vulnerabilities. - * This line must be present before any global variable is referenced. - */ -if ( !defined( 'MEDIAWIKI' ) ) { - die( "Not a valid entry point.\n" ); -} -$wgHooks['ParserFirstCallInit'][] = 'wfSiteActivity'; -/** - * Register <siteactivity> hook with the Parser - * - * @param $parser Parser - * @return Boolean - */ -function wfSiteActivity( &$parser ) { - $parser->setHook( 'siteactivity', 'getSiteActivity' ); - return true; -} +class SiteActivityHook { -function getSiteActivity( $input, $args, $parser ) { - global $wgMemc, $wgExtensionAssetsPath; - - $parser->disableCache(); - - $limit = ( isset( $args['limit'] ) && is_numeric( $args['limit'] ) ) ? $args['limit'] : 10; - - // so that <siteactivity limit=5 /> will return 5 items instead of 4... - $fixedLimit = $limit + 1; - - $key = wfMemcKey( 'site_activity', 'all', $fixedLimit ); - $data = $wgMemc->get( $key ); - if ( !$data ) { - wfDebug( "Got site activity from DB\n" ); - $rel = new UserActivity( '', 'ALL', $fixedLimit ); - - $rel->setActivityToggle( 'show_votes', 0 ); - $activity = $rel->getActivityListGrouped(); - $wgMemc->set( $key, $activity, 60 * 2 ); - } else { - wfDebug( "Got site activity from cache\n" ); - $activity = $data; + /** + * Register the <siteactivity> hook with the Parser. + * + * @param Parser $parser Parser + * @return bool + */ + public static function onParserFirstCallInit( &$parser ) { + $parser->setHook( 'siteactivity', array( __CLASS__, 'getSiteActivity' ) ); + return true; } - $output = ''; - if ( $activity ) { - $output .= '<div class="mp-site-activity"> - <h2>' . wfMessage( 'useractivity-siteactivity' )->plain() . '</h2>'; + public static function getSiteActivity( $input, $args, $parser ) { + global $wgMemc, $wgExtensionAssetsPath; - $x = 1; - foreach ( $activity as $item ) { - if ( $x < $fixedLimit ) { - $typeIcon = UserActivity::getTypeIcon( $item['type'] ); - $output .= '<div class="mp-activity' . ( ( $x == $fixedLimit ) ? ' mp-activity-border-fix' : '' ) . '"> - <img src="' . $wgExtensionAssetsPath . '/SocialProfile/images/' . $typeIcon . '" alt="' . $typeIcon . '" border="0" />' - . $item['data'] . - '</div>'; - $x++; - } + $parser->disableCache(); + + $limit = ( isset( $args['limit'] ) && is_numeric( $args['limit'] ) ) ? $args['limit'] : 10; + + // so that <siteactivity limit=5 /> will return 5 items instead of 4... + $fixedLimit = $limit + 1; + + $key = wfMemcKey( 'site_activity', 'all', $fixedLimit ); + $data = $wgMemc->get( $key ); + if ( !$data ) { + wfDebug( "Got site activity from DB\n" ); + $rel = new UserActivity( '', 'ALL', $fixedLimit ); + + $rel->setActivityToggle( 'show_votes', 0 ); + $activity = $rel->getActivityListGrouped(); + $wgMemc->set( $key, $activity, 60 * 2 ); + } else { + wfDebug( "Got site activity from cache\n" ); + $activity = $data; } - $output .= '</div>'; + $output = ''; + if ( $activity ) { + $output .= '<div class="mp-site-activity"> + <h2>' . wfMessage( 'useractivity-siteactivity' )->plain() . '</h2>'; + + $x = 1; + foreach ( $activity as $item ) { + if ( $x < $fixedLimit ) { + $typeIcon = UserActivity::getTypeIcon( $item['type'] ); + $output .= '<div class="mp-activity' . ( ( $x == $fixedLimit ) ? ' mp-activity-border-fix' : '' ) . '"> + <img src="' . $wgExtensionAssetsPath . '/SocialProfile/images/' . $typeIcon . '" alt="' . $typeIcon . '" border="0" />' + . $item['data'] . + '</div>'; + $x++; + } + } + + $output .= '</div>'; + } + + return $output; } - return $output; -} +} \ No newline at end of file diff --git a/UserActivity/UserActivity.php b/UserActivity/UserActivity.php index eba3948..d73079f 100644 --- a/UserActivity/UserActivity.php +++ b/UserActivity/UserActivity.php @@ -4,25 +4,17 @@ * * @file * @ingroup Extensions - * @version 1.2 + * @version 1.3 * @author Aaron Wright <aaron.wri...@gmail.com> * @author David Pean <david.p...@gmail.com> * @author Jack Phoenix <j...@countervandalism.net> * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later */ -/** - * Protect against register_globals vulnerabilities. - * This line must be present before any global variable is referenced. - */ -if ( !defined( 'MEDIAWIKI' ) ) { - die( "Not a valid entry point.\n" ); -} - // Extension credits that will show up on Special:Version $wgExtensionCredits['specialpage'][] = array( 'name' => 'UserActivity', - 'version' => '1.2', + 'version' => '1.3', 'author' => array( 'Aaron Wright', 'David Pean', 'Jack Phoenix' ), 'description' => "Shows users' social activity", 'url' => 'https://www.mediawiki.org/wiki/Extension:SocialProfile' @@ -30,8 +22,11 @@ // Set up the new special page $wgMessagesDirs['UserActivity'] = __DIR__ . '/i18n'; + +$wgAutoloadClasses['SiteActivityHook'] = __DIR__ . '/SiteActivityHook.php'; $wgAutoloadClasses['UserActivity'] = __DIR__ . '/UserActivityClass.php'; $wgAutoloadClasses['UserHome'] = __DIR__ . '/UserActivity.body.php'; + $wgSpecialPages['UserActivity'] = 'UserHome'; // Register the CSS with ResourceLoader @@ -42,5 +37,5 @@ 'position' => 'top' ); -// Load <siteactivity> parser hook -require_once( 'SiteActivityHook.php' ); +// Set up the <siteactivity> parser hook +$wgHooks['ParserFirstCallInit'][] = 'SiteActivityHook::onParserFirstCallInit'; \ No newline at end of file -- To view, visit https://gerrit.wikimedia.org/r/331968 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ib66da8d63d6c9808c5529824253c4a769167bc8b Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/SocialProfile 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