* (bug 10793) Show patrol links on all eligible diff pages
authorRob Church <robchurch@users.mediawiki.org>
Mon, 6 Aug 2007 03:29:40 +0000 (03:29 +0000)
committerRob Church <robchurch@users.mediawiki.org>
Mon, 6 Aug 2007 03:29:40 +0000 (03:29 +0000)
* Introduce RecentChange::newFromConds() to support the above, and a new index
* Refactored some bits

RELEASE-NOTES
includes/DifferenceEngine.php
includes/RecentChange.php
maintenance/archives/patch-rc_patrol_index.sql [new file with mode: 0644]
maintenance/tables.sql
maintenance/updaters.inc

index b491594..be3fa46 100644 (file)
@@ -164,6 +164,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * Improved handling of permissions errors
 * (bug 10798) Exclude MediaWiki namespace from filtering options on
   Special:Protectedpages (implicit protection, doesn't make sense to have it)
+* (bug 10793) "Mark patrolled" links will now be shown for users with
+  patrol permissions on all eligible diff pages
 
 == Bugfixes since 1.10 ==
 
index 1deabe8..8c8f3d5 100644 (file)
@@ -156,8 +156,39 @@ CONTROL;
                } else {
                        $rollback = '';
                }
-               if( $wgUseRCPatrol && $this->mRcidMarkPatrolled != 0 && $wgUser->isAllowed( 'patrol' ) ) {
-                       $patrol = ' [' . $sk->makeKnownLinkObj( $this->mTitle, wfMsg( 'markaspatrolleddiff' ), "action=markpatrolled&rcid={$this->mRcidMarkPatrolled}" ) . ']';
+               
+               // Prepare a change patrol link, if applicable
+               if( $wgUseRCPatrol && $wgUser->isAllowed( 'patrol' ) ) {
+                       // If we've been given an explicit change identifier, use it; saves time
+                       if( $this->mRcidMarkPatrolled ) {
+                               $rcid = $this->mRcidMarkPatrolled;
+                       } else {
+                               // Look for an unpatrolled change corresponding to this diff
+                               $change = RecentChange::newFromConds(
+                                       array(
+                                               'rc_this_oldid' => $this->mNewid,
+                                               'rc_last_oldid' => $this->mOldid,
+                                               'rc_patrolled' => 0,
+                                       ),
+                                       __METHOD__
+                               );
+                               if( $change instanceof RecentChange ) {
+                                       $rcid = $change->mAttribs['rc_id'];
+                               } else {
+                                       // None found
+                                       $rcid = 0;
+                               }
+                       }
+                       // Build the link
+                       if( $rcid ) {
+                               $patrol = ' [' . $sk->makeKnownLinkObj(
+                                       $this->mTitle,
+                                       wfMsgHtml( 'markaspatrolleddiff' ),
+                                       "action=markpatrolled&rcid={$rcid}"
+                               ) . ']';
+                       } else {
+                               $patrol = '';
+                       }
                } else {
                        $patrol = '';
                }
index a28ee0a..f9673a3 100644 (file)
@@ -80,6 +80,31 @@ class RecentChange
                        return NULL;
                }
        }
+       
+       /**
+        * Find the first recent change matching some specific conditions
+        *
+        * @param array $conds Array of conditions
+        * @param mixed $fname Override the method name in profiling/logs
+        * @return RecentChange
+        */
+       public static function newFromConds( $conds, $fname = false ) {
+               if( $fname === false )
+                       $fname = __METHOD__;
+               $dbr = wfGetDB( DB_SLAVE );
+               $res = $dbr->select(
+                       'recentchanges',
+                       '*',
+                       $conds,
+                       $fname
+               );
+               if( $res instanceof ResultWrapper && $res->numRows() > 0 ) {
+                       $row = $res->fetchObject();
+                       $res->free();
+                       return self::newFromRow( $row );
+               }
+               return null;
+       }
 
        # Accessors
 
@@ -210,19 +235,25 @@ class RecentChange
                wfRunHooks( 'RecentChange_save', array( &$this ) );
        }
 
