r85746 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85745‎ | r85746 | r85747 >
Date:06:32, 10 April 2011
Author:aaron
Status:ok
Tags:
Comment:
* Removed some of the duplicated latest revision attribute fields (using mLastRevision instead)
* Added access level (raw/public/user) options to user, text, and comment accessors for latest revision
* Fixed minor related FIXME in FlaggedArticleView
Modified paths:
  • /trunk/extensions/FlaggedRevs/presentation/FlaggedArticleView.php (modified) (history)
  • /trunk/phase3/includes/Article.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Article.php
@@ -17,7 +17,6 @@
1818 /**@{{
1919 * @private
2020 */
21 - var $mComment = ''; // !<
2221 var $mContent; // !<
2322 var $mContentLoaded = false; // !<
2423 var $mCounter = -1; // !< Not loaded
@@ -26,20 +25,18 @@
2726 var $mGoodAdjustment = 0; // !<
2827 var $mIsRedirect = false; // !<
2928 var $mLatest = false; // !<
30 - var $mMinorEdit; // !<
3129 var $mOldId; // !<
3230 var $mPreparedEdit = false; // !< Title object if set
3331 var $mRedirectedFrom = null; // !< Title object if set
3432 var $mRedirectTarget = null; // !< Title object if set
3533 var $mRedirectUrl = false; // !<
3634 var $mRevIdFetched = 0; // !<
37 - var $mRevision = null; // !< Revision object if set
 35+ var $mLastRevision = null; // !< Latest revision if set
 36+ var $mRevision = null; // !< Loaded revision object if set
3837 var $mTimestamp = ''; // !<
3938 var $mTitle; // !< Title object
4039 var $mTotalAdjustment = 0; // !<
4140 var $mTouched = '19700101000000'; // !<
42 - var $mUser = -1; // !< Not loaded
43 - var $mUserText = ''; // !< username from Revision if set
4441 var $mParserOptions; // !< ParserOptions object
4542 var $mParserOutput; // !< ParserCache object if set
4643 /**@}}*/
@@ -223,11 +220,11 @@
224221 $this->mDataLoaded = false;
225222 $this->mContentLoaded = false;
226223
227 - $this->mUser = $this->mCounter = -1; # Not loaded
 224+ $this->mCounter = -1; # Not loaded
228225 $this->mRedirectedFrom = null; # Title object if set
229226 $this->mRedirectTarget = null; # Title object if set
230 - $this->mUserText =
231 - $this->mTimestamp = $this->mComment = '';
 227+ $this->mLastRevision = null; # Latest revision
 228+ $this->mTimestamp = '';
232229 $this->mGoodAdjustment = $this->mTotalAdjustment = 0;
233230 $this->mTouched = '19700101000000';
234231 $this->mForUpdate = false;
@@ -691,8 +688,8 @@
692689 * This isn't necessary for all uses, so it's only done if needed.
693690 */
694691 protected function loadLastEdit() {
695 - if ( -1 != $this->mUser ) {
696 - return;
 692+ if ( $this->mLastRevision !== null ) {
 693+ return; // already loaded
697694 }
698695
699696 # New or non-existent articles have no user information
@@ -702,7 +699,7 @@
703700 }
704701
705702 $revision = Revision::loadFromPageId( wfGetDB( DB_MASTER ), $id );
706 - if ( !is_null( $revision ) ) {
 703+ if ( $revision ) {
707704 $this->setLastEdit( $revision );
708705 }
709706 }
@@ -712,11 +709,7 @@
713710 */
714711 protected function setLastEdit( Revision $revision ) {
715712 $this->mLastRevision = $revision;
716 - $this->mUser = $revision->getUser();
717 - $this->mUserText = $revision->getUserText();
718713 $this->mTimestamp = $revision->getTimestamp();
719 - $this->mComment = $revision->getComment();
720 - $this->mMinorEdit = $revision->isMinor();
721714 }
722715
723716 /**
@@ -727,32 +720,55 @@
728721 if ( !$this->mTimestamp ) {
729722 $this->loadLastEdit();
730723 }
731 -
732724 return wfTimestamp( TS_MW, $this->mTimestamp );
733725 }
734726
735727 /**
 728+ * @param $audience Integer: one of:
 729+ * Revision::FOR_PUBLIC to be displayed to all users
 730+ * Revision::FOR_THIS_USER to be displayed to $wgUser
 731+ * Revision::RAW get the text regardless of permissions
736732 * @return int user ID for the user that made the last article revision
737733 */
738 - public function getUser() {
 734+ public function getUser( $audience = Revision::FOR_PUBLIC ) {
739735 $this->loadLastEdit();
740 - return $this->mUser;
 736+ if ( $this->mLastRevision ) {
 737+ return $this->mLastRevision->getUser( $audience );
 738+ } else {
 739+ return -1;
 740+ }
741741 }
742742
743743 /**
 744+ * @param $audience Integer: one of:
 745+ * Revision::FOR_PUBLIC to be displayed to all users
 746+ * Revision::FOR_THIS_USER to be displayed to $wgUser
 747+ * Revision::RAW get the text regardless of permissions
744748 * @return string username of the user that made the last article revision
745749 */
746 - public function getUserText() {
 750+ public function getUserText( $audience = Revision::FOR_PUBLIC ) {
747751 $this->loadLastEdit();
748 - return $this->mUserText;
 752+ if ( $this->mLastRevision ) {
 753+ return $this->mLastRevision->getUserText( $audience );
 754+ } else {
 755+ return '';
 756+ }
749757 }
750758
751759 /**
 760+ * @param $audience Integer: one of:
 761+ * Revision::FOR_PUBLIC to be displayed to all users
 762+ * Revision::FOR_THIS_USER to be displayed to $wgUser
 763+ * Revision::RAW get the text regardless of permissions
752764 * @return string Comment stored for the last article revision
753765 */
754 - public function getComment() {
 766+ public function getComment( $audience = Revision::FOR_PUBLIC ) {
755767 $this->loadLastEdit();
756 - return $this->mComment;
 768+ if ( $this->mLastRevision ) {
 769+ return $this->mLastRevision->getComment( $audience );
 770+ } else {
 771+ return '';
 772+ }
757773 }
758774
759775 /**
@@ -762,7 +778,11 @@
763779 */
764780 public function getMinorEdit() {
765781 $this->loadLastEdit();
766 - return $this->mMinorEdit;
 782+ if ( $this->mLastRevision ) {
 783+ return $this->mLastRevision->isMinor();
 784+ } else {
 785+ return false;
 786+ }
767787 }
768788
769789 /**
Index: trunk/extensions/FlaggedRevs/presentation/FlaggedArticleView.php
@@ -456,7 +456,7 @@
457457 # Give a "your edit is pending" notice to newer users if
458458 # an unreviewed edit was completed...
459459 if ( $wgRequest->getVal( 'shownotice' )
460 - && $this->article->getUserText() == $wgUser->getName() // FIXME: rawUserText?
 460+ && $this->article->getUserText( Revision::RAW ) == $wgUser->getName()
461461 && $this->article->revsArePending()
462462 && !$wgUser->isAllowed( 'review' ) )
463463 {

Sign-offs

UserFlagDate
Platonidesinspected22:10, 7 June 2011

Status & tagging log