r103794 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103793‎ | r103794 | r103795 >
Date:00:23, 21 November 2011
Author:jeroendedauw
Status:reverted
Tags:
Comment:
work on pager and schema
Modified paths:
  • /trunk/extensions/Reviews/Reviews.hooks.php (modified) (history)
  • /trunk/extensions/Reviews/Reviews.i18n.php (modified) (history)
  • /trunk/extensions/Reviews/Reviews.php (modified) (history)
  • /trunk/extensions/Reviews/api/ApiSubmitReview.php (modified) (history)
  • /trunk/extensions/Reviews/includes/ReviewPager.php (modified) (history)
  • /trunk/extensions/Reviews/resources/jquery.reviewControl.js (modified) (history)
  • /trunk/extensions/Reviews/specials/SpecialReviews.php (modified) (history)
  • /trunk/extensions/Reviews/sql/Reviews.sql (modified) (history)

Diff [purge]

Index: trunk/extensions/Reviews/sql/Reviews.sql
@@ -16,7 +16,10 @@
1717 ) /*$wgDBTableOptions*/;
1818
1919 CREATE UNIQUE INDEX /*i*/review_page_user ON /*_*/reviews (review_page_id, review_user_id);
20 -CREATE INDEX /*i*/review_time ON /*_*/reviews (review_time);
 20+CREATE INDEX /*i*/review_user_id ON /*_*/reviews (review_user_id);
 21+CREATE INDEX /*i*/review_title ON /*_*/reviews (review_title);
 22+CREATE INDEX /*i*/review_post_time ON /*_*/reviews (review_post_time);
 23+CREATE INDEX /*i*/review_edit_time ON /*_*/reviews (review_edit_time);
2124 CREATE INDEX /*i*/review_state ON /*_*/reviews (review_state);
2225 CREATE INDEX /*i*/review_rating ON /*_*/reviews (review_rating);
2326
@@ -28,3 +31,4 @@
2932 ) /*$wgDBTableOptions*/;
3033
3134 CREATE UNIQUE INDEX /*i*/rrating_review_type ON /*_*/review_ratings (rating_review_id, rating_type);
 35+CREATE INDEX /*i*/review_rating_type ON /*_*/review_ratings (rating_type);
Index: trunk/extensions/Reviews/specials/SpecialReviews.php
@@ -21,7 +21,7 @@
2222 * @since 0.1
2323 */
2424 public function __construct() {
25 - parent::__construct( 'Reviews', 'reviewer' );
 25+ parent::__construct( 'Reviews', 'review' );
2626 }
2727
2828 /**
@@ -32,6 +32,7 @@
3333 * @param string $arg
3434 */
3535 public function execute( $subPage ) {
 36+ $subPage = is_null( $subPage ) ? '' : $subPage;
3637 $this->subPage = str_replace( '_', ' ', $subPage );
3738
3839 $this->setHeaders();
@@ -51,12 +52,23 @@
5253 $this->displayReviewList();
5354 }
5455 else {
55 -
5656 }
5757 }
5858 }
5959
6060 protected function displayReviewList() {
 61+ $reviewPager = new ReviewPager( array() );
 62+
 63+ if ( $reviewPager->getNumRows() ) {
 64+ $this->getOutput()->addHTML(
 65+ $reviewPager->getNavigationBar() .
 66+ $reviewPager->getBody() .
 67+ $reviewPager->getNavigationBar()
 68+ );
 69+ }
 70+ else {
 71+ $this->getOutput()->addWikiMsg( 'reviews-pager-no-results' );
 72+ }
6173 }
6274
6375 }
Index: trunk/extensions/Reviews/includes/ReviewPager.php
@@ -81,7 +81,11 @@
8282
8383 if ( is_null( $headers ) ) {
8484 $headers = array(
85 - // TODO
 85+ 'reviews-pager-post-time',
 86+ 'reviews-pager-state',
 87+ 'reviews-pager-title',
 88+ 'reviews-pager-user',
 89+ 'reviews-pager-page',
8690 );
8791
8892 $headers = array_map( 'wfMsg', $headers );
@@ -117,7 +121,12 @@
118122 return array(
119123 'tables' => array( 'reviews' ),
120124 'fields' => array(
121 - // TODO
 125+ 'review_id',
 126+ 'review_post_time',
 127+ 'review_state',
 128+ 'review_title',
 129+ 'review_user_id',
 130+ 'review_page_id',
122131 ),
123132 'conds' => $this->conds,
124133 );
@@ -132,7 +141,7 @@
133142 }
134143
135144 function getDefaultSort() {
136 - return 'review_time';
 145+ return 'review_post_time';
137146 }
138147
139148 function isFieldSortable( $name ) {
Index: trunk/extensions/Reviews/Reviews.i18n.php
@@ -25,7 +25,7 @@
2626
2727 // Rights
2828 'right-reviewsadmin' => 'Manage reviews',
29 - 'right-reviewer' => 'Post reviews',
 29+ 'right-review' => 'Post reviews',
3030
3131 'action-reviewsadmin' => 'manage reviews',
3232 'action-reviewer' => 'post reviews',
@@ -38,4 +38,7 @@
3939 'group-reviewer' => 'Reviewer',
4040 'group-reviewer-member' => '{{GENDER:$1|Reviewer}}',
4141 'grouppage-reviewer' => '{{ns:project}}:Reviewers',
 42+
 43+ // Review control
 44+ 'reviews-submission-submit' => 'Submit',
4245 );
Index: trunk/extensions/Reviews/api/ApiSubmitReview.php
@@ -21,25 +21,29 @@
2222
2323 $params = $this->extractRequestParams();
2424
25 - if ( !( isset( $params['id'] ) XOR isset( $params['name'] ) ) ) {
26 - $this->dieUsage( wfMsgExt( 'review-err-id-xor-name' ), 'id-xor-name' );
27 - }
 25+ unset( $params['token'] );
 26+ $params['edit_time'] = wfTimestampNow();
 27+ $params['user_id'] = $this->getUser()->getId();
2828
29 - if ( isset( $params['name'] ) ) {
30 - $review = Review::selectRow( null, array( 'name' => $params['name'] ) );
 29+ if ( array_key_exists( 'id', $params ) ) {
 30+ $review = Review::selectRow( array( 'id', 'user_id' ), array( 'id' => $params['id'] ) );
3131
32 - if ( $review === false ) {
33 - $this->dieUsage( wfMsgExt( 'review-err-review-name-unknown', 'parsemag', $params['name'] ), 'review-name-unknown' );
 32+ if ( $review->getField( 'user_id' ) === $this->getUser()->getId() ) {
 33+ $review->setFields( $params );
 34+ $review->writeToDB();
3435 }
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' );
 36+ else {
 37+ $this->dieUsageMsg( array( 'badaccess-groups' ) );
4038 }
4139 }
42 -
43 - // TODO
 40+ else {
 41+ $review = new Review( $params );
 42+
 43+ $review->setField( 'state', Review::STATUS_NEW );
 44+ $review->setField( 'post_time', wfTimestampNow() );
 45+
 46+ $review->writeToDB();
 47+ }
4448 }
4549
4650 public function needsToken() {
@@ -51,24 +55,49 @@
5256 }
5357
5458 public function getAllowedParams() {
55 - return array(
 59+ $params = array(
5660 'id' => array(
5761 ApiBase::PARAM_TYPE => 'integer',
5862 ),
59 - 'name' => array(
 63+ 'title' => array(
6064 ApiBase::PARAM_TYPE => 'string',
 65+ ApiBase::PARAM_REQUIRED => true,
6166 ),
 67+ 'text' => array(
 68+ ApiBase::PARAM_TYPE => 'string',
 69+ ApiBase::PARAM_REQUIRED => true,
 70+ ),
 71+ 'rating' => array(
 72+ ApiBase::PARAM_TYPE => 'integer',
 73+ ApiBase::PARAM_REQUIRED => true,
 74+ ),
 75+ 'ratings' => array(
 76+ ApiBase::PARAM_TYPE => 'string',
 77+ ApiBase::PARAM_REQUIRED => true,
 78+ ),
 79+ 'page_id' => array(
 80+ ApiBase::PARAM_TYPE => 'integer',
 81+ ApiBase::PARAM_REQUIRED => true,
 82+ ),
6283 // TODO
6384 'token' => null,
6485 );
 86+
 87+ return $params;
6588 }
6689
6790 public function getParamDescription() {
68 - return array(
69 - 'id' => 'The ID of the review being submitted.',
70 - 'name' => 'The name of the review being submitted.',
 91+ $descs = array(
 92+ 'id' => 'The ID of the review being submitted, ommit for new review.',
7193 'token' => 'Edit token. You can get one of these through prop=info.',
 94+ 'title' => 'The review title',
 95+ 'text' => 'The review text',
 96+ 'rating' => 'The main rating for the review',
 97+ 'ratings' => 'JSON string holding the rating data',
 98+ 'page_id' => 'The ID of the page to which the review belongs',
7299 );
 100+
 101+ return $descs;
73102 }
74103
75104 public function getDescription() {
Index: trunk/extensions/Reviews/Reviews.php
@@ -84,7 +84,7 @@
8585
8686 // Rights
8787 $wgAvailableRights[] = 'reviewsadmin';
88 -$wgAvailableRights[] = 'reviewer';
 88+$wgAvailableRights[] = 'review';
8989
9090 # Users that can manage the reviews.
9191 $wgGroupPermissions['*' ]['reviewsadmin'] = false;
@@ -95,12 +95,12 @@
9696 $wgGroupPermissions['reviewsadmin' ]['reviewsadmin'] = true;
9797
9898 # Users that can post reviews.
99 -$wgGroupPermissions['*' ]['reviewer'] = false;
100 -$wgGroupPermissions['user' ]['reviewer'] = true;
101 -//$wgGroupPermissions['autoconfirmed']['reviewer'] = true;
102 -//$wgGroupPermissions['bot' ]['reviewer'] = false;
103 -$wgGroupPermissions['sysop' ]['reviewer'] = true;
104 -$wgGroupPermissions['reviewer']['reviewer'] = true;
 99+$wgGroupPermissions['*' ]['review'] = false;
 100+$wgGroupPermissions['user' ]['review'] = true;
 101+//$wgGroupPermissions['autoconfirmed']['review'] = true;
 102+//$wgGroupPermissions['bot' ]['review'] = false;
 103+$wgGroupPermissions['sysop' ]['review'] = true;
 104+$wgGroupPermissions['reviewer']['review'] = true;
105105
106106
107107 // Resource loader modules
@@ -125,9 +125,10 @@
126126 'jquery.reviewControl.css',
127127 ),
128128 'messages' => array(
 129+ 'reviews-submission-submit'
129130 ),
130131 'dependencies' => array(
131 - 'jquery.json', 'ext.reviews'
 132+ 'jquery.json', 'ext.reviews', 'jquery.ui.button',
132133 ),
133134 );
134135
Index: trunk/extensions/Reviews/resources/jquery.reviewControl.js
@@ -27,7 +27,15 @@
2828
2929 $this.append( $( '<textarea />' ).attr( {
3030 'name': this.fieldName( 'text' )
31 - } ).text( this.review.fields.text ) );
 31+ } ).text( this.review.fields.text ) );
 32+
 33+ this.button = $( '<button />' )
 34+ .button( { 'label': mw.msg( 'reviews-submission-submit' ) } )
 35+ .click( function() {
 36+ _this.save();
 37+ } );
 38+
 39+ $this.append( this.button );
3240 };
3341
3442 this.setup = function() {
@@ -39,15 +47,16 @@
4048
4149 this.readInputs = function() {
4250
43 - this.review = new reviews.review(); // TODO
 51+ //this.review = new reviews.review(); // TODO
4452 };
4553
4654 this.save = function() {
4755 this.readInputs();
4856
 57+ this.button.button( 'disable' );
4958
5059 this.review.save( function() {
51 -
 60+ this.button.button( 'enable' );
5261 } );
5362 };
5463
Index: trunk/extensions/Reviews/Reviews.hooks.php
@@ -23,7 +23,13 @@
2424 * @return true
2525 */
2626 public static function onSchemaUpdate( /* DatabaseUpdater */ $updater = null ) {
27 -
 27+ $updater->addExtensionUpdate( array(
 28+ 'addTable',
 29+ 'reviews',
 30+ dirname( __FILE__ ) . '/sql/Reviews.sql',
 31+ true
 32+ ) );
 33+
2834 return true;
2935 }
3036

Status & tagging log