Index: trunk/extensions/Invitations/Invitations_obj.php |
— | — | @@ -26,7 +26,7 @@ |
27 | 27 | |
28 | 28 | class Invitations { |
29 | 29 | |
30 | | - /* |
| 30 | + /** |
31 | 31 | * Does this user have a valid invite to this feature? |
32 | 32 | * @param string $feature The feature to check. |
33 | 33 | * @param object $user The user to check, or null for the current user ($wgUser) |
— | — | @@ -34,7 +34,7 @@ |
35 | 35 | */ |
36 | 36 | public static function hasInvite( $feature, $user = null, &$invite_age = false ) { |
37 | 37 | global $wgUser, $wgInvitationTypes, $wgDBtype; |
38 | | - if ($user == null) |
| 38 | + if ($user === null) |
39 | 39 | $user = $wgUser; |
40 | 40 | |
41 | 41 | // No such invitation type. |
— | — | @@ -66,7 +66,7 @@ |
67 | 67 | */ |
68 | 68 | public static function getAllowedFeatures( $user = null ) { |
69 | 69 | global $wgUser; |
70 | | - if ($user == null) |
| 70 | + if ($user === null) |
71 | 71 | $user = $wgUser; |
72 | 72 | |
73 | 73 | $dbr = wfGetDb( DB_SLAVE ); |
— | — | @@ -82,7 +82,7 @@ |
83 | 83 | return $features; |
84 | 84 | } |
85 | 85 | |
86 | | - /* |
| 86 | + /** |
87 | 87 | * Can the given inviter invite the given invitee to the given feature? |
88 | 88 | * @param string $feature The feature to check. |
89 | 89 | * @param object $invitee The user to be invited. |
— | — | @@ -110,7 +110,7 @@ |
111 | 111 | if (!Invitations::checkDelay($feature, $user, $accountAge)) |
112 | 112 | return INVITE_RESULT_NONE_YET; |
113 | 113 | |
114 | | - if ($wgInvitationTypes[$feature][limitedinvites]) { |
| 114 | + if ($wgInvitationTypes[$feature]['limitedinvites']) { |
115 | 115 | if (Invitations::getRemainingInvites( $feature, $inviter ) == 0) { |
116 | 116 | return INVITE_RESULT_NONE_LEFT; |
117 | 117 | } |
— | — | @@ -120,7 +120,7 @@ |
121 | 121 | return INVITE_RESULT_OK; |
122 | 122 | } |
123 | 123 | |
124 | | - /* |
| 124 | + /** |
125 | 125 | * How many invites does the given inviter have? |
126 | 126 | * @param string $feature The feature to check. |
127 | 127 | * @param object $user The user to check, or null for $wgUser. |
— | — | @@ -128,7 +128,7 @@ |
129 | 129 | */ |
130 | 130 | public static function getRemainingInvites( $feature, $user = null ) { |
131 | 131 | global $wgUser, $wgInvitationTypes; |
132 | | - if ($user == null) |
| 132 | + if ($user === null) |
133 | 133 | $user = $wgUser; |
134 | 134 | |
135 | 135 | $accountAge = 1; |
— | — | @@ -143,7 +143,7 @@ |
144 | 144 | |
145 | 145 | $accountAge = time() - $accountAge; |
146 | 146 | |
147 | | - if (!$wgInvitationTypes[$feature][limitedinvites]) |
| 147 | + if (!$wgInvitationTypes[$feature]['limitedinvites']) |
148 | 148 | return -1; |
149 | 149 | |
150 | 150 | if (!Invitations::checkDelay( $feature, $user, $accountAge )) |
— | — | @@ -151,18 +151,21 @@ |
152 | 152 | |
153 | 153 | $dbr = wfGetDb( DB_SLAVE ); |
154 | 154 | |
155 | | - $res = $dbr->select( 'invite_count', array( 'ic_count' ), array( ic_user => $user->getId(), ic_type => $feature ), __METHOD__ ); |
| 155 | + $res = $dbr->select( 'invite_count', |
| 156 | + array( 'ic_count' ), |
| 157 | + array( 'ic_user' => $user->getId(), 'ic_type' => $feature ), |
| 158 | + __METHOD__ ); |
156 | 159 | |
157 | 160 | if ($dbr->numRows($res) > 0) { |
158 | 161 | $num = $dbr->fetchObject($res)->ic_count; |
159 | 162 | return $num; |
160 | 163 | } else { |
161 | | - Invitations::insertCountRow( $feature, $user, $wgInvitationTypes[$feature][reserve]); |
162 | | - return $wgInvitationTypes[$feature][reserve]; |
| 164 | + Invitations::insertCountRow( $feature, $user, $wgInvitationTypes[$feature]['reserve']); |
| 165 | + return $wgInvitationTypes[$feature]['reserve']; |
163 | 166 | } |
164 | 167 | } |
165 | 168 | |
166 | | - /* |
| 169 | + /** |
167 | 170 | * Check if the given user has had the given feature for long enough to invite. |
168 | 171 | * @param string $feature The feature to check |
169 | 172 | * @param object $user The user to check |
— | — | @@ -170,24 +173,24 @@ |
171 | 174 | */ |
172 | 175 | public static function checkDelay( $feature, $user = null, $time = null ) { |
173 | 176 | global $wgUser, $wgInvitationTypes; |
174 | | - if ($user == null) |
| 177 | + if ($user === null) |
175 | 178 | $user = $wgUser; |
176 | 179 | |
177 | | - if ($time != null) { |
| 180 | + if ($time !== null) { |
178 | 181 | // Do nothing |
179 | | - } else if ($time == null && !Invitations::hasInvite( $feature, $user, $time )) { |
| 182 | + } else if ($time === null && !Invitations::hasInvite( $feature, $user, $time )) { |
180 | 183 | return false; |
181 | 184 | } else { |
182 | 185 | // The user has an invite, and we retrieved its creation point. Find its age |
183 | 186 | $time = time() - $time; |
184 | 187 | } |
185 | 188 | |
186 | | - if ($time < $wgInvitationTypes[$feature][invitedelay]) { |
| 189 | + if ($time < $wgInvitationTypes[$feature]['invitedelay']) { |
187 | 190 | return false; |
188 | 191 | } else return true; |
189 | 192 | } |
190 | 193 | |
191 | | - /* |
| 194 | + /** |
192 | 195 | * Insert a row into the invite_count table for the given user and feature. |
193 | 196 | * @param string $feature The feature to check. |
194 | 197 | * @param object $user The user to check, or null for $wgUser. |
— | — | @@ -196,7 +199,7 @@ |
197 | 200 | */ |
198 | 201 | private static function insertCountRow( $feature, $user = null, $count = null ) { |
199 | 202 | global $wgUser, $wgInvitationTypes; |
200 | | - if ($user == null) |
| 203 | + if ($user === null) |
201 | 204 | $user = $wgUser; |
202 | 205 | |
203 | 206 | // No such invitation type. |
— | — | @@ -215,7 +218,7 @@ |
216 | 219 | } |
217 | 220 | } |
218 | 221 | |
219 | | - /* |
| 222 | + /** |
220 | 223 | * Add an invitation for the given invitee, from the given inviter. |
221 | 224 | * @param string $feature The feature to invite to. |
222 | 225 | * @param object $invitee The user to be invited. |
— | — | @@ -224,7 +227,7 @@ |
225 | 228 | */ |
226 | 229 | public static function inviteUser( $feature, $invitee, $inviter = null ) { |
227 | 230 | global $wgUser, $wgInvitationTypes; |
228 | | - if ($inviter == null) |
| 231 | + if ($inviter === null) |
229 | 232 | $inviter = $wgUser; |
230 | 233 | |
231 | 234 | if ( ($res = Invitations::checkInviteOperation($feature, $invitee, $inviter)) != INVITE_RESULT_OK) { |
— | — | @@ -235,11 +238,16 @@ |
236 | 239 | $dbw = wfGetDB( DB_MASTER ); |
237 | 240 | |
238 | 241 | $dbw->update( 'invite_count', array( 'ic_count=ic_count-1' ), |
239 | | - array( ic_user => $inviter->getId(), ic_type => $feature ), __METHOD__ ); |
| 242 | + array( 'ic_user' => $inviter->getId(), 'ic_type' => $feature ), |
| 243 | + __METHOD__ ); |
240 | 244 | |
241 | 245 | $dbw->insert( 'invitation', |
242 | | - array( 'inv_invitee' => $invitee->getId(), 'inv_inviter' => $inviter->getId(), |
243 | | - 'inv_type' => $feature ), __METHOD__ ); |
| 246 | + array( |
| 247 | + 'inv_invitee' => $invitee->getId(), |
| 248 | + 'inv_inviter' => $inviter->getId(), |
| 249 | + 'inv_type' => $feature |
| 250 | + ), |
| 251 | + __METHOD__ ); |
244 | 252 | |
245 | 253 | // Log it. |
246 | 254 | $log = new LogPage( 'invite' ); |
Index: trunk/extensions/Invitations/Invitations_page.php |
— | — | @@ -17,20 +17,13 @@ |
18 | 18 | * @addtogroup Extensions |
19 | 19 | */ |
20 | 20 | |
21 | | -if ( !defined( 'MEDIAWIKI' ) ) { |
22 | | - echo "Invitations extension\n"; |
23 | | - exit( 1 ); |
24 | | -} |
25 | | - |
26 | | - |
27 | | -class SpecialInvitations extends SpecialPage |
28 | | -{ |
29 | | - function SpecialInvitations() { |
30 | | - SpecialPage::SpecialPage('Invitations'); |
31 | | - wfLoadExtensionMessages('Invitations'); |
| 21 | +class SpecialInvitations extends SpecialPage { |
| 22 | + function __construct() { |
| 23 | + parent::__construct('Invitations'); |
32 | 24 | } |
33 | 25 | |
34 | 26 | function execute( $subpage ) { |
| 27 | + wfLoadExtensionMessages('Invitations'); |
35 | 28 | global $wgRequest; |
36 | 29 | |
37 | 30 | if ($subpage != '' && $wgRequest->getBool('invite_submit')) { |
— | — | @@ -43,7 +36,7 @@ |
44 | 37 | } |
45 | 38 | |
46 | 39 | function buildMainView() { |
47 | | - global $wgOut,$wgUser,$wgInvitationTypes; |
| 40 | + global $wgOut,$wgUser,$wgInvitationTypes, $wgLang; |
48 | 41 | $sk = $wgUser->getSkin(); |
49 | 42 | |
50 | 43 | $wgOut->setPageTitle( wfMsg( 'invitations-pagetitle' ) ); |
— | — | @@ -54,37 +47,37 @@ |
55 | 48 | $invitedfeatures = Invitations::getAllowedFeatures(); |
56 | 49 | |
57 | 50 | if (count($invitedfeatures)) { |
58 | | - $wgOut->addWikitext( wfMsg( 'invitations-invitedlist-description' ) ); |
| 51 | + $wgOut->addWikiMsg( 'invitations-invitedlist-description' ); |
59 | 52 | $wgOut->addHTML( '<ul>' ); |
60 | 53 | |
61 | 54 | foreach ($invitedfeatures as $feature) { |
62 | | - $link = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'Invitations', $feature ), wfMsg("invitation-type-$feature") ); |
63 | | - $num = Invitations::getRemainingInvites( $feature ); |
| 55 | + $link = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'Invitations', $feature ), wfMsgHtml("invitation-type-$feature") ); |
| 56 | + $num = $wgLang->formatNum( Invitations::getRemainingInvites( $feature ) ); |
64 | 57 | |
65 | | - $text = wfMsgExt( 'invitations-invitedlist-item', array( 'parseinline', 'replaceafter' ), $link, $num ); |
| 58 | + $text = "<b>$link</b>"; |
| 59 | + $text = ' '. wfMsgExt( 'invitations-invitedlist-item-count', 'parseinline', $num ); |
66 | 60 | |
67 | 61 | $wgOut->addHTML( "<li> $text </li>" ); |
68 | 62 | } |
69 | 63 | } else { |
70 | | - $wgOut->addWikitext( wfMsg( 'invitations-invitedlist-none' ) ); |
| 64 | + $wgOut->addWikiMsg( 'invitations-invitedlist-none' ); |
71 | 65 | } |
72 | 66 | |
73 | 67 | $uninvitedfeatures = array_diff( array_keys($wgInvitationTypes), $invitedfeatures ); |
74 | 68 | |
75 | 69 | if (count($uninvitedfeatures)) { |
76 | | - $wgOut->addWikitext( wfMsg( 'invitations-uninvitedlist-description' ) ); |
| 70 | + $wgOut->addWikiMsg( 'invitations-uninvitedlist-description' ); |
77 | 71 | $wgOut->addHTML( '<ul>' ); |
78 | 72 | |
79 | 73 | foreach ($uninvitedfeatures as $feature) { |
80 | | - $link = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'Invitations', $feature ), wfMsg("invitation-type-$feature") ); |
81 | | - $num = Invitations::getRemainingInvites( $feature ); |
| 74 | + $link = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'Invitations', $feature ), wfMsgHtml("invitation-type-$feature") ); |
82 | 75 | |
83 | | - $text = wfMsgExt( 'invitations-uninvitedlist-item', array( 'parseinline', 'replaceafter' ), $link, $num ); |
| 76 | + $text = "<b>$link</b>"; |
84 | 77 | |
85 | 78 | $wgOut->addHTML( "<li> $text </li>" ); |
86 | 79 | } |
87 | 80 | } else { |
88 | | - $wgOut->addWikitext( wfMsg( 'invitations-uninvitedlist-none' ) ); |
| 81 | + $wgOut->addWikiMsg( 'invitations-uninvitedlist-none' ); |
89 | 82 | } |
90 | 83 | } |
91 | 84 | |
— | — | @@ -95,26 +88,24 @@ |
96 | 89 | $invitee = User::newFromName($username); |
97 | 90 | |
98 | 91 | if ($invitee->getId() == 0) { |
99 | | - $this->buildFeatureView( $feature, wfMsg( 'invitation-error-baduser' ) ); |
| 92 | + $this->buildFeatureView( $feature, 'invitation-error-baduser' ); |
100 | 93 | return; |
101 | 94 | } |
102 | 95 | |
103 | 96 | if ( ($res = Invitations::inviteUser( $feature, $invitee )) == INVITE_RESULT_OK ) { |
104 | | - $this->buildFeatureView( $feature, false, wfMsg( 'invitations-invite-success', $username ) ); |
| 97 | + $this->buildFeatureView( $feature, false, array( 'invitations-invite-success', $username ) ); |
105 | 98 | } else { |
106 | 99 | $results = array( INVITE_RESULT_ALREADY_INVITED => array( 'invitations-error-alreadyinvited', $username ), |
107 | 100 | INVITE_RESULT_NOT_ALLOWED => array( 'invitations-feature-notallowed', wfMsg("invitations-type-$feature") ), |
108 | 101 | INVITE_RESULT_NONE_LEFT => array( 'invitations-feature-noneleft' ), |
109 | 102 | INVITE_RESULT_NONE_YET => array( 'invitations-feature-noneyet' ) ); |
110 | 103 | |
111 | | - $message = call_user_func_array( 'wfMsg', $results[$res] ); |
112 | | - |
113 | | - $this->buildFeatureView( $feature, $message ); |
| 104 | + $this->buildFeatureView( $feature, $results[$res] ); |
114 | 105 | } |
115 | 106 | } |
116 | 107 | |
117 | 108 | function buildFeatureView( $feature, $error = false, $success = false ) { |
118 | | - global $wgUser, $wgOut, $wgInvitationTypes; |
| 109 | + global $wgUser, $wgOut, $wgInvitationTypes, $wgLang; |
119 | 110 | |
120 | 111 | $friendlyname = wfMsg("invitation-type-$feature"); |
121 | 112 | |
— | — | @@ -124,41 +115,42 @@ |
125 | 116 | $wgOut->enableClientCache( false ); |
126 | 117 | |
127 | 118 | if (Invitations::hasInvite($feature)) { |
128 | | - $wgOut->addWikitext( wfMsg( 'invitations-feature-access', $friendlyname ) ); |
| 119 | + $wgOut->addWikiMsg( 'invitations-feature-access', $friendlyname ); |
129 | 120 | $numleft = Invitations::getRemainingInvites($feature); |
| 121 | + $numLeftFmt = $wgLang->formatNum( $numleft ); |
130 | 122 | |
131 | 123 | if ($numleft > 0) { |
132 | | - $allocation = $wgInvitationTypes[$feature][reserve]; |
| 124 | + $allocation = $wgLang->formatNum( $wgInvitationTypes[$feature]['reserve'] ); |
133 | 125 | |
134 | | - $wgOut->addWikitext( wfMsg( 'invitations-feature-numleft', $numleft, $allocation ) ); |
| 126 | + $wgOut->addWikiMsg( 'invitations-feature-numleft', $numleftFmt, $allocation ); |
135 | 127 | } else if ($numleft == -1) { |
136 | 128 | # Do nothing. |
137 | 129 | } else if (!Invitations::checkDelay( $feature ) ) { |
138 | | - $wgOut->addWikitext( wfMsg( 'invitations-feature-noneyet' ) ); |
| 130 | + $wgOut->addWikiMsg( 'invitations-feature-noneyet' ); |
139 | 131 | } else { |
140 | | - $wgOut->addWikitext( wfMsg( 'invitations-feature-noneleft' ) ); |
| 132 | + $wgOut->addWikiMsg( 'invitations-feature-noneleft' ); |
141 | 133 | } |
142 | 134 | |
143 | 135 | // Successes and errors |
144 | 136 | |
145 | 137 | if ($error) { |
146 | | - $wgOut->addWikitext( '<div class="error">'.$error.'</div>' ); |
| 138 | + $wgOut->wrapWikiMsg( '<div class="error">$1</div>', $error ); |
147 | 139 | } else if ($success) { |
148 | | - $wgOut->addWikitext( '<big>'.$success.'</big>' ); |
| 140 | + $wgOut->wrapWikiMsg( '<big>$1</big>', $success ); |
149 | 141 | } |
150 | 142 | |
151 | 143 | // Invitation form |
152 | 144 | if ($numleft != 0) |
153 | 145 | $wgOut->addHTML( $this->buildInvitationForm($feature, $error) ); |
154 | 146 | } else { |
155 | | - $wgOut->addWikitext( wfMsg( 'invitations-feature-notallowed', $friendlyname ) ); |
| 147 | + $wgOut->addWikiMsg( 'invitations-feature-notallowed', $friendlyname ); |
156 | 148 | } |
157 | 149 | } |
158 | 150 | |
159 | 151 | function buildInvitationForm( $feature, $error = false ) { |
160 | | - $friendlyname = wfMsg("invitation-type-$feature"); |
| 152 | + $friendlyname = wfMsgHtml("invitation-type-$feature"); |
161 | 153 | |
162 | | -# $form = '<h2>'.wfMsgExt('invitations-inviteform-title', 'parseinline', $friendlyname).'</h2>'; |
| 154 | + $form = '<h2>'.wfMsgExt('invitations-inviteform-title', 'parseinline', $friendlyname).'</h2>'; |
163 | 155 | $form = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $wgScript, 'name' => 'uluser' ) ); |
164 | 156 | $form .= Xml::hidden( 'title', SpecialPage::getTitleFor('Invitations', $feature)->getPrefixedText() ); |
165 | 157 | $form .= Xml::hidden( 'invite_submit', 1 ); |
Index: trunk/extensions/Invitations/Invitations.i18n.php |
— | — | @@ -16,14 +16,13 @@ |
17 | 17 | 'invitations-invitedlist-description' => 'You have access to the following invitation-only software features. |
18 | 18 | To manage invitations for an individual feature, click on its name.', |
19 | 19 | 'invitations-invitedlist-none' => 'You have not been invited to use any invitation-only software features.', |
20 | | - 'invitations-invitedlist-item' => '<b>$1</b> ($2 invitations available)', |
| 20 | + 'invitations-invitedlist-item-count' => '({{PLURAL:$1|One invitation|$1 invitations}} available)', |
21 | 21 | 'invitations-pagetitle' => 'Invite-only software features', |
22 | 22 | 'invitations-uninvitedlist-description' => 'You do not have access to these other invitation-only software features.', |
23 | | - 'invitations-uninvitedlist-item' => '<b>$1</b>', |
24 | 23 | 'invitations-uninvitedlist-none' => 'At this time, no other software features are designated invitation-only.', |
25 | 24 | 'invitations-feature-pagetitle' => 'Invitation Management - $1', |
26 | 25 | 'invitations-feature-access' => 'You currently have access to use <i>$1</i>.', |
27 | | - 'invitations-feature-numleft' => 'You still have <b>$1</b> out of your $2 invitations left.', |
| 26 | + 'invitations-feature-numleft' => 'You still have {{PLURAL:$2|one invitation left|<b>$1</b> out of your $2 invitations left}}.', |
28 | 27 | 'invitations-feature-noneleft' => 'You have used all of your allocated invitations for this feature', |
29 | 28 | 'invitations-feature-noneyet' => 'You have not yet received your allocation of invitations for this feature.', |
30 | 29 | 'invitations-feature-notallowed' => 'You do not have access to use <i>$1</i>.', |
Index: trunk/extensions/Invitations/Invitations.php |
— | — | @@ -36,16 +36,24 @@ |
37 | 37 | |
38 | 38 | $wgSpecialPages['Invitations'] = 'SpecialInvitations'; |
39 | 39 | $wgAutoloadClasses['SpecialInvitations'] = $dir . 'Invitations_page.php'; |
40 | | - |
41 | 40 | $wgAutoloadClasses['Invitations'] = $dir . 'Invitations_obj.php'; |
42 | 41 | |
43 | 42 | $wgExtensionMessagesFiles['Invitations'] = $dir . 'Invitations.i18n.php'; |
| 43 | +$wgExtensionAliasesFiles['Invitations'] = $dir . 'Invitations.i18n.alias.php'; |
44 | 44 | |
45 | 45 | $wgInvitationTypes = array(); |
46 | 46 | |
47 | | -// Example: $wgInvitationTypes['centralauth'] = array( reserve => 5, limitedinvites => true, invitedelay => 24 * 3600 * 4 ); |
48 | | -// Limits invites to 'centralauth' to 5 invites per inviter, which can be used 4 days after the user is invited. |
| 47 | +/* |
| 48 | +Example: |
| 49 | +$wgInvitationTypes['centralauth'] = array( |
| 50 | + 'reserve' => 5, |
| 51 | + 'limitedinvites' => true, |
| 52 | + 'invitedelay' => 24 * 3600 * 4 |
| 53 | +); |
49 | 54 | |
| 55 | +Limits invites to 'centralauth' to 5 invites per inviter, which can be used |
| 56 | +4 days after the user is invited. */ |
| 57 | + |
50 | 58 | # Add invite log |
51 | 59 | $wgLogTypes[] = 'invite'; |
52 | 60 | $wgLogNames['invite'] = 'invite-logpage'; |