Index: branches/wmf/1.18wmf1/extensions/MarkAsHelpful/sql/mark_as_helpful.sql |
— | — | @@ -0,0 +1,19 @@ |
| 2 | +CREATE TABLE /*_*/mark_as_helpful ( |
| 3 | + mah_id int unsigned NOT NULL PRIMARY KEY auto_increment, -- Primary key |
| 4 | + |
| 5 | + mah_type varbinary(32) NOT NULL, -- the object type that is being marked as helpful |
| 6 | + mah_item int unsigned NOT NULL, -- the object item that is being marked as helpful |
| 7 | + mah_user_id int unsigned NOT NULL, -- User ID |
| 8 | + mah_user_editcount int unsigned NOT NULL, -- number of edit for the user |
| 9 | + |
| 10 | + mah_namespace int, |
| 11 | + mah_title varchar(255) binary, |
| 12 | + |
| 13 | + -- Options and context |
| 14 | + mah_timestamp varchar(14) binary NOT NULL, -- When response was received |
| 15 | + mah_system_type varchar(64) binary NULL, -- Operating System |
| 16 | + mah_user_agent varchar(255) binary NULL, -- User-Agent header |
| 17 | + mah_locale varchar(32) binary NULL -- The locale of the user's browser |
| 18 | +) /*$wgDBTableOptions*/; |
| 19 | + |
| 20 | +CREATE UNIQUE INDEX /*i*/mah_type_item_user_id ON /*_*/mark_as_helpful (mah_type, mah_item, mah_user_id); |
Property changes on: branches/wmf/1.18wmf1/extensions/MarkAsHelpful/sql/mark_as_helpful.sql |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 21 | + native |
Index: branches/wmf/1.18wmf1/extensions/MarkAsHelpful/MarkAsHelpful.i18n.php |
— | — | @@ -0,0 +1,150 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Internationalisation file for MarkAsHelpful extension. |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
| 8 | + */ |
| 9 | + |
| 10 | +$messages = array(); |
| 11 | + |
| 12 | +/** English |
| 13 | + * @author Rob Moen |
| 14 | + */ |
| 15 | +$messages['en'] = array( |
| 16 | + 'markashelpful-desc' => 'Provides a user interface to mark comments as helpful', |
| 17 | + 'mah-mark-text' => 'Mark as helpful', |
| 18 | + 'mah-you-marked-text' => 'You think this is helpful', |
| 19 | + 'mah-someone-marked-text' => '{{GENDER:$1|$1 thinks this is helpful}}', |
| 20 | + 'mah-undo-mark-text' => 'undo', |
| 21 | + 'mah-action-error' => 'There was an error performing this action', |
| 22 | +); |
| 23 | + |
| 24 | +/** Message documentation (Message documentation) |
| 25 | + * @author Rob Moen |
| 26 | + */ |
| 27 | +$messages['qqq'] = array( |
| 28 | + 'markashelpful-desc' => '{{desc}} |
| 29 | +This is a feature in development. See [[mw:MarkAsHelpful]] for background information.', |
| 30 | + 'mah-mark-text' => 'Text to prompt the user to mark this item as helpful', |
| 31 | + 'mah-you-marked-text' => 'Text displayed to the logged in user if they mark an item helpful', |
| 32 | + 'mah-someone-marked-text' => '$1 is the username that can be used for GENDER. $1 displays username who marked as helpful', |
| 33 | + 'mah-undo-mark-text' => 'Text for the the undo mark link', |
| 34 | + 'mah-action-error' => 'Generic error message', |
| 35 | +); |
| 36 | + |
| 37 | +/** Breton (Brezhoneg) |
| 38 | + * @author Y-M D |
| 39 | + */ |
| 40 | +$messages['br'] = array( |
| 41 | + 'markashelpful-desc' => 'Pourchas a ra un etrefas implijer evit merkañ an evezhiadennoù evel talvoudus', |
| 42 | + 'mah-mark-text' => 'Merkañ evel talvoudus', |
| 43 | + 'mah-you-marked-text' => "Soñjal a ra deoc'h ez eo talvoudus", |
| 44 | + 'mah-someone-marked-text' => 'Soñjal a ra {{GENDER:$1|$1}} ez eo talvoudus', |
| 45 | + 'mah-undo-mark-text' => 'dizober', |
| 46 | + 'mah-action-error' => "Ur fazi a zo bet oc'h ober an obererezh-mañ", |
| 47 | +); |
| 48 | + |
| 49 | +/** German (Deutsch) |
| 50 | + * @author Kghbln |
| 51 | + */ |
| 52 | +$messages['de'] = array( |
| 53 | + 'markashelpful-desc' => 'Ermöglicht eine Benutzeroberfläche mit der Kommentare als hilfreich markiert werden können', |
| 54 | + 'mah-mark-text' => 'Als hilfreich markieren', |
| 55 | + 'mah-you-marked-text' => 'Du meinst, dass dieser Kommentar hilfreich ist.', |
| 56 | + 'mah-someone-marked-text' => '{{GENDER:$1|$1}} meint, dass dieser Kommentar hilfreich ist.', |
| 57 | + 'mah-undo-mark-text' => 'rückgängig machen', |
| 58 | + 'mah-action-error' => 'Beim Ausführen dieser Aktion ist ein Fehler aufgetreten.', |
| 59 | +); |
| 60 | + |
| 61 | +/** German (formal address) (Deutsch (Sie-Form)) |
| 62 | + * @author Kghbln |
| 63 | + */ |
| 64 | +$messages['de-formal'] = array( |
| 65 | + 'mah-you-marked-text' => 'Sie meinen, dass dieser Kommentar hilfreich ist.', |
| 66 | +); |
| 67 | + |
| 68 | +/** Lower Sorbian (Dolnoserbski) |
| 69 | + * @author Michawiki |
| 70 | + */ |
| 71 | +$messages['dsb'] = array( |
| 72 | + 'markashelpful-desc' => 'Staja wužywarski pówjerch k dispoziciji, aby se komentary ako pomocniwe markěrowali', |
| 73 | + 'mah-mark-text' => 'Ako pomocniwe markěrowaś', |
| 74 | + 'mah-you-marked-text' => 'Maš to za pomocniwe', |
| 75 | + 'mah-someone-marked-text' => '{{GENDER:$1|$1}} ma to za pomoclnwe', |
| 76 | + 'mah-undo-mark-text' => 'anulěrowaś', |
| 77 | + 'mah-action-error' => 'Pśi wuwjeźenju akcije jo zmólka nastała', |
| 78 | +); |
| 79 | + |
| 80 | +/** French (Français) |
| 81 | + * @author Gomoko |
| 82 | + */ |
| 83 | +$messages['fr'] = array( |
| 84 | + 'markashelpful-desc' => 'Fournit une interface utilisateur pour marquer les commentaires comme utiles', |
| 85 | + 'mah-mark-text' => 'Marquer comme utile', |
| 86 | + 'mah-you-marked-text' => 'Vous pensez que ceci est utile', |
| 87 | + 'mah-someone-marked-text' => '{{GENDER:$1|$1}} pense que cela est utile', |
| 88 | + 'mah-undo-mark-text' => 'annuler', |
| 89 | + 'mah-action-error' => 'Il y a eu une erreur en exécutant cette action', |
| 90 | +); |
| 91 | + |
| 92 | +/** Galician (Galego) |
| 93 | + * @author Toliño |
| 94 | + */ |
| 95 | +$messages['gl'] = array( |
| 96 | + 'markashelpful-desc' => 'Proporciona unha interface de usuario para marcar comentarios como útiles', |
| 97 | + 'mah-mark-text' => 'Marcar isto como útil', |
| 98 | + 'mah-you-marked-text' => 'Pensa que isto é útil', |
| 99 | + 'mah-someone-marked-text' => '{{GENDER:$1|$1}} pensa que isto é útil', |
| 100 | + 'mah-undo-mark-text' => 'desfacer', |
| 101 | + 'mah-action-error' => 'Houbo un erro ao levar a cabo a acción', |
| 102 | +); |
| 103 | + |
| 104 | +/** Upper Sorbian (Hornjoserbsce) |
| 105 | + * @author Michawiki |
| 106 | + */ |
| 107 | +$messages['hsb'] = array( |
| 108 | + 'markashelpful-desc' => 'Staja wužiwarski powjerch k dispoziciji, zo bychu so komentary jako pomocliwe markěrowali', |
| 109 | + 'mah-mark-text' => 'Jako pomocliwy markěrować', |
| 110 | + 'mah-you-marked-text' => 'Maš to za pomocliwe', |
| 111 | + 'mah-someone-marked-text' => '{{GENDER:$1|$1}} ma to za pomocliwe', |
| 112 | + 'mah-undo-mark-text' => 'cofnyć', |
| 113 | + 'mah-action-error' => 'Při wuwjedźenju akcije je zmylk wustupił', |
| 114 | +); |
| 115 | + |
| 116 | +/** Luxembourgish (Lëtzebuergesch) |
| 117 | + * @author Robby |
| 118 | + */ |
| 119 | +$messages['lb'] = array( |
| 120 | + 'markashelpful-desc' => 'E Benotzerinterface fir Bemierkungen als hëllefräich ze markéieren', |
| 121 | + 'mah-mark-text' => 'Dëst als nëtzlech markéieren', |
| 122 | + 'mah-you-marked-text' => 'Dir mengt datt dat nëtzlech ass', |
| 123 | + 'mah-someone-marked-text' => '{{GENDER:$1|$1}} mengt, datt dës Bemierkung hëllefräich ass.', |
| 124 | + 'mah-undo-mark-text' => 'réckgängeg maachen', |
| 125 | + 'mah-action-error' => 'Et gouf e Feeler wéi dës Aktioun gemaach gouf', |
| 126 | +); |
| 127 | + |
| 128 | +/** Macedonian (Македонски) |
| 129 | + * @author Bjankuloski06 |
| 130 | + */ |
| 131 | +$messages['mk'] = array( |
| 132 | + 'markashelpful-desc' => 'Овозможува кориснички посредник за означување на коментари како корисни (т.е. од помош)', |
| 133 | + 'mah-mark-text' => 'Означете го ова како корисно', |
| 134 | + 'mah-you-marked-text' => 'Сметате дека ова е корисно', |
| 135 | + 'mah-someone-marked-text' => '{{GENDER:$1|$1}} смета дека ова е корисно', |
| 136 | + 'mah-undo-mark-text' => 'врати', |
| 137 | + 'mah-action-error' => 'Се појави грешка при извршувањето на дејството', |
| 138 | +); |
| 139 | + |
| 140 | +/** Dutch (Nederlands) |
| 141 | + * @author Siebrand |
| 142 | + */ |
| 143 | +$messages['nl'] = array( |
| 144 | + 'markashelpful-desc' => 'Biedt een gebruikersinterface om opmerkingen als nuttig te markeren', |
| 145 | + 'mah-mark-text' => 'Als nuttig markeren', |
| 146 | + 'mah-you-marked-text' => 'U denkt dat dit nuttig is', |
| 147 | + 'mah-someone-marked-text' => '{{GENDER:$1|$1}} denkt dat dit nuttig is', |
| 148 | + 'mah-undo-mark-text' => 'ongedaan maken', |
| 149 | + 'mah-action-error' => 'Er is een fout opgetreden tijdens het uitvoeren van deze handeling', |
| 150 | +); |
| 151 | + |
Property changes on: branches/wmf/1.18wmf1/extensions/MarkAsHelpful/MarkAsHelpful.i18n.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 152 | + native |
Index: branches/wmf/1.18wmf1/extensions/MarkAsHelpful/MarkAsHelpful.php |
— | — | @@ -0,0 +1,66 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * HelpfulMarker extension |
| 5 | + * Allows specified users to mark certain objects as "Helpful" |
| 6 | + */ |
| 7 | + |
| 8 | +if ( !defined( 'MEDIAWIKI' ) ) { |
| 9 | + die(); |
| 10 | +} |
| 11 | + |
| 12 | +// Configuration |
| 13 | +// TODO: document |
| 14 | +$wgMarkAsHelpfulType = array(); |
| 15 | + |
| 16 | +// Extension credits that will show up on Special:Version |
| 17 | +$wgExtensionCredits['other'][] = array( |
| 18 | + 'path' => __FILE__, |
| 19 | + 'name' => 'MarkAsHelpful', |
| 20 | + 'version' => '0.1', |
| 21 | + 'author' => array( 'Rob Moen', 'Benny Situ' ), |
| 22 | + 'descriptionmsg' => 'markashelpful-desc', |
| 23 | + 'url' => 'https://www.mediawiki.org/wiki/Mark_as_Helpful', // FIXME: A page in the extension namespace should be created |
| 24 | +); |
| 25 | + |
| 26 | +$dir = dirname( __FILE__ ) . '/'; |
| 27 | +// Object model |
| 28 | +$wgAutoloadClasses['MarkAsHelpfulItem'] = $dir . 'includes/MarkAsHelpfulItem.php'; |
| 29 | +$wgAutoloadClasses['MarkAsHelpfulUtil'] = $dir . 'includes/MarkAsHelpfulUtil.php'; |
| 30 | + |
| 31 | +// API |
| 32 | +$wgAutoloadClasses['ApiMarkAsHelpful'] = $dir . 'api/ApiMarkAsHelpful.php'; |
| 33 | +$wgAPIModules['markashelpful'] = 'ApiMarkAsHelpful'; |
| 34 | +$wgAutoloadClasses['ApiGetMarkAsHelpfulItem'] = $dir . 'api/ApiGetMarkAsHelpfulItem.php'; |
| 35 | +$wgAPIModules['getmarkashelpfulitem'] = 'ApiGetMarkAsHelpfulItem'; |
| 36 | + |
| 37 | +// Hooks |
| 38 | +$wgAutoloadClasses['MarkAsHelpfulHooks'] = $dir . 'MarkAsHelpful.hooks.php'; |
| 39 | +$wgHooks['BeforePageDisplay'][] = 'MarkAsHelpfulHooks::onPageDisplay'; |
| 40 | +$wgHooks['LoadExtensionSchemaUpdates'][] = 'MarkAsHelpfulHooks::onLoadExtensionSchemaUpdates'; |
| 41 | +$wgHooks['MakeGlobalVariablesScript'][] = 'MarkAsHelpfulHooks::makeGlobalVariablesScript'; |
| 42 | + |
| 43 | +// Special pages |
| 44 | + |
| 45 | + |
| 46 | +// User rights |
| 47 | +$wgAvailableRights[] = 'markashelpful-view'; |
| 48 | +$wgAvailableRights[] = 'markashelpful-admin'; |
| 49 | + |
| 50 | +$wgGroupPermissions['sysop']['markashelpful-admin'] = true; |
| 51 | + |
| 52 | +// Internationalisation |
| 53 | +$wgExtensionMessagesFiles['MarkAsHelpful'] = $dir . 'MarkAsHelpful.i18n.php'; |
| 54 | + |
| 55 | +// Resources |
| 56 | +$mahResourceTemplate = array( |
| 57 | + 'localBasePath' => $dir . 'modules', |
| 58 | + 'remoteExtPath' => 'MarkAsHelpful/modules' |
| 59 | +); |
| 60 | + |
| 61 | +$wgResourceModules['ext.markAsHelpful'] = $mahResourceTemplate + array( |
| 62 | + 'styles' => 'ext.markAsHelpful/ext.markAsHelpful.css', |
| 63 | + 'scripts' => 'ext.markAsHelpful/ext.markAsHelpful.js', |
| 64 | + 'dependencies' => array( |
| 65 | + 'mediawiki.util' |
| 66 | + ), |
| 67 | +); |
\ No newline at end of file |
Property changes on: branches/wmf/1.18wmf1/extensions/MarkAsHelpful/MarkAsHelpful.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 68 | + native |
Index: branches/wmf/1.18wmf1/extensions/MarkAsHelpful/MarkAsHelpful.hooks.php |
— | — | @@ -0,0 +1,46 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class MarkAsHelpfulHooks { |
| 5 | + /** |
| 6 | + * Adds MarkAsHelpful JS to the output if appropriate. |
| 7 | + * |
| 8 | + * @param $output OutputPage |
| 9 | + * @param $skin Skin |
| 10 | + */ |
| 11 | + public static function onPageDisplay( &$output, &$skin ) { |
| 12 | + if ( self::addMarkAsHelpful( $output, $skin ) ) { |
| 13 | + $output->addModules( array( 'ext.markAsHelpful' ) ); |
| 14 | + } |
| 15 | + |
| 16 | + return true; |
| 17 | + } |
| 18 | + |
| 19 | + /** |
| 20 | + * Determines whether or not we should add MarkAsHelpful to the current page. |
| 21 | + * |
| 22 | + * @param $output OutputPage |
| 23 | + * @param $skin Skin |
| 24 | + */ |
| 25 | + public static function addMarkAsHelpful( &$output, &$skin ) { |
| 26 | + |
| 27 | + return true; |
| 28 | + } |
| 29 | + |
| 30 | + /** |
| 31 | + * Runs MarkAsHelpful schema updates# |
| 32 | + * |
| 33 | + * @param $updater DatabaseUpdater |
| 34 | + */ |
| 35 | + public static function onLoadExtensionSchemaUpdates( $updater = null ) { |
| 36 | + $updater->addExtensionTable( 'mark_as_helpful', dirname( __FILE__ ) . '/sql/mark_as_helpful.sql' ); |
| 37 | + |
| 38 | + return true; |
| 39 | + } |
| 40 | + |
| 41 | + public static function makeGlobalVariablesScript( &$vars ) { |
| 42 | + global $wgUser; |
| 43 | + $vars['mahEditToken'] = $wgUser->editToken(); |
| 44 | + return true; |
| 45 | + } |
| 46 | + |
| 47 | +} |
Property changes on: branches/wmf/1.18wmf1/extensions/MarkAsHelpful/MarkAsHelpful.hooks.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 48 | + native |
Index: branches/wmf/1.18wmf1/extensions/MarkAsHelpful/includes/MarkAsHelpfulUtil.php |
— | — | @@ -0,0 +1,105 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Utility class for Mark As Helpful |
| 6 | + */ |
| 7 | +class MarkAsHelpfulUtil { |
| 8 | + |
| 9 | + /** |
| 10 | + * Generate 'mark as helpful' template for current user |
| 11 | + * @param $user Object - The current user |
| 12 | + * @param $isAbleToMark bool - flag to check if the user is able to mark the item as helpful |
| 13 | + * @param $helpfulUserList array - list of users who have marked this item as helpful |
| 14 | + * @param $type string - the object type |
| 15 | + * @param $item int - the object id |
| 16 | + * @return html | empty text |
| 17 | + */ |
| 18 | + public static function getMarkAsHelpfulTemplate( $user, $isAbleToMark, $helpfulUserList, $type, $item ) { |
| 19 | + |
| 20 | + if ( $user->isAnon() ) { |
| 21 | + $html = self::otherMarkedTemplate( $helpfulUserList ); |
| 22 | + } else { |
| 23 | + $userId = $user->getId(); |
| 24 | + |
| 25 | + if ( isset( $helpfulUserList[$userId] ) ) { |
| 26 | + $html = self::ownerMarkedTemplate(); |
| 27 | + } else { |
| 28 | + if ( $isAbleToMark ) { |
| 29 | + $html = self::requestToMarkTemplate(); |
| 30 | + } |
| 31 | + else { |
| 32 | + $html = self::otherMarkedTemplate( $helpfulUserList ); |
| 33 | + } |
| 34 | + |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + return $html; |
| 39 | + |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * The template to display in this format: {{user name or ip}} thinks this is helpful |
| 44 | + * @param $helpfulUserList array - List of users that mark the item as helpful |
| 45 | + * @return string html | empty text |
| 46 | + */ |
| 47 | + private static function otherMarkedTemplate( $helpfulUserList ) { |
| 48 | + |
| 49 | + if ( count( $helpfulUserList ) == 0 ) { |
| 50 | + return ''; |
| 51 | + } |
| 52 | + |
| 53 | + reset( $helpfulUserList ); |
| 54 | + |
| 55 | + $user = current( $helpfulUserList ); |
| 56 | + |
| 57 | + // show the first user 'in mark as helpful' template |
| 58 | + $data = wfMessage( 'mah-someone-marked-text' )->params( $user['user_name'] )->escaped(); |
| 59 | + |
| 60 | + // Add other user in user list to a hidden div, this is for future enhancement |
| 61 | + |
| 62 | + return <<<HTML |
| 63 | + <div class='mw-mah-wrapper'> |
| 64 | + <span class='mah-helpful-marked-state'> |
| 65 | + $data |
| 66 | + </span> |
| 67 | + </div> |
| 68 | +HTML; |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * The template to display in this format: You think this is helpful |
| 73 | + * @Todo future enhancement: We may pass the list of other users as well |
| 74 | + * so we can put them in hidden div |
| 75 | + * @return string html |
| 76 | + */ |
| 77 | + private static function ownerMarkedTemplate() { |
| 78 | + $mahMarkedText = wfMessage( 'mah-you-marked-text' )->escaped(); |
| 79 | + $undoLinkText = wfMessage( 'mah-undo-mark-text' )->escaped(); |
| 80 | + |
| 81 | + return <<<HTML |
| 82 | + <div class='mw-mah-wrapper'> |
| 83 | + <span class='mah-helpful-marked-state'> |
| 84 | + $mahMarkedText |
| 85 | + </span> |
| 86 | + (<a class='markashelpful-undo'>$undoLinkText</a>) |
| 87 | + </div> |
| 88 | +HTML; |
| 89 | + } |
| 90 | + |
| 91 | + /** |
| 92 | + * The template to request a user to mark an item as helpful |
| 93 | + * @return string html |
| 94 | + */ |
| 95 | + private static function requestToMarkTemplate() { |
| 96 | + $mahLinkText = wfMessage( 'mah-mark-text' )->escaped(); |
| 97 | + return <<<HTML |
| 98 | + <div class='mw-mah-wrapper'> |
| 99 | + <a class='mah-helpful-state markashelpful-mark'> |
| 100 | + $mahLinkText |
| 101 | + </a> |
| 102 | + </div> |
| 103 | +HTML; |
| 104 | + } |
| 105 | + |
| 106 | +} |
Property changes on: branches/wmf/1.18wmf1/extensions/MarkAsHelpful/includes/MarkAsHelpfulUtil.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 107 | + native |
Index: branches/wmf/1.18wmf1/extensions/MarkAsHelpful/includes/MarkAsHelpfulItem.php |
— | — | @@ -0,0 +1,275 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * An entity that handles 'Mark As Helpful' items |
| 5 | + */ |
| 6 | +class MarkAsHelpfulItem { |
| 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_editcount' => null, |
| 15 | + 'mah_namespace' => null, |
| 16 | + 'mah_title' => null, |
| 17 | + 'mah_timestamp' => null, |
| 18 | + 'mah_system_type' => null, |
| 19 | + 'mah_user_agent' => null, |
| 20 | + 'mah_locale' => null |
| 21 | + ); |
| 22 | + |
| 23 | + protected $user; |
| 24 | + protected $loadedFromDatabase = false; |
| 25 | + |
| 26 | + /** |
| 27 | + * Constructor |
| 28 | + * @param $mah_id int - an id that represents a unique mark as helpful record |
| 29 | + */ |
| 30 | + public function __construct( $mah_id = null ) { |
| 31 | + if ( $mah_id == intval( $mah_id ) ) { |
| 32 | + $this->property['mah_id'] = $mah_id; |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * Getter method |
| 38 | + * @param $key string - the name of a property |
| 39 | + */ |
| 40 | + public function getProperty( $key ) { |
| 41 | + if ( array_key_exists( $key, $this->property ) ) { |
| 42 | + return $this->property[$key]; |
| 43 | + } else { |
| 44 | + return null; |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * Setter method |
| 50 | + * @param $key string - the name of the property |
| 51 | + * @param $value mixed - the value of the property |
| 52 | + */ |
| 53 | + public function setProperty( $key, $value ) { |
| 54 | + if ( array_key_exists( $key, $this->property ) ) { |
| 55 | + $this->property[$key] = $value; |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * get the owner of the 'mark as helpful' item |
| 61 | + */ |
| 62 | + public function getUser() { |
| 63 | + if ( !$this->user ) { |
| 64 | + if ( $this->loadedFromDatabase ) { |
| 65 | + if ( $this->getProperty( 'mah_user_id' ) ) { |
| 66 | + $this->user = User::newFromId( $this->getProperty( 'mah_user_id' ) ); |
| 67 | + } |
| 68 | + } else { |
| 69 | + global $wgUser; |
| 70 | + |
| 71 | + $this->user = $wgUser; |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + return $this->user; |
| 76 | + } |
| 77 | + |
| 78 | + /** |
| 79 | + * Load data into object from external data |
| 80 | + * @param $params array - an array of data to be loaded into the object |
| 81 | + * @exception MWMarkAsHelpFulItemPropertyException |
| 82 | + */ |
| 83 | + public function loadFromRequest( $params ) { |
| 84 | + global $wgUser, $wgMarkAsHelpfulType; |
| 85 | + |
| 86 | + if ( isset( $params['type'] ) && in_array( $params['type'], $wgMarkAsHelpfulType ) ) { |
| 87 | + $this->setProperty( 'mah_type', $params['type'] ); |
| 88 | + } else { |
| 89 | + throw new MWMarkAsHelpFulItemPropertyException( 'Unsupported type!' ); |
| 90 | + } |
| 91 | + |
| 92 | + if ( isset( $params['item'] ) && $params['item'] == intval( $params['item'] ) ) { |
| 93 | + $this->setProperty( 'mah_item', $params['item'] ); |
| 94 | + } else { |
| 95 | + throw new MWMarkAsHelpFulItemPropertyException( 'Invalid item!' ); |
| 96 | + } |
| 97 | + |
| 98 | + if ( $wgUser->isAnon() ) { |
| 99 | + throw new MWMarkAsHelpFulItemPropertyException( 'User not logged in!' ); |
| 100 | + } |
| 101 | + |
| 102 | + $this->setProperty( 'mah_user_id', $wgUser->getId() ); |
| 103 | + $this->setProperty( 'mah_user_editcount', $wgUser->getEditCount() ); |
| 104 | + |
| 105 | + if ( isset( $params['page'] ) ) { |
| 106 | + $page = Title::newFromText( $params['page'] ); |
| 107 | + |
| 108 | + if ( $page ) { |
| 109 | + $this->setProperty( 'mah_namespace', $page->getNamespace() ); |
| 110 | + $this->setProperty( 'mah_title', $page->getDBkey() ); |
| 111 | + } else { |
| 112 | + throw new MWMarkAsHelpFulItemPropertyException( 'Invalid page!' ); |
| 113 | + } |
| 114 | + } |
| 115 | + |
| 116 | + $this->setProperty( 'mah_timestamp', wfTimestampNow() ); |
| 117 | + |
| 118 | + if ( isset( $params['system'] ) ) { |
| 119 | + $this->setProperty( 'mah_system_type', $params['system'] ); |
| 120 | + } |
| 121 | + if ( isset( $params['useragent'] ) ) { |
| 122 | + $this->setProperty( 'mah_user_agent', $params['useragent'] ); |
| 123 | + } |
| 124 | + if ( isset( $params['locale'] ) ) { |
| 125 | + $this->setProperty( 'mah_locale', $params['locale'] ); |
| 126 | + } |
| 127 | + } |
| 128 | + |
| 129 | + /** |
| 130 | + * Load from database |
| 131 | + * @param $conds Array: keys to load unique item from database, it must be one of the allowed keys |
| 132 | + * @exception MWMarkAsHelpFulItemSearchKeyException |
| 133 | + */ |
| 134 | + public function loadFromDatabase( $conds ) { |
| 135 | + |
| 136 | + $searchKey = array_keys( $conds ); |
| 137 | + |
| 138 | + $flag = sort( $searchKey ); |
| 139 | + |
| 140 | + if ( !$flag ) { |
| 141 | + return false; |
| 142 | + } |
| 143 | + |
| 144 | + $searchKey = implode( ',', $searchKey ); |
| 145 | + |
| 146 | + $allowableSearchKey = array( 'mah_id', 'mah_item,mah_type,mah_user_id' ); |
| 147 | + |
| 148 | + if ( !in_array( $searchKey, $allowableSearchKey ) ) { |
| 149 | + throw new MWMarkAsHelpFulItemSearchKeyException( 'Invalid search key!' ); |
| 150 | + } |
| 151 | + |
| 152 | + $dbr = wfGetDB( DB_SLAVE ); |
| 153 | + |
| 154 | + $res = $dbr->selectRow( |
| 155 | + array( 'mark_as_helpful' ), |
| 156 | + array( '*' ), |
| 157 | + $conds, |
| 158 | + __METHOD__ |
| 159 | + ); |
| 160 | + |
| 161 | + if ( $res !== false ) { |
| 162 | + foreach ( $this->property as $key => $val ) { |
| 163 | + $this->setProperty( $key, $res->$key ); |
| 164 | + } |
| 165 | + |
| 166 | + $this->loadedFromDatabase = true; |
| 167 | + return true; |
| 168 | + } else { |
| 169 | + return false; |
| 170 | + } |
| 171 | + } |
| 172 | + |
| 173 | + /** |
| 174 | + * To mark an item as helpful, this function should be called after either loadFromRequest() or setProperty() |
| 175 | + * data must be validated if called from setProperty() |
| 176 | + */ |
| 177 | + public function mark() { |
| 178 | + |
| 179 | + $dbw = wfGetDB( DB_MASTER ); |
| 180 | + |
| 181 | + $row = array(); |
| 182 | + |
| 183 | + foreach ( $this->property as $key => $value ) { |
| 184 | + if ( !is_null ( $value ) ) { |
| 185 | + $row[$key] = $value; |
| 186 | + } |
| 187 | + } |
| 188 | + |
| 189 | + $this->property['mah_id'] = $dbw->nextSequenceValue( 'mark_as_helpful_mah_id' ); |
| 190 | + $dbw->insert( 'mark_as_helpful', $row, __METHOD__, array( 'IGNORE' ) ); |
| 191 | + $this->setProperty( 'mah_id', $dbw->insertId() ); |
| 192 | + |
| 193 | + } |
| 194 | + |
| 195 | + /** |
| 196 | + * Unmark an item as helpful, we don't allow anonymous user to unmark an item |
| 197 | + * @param $currentUser User - the current user who is browsing the site |
| 198 | + */ |
| 199 | + public function unmark( $currentUser ) { |
| 200 | + |
| 201 | + if ( $currentUser->isAnon() ) { |
| 202 | + return; |
| 203 | + } |
| 204 | + |
| 205 | + if ( $this->getProperty( 'mah_id' ) ) { |
| 206 | + |
| 207 | + // Attempt to load from database if not loaded yet |
| 208 | + if ( !$this->loadedFromDatabase ) { |
| 209 | + if ( !$this->loadFromDatabase( array( 'mah_id' => $this->getProperty( 'mah_id' ) ) ) ) { |
| 210 | + return; |
| 211 | + } |
| 212 | + } |
| 213 | + |
| 214 | + $user = $this->getUser(); |
| 215 | + |
| 216 | + if ( $user ) { |
| 217 | + |
| 218 | + if ( !$user->isAnon() ) { |
| 219 | + |
| 220 | + if ( $currentUser->getId() == $user->getId() ) { |
| 221 | + |
| 222 | + $dbw = wfGetDB( DB_MASTER ); |
| 223 | + |
| 224 | + $dbw->delete( |
| 225 | + 'mark_as_helpful', |
| 226 | + array( 'mah_id' => $this->getProperty( 'mah_id' ) ), |
| 227 | + __METHOD__ |
| 228 | + ); |
| 229 | + |
| 230 | + } |
| 231 | + |
| 232 | + } |
| 233 | + |
| 234 | + } |
| 235 | + } |
| 236 | + |
| 237 | + } |
| 238 | + |
| 239 | + /** |
| 240 | + * Get a list of all users that marked this item as helpful |
| 241 | + * @param $type string - the object type |
| 242 | + * @param $item int - the object id |
| 243 | + * @return array |
| 244 | + */ |
| 245 | + public static function getMarkAsHelpfulList( $type, $item ) { |
| 246 | + $dbr = wfGetDB( DB_SLAVE ); |
| 247 | + |
| 248 | + $conds = array( |
| 249 | + 'mah_type' => $type, |
| 250 | + 'mah_item' => intval( $item ) |
| 251 | + ); |
| 252 | + |
| 253 | + $conds[] = 'mah_user_id = user_id'; |
| 254 | + |
| 255 | + // Grab only one record for the 1st phase |
| 256 | + $res = $dbr->select( |
| 257 | + array( 'mark_as_helpful', 'user' ), |
| 258 | + array( 'mah_id', 'user_id', 'user_name' ), |
| 259 | + $conds, |
| 260 | + __METHOD__, |
| 261 | + array( 'LIMIT' => 1 ) |
| 262 | + ); |
| 263 | + |
| 264 | + $list = array(); |
| 265 | + |
| 266 | + foreach ( $res as $val ) { |
| 267 | + $list[$val->user_id] = array( 'user_name' => $val->user_name, |
| 268 | + 'user_id' => $val->user_id ); |
| 269 | + } |
| 270 | + |
| 271 | + return $list; |
| 272 | + } |
| 273 | +} |
| 274 | + |
| 275 | +class MWMarkAsHelpFulItemPropertyException extends MWException {} |
| 276 | +class MWMarkAsHelpFulItemSearchKeyException extends MWException {} |
Property changes on: branches/wmf/1.18wmf1/extensions/MarkAsHelpful/includes/MarkAsHelpfulItem.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 277 | + native |
Index: branches/wmf/1.18wmf1/extensions/MarkAsHelpful/modules/ext.markAsHelpful/ext.markAsHelpful.css |
— | — | @@ -0,0 +1,20 @@ |
| 2 | +.mw-mah-wrapper a{ |
| 3 | + cursor:pointer; |
| 4 | +} |
| 5 | + |
| 6 | +.mw-mah-wrapper .mah-helpful-state { |
| 7 | + /* @embed */ |
| 8 | + background: transparent url(images/mah-helpful-dull.png) left center no-repeat; |
| 9 | + padding-left: 18px; |
| 10 | +} |
| 11 | + |
| 12 | +.mw-mah-wrapper .mah-helpful-state:hover { |
| 13 | + /* @embed */ |
| 14 | + background: transparent url(images/mah-helpful-hover.png) left center no-repeat; |
| 15 | +} |
| 16 | + |
| 17 | +.mw-mah-wrapper .mah-helpful-marked-state { |
| 18 | + /* @embed */ |
| 19 | + background: transparent url(images/mah-helpful-marked.png) left center no-repeat; |
| 20 | + padding-left:18px; |
| 21 | +} |
\ No newline at end of file |
Property changes on: branches/wmf/1.18wmf1/extensions/MarkAsHelpful/modules/ext.markAsHelpful/ext.markAsHelpful.css |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 22 | + native |
Index: branches/wmf/1.18wmf1/extensions/MarkAsHelpful/modules/ext.markAsHelpful/images/mah-helpful-dull.png |
Cannot display: file marked as a binary type. |
svn:mime-type = image/png |
Property changes on: branches/wmf/1.18wmf1/extensions/MarkAsHelpful/modules/ext.markAsHelpful/images/mah-helpful-dull.png |
___________________________________________________________________ |
Added: svn:mime-type |
2 | 23 | + image/png |
Index: branches/wmf/1.18wmf1/extensions/MarkAsHelpful/modules/ext.markAsHelpful/images/mah-helpful-hover.png |
Cannot display: file marked as a binary type. |
svn:mime-type = image/png |
Property changes on: branches/wmf/1.18wmf1/extensions/MarkAsHelpful/modules/ext.markAsHelpful/images/mah-helpful-hover.png |
___________________________________________________________________ |
Added: svn:mime-type |
3 | 24 | + image/png |
Index: branches/wmf/1.18wmf1/extensions/MarkAsHelpful/modules/ext.markAsHelpful/images/mah-helpful-marked.png |
Cannot display: file marked as a binary type. |
svn:mime-type = image/png |
Property changes on: branches/wmf/1.18wmf1/extensions/MarkAsHelpful/modules/ext.markAsHelpful/images/mah-helpful-marked.png |
___________________________________________________________________ |
Added: svn:mime-type |
4 | 25 | + image/png |
Index: branches/wmf/1.18wmf1/extensions/MarkAsHelpful/modules/ext.markAsHelpful/ext.markAsHelpful.js |
— | — | @@ -0,0 +1,122 @@ |
| 2 | +/** |
| 3 | + * Front-end scripting core for the MarkAsHelpful MediaWiki extension |
| 4 | + * |
| 5 | + * @author Rob Moen, 2011 |
| 6 | + */ |
| 7 | + |
| 8 | +(function( $ ) { |
| 9 | + |
| 10 | + var mah = mw.mah = { |
| 11 | + loadedItems: [], |
| 12 | + selector: '.markashelpful-item', //class of element(s) to apply MarkAsHelpful to. |
| 13 | + |
| 14 | + init: function() { |
| 15 | + var props, thisItem; |
| 16 | + $( mah.selector ).each( function ( i, e ) { |
| 17 | + props = mah.getItemProperties( $(this) ); |
| 18 | + thisItem = props.type + props.item; //create an item reference to place in the loaded items array. |
| 19 | + |
| 20 | + //load once per type+id because user can copy / paste element on the talk page and load the same item many times. |
| 21 | + if( $.inArray( thisItem, mah.loadedItems ) === -1 ) { |
| 22 | + mah.loadedItems.push( thisItem ); |
| 23 | + mah.loadItem( $( this ) ); |
| 24 | + } |
| 25 | + }); |
| 26 | + }, |
| 27 | + |
| 28 | + /* |
| 29 | + * Return object of item properties |
| 30 | + */ |
| 31 | + getItemProperties: function( $item ) { |
| 32 | + var properties = { |
| 33 | + 'item': $item.data('markashelpful-item'), // item id |
| 34 | + 'type': $item.data('markashelpful-type') // item type (eg, mbresponse) |
| 35 | + }; |
| 36 | + return properties; |
| 37 | + }, |
| 38 | + |
| 39 | + /* |
| 40 | + * Load the current state of the MarkAsHelpful item |
| 41 | + */ |
| 42 | + loadItem: function( $item ) { |
| 43 | + var props = mah.getItemProperties( $item ), |
| 44 | + request = { |
| 45 | + 'action': 'getmarkashelpfulitem', |
| 46 | + 'item': props.item, |
| 47 | + 'type': props.type, |
| 48 | + 'format': 'json' |
| 49 | + }; |
| 50 | + |
| 51 | + $.ajax({ |
| 52 | + type: 'get', |
| 53 | + url: mw.util.wikiScript('api'), |
| 54 | + cache: false, |
| 55 | + data: request, |
| 56 | + success: function( data ) { |
| 57 | + |
| 58 | + if ( data && data.getmarkashelpfulitem.result == 'success' && |
| 59 | + data.getmarkashelpfulitem.formatted |
| 60 | + ) { |
| 61 | + var $content = $( data.getmarkashelpfulitem.formatted ); |
| 62 | + $item.html( $content ); |
| 63 | + } else { |
| 64 | + // Failure, do nothing to the item for now |
| 65 | + } |
| 66 | + }, |
| 67 | + error: function ( data ) { |
| 68 | + // Failure, do nothing to the item for now |
| 69 | + }, |
| 70 | + dataType: 'json' |
| 71 | + }); |
| 72 | + |
| 73 | + }, |
| 74 | + /* |
| 75 | + * API call to mark or unmark an item as helpful. |
| 76 | + */ |
| 77 | + markItem: function( $clicked, action ) { |
| 78 | + var $item = $clicked.parent().parent(), |
| 79 | + props = mah.getItemProperties( $item ), |
| 80 | + clientData = $.client.profile(), |
| 81 | + request; |
| 82 | + props.mahaction = action; |
| 83 | + request = $.extend( { |
| 84 | + 'action': 'markashelpful', |
| 85 | + 'page': mw.config.get( 'wgPageName' ), |
| 86 | + 'useragent': clientData.name + '/' + clientData.versionNumber, |
| 87 | + 'system': clientData.platform, |
| 88 | + 'token': mw.config.get( 'mahEditToken' ), |
| 89 | + 'format': 'json' |
| 90 | + }, props ); |
| 91 | + |
| 92 | + $.ajax( { |
| 93 | + type: 'post', |
| 94 | + url: mw.util.wikiScript( 'api' ), |
| 95 | + data: request, |
| 96 | + success: function () { |
| 97 | + mah.loadItem( $item ); |
| 98 | + }, |
| 99 | + dataType: 'json' |
| 100 | + } ); |
| 101 | + |
| 102 | + } |
| 103 | + }; |
| 104 | + |
| 105 | + // Some live events for the different modes |
| 106 | + |
| 107 | + /* |
| 108 | + * Click Event for marking an item as helpful. |
| 109 | + */ |
| 110 | + $( '.markashelpful-mark' ).live( 'click', function() { |
| 111 | + mah.markItem( $(this), 'mark' ); |
| 112 | + } ); |
| 113 | + |
| 114 | + /* |
| 115 | + * Click Event for removing helpful status from an item. |
| 116 | + */ |
| 117 | + $( '.markashelpful-undo' ).live( 'click', function() { |
| 118 | + mah.markItem( $(this), 'unmark' ); |
| 119 | + } ); |
| 120 | + |
| 121 | + // Initialize MarkAsHelpful |
| 122 | + $( mah.init ); |
| 123 | +} ) ( jQuery ); |
\ No newline at end of file |
Property changes on: branches/wmf/1.18wmf1/extensions/MarkAsHelpful/modules/ext.markAsHelpful/ext.markAsHelpful.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 124 | + native |
Index: branches/wmf/1.18wmf1/extensions/MarkAsHelpful/api/ApiGetMarkAsHelpfulItem.php |
— | — | @@ -0,0 +1,68 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class ApiGetMarkAsHelpfulItem extends ApiBase { |
| 5 | + |
| 6 | + public function execute() { |
| 7 | + global $wgUser; |
| 8 | + |
| 9 | + $params = $this->extractRequestParams(); |
| 10 | + |
| 11 | + // check if current user has permission to mark this item, |
| 12 | + $isAbleToMark = true; |
| 13 | + |
| 14 | + wfRunHooks( 'onMarkItemAsHelpful', array( 'mark', $params['type'], $params['item'], $wgUser, &$isAbleToMark ) ); |
| 15 | + |
| 16 | + $HelpfulUserList = MarkAsHelpfulItem::getMarkAsHelpfulList( $params['type'], $params['item'] ); |
| 17 | + |
| 18 | + if ( $params['prop'] == 'metadata') { |
| 19 | + $data = $HelpfulUserList; |
| 20 | + $format = 'metadata'; |
| 21 | + } else { |
| 22 | + $data = MarkAsHelpfulUtil::getMarkAsHelpfulTemplate( |
| 23 | + $wgUser, $isAbleToMark, $HelpfulUserList, $params['type'], |
| 24 | + $params['item'] |
| 25 | + ); |
| 26 | + $format = 'formatted'; |
| 27 | + } |
| 28 | + |
| 29 | + $result = array( 'result' => 'success', $format => $data ); |
| 30 | + $this->getResult()->addValue( null, $this->getModuleName(), $result ); |
| 31 | + } |
| 32 | + |
| 33 | + public function getAllowedParams() { |
| 34 | + global $wgMarkAsHelpfulType; |
| 35 | + |
| 36 | + return array( |
| 37 | + 'type' => array( |
| 38 | + ApiBase::PARAM_REQUIRED => true, |
| 39 | + ApiBase::PARAM_TYPE => $wgMarkAsHelpfulType, |
| 40 | + ), |
| 41 | + 'item' => array( |
| 42 | + ApiBase::PARAM_REQUIRED => true, |
| 43 | + ApiBase::PARAM_TYPE => 'integer' |
| 44 | + ), |
| 45 | + 'prop' => array( |
| 46 | + ApiBase::PARAM_TYPE => array( 'metadata', 'formatted' ), |
| 47 | + ), |
| 48 | + ); |
| 49 | + } |
| 50 | + |
| 51 | + public function getVersion() { |
| 52 | + return __CLASS__ . ': $Id$'; |
| 53 | + } |
| 54 | + |
| 55 | + public function getParamDescription() { |
| 56 | + return array( |
| 57 | + 'type' => 'The object type that is being marked as helpful', |
| 58 | + 'item' => 'The object item that is being marked as helpful', |
| 59 | + 'prop' => 'Which property to get', |
| 60 | + ); |
| 61 | + } |
| 62 | + |
| 63 | + public function getDescription() { |
| 64 | + return 'Get a list of all helpful status for an object item'; |
| 65 | + } |
| 66 | + |
| 67 | +} |
| 68 | + |
| 69 | +class MWApiGetMarkAsHelpfulItemInvalidActionException extends MWException {} |
\ No newline at end of file |
Property changes on: branches/wmf/1.18wmf1/extensions/MarkAsHelpful/api/ApiGetMarkAsHelpfulItem.php |
___________________________________________________________________ |
Added: svn:keywords |
1 | 70 | + Id |
Added: svn:eol-style |
2 | 71 | + native |
Index: branches/wmf/1.18wmf1/extensions/MarkAsHelpful/api/ApiMarkAsHelpful.php |
— | — | @@ -0,0 +1,136 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class ApiMarkAsHelpful extends ApiBase { |
| 5 | + |
| 6 | + public function execute() { |
| 7 | + global $wgUser; |
| 8 | + |
| 9 | + if ( $wgUser->isBlocked( false ) ) { |
| 10 | + $this->dieUsageMsg( array( 'blockedtext' ) ); |
| 11 | + } |
| 12 | + |
| 13 | + // Disallow anonymous user to mark/unmark an 'Mark As Helpful' item |
| 14 | + if ( $wgUser->isAnon() ) { |
| 15 | + $this->noPermissionError(); |
| 16 | + } |
| 17 | + |
| 18 | + $params = $this->extractRequestParams(); |
| 19 | + |
| 20 | + $isAbleToMark = true; |
| 21 | + |
| 22 | + // Gives other extension the last chance to specify mark as helpful permission rules |
| 23 | + wfRunHooks( 'onMarkItemAsHelpful', array( $params['mahaction'], $params['type'], $params['item'], $wgUser, &$isAbleToMark ) ); |
| 24 | + |
| 25 | + if ( !$isAbleToMark ) { |
| 26 | + $this->noPermissionError(); |
| 27 | + } |
| 28 | + |
| 29 | + $error = false; |
| 30 | + |
| 31 | + switch ( $params['mahaction'] ) { |
| 32 | + case 'mark': |
| 33 | + $item = new MarkAsHelpfulItem(); |
| 34 | + $item->loadFromRequest( $params ); |
| 35 | + $item->mark(); |
| 36 | + break; |
| 37 | + |
| 38 | + case 'unmark': |
| 39 | + $item = new MarkAsHelpfulItem(); |
| 40 | + |
| 41 | + $conds = array( 'mah_type' => $params['type'], |
| 42 | + 'mah_item' => $params['item'], |
| 43 | + 'mah_user_id' => $wgUser->getId() ); |
| 44 | + |
| 45 | + $status = $item->loadFromDatabase( $conds ); |
| 46 | + |
| 47 | + if ( $status ) { |
| 48 | + $item->unmark( $wgUser ); |
| 49 | + } |
| 50 | + else { |
| 51 | + $error = true; |
| 52 | + } |
| 53 | + break; |
| 54 | + |
| 55 | + default: |
| 56 | + throw new MWApiMarkAsHelpfulInvalidActionException( "Action {$params['mbaction']} not implemented" ); |
| 57 | + break; |
| 58 | + } |
| 59 | + |
| 60 | + if ( $error === false ) { |
| 61 | + $result = array( 'result' => 'success' ); |
| 62 | + } else { |
| 63 | + $result = array( 'result' => 'error', 'error' => 'mah-action-error' ); |
| 64 | + } |
| 65 | + $this->getResult()->addValue( null, $this->getModuleName(), $result ); |
| 66 | + } |
| 67 | + |
| 68 | + private function noPermissionError() { |
| 69 | + $this->dieUsage( "You don't have permission to do that", 'permission-denied' ); |
| 70 | + } |
| 71 | + |
| 72 | + public function needsToken() { |
| 73 | + return true; |
| 74 | + } |
| 75 | + |
| 76 | + public function getTokenSalt() { |
| 77 | + return ''; |
| 78 | + } |
| 79 | + |
| 80 | + public function getAllowedParams() { |
| 81 | + global $wgMarkAsHelpfulType; |
| 82 | + |
| 83 | + return array( |
| 84 | + 'mahaction' => array( |
| 85 | + ApiBase::PARAM_REQUIRED => true, |
| 86 | + ApiBase::PARAM_TYPE => array( 'mark', 'unmark' ), |
| 87 | + ), |
| 88 | + 'page' => array( |
| 89 | + ApiBase::PARAM_REQUIRED => true, |
| 90 | + ), |
| 91 | + 'type' => array( |
| 92 | + ApiBase::PARAM_REQUIRED => true, |
| 93 | + ApiBase::PARAM_TYPE => $wgMarkAsHelpfulType, |
| 94 | + ), |
| 95 | + 'item' => array( |
| 96 | + ApiBase::PARAM_REQUIRED => true, |
| 97 | + ApiBase::PARAM_TYPE => 'integer' |
| 98 | + ), |
| 99 | + 'useragent' => null, |
| 100 | + 'system' => null, |
| 101 | + 'locale' => null, |
| 102 | + 'token' => null, |
| 103 | + ); |
| 104 | + } |
| 105 | + |
| 106 | + public function mustBePosted() { |
| 107 | + return true; |
| 108 | + } |
| 109 | + |
| 110 | + public function isWriteMode() { |
| 111 | + return true; |
| 112 | + } |
| 113 | + |
| 114 | + public function getVersion() { |
| 115 | + return __CLASS__ . ': $Id$'; |
| 116 | + } |
| 117 | + |
| 118 | + public function getParamDescription() { |
| 119 | + return array( |
| 120 | + 'mahaction' => 'the mark or unmark an item as helpful', |
| 121 | + 'page' => 'The page which the item to be marked is on', |
| 122 | + 'type' => 'The object type that is being marked as helpful', |
| 123 | + 'item' => 'The object item that is being marked as helpful', |
| 124 | + 'useragent' => 'The User-Agent header of the browser', |
| 125 | + 'system' => 'The operating system being used', |
| 126 | + 'locale' => 'The locale in use', |
| 127 | + 'token' => 'An edit token', |
| 128 | + ); |
| 129 | + } |
| 130 | + |
| 131 | + public function getDescription() { |
| 132 | + return 'Allows users to mark/unmark an object item in the site as helpful'; |
| 133 | + } |
| 134 | + |
| 135 | +} |
| 136 | + |
| 137 | +class MWApiMarkAsHelpfulInvalidActionException extends MWException {} |
Property changes on: branches/wmf/1.18wmf1/extensions/MarkAsHelpful/api/ApiMarkAsHelpful.php |
___________________________________________________________________ |
Added: svn:keywords |
1 | 138 | + Id |
Added: svn:eol-style |
2 | 139 | + native |