r107587 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107586‎ | r107587 | r107588 >
Date:19:08, 29 December 2011
Author:bsitu
Status:ok
Tags:
Comment:
Introducing page request permission check to MarkAsHelpful
Modified paths:
  • /trunk/extensions/MarkAsHelpful/MarkAsHelpful.php (modified) (history)
  • /trunk/extensions/MarkAsHelpful/api/ApiGetMarkAsHelpfulItem.php (modified) (history)
  • /trunk/extensions/MarkAsHelpful/api/ApiMarkAsHelpful.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MarkAsHelpful/MarkAsHelpful.php
@@ -32,11 +32,12 @@
3333
3434 // API
3535 $wgAutoloadClasses['ApiMarkAsHelpful'] = $dir . 'api/ApiMarkAsHelpful.php';
36 -$wgAutoloadClasses['MWApiGetMarkAsHelpfulItemInvalidActionException'] = $dir . 'api/ApiMarkAsHelpful.php';
 36+$wgAutoloadClasses['MWApiGetMarkAsHelpfulItemInvalidPageException'] = $dir . 'api/ApiGetMarkAsHelpfulItem.php';
3737 $wgAPIModules['markashelpful'] = 'ApiMarkAsHelpful';
3838
3939 $wgAutoloadClasses['ApiGetMarkAsHelpfulItem'] = $dir . 'api/ApiGetMarkAsHelpfulItem.php';
40 -$wgAutoloadClasses['MWApiMarkAsHelpfulInvalidActionException'] = $dir . 'api/ApiGetMarkAsHelpfulItem.php';
 40+$wgAutoloadClasses['MWApiMarkAsHelpfulInvalidActionException'] = $dir . 'api/ApiMarkAsHelpful.php';
 41+$wgAutoloadClasses['MWApiMarkAsHelpfulInvalidPageException'] = $dir . 'api/ApiMarkAsHelpful.php';
4142 $wgAPIModules['getmarkashelpfulitem'] = 'ApiGetMarkAsHelpfulItem';
4243
4344 // Hooks
Index: trunk/extensions/MarkAsHelpful/api/ApiGetMarkAsHelpfulItem.php
@@ -7,24 +7,43 @@
88
99 $params = $this->extractRequestParams();
1010
11 - // check if current user has permission to mark this item,
12 - $isAbleToMark = true;
 11+ $page = Title::newFromText( $params['page'] );
1312
14 - wfRunHooks( 'onMarkItemAsHelpful', array( 'mark', $params['type'], $params['item'], $wgUser, &$isAbleToMark ) );
 13+ if ( !$page ) {
 14+ throw new MWApiGetMarkAsHelpfulItemInvalidPageException( 'Invalid page!' );
 15+ }
1516
16 - $HelpfulUserList = MarkAsHelpfulItem::getMarkAsHelpfulList( $params['type'], $params['item'] );
 17+ // check if current user has permission to mark the item,
 18+ $isAbleToMark = false;
 19+ // check if the page has permission to request the item
 20+ $isAbleToShow = false;
1721
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';
 22+ wfRunHooks( 'onMarkItemAsHelpful', array( $params['type'], $params['item'], $wgUser, &$isAbleToMark, $page, &$isAbleToShow ) );
 23+
 24+ if ( $isAbleToShow ) {
 25+ $HelpfulUserList = MarkAsHelpfulItem::getMarkAsHelpfulList( $params['type'], $params['item'] );
 26+
 27+ if ( $params['prop'] == 'metadata') {
 28+ $data = $HelpfulUserList;
 29+ $format = 'metadata';
 30+ } else {
 31+ $data = MarkAsHelpfulUtil::getMarkAsHelpfulTemplate(
 32+ $wgUser, $isAbleToMark, $HelpfulUserList, $params['type'],
 33+ $params['item']
 34+ );
 35+ $format = 'formatted';
 36+ }
2737 }
 38+ else {
 39+ $data = '';
2840
 41+ if ( $params['prop'] == 'metadata') {
 42+ $format = 'metadata';
 43+ } else {
 44+ $format = 'formatted';
 45+ }
 46+ }
 47+
2948 $result = array( 'result' => 'success', $format => $data );
3049 $this->getResult()->addValue( null, $this->getModuleName(), $result );
3150 }
@@ -44,6 +63,9 @@
4564 'prop' => array(
4665 ApiBase::PARAM_TYPE => array( 'metadata', 'formatted' ),
4766 ),
 67+ 'page' => array(
 68+ ApiBase::PARAM_REQUIRED => true,
 69+ ),
4870 );
4971 }
5072
@@ -56,6 +78,7 @@
5779 'type' => 'The object type that is being marked as helpful',
5880 'item' => 'The object item that is being marked as helpful',
5981 'prop' => 'Which property to get',
 82+ 'page' => 'The page which is requesting the item',
6083 );
6184 }
6285
@@ -65,5 +88,4 @@
6689
6790 }
6891
69 -class MWApiGetMarkAsHelpfulItemInvalidActionException extends MWException {}
70 -
 92+class MWApiGetMarkAsHelpfulItemInvalidPageException extends MWException {}
\ No newline at end of file
Index: trunk/extensions/MarkAsHelpful/api/ApiMarkAsHelpful.php
@@ -16,12 +16,21 @@
1717
1818 $params = $this->extractRequestParams();
1919
20 - $isAbleToMark = true;
 20+ $page = Title::newFromText( $params['page'] );
2121
 22+ if ( !$page ) {
 23+ throw new MWApiMarkAsHelpfulInvalidPageException( 'Invalid page!' );
 24+ }
 25+
 26+ // check if current user has permission to mark the item,
 27+ $isAbleToMark = false;
 28+ // check if the page has permission to request the item
 29+ $isAbleToShow = false;
 30+
2231 // 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 ) );
 32+ wfRunHooks( 'onMarkItemAsHelpful', array( $params['type'], $params['item'], $wgUser, &$isAbleToMark, $page, &$isAbleToShow ) );
2433
25 - if ( !$isAbleToMark ) {
 34+ if ( !$isAbleToShow || !$isAbleToMark ) {
2635 $this->noPermissionError();
2736 }
2837
@@ -132,4 +141,4 @@
133142 }
134143
135144 class MWApiMarkAsHelpfulInvalidActionException extends MWException {}
136 -
 145+class MWApiMarkAsHelpfulInvalidPageException extends MWException {}
\ No newline at end of file

Status & tagging log