Index: trunk/extensions/FlaggedRevs/FlaggedArticle.php |
— | — | @@ -7,10 +7,13 @@ |
8 | 8 | class FlaggedArticle extends Article { |
9 | 9 | /* Process cache variables */ |
10 | 10 | protected $stableRev = null; |
11 | | - protected $pendingRevs = null; |
| 11 | + protected $revsArePending = null; |
| 12 | + protected $pendingRevCount = null; |
12 | 13 | protected $pageConfig = null; |
13 | 14 | protected $imagePage = null; // for file pages |
14 | 15 | |
| 16 | + protected $stabilityDataLoaded = false; |
| 17 | + |
15 | 18 | /** |
16 | 19 | * Get a FlaggedArticle for a given title |
17 | 20 | * @param Title |
— | — | @@ -39,9 +42,12 @@ |
40 | 43 | */ |
41 | 44 | public function clear() { |
42 | 45 | $this->stableRev = null; |
43 | | - $this->pendingRevs = null; |
| 46 | + $this->revsArePending = null; |
| 47 | + $this->pendingRevCount = null; |
44 | 48 | $this->pageConfig = null; |
45 | 49 | $this->imagePage = null; |
| 50 | + |
| 51 | + $this->stabilityDataLoaded = false; |
46 | 52 | parent::clear(); |
47 | 53 | } |
48 | 54 | |
— | — | @@ -81,10 +87,11 @@ |
82 | 88 | * @return bool |
83 | 89 | */ |
84 | 90 | public function isStableShownByDefault( $flags = 0 ) { |
85 | | - if ( !$this->isReviewable( $flags ) ) { |
| 91 | + $this->loadFlaggedRevsData( $flags ); |
| 92 | + if ( !$this->isReviewable() ) { |
86 | 93 | return false; // no stable versions can exist |
87 | 94 | } |
88 | | - $config = $this->getStabilitySettings( $flags ); // page configuration |
| 95 | + $config = $this->getStabilitySettings(); // page configuration |
89 | 96 | return (bool)$config['override']; |
90 | 97 | } |
91 | 98 | |
— | — | @@ -94,10 +101,11 @@ |
95 | 102 | * @return bool |
96 | 103 | */ |
97 | 104 | public function editsRequireReview( $flags = 0 ) { |
| 105 | + $this->loadFlaggedRevsData( $flags ); |
98 | 106 | return ( |
99 | | - $this->isReviewable( $flags ) && // reviewable page |
100 | | - $this->isStableShownByDefault( $flags ) && // and stable versions override |
101 | | - $this->getStableRev( $flags ) // and there is a stable version |
| 107 | + $this->isReviewable() && // reviewable page |
| 108 | + $this->isStableShownByDefault() && // and stable versions override |
| 109 | + $this->getStableRev() // and there is a stable version |
102 | 110 | ); |
103 | 111 | } |
104 | 112 | |
— | — | @@ -107,18 +115,8 @@ |
108 | 116 | * @return bool |
109 | 117 | */ |
110 | 118 | public function revsArePending( $flags = 0 ) { |
111 | | - if ( $this->isReviewable() ) { |
112 | | - $srev = $this->getStableRev( $flags ); |
113 | | - if ( $srev ) { |
114 | | - if ( $flags & FR_MASTER ) { |
115 | | - $latest = $this->getTitle()->getLatestRevID( Title::GAID_FOR_UPDATE ); |
116 | | - } else { |
117 | | - $latest = $this->getLatest(); |
118 | | - } |
119 | | - return ( $srev->getRevId() != $latest ); // edits need review |
120 | | - } |
121 | | - } |
122 | | - return false; // all edits go live |
| 119 | + $this->loadFlaggedRevsData( $flags ); |
| 120 | + return $this->revsArePending; |
123 | 121 | } |
124 | 122 | |
125 | 123 | /** |
— | — | @@ -129,11 +127,11 @@ |
130 | 128 | */ |
131 | 129 | public function getPendingRevCount( $flags = 0 ) { |
132 | 130 | global $wgMemc, $wgParserCacheExpireTime; |
133 | | - # Cached results available? |
134 | | - if ( !( $flags & FR_MASTER ) && $this->pendingRevs !== null ) { |
135 | | - return $this->pendingRevs; |
| 131 | + $this->loadFlaggedRevsData( $flags ); |
| 132 | + if ( !( $flags & FR_MASTER ) && $this->pendingRevCount !== null ) { |
| 133 | + return $this->pendingRevCount; // use process cache |
136 | 134 | } |
137 | | - $srev = $this->getStableRev( $flags ); |
| 135 | + $srev = $this->getStableRev(); |
138 | 136 | if ( !$srev ) { |
139 | 137 | return 0; // none |
140 | 138 | } |
— | — | @@ -166,8 +164,8 @@ |
167 | 165 | $data = FlaggedRevs::makeMemcObj( "{$sRevId}-{$count}" ); |
168 | 166 | $wgMemc->set( $key, $data, $wgParserCacheExpireTime ); |
169 | 167 | } |
170 | | - $this->pendingRevs = $count; |
171 | | - return $this->pendingRevs; |
| 168 | + $this->pendingRevCount = $count; |
| 169 | + return $this->pendingRevCount; |
172 | 170 | } |
173 | 171 | |
174 | 172 | /** |
— | — | @@ -255,12 +253,13 @@ |
256 | 254 | * @return bool |
257 | 255 | */ |
258 | 256 | public function isReviewable( $flags = 0 ) { |
| 257 | + $this->loadFlaggedRevsData( $flags ); |
259 | 258 | if ( !FlaggedRevs::inReviewNamespace( $this->getTitle() ) ) { |
260 | 259 | return false; |
261 | 260 | } |
262 | 261 | # Check if flagging is disabled for this page via config |
263 | 262 | if ( FlaggedRevs::useOnlyIfProtected() ) { |
264 | | - $config = $this->getStabilitySettings( $flags ); // page configuration |
| 263 | + $config = $this->getStabilitySettings(); // page configuration |
265 | 264 | return (bool)$config['override']; // stable is default or flagging disabled |
266 | 265 | } |
267 | 266 | return true; |
— | — | @@ -294,14 +293,8 @@ |
295 | 294 | * @return mixed (FlaggedRevision/null) |
296 | 295 | */ |
297 | 296 | public function getStableRev( $flags = 0 ) { |
298 | | - # Cached results available? |
299 | | - if ( $this->stableRev === null || ( $flags & FR_MASTER ) ) { |
300 | | - $this->loadStableRevAndConfig( $flags ); |
301 | | - } |
302 | | - if ( $this->stableRev ) { |
303 | | - return $this->stableRev; |
304 | | - } |
305 | | - return null; // false => null |
| 297 | + $this->loadFlaggedRevsData( $flags ); |
| 298 | + return $this->stableRev ? $this->stableRev : null; // false => null |
306 | 299 | } |
307 | 300 | |
308 | 301 | /** |
— | — | @@ -310,10 +303,7 @@ |
311 | 304 | * @return array (select,override) |
312 | 305 | */ |
313 | 306 | public function getStabilitySettings( $flags = 0 ) { |
314 | | - if ( !( $flags & FR_MASTER ) && $this->pageConfig !== null ) { |
315 | | - return $this->pageConfig; // use process cache |
316 | | - } |
317 | | - $this->loadStableRevAndConfig( $flags); |
| 307 | + $this->loadFlaggedRevsData( $flags ); |
318 | 308 | return $this->pageConfig; |
319 | 309 | } |
320 | 310 | |
— | — | @@ -322,9 +312,17 @@ |
323 | 313 | * @param Title $title, page title |
324 | 314 | * @param int $flags FR_MASTER |
325 | 315 | */ |
326 | | - protected function loadStableRevAndConfig( $flags = 0 ) { |
| 316 | + protected function loadFlaggedRevsData( $flags = 0 ) { |
| 317 | + if ( $this->stabilityDataLoaded && !( $flags & FR_MASTER ) ) { |
| 318 | + return; // no need to reload everything |
| 319 | + } |
| 320 | + $this->stabilityDataLoaded = true; |
| 321 | + |
| 322 | + $this->pageConfig = FlaggedPageConfig::getDefaultVisibilitySettings(); // default |
327 | 323 | $this->stableRev = false; // false => "found nothing" |
328 | | - $this->pageConfig = FlaggedPageConfig::getDefaultVisibilitySettings(); // default |
| 324 | + $this->revsArePending = false; |
| 325 | + $this->pendingRevCount = null; // defer this one |
| 326 | + |
329 | 327 | if ( !FlaggedRevs::inReviewNamespace( $this->getTitle() ) ) { |
330 | 328 | return; // short-circuit |
331 | 329 | } |
— | — | @@ -333,7 +331,8 @@ |
334 | 332 | wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE ); |
335 | 333 | $row = $db->selectRow( |
336 | 334 | array( 'page', 'flaggedpages', 'flaggedrevs', 'flaggedpage_config' ), |
337 | | - array_merge( FlaggedRevision::selectFields(), FlaggedPageConfig::selectFields() ), |
| 335 | + array_merge( FlaggedRevision::selectFields(), |
| 336 | + FlaggedPageConfig::selectFields(), array( 'fp_pending_since' ) ), |
338 | 337 | array( 'page_id' => $this->getID() ), |
339 | 338 | __METHOD__, |
340 | 339 | array(), |
— | — | @@ -355,5 +354,6 @@ |
356 | 355 | $this->stableRev = new FlaggedRevision( $row ); |
357 | 356 | } |
358 | 357 | } |
| 358 | + $this->revsArePending = ( $row->fp_pending_since !== null ); // revs await review |
359 | 359 | } |
360 | 360 | } |