r62110 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62109‎ | r62110 | r62111 >
Date:02:05, 8 February 2010
Author:aaron
Status:ok
Tags:
Comment:
* Removed weird 'patrol'/'autopatrol' right behavior
* Removed $titleOnly param from isPatrollable()/isReviewable()
* Don't waste CSS/JS on unreviewable pages
* Refactored autoMarkPatrolled() a bit
* GAID_FOR_UPDATE -> FR_MASTER
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedArticle.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedArticleView.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.class.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedArticle.php
@@ -68,33 +68,24 @@
6969
7070 /**
7171 * Is this article reviewable?
72 - * @param bool $titleOnly, only check if title is in reviewable namespace
 72+ * @returns bool
7373 */
74 - public function isReviewable( $titleOnly = false ) {
 74+ public function isReviewable() {
7575 if ( !FlaggedRevs::inReviewNamespace( $this->getTitle() ) ) {
7676 return false;
77 - } elseif ( !$titleOnly && FlaggedRevs::forDefaultVersionOnly()
78 - && !$this->isStableShownByDefault() )
79 - {
80 - return false;
8177 }
82 - return true;
 78+ return !( FlaggedRevs::forDefaultVersionOnly() && !$this->isStableShownByDefault() );
8379 }
8480
8581 /**
8682 * Is this page in patrolable?
87 - * @param bool $titleOnly, only check if title is in reviewable namespace
8883 * @return bool
8984 */
90 - public function isPatrollable( $titleOnly = false ) {
91 - if ( FlaggedRevs::inPatrolNamespace( $this->getTitle() ) ) {
92 - return true;
93 - } elseif ( !$titleOnly && FlaggedRevs::forDefaultVersionOnly()
94 - && !$this->isStableShownByDefault() )
95 - {
96 - return true;
97 - }
98 - return false;
 85+ public function isPatrollable() {
 86+ if ( !FlaggedRevs::inPatrolNamespace( $this->getTitle() ) ) {
 87+ return false;
 88+ }
 89+ return !$this->isReviewable(); // pages that are reviewable are not patrollable
9990 }
10091
10192 /**
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.class.php
@@ -98,7 +98,7 @@
9999 self::$restrictionLevels = array( '' ) + self::$restrictionLevels;
100100 }
101101 # Make sure no talk namespaces are in review namespace
102 - global $wgFlaggedRevsNamespaces;
 102+ global $wgFlaggedRevsNamespaces, $wgFlaggedRevsPatrolNamespaces;
103103 foreach ( $wgFlaggedRevsNamespaces as $ns ) {
104104 if ( MWNamespace::isTalk( $ns ) ) {
105105 throw new MWException( 'FlaggedRevs given talk namespace in $wgFlaggedRevsNamespaces!' );
@@ -107,11 +107,8 @@
108108 }
109109 }
110110 self::$reviewNamespaces = $wgFlaggedRevsNamespaces;
111 - # Reviewable namespaces override patrolable ones
112 - global $wgFlaggedRevsPatrolNamespaces;
113 - self::$patrolNamespaces = array_diff(
114 - $wgFlaggedRevsPatrolNamespaces, $wgFlaggedRevsNamespaces
115 - );
 111+ # Note: reviewable *pages* override patrollable ones
 112+ self::$patrolNamespaces = $wgFlaggedRevsPatrolNamespaces;
116113
117114 self::$loaded = true;
118115 }
@@ -1107,12 +1104,13 @@
11081105 /**
11091106 * @param int $page_id
11101107 * @param int $rev_id
1111 - * @param $flags, GAID_FOR_UPDATE
 1108+ * @param $flags, FR_MASTER
11121109 * @returns mixed (int or false)
11131110 * Get quality of a revision
11141111 */
11151112 public static function getRevQuality( $page_id, $rev_id, $flags = 0 ) {
1116 - $db = ( $flags & GAID_FOR_UPDATE ) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE );
 1113+ $db = ( $flags & FR_MASTER ) ?
 1114+ wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE );
11171115 return $db->selectField( 'flaggedrevs',
11181116 'fr_quality',
11191117 array( 'fr_page_id' => $page_id, 'fr_rev_id' => $rev_id ),
@@ -1124,7 +1122,7 @@
11251123 /**
11261124 * @param Title $title
11271125 * @param int $rev_id
1128 - * @param $flags, GAID_FOR_UPDATE
 1126+ * @param $flags, FR_MASTER
11291127 * @returns bool
11301128 * Useful for quickly pinging to see if a revision is flagged
11311129 */
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php
@@ -45,7 +45,7 @@
4646 }
4747 $fa = FlaggedArticleView::globalArticleInstance();
4848 # Try to only add to relevant pages
49 - if ( !$fa || !$fa->isReviewable( true ) ) {
 49+ if ( !$fa || !$fa->isReviewable() ) {
5050 return true;
5151 }
5252 global $wgScriptPath, $wgJsMimeType, $wgFlaggedRevsStylePath, $wgFlaggedRevStyleVersion;
@@ -78,7 +78,7 @@
7979 global $wgUser;
8080 $fa = FlaggedArticleView::globalArticleInstance();
8181 # Try to only add to relevant pages
82 - if ( !$fa || !$fa->isReviewable( true ) ) {
 82+ if ( !$fa || !FlaggedRevs::inReviewNamespace( $fa->getTitle() ) ) {
8383 return true;
8484 }
8585 # Get the review tags on this wiki
@@ -773,8 +773,9 @@
774774 }
775775 # Don't let users vandalize pages by moving them...
776776 if ( $action === 'move' ) {
777 - if ( !FlaggedRevs::inReviewNamespace( $title ) || !$title->exists() )
 777+ if ( !FlaggedRevs::inReviewNamespace( $title ) || !$title->exists() ) {
778778 return true;
 779+ }
779780 $flaggedArticle = FlaggedArticle::getTitleInstance( $title );
780781 # If the current shows be default anyway, nothing to do...
781782 if ( !$flaggedArticle->isStableShownByDefault() ) {
@@ -788,28 +789,15 @@
789790 }
790791 # Don't let users patrol pages not in $wgFlaggedRevsPatrolNamespaces
791792 } else if ( $action === 'patrol' || $action === 'autopatrol' ) {
792 - # Pages in reviewable namespace can be patrolled IF reviewing
793 - # is disabled for pages that don't show the stable by default.
794 - # In such cases, we let people with 'review' rights patrol them.
795 - if ( FlaggedRevs::inReviewNamespace( $title ) && !$user->isAllowed( 'review' ) ) {
 793+ $flaggedArticle = FlaggedArticle::getTitleInstance( $title );
 794+ # For a page to be patrollable it must not be reviewable.
 795+ # Note: normally, edits to non-reviewable, non-patrollable, pages are
 796+ # silently marked patrolled automatically. With $wgUseNPPatrol on, the
 797+ # first edit to those pages is left as being unpatrolled.
 798+ if ( $flaggedArticle->isReviewable() ) {
796799 $result = false;
797800 return false;
798801 }
799 - $flaggedArticle = FlaggedArticle::getTitleInstance( $title );
800 - # The page must be in a patrollable namespace ($wgFlaggedRevsPatrolNamespaces)...
801 - if ( !$flaggedArticle->isPatrollable() ) {
802 - global $wgUseNPPatrol;
803 - # ...unless the page is not in a reviewable namespace and
804 - # new page patrol is enabled. In this scenario, any edits
805 - # to pages outside of patrollable namespaces would already
806 - # be auto-patrolled, except for the new page edits.
807 - if ( $wgUseNPPatrol && !$flaggedArticle->isReviewable() ) {
808 - return true;
809 - } else {
810 - $result = false;
811 - return false;
812 - }
813 - }
814802 # Enforce autoreview restrictions
815803 } else if( $action === 'autoreview' ) {
816804 # Get autoreview restriction settings...
@@ -1046,15 +1034,13 @@
10471035 if ( empty( $rc->mAttribs['rc_this_oldid'] ) ) {
10481036 return true;
10491037 }
 1038+ $fa = FlaggedArticle::getTitleInstance( $rc->getTitle() );
10501039 // Is the page reviewable?
1051 - if ( FlaggedRevs::inReviewNamespace( $rc->getTitle() ) ) {
1052 - # Note: pages in reviewable namespace with FR disabled
1053 - # won't autopatrol. May or may not be useful...
1054 - $quality = FlaggedRevs::getRevQuality( $rc->mAttribs['rc_cur_id'],
1055 - $rc->mAttribs['rc_this_oldid'], GAID_FOR_UPDATE );
 1040+ if ( $fa->isReviewable() ) {
 1041+ $revId = $rc->mAttribs['rc_this_oldid'];
 1042+ $quality = FlaggedRevs::getRevQuality( $rc->mAttribs['rc_cur_id'], $revId, FR_MASTER );
10561043 if ( $quality !== false && $quality >= FlaggedRevs::getPatrolLevel() ) {
1057 - RevisionReview::updateRecentChanges( $rc->getTitle(),
1058 - $rc->mAttribs['rc_this_oldid'] );
 1044+ RevisionReview::updateRecentChanges( $rc->getTitle(), $revId );
10591045 $rc->mAttribs['rc_patrolled'] = 1; // make sure irc/email notifs know status
10601046 }
10611047 return true;
@@ -1062,21 +1048,22 @@
10631049 // Is this page in patrollable namespace?
10641050 $patrol = $record = false;
10651051 if ( FlaggedRevs::inPatrolNamespace( $rc->getTitle() ) ) {
1066 - # Bots and users with 'autopatrol' have edits to patrolleable pages
1067 - # marked automatically on edit.
 1052+ # Bots and users with 'autopatrol' have edits to patrollable
 1053+ # pages marked automatically on edit.
10681054 $patrol = $wgUser->isAllowed( 'autopatrol' ) || $wgUser->isAllowed( 'bot' );
1069 - $record = true;
 1055+ $record = true; // record if patrolled
10701056 } else {
10711057 global $wgUseNPPatrol;
1072 - # Mark patrolled by default unless this is a new page and new page patrol
1073 - # is enabled (except when the user has 'autopatrol', then patrol it).
1074 - # This is just to avoid RC clutter for non-patrollable pages.
1075 - if ( $wgUser->isAllowed( 'autopatrol' ) ) {
1076 - $patrol = true;
1077 - # Record patrolled new pages if $wgUseNPPatrol is on
1078 - $record = ( $wgUseNPPatrol && !empty( $rc->mAttribs['rc_new'] ) );
 1058+ // Is this is a new page edit and $wgUseNPPatrol is enabled?
 1059+ if( $wgUseNPPatrol && !empty( $rc->mAttribs['rc_new'] ) ) {
 1060+ # Automatically mark it patrolled if the user can do so
 1061+ $patrol = $wgUser->isAllowed( 'autopatrol' );
 1062+ $record = true;
 1063+ // Otherwise, this edit is not patrollable
10791064 } else {
1080 - $patrol = !( $wgUseNPPatrol && !empty( $rc->mAttribs['rc_new'] ) );
 1065+ # Silently mark it "patrolled" so that it doesn't show up as being unpatrolled
 1066+ $patrol = true;
 1067+ $record = false;
10811068 }
10821069 }
10831070 // Set rc_patrolled flag and add log entry as needed
Index: trunk/extensions/FlaggedRevs/FlaggedArticleView.php
@@ -122,8 +122,8 @@
123123 public function displayTag() {
124124 global $wgOut, $wgRequest;
125125 $this->load();
126 - // Sanity check that this is in reviewable namespace
127 - if ( $this->article->isReviewable( true ) ) {
 126+ // Sanity check that this is a reviewable page
 127+ if ( $this->article->isReviewable() ) {
128128 $wgOut->appendSubtitle( $this->reviewNotice );
129129 }
130130 return true;
@@ -945,7 +945,7 @@
946946 if ( FlaggedRevs::getProtectionLevels() )
947947 return true; // simple custom levels set for action=protect
948948 # Check only if the title is reviewable
949 - if ( !$this->article->isReviewable( true ) ) {
 949+ if ( !FlaggedRevs::inReviewNamespace( $this->article->getTitle() ) ) {
950950 return true;
951951 }
952952 $action = $wgRequest->getVal( 'action', 'view' );

Status & tagging log