Index: trunk/extensions/MarkAsHelpful/MarkAsHelpful.php |
— | — | @@ -4,28 +4,33 @@ |
5 | 5 | * Allows specified users to mark certain objects as "Helpful" |
6 | 6 | */ |
7 | 7 | |
| 8 | +if ( !defined( 'MEDIAWIKI' ) ) { |
| 9 | + die(); |
| 10 | +} |
| 11 | + |
| 12 | +// Extension credits that will show up on Special:Version |
8 | 13 | $wgExtensionCredits['other'][] = array( |
| 14 | + 'path' => __FILE__, |
| 15 | + 'name' => 'MarkAsHelpful', |
| 16 | + 'version' => '0.1', |
9 | 17 | 'author' => array( 'Rob Moen', 'Benny Situ' ), |
10 | 18 | 'descriptionmsg' => 'markashelpful-desc', |
11 | | - 'name' => 'MarkAsHelpful', |
12 | 19 | '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__, |
15 | 20 | ); |
16 | 21 | |
17 | | - |
| 22 | +$dir = dirname( __FILE__ ) . '/'; |
18 | 23 | // 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'; |
21 | 26 | |
22 | 27 | // API |
23 | | -$wgAutoloadClasses['ApiMarkAsHelpful'] = dirname(__FILE__).'/api/ApiMarkAsHelpful.php'; |
| 28 | +$wgAutoloadClasses['ApiMarkAsHelpful'] = $dir . 'api/ApiMarkAsHelpful.php'; |
24 | 29 | $wgAPIModules['markashelpful'] = 'ApiMarkAsHelpful'; |
25 | | -$wgAutoloadClasses['ApiGetMarkAsHelpfulItem'] = dirname(__FILE__).'/api/ApiGetMarkAsHelpfulItem.php'; |
| 30 | +$wgAutoloadClasses['ApiGetMarkAsHelpfulItem'] = $dir . 'api/ApiGetMarkAsHelpfulItem.php'; |
26 | 31 | $wgAPIModules['getmarkashelpfulitem'] = 'ApiGetMarkAsHelpfulItem'; |
27 | 32 | |
28 | 33 | // Hooks |
29 | | -$wgAutoloadClasses['MarkAsHelpfulHooks'] = dirname(__FILE__).'/MarkAsHelpful.hooks.php'; |
| 34 | +$wgAutoloadClasses['MarkAsHelpfulHooks'] = $dir . 'MarkAsHelpful.hooks.php'; |
30 | 35 | $wgHooks['BeforePageDisplay'][] = 'MarkAsHelpfulHooks::onPageDisplay'; |
31 | 36 | $wgHooks['LoadExtensionSchemaUpdates'][] = 'MarkAsHelpfulHooks::onLoadExtensionSchemaUpdates'; |
32 | 37 | $wgHooks['MakeGlobalVariablesScript'][] = 'MoodBarHooks::makeGlobalVariablesScript'; |
— | — | @@ -40,11 +45,11 @@ |
41 | 46 | $wgGroupPermissions['sysop']['makrashelpful-admin'] = true; |
42 | 47 | |
43 | 48 | // Internationalisation |
44 | | -$wgExtensionMessagesFiles['MarkAsHelpful'] = dirname(__FILE__).'/MarkAsHelpful.i18n.php'; |
| 49 | +$wgExtensionMessagesFiles['MarkAsHelpful'] = $dir . 'MarkAsHelpful.i18n.php'; |
45 | 50 | |
46 | 51 | // Resources |
47 | 52 | $mbResourceTemplate = array( |
48 | | - 'localBasePath' => dirname(__FILE__) . '/modules', |
| 53 | + 'localBasePath' => $dir . 'modules', |
49 | 54 | 'remoteExtPath' => 'MarkAsHelpful/modules' |
50 | 55 | ); |
51 | 56 | |
Index: trunk/extensions/MarkAsHelpful/MarkAsHelpful.hooks.php |
— | — | @@ -1,4 +1,4 @@ |
2 | | -<? |
| 2 | +<?php |
3 | 3 | |
4 | 4 | class MarkAsHelpfulHooks { |
5 | 5 | /** |
— | — | @@ -7,7 +7,6 @@ |
8 | 8 | * @param $output OutputPage |
9 | 9 | * @param $skin Skin |
10 | 10 | */ |
11 | | - |
12 | 11 | public static function onPageDisplay( &$output, &$skin ) { |
13 | 12 | if ( self::addMarkAsHelpful( $output, $skin ) ) { |
14 | 13 | $output->addModules( array( 'ext.markAsHelpful' ) ); |
— | — | @@ -22,12 +21,11 @@ |
23 | 22 | * @param $output OutputPage |
24 | 23 | * @param $skin Skin |
25 | 24 | */ |
26 | | - public static function addMarkAsHelpful ( &$output, &$skin ) { |
27 | | - |
| 25 | + public static function addMarkAsHelpful( &$output, &$skin ) { |
| 26 | + |
28 | 27 | return true; |
29 | 28 | } |
30 | 29 | |
31 | | - |
32 | 30 | /** |
33 | 31 | * Runs MarkAsHelpful schema updates# |
34 | 32 | * |
— | — | @@ -35,11 +33,10 @@ |
36 | 34 | */ |
37 | 35 | public static function onLoadExtensionSchemaUpdates( $updater = null ) { |
38 | 36 | $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 | + |
41 | 39 | return true; |
42 | 40 | } |
43 | | - |
44 | 41 | |
45 | 42 | public static function makeGlobalVariablesScript( &$vars ) { |
46 | 43 | global $wgUser; |
— | — | @@ -47,5 +44,4 @@ |
48 | 45 | return true; |
49 | 46 | } |
50 | 47 | |
51 | | - |
52 | 48 | } |
Index: trunk/extensions/MarkAsHelpful/includes/MarkAsHelpfulUtil.php |
— | — | @@ -2,25 +2,18 @@ |
3 | 3 | |
4 | 4 | class MarkAsHelpfulUtil { |
5 | 5 | |
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() ) { |
13 | 8 | $userList = ''; |
14 | | - |
15 | | - foreach ( $HelpfulUserList AS $val ) { |
16 | | - $userList .= $val['user_name'] . ' '; |
| 9 | + |
| 10 | + foreach ( $helpfulUserList as $val ) { |
| 11 | + $userList .= $val['user_name'] . ' '; |
17 | 12 | } |
18 | | - |
| 13 | + |
19 | 14 | $data = ''; |
20 | | - |
| 15 | + |
21 | 16 | if ( $userList ) { |
22 | | - |
23 | 17 | $data = wfMessage( 'mah-someone-marked-text' )->params( $userList )->escape(); |
24 | | - |
25 | 18 | } |
26 | 19 | |
27 | 20 | return <<<HTML |
— | — | @@ -28,24 +21,20 @@ |
29 | 22 | $data |
30 | 23 | </div> |
31 | 24 | HTML; |
32 | | - |
33 | | - } |
34 | | - else { |
35 | | - |
| 25 | + } else { |
36 | 26 | $userList = ''; |
37 | | - $userId = $User->getId(); |
38 | | - if ( isset( $HelpfulUserList[$userId] ) ) { |
39 | | - |
| 27 | + $userId = $user->getId(); |
| 28 | + |
| 29 | + if ( isset( $helpfulUserList[$userId] ) ) { |
40 | 30 | $data = wfMessage( 'mah-you-marked-text' )->escaped(); |
41 | 31 | $undo = wfMessage( 'mah-undo-mark-text' )->escaped(); |
42 | | - |
| 32 | + |
43 | 33 | return <<<HTML |
44 | 34 | <div id="markashelpful-$type-$item"> |
45 | 35 | $data | $undo |
46 | 36 | </div> |
47 | 37 | HTML; |
48 | | - } |
49 | | - else { |
| 38 | + } else { |
50 | 39 | if ( $isAbleToMark ) { |
51 | 40 | $linkText = wfMessage( 'mah-mark-text' )->escaped(); |
52 | 41 | return <<<HTML |
— | — | @@ -54,13 +43,10 @@ |
55 | 44 | </div> |
56 | 45 | HTML; |
57 | 46 | } |
58 | | - |
| 47 | + |
59 | 48 | } |
60 | | - |
61 | 49 | } |
62 | | - |
63 | | - |
| 50 | + |
64 | 51 | } |
65 | | - |
66 | | - |
| 52 | + |
67 | 53 | } |
Index: trunk/extensions/MarkAsHelpful/includes/MarkAsHelpfulItem.php |
— | — | @@ -1,29 +1,29 @@ |
2 | 2 | <?php |
3 | | - |
4 | | - |
5 | 3 | /** |
6 | | - * An Enity that handles 'Mark As Helpful' items |
| 4 | + * An entity that handles 'Mark As Helpful' items |
7 | 5 | */ |
8 | 6 | 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; |
26 | 26 | protected $loadFromDatabase = false; |
27 | | - |
| 27 | + |
28 | 28 | /** |
29 | 29 | * Constructor |
30 | 30 | */ |
— | — | @@ -32,240 +32,237 @@ |
33 | 33 | $this->property['mah_id'] = $mah_id; |
34 | 34 | } |
35 | 35 | } |
36 | | - |
| 36 | + |
37 | 37 | public function getProperty( $key ) { |
38 | 38 | if( isset( $key, $this->property) ) { |
39 | 39 | return $this->property[$key]; |
40 | 40 | } |
41 | 41 | } |
42 | | - |
| 42 | + |
43 | 43 | public function setProperty( $key, $value ) { |
44 | 44 | if( isset( $key, $this->property) ) { |
45 | 45 | $this->property[$key] = $value; |
46 | 46 | } |
47 | 47 | } |
48 | | - |
| 48 | + |
49 | 49 | public function getUser() { |
50 | | - if ( !$this->User ) { |
51 | | - |
| 50 | + if ( !$this->user ) { |
52 | 51 | 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' ) ); |
55 | 56 | } |
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 { |
62 | 58 | global $wgUser; |
63 | | - |
64 | | - $this->User = $wgUser; |
| 59 | + |
| 60 | + $this->user = $wgUser; |
65 | 61 | } |
66 | | - |
67 | 62 | } |
68 | | - |
69 | | - return $this->User; |
| 63 | + |
| 64 | + return $this->user; |
70 | 65 | } |
71 | | - |
| 66 | + |
72 | 67 | public function loadFromRequest( $params ) { |
73 | | - |
74 | 68 | global $wgUser, $wgMarkAsHelpfulType; |
75 | 69 | |
76 | 70 | if ( isset( $params['type'] ) && in_array( $params['type'], $wgMarkAsHelpfulType ) ) { |
77 | 71 | $this->setProperty( 'mah_type', $params['type'] ); |
78 | | - } |
79 | | - else { |
| 72 | + } else { |
80 | 73 | throw new MWMarkAsHelpFulItemPropertyException( 'Unsupported type!' ); |
81 | 74 | } |
82 | | - |
| 75 | + |
83 | 76 | if ( isset( $params['item'] ) && $params['item'] == intval( $params['item'] ) ) { |
84 | 77 | $this->setProperty( 'mah_item', $params['item'] ); |
85 | | - } |
86 | | - else { |
| 78 | + } else { |
87 | 79 | throw new MWMarkAsHelpFulItemPropertyException( 'Invalid item!' ); |
88 | 80 | } |
89 | | - |
| 81 | + |
90 | 82 | if ( $wgUser->isAnon() ) { |
91 | 83 | $this->setProperty( 'mah_user_ip', $wgUser->getName() ); |
92 | 84 | $this->setProperty( 'mah_user_editcount', 0 ); |
93 | | - } |
94 | | - else { |
| 85 | + } else { |
95 | 86 | $this->setProperty( 'mah_user_id', $wgUser->getId() ); |
96 | 87 | $this->setProperty( 'mah_user_editcount', $wgUser->getEditCount() ); |
97 | 88 | } |
98 | | - |
| 89 | + |
99 | 90 | 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 { |
107 | 97 | throw new MWMarkAsHelpFulItemPropertyException( 'Invalid page!' ); |
108 | 98 | } |
109 | 99 | } |
110 | | - |
| 100 | + |
111 | 101 | $this->setProperty( 'mah_active', '1' ); |
112 | 102 | $this->setProperty( 'mah_timestamp', wfTimestampNow() ); |
113 | | - |
| 103 | + |
114 | 104 | if ( isset( $params['system'] ) ) { |
115 | 105 | $this->setProperty( 'mah_system_type', $params['system'] ); |
116 | 106 | } |
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'] ); |
119 | 109 | } |
120 | | - if ( isset ( $params['locale'] ) ) { |
121 | | - $this->setProperty( 'mah_locale', $params['locale'] ); |
| 110 | + if ( isset( $params['locale'] ) ) { |
| 111 | + $this->setProperty( 'mah_locale', $params['locale'] ); |
122 | 112 | } |
123 | | - |
124 | 113 | } |
125 | | - |
| 114 | + |
126 | 115 | /** |
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 |
129 | 118 | */ |
130 | 119 | public function loadFromDatabase( $conds = array() ) { |
131 | | - |
132 | 120 | $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 | + |
139 | 129 | 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 ); |
142 | 132 | } |
143 | | - |
| 133 | + |
| 134 | + // @todo FIXME: $Item is not defined (and it should be called $item |
| 135 | + // as per our coding conventions) |
144 | 136 | $Item->setLoadFromDatabase = true; |
145 | | - |
| 137 | + |
146 | 138 | return true; |
| 139 | + } else { |
| 140 | + return false; |
147 | 141 | } |
148 | | - else { |
149 | | - return false; |
150 | | - } |
151 | | - |
152 | 142 | } |
153 | | - |
| 143 | + |
154 | 144 | /** |
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() |
157 | 147 | */ |
158 | 148 | public function mark() { |
159 | | - |
160 | 149 | if ( $this->userHasMarked() ) { |
161 | 150 | return; |
162 | 151 | } |
163 | | - |
164 | | - |
| 152 | + |
165 | 153 | $dbw = wfGetDB( DB_MASTER ); |
166 | | - |
| 154 | + |
167 | 155 | $row = array(); |
168 | | - |
169 | | - foreach ( $this->property AS $key => $value ) { |
| 156 | + |
| 157 | + foreach ( $this->property as $key => $value ) { |
170 | 158 | if ( !is_null ( $value ) ) { |
171 | 159 | $row[$key] = $value; |
172 | 160 | } |
173 | 161 | } |
174 | | - |
175 | | - |
| 162 | + |
176 | 163 | $this->property['mah_id'] = $dbw->nextSequenceValue( 'mark_as_helpful_mah_id' ); |
177 | 164 | $dbw->insert( 'mark_as_helpful', $row, __METHOD__ ); |
178 | | - $this->setProperty( 'mah_id', $dbw->insertId() ); |
179 | | - |
| 165 | + $this->setProperty( 'mah_id', $dbw->insertId() ); |
180 | 166 | } |
181 | | - |
182 | | - public function unmark( $CurrentUser ) { |
183 | | - |
| 167 | + |
| 168 | + public function unmark( $currentUser ) { |
184 | 169 | if ( $this->getProperty( 'mah_id' ) ) { |
185 | 170 | if ( !$this->getProperty( 'mah_type' ) ) { |
186 | 171 | if( !$this->loadFromDatabase() ) { |
187 | | - return; |
| 172 | + return; |
188 | 173 | } |
189 | 174 | } |
190 | | - |
191 | | - //for sure this is an invalid item |
| 175 | + |
| 176 | + // for sure this is an invalid item |
192 | 177 | if( !$this->getProperty( 'mah_item' ) ) { |
193 | 178 | return; |
194 | 179 | } |
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 | + { |
200 | 189 | $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 | + } |
204 | 197 | } |
205 | | - |
206 | | - |
207 | 198 | } |
208 | 199 | |
209 | 200 | } |
210 | | - |
| 201 | + |
211 | 202 | public function userHasMarked() { |
212 | | - |
213 | 203 | $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(); |
223 | 217 | } |
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 |
230 | 220 | return true; |
231 | 221 | } |
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 |
239 | 231 | if ( $res === false ) { |
240 | 232 | return false; |
241 | | - } |
242 | | - else { |
| 233 | + } else { |
243 | 234 | return true; |
244 | 235 | } |
245 | | - |
246 | 236 | } |
247 | | - |
248 | | - |
| 237 | + |
249 | 238 | public static function getMarkAsHelpfulList( $type, $item ) { |
250 | 239 | $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 | + |
262 | 255 | $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 | + ); |
266 | 263 | } |
267 | | - |
| 264 | + |
268 | 265 | return $list; |
269 | 266 | } |
270 | 267 | } |
271 | 268 | |
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 @@ |
6 | 6 | */ |
7 | 7 | |
8 | 8 | (function( $ ) { |
9 | | - |
| 9 | + |
10 | 10 | var mah = mw.mah = { |
11 | | - |
12 | 11 | selector: '[class^=markashelpful-]', //only selector for now |
13 | 12 | |
14 | 13 | init: function() { |
— | — | @@ -15,34 +14,34 @@ |
16 | 15 | |
17 | 16 | $( mah.selector ).each ( function () { |
18 | 17 | $( this ).append( $mahWrap ); |
19 | | - mah.loadItem( $(this) ); |
| 18 | + mah.loadItem( $( this ) ); |
20 | 19 | }); |
21 | | - }, |
| 20 | + }, |
22 | 21 | |
23 | | - /* |
24 | | - * Return object of item properties |
| 22 | + /* |
| 23 | + * Return object of item properties |
25 | 24 | */ |
26 | 25 | getItemProperties: function( $item ) { |
27 | 26 | var tag = $item.attr( 'class' ), |
28 | 27 | 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) |
31 | 30 | }; |
32 | 31 | return properties; |
33 | 32 | }, |
34 | 33 | |
35 | | - /* |
| 34 | + /* |
36 | 35 | * 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 ); |
40 | 39 | |
41 | 40 | var request = { |
42 | 41 | 'action': 'getmarkashelpfulitem', |
43 | 42 | 'item': props.item, |
44 | 43 | 'type': props.type, |
45 | 44 | 'format': 'json' |
46 | | - |
| 45 | + |
47 | 46 | }; |
48 | 47 | $.ajax({ |
49 | 48 | type: 'get', |
— | — | @@ -67,7 +66,7 @@ |
68 | 67 | }); |
69 | 68 | }, |
70 | 69 | /* |
71 | | - * API call to mark or unmark an item as helpful. |
| 70 | + * API call to mark or unmark an item as helpful. |
72 | 71 | */ |
73 | 72 | markItem: function( $item, action ) { |
74 | 73 | var props = mah.getItemProperties( $item ), |
— | — | @@ -82,7 +81,7 @@ |
83 | 82 | 'token': mw.config.get('mahEditToken'), |
84 | 83 | 'format': 'json' |
85 | 84 | }, props ); |
86 | | - |
| 85 | + |
87 | 86 | $.ajax( { |
88 | 87 | type: 'post', |
89 | 88 | url: mw.util.wikiScript( 'api' ), |
— | — | @@ -92,27 +91,26 @@ |
93 | 92 | } ); |
94 | 93 | |
95 | 94 | } |
96 | | - }; |
| 95 | + }; |
97 | 96 | |
98 | 97 | // Some live events for the different modes |
99 | 98 | |
100 | | - /* |
| 99 | + /* |
101 | 100 | * Click Event for marking an item as helpful. |
102 | 101 | */ |
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' ); |
106 | 105 | } ); |
107 | 106 | |
108 | | - /* |
| 107 | + /* |
109 | 108 | * Click Event for removing helpful status from an item. |
110 | 109 | */ |
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' ); |
114 | 113 | } ); |
115 | 114 | |
116 | 115 | // Initialize MarkAsHelpful |
117 | 116 | mah.init(); |
118 | | - |
119 | 117 | } ) ( jQuery ); |
\ No newline at end of file |
Index: trunk/extensions/MarkAsHelpful/api/ApiGetMarkAsHelpfulItem.php |
— | — | @@ -1,27 +1,28 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | class ApiGetMarkAsHelpfulItem extends ApiBase { |
5 | | - |
| 5 | + |
6 | 6 | public function execute() { |
7 | 7 | global $wgUser; |
8 | | - |
| 8 | + |
9 | 9 | $params = $this->extractRequestParams(); |
10 | 10 | |
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 ) ); |
13 | 13 | |
14 | 14 | $HelpfulUserList = MarkAsHelpfulItem::getMarkAsHelpfulList( $params['type'], $params['item'] ); |
15 | | - |
| 15 | + |
16 | 16 | if ( $params['prop'] == 'metadata') { |
17 | 17 | $data = $HelpfulUserList; |
18 | 18 | $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 | + ); |
22 | 24 | $format = 'formatted'; |
23 | 25 | } |
24 | | - |
25 | | - |
| 26 | + |
26 | 27 | $result = array( 'result' => 'success', $format => $data ); |
27 | 28 | $this->getResult()->addValue( null, $this->getModuleName(), $result ); |
28 | 29 | } |
— | — | @@ -41,7 +42,7 @@ |
42 | 43 | 'locale' => null, |
43 | 44 | 'prop' => array( |
44 | 45 | ApiBase::PARAM_TYPE => array( 'metadata', 'formatted' ), |
45 | | - ), |
| 46 | + ), |
46 | 47 | ); |
47 | 48 | } |
48 | 49 | |
— | — | @@ -62,7 +63,7 @@ |
63 | 64 | public function getDescription() { |
64 | 65 | return 'Get a list of all helpful status for an object item'; |
65 | 66 | } |
66 | | - |
| 67 | + |
67 | 68 | } |
68 | 69 | |
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 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | class ApiMarkAsHelpful extends ApiBase { |
5 | | - |
| 5 | + |
6 | 6 | public function execute() { |
7 | 7 | global $wgUser; |
8 | | - |
| 8 | + |
9 | 9 | if ( $wgUser->isBlocked( false ) ) { |
10 | 10 | $this->dieUsageMsg( array( 'blockedtext' ) ); |
11 | 11 | } |
— | — | @@ -12,38 +12,42 @@ |
13 | 13 | $params = $this->extractRequestParams(); |
14 | 14 | |
15 | 15 | // 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' ); |
18 | 18 | } |
19 | 19 | |
20 | 20 | switch ( $params['mahaction'] ) { |
21 | | - |
22 | 21 | case 'mark': |
23 | | - $Item = new MarkAsHelpfulItem(); |
24 | | - $Item->loadFromRequest( $params ); |
25 | | - $Item->mark(); |
| 22 | + $item = new MarkAsHelpfulItem(); |
| 23 | + $item->loadFromRequest( $params ); |
| 24 | + $item->mark(); |
26 | 25 | break; |
27 | | - |
| 26 | + |
28 | 27 | case 'unmark': |
29 | | - $Item = new MarkAsHelpfulItem( ); |
30 | | - |
| 28 | + $item = new MarkAsHelpfulItem(); |
| 29 | + |
31 | 30 | 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 | + ) ); |
33 | 42 | } |
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 ); |
39 | 45 | break; |
40 | | - |
| 46 | + |
41 | 47 | default: |
42 | 48 | throw new MWApiMarkAsHelpfulInvalidActionException( "Action {$params['mbaction']} not implemented" ); |
43 | 49 | break; |
44 | | - |
45 | 50 | } |
46 | | - |
47 | | - |
| 51 | + |
48 | 52 | $result = array( 'result' => 'success' ); |
49 | 53 | $this->getResult()->addValue( null, $this->getModuleName(), $result ); |
50 | 54 | } |
— | — | @@ -108,7 +112,7 @@ |
109 | 113 | public function getDescription() { |
110 | 114 | return 'Allows users to mark/unmark an object item in the site as helpful'; |
111 | 115 | } |
112 | | - |
| 116 | + |
113 | 117 | } |
114 | 118 | |
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 @@ |
2 | 2 | CREATE TABLE /*_*/mark_as_helpful ( |
3 | 3 | mah_id int unsigned NOT NULL PRIMARY KEY auto_increment, -- Primary key |
4 | | - |
| 4 | + |
5 | 5 | mah_type varbinary(32) NOT NULL, -- the object type that is being marked as helpful |
6 | 6 | mah_item int unsigned NOT NULL, -- the object item that is being marked as helpful |
7 | 7 | mah_user_id int unsigned NOT NULL, -- User ID, or zero |
8 | 8 | 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 | + |
11 | 11 | mah_namespace int, |
12 | 12 | 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 | + |
15 | 15 | -- Options and context |
16 | 16 | mah_timestamp varchar(14) binary NOT NULL, -- When response was received |
17 | 17 | mah_system_type varchar(64) binary NULL, -- Operating System |