-       # Marks a certain row as patrolled
-       function markPatrolled( $rcid )
-       {
-               $fname = 'RecentChange::markPatrolled';
-
+       /**
+        * Mark a given change as patrolled
+        *
+        * @param mixed $change RecentChange or corresponding rc_id
+        */
+       public static function markPatrolled( $change ) {
+               $rcid = $change instanceof RecentChange
+                       ? $change->mAttribs['rc_id']
+                       : $change;
                $dbw = wfGetDB( DB_MASTER );
-
-               $dbw->update( 'recentchanges',
-                       array( /* SET */
+               $dbw->update(
+                       'recentchanges',
+                       array(
                                'rc_patrolled' => 1
-                       ), array( /* WHERE */
-                               'rc_id' => $rcid
-                       ), $fname
+                       ),
+                       array(
+                               'rc_id' => $change
+                       ),
+                       __METHOD__
                );
        }
 
diff --git a/maintenance/archives/patch-rc_patrol_index.sql b/maintenance/archives/patch-rc_patrol_index.sql
new file mode 100644 (file)
index 0000000..d706272
--- /dev/null
@@ -0,0 +1,4 @@
+-- Index to speed up locating unpatrolled changes
+-- matching specific edit criteria
+ALTER TABLE /*$wgDBprefix*/recentchanges
+       ADD INDEX `rc_patrolling` ( `rc_this_oldid` , `rc_last_oldid` , `rc_patrolled` );
\ No newline at end of file
index e9d6afb..615d15b 100644 (file)
@@ -880,6 +880,7 @@ CREATE TABLE /*$wgDBprefix*/recentchanges (
   INDEX rc_ip (rc_ip),
   INDEX rc_ns_usertext (rc_namespace, rc_user_text),
   INDEX rc_user_text (rc_user_text, rc_timestamp)
+  INDEX `rc_patrolling` ( `rc_this_oldid`, `rc_last_oldid`, `rc_patrolled` )
 
 ) /*$wgDBTableOptions*/;
 
index 2b04740..10b5e65 100644 (file)
@@ -848,32 +848,28 @@ function do_templatelinks_update() {
        echo "Done. Please run maintenance/refreshLinks.php for a more thorough templatelinks update.\n";
 }
 
-# July 2006
-# Add ( rc_namespace, rc_user_text ) index [R. Church]
+// Add index on ( rc_namespace, rc_user_text ) [Jul. 2006]
+// Add index on ( rc_user_text, rc_timestamp ) [Nov. 2006]
+// Add index on ( rc_this_oldid, rc_last_oldid, rc_patrolled ) [Aug. 2007]
 function do_rc_indices_update() {
        global $wgDatabase;
        echo( "Checking for additional recent changes indices...\n" );
-       # See if we can find the index we want
-       $info = $wgDatabase->indexInfo( 'recentchanges', 'rc_ns_usertext', __METHOD__ );
-       if( !$info ) {
-               # None, so create
-               echo( "...index on ( rc_namespace, rc_user_text ) not found; creating\n" );
-               dbsource( archive( 'patch-recentchanges-utindex.sql' ) );
-       } else {
-               # Index seems to exist
-               echo( "...index on ( rc_namespace, rc_user_text ) seems to be ok\n" );
-       }
 
-       #Add (rc_user_text, rc_timestamp) index [A. Garrett], November 2006
-       # See if we can find the index we want
-       $info = $wgDatabase->indexInfo( 'recentchanges', 'rc_user_text', __METHOD__ );
-       if( !$info ) {
-               # None, so create
-               echo( "...index on ( rc_user_text, rc_timestamp ) not found; creating\n" );
-               dbsource( archive( 'patch-rc_user_text-index.sql' ) );
-       } else {
-               # Index seems to exist
-               echo( "...index on ( rc_user_text, rc_timestamp ) seems to be ok\n" );
+       $indexes = array(
+               'rc_ns_usertext' => 'patch-recentchanges-utindex.sql',
+               'rc_user_text' => 'patch-rc_user_text-index.sql',
+               'rc_patrolling' => 'patch-rc_patrol_index.sql',
+       );
+       
+       foreach( $indexes as $index => $patch ) {
+               $info = $wgDatabase->indexInfo( 'recentchanges', $index, __METHOD__ );
+               if( !$info ) {
+                       echo( "...index `{$index}` not found; adding..." );
+                       dbsource( archive( $patch ) );
+                       echo( "done.\n" );
+               } else {
+                       echo( "...index `{$index}` seems ok.\n" );
+               }
        }
 }