From: Rob Church Date: Mon, 6 Aug 2007 03:29:40 +0000 (+0000) Subject: * (bug 10793) Show patrol links on all eligible diff pages X-Git-Tag: 1.31.0-rc.0~51868 X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=commitdiff_plain;h=4280f45ccc40de220c7b16812f6a755c736f6099;p=lhc%2Fweb%2Fwiklou.git * (bug 10793) Show patrol links on all eligible diff pages * Introduce RecentChange::newFromConds() to support the above, and a new index * Refactored some bits --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index b491594b08..be3fa46877 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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 == diff --git a/includes/DifferenceEngine.php b/includes/DifferenceEngine.php index 1deabe8810..8c8f3d5990 100644 --- a/includes/DifferenceEngine.php +++ b/includes/DifferenceEngine.php @@ -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 = ''; } diff --git a/includes/RecentChange.php b/includes/RecentChange.php index a28ee0a4f2..f9673a3547 100644 --- a/includes/RecentChange.php +++ b/includes/RecentChange.php @@ -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 index 0000000000..d7062720f4 --- /dev/null +++ b/maintenance/archives/patch-rc_patrol_index.sql @@ -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 diff --git a/maintenance/tables.sql b/maintenance/tables.sql index e9d6afbbdd..615d15b12b 100644 --- a/maintenance/tables.sql +++ b/maintenance/tables.sql @@ -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*/; diff --git a/maintenance/updaters.inc b/maintenance/updaters.inc index 2b04740e65..10b5e65cf8 100644 --- a/maintenance/updaters.inc +++ b/maintenance/updaters.inc @@ -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" ); + } } }