r19341 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r19340‎ | r19341 | r19342 >
Date:17:05, 16 January 2007
Author:robchurch
Status:old
Tags:
Comment:
* (bug 8621) Log revisions marked as patrolled
* Uses normal logging framework, but
** doesn't duplicate the log in recentchanges ;)
** uses a cleaner method to override LogPage::actionText() and do all the formatting
* Introduces PatrolLog::record()
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/LogPage.php (modified) (history)
  • /trunk/phase3/includes/PatrolLog.php (added) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Article.php
@@ -1348,6 +1348,7 @@
13491349 # Mark as patrolled if the user can do so
13501350 if( $wgUser->isAllowed( 'autopatrol' ) ) {
13511351 RecentChange::markPatrolled( $rcid );
 1352+ PatrolLog::record( $rcid, true );
13521353 }
13531354 }
13541355 $wgUser->incEditCount();
@@ -1409,6 +1410,7 @@
14101411 # Mark as patrolled if the user can
14111412 if( $wgUser->isAllowed( 'autopatrol' ) ) {
14121413 RecentChange::markPatrolled( $rcid );
 1414+ PatrolLog::record( $rcid, true );
14131415 }
14141416 }
14151417 $wgUser->incEditCount();
@@ -1514,6 +1516,7 @@
15151517
15161518 # Mark the edit as patrolled
15171519 RecentChange::markPatrolled( $rcid );
 1520+ PatrolLog::record( $rcid );
15181521 wfRunHooks( 'MarkPatrolledComplete', array( &$rcid, &$wgUser, false ) );
15191522
15201523 # Inform the user
Index: trunk/phase3/includes/PatrolLog.php
@@ -0,0 +1,84 @@
 2+<?php
 3+
 4+/**
 5+ * Class containing static functions for working with
 6+ * logs of patrol events
 7+ *
 8+ * @package MediaWiki
 9+ * @author Rob Church <robchur@gmail.com>
 10+ */
 11+class PatrolLog {
 12+
 13+ /**
 14+ * Record a log event for a change being patrolled
 15+ *
 16+ * @param mixed $change Change identifier or RecentChange object
 17+ * @param bool $auto Was this patrol event automatic?
 18+ */
 19+ public static function record( $change, $auto = false ) {
 20+ if( !( is_object( $change ) && $change instanceof RecentChange ) ) {
 21+ $change = RecentChange::newFromId( $change );
 22+ if( !is_object( $change ) )
 23+ return false;
 24+ }
 25+ $title = Title::makeTitleSafe( $change->getAttribute( 'rc_namespace' ),
 26+ $change->getAttribute( 'rc_title' ) );
 27+ if( is_object( $title ) ) {
 28+ $params = self::buildParams( $change, $auto );
 29+ $log = new LogPage( 'patrol', false ); # False suppresses RC entries
 30+ $log->addEntry( 'patrol', $title, '', $params );
 31+ return true;
 32+ } else {
 33+ return false;
 34+ }
 35+ }
 36+
 37+ /**
 38+ * Generate the log action text corresponding to a patrol log item
 39+ *
 40+ * @param Title $title Title of the page that was patrolled
 41+ * @param array $params Log parameters (from logging.log_params)
 42+ * @param Skin $skin Skin to use for building links, etc.
 43+ * @return string
 44+ */
 45+ public static function makeActionText( $title, $params, $skin ) {
 46+ # This is a bit of a hack, but...if $skin is not a Skin, then *do nothing*
 47+ # -- this is fine, because the action text we would be queried for under
 48+ # these conditions would have gone into recentchanges, which we aren't
 49+ # supposed to be updating
 50+ if( is_object( $skin ) ) {
 51+ list( $cur, $prev, $auto ) = $params;
 52+ # Standard link to the page in question
 53+ $link = $skin->makeLinkObj( $title );
 54+ # Generate a diff link
 55+ $bits[] = 'oldid=' . urlencode( $cur );
 56+ $bits[] = 'diff=prev';
 57+ $bits = implode( '&', $bits );
 58+ $diff = $skin->makeLinkObj( $title, htmlspecialchars( wfMsg( 'patrol-log-diff', $cur ) ), $bits );
 59+ # Indicate whether or not the patrolling was automatic
 60+ $auto = $auto ? wfMsgHtml( 'patrol-log-auto' ) : '';
 61+ # Put it all together
 62+ return wfMsgHtml( 'patrol-log-line', $diff, $link, $auto );
 63+ } else {
 64+ return '';
 65+ }
 66+ }
 67+
 68+ /**
 69+ * Prepare log parameters for a patrolled change
 70+ *
 71+ * @param RecentChange $change RecentChange to represent
 72+ * @param bool $auto Whether the patrol event was automatic
 73+ * @return array
 74+ */
 75+ private static function buildParams( $change, $auto ) {
 76+ return array(
 77+ $change->getAttribute( 'rc_this_oldid' ),
 78+ $change->getAttribute( 'rc_last_oldid' ),
 79+ (int)$auto
 80+ );
 81+ }
 82+
 83+}
 84+
 85+?>
\ No newline at end of file
Property changes on: trunk/phase3/includes/PatrolLog.php
___________________________________________________________________
Added: svn:eol-style
186 + native
Index: trunk/phase3/includes/AutoLoader.php
@@ -240,6 +240,7 @@
241241 'UserloginTemplate' => 'includes/templates/Userlogin.php',
242242 'Language' => 'languages/Language.php',
243243 'PasswordResetForm' => 'includes/SpecialResetpass.php',
 244+ 'PatrolLog' => 'includes/PatrolLog.php',
244245
245246 // API classes
246247 'ApiBase' => 'includes/api/ApiBase.php',
Index: trunk/phase3/includes/DefaultSettings.php
@@ -2004,7 +2004,9 @@
20052005 'delete',
20062006 'upload',
20072007 'move',
2008 - 'import' );
 2008+ 'import',
 2009+ 'patrol',
 2010+);
20092011
20102012 /**
20112013 * Lists the message key string for each log type. The localized messages
@@ -2020,7 +2022,9 @@
20212023 'delete' => 'dellogpage',
20222024 'upload' => 'uploadlogpage',
20232025 'move' => 'movelogpage',
2024 - 'import' => 'importlogpage' );
 2026+ 'import' => 'importlogpage',
 2027+ 'patrol' => 'patrol-log-page',
 2028+);
20252029
20262030 /**
20272031 * Lists the message key string for descriptive text to be shown at the
@@ -2036,7 +2040,9 @@
20372041 'delete' => 'dellogpagetext',
20382042 'upload' => 'uploadlogpagetext',
20392043 'move' => 'movelogpagetext',
2040 - 'import' => 'importlogpagetext', );
 2044+ 'import' => 'importlogpagetext',
 2045+ 'patrol' => 'patrol-log-header',
 2046+);
20412047
20422048 /**
20432049 * Lists the message key string for formatting individual events of each
@@ -2058,7 +2064,8 @@
20592065 'move/move' => '1movedto2',
20602066 'move/move_redir' => '1movedto2_redir',
20612067 'import/upload' => 'import-logentry-upload',
2062 - 'import/interwiki' => 'import-logentry-interwiki' );
 2068+ 'import/interwiki' => 'import-logentry-interwiki',
 2069+);
20632070
20642071 /**
20652072 * Experimental preview feature to fetch rendered text
Index: trunk/phase3/includes/LogPage.php
@@ -134,6 +134,10 @@
135135 global $wgLang, $wgContLang, $wgLogActions;
136136
137137 $key = "$type/$action";
 138+
 139+ if( $key == 'patrol/patrol' )
 140+ return PatrolLog::makeActionText( $title, $params, $skin );
 141+
138142 if( isset( $wgLogActions[$key] ) ) {
139143 if( is_null( $title ) ) {
140144 $rv=wfMsg( $wgLogActions[$key] );
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -2236,6 +2236,13 @@
22372237 'markedaspatrollederrortext' => "You need to specify a revision to mark as patrolled.",
22382238 'markedaspatrollederror-noautopatrol' => 'You are not allowed to mark your own changes as patrolled.',
22392239
 2240+# Patrol log
 2241+'patrol-log-page' => 'Patrol log',
 2242+'patrol-log-header' => '',
 2243+'patrol-log-line' => 'marked $1 of $2 patrolled $3',
 2244+'patrol-log-auto' => '(automatic)',
 2245+'patrol-log-diff' => 'r$1',
 2246+
22402247 # image deletion
22412248 'deletedrevision' => 'Deleted old revision $1.',
22422249
Index: trunk/phase3/RELEASE-NOTES
@@ -78,8 +78,8 @@
7979 * Suppress PHP warning about set_time_limit in installer when safe mode is on
8080 * (bug 3000) Fall back to SCRIPT_NAME plus QUERY_STRING when REQUEST_URI is
8181 not available, as on IIS with PHP-CGI
 82+* (bug 8621) Log revisions marked as patrolled
8283
83 -
8484 == Languages updated ==
8585
8686 * Belarusian (be)