r97495 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97494‎ | r97495 | r97496 >
Date:14:21, 19 September 2011
Author:nikerabbit
Status:resolved (Comments)
Tags:
Comment:
Converted patrol log to the new system
Modified paths:
  • /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 (modified) (history)
  • /trunk/phase3/includes/logging/LogEntry.php (modified) (history)
  • /trunk/phase3/includes/logging/LogFormatter.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)
  • /trunk/phase3/maintenance/language/messages.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/language/messages.inc
@@ -2556,9 +2556,6 @@
25572557 'patrol-log' => array(
25582558 'patrol-log-page',
25592559 'patrol-log-header',
2560 - 'patrol-log-line',
2561 - 'patrol-log-auto',
2562 - 'patrol-log-diff',
25632560 'log-show-hide-patrol',
25642561 ),
25652562 'imagedeletion' => array(
@@ -3515,6 +3512,8 @@
35163513 'logentry-move-move-noredirect',
35173514 'logentry-move-move_redir',
35183515 'logentry-move-move_redir-noredirect',
 3516+ 'logentry-patrol-patrol',
 3517+ 'logentry-patrol-patrol-auto',
35193518 ),
35203519 );
35213520
Index: trunk/phase3/includes/PatrolLog.php
@@ -5,6 +5,7 @@
66 * logs of patrol events
77 *
88 * @author Rob Church <robchur@gmail.com>
 9+ * @author Niklas Laxström
