r106848 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106847‎ | r106848 | r106849 >
Date:20:04, 20 December 2011
Author:ashley
Status:ok
Tags:
Comment:
MarkAsHelpful: coding conventions, added check for MW environment to the main setup file, trimmed trailing spaces
Modified paths:
  • /trunk/extensions/MarkAsHelpful/MarkAsHelpful.hooks.php (modified) (history)
  • /trunk/extensions/MarkAsHelpful/MarkAsHelpful.php (modified) (history)
  • /trunk/extensions/MarkAsHelpful/api/ApiGetMarkAsHelpfulItem.php (modified) (history)
  • /trunk/extensions/MarkAsHelpful/api/ApiMarkAsHelpful.php (modified) (history)
  • /trunk/extensions/MarkAsHelpful/includes/MarkAsHelpfulItem.php (modified) (history)
  • /trunk/extensions/MarkAsHelpful/includes/MarkAsHelpfulUtil.php (modified) (history)
  • /trunk/extensions/MarkAsHelpful/modules/ext.markAsHelpful/ext.markAsHelpful.js (modified) (history)
  • /trunk/extensions/MarkAsHelpful/sql/mark_as_helpful.sql (modified) (history)

Diff [purge]

Index: trunk/extensions/MarkAsHelpful/MarkAsHelpful.php
@@ -4,28 +4,33 @@
55 * Allows specified users to mark certain objects as "Helpful"
66 */
77
 8+if ( !defined( 'MEDIAWIKI' ) ) {
 9+ die();
 10+}
 11+
 12+// Extension credits that will show up on Special:Version
813 $wgExtensionCredits['other'][] = array(
 14+ 'path' => __FILE__,
 15+ 'name' => 'MarkAsHelpful',
 16+ 'version' => '0.1',
917 'author' => array( 'Rob Moen', 'Benny Situ' ),
1018 'descriptionmsg' => 'markashelpful-desc',
11 - 'name' => 'MarkAsHelpful',
1219 'url' => 'https://www.mediawiki.org/wiki/Mark_as_Helpful', // FIXME: A page in the extension namespace should be created
13 - 'version' => '0.1',
14 - 'path' => __FILE__,
1520 );
1621
17 -
 22+$dir = dirname( __FILE__ ) . '/';
1823 // Object model
19 -$wgAutoloadClasses['MarkAsHelpfulItem'] = dirname(__FILE__).'/includes/MarkAsHelpfulItem.php';
20 -$wgAutoloadClasses['MarkAsHelpfulUtil'] = dirname(__FILE__).'/includes/MarkAsHelpfulUtil.php';
 24+$wgAutoloadClasses['MarkAsHelpfulItem'] = $dir . 'includes/MarkAsHelpfulItem.php';
 25+$wgAutoloadClasses['MarkAsHelpfulUtil'] = $dir . 'includes/MarkAsHelpfulUtil.php';
2126
2227 // API
23 -$wgAutoloadClasses['ApiMarkAsHelpful'] = dirname(__FILE__).'/api/ApiMarkAsHelpful.php';
 28+$wgAutoloadClasses['ApiMarkAsHelpful'] = $dir . 'api/ApiMarkAsHelpful.php';
2429 $wgAPIModules['markashelpful'] = 'ApiMarkAsHelpful';
25 -$wgAutoloadClasses['ApiGetMarkAsHelpfulItem'] = dirname(__FILE__).'/api/ApiGetMarkAsHelpfulItem.php';
 30+$wgAutoloadClasses['ApiGetMarkAsHelpfulItem'] = $dir . 'api/ApiGetMarkAsHelpfulItem.php';
2631 $wgAPIModules['getmarkashelpfulitem'] = 'ApiGetMarkAsHelpfulItem';
2732
2833 // Hooks
29 -$wgAutoloadClasses['MarkAsHelpfulHooks'] = dirname(__FILE__).'/MarkAsHelpful.hooks.php';
 34+$wgAutoloadClasses['MarkAsHelpfulHooks'] = $dir . 'MarkAsHelpful.hooks.php';
