Index: trunk/extensions/OnlineStatusBar/OnlineStatusBar.body.php |
— | — | @@ -34,25 +34,6 @@ |
35 | 35 | return Html::element( 'img', array( 'src' => $icon ) ); |
36 | 36 | } |
37 | 37 | |
38 | | - public static function ParserGetVariable ( &$parser, &$varCache, &$index, &$ret ){ |
39 | | - global $wgOnlineStatusBarModes; |
40 | | - if( $index == 'isonline' ){ |
41 | | - $name = self::GetOwnerFromTitle ( $parser->getTitle() )->getName(); |
42 | | - |
43 | | - if ( self::IsValid($name) != true ) { |
44 | | - $ret = "unknown"; |
45 | | - return true; |
46 | | - } |
47 | | - $ret = $wgOnlineStatusBarModes[self::GetStatus( $name )]; |
48 | | - } |
49 | | - return true; |
50 | | - } |
51 | | - |
52 | | - public static function StylePage ( &$out, &$skin ) { |
53 | | - $out->addModules ( 'ext.OnlineStatusBar' ); |
54 | | - return true; |
55 | | - } |
56 | | - |
57 | 38 | public static function GetNow() { |
58 | 39 | return gmdate( 'Ymdhis', time() ); |
59 | 40 | } |
— | — | @@ -73,7 +54,7 @@ |
74 | 55 | $dbw = wfGetDB( DB_MASTER ); |
75 | 56 | $row = array( |
76 | 57 | 'username' => $wgUser->getName(), |
77 | | - 'timestamp' => $dbw->timestamp( wfTimestamp() ), |
| 58 | + 'timestamp' => $dbw->timestamp( wfTimestamp() ), /// fixme |
78 | 59 | ); |
79 | 60 | $dbw->insert( 'online_status', $row, __METHOD__, 'DELAYED' ); |
80 | 61 | } |
— | — | @@ -81,17 +62,6 @@ |
82 | 63 | return false; |
83 | 64 | } |
84 | 65 | |
85 | | - public static function MagicWordSet ( &$vars ) { |
86 | | - $vars[] = 'isonline'; |
87 | | - return true; |
88 | | - } |
89 | | - |
90 | | - public static function MagicWordVar ( &$magicWords, $ln ) { |
91 | | - $magicWords['isonline'] = array ( 0, 'isonline' ); |
92 | | - |
93 | | - return true; |
94 | | - } |
95 | | - |
96 | 66 | public static function UpdateStatus() { |
97 | 67 | global $wgUser, $wgOnlineStatusBarDefaultOffline; |
98 | 68 | if ( OnlineStatusBar::GetStatus( $wgUser->getName() ) == $wgOnlineStatusBarDefaultOffline ) { |
Index: trunk/extensions/OnlineStatusBar/OnlineStatusBar.php |
— | — | @@ -1,9 +1,4 @@ |
2 | 2 | <?php |
3 | | -if ( !defined( 'MEDIAWIKI' ) ) { |
4 | | - echo "This is a part of mediawiki and can't be started separately"; |
5 | | - die(); |
6 | | -} |
7 | | - |
8 | 3 | /** |
9 | 4 | * Insert a special box on user page showing their status. |
10 | 5 | * |
— | — | @@ -14,6 +9,11 @@ |
15 | 10 | * @link http://www.mediawiki.org/wiki/Extension:OnlineStatusBar Documentation |
16 | 11 | */ |
17 | 12 | |
| 13 | +if ( !defined( 'MEDIAWIKI' ) ) { |
| 14 | + echo "This is a part of mediawiki and can't be started separately"; |
| 15 | + die(); |
| 16 | +} |
| 17 | + |
18 | 18 | $wgExtensionCredits[version_compare( $wgVersion, '1.17', '>=' ) ? 'userpage tools' : 'other'][] = array( |
19 | 19 | 'path' => __FILE__, |
20 | 20 | 'name' => 'Online status bar', |
— | — | @@ -30,9 +30,10 @@ |
31 | 31 | 'styles' => 'OnlineStatusBar.css', |
32 | 32 | 'localBasePath' => dirname ( __FILE__ ), |
33 | 33 | 'remoteExtPath' => 'OnlineStatusBar', |
34 | | - ); |
| 34 | +); |
35 | 35 | |
36 | 36 | $wgAutoloadClasses['OnlineStatusBar'] = "$dir/OnlineStatusBar.body.php"; |
| 37 | +$wgAutoloadClasses['OnlineStatusBarHooks'] = "$dir/OnlineStatusBarHooks.php"; |
37 | 38 | |
38 | 39 | // Configuration |
39 | 40 | // Those values can be overriden in LocalSettings, do not change it here |
— | — | @@ -69,83 +70,13 @@ |
70 | 71 | // how long to wait until user is considered as offline |
71 | 72 | $wgOnlineStatusBar_LogoutTime = 3600; |
72 | 73 | |
73 | | -$wgHooks['LoadExtensionSchemaUpdates'][] = 'wfOnlineStatusBar_CkSchema'; |
74 | | -function wfOnlineStatusBar_CkSchema( $updater = null ) { |
75 | | - if ( $updater !== null ){ |
76 | | - $updater->addExtensionUpdate( array( 'addtable', 'online_status', dirname( __FILE__ ) . '/OnlineStatusBar.sql', true ) ); |
77 | | - } else { |
78 | | - global $wgExtNewTables; |
79 | | - $wgExtNewTables[] = array( |
80 | | - 'online_status', dirname( __FILE__ ) . '/OnlineStatusBar.sql' ); |
81 | | - } |
82 | | - return true; |
83 | | -} |
84 | | - |
85 | | -$wgHooks['UserLogoutComplete'][] = 'wfOnlineStatusBar_Logout'; |
86 | | -function wfOnlineStatusBar_Logout( &$user, &$inject_html, $old_name ) { |
87 | | - OnlineStatusBar::DeleteStatus( $old_name ); |
88 | | - return true; |
89 | | -} |
90 | | - |
91 | | -$wgHooks['ArticleViewHeader'][] = 'wfOnlineStatusBar_RenderBar'; |
92 | | -function wfOnlineStatusBar_RenderBar( &$article, &$outputDone, &$pcache ) { |
93 | | - global $wgOnlineStatusBar_Template, $messages, $wgOnlineStatusBarModes, $wgOut; |
94 | | - OnlineStatusBar::UpdateStatus(); |
95 | | - $ns = $article->getTitle()->getNamespace(); |
96 | | - if ( ( $ns == NS_USER_TALK ) || ( $ns == NS_USER ) ) { |
97 | | - $user = OnlineStatusBar::GetOwnerFromTitle ( $article->getTitle() ); |
98 | | - if ( $user == null ) { |
99 | | - return true; |
100 | | - } |
101 | | - $username = $user->getName(); |
102 | | - if ( $user->getOption ( "OnlineStatusBar_hide" ) == true ) { |
103 | | - return true; |
104 | | - } |
105 | | - if ( OnlineStatusBar::IsValid( $username ) ) { |
106 | | - $mode = OnlineStatusBar::GetStatus( $username ); |
107 | | - $modetext = $wgOnlineStatusBarModes[$mode]; |
108 | | - $image = OnlineStatusBar::getImageHtml( $mode ); |
109 | | - $text = wfMessage( 'onlinestatusbar-line', $username )->rawParams( $image )->params( $modetext )->escaped(); |
110 | | - $wgOut->addHtml( OnlineStatusBar::Get_Html( $text, $mode ) ); |
111 | | - } |
112 | | - } |
113 | | - return true; |
114 | | -} |
115 | | - |
116 | | -$wgHooks['UserLoginComplete'][] = 'wfOnlineStatusBar_UpdateStatus'; |
117 | | -function wfOnlineStatusBar_UpdateStatus() { |
118 | | - OnlineStatusBar::UpdateDb(); |
119 | | - return true; |
120 | | -} |
121 | | - |
122 | | -$wgHooks['GetPreferences'][] = 'wfOnlineStatusBar_PreferencesHook'; |
123 | | -function wfOnlineStatusBar_PreferencesHook( $user, &$preferences ) { |
124 | | - global $wgOnlineStatusBarDefaultOnline, $wgOnlineStatusBarDefaultEnabled, $wgOnlineStatusBarModes; |
125 | | - $preferences['OnlineStatusBar_active'] = array( 'type' => 'toggle', 'label-message' => 'onlinestatusbar-used', 'section' => 'misc/onlinestatus' ); |
126 | | - $preferences['OnlineStatusBar_hide'] = array( 'type' => 'toggle', 'label-message' => 'onlinestatusbar-hide', 'section' => 'misc/onlinestatus' ); |
127 | | - $preferences['OnlineStatusBar_status'] = array( 'type' => 'radio', 'label-message' => 'onlinestatusbar-status', 'section' => 'misc/onlinestatus', |
128 | | - 'options' => array( |
129 | | - $wgOnlineStatusBarModes['online'] => 'online', |
130 | | - $wgOnlineStatusBarModes['busy'] => 'busy', |
131 | | - $wgOnlineStatusBarModes['away'] => 'away', |
132 | | - $wgOnlineStatusBarModes['hidden'] => 'hidden' |
133 | | - ), |
134 | | - ); |
135 | | - return true; |
136 | | -} |
137 | | - |
138 | | -$wgHooks['UserGetDefaultOptions'][] = 'wfOnlineStatusBar_SetDefaultOptions'; |
139 | | -function wfOnlineStatusBar_SetDefaultOptions( &$defaultOptions ) { |
140 | | - global $wgOnlineStatusBarDefaultOnline, $wgOnlineStatusBarDefaultEnabled; |
141 | | - // set defaults |
142 | | - $defaultOptions['OnlineStatusBar_status'] = $wgOnlineStatusBarDefaultOnline; |
143 | | - $defaultOptions['OnlineStatusBar_active'] = $wgOnlineStatusBarDefaultEnabled; |
144 | | - $defaultOptions['OnlineStatusBar_hide'] = false; |
145 | | - // quit |
146 | | - return true; |
147 | | -} |
148 | | - |
149 | | -$wgHooks['LanguageGetMagic'][] = 'OnlineStatusBar::MagicWordVar'; |
150 | | -$wgHooks['BeforePageDisplay'][] = 'OnlineStatusBar::StylePage'; |
151 | | -$wgHooks['MagicWordwgVariableIDs'][] = 'OnlineStatusBar::MagicWordSet'; |
152 | | -$wgHooks['ParserGetVariableValueSwitch'][] = 'OnlineStatusBar::ParserGetVariable'; |
| 74 | +$wgHooks['LoadExtensionSchemaUpdates'][] = 'OnlineStatusBarHooks::ckSchema'; |
| 75 | +$wgHooks['UserLogoutComplete'][] = 'OnlineStatusBarHooks::logout'; |
| 76 | +$wgHooks['ArticleViewHeader'][] = 'OnlineStatusBarHooks::renderBar'; |
| 77 | +$wgHooks['UserLoginComplete'][] = 'OnlineStatusBarHooks::updateStatus'; |
| 78 | +$wgHooks['GetPreferences'][] = 'OnlineStatusBarHooks::preferencesHook'; |
| 79 | +$wgHooks['UserGetDefaultOptions'][] = 'OnlineStatusBarHooks::setDefaultOptions'; |
| 80 | +$wgHooks['LanguageGetMagic'][] = 'OnlineStatusBarHooks::magicWordVar'; |
| 81 | +$wgHooks['BeforePageDisplay'][] = 'OnlineStatusBarHooks::stylePage'; |
| 82 | +$wgHooks['MagicWordwgVariableIDs'][] = 'OnlineStatusBarHooks::magicWordSet'; |
| 83 | +$wgHooks['ParserGetVariableValueSwitch'][] = 'OnlineStatusBarHooks::parserGetVariable'; |
Index: trunk/extensions/OnlineStatusBar/OnlineStatusBarHooks.php |
— | — | @@ -0,0 +1,157 @@ |
| 2 | +<?php
|
| 3 | +
|
| 4 | +/**
|
| 5 | + * Hooks for OnlineStatusBar
|
| 6 | + *
|
| 7 | + * @group Extensions
|
| 8 | + */
|
| 9 | +class OnlineStatusBarHooks {
|
| 10 | + /**
|
| 11 | + * @param DatabaseUpdate|null $updater
|
| 12 | + * @return bool
|
| 13 | + */
|
| 14 | + public static function ckSchema( $updater = null ) {
|
| 15 | + if ( ( $updater === null ) != true ){
|
| 16 | + $updater->addExtensionUpdate( array( 'addtable', 'online_status', dirname( __FILE__ ) . '/OnlineStatusBar.sql', true ) );
|
| 17 | + } else {
|
| 18 | + global $wgExtNewTables;
|
| 19 | + $wgExtNewTables[] = array(
|
| 20 | + 'online_status', dirname( __FILE__ ) . '/OnlineStatusBar.sql' );
|
| 21 | + }
|
| 22 | + return true;
|
| 23 | + }
|
| 24 | +
|
| 25 | + /**
|
| 26 | + * @param $user User
|
| 27 | + * @param $inject_html string
|
| 28 | + * @param $old_name string
|
| 29 | + * @return bool
|
| 30 | + */
|
| 31 | + public static function logout( &$user, &$inject_html, $old_name ) {
|
| 32 | + OnlineStatusBar::DeleteStatus( $old_name );
|
| 33 | + return true;
|
| 34 | + }
|
| 35 | +
|
| 36 | + /**
|
| 37 | + * @return bool
|
| 38 | + */
|
| 39 | + public static function updateStatus() {
|
| 40 | + OnlineStatusBar::UpdateDb();
|
| 41 | + return true;
|
| 42 | + }
|
| 43 | +
|
| 44 | + /**
|
| 45 | + * @param $article Article
|
| 46 | + * @param $outputDone bool
|
| 47 | + * @param $pcache string
|
| 48 | + * @return bool
|
| 49 | + */
|
| 50 | + public static function renderBar( &$article, &$outputDone, &$pcache ) {
|
| 51 | + global $wgOnlineStatusBar_Template, $messages, $wgOnlineStatusBarModes, $wgOut;
|
| 52 | + OnlineStatusBar::UpdateStatus();
|
| 53 | + $ns = $article->getTitle()->getNamespace();
|
| 54 | + if ( ( $ns == NS_USER_TALK ) || ( $ns == NS_USER ) ) {
|
| 55 | + $user = OnlineStatusBar::GetOwnerFromTitle ( $article->getTitle() );
|
| 56 | + if ( $user === null ) {
|
| 57 | + return true;
|
| 58 | + }
|
| 59 | + $username = $user->getName();
|
| 60 | + if ( $user->getOption ( "OnlineStatusBar_hide" ) == true ) {
|
| 61 | + return true;
|
| 62 | + }
|
| 63 | + if ( OnlineStatusBar::IsValid( $username ) ) {
|
| 64 | + $mode = OnlineStatusBar::GetStatus( $username );
|
| 65 | + $modetext = $wgOnlineStatusBarModes[$mode];
|
| 66 | + $image = OnlineStatusBar::getImageHtml( $mode );
|
| 67 | + $text = wfMessage( 'onlinestatusbar-line', $username )->rawParams( $image )->params( $modetext )->escaped();
|
| 68 | + $wgOut->addHtml( OnlineStatusBar::Get_Html( $text, $mode ) );
|
| 69 | + }
|
| 70 | + }
|
| 71 | + return true;
|
| 72 | + }
|
| 73 | +
|
| 74 | + /**
|
| 75 | + * @param $user User
|
| 76 | + * @paramNireferences array
|
| 77 | + * @return bool
|
| 78 | + */
|
| 79 | + public static function preferencesHook( User $user, array &$preferences ) {
|
| 80 | + global $wgOnlineStatusBarDefaultOnline, $wgOnlineStatusBarDefaultEnabled, $wgOnlineStatusBarModes;
|
| 81 | + $preferences['OnlineStatusBar_active'] = array( 'type' => 'toggle', 'label-message' => 'onlinestatusbar-used', 'section' => 'misc/onlinestatus' );
|
| 82 | + $preferences['OnlineStatusBar_hide'] = array( 'type' => 'toggle', 'label-message' => 'onlinestatusbar-hide', 'section' => 'misc/onlinestatus' );
|
| 83 | + $preferences['OnlineStatusBar_status'] = array( 'type' => 'radio', 'label-message' => 'onlinestatusbar-status', 'section' => 'misc/onlinestatus',
|
| 84 | + 'options' => array(
|
| 85 | + $wgOnlineStatusBarModes['online'] => 'online',
|
| 86 | + $wgOnlineStatusBarModes['busy'] => 'busy',
|
| 87 | + $wgOnlineStatusBarModes['away'] => 'away',
|
| 88 | + $wgOnlineStatusBarModes['hidden'] => 'hidden'
|
| 89 | + ),
|
| 90 | + );
|
| 91 | + return true;
|
| 92 | + }
|
| 93 | +
|
| 94 | + /**
|
| 95 | + * @param $defaultOptions array
|
| 96 | + * @return bool
|
| 97 | + */
|
| 98 | + public static function setDefaultOptions( &$defaultOptions ) {
|
| 99 | + global $wgOnlineStatusBarDefaultOnline, $wgOnlineStatusBarDefaultEnabled;
|
| 100 | + // set defaults
|
| 101 | + $defaultOptions['OnlineStatusBar_status'] = $wgOnlineStatusBarDefaultOnline;
|
| 102 | + $defaultOptions['OnlineStatusBar_active'] = $wgOnlineStatusBarDefaultEnabled;
|
| 103 | + $defaultOptions['OnlineStatusBar_hide'] = false;
|
| 104 | + // quit
|
| 105 | + return true;
|
| 106 | + }
|
| 107 | +
|
| 108 | + /**
|
| 109 | + * @param $magicWords array
|
| 110 | + * @param $ln string?
|
| 111 | + * @return bool
|
| 112 | + */
|
| 113 | + public static function magicWordVar ( array &$magicWords, $ln ) {
|
| 114 | + $magicWords['isonline'] = array ( 0, 'isonline' );
|
| 115 | +
|
| 116 | + return true;
|
| 117 | + }
|
| 118 | +
|
| 119 | + /**
|
| 120 | + * @param $out OutputPage
|
| 121 | + * @param $skin Skin
|
| 122 | + * @return bool
|
| 123 | + */
|
| 124 | + public static function stylePage ( &$out, &$skin ) {
|
| 125 | + $out->addModules( 'ext.OnlineStatusBar' );
|
| 126 | + return true;
|
| 127 | + }
|
| 128 | +
|
| 129 | + /**
|
| 130 | + * @param $vars array
|
| 131 | + * @return bool
|
| 132 | + */
|
| 133 | + public static function magicWordSet ( &$vars ) {
|
| 134 | + $vars[] = 'isonline';
|
| 135 | + return true;
|
| 136 | + }
|
| 137 | +
|
| 138 | + /**
|
| 139 | + * @param $parser Parser
|
| 140 | + * @param $varCache ??
|
| 141 | + * @param $index ??
|
| 142 | + * @param $ret string?
|
| 143 | + * @return bool
|
| 144 | + */
|
| 145 | + public static function parserGetVariable ( &$parser, &$varCache, &$index, &$ret ){
|
| 146 | + global $wgOnlineStatusBarModes;
|
| 147 | + if( $index == 'isonline' ){
|
| 148 | + $name = OnlineStatusBar::GetOwnerFromTitle ( $parser->getTitle() )->getName();
|
| 149 | +
|
| 150 | + if ( OnlineStatusBar::IsValid($name) != true ) {
|
| 151 | + $ret = "unknown";
|
| 152 | + return true;
|
| 153 | + }
|
| 154 | + $ret = $wgOnlineStatusBarModes[OnlineStatusBar::GetStatus( $name )];
|
| 155 | + }
|
| 156 | + return true;
|
| 157 | + }
|
| 158 | +}
|