910 */
1011 class PatrolLog {
1112
@@ -17,64 +18,29 @@
1819 * @return bool
1920 */
2021 public static function record( $rc, $auto = false ) {
21 - if( !( $rc instanceof RecentChange ) ) {
 22+ if ( !$rc instanceof RecentChange ) {
2223 $rc = RecentChange::newFromId( $rc );
23 - if( !is_object( $rc ) )
 24+ if ( !is_object( $rc ) ) {
2425 return false;
 26+ }
2527 }
 28+
2629 $title = Title::makeTitleSafe( $rc->getAttribute( 'rc_namespace' ), $rc->getAttribute( 'rc_title' ) );
27 - if( is_object( $title ) ) {
28 - $params = self::buildParams( $rc, $auto );
29 - $log = new LogPage( 'patrol', false, $auto ? "skipUDP" : "UDP" ); # False suppresses RC entries
30 - $log->addEntry( 'patrol', $title, '', $params );
 30+ if( $title ) {
 31+ $entry = new ManualLogEntry( 'patrol', 'patrol' );
 32+ $entry->setTarget( $title );
 33+ $entry->setParameters( self::buildParams( $rc, $auto ) );
 34+ $entry->setPerformer( User::newFromName( $rc->getAttribute( 'rc_user_text' ) ) );
 35+ $logid = $entry->insert();
 36+ if ( !$auto ) {
 37+ $entry->publish( $logid, 'udp' );
 38+ }
3139 return true;
3240 }
3341 return false;
3442 }
3543
3644 /**
37 - * Generate the log action text corresponding to a patrol log item
38 - *
39 - * @param $title Title of the page that was patrolled
40 - * @param $params Array: log parameters (from logging.log_params)
41 - * @param $lang Language object to use, or false
42 - * @return String
43 - */
44 - public static function makeActionText( $title, $params, $lang ) {
45 - list( $cur, /* $prev */, $auto ) = $params;
46 - if( is_object( $lang ) ) {
47 - # Standard link to the page in question
48 - $link = Linker::link( $title );
49 - if( $title->exists() ) {
50 - # Generate a diff link
51 - $query = array(
52 - 'oldid' => $cur,
53 - 'diff' => 'prev'
54 - );
55 -
56 - $diff = Linker::link(
57 - $title,
58 - htmlspecialchars( wfMsg( 'patrol-log-diff', $lang->formatNum( $cur, true ) ) ),
59 - array(),
60 - $query,
61 - array( 'known', 'noclasses' )
62 - );
63 - } else {
64 - # Don't bother with a diff link, it's useless
65 - $diff = htmlspecialchars( wfMsg( 'patrol-log-diff', $cur ) );
66 - }
67 - # Indicate whether or not the patrolling was automatic
68 - $auto = $auto ? wfMsgHtml( 'patrol-log-auto' ) : '';
69 - # Put it all together
70 - return wfMsgHtml( 'patrol-log-line', $diff, $link, $auto );
71 - } else {
72 - $text = $title->getPrefixedText();
73 - $diff = htmlspecialchars( wfMsgForContent( 'patrol-log-diff', $cur ) );
74 - return wfMsgForContent( 'patrol-log-line', $diff, "[[$text]]", '' );
75 - }
76 - }
77 -
78 - /**
7945 * Prepare log parameters for a patrolled change
8046 *
8147 * @param $change RecentChange to represent
@@ -83,9 +49,10 @@
8450 */
8551 private static function buildParams( $change, $auto ) {
8652 return array(
87 - $change->getAttribute( 'rc_this_oldid' ),
88 - $change->getAttribute( 'rc_last_oldid' ),
89 - (int)$auto
 53+ '4::curid' => $change->getAttribute( 'rc_this_oldid' ),
 54+ '5::previd' => $change->getAttribute( 'rc_last_oldid' ),
 55+ '6::auto' => (int)$auto
9056 );
9157 }
 58+
9259 }
Index: trunk/phase3/includes/logging/LogEntry.php
@@ -312,7 +312,7 @@
313313 protected $performer; ///!< @var User
314314 protected $target; ///!< @var Title
315315 protected $timestamp; ///!< @var string
316 - protected $comment; ///!< @var string
 316+ protected $comment = ''; ///!< @var string
317317 protected $deleted; ///!< @var int
318318
319319 public function __construct( $type, $subtype ) {
Index: trunk/phase3/includes/logging/LogFormatter.php
@@ -417,3 +417,42 @@
418418 }
419419 }
420420 }
 421+
 422+/**
 423+ * This class formats patrol log entries.
 424+ * @since 1.19
 425+ */
 426+class PatrolLogFormatter extends LogFormatter {
 427+ protected function getMessageKey() {
 428+ $key = parent::getMessageKey();
 429+ $params = $this->getMessageParameters();
 430+ if ( isset( $params[5] ) && $params[5] ) {
 431+ $key .= '-auto';
 432+ }
 433+ return $key;
 434+ }
 435+
 436+ protected function getMessageParameters() {
 437+ $params = parent::getMessageParameters();
 438+ $newParams = array_slice( $params, 0, 3 );
 439+
 440+ $target = $this->entry->getTarget();
 441+ $oldid = $params[3];
 442+ $revision = $this->context->getLang()->formatNum( $oldid, true );
 443+
 444+ if ( $this->plaintext ) {
 445+ $revlink = $revision;
 446+ } elseif ( $target->exists() ) {
 447+ $query = array(
 448+ 'oldid' => $oldid,
 449+ 'diff' => 'prev'
 450+ );
 451+ $revlink = Linker::link( $target, htmlspecialchars( $revision ), array(), $query );
 452+ } else {
 453+ $revlink = htmlspecialchars( $revision );
 454+ }
 455+
 456+ $newParams[3] = Message::rawParam( $revlink );
 457+ return $newParams;
 458+ }
 459+}
\ No newline at end of file
Index: trunk/phase3/includes/AutoLoader.php
@@ -547,6 +547,7 @@
548548 'LegacyLogFormatter' => 'includes/logging/LogFormatter.php',
549549 'DeleteLogFormatter' => 'includes/logging/LogFormatter.php',
550550 'MoveLogFormatter' => 'includes/logging/LogFormatter.php',
 551+ 'PatrolLogFormatter' => 'includes/logging/LogFormatter.php',