3035 $wgHooks['BeforePageDisplay'][] = 'MarkAsHelpfulHooks::onPageDisplay';
3136 $wgHooks['LoadExtensionSchemaUpdates'][] = 'MarkAsHelpfulHooks::onLoadExtensionSchemaUpdates';
3237 $wgHooks['MakeGlobalVariablesScript'][] = 'MoodBarHooks::makeGlobalVariablesScript';
@@ -40,11 +45,11 @@
4146 $wgGroupPermissions['sysop']['makrashelpful-admin'] = true;
4247
4348 // Internationalisation
44 -$wgExtensionMessagesFiles['MarkAsHelpful'] = dirname(__FILE__).'/MarkAsHelpful.i18n.php';
 49+$wgExtensionMessagesFiles['MarkAsHelpful'] = $dir . 'MarkAsHelpful.i18n.php';
4550
4651 // Resources
4752 $mbResourceTemplate = array(
48 - 'localBasePath' => dirname(__FILE__) . '/modules',
 53+ 'localBasePath' => $dir . 'modules',
4954 'remoteExtPath' => 'MarkAsHelpful/modules'
5055 );
5156
Index: trunk/extensions/MarkAsHelpful/MarkAsHelpful.hooks.php
@@ -1,4 +1,4 @@
2 -<?
 2+<?php
