Index: trunk/extensions/FlaggedRevs/FlaggedRevision.php |
— | — | @@ -1,17 +1,28 @@ |
2 | 2 | <?php |
3 | | - |
| 3 | +/** |
| 4 | + * Class representing a stable version of a MediaWiki revision |
| 5 | + * |
| 6 | + * This contains a page revision, a file version, and versions |
| 7 | + * of templates and files (to determine template inclusion and thumbnails) |
| 8 | + */ |
4 | 9 | class FlaggedRevision { |
5 | | - private $mTitle = null; |
6 | | - private $mRevId, $mPageId; |
| 10 | + private $mRevision; // base revision |
| 11 | + private $mTemplates; // included template versions |
| 12 | + private $mFiles; // included file versions |
| 13 | + private $mFileSha1; // file version sha-1 (for revisions of File pages) |
| 14 | + private $mFileTimestamp; // file version timestamp (for revisions of File pages) |
| 15 | + /* Flagging metadata */ |
7 | 16 | private $mTimestamp; |
8 | 17 | private $mComment; |
9 | 18 | private $mQuality; |
10 | 19 | private $mTags; |
11 | | - private $mText = null; |
12 | 20 | private $mFlags; |
13 | | - private $mUser; |
14 | | - private $mRevision; |
15 | | - private $mFileName, $mFileSha1, $mFileTimestamp; |
| 21 | + private $mUser; // reviewing user |
| 22 | + private $mFileName; // file name when reviewed |
| 23 | + /* Redundant fields for lazy-loading */ |
| 24 | + private $mTitle; |
| 25 | + private $mPageId; |
| 26 | + private $mRevId; |
16 | 27 | |
17 | 28 | /** |
18 | 29 | * @param Row $row (from database) |
— | — | @@ -30,8 +41,9 @@ |
31 | 42 | $this->mFileTimestamp = $row->fr_img_timestamp ? $row->fr_img_timestamp : null; |
32 | 43 | $this->mUser = intval( $row->fr_user ); |
33 | 44 | # Optional fields |
34 | | - $this->mTitle = isset($row->page_namespace) && isset($row->page_title) ? |
35 | | - Title::makeTitleSafe( $row->page_namespace, $row->page_title ) : null; |
| 45 | + $this->mTitle = isset($row->page_namespace) && isset($row->page_title) |
| 46 | + ? Title::makeTitleSafe( $row->page_namespace, $row->page_title ) |
| 47 | + : null; |
36 | 48 | $this->mFlags = isset($row->fr_flags) ? explode(',',$row->fr_flags) : null; |
37 | 49 | } elseif( is_array($row) ) { |
38 | 50 | $this->mRevId = intval( $row['fr_rev_id'] ); |
— | — | @@ -293,12 +305,12 @@ |
294 | 306 | * @returns Revision |
295 | 307 | */ |
296 | 308 | public function getRevision() { |
297 | | - if( !is_null($this->mRevision) ) |
298 | | - return $this->mRevision; |
299 | | - # Get corresponding revision |
300 | | - $rev = Revision::newFromId( $this->mRevId ); |
301 | | - # Save to cache |
302 | | - $this->mRevision = $rev ? $rev : false; |
| 309 | + if( is_null($this->mRevision) ) { |
| 310 | + # Get corresponding revision |
| 311 | + $rev = Revision::newFromId( $this->mRevId ); |
| 312 | + # Save to cache |
| 313 | + $this->mRevision = $rev ? $rev : false; |
| 314 | + } |
303 | 315 | return $this->mRevision; |
304 | 316 | } |
305 | 317 | |
— | — | @@ -371,36 +383,60 @@ |
372 | 384 | public function userCanSetFlags() { |
373 | 385 | return RevisionReview::userCanSetFlags( $this->mTags ); |
374 | 386 | } |
| 387 | + |
| 388 | + /** |
| 389 | + * Set template versions array |
| 390 | + * @param Array template versions (ns -> dbKey -> rev id) |
| 391 | + */ |
| 392 | + public function setTemplateVersions( $templateVersions ) { |
| 393 | + $this->mTemplates = $templateVersions; |
| 394 | + } |
375 | 395 | |
376 | 396 | /** |
| 397 | + * Set file versions array |
| 398 | + * @param Array file versions (dbKey -> sha1) |
| 399 | + */ |
| 400 | + public function setFileVersions( $fileVersions ) { |
| 401 | + $this->mFiles = $fileVersions; |
| 402 | + } |
| 403 | + |
| 404 | + /** |
377 | 405 | * @returns Array template versions (ns -> dbKey -> rev id) |
378 | 406 | */ |
379 | 407 | public function getTemplateVersions() { |
380 | | - $templates = array(); |
381 | | - $dbr = wfGetDB( DB_SLAVE ); |
382 | | - $res = $dbr->select( 'flaggedtemplates', '*', |
383 | | - array('ft_rev_id' => $this->getRevId()), __METHOD__ ); |
384 | | - while( $row = $res->fetchObject() ) { |
385 | | - if( !isset($templates[$row->ft_namespace]) ) { |
386 | | - $templates[$row->ft_namespace] = array(); |
| 408 | + if( $this->mTemplates == null ) { |
| 409 | + $this->mTemplates = array(); |
| 410 | + $dbr = wfGetDB( DB_SLAVE ); |
| 411 | + $res = $dbr->select( 'flaggedtemplates', '*', |
| 412 | + array( 'ft_rev_id' => $this->getRevId() ), |
| 413 | + __METHOD__ |
| 414 | + ); |
| 415 | + while( $row = $res->fetchObject() ) { |
| 416 | + if( !isset($this->mTemplates[$row->ft_namespace]) ) { |
| 417 | + $this->mTemplates[$row->ft_namespace] = array(); |
| 418 | + } |
| 419 | + $this->mTemplates[$row->ft_namespace][$row->ft_title] = $row->ft_tmp_rev_id; |
387 | 420 | } |
388 | | - $templates[$row->ft_namespace][$row->ft_title] = $row->ft_tmp_rev_id; |
389 | 421 | } |
390 | | - return $templates; |
| 422 | + return $this->mTemplates; |
391 | 423 | } |
392 | 424 | |
393 | 425 | /** |
394 | | - * @returns Array template versions (dbKey -> sha1) |
| 426 | + * @returns Array file versions (dbKey -> sha1) |
395 | 427 | */ |
396 | 428 | public function getFileVersions() { |
397 | | - $files = array(); |
398 | | - $dbr = wfGetDB( DB_SLAVE ); |
399 | | - $res = $dbr->select( 'flaggedimages', '*', |
400 | | - array('fi_rev_id' => $this->getRevId()), __METHOD__ ); |
401 | | - while( $row = $res->fetchObject() ) { |
402 | | - $files[$row->fi_name] = $row->fi_img_sha1; |
| 429 | + if( $this->mFiles == null ) { |
| 430 | + $this->mFiles = array(); |
| 431 | + $dbr = wfGetDB( DB_SLAVE ); |
| 432 | + $res = $dbr->select( 'flaggedimages', '*', |
| 433 | + array( 'fi_rev_id' => $this->getRevId() ), |
| 434 | + __METHOD__ |
| 435 | + ); |
| 436 | + while( $row = $res->fetchObject() ) { |
| 437 | + $this->mFiles[$row->fi_name] = $row->fi_img_sha1; |
| 438 | + } |
403 | 439 | } |
404 | | - return $files; |
| 440 | + return $this->mFiles; |
405 | 441 | } |
406 | 442 | |
407 | 443 | /** |