r58573 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r58572‎ | r58573 | r58574 >
Date:07:40, 5 November 2009
Author:aaron
Status:ok
Tags:
Comment:
* Added class description
* Added setTemplateVersions()/setFileVersions()
* Removed unused mText var
* Fixed doc typo
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedRevision.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedRevision.php
@@ -1,17 +1,28 @@
22 <?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+ */
49 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 */
716 private $mTimestamp;
817 private $mComment;
918 private $mQuality;
1019 private $mTags;
11 - private $mText = null;
1220 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;
1627
1728 /**
1829 * @param Row $row (from database)
@@ -30,8 +41,9 @@
3142 $this->mFileTimestamp = $row->fr_img_timestamp ? $row->fr_img_timestamp : null;
3243 $this->mUser = intval( $row->fr_user );
3344 # 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;
3648 $this->mFlags = isset($row->fr_flags) ? explode(',',$row->fr_flags) : null;
3749 } elseif( is_array($row) ) {
3850 $this->mRevId = intval( $row['fr_rev_id'] );
@@ -293,12 +305,12 @@
294306 * @returns Revision
295307 */
296308 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+ }
303315 return $this->mRevision;
304316 }
305317
@@ -371,36 +383,60 @@
372384 public function userCanSetFlags() {
373385 return RevisionReview::userCanSetFlags( $this->mTags );
374386 }
 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+ }
375395
376396 /**
 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+ /**
377405 * @returns Array template versions (ns -> dbKey -> rev id)
378406 */
379407 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;
387420 }
388 - $templates[$row->ft_namespace][$row->ft_title] = $row->ft_tmp_rev_id;
389421 }
390 - return $templates;
 422+ return $this->mTemplates;
391423 }
392424
393425 /**
394 - * @returns Array template versions (dbKey -> sha1)
 426+ * @returns Array file versions (dbKey -> sha1)
395427 */
396428 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+ }
403439 }
404 - return $files;
 440+ return $this->mFiles;
405441 }
406442
407443 /**

Status & tagging log