33
44 class MarkAsHelpfulHooks {
55 /**
@@ -7,7 +7,6 @@
88 * @param $output OutputPage
99 * @param $skin Skin
1010 */
11 -
1211 public static function onPageDisplay( &$output, &$skin ) {
1312 if ( self::addMarkAsHelpful( $output, $skin ) ) {
1413 $output->addModules( array( 'ext.markAsHelpful' ) );
@@ -22,12 +21,11 @@
2322 * @param $output OutputPage
2423 * @param $skin Skin
2524 */
26 - public static function addMarkAsHelpful ( &$output, &$skin ) {
27 -
 25+ public static function addMarkAsHelpful( &$output, &$skin ) {
 26+
2827 return true;
2928 }
3029
31 -
3230 /**
3331 * Runs MarkAsHelpful schema updates#
3432 *
@@ -35,11 +33,10 @@
3634 */
3735 public static function onLoadExtensionSchemaUpdates( $updater = null ) {
3836 $updater->addExtensionUpdate( array( 'addTable', 'mark_as_helpful',
39 - dirname(__FILE__).'/sql/mark_as_helpful.sql', true ) );
40 -
 37+ dirname( __FILE__ ) . '/sql/mark_as_helpful.sql', true ) );
 38+
4139 return true;
4240 }
43 -
4441
4542 public static function makeGlobalVariablesScript( &$vars ) {
4643 global $wgUser;
@@ -47,5 +44,4 @@
4845 return true;
4946 }
5047
51 -
5248 }
Index: trunk/extensions/MarkAsHelpful/includes/MarkAsHelpfulUtil.php
@@ -2,25 +2,18 @@
33
44 class MarkAsHelpfulUtil {
55
6 -
7 - public static function getMarkAsHelpfulTemplate( $User, $isAbleToMark, $HelpfulUserList, $type, $item ) {
8 -
9 -
10 -
11 - if ( $User->isAnon() ) {
12 -
 6+ public static function getMarkAsHelpfulTemplate( $user, $isAbleToMark, $helpfulUserList, $type, $item ) {
 7+ if ( $user->isAnon() ) {
138 $userList = '';
14 -
15 - foreach ( $HelpfulUserList AS $val ) {
16 - $userList .= $val['user_name'] . ' ';
 9+
 10+ foreach ( $helpfulUserList as $val ) {
 11+ $userList .= $val['user_name'] . ' ';
1712 }
18 -
 13+
1914 $data = '';
20 -
 15+
2116 if ( $userList ) {
22 -
2317 $data = wfMessage( 'mah-someone-marked-text' )->params( $userList )->escape();
24 -
2518 }
2619
2720 return <<<HTML
@@ -28,24 +21,20 @@
2922 $data
3023 </div>
3124 HTML;
32 -
33 - }
34 - else {
35 -
 25+ } else {
3626 $userList = '';
37 - $userId = $User->getId();
38 - if ( isset( $HelpfulUserList[$userId] ) ) {
39 -
 27+ $userId = $user->getId();
 28+
 29+ if ( isset( $helpfulUserList[$userId] ) ) {
4030 $data = wfMessage( 'mah-you-marked-text' )->escaped();
4131 $undo = wfMessage( 'mah-undo-mark-text' )->escaped();
42 -
 32+
4333 return <<<HTML
4434 <div id="markashelpful-$type-$item">
4535 $data | $undo
4636 </div>
4737 HTML;
48 - }
49 - else {
 38+ } else {
5039 if ( $isAbleToMark ) {
5140 $linkText = wfMessage( 'mah-mark-text' )->escaped();
5241 return <<<HTML
@@ -54,13 +43,10 @@
5544 </div>
5645 HTML;
5746 }
58 -
 47+
5948 }
60 -
6149 }
62 -
63 -
 50+
6451 }
65 -
66 -
 52+
6753 }
Index: trunk/extensions/MarkAsHelpful/includes/MarkAsHelpfulItem.php
@@ -1,29 +1,29 @@
22 <?php
3 -
4 -
53 /**
6 - * An Enity that handles 'Mark As Helpful' items
 4+ * An entity that handles 'Mark As Helpful' items
75 */
86 class MarkAsHelpfulItem {
9 -
10 - //database field definition
11 - protected $property = array('mah_id' => null,
12 - 'mah_type' => null,
13 - 'mah_item' => null,
14 - 'mah_user_id' => null,
15 - 'mah_user_ip' => null,
16 - 'mah_user_editcount' => null,
17 - 'mah_namespace' => null,
18 - 'mah_title' => null,
19 - 'mah_active' => null,
20 - 'mah_timestamp' => null,
21 - 'mah_system_type' => null,
22 - 'mah_user_agent' => null,
23 - 'mah_locale' => null );
24 -
25 - protected $User;
 7+
 8+ // database field definition
 9+ protected $property = array(
 10+ 'mah_id' => null,
 11+ 'mah_type' => null,
 12+ 'mah_item' => null,
 13+ 'mah_user_id' => null,
 14+ 'mah_user_ip' => null,
 15+ 'mah_user_editcount' => null,
 16+ 'mah_namespace' => null,
 17+ 'mah_title' => null,
 18+ 'mah_active' => null,
 19+ 'mah_timestamp' => null,
 20+ 'mah_system_type' => null,
 21+ 'mah_user_agent' => null,
 22+ 'mah_locale' => null
 23+ );
 24+
 25+ protected $user;
2626 protected $loadFromDatabase = false;
27 -
 27+
2828 /**
2929 * Constructor
3030 */
@@ -32,240 +32,237 @@
3333 $this->property['mah_id'] = $mah_id;
3434 }
3535 }
36 -
 36+
3737 public function getProperty( $key ) {
3838 if( isset( $key, $this->property) ) {
3939 return $this->property[$key];
4040 }
4141 }
42 -
 42+
4343 public function setProperty( $key, $value ) {
4444 if( isset( $key, $this->property) ) {
4545 $this->property[$key] = $value;
4646 }
4747 }
48 -
 48+
4949 public function getUser() {
50 - if ( !$this->User ) {
51 -
 50+ if ( !$this->user ) {
5251 if ( $this->loadFromDatabase ) {
53 - if ( $this->getProperty('mah_user_id') ) {
54 - $this->User = User::newFromId( $this->getProperty( 'mah_user_id' ) );
 52+ if ( $this->getProperty( 'mah_user_id' ) ) {
 53+ $this->user = User::newFromId( $this->getProperty( 'mah_user_id' ) );
 54+ } elseif ( $this->getProperty( 'mah_user_ip' ) ) {
 55+ $this->user = User::newFromName( $this->getProperty( 'mah_user_ip' ) );
5556 }
56 - else if ( $this->getProperty('mah_user_ip') ) {
57 - $this->User = User::newFromName( $this->getProperty( 'mah_user_ip' ) );
58 - }
59 -
60 - }
61 - else {
 57+ } else {
6258 global $wgUser;
63 -
64 - $this->User = $wgUser;
 59+
 60+ $this->user = $wgUser;
6561 }
66 -
6762 }
68 -
69 - return $this->User;
 63+
 64+ return $this->user;
7065 }
71 -
 66+
7267 public function loadFromRequest( $params ) {
73 -
7468 global $wgUser, $wgMarkAsHelpfulType;
7569
7670 if ( isset( $params['type'] ) && in_array( $params['type'], $wgMarkAsHelpfulType ) ) {
7771 $this->setProperty( 'mah_type', $params['type'] );
78 - }
79 - else {
 72+ } else {
8073 throw new MWMarkAsHelpFulItemPropertyException( 'Unsupported type!' );
8174 }
82 -
 75+
8376 if ( isset( $params['item'] ) && $params['item'] == intval( $params['item'] ) ) {
8477 $this->setProperty( 'mah_item', $params['item'] );
85 - }
86 - else {
 78+ } else {
8779 throw new MWMarkAsHelpFulItemPropertyException( 'Invalid item!' );
8880 }
89 -
 81+
9082 if ( $wgUser->isAnon() ) {
9183 $this->setProperty( 'mah_user_ip', $wgUser->getName() );
9284 $this->setProperty( 'mah_user_editcount', 0 );
93 - }
94 - else {
 85+ } else {
9586 $this->setProperty( 'mah_user_id', $wgUser->getId() );
9687 $this->setProperty( 'mah_user_editcount', $wgUser->getEditCount() );
9788 }
98 -
 89+
9990 if ( isset( $params['page'] ) ) {
100 - $Page = Title::newFromText( $params['page'] );
101 -
102 - if ( $Page ) {
103 - $this->setProperty( 'mah_namespace', $Page->getNamespace() );
104 - $this->setProperty( 'mah_title', $Page->getDBkey() );
105 - }
106 - else {
 91+ $page = Title::newFromText( $params['page'] );
 92+
 93+ if ( $page ) {
 94+ $this->setProperty( 'mah_namespace', $page->getNamespace() );
 95+ $this->setProperty( 'mah_title', $page->getDBkey() );
 96+ } else {
10797 throw new MWMarkAsHelpFulItemPropertyException( 'Invalid page!' );
10898 }
10999 }
110 -
 100+
111101 $this->setProperty( 'mah_active', '1' );
112102 $this->setProperty( 'mah_timestamp', wfTimestampNow() );
113 -
 103+
114104 if ( isset( $params['system'] ) ) {
115105 $this->setProperty( 'mah_system_type', $params['system'] );
116106 }
117 - if ( isset ( $params['useragent'] ) ) {
118 - $this->setProperty( 'mah_user_agent', $params['useragent'] );
 107+ if ( isset( $params['useragent'] ) ) {
 108+ $this->setProperty( 'mah_user_agent', $params['useragent'] );
119109 }
120 - if ( isset ( $params['locale'] ) ) {
121 - $this->setProperty( 'mah_locale', $params['locale'] );
 110+ if ( isset( $params['locale'] ) ) {
 111+ $this->setProperty( 'mah_locale', $params['locale'] );
122112 }
123 -
124113 }
125 -
 114+
126115 /**
127 - * Load from Database
128 - * @param $conds array - keys to load unique item from database
 116+ * Load from database
 117+ * @param $conds Array: keys to load unique item from database
129118 */
130119 public function loadFromDatabase( $conds = array() ) {
131 -
132120 $dbr = wfGetDB( DB_SLAVE );
133 -
134 - $res = $dbr->selectRow( array( 'mark_as_helpful' ),
135 - array( '*' ),
136 - $conds,
137 - __METHOD__ );
138 -
 121+
 122+ $res = $dbr->selectRow(
 123+ array( 'mark_as_helpful' ),
 124+ array( '*' ),
 125+ $conds,
 126+ __METHOD__
 127+ );
 128+
139129 if( $res !== false ) {
140 - foreach( $this->property AS $key => $val) {
141 - $this->setProperty( $key, $res->$key );
 130+ foreach( $this->property as $key => $val ) {
 131+ $this->setProperty( $key, $res->$key );
142132 }
143 -
 133+
 134+ // @todo FIXME: $Item is not defined (and it should be called $item
 135+ // as per our coding conventions)
144136 $Item->setLoadFromDatabase = true;
145 -
 137+
146138 return true;
 139+ } else {
 140+ return false;
147141 }
148 - else {
149 - return false;
150 - }
151 -
152142 }
153 -
 143+
154144 /**
155 - * this function should be called after either prepareDataBeforeMark() or setProperty()
156 - * data must be valiated if called from setProperty()
 145+ * This function should be called after either prepareDataBeforeMark() or setProperty()
 146+ * data must be validated if called from setProperty()
157147 */
158148 public function mark() {
159 -
160149 if ( $this->userHasMarked() ) {
161150 return;
162151 }
163 -
164 -
 152+
165153 $dbw = wfGetDB( DB_MASTER );
166 -
 154+
167155 $row = array();
168 -
169 - foreach ( $this->property AS $key => $value ) {
 156+
 157+ foreach ( $this->property as $key => $value ) {
170158 if ( !is_null ( $value ) ) {
171159 $row[$key] = $value;
172160 }
173161 }
174 -
175 -
 162+
176163 $this->property['mah_id'] = $dbw->nextSequenceValue( 'mark_as_helpful_mah_id' );
177164 $dbw->insert( 'mark_as_helpful', $row, __METHOD__ );
178 - $this->setProperty( 'mah_id', $dbw->insertId() );
179 -
 165+ $this->setProperty( 'mah_id', $dbw->insertId() );
180166 }
181 -
182 - public function unmark( $CurrentUser ) {
183 -
 167+
 168+ public function unmark( $currentUser ) {
184169 if ( $this->getProperty( 'mah_id' ) ) {
185170 if ( !$this->getProperty( 'mah_type' ) ) {
186171 if( !$this->loadFromDatabase() ) {
187 - return;
 172+ return;
188173 }
189174 }
190 -
191 - //for sure this is an invalid item
 175+
 176+ // for sure this is an invalid item
192177 if( !$this->getProperty( 'mah_item' ) ) {
193178 return;
194179 }
195 -
196 - $User = $this->getUser();
197 -
198 - if ( $User ) {
199 - if ( $CurrentUser->getId() == $User->getId() || $CurrentUser->getName() == $User->getName() ) {
 180+
 181+ $user = $this->getUser();
 182+
 183+ if ( $user ) {
 184+ if (
 185+ $currentUser->getId() == $user->getId() ||
 186+ $currentUser->getName() == $user->getName()
 187+ )
 188+ {
200189 $dbw = wfGetDB( DB_MASTER );
201 -
202 - $dbw->delete( 'mark_as_helpful', array( 'mah_id' => $this->getProperty( 'mah_id' ) ), __METHOD__ );
203 - }
 190+
 191+ $dbw->delete(
 192+ 'mark_as_helpful',
 193+ array( 'mah_id' => $this->getProperty( 'mah_id' ) ),
 194+ __METHOD__
 195+ );
 196+ }
204197 }
205 -
206 -
207198 }
208199
209200 }
210 -
 201+
211202 public function userHasMarked() {
212 -
213203 $dbr = wfGetDB( DB_SLAVE );
214 -
215 - $conds = array( 'mah_type' => $this->getProperty( 'mah_type' ),
216 - 'mah_item' => intval( $this->getProperty( 'mah_item' ) ) );
217 -
218 - $User = $this->getUser();
219 -
220 - if ( $User ) {
221 - if ( $User->isAnon() ) {
222 - $conds['mah_user_ip'] = $User->getName();
 204+
 205+ $conds = array(
 206+ 'mah_type' => $this->getProperty( 'mah_type' ),
 207+ 'mah_item' => intval( $this->getProperty( 'mah_item' ) )
 208+ );
 209+
 210+ $user = $this->getUser();
 211+
 212+ if ( $user ) {
 213+ if ( $user->isAnon() ) {
 214+ $conds['mah_user_ip'] = $user->getName();
 215+ } else {
 216+ $conds['mah_user_id'] = $user->getId();
223217 }
224 - else {
225 - $conds['mah_user_id'] = $User->getId();
226 - }
227 - }
228 - // Invalid User object, we can't treat this user has marked an item
229 - else {
 218+ } else {
 219+ // Invalid User object, we can't treat this user has marked an item
230220 return true;
231221 }
232 -
233 - $res = $dbr->selectRow( array( 'mark_as_helpful' ),
234 - array( 'mah_id' ),
235 - $conds,
236 - __METHOD__ );
237 -
238 - //user has not marked this item
 222+
 223+ $res = $dbr->selectRow(
 224+ array( 'mark_as_helpful' ),
 225+ array( 'mah_id' ),
 226+ $conds,
 227+ __METHOD__
 228+ );
 229+
 230+ // user has not marked this item
239231 if ( $res === false ) {
240232 return false;
241 - }
242 - else {
 233+ } else {
243234 return true;
244235 }
245 -
246236 }
247 -
248 -
 237+
249238 public static function getMarkAsHelpfulList( $type, $item ) {
250239 $dbr = wfGetDB( DB_SLAVE );
251 -
252 - $conds = array( 'mah_type' => $type,
253 - 'mah_item' => intval( $item ) );
254 -
255 - $res = $dbr->select( array( 'mark_as_helpful', 'user' ),
256 - array( 'mah_id', 'user_id', 'user_name', 'mah_user_ip' ),
257 - $conds,
258 - __METHOD__,
259 - array(),
260 - array( 'user' => array( 'LEFT JOIN', 'mah_user_id=user_id' ) ) );
261 -
 240+
 241+ $conds = array(
 242+ 'mah_type' => $type,
 243+ 'mah_item' => intval( $item )
 244+ );
 245+
 246+ $res = $dbr->select(
 247+ array( 'mark_as_helpful', 'user' ),
 248+ array( 'mah_id', 'user_id', 'user_name', 'mah_user_ip' ),
 249+ $conds,
 250+ __METHOD__,
 251+ array(),
 252+ array( 'user' => array( 'LEFT JOIN', 'mah_user_id=user_id' ) )
 253+ );
 254+
262255 $list = array();
263 -
264 - foreach( $res AS $val ) {
265 - $list[$val['user_id']] = array( 'user_name' => $val['user_name'], 'user_id' => $val['user_id'], 'user_ip' => $val['mah_user_ip'] );
 256+
 257+ foreach( $res as $val ) {
 258+ $list[$val['user_id']] = array(
 259+ 'user_name' => $val['user_name'],
 260+ 'user_id' => $val['user_id'],
 261+ 'user_ip' => $val['mah_user_ip']
 262+ );
266263 }
267 -
 264+
268265 return $list;
269266 }
270267 }
271268
272 -class MWMarkAsHelpFulItemPropertyException extends MWException {};
 269+class MWMarkAsHelpFulItemPropertyException extends MWException {}
\ No newline at end of file
Index: trunk/extensions/MarkAsHelpful/modules/ext.markAsHelpful/ext.markAsHelpful.js
@@ -5,9 +5,8 @@
66 */
77
88 (function( $ ) {
9 -
 9+
1010 var mah = mw.mah = {
11 -
1211 selector: '[class^=markashelpful-]', //only selector for now
1312
1413 init: function() {
@@ -15,34 +14,34 @@
1615
1716 $( mah.selector ).each ( function () {
1817 $( this ).append( $mahWrap );
19 - mah.loadItem( $(this) );
 18+ mah.loadItem( $( this ) );
2019 });
21 - },
 20+ },
2221
23 - /*
24 - * Return object of item properties
 22+ /*
 23+ * Return object of item properties
2524 */
2625 getItemProperties: function( $item ) {
2726 var tag = $item.attr( 'class' ),
2827 properties = {
29 - 'item': tag.split('-')[2], // item id
30 - 'type': tag.split('-')[1] // item type (eg, mbresponse)
 28+ 'item': tag.split( '-' )[2], // item id
 29+ 'type': tag.split( '-' )[1] // item type (eg, mbresponse)
3130 };
3231 return properties;
3332 },
3433
35 - /*
 34+ /*
3635 * Load the current state of the MarkAsHelpful item
37 - */
38 - loadItem: function( $item ) {
39 - var props = mah.getItemProperties( $item );
 36+ */
 37+ loadItem: function( $item ) {
 38+ var props = mah.getItemProperties( $item );
4039
4140 var request = {
4241 'action': 'getmarkashelpfulitem',
4342 'item': props.item,
4443 'type': props.type,
4544 'format': 'json'
46 -
 45+
4746 };
4847 $.ajax({
4948 type: 'get',
@@ -67,7 +66,7 @@
6867 });
6968 },
7069 /*
71 - * API call to mark or unmark an item as helpful.
 70+ * API call to mark or unmark an item as helpful.
7271 */
7372 markItem: function( $item, action ) {
7473 var props = mah.getItemProperties( $item ),
@@ -82,7 +81,7 @@
8382 'token': mw.config.get('mahEditToken'),
8483 'format': 'json'
8584 }, props );
86 -
 85+
8786 $.ajax( {
8887 type: 'post',
8988 url: mw.util.wikiScript( 'api' ),
@@ -92,27 +91,26 @@
9392 } );
9493
9594 }
96 - };
 95+ };
9796
9897 // Some live events for the different modes
9998
100 - /*
 99+ /*
101100 * Click Event for marking an item as helpful.
102101 */
103 - $('.markashelpful-mark').live( 'click', function() {
104 - $item = $(this).parent().parent();
105 - mah.markItem ( $item, 'mark' );
 102+ $( '.markashelpful-mark' ).live( 'click', function() {
 103+ $item = $( this ).parent().parent();
 104+ mah.markItem( $item, 'mark' );
106105 } );
107106
108 - /*
 107+ /*
109108 * Click Event for removing helpful status from an item.
110109 */
111 - $('.markashelpful-undo').live( 'click', function() {
112 - $item = $(this).parent().parent();
113 - mah.markItem ( $item, 'unmark' );
 110+ $( '.markashelpful-undo' ).live( 'click', function() {
 111+ $item = $( this ).parent().parent();
 112+ mah.markItem( $item, 'unmark' );
114113 } );
115114
116115 // Initialize MarkAsHelpful
117116 mah.init();
118 -
119117 } ) ( jQuery );
\ No newline at end of file
Index: trunk/extensions/MarkAsHelpful/api/ApiGetMarkAsHelpfulItem.php
@@ -1,27 +1,28 @@
22 <?php
33
44 class ApiGetMarkAsHelpfulItem extends ApiBase {
5 -
 5+
66 public function execute() {
77 global $wgUser;
8 -
 8+
99 $params = $this->extractRequestParams();
1010
11 - // check if current user has permission to mark this item,
12 - $isAbleToMark = wfRunHooks( 'onMarkItemAsHelpful', array( 'mark', $params['type'], $params['item'], $wgUser ) );
 11+ // check if current user has permission to mark this item,
 12+ $isAbleToMark = wfRunHooks( 'onMarkItemAsHelpful', array( 'mark', $params['type'], $params['item'], $wgUser ) );
1313
1414 $HelpfulUserList = MarkAsHelpfulItem::getMarkAsHelpfulList( $params['type'], $params['item'] );
15 -
 15+
1616 if ( $params['prop'] == 'metadata') {
1717 $data = $HelpfulUserList;
1818 $format = 'metadata';
19 - }
20 - else {
21 - $data = MarkAsHelpfulUtil::getMarkAsHelpfulTemplate( $wgUser, $isAbleToMark, $HelpfulUserList, $params['type'], $params['item'] );
 19+ } else {
 20+ $data = MarkAsHelpfulUtil::getMarkAsHelpfulTemplate(
 21+ $wgUser, $isAbleToMark, $HelpfulUserList, $params['type'],
 22+ $params['item']
 23+ );
2224 $format = 'formatted';
2325 }
24 -
25 -
 26+
2627 $result = array( 'result' => 'success', $format => $data );
2728 $this->getResult()->addValue( null, $this->getModuleName(), $result );
2829 }
@@ -41,7 +42,7 @@
4243 'locale' => null,
4344 'prop' => array(
4445 ApiBase::PARAM_TYPE => array( 'metadata', 'formatted' ),
45 - ),
 46+ ),
4647 );
4748 }
4849
@@ -62,7 +63,7 @@
6364 public function getDescription() {
6465 return 'Get a list of all helpful status for an object item';
6566 }
66 -
 67+
6768 }
6869
69 -class MWApiGetMarkAsHelpfulItemInvalidActionException extends MWException {};
 70+class MWApiGetMarkAsHelpfulItemInvalidActionException extends MWException {}
\ No newline at end of file
Index: trunk/extensions/MarkAsHelpful/api/ApiMarkAsHelpful.php
@@ -1,10 +1,10 @@
22 <?php
33
44 class ApiMarkAsHelpful extends ApiBase {
5 -
 5+
66 public function execute() {
77 global $wgUser;
8 -
 8+
99 if ( $wgUser->isBlocked( false ) ) {
1010 $this->dieUsageMsg( array( 'blockedtext' ) );
1111 }
@@ -12,38 +12,42 @@
1313 $params = $this->extractRequestParams();
1414
1515 // Gives other extension the last chance to speicfy mark as helpful permission rules
16 - if ( !wfRunHooks( 'onMarkItemAsHelpful', array( $params['mahaction'], $params['type'], $params['item'], $wgUser ) ) ) {
17 - $this->dieUsage( "You don't have permission to do that", 'permission-denied' );
 16+ if ( !wfRunHooks( 'onMarkItemAsHelpful', array( $params['mahaction'], $params['type'], $params['item'], $wgUser ) ) ) {
 17+ $this->dieUsage( "You don't have permission to do that", 'permission-denied' );
1818 }
1919
2020 switch ( $params['mahaction'] ) {
21 -
2221 case 'mark':
23 - $Item = new MarkAsHelpfulItem();
24 - $Item->loadFromRequest( $params );
25 - $Item->mark();
 22+ $item = new MarkAsHelpfulItem();
 23+ $item->loadFromRequest( $params );
 24+ $item->mark();
2625 break;
27 -
 26+
2827 case 'unmark':
29 - $Item = new MarkAsHelpfulItem( );
30 -
 28+ $item = new MarkAsHelpfulItem();
 29+
3130 if( $wgUser->isAnon() ) {
32 - $Item->loadFromDatabase( array( 'mah_type' => $params['type'], 'mah_item' => $params['item'], 'mah_user_ip' => $wgUser->getName() ) );
 31+ $item->loadFromDatabase( array(
 32+ 'mah_type' => $params['type'],
 33+ 'mah_item' => $params['item'],
 34+ 'mah_user_ip' => $wgUser->getName()
 35+ ) );
 36+ } else {
 37+ $item->loadFromDatabase( array(
 38+ 'mah_type' => $params['type'],
 39+ 'mah_item' => $params['item'],
 40+ 'mah_user_id' => $wgUser->getId()
 41+ ) );
3342 }
34 - else {
35 - $Item->loadFromDatabase( array( 'mah_type' => $params['type'], 'mah_item' => $params['item'], 'mah_user_id' => $wgUser->getId() ) );
36 - }
37 -
38 - $Item->unmark( $wgUser );
 43+
 44+ $item->unmark( $wgUser );
3945 break;
40 -
 46+
4147 default:
4248 throw new MWApiMarkAsHelpfulInvalidActionException( "Action {$params['mbaction']} not implemented" );
4349 break;
44 -
4550 }
46 -
47 -
 51+
4852 $result = array( 'result' => 'success' );
4953 $this->getResult()->addValue( null, $this->getModuleName(), $result );
5054 }
@@ -108,7 +112,7 @@
109113 public function getDescription() {
110114 return 'Allows users to mark/unmark an object item in the site as helpful';
111115 }
112 -
 116+
113117 }
114118
115 -class MWApiMarkAsHelpfulInvalidActionException extends MWException {};
 119+class MWApiMarkAsHelpfulInvalidActionException extends MWException {}
\ No newline at end of file
Index: trunk/extensions/MarkAsHelpful/sql/mark_as_helpful.sql
@@ -1,16 +1,16 @@
22 CREATE TABLE /*_*/mark_as_helpful (
33 mah_id int unsigned NOT NULL PRIMARY KEY auto_increment, -- Primary key
4 -
 4+
55 mah_type varbinary(32) NOT NULL, -- the object type that is being marked as helpful
66 mah_item int unsigned NOT NULL, -- the object item that is being marked as helpful
77 mah_user_id int unsigned NOT NULL, -- User ID, or zero
88 mah_user_ip varbinary(40) NULL, -- If anonymous, user's IP address
9 - mah_user_editcount int unsigned NOT NULL, -- number of edit for the user
10 -
 9+ mah_user_editcount int unsigned NOT NULL, -- number of edit for the user
 10+
1111 mah_namespace int,
1212 mah_title varchar(255) binary,
13 - mah_active tinyint unsigned not null default 1, -- is this an active 'mark as helpful'
14 -
 13+ mah_active tinyint unsigned NOT NULL default 1, -- is this an active 'mark as helpful'
 14+
1515 -- Options and context
1616 mah_timestamp varchar(14) binary NOT NULL, -- When response was received
1717 mah_system_type varchar(64) binary NULL, -- Operating System

Status & tagging log