r36735 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r36734‎ | r36735 | r36736 >
Date:13:13, 27 June 2008
Author:nikerabbit
Status:old
Tags:
Comment:
* Coding standards, plural for two messages
Modified paths:
  • /trunk/extensions/Invitations/Invitations.i18n.php (modified) (history)
  • /trunk/extensions/Invitations/Invitations.php (modified) (history)
  • /trunk/extensions/Invitations/Invitations_obj.php (modified) (history)
  • /trunk/extensions/Invitations/Invitations_page.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Invitations/Invitations_obj.php
@@ -26,7 +26,7 @@
2727
2828 class Invitations {
2929
30 - /*
 30+ /**
3131 * Does this user have a valid invite to this feature?
3232 * @param string $feature The feature to check.
3333 * @param object $user The user to check, or null for the current user ($wgUser)
@@ -34,7 +34,7 @@
3535 */
3636 public static function hasInvite( $feature, $user = null, &$invite_age = false ) {
3737 global $wgUser, $wgInvitationTypes, $wgDBtype;
38 - if ($user == null)
 38+ if ($user === null)
3939 $user = $wgUser;
4040
4141 // No such invitation type.
@@ -66,7 +66,7 @@
6767 */
6868 public static function getAllowedFeatures( $user = null ) {
6969 global $wgUser;
70 - if ($user == null)
 70+ if ($user === null)
7171 $user = $wgUser;
7272
7373 $dbr = wfGetDb( DB_SLAVE );
@@ -82,7 +82,7 @@
8383 return $features;
8484 }
8585
86 - /*
 86+ /**
8787 * Can the given inviter invite the given invitee to the given feature?
8888 * @param string $feature The feature to check.
8989 * @param object $invitee The user to be invited.
@@ -110,7 +110,7 @@
111111 if (!Invitations::checkDelay($feature, $user, $accountAge))
112112 return INVITE_RESULT_NONE_YET;
113113
114 - if ($wgInvitationTypes[$feature][limitedinvites]) {
 114+ if ($wgInvitationTypes[$feature]['limitedinvites']) {
115115 if (Invitations::getRemainingInvites( $feature, $inviter ) == 0) {
116116 return INVITE_RESULT_NONE_LEFT;
117117 }
@@ -120,7 +120,7 @@
121121 return INVITE_RESULT_OK;
122122 }
123123
124 - /*
 124+ /**
125125 * How many invites does the given inviter have?
126126 * @param string $feature The feature to check.
127127 * @param object $user The user to check, or null for $wgUser.
@@ -128,7 +128,7 @@
129129 */
130130 public static function getRemainingInvites( $feature, $user = null ) {
131131 global $wgUser, $wgInvitationTypes;
132 - if ($user == null)
 132+ if ($user === null)
133133 $user = $wgUser;
134134
135135 $accountAge = 1;
@@ -143,7 +143,7 @@
144144
145145 $accountAge = time() - $accountAge;
146146
147 - if (!$wgInvitationTypes[$feature][limitedinvites])
 147+ if (!$wgInvitationTypes[$feature]['limitedinvites'])
148148 return -1;
149149
150150 if (!Invitations::checkDelay( $feature, $user, $accountAge ))
@@ -151,18 +151,21 @@
152152
153153 $dbr = wfGetDb( DB_SLAVE );
154154
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__ );
156159
157160 if ($dbr->numRows($res) > 0) {
158161 $num = $dbr->fetchObject($res)->ic_count;
159162 return $num;
160163 } 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'];
163166 }
164167 }
165168
166 - /*
 169+ /**
167170 * Check if the given user has had the given feature for long enough to invite.
168171 * @param string $feature The feature to check
169172 * @param object $user The user to check
@@ -170,24 +173,24 @@
171174 */
172175 public static function checkDelay( $feature, $user = null, $time = null ) {
173176 global $wgUser, $wgInvitationTypes;
174 - if ($user == null)
 177+ if ($user === null)
175178 $user = $wgUser;
176179
177 - if ($time != null) {
 180+ if ($time !== null) {
178181 // Do nothing
179 - } else if ($time == null && !Invitations::hasInvite( $feature, $user, $time )) {
 182+ } else if ($time === null && !Invitations::hasInvite( $feature, $user, $time )) {
180183 return false;
181184 } else {
182185 // The user has an invite, and we retrieved its creation point. Find its age
183186 $time = time() - $time;
184187 }
185188
186 - if ($time < $wgInvitationTypes[$feature][invitedelay]) {
 189+ if ($time < $wgInvitationTypes[$feature]['invitedelay']) {
187190 return false;
188191 } else return true;
189192 }
190193
191 - /*
 194+ /**
192195 * Insert a row into the invite_count table for the given user and feature.
193196 * @param string $feature The feature to check.
194197 * @param object $user The user to check, or null for $wgUser.
@@ -196,7 +199,7 @@
197200 */
198201 private static function insertCountRow( $feature, $user = null, $count = null ) {
199202 global $wgUser, $wgInvitationTypes;
200 - if ($user == null)
 203+ if ($user === null)
201204 $user = $wgUser;
202205
203206 // No such invitation type.
@@ -215,7 +218,7 @@
216219 }
217220 }
218221
219 - /*
 222+ /**
220223 * Add an invitation for the given invitee, from the given inviter.
221224 * @param string $feature The feature to invite to.
222225 * @param object $invitee The user to be invited.
@@ -224,7 +227,7 @@
225228 */
226229 public static function inviteUser( $feature, $invitee, $inviter = null ) {
227230 global $wgUser, $wgInvitationTypes;
228 - if ($inviter == null)
 231+ if ($inviter === null)
229232 $inviter = $wgUser;
230233
231234 if ( ($res = Invitations::checkInviteOperation($feature, $invitee, $inviter)) != INVITE_RESULT_OK) {
@@ -235,11 +238,16 @@
236239 $dbw = wfGetDB( DB_MASTER );
237240
238241 $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__ );
240244
241245 $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__ );
244252
245253 // Log it.
246254 $log = new LogPage( 'invite' );
Index: trunk/extensions/Invitations/Invitations_page.php
@@ -17,20 +17,13 @@
1818 * @addtogroup Extensions
1919 */
2020
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');
3224 }
3325
3426 function execute( $subpage ) {
 27+ wfLoadExtensionMessages('Invitations');
3528 global $wgRequest;
3629
3730 if ($subpage != '' && $wgRequest->getBool('invite_submit')) {
@@ -43,7 +36,7 @@
4437 }
4538
4639 function buildMainView() {
47 - global $wgOut,$wgUser,$wgInvitationTypes;
 40+ global $wgOut,$wgUser,$wgInvitationTypes, $wgLang;
4841 $sk = $wgUser->getSkin();
4942
5043 $wgOut->setPageTitle( wfMsg( 'invitations-pagetitle' ) );
@@ -54,37 +47,37 @@
5548 $invitedfeatures = Invitations::getAllowedFeatures();
5649
5750 if (count($invitedfeatures)) {
58 - $wgOut->addWikitext( wfMsg( 'invitations-invitedlist-description' ) );
 51+ $wgOut->addWikiMsg( 'invitations-invitedlist-description' );
5952 $wgOut->addHTML( '<ul>' );
6053
6154 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 ) );
6457
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 );
6660
6761 $wgOut->addHTML( "<li> $text </li>" );
6862 }
6963 } else {
70 - $wgOut->addWikitext( wfMsg( 'invitations-invitedlist-none' ) );
 64+ $wgOut->addWikiMsg( 'invitations-invitedlist-none' );
7165 }
7266
7367 $uninvitedfeatures = array_diff( array_keys($wgInvitationTypes), $invitedfeatures );
7468
7569 if (count($uninvitedfeatures)) {
76 - $wgOut->addWikitext( wfMsg( 'invitations-uninvitedlist-description' ) );
 70+ $wgOut->addWikiMsg( 'invitations-uninvitedlist-description' );
7771 $wgOut->addHTML( '<ul>' );
7872
7973 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") );
8275
83 - $text = wfMsgExt( 'invitations-uninvitedlist-item', array( 'parseinline', 'replaceafter' ), $link, $num );
 76+ $text = "<b>$link</b>";
8477
8578 $wgOut->addHTML( "<li> $text </li>" );
8679 }
8780 } else {
88 - $wgOut->addWikitext( wfMsg( 'invitations-uninvitedlist-none' ) );
 81+ $wgOut->addWikiMsg( 'invitations-uninvitedlist-none' );
8982 }
9083 }
9184
@@ -95,26 +88,24 @@
9689 $invitee = User::newFromName($username);
9790
9891 if ($invitee->getId() == 0) {
99 - $this->buildFeatureView( $feature, wfMsg( 'invitation-error-baduser' ) );
 92+ $this->buildFeatureView( $feature, 'invitation-error-baduser' );
10093 return;
10194 }
10295
10396 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 ) );
10598 } else {
10699 $results = array( INVITE_RESULT_ALREADY_INVITED => array( 'invitations-error-alreadyinvited', $username ),
107100 INVITE_RESULT_NOT_ALLOWED => array( 'invitations-feature-notallowed', wfMsg("invitations-type-$feature") ),
108101 INVITE_RESULT_NONE_LEFT => array( 'invitations-feature-noneleft' ),
109102 INVITE_RESULT_NONE_YET => array( 'invitations-feature-noneyet' ) );
110103
111 - $message = call_user_func_array( 'wfMsg', $results[$res] );
112 -
113 - $this->buildFeatureView( $feature, $message );
 104+ $this->buildFeatureView( $feature, $results[$res] );
114105 }
115106 }
116107
117108 function buildFeatureView( $feature, $error = false, $success = false ) {
118 - global $wgUser, $wgOut, $wgInvitationTypes;
 109+ global $wgUser, $wgOut, $wgInvitationTypes, $wgLang;
119110
120111 $friendlyname = wfMsg("invitation-type-$feature");
121112
@@ -124,41 +115,42 @@
125116 $wgOut->enableClientCache( false );
126117
127118 if (Invitations::hasInvite($feature)) {
128 - $wgOut->addWikitext( wfMsg( 'invitations-feature-access', $friendlyname ) );
 119+ $wgOut->addWikiMsg( 'invitations-feature-access', $friendlyname );
129120 $numleft = Invitations::getRemainingInvites($feature);
 121+ $numLeftFmt = $wgLang->formatNum( $numleft );
130122
131123 if ($numleft > 0) {
132 - $allocation = $wgInvitationTypes[$feature][reserve];
 124+ $allocation = $wgLang->formatNum( $wgInvitationTypes[$feature]['reserve'] );
133125
134 - $wgOut->addWikitext( wfMsg( 'invitations-feature-numleft', $numleft, $allocation ) );
 126+ $wgOut->addWikiMsg( 'invitations-feature-numleft', $numleftFmt, $allocation );
135127 } else if ($numleft == -1) {
136128 # Do nothing.
137129 } else if (!Invitations::checkDelay( $feature ) ) {
138 - $wgOut->addWikitext( wfMsg( 'invitations-feature-noneyet' ) );
 130+ $wgOut->addWikiMsg( 'invitations-feature-noneyet' );
139131 } else {
140 - $wgOut->addWikitext( wfMsg( 'invitations-feature-noneleft' ) );
 132+ $wgOut->addWikiMsg( 'invitations-feature-noneleft' );
141133 }
142134
143135 // Successes and errors
144136
145137 if ($error) {
146 - $wgOut->addWikitext( '<div class="error">'.$error.'</div>' );
 138+ $wgOut->wrapWikiMsg( '<div class="error">$1</div>', $error );
147139 } else if ($success) {
148 - $wgOut->addWikitext( '<big>'.$success.'</big>' );
 140+ $wgOut->wrapWikiMsg( '<big>$1</big>', $success );
149141 }
150142
151143 // Invitation form
152144 if ($numleft != 0)
153145 $wgOut->addHTML( $this->buildInvitationForm($feature, $error) );
154146 } else {
155 - $wgOut->addWikitext( wfMsg( 'invitations-feature-notallowed', $friendlyname ) );
 147+ $wgOut->addWikiMsg( 'invitations-feature-notallowed', $friendlyname );
156148 }
157149 }
158150
159151 function buildInvitationForm( $feature, $error = false ) {
160 - $friendlyname = wfMsg("invitation-type-$feature");
 152+ $friendlyname = wfMsgHtml("invitation-type-$feature");
161153
162 -# $form = '<h2>'.wfMsgExt('invitations-inviteform-title', 'parseinline', $friendlyname).'</h2>';
 154+ $form = '<h2>'.wfMsgExt('invitations-inviteform-title', 'parseinline', $friendlyname).'</h2>';
163155 $form = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $wgScript, 'name' => 'uluser' ) );
164156 $form .= Xml::hidden( 'title', SpecialPage::getTitleFor('Invitations', $feature)->getPrefixedText() );
165157 $form .= Xml::hidden( 'invite_submit', 1 );
Index: trunk/extensions/Invitations/Invitations.i18n.php
@@ -16,14 +16,13 @@
1717 'invitations-invitedlist-description' => 'You have access to the following invitation-only software features.
1818 To manage invitations for an individual feature, click on its name.',
1919 '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)',
2121 'invitations-pagetitle' => 'Invite-only software features',
2222 'invitations-uninvitedlist-description' => 'You do not have access to these other invitation-only software features.',
23 - 'invitations-uninvitedlist-item' => '<b>$1</b>',
2423 'invitations-uninvitedlist-none' => 'At this time, no other software features are designated invitation-only.',
2524 'invitations-feature-pagetitle' => 'Invitation Management - $1',
2625 '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}}.',
2827 'invitations-feature-noneleft' => 'You have used all of your allocated invitations for this feature',
2928 'invitations-feature-noneyet' => 'You have not yet received your allocation of invitations for this feature.',
3029 'invitations-feature-notallowed' => 'You do not have access to use <i>$1</i>.',
Index: trunk/extensions/Invitations/Invitations.php
@@ -36,16 +36,24 @@
3737
3838 $wgSpecialPages['Invitations'] = 'SpecialInvitations';
3939 $wgAutoloadClasses['SpecialInvitations'] = $dir . 'Invitations_page.php';
40 -
4140 $wgAutoloadClasses['Invitations'] = $dir . 'Invitations_obj.php';
4241
4342 $wgExtensionMessagesFiles['Invitations'] = $dir . 'Invitations.i18n.php';
 43+$wgExtensionAliasesFiles['Invitations'] = $dir . 'Invitations.i18n.alias.php';
4444
4545 $wgInvitationTypes = array();
4646
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+);
4954
 55+Limits invites to 'centralauth' to 5 invites per inviter, which can be used
 56+4 days after the user is invited. */
 57+
5058 # Add invite log
5159 $wgLogTypes[] = 'invite';
5260 $wgLogNames['invite'] = 'invite-logpage';

Status & tagging log