r85712 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85711‎ | r85712 | r85713 >
Date:04:15, 9 April 2011
Author:aaron
Status:ok
Tags:
Comment:
* Fixed two API pages to use new FRUserActivity class (old code wouldn't work)
* Various API code and desc cleanups
Modified paths:
  • /trunk/extensions/FlaggedRevs/FRUserActivity.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/api/ApiQueryFlagged.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/api/ApiQueryOldreviewedpages.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/api/ApiQueryReviewedpages.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/api/ApiQueryUnreviewedpages.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/api/ApiStabilize.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FRUserActivity.php
@@ -55,6 +55,16 @@
5656 }
5757
5858 /*
 59+ * Check is someone is currently reviewing a page
 60+ * @param int $pageId
 61+ * @return bool
 62+ */
 63+ public static function pageIsUnderReview( $pageId ) {
 64+ $m = self::getUserReviewingPage( $pageId );
 65+ return ( $m[0] !== null );
 66+ }
 67+
 68+ /*
5969 * Set the flag for who is reviewing a page if not already set by someone
6070 * @param User $user
6171 * @param int $pageId
@@ -112,6 +122,17 @@
113123 }
114124
115125 /*
 126+ * Check is someone is currently reviewing a diff
 127+ * @param int $oldId
 128+ * @param int $newId
 129+ * @return bool
 130+ */
 131+ public static function diffIsUnderReview( $oldId, $newId ) {
 132+ $m = self::getUserReviewingDiff( $oldId, $newId );
 133+ return ( $m[0] !== null );
 134+ }
 135+
 136+ /*
116137 * Set the flag for who is reviewing a diff if not already set by someone
117138 * @param User $user
118139 * @param int $pageId
Index: trunk/extensions/FlaggedRevs/api/ApiQueryFlagged.php
@@ -45,15 +45,15 @@
4646
4747 $result = $this->getResult();
4848 foreach( $res as $row ) {
49 - $pageid = $row->fp_page_id;
5049 $data = array(
51 - 'stable_revid' => intval( $row->fp_stable ),
52 - 'level' => intval( $row->fp_quality ),
53 - 'level_text' => FlaggedRevs::getQualityLevelText( $row->fp_quality )
 50+ 'stable_revid' => intval( $row->fp_stable ),
 51+ 'level' => intval( $row->fp_quality ),
 52+ 'level_text' => FlaggedRevs::getQualityLevelText( $row->fp_quality )
5453 );
55 - if ( $row->fp_pending_since )
 54+ if ( $row->fp_pending_since ) {
5655 $data['pending_since'] = wfTimestamp( TS_ISO_8601, $row->fp_pending_since );
57 - $result->addValue( array( 'query', 'pages', $pageid ), 'flagged', $data );
 56+ }
 57+ $result->addValue( array( 'query', 'pages', $row->fp_page_id ), 'flagged', $data );
5858 }
5959 }
6060
Index: trunk/extensions/FlaggedRevs/api/ApiQueryOldreviewedpages.php
@@ -48,15 +48,18 @@
4949 $this->addTables( array( 'page', 'flaggedpages', 'revision' ) );
5050 $this->addWhereFld( 'page_namespace', $params['namespace'] );
5151 $useIndex = array( 'flaggedpages' => 'fp_pending_since' );
52 - if ( $params['filterredir'] == 'redirects' )
 52+ if ( $params['filterredir'] == 'redirects' ) {
5353 $this->addWhereFld( 'page_is_redirect', 1 );
54 - if ( $params['filterredir'] == 'nonredirects' )
 54+ }
 55+ if ( $params['filterredir'] == 'nonredirects' ) {
5556 $this->addWhereFld( 'page_is_redirect', 0 );
56 - if ( $params['maxsize'] !== null )
 57+ }
 58+ if ( $params['maxsize'] !== null ) {
5759 # Get absolute difference for comparison. ABS(x-y)
5860 # is broken due to mysql unsigned int design.
5961 $this->addWhere( 'GREATEST(page_len,rev_len)-LEAST(page_len,rev_len) <= ' .
6062 intval( $params['maxsize'] ) );
 63+ }
6164 if ( $params['filterwatched'] == 'watched' ) {
6265 if ( !( $uid = $wgUser->getId() ) ) {
6366 $this->dieUsage( 'You must be logged-in to have a watchlist', 'notloggedin' );
@@ -72,6 +75,7 @@
7376 $this->addWhereFld( 'cl_to', $params['category'] );
7477 $useIndex['categorylinks'] = 'cl_from';
7578 }
 79+
7680 $this->addWhereRange(
7781 'fp_pending_since',
7882 $params['dir'],
@@ -80,13 +84,13 @@
8185 );
8286 $this->addWhere( 'page_id=fp_page_id' );
8387 $this->addWhere( 'rev_id=fp_stable' );
84 - if ( !isset( $params['start'] ) && !isset( $params['end'] ) )
 88+ if ( !isset( $params['start'] ) && !isset( $params['end'] ) ) {
8589 $this->addWhere( 'fp_pending_since IS NOT NULL' );
86 -
 90+ }
8791 $this->addOption( 'USE INDEX', $useIndex );
8892
8993 if ( is_null( $resultPageSet ) ) {
90 - $this->addFields( array (
 94+ $this->addFields( array(
9195 'page_id',
9296 'page_namespace',
9397 'page_title',
@@ -106,7 +110,7 @@
107111 $this->addOption( 'LIMIT', $limit + 1 );
108112 $res = $this->select( __METHOD__ );
109113
110 - $data = array ();
 114+ $data = array();
111115 $count = 0;
112116 foreach( $res as $row ) {
113117 if ( ++$count > $limit ) {
@@ -121,19 +125,19 @@
122126
123127 if ( is_null( $resultPageSet ) ) {
124128 $title = Title::newFromRow( $row );
125 - $key = wfMemcKey( 'stableDiffs', 'underReview',
 129+ $underReview = FRUserActivity::diffIsUnderReview(
126130 $row->fp_stable, $row->page_latest );
127131 $data[] = array(
128 - 'pageid' => intval( $row->page_id ),
129 - 'ns' => intval( $title->getNamespace() ),
130 - 'title' => $title->getPrefixedText(),
131 - 'revid' => intval( $row->page_latest ),
132 - 'stable_revid' => intval( $row->fp_stable ),
133 - 'pending_since' => wfTimestamp( TS_ISO_8601, $row->fp_pending_since ),
134 - 'flagged_level' => intval( $row->fp_quality ),
 132+ 'pageid' => intval( $row->page_id ),
 133+ 'ns' => intval( $row->page_namespace ),
 134+ 'title' => $title->getPrefixedText(),
 135+ 'revid' => intval( $row->page_latest ),
 136+ 'stable_revid' => intval( $row->fp_stable ),
 137+ 'pending_since' => wfTimestamp( TS_ISO_8601, $row->fp_pending_since ),
 138+ 'flagged_level' => intval( $row->fp_quality ),
135139 'flagged_level_text' => FlaggedRevs::getQualityLevelText( $row->fp_quality ),
136 - 'diff_size' => (int)$row->page_len - (int)$row->rev_len,
137 - 'under_review' => (bool)$wgMemc->get( $key )
 140+ 'diff_size' => (int)$row->page_len - (int)$row->rev_len,
 141+ 'under_review' => $underReview
138142 );
139143 } else {
140144 $resultPageSet->processDbRow( $row );
@@ -158,51 +162,50 @@
159163
160164 public function getAllowedParams() {
161165 $namespaces = FlaggedRevs::getReviewNamespaces();
162 - return array (
163 - 'start' => array (
 166+ return array(
 167+ 'start' => array(
164168 ApiBase::PARAM_TYPE => 'timestamp'
165169 ),
166 - 'end' => array (
 170+ 'end' => array(
167171 ApiBase::PARAM_TYPE => 'timestamp'
168172 ),
169 - 'dir' => array (
 173+ 'dir' => array(
170174 ApiBase::PARAM_DFLT => 'newer',
171175 ApiBase::PARAM_TYPE => array( 'newer', 'older' )
172176 ),
173 - 'maxsize' => array (
 177+ 'maxsize' => array(
174178 ApiBase::PARAM_TYPE => 'integer',
175179 ApiBase::PARAM_DFLT => null,
176180 ApiBase::PARAM_MIN => 0
177181 ),
178 - 'filterwatched' => array (
 182+ 'filterwatched' => array(
179183 ApiBase::PARAM_DFLT => 'all',
180184 ApiBase::PARAM_TYPE => array( 'watched', 'all' )
181185 ),
182 - 'namespace' => array (
183 - ApiBase::PARAM_DFLT => !$namespaces ?
184 - NS_MAIN : $namespaces[0],
 186+ 'namespace' => array(
 187+ ApiBase::PARAM_DFLT => !$namespaces ? NS_MAIN : $namespaces[0],
185188 ApiBase::PARAM_TYPE => 'namespace',
186189 ApiBase::PARAM_ISMULTI => true,
187190 ),
188191 'category' => array(
189192 ApiBase::PARAM_TYPE => 'string'
190193 ),
191 - 'filterredir' => array (
 194+ 'filterredir' => array(
192195 ApiBase::PARAM_DFLT => 'all',
193196 ApiBase::PARAM_TYPE => array( 'redirects', 'nonredirects', 'all' )
194197 ),
195 - 'limit' => array (
 198+ 'limit' => array(
196199 ApiBase::PARAM_DFLT => 10,
197200 ApiBase::PARAM_TYPE => 'limit',
198 - ApiBase::PARAM_MIN => 1,
199 - ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
 201+ ApiBase::PARAM_MIN => 1,
 202+ ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
200203 ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
201204 )
202205 );
203206 }
204207
205208 public function getParamDescription() {
206 - return array (
 209+ return array(
207210 'start' => 'Start listing at this timestamp.',
208211 'end' => 'Stop listing at this timestamp.',
209212 'namespace' => 'The namespaces to enumerate.',
@@ -220,12 +223,9 @@
221224 }
222225
223226 public function getDescription() {
224 - return array(
225 - 'Returns a list of pages, that have an outdated review flag,',
226 - 'sorted by timestamp of the first unreviewed edit of that page.'
227 - );
 227+ return 'Enumerates pages that have changes pending review';
228228 }
229 -
 229+
230230 public function getPossibleErrors() {
231231 return array_merge( parent::getPossibleErrors(), array(
232232 array( 'code' => 'notloggedin', 'info' => 'You must be logged-in to have a watchlist' ),
@@ -233,7 +233,7 @@
234234 }
235235
236236 protected function getExamples() {
237 - return array (
 237+ return array(
238238 'Show a list of pages with pending unreviewed changes',
239239 ' api.php?action=query&list=oldreviewedpages&ornamespace=0',
240240 'Show info about some old reviewed pages',
Index: trunk/extensions/FlaggedRevs/api/ApiQueryReviewedpages.php
@@ -46,12 +46,15 @@
4747 // Construct SQL Query
4848 $this->addTables( array( 'page', 'flaggedpages' ) );
4949 $this->addWhereFld( 'page_namespace', $params['namespace'] );
50 - if ( $params['filterredir'] == 'redirects' )
 50+ if ( $params['filterredir'] == 'redirects' ) {
5151 $this->addWhereFld( 'page_is_redirect', 1 );
52 - if ( $params['filterredir'] == 'nonredirects' )
 52+ }
 53+ if ( $params['filterredir'] == 'nonredirects' ) {
5354 $this->addWhereFld( 'page_is_redirect', 0 );
54 - if ( $params['filterlevel'] !== null )
 55+ }
 56+ if ( $params['filterlevel'] !== null ) {
5557 $this->addWhereFld( 'fp_quality', $params['filterlevel'] );
 58+ }
5659 $this->addWhereRange(
5760 'fp_page_id',
5861 $params['dir'],
@@ -97,11 +100,11 @@
98101 if ( is_null( $resultPageSet ) ) {
99102 $title = Title::newFromRow( $row );
100103 $data[] = array(
101 - 'pageid' => intval( $row->page_id ),
102 - 'ns' => intval( $title->getNamespace() ),
103 - 'title' => $title->getPrefixedText(),
104 - 'revid' => intval( $row->page_latest ),
105 - 'stable_revid' => intval( $row->fp_stable ),
 104+ 'pageid' => intval( $row->page_id ),
 105+ 'ns' => intval( $title->getNamespace() ),
 106+ 'title' => $title->getPrefixedText(),
 107+ 'revid' => intval( $row->page_latest ),
 108+ 'stable_revid' => intval( $row->fp_stable ),
106109 'flagged_level' => intval( $row->fp_quality ),
107110 'flagged_level_text' => FlaggedRevs::getQualityLevelText( $row->fp_quality )
108111 );
@@ -169,13 +172,13 @@
170173
171174 public function getParamDescription() {
172175 return array (
173 - 'start' => 'Start listing at this page id.',
174 - 'end' => 'Stop listing at this page id.',
175 - 'namespace' => 'The namespaces to enumerate.',
176 - 'filterredir' => 'How to filter for redirects',
177 - 'filterlevel' => 'How to filter by quality (0=checked,1=quality)',
178 - 'limit' => 'How many total pages to return.',
179 - 'dir' => array(
 176+ 'start' => 'Start listing at this page id.',
 177+ 'end' => 'Stop listing at this page id.',
 178+ 'namespace' => 'The namespaces to enumerate.',
 179+ 'filterredir' => 'How to filter for redirects',
 180+ 'filterlevel' => 'How to filter by quality (0=checked,1=quality)',
 181+ 'limit' => 'How many total pages to return.',
 182+ 'dir' => array(
180183 'In which direction to list.',
181184 '*newer: list the newest pages first',
182185 '*older: list the oldest pages first'
@@ -184,10 +187,7 @@
185188 }
186189
187190 public function getDescription() {
188 - return array(
189 - 'Returns a list of pages, that have been reviewed,',
190 - 'sorted by page id.'
191 - );
 191+ return 'Enumerates pages that have a reviewed version';
192192 }
193193
194194 protected function getExamples() {
Index: trunk/extensions/FlaggedRevs/api/ApiQueryUnreviewedpages.php
@@ -47,10 +47,13 @@
4848 // Construct SQL Query
4949 $this->addTables( array( 'page', 'flaggedpages' ) );
5050 $this->addWhereFld( 'page_namespace', $params['namespace'] );
51 - if ( $params['filterredir'] == 'redirects' )
 51+ if ( $params['filterredir'] == 'redirects' ) {
5252 $this->addWhereFld( 'page_is_redirect', 1 );
53 - if ( $params['filterredir'] == 'nonredirects' )
 53+ }
 54+ if ( $params['filterredir'] == 'nonredirects' ) {
5455 $this->addWhereFld( 'page_is_redirect', 0 );
 56+ }
 57+
5558 $this->addWhereRange(
5659 'page_title',
5760 'newer',
@@ -95,13 +98,12 @@
9699
97100 if ( is_null( $resultPageSet ) ) {
98101 $title = Title::newFromRow( $row );
99 - $key = wfMemcKey( 'unreviewedPages', 'underReview', $row->page_id );
100102 $data[] = array(
101103 'pageid' => intval( $row->page_id ),
102104 'ns' => intval( $title->getNamespace() ),
103105 'title' => $title->getPrefixedText(),
104106 'revid' => intval( $row->page_latest ),
105 - 'under_review' => (bool)$wgMemc->get( $key )
 107+ 'under_review' => FRUserActivity::pageIsUnderReview( $row->page_id )
106108 );
107109 } else {
108110 $resultPageSet->processDbRow( $row );
@@ -129,8 +131,7 @@
130132 ApiBase::PARAM_TYPE => 'string'
131133 ),
132134 'namespace' => array (
133 - ApiBase::PARAM_DFLT => !$namespaces ?
134 - NS_MAIN : $namespaces[0],
 135+ ApiBase::PARAM_DFLT => !$namespaces ? NS_MAIN : $namespaces[0],
135136 ApiBase::PARAM_TYPE => 'namespace',
136137 ApiBase::PARAM_ISMULTI => true,
137138 ),
@@ -160,20 +161,17 @@
161162
162163 public function getParamDescription() {
163164 return array (
164 - 'start' => 'Start listing at this page title.',
165 - 'end' => 'Stop listing at this page title.',
166 - 'namespace' => 'The namespaces to enumerate.',
167 - 'filterredir' => 'How to filter for redirects',
168 - 'filterlevel' => 'How to filter by quality (0=checked,1=quality)',
169 - 'limit' => 'How many total pages to return.',
 165+ 'start' => 'Start listing at this page title.',
 166+ 'end' => 'Stop listing at this page title.',
 167+ 'namespace' => 'The namespaces to enumerate.',
 168+ 'filterredir' => 'How to filter for redirects',
 169+ 'filterlevel' => 'How to filter by quality (0=checked,1=quality)',
 170+ 'limit' => 'How many total pages to return.',
170171 );
171172 }
172173
173174 public function getDescription() {
174 - return array(
175 - 'Returns a list of pages, that have not been reviewed (to "filterlevel"),',
176 - 'sorted by page title.'
177 - );
 175+ return 'Enumerates pages that have not been reviewed to a given quality level ("filterlevel")';
178176 }
179177
180178 protected function getExamples() {
Index: trunk/extensions/FlaggedRevs/api/ApiStabilize.php
@@ -251,7 +251,7 @@
252252 }
253253
254254 public function getDescription() {
255 - return 'Configure review-protection settings.';
 255+ return 'Configure review-protection settings for a page';
256256 }
257257
258258 // @TODO: fill in stabilize_* values from PageStabilityProtectForm

Status & tagging log