551552
552553 # includes/media
553554 'BitmapHandler' => 'includes/media/Bitmap.php',
Index: trunk/phase3/includes/DefaultSettings.php
@@ -5063,7 +5063,6 @@
50645064 'merge/merge' => 'pagemerge-logentry',
50655065 'suppress/block' => 'blocklogentry',
50665066 'suppress/reblock' => 'reblock-logentry',
5067 - 'patrol/patrol' => 'patrol-log-line',
50685067 );
50695068
50705069 /**
@@ -5080,6 +5079,7 @@
50815080 'suppress/revision' => 'DeleteLogFormatter',
50825081 'suppress/event' => 'DeleteLogFormatter',
50835082 'suppress/delete' => 'DeleteLogFormatter',
 5083+ 'patrol/patrol' => 'PatrolLogFormatter',
50845084 );
50855085
50865086 /**
Index: trunk/phase3/includes/LogPage.php
@@ -225,11 +225,6 @@
226226
227227 $key = "$type/$action";
228228
229 - # Defer patrol log to PatrolLog class
230 - if( $key == 'patrol/patrol' ) {
231 - return PatrolLog::makeActionText( $title, $params, $langObjOrNull );
232 - }
233 -
234229 if( isset( $wgLogActions[$key] ) ) {
235230 if( is_null( $title ) ) {
236231 $rv = wfMsgExt( $wgLogActions[$key], array( 'parsemag', 'escape', 'language' => $langObj ) );
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -3603,9 +3603,6 @@
36043604 # Patrol log
36053605 'patrol-log-page' => 'Patrol log',
36063606 'patrol-log-header' => 'This is a log of patrolled revisions.',
3607 -'patrol-log-line' => 'marked $1 of $2 patrolled $3',
3608 -'patrol-log-auto' => '(automatic)',
3609 -'patrol-log-diff' => 'revision $1',
36103607 'log-show-hide-patrol' => '$1 patrol log',
36113608
36123609 # Image deletion
@@ -4651,5 +4648,7 @@
46524649 'logentry-move-move-noredirect' => '$1 {{GENDER:$2|moved}} page $3 to $4 without leaving a redirect',
46534650 'logentry-move-move_redir' => '$1 {{GENDER:$2|moved}} page $3 to $4 over redirect',
46544651 'logentry-move-move_redir-noredirect' => '$1 {{GENDER:$2|moved}} page $3 to $4 over a redirect without leaving a redirect',
 4652+'logentry-patrol-patrol' => '$1 {{GENDER:$2|marked}} revision $4 of page $3 patrolled',
 4653+'logentry-patrol-patrol-auto' => '$1 automatically {{GENDER:$2|marked}} revision $4 of page $3 patrolled',
46554654
46564655 );

Follow-up revisions

RevisionCommit summaryAuthorDate
r97601Fixing a bug in r97495 that Aaron catched. I misinterpreted the documentation...nikerabbit08:18, 20 September 2011
r112079* General log formatting fixes, like using the content language, for IRC feed...aaron02:28, 22 February 2012

Comments

#Comment by Aaron Schulz (talk | contribs)   22:22, 19 September 2011

+ $entry->setPerformer( User::newFromName( $rc->getAttribute( 'rc_user_text' ) ) );

You should disable username validation for that call, right?

#Comment by Nikerabbit (talk | contribs)   08:16, 20 September 2011

Yes, I've misunderstood the documentation:

*                - 'valid'      Valid for batch processes

Maybe it could be clarified.

#Comment by Aaron Schulz (talk | contribs)   04:52, 5 November 2011

getPerformer() gets called on each LogEventsListRow, which is a similar performance regression as what happened with BlockList recently.

	public function getPerformer() {
		$userId = (int) $this->row->log_user;
		if ( $userId !== 0 ) {
			return User::newFromRow( $this->row );
		} else {
			$userText = $this->row->log_user_text;
			return User::newFromName( $userText, false );
		}
	}
#Comment by Aaron Schulz (talk | contribs)   05:58, 5 November 2011

Gah, this should be on r96545. Too many tabs open...

Status & tagging log