Index: trunk/extensions/Reviews/specials/SpecialMyReviews.php |
— | — | @@ -0,0 +1,62 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * List of reviews for a user. |
| 6 | + * |
| 7 | + * @since 0.1 |
| 8 | + * |
| 9 | + * @file SpecialMyReviews.php |
| 10 | + * @ingroup Reviews |
| 11 | + * |
| 12 | + * @licence GNU GPL v3 or later |
| 13 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 14 | + */ |
| 15 | +class SpecialMyReviews extends SpecialPage { |
| 16 | + |
| 17 | + public $subPage; |
| 18 | + |
| 19 | + /** |
| 20 | + * Constructor. |
| 21 | + * |
| 22 | + * @since 0.1 |
| 23 | + */ |
| 24 | + public function __construct() { |
| 25 | + parent::__construct( 'MyReviews', 'reviewer' ); |
| 26 | + } |
| 27 | + |
| 28 | + /** |
| 29 | + * Main method. |
| 30 | + * |
| 31 | + * @since 0.1 |
| 32 | + * |
| 33 | + * @param string $arg |
| 34 | + */ |
| 35 | + public function execute( $subPage ) { |
| 36 | + $this->subPage = str_replace( '_', ' ', $subPage ); |
| 37 | + |
| 38 | + $this->setHeaders(); |
| 39 | + $this->outputHeader(); |
| 40 | + |
| 41 | + // If the user is authorized, display the page, if not, show an error. |
| 42 | + if ( !$this->userCanExecute( $this->getUser() ) ) { |
| 43 | + $this->displayRestrictionError(); |
| 44 | + return false; |
| 45 | + } |
| 46 | + |
| 47 | + if ( $this->getRequest()->wasPosted() ) { |
| 48 | + |
| 49 | + } |
| 50 | + else { |
| 51 | + if ( $subPage === '' ) { |
| 52 | + $this->displayReviewList(); |
| 53 | + } |
| 54 | + else { |
| 55 | + |
| 56 | + } |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + protected function displayReviewList() { |
| 61 | + } |
| 62 | + |
| 63 | +} |
Property changes on: trunk/extensions/Reviews/specials/SpecialMyReviews.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 64 | + native |
Index: trunk/extensions/Reviews/specials/SpecialReviews.php |
— | — | @@ -0,0 +1,62 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * List of reviews. |
| 6 | + * |
| 7 | + * @since 0.1 |
| 8 | + * |
| 9 | + * @file SpecialReviews.php |
| 10 | + * @ingroup Reviews |
| 11 | + * |
| 12 | + * @licence GNU GPL v3 or later |
| 13 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 14 | + */ |
| 15 | +class SpecialReviews extends SpecialPage { |
| 16 | + |
| 17 | + public $subPage; |
| 18 | + |
| 19 | + /** |
| 20 | + * Constructor. |
| 21 | + * |
| 22 | + * @since 0.1 |
| 23 | + */ |
| 24 | + public function __construct() { |
| 25 | + parent::__construct( 'Reviews', 'reviewer' ); |
| 26 | + } |
| 27 | + |
| 28 | + /** |
| 29 | + * Main method. |
| 30 | + * |
| 31 | + * @since 0.1 |
| 32 | + * |
| 33 | + * @param string $arg |
| 34 | + */ |
| 35 | + public function execute( $subPage ) { |
| 36 | + $this->subPage = str_replace( '_', ' ', $subPage ); |
| 37 | + |
| 38 | + $this->setHeaders(); |
| 39 | + $this->outputHeader(); |
| 40 | + |
| 41 | + // If the user is authorized, display the page, if not, show an error. |
| 42 | + if ( !$this->userCanExecute( $this->getUser() ) ) { |
| 43 | + $this->displayRestrictionError(); |
| 44 | + return false; |
| 45 | + } |
| 46 | + |
| 47 | + if ( $this->getRequest()->wasPosted() ) { |
| 48 | + |
| 49 | + } |
| 50 | + else { |
| 51 | + if ( $subPage === '' ) { |
| 52 | + $this->displayReviewList(); |
| 53 | + } |
| 54 | + else { |
| 55 | + |
| 56 | + } |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + protected function displayReviewList() { |
| 61 | + } |
| 62 | + |
| 63 | +} |
Property changes on: trunk/extensions/Reviews/specials/SpecialReviews.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 64 | + native |
Index: trunk/extensions/Reviews/includes/ReviewPager.php |
— | — | @@ -0,0 +1,147 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Review pager, for on Special:Reviews and Special:MyReviews |
| 6 | + * |
| 7 | + * @since 0.1 |
| 8 | + * |
| 9 | + * @file ReviewPager.php |
| 10 | + * @ingroup Reviews |
| 11 | + * |
| 12 | + * @licence GNU GPL v3 or later |
| 13 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 14 | + */ |
| 15 | +class ReviewPager extends TablePager { |
| 16 | + |
| 17 | + /** |
| 18 | + * Query conditions, full field names (ie inc prefix). |
| 19 | + * @var array |
| 20 | + */ |
| 21 | + protected $conds; |
| 22 | + |
| 23 | + /** |
| 24 | + * Constructor. |
| 25 | + * |
| 26 | + * @param array $conds |
| 27 | + */ |
| 28 | + public function __construct( array $conds ) { |
| 29 | + $this->conds = $conds; |
| 30 | + $this->mDefaultDirection = true; |
| 31 | + |
| 32 | + // when MW 1.19 becomes min, we want to pass an IContextSource $context here. |
| 33 | + parent::__construct(); |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * Gets the title of a challenge given it's id. |
| 38 | + * |
| 39 | + * @since 0.1 |
| 40 | + * |
| 41 | + * @param integer $challengeId |
| 42 | + * @throws MWException |
| 43 | + */ |
| 44 | + protected function getChallengeTitle( $challengeId ) { |
| 45 | + if ( array_key_exists( $challengeId, $this->challengeTitles ) ) { |
| 46 | + return $this->challengeTitles[$challengeId]; |
| 47 | + } |
| 48 | + else { |
| 49 | + throw new MWException( 'Attempt to get non-set challenge title' ); |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * Get the OutputPage being used for this instance. |
| 55 | + * IndexPager extends ContextSource as of 1.19. |
| 56 | + * |
| 57 | + * @since 0.1 |
| 58 | + * |
| 59 | + * @return OutputPage |
| 60 | + */ |
| 61 | + public function getOutput() { |
| 62 | + return version_compare( $GLOBALS['wgVersion'], '1.18', '>' ) ? parent::getOutput() : $GLOBALS['wgOut']; |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * Get the Language being used for this instance. |
| 67 | + * IndexPager extends ContextSource as of 1.19. |
| 68 | + * |
| 69 | + * @since 0.1 |
| 70 | + * |
| 71 | + * @return Language |
| 72 | + */ |
| 73 | + public function getLang() { |
| 74 | + return version_compare( $GLOBALS['wgVersion'], '1.18', '>' ) ? parent::getLang() : $GLOBALS['wgLang']; |
| 75 | + } |
| 76 | + |
| 77 | + /** |
| 78 | + * @return array |
| 79 | + */ |
| 80 | + public function getFieldNames() { |
| 81 | + static $headers = null; |
| 82 | + |
| 83 | + if ( is_null( $headers ) ) { |
| 84 | + $headers = array( |
| 85 | + // TODO |
| 86 | + ); |
| 87 | + |
| 88 | + $headers = array_map( 'wfMsg', $headers ); |
| 89 | + } |
| 90 | + |
| 91 | + return $headers; |
| 92 | + } |
| 93 | + |
| 94 | + /** |
| 95 | + * @param $row |
| 96 | + * @return string |
| 97 | + */ |
| 98 | + function getRowClass( $row ) { |
| 99 | + return 'review-row'; |
| 100 | + } |
| 101 | + |
| 102 | + /** |
| 103 | + * @param $name |
| 104 | + * @param $value |
| 105 | + * @return string |
| 106 | + */ |
| 107 | + public function formatValue( $name, $value ) { |
| 108 | + switch ( $name ) { |
| 109 | + case '': |
| 110 | + |
| 111 | + break; |
| 112 | + } |
| 113 | + |
| 114 | + return $value; |
| 115 | + } |
| 116 | + |
| 117 | + function getQueryInfo() { |
| 118 | + return array( |
| 119 | + 'tables' => array( 'reviews' ), |
| 120 | + 'fields' => array( |
| 121 | + // TODO |
| 122 | + ), |
| 123 | + 'conds' => $this->conds, |
| 124 | + ); |
| 125 | + } |
| 126 | + |
| 127 | + public function getTableClass(){ |
| 128 | + return 'TablePager review-contestants'; |
| 129 | + } |
| 130 | + |
| 131 | + function getIndexField() { |
| 132 | + return 'review_id'; |
| 133 | + } |
| 134 | + |
| 135 | + function getDefaultSort() { |
| 136 | + return 'review_time'; |
| 137 | + } |
| 138 | + |
| 139 | + function isFieldSortable( $name ) { |
| 140 | + return in_array( |
| 141 | + $name, |
| 142 | + array( |
| 143 | + // TODO |
| 144 | + ) |
| 145 | + ); |
| 146 | + } |
| 147 | + |
| 148 | +} |
Property changes on: trunk/extensions/Reviews/includes/ReviewPager.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 149 | + native |
Index: trunk/extensions/Reviews/includes/Review.php |
— | — | @@ -0,0 +1,82 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Class representing a single review. |
| 6 | + * |
| 7 | + * @since 0.1 |
| 8 | + * |
| 9 | + * @file Review.php |
| 10 | + * @ingroup Reviews |
| 11 | + * |
| 12 | + * @licence GNU GPL v3 or later |
| 13 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 14 | + */ |
| 15 | +class Review extends ReviewsDBObject { |
| 16 | + |
| 17 | + // Constants representing the states a review can have. |
| 18 | + const STATUS_NEW = 0; |
| 19 | + const STATUS_FLAGGED = 1; |
| 20 | + const STATUS_REVIEWED = 2; |
| 21 | + |
| 22 | + /** |
| 23 | + * |
| 24 | + * |
| 25 | + * @since 0.1 |
| 26 | + * @var array of ReviewRating |
| 27 | + */ |
| 28 | + protected $ratings = false; |
| 29 | + |
| 30 | + /** |
| 31 | + * @see parent::getFieldTypes |
| 32 | + * |
| 33 | + * @since 0.1 |
| 34 | + * |
| 35 | + * @return string |
| 36 | + */ |
| 37 | + public static function getDBTable() { |
| 38 | + return 'reviews'; |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * @see parent::getFieldTypes |
| 43 | + * |
| 44 | + * @since 0.1 |
| 45 | + * |
| 46 | + * @return string |
| 47 | + */ |
| 48 | + protected static function getFieldPrefix() { |
| 49 | + return 'review_'; |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * @see parent::getFieldTypes |
| 54 | + * |
| 55 | + * @since 0.1 |
| 56 | + * |
| 57 | + * @return array |
| 58 | + */ |
| 59 | + protected static function getFieldTypes() { |
| 60 | + return array( |
| 61 | + 'id' => 'id', |
| 62 | + 'time' => 'str', // TS_MW |
| 63 | + |
| 64 | + ); |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * @see parent::getDefaults |
| 69 | + * |
| 70 | + * @since 0.1 |
| 71 | + * |
| 72 | + * @return array |
| 73 | + */ |
| 74 | + public static function getDefaults() { |
| 75 | + return array( |
| 76 | + ); |
| 77 | + } |
| 78 | + |
| 79 | + public function removeAllFromDB() { |
| 80 | + |
| 81 | + } |
| 82 | + |
| 83 | +} |
Property changes on: trunk/extensions/Reviews/includes/Review.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 84 | + native |
Index: trunk/extensions/Reviews/includes/ReviewsDBObject.php |
— | — | @@ -2,16 +2,21 @@ |
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Abstract base class for representing objects that are stored in some DB table. |
| 6 | + * These methods must be implemented in deriving classes: |
| 7 | + * * getDBTable |
| 8 | + * * getFieldPrefix |
| 9 | + * * getFieldTypes |
| 10 | + * * getDefaults |
6 | 11 | * |
7 | 12 | * @since 0.1 |
8 | 13 | * |
9 | | - * @file ReviewDBObject.php |
| 14 | + * @file ReviewsDBObject.php |
10 | 15 | * @ingroup Review |
11 | 16 | * |
12 | 17 | * @licence GNU GPL v3 or later |
13 | 18 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
14 | 19 | */ |
15 | | -abstract class ReviewDBObject { |
| 20 | +abstract class ReviewsDBObject { |
16 | 21 | |
17 | 22 | /** |
18 | 23 | * The fields of the object. |
— | — | @@ -31,6 +36,66 @@ |
32 | 37 | protected static $readDb = DB_SLAVE; |
33 | 38 | |
34 | 39 | /** |
| 40 | + * Returns the name of the database table objects of this type are stored in. |
| 41 | + * |
| 42 | + * @since 0.1 |
| 43 | + * |
| 44 | + * @throws MWException |
| 45 | + * @return string |
| 46 | + */ |
| 47 | + public static function getDBTable() { |
| 48 | + throw new MWException( 'Class did not implement getDBTable' ); |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * Gets the db field prefix. |
| 53 | + * |
| 54 | + * @since 0.1 |
| 55 | + * |
| 56 | + * @throws MWException |
| 57 | + * @return string |
| 58 | + */ |
| 59 | + protected static function getFieldPrefix() { |
| 60 | + throw new MWException( 'Class did not implement getFieldPrefix' ); |
| 61 | + } |
| 62 | + |
| 63 | + /** |
| 64 | + * Returns an array with the fields and their types this object contains. |
| 65 | + * This corresponds directly to the fields in the database, without prefix. |
| 66 | + * |
| 67 | + * field name => type |
| 68 | + * |
| 69 | + * Allowed types: |
| 70 | + * * id |
| 71 | + * * str |
| 72 | + * * int |
| 73 | + * * float |
| 74 | + * * bool |
| 75 | + * * array |
| 76 | + * |
| 77 | + * @since 0.1 |
| 78 | + * |
| 79 | + * @throws MWException |
| 80 | + * @return array |
| 81 | + */ |
| 82 | + protected static function getFieldTypes() { |
| 83 | + throw new MWException( 'Class did not implement getFieldTypes' ); |
| 84 | + } |
| 85 | + |
| 86 | + /** |
| 87 | + * Returns a list of default field values. |
| 88 | + * field name => field value |
| 89 | + * |
| 90 | + * @since 0.1 |
| 91 | + * |
| 92 | + * @throws MWException |
| 93 | + * @return array |
| 94 | + */ |
| 95 | + public static function getDefaults() { |
| 96 | + throw new MWException( 'Class did not implement getDefaults' ); |
| 97 | + } |
| 98 | + |
| 99 | + /** |
35 | 100 | * Constructor. |
36 | 101 | * |
37 | 102 | * @since 0.1 |
— | — | @@ -84,24 +149,6 @@ |
85 | 150 | } |
86 | 151 | |
87 | 152 | /** |
88 | | - * Returns the name of the database table objects of this type are stored in. |
89 | | - * |
90 | | - * @since 0.1 |
91 | | - * |
92 | | - * @return string |
93 | | - */ |
94 | | - public abstract function getDBTable(); |
95 | | - |
96 | | - /** |
97 | | - * Gets the db field prefix. |
98 | | - * |
99 | | - * @since 0.1 |
100 | | - * |
101 | | - * @return string |
102 | | - */ |
103 | | - protected abstract function getFieldPrefix(); |
104 | | - |
105 | | - /** |
106 | 153 | * Gets the value of a field. |
107 | 154 | * |
108 | 155 | * @since 0.1 |
— | — | @@ -408,36 +455,6 @@ |
409 | 456 | } |
410 | 457 | |
411 | 458 | /** |
412 | | - * Returns an array with the fields and their types this object contains. |
413 | | - * This corresponds directly to the fields in the database, without prefix. |
414 | | - * |
415 | | - * field name => type |
416 | | - * |
417 | | - * Allowed types: |
418 | | - * * id |
419 | | - * * str |
420 | | - * * int |
421 | | - * * float |
422 | | - * * bool |
423 | | - * * array |
424 | | - * |
425 | | - * @since 0.1 |
426 | | - * |
427 | | - * @return array |
428 | | - */ |
429 | | - protected abstract function getFieldTypes(); |
430 | | - |
431 | | - /** |
432 | | - * Returns a list of default field values. |
433 | | - * field name => field value |
434 | | - * |
435 | | - * @since 0.1 |
436 | | - * |
437 | | - * @return array |
438 | | - */ |
439 | | - public abstract function getDefaults(); |
440 | | - |
441 | | - /** |
442 | 459 | * Get a new instance of the class from an array. |
443 | 460 | * |
444 | 461 | * @since 0.1 |
Index: trunk/extensions/Reviews/includes/ReviewRating.php |
— | — | @@ -0,0 +1,64 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Class representing a single review rating. |
| 6 | + * |
| 7 | + * @since 0.1 |
| 8 | + * |
| 9 | + * @file ReviewRating.php |
| 10 | + * @ingroup Reviews |
| 11 | + * |
| 12 | + * @licence GNU GPL v3 or later |
| 13 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 14 | + */ |
| 15 | +class ReviewRating extends ReviewsDBObject { |
| 16 | + |
| 17 | + /** |
| 18 | + * @see parent::getFieldTypes |
| 19 | + * |
| 20 | + * @since 0.1 |
| 21 | + * |
| 22 | + * @return string |
| 23 | + */ |
| 24 | + public static function getDBTable() { |
| 25 | + return 'review_ratings'; |
| 26 | + } |
| 27 | + |
| 28 | + /** |
| 29 | + * @see parent::getFieldTypes |
| 30 | + * |
| 31 | + * @since 0.1 |
| 32 | + * |
| 33 | + * @return string |
| 34 | + */ |
| 35 | + protected static function getFieldPrefix() { |
| 36 | + return 'rating_'; |
| 37 | + } |
| 38 | + |
| 39 | + /** |
| 40 | + * @see parent::getFieldTypes |
| 41 | + * |
| 42 | + * @since 0.1 |
| 43 | + * |
| 44 | + * @return array |
| 45 | + */ |
| 46 | + protected static function getFieldTypes() { |
| 47 | + return array( |
| 48 | + 'id' => 'id', |
| 49 | + |
| 50 | + ); |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * @see parent::getDefaults |
| 55 | + * |
| 56 | + * @since 0.1 |
| 57 | + * |
| 58 | + * @return array |
| 59 | + */ |
| 60 | + public static function getDefaults() { |
| 61 | + return array( |
| 62 | + ); |
| 63 | + } |
| 64 | + |
| 65 | +} |
Property changes on: trunk/extensions/Reviews/includes/ReviewRating.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 66 | + native |
Index: trunk/extensions/Reviews/Reviews.settings.php |
— | — | @@ -28,6 +28,7 @@ |
29 | 29 | */ |
30 | 30 | protected static function getDefaultSettings() { |
31 | 31 | return array( |
| 32 | + 'reviewDeletionEnabled' => true, |
32 | 33 | 'enableTopLink' => true, |
33 | 34 | ); |
34 | 35 | } |
Index: trunk/extensions/Reviews/api/ApiSubmitReview.php |
— | — | @@ -0,0 +1,99 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * API module to submit reviews. |
| 6 | + * |
| 7 | + * @since 0.1 |
| 8 | + * |
| 9 | + * @file ApiSubmitReview.php |
| 10 | + * @ingroup Reviews |
| 11 | + * @ingroup API |
| 12 | + * |
| 13 | + * @licence GNU GPL v3+ |
| 14 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 15 | + */ |
| 16 | +class ApiSubmitReview extends ApiBase { |
| 17 | + |
| 18 | + public function execute() { |
| 19 | + if ( !$this->getUser()->isAllowed( 'review' ) || $this->getUser()->isBlocked() ) { |
| 20 | + $this->dieUsageMsg( array( 'badaccess-groups' ) ); |
| 21 | + } |
| 22 | + |
| 23 | + $params = $this->extractRequestParams(); |
| 24 | + |
| 25 | + if ( !( isset( $params['id'] ) XOR isset( $params['name'] ) ) ) { |
| 26 | + $this->dieUsage( wfMsgExt( 'review-err-id-xor-name' ), 'id-xor-name' ); |
| 27 | + } |
| 28 | + |
| 29 | + if ( isset( $params['name'] ) ) { |
| 30 | + $review = Review::selectRow( null, array( 'name' => $params['name'] ) ); |
| 31 | + |
| 32 | + if ( $review === false ) { |
| 33 | + $this->dieUsage( wfMsgExt( 'review-err-review-name-unknown', 'parsemag', $params['name'] ), 'review-name-unknown' ); |
| 34 | + } |
| 35 | + } else { |
| 36 | + $review = Review::selectRow( null, array( 'id' => $params['id'] ) ); |
| 37 | + |
| 38 | + if ( $review === false ) { |
| 39 | + $this->dieUsage( wfMsgExt( 'review-err-review-id-unknown', 'parsemag', $params['id'] ), 'review-id-unknown' ); |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + // TODO |
| 44 | + } |
| 45 | + |
| 46 | + public function needsToken() { |
| 47 | + return true; |
| 48 | + } |
| 49 | + |
| 50 | + public function getTokenSalt() { |
| 51 | + return serialize( array( 'submitreview', $this->getUser()->getName() ) ); |
| 52 | + } |
| 53 | + |
| 54 | + public function mustBePosted() { |
| 55 | + return true; |
| 56 | + } |
| 57 | + |
| 58 | + public function getAllowedParams() { |
| 59 | + return array( |
| 60 | + 'id' => array( |
| 61 | + ApiBase::PARAM_TYPE => 'integer', |
| 62 | + ), |
| 63 | + 'name' => array( |
| 64 | + ApiBase::PARAM_TYPE => 'string', |
| 65 | + ), |
| 66 | + // TODO |
| 67 | + 'token' => null, |
| 68 | + ); |
| 69 | + } |
| 70 | + |
| 71 | + public function getParamDescription() { |
| 72 | + return array( |
| 73 | + 'id' => 'The ID of the review being submitted.', |
| 74 | + 'name' => 'The name of the review being submitted.', |
| 75 | + 'token' => 'Edit token. You can get one of these through prop=info.', |
| 76 | + ); |
| 77 | + } |
| 78 | + |
| 79 | + public function getDescription() { |
| 80 | + return array( |
| 81 | + '' |
| 82 | + ); |
| 83 | + } |
| 84 | + |
| 85 | + public function getPossibleErrors() { |
| 86 | + return array_merge( parent::getPossibleErrors(), array( |
| 87 | + ) ); |
| 88 | + } |
| 89 | + |
| 90 | + protected function getExamples() { |
| 91 | + return array( |
| 92 | + 'api.php?action=submitreview&', |
| 93 | + ); |
| 94 | + } |
| 95 | + |
| 96 | + public function getVersion() { |
| 97 | + return __CLASS__ . ': $Id$'; |
| 98 | + } |
| 99 | + |
| 100 | +} |
Property changes on: trunk/extensions/Reviews/api/ApiSubmitReview.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 101 | + native |
Added: svn:keywords |
2 | 102 | + Id |
Index: trunk/extensions/Reviews/api/ApiDeleteReviews.php |
— | — | @@ -0,0 +1,96 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * API module to delete reviews. |
| 6 | + * |
| 7 | + * @since 0.1 |
| 8 | + * |
| 9 | + * @file ApiDeleteReviews.php |
| 10 | + * @ingroup Reviews |
| 11 | + * @ingroup API |
| 12 | + * |
| 13 | + * @licence GNU GPL v3+ |
| 14 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 15 | + */ |
| 16 | +class ApiDeleteReviews extends ApiBase { |
| 17 | + |
| 18 | + public function execute() { |
| 19 | + if ( !ReviewsSettings::get( 'reviewDeletionEnabled' ) ) { |
| 20 | + $this->dieUsage( 'Review deletion is disabled', 'reviewdeletiondisabled' ); |
| 21 | + } |
| 22 | + |
| 23 | + if ( !$this->getUser()->isAllowed( 'reviewadmin' ) || $this->getUser()->isBlocked() ) { |
| 24 | + $this->dieUsageMsg( array( 'badaccess-groups' ) ); |
| 25 | + } |
| 26 | + |
| 27 | + $params = $this->extractRequestParams(); |
| 28 | + |
| 29 | + $everythingOk = true; |
| 30 | + |
| 31 | + foreach ( $params['ids'] as $id ) { |
| 32 | + $review = new Review( array( 'id' => $id ) ); |
| 33 | + $everythingOk = $review->removeAllFromDB() && $everythingOk; |
| 34 | + } |
| 35 | + |
| 36 | + $this->getResult()->addValue( |
| 37 | + null, |
| 38 | + 'success', |
| 39 | + $everythingOk |
| 40 | + ); |
| 41 | + } |
| 42 | + |
| 43 | + public function needsToken() { |
| 44 | + return true; |
| 45 | + } |
| 46 | + |
| 47 | + public function getTokenSalt() { |
| 48 | + $params = $this->extractRequestParams(); |
| 49 | + return 'deletereview' . implode( '|', $params['ids'] ); |
| 50 | + } |
| 51 | + |
| 52 | + public function mustBePosted() { |
| 53 | + return true; |
| 54 | + } |
| 55 | + |
| 56 | + public function getAllowedParams() { |
| 57 | + return array( |
| 58 | + 'ids' => array( |
| 59 | + ApiBase::PARAM_TYPE => 'integer', |
| 60 | + ApiBase::PARAM_REQUIRED => true, |
| 61 | + ApiBase::PARAM_ISMULTI => true, |
| 62 | + ), |
| 63 | + 'token' => null, |
| 64 | + ); |
| 65 | + } |
| 66 | + |
| 67 | + public function getParamDescription() { |
| 68 | + return array( |
| 69 | + 'ids' => 'The IDs of the reviews to delete', |
| 70 | + 'token' => 'Edit token, salted with the review ids', |
| 71 | + ); |
| 72 | + } |
| 73 | + |
| 74 | + public function getDescription() { |
| 75 | + return array( |
| 76 | + 'API module for deleting reviews.' |
| 77 | + ); |
| 78 | + } |
| 79 | + |
| 80 | + public function getPossibleErrors() { |
| 81 | + return array_merge( parent::getPossibleErrors(), array( |
| 82 | + array( 'code' => 'reviewdeletiondisabled', 'info' => 'Review deletion is disabled' ), |
| 83 | + ) ); |
| 84 | + } |
| 85 | + |
| 86 | + protected function getExamples() { |
| 87 | + return array( |
| 88 | + 'api.php?action=deletereviews&ids=42', |
| 89 | + 'api.php?action=deletereviews&ids=4|2', |
| 90 | + ); |
| 91 | + } |
| 92 | + |
| 93 | + public function getVersion() { |
| 94 | + return __CLASS__ . ': $Id$'; |
| 95 | + } |
| 96 | + |
| 97 | +} |
Property changes on: trunk/extensions/Reviews/api/ApiDeleteReviews.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 98 | + native |
Added: svn:keywords |
2 | 99 | + Id |
Index: trunk/extensions/Reviews/api/ApiReviewQuery.php |
— | — | @@ -0,0 +1,233 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Base class for API query modules that return results using a |
| 6 | + * ReviewsDBObject deriving class. |
| 7 | + * |
| 8 | + * @since 0.1 |
| 9 | + * |
| 10 | + * @file ApiReviewQuery.php |
| 11 | + * @ingroup Reviews |
| 12 | + * @ingroup API |
| 13 | + * |
| 14 | + * @licence GNU GPL v3+ |
| 15 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 16 | + */ |
| 17 | +abstract class ApiReviewQuery extends ApiQueryBase { |
| 18 | + |
| 19 | + /** |
| 20 | + * Returns the class specific info. |
| 21 | + * * class: name of the ReviewsDBObject deriving class (ie Contest) |
| 22 | + * * item: item name (ie contest) |
| 23 | + * * set: item set name (ie contests) |
| 24 | + * |
| 25 | + * @since 0.1 |
| 26 | + * |
| 27 | + * @return array of string |
| 28 | + */ |
| 29 | + protected abstract function getClassInfo(); |
| 30 | + |
| 31 | + /** |
| 32 | + * Returns the name of the ReviewsDBObject deriving class. |
| 33 | + * |
| 34 | + * @since 0.1 |
| 35 | + * |
| 36 | + * @return string |
| 37 | + */ |
| 38 | + protected function getClass() { |
| 39 | + $className = $this->getClassInfo(); |
| 40 | + return $className['class']; |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * Get the parameters, find out what the conditions for the query are, |
| 45 | + * run it, and add the results. |
| 46 | + * |
| 47 | + * @since 0.1 |
| 48 | + */ |
| 49 | + public function execute() { |
| 50 | + $params = $this->getParams(); |
| 51 | + |
| 52 | + if ( count( $params['props'] ) > 0 ) { |
| 53 | + $results = $this->getResults( $params, $this->getConditions( $params ) ); |
| 54 | + $this->addResults( $params, $results ); |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * Get the request parameters, handle the * value for the props param |
| 60 | + * and remove all params set to null (ie those that are not actually provided). |
| 61 | + * |
| 62 | + * @since 0.1 |
| 63 | + * |
| 64 | + * @return array |
| 65 | + */ |
| 66 | + protected function getParams() { |
| 67 | + // Get the requests parameters. |
| 68 | + $params = $this->extractRequestParams(); |
| 69 | + |
| 70 | + $starPropPosition = array_search( '*', $params['props'] ); |
| 71 | + |
| 72 | + if ( $starPropPosition !== false ) { |
| 73 | + unset( $params['props'][$starPropPosition] ); |
| 74 | + $class = $this->getClass(); |
| 75 | + $params['props'] = array_merge( $params['props'], $class::getFieldNames() ); |
| 76 | + } |
| 77 | + |
| 78 | + return array_filter( $params, create_function( '$p', 'return isset( $p );' ) ); |
| 79 | + } |
| 80 | + |
| 81 | + /** |
| 82 | + * Get the conditions for the query. These will be provided as |
| 83 | + * regular parameters, together with limit, props, continue, |
| 84 | + * and possibly others which we need to get rid off. |
| 85 | + * |
| 86 | + * @since 0.1 |
| 87 | + * |
| 88 | + * @param array $params |
| 89 | + * |
| 90 | + * @return array |
| 91 | + */ |
| 92 | + protected function getConditions( array $params ) { |
| 93 | + $conditions = array(); |
| 94 | + |
| 95 | + foreach ( $params as $name => $value ) { |
| 96 | + $class = $this->getClass(); |
| 97 | + if ( $class::canHasField( $name ) ) { |
| 98 | + $conditions[$name] = $value; |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + return $conditions; |
| 103 | + } |
| 104 | + |
| 105 | + /** |
| 106 | + * Get the actual results. |
| 107 | + * |
| 108 | + * @since 0.1 |
| 109 | + * |
| 110 | + * @param array $params |
| 111 | + * @param array $conditions |
| 112 | + * |
| 113 | + * @return array of ReviewsDBObject |
| 114 | + */ |
| 115 | + protected function getResults( array $params, array $conditions ) { |
| 116 | + $class = $this->getClass(); |
| 117 | + return $this->getClass()->select( |
| 118 | + $params['props'], |
| 119 | + $conditions, |
| 120 | + array( |
| 121 | + 'LIMIT' => $params['limit'] + 1, |
| 122 | + 'ORDER BY' => $class::getPrefixedField( 'id' ) . ' ASC' |
| 123 | + ) |
| 124 | + ); |
| 125 | + } |
| 126 | + |
| 127 | + /** |
| 128 | + * Serialize the results and add them to the result object. |
| 129 | + * |
| 130 | + * @since 0.1 |
| 131 | + * |
| 132 | + * @param array $params |
| 133 | + * @param array $results |
| 134 | + */ |
| 135 | + protected function addResults( array $params, array /* of ReviewsDBObject */ $results ) { |
| 136 | + $serializedResults = array(); |
| 137 | + $count = 0; |
| 138 | + |
| 139 | + foreach ( $results as $result ) { |
| 140 | + if ( ++$count > $params['limit'] ) { |
| 141 | + // We've reached the one extra which shows that |
| 142 | + // there are additional pages to be had. Stop here... |
| 143 | + $this->setContinueEnumParameter( 'continue', $result->getId() ); |
| 144 | + break; |
| 145 | + } |
| 146 | + |
| 147 | + $serializedResults[] = $result->toArray( $params['props'] ); |
| 148 | + } |
| 149 | + |
| 150 | + $this->setIndexedTagNames( $serializedResults ); |
| 151 | + $this->addSerializedResults( $serializedResults ); |
| 152 | + } |
| 153 | + |
| 154 | + /** |
| 155 | + * Set the tag names for formats such as XML. |
| 156 | + * |
| 157 | + * @since 0.1 |
| 158 | + * |
| 159 | + * @param array $serializedResults |
| 160 | + */ |
| 161 | + protected function setIndexedTagNames( array &$serializedResults ) { |
| 162 | + $classInfo = $this->getClassInfo(); |
| 163 | + $this->getResult()->setIndexedTagName( $serializedResults, $classInfo['item'] ); |
| 164 | + } |
| 165 | + |
| 166 | + /** |
| 167 | + * Add the serialized results to the result object. |
| 168 | + * |
| 169 | + * @since 0.1 |
| 170 | + * |
| 171 | + * @param array $serializedResults |
| 172 | + */ |
| 173 | + protected function addSerializedResults( array $serializedResults ) { |
| 174 | + $classInfo = $this->getClassInfo(); |
| 175 | + |
| 176 | + $this->getResult()->addValue( |
| 177 | + null, |
| 178 | + $classInfo['set'], |
| 179 | + $serializedResults |
| 180 | + ); |
| 181 | + } |
| 182 | + |
| 183 | + /** |
| 184 | + * (non-PHPdoc) |
| 185 | + * @see includes/api/ApiBase#getAllowedParams() |
| 186 | + * @return array |
| 187 | + */ |
| 188 | + public function getAllowedParams() { |
| 189 | + $class = $this->getClass(); |
| 190 | + $params = array ( |
| 191 | + 'props' => array( |
| 192 | + ApiBase::PARAM_TYPE => array_merge( $class::getFieldNames(), array( '*' ) ), |
| 193 | + ApiBase::PARAM_ISMULTI => true, |
| 194 | + ApiBase::PARAM_DFLT => '*' |
| 195 | + ), |
| 196 | + 'limit' => array( |
| 197 | + ApiBase::PARAM_DFLT => 20, |
| 198 | + ApiBase::PARAM_TYPE => 'limit', |
| 199 | + ApiBase::PARAM_MIN => 1, |
| 200 | + ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1, |
| 201 | + ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2 |
| 202 | + ), |
| 203 | + 'continue' => null, |
| 204 | + ); |
| 205 | + |
| 206 | + return array_merge( $class::getAPIParams(), $params ); |
| 207 | + } |
| 208 | + |
| 209 | + /** |
| 210 | + * (non-PHPdoc) |
| 211 | + * @see includes/api/ApiBase#getParamDescription() |
| 212 | + */ |
| 213 | + public function getParamDescription() { |
| 214 | + $descs = array ( |
| 215 | + 'props' => 'Fields to query', |
| 216 | + 'continue' => 'Offset number from where to continue the query', |
| 217 | + 'limit' => 'Max amount of rows to return', |
| 218 | + ); |
| 219 | + |
| 220 | + $class = $this->getClass(); |
| 221 | + return array_merge( $class::getFieldDescriptions(), $descs ); |
| 222 | + } |
| 223 | + |
| 224 | + /** |
| 225 | + * (non-PHPdoc) |
| 226 | + * @see includes/api/ApiBase#getPossibleErrors() |
| 227 | + */ |
| 228 | + public function getPossibleErrors() { |
| 229 | + return array_merge( parent::getPossibleErrors(), array( |
| 230 | + array( 'badaccess-groups' ), |
| 231 | + ) ); |
| 232 | + } |
| 233 | + |
| 234 | +} |
Property changes on: trunk/extensions/Reviews/api/ApiReviewQuery.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 235 | + native |
Added: svn:keywords |
2 | 236 | + Id |
Index: trunk/extensions/Reviews/api/ApiQueryReviews.php |
— | — | @@ -0,0 +1,75 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * API module to get a list of reviews. |
| 6 | + * |
| 7 | + * @since 0.1 |
| 8 | + * |
| 9 | + * @file ApiQueryReviews.php |
| 10 | + * @ingroup Reviews |
| 11 | + * @ingroup API |
| 12 | + * |
| 13 | + * @licence GNU GPL v3+ |
| 14 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 15 | + */ |
| 16 | +class ApiQueryReviews extends ApiReviewQuery { |
| 17 | + |
| 18 | + /** |
| 19 | + * (non-PHPdoc) |
| 20 | + * @see ApiContestQuery::getClassInfo() |
| 21 | + * @return array |
| 22 | + */ |
| 23 | + protected function getClassInfo() { |
| 24 | + return array( |
| 25 | + 'class' => 'Review', |
| 26 | + 'item' => 'review', |
| 27 | + 'set' => 'reviews', |
| 28 | + ); |
| 29 | + } |
| 30 | + |
| 31 | + public function __construct( $main, $action ) { |
| 32 | + parent::__construct( $main, $action, 're' ); |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * Handle the API request. |
| 37 | + * Checks for access rights and then let's the parent method do the actual work. |
| 38 | + */ |
| 39 | + public function execute() { |
| 40 | + global $wgUser; |
| 41 | + |
| 42 | + if ( !$wgUser->isAllowed( 'contestadmin' ) || $wgUser->isBlocked() ) { |
| 43 | + $this->dieUsageMsg( array( 'badaccess-groups' ) ); |
| 44 | + } |
| 45 | + |
| 46 | + parent::execute(); |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * (non-PHPdoc) |
| 51 | + * @see includes/api/ApiBase#getDescription() |
| 52 | + */ |
| 53 | + public function getDescription() { |
| 54 | + return 'API module for querying reviews'; |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * (non-PHPdoc) |
| 59 | + * @see includes/api/ApiBase#getExamples() |
| 60 | + */ |
| 61 | + protected function getExamples() { |
| 62 | + return array ( |
| 63 | + 'api.php?action=query&list=reviews&reprops=id|name', |
| 64 | + 'api.php?action=query&list=reviews&restatus=1', |
| 65 | + ); |
| 66 | + } |
| 67 | + |
| 68 | + /** |
| 69 | + * (non-PHPdoc) |
| 70 | + * @see includes/api/ApiBase#getVersion() |
| 71 | + */ |
| 72 | + public function getVersion() { |
| 73 | + return __CLASS__ . ': $Id$'; |
| 74 | + } |
| 75 | + |
| 76 | +} |
Property changes on: trunk/extensions/Reviews/api/ApiQueryReviews.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 77 | + native |
Added: svn:keywords |
2 | 78 | + Id |
Index: trunk/extensions/Reviews/Reviews.php |
— | — | @@ -49,7 +49,19 @@ |
50 | 50 | $wgAutoloadClasses['ReviewsHooks'] = dirname( __FILE__ ) . '/Reviews.hooks.php'; |
51 | 51 | $wgAutoloadClasses['ReviewsSettings'] = dirname( __FILE__ ) . '/Reviews.settings.php'; |
52 | 52 | |
| 53 | +$wgAutoloadClasses['ApiDeleteReviews'] = dirname( __FILE__ ) . '/api/ApiDeleteReviews.php'; |
| 54 | +$wgAutoloadClasses['ApiQueryReviews'] = dirname( __FILE__ ) . '/api/ApiQueryReviews.php'; |
| 55 | +$wgAutoloadClasses['ApiReviewQuery'] = dirname( __FILE__ ) . '/api/ApiReviewQuery.php'; |
| 56 | +$wgAutoloadClasses['ApiSubmitReview'] = dirname( __FILE__ ) . '/api/ApiSubmitReview.php'; |
53 | 57 | |
| 58 | +$wgAutoloadClasses['Review'] = dirname( __FILE__ ) . '/includes/Review.php'; |
| 59 | +$wgAutoloadClasses['ReviewPager'] = dirname( __FILE__ ) . '/includes/ReviewPager.php'; |
| 60 | +$wgAutoloadClasses['ReviewRating'] = dirname( __FILE__ ) . '/includes/ReviewRating.php'; |
| 61 | +$wgAutoloadClasses['ReviewsDBObject'] = dirname( __FILE__ ) . '/includes/ReviewsDBObject.php'; |
| 62 | + |
| 63 | +$wgAutoloadClasses['SpecialMyReviews'] = dirname( __FILE__ ) . '/specials/SpecialMyReviews.php'; |
| 64 | +$wgAutoloadClasses['SpecialReviews'] = dirname( __FILE__ ) . '/specials/SpecialReviews.php'; |
| 65 | + |
54 | 66 | // Special pages |
55 | 67 | $wgSpecialPages['Reviews'] = 'SpecialReviews'; |
56 | 68 | $wgSpecialPages['MyReviews'] = 'SpecialMyReviews'; |
— | — | @@ -58,6 +70,9 @@ |
59 | 71 | $wgSpecialPageGroups['MyReviews'] = 'reviews'; |
60 | 72 | |
61 | 73 | // API |
| 74 | +$wgAPIModules['deletereviews'] = 'ApiDeleteReviews'; |
| 75 | +$wgAPIModules['submitreview'] = 'ApiSubmitReview'; |
| 76 | +$wgAPIListModules['reviews'] = 'ApiQueryReviews'; |
62 | 77 | |
63 | 78 | // Hooks |
64 | 79 | $wgHooks['LoadExtensionSchemaUpdates'][] = 'ReviewsHooks::onSchemaUpdate'; |