wiki.techinc.nl/includes/PatrolLog.php
Siebrand Mazeland 38ca12aa82 * replace some use of deprecated makeKnownLinkObj() by link() in core
* use array type parameter instead of string to escapeLocalUrl(), getFullURL() and getFullUrl() for readability
* add FIXME in Parser.php and LogEventsList.php where I didn't know how to replace makeKnownLinkObj by link()
* return type for private method Skin::editUrlOptions() changed from string to array
* some code readability improvements

Linking this to r51559 for CodeReview as there is some discussion there, and these changes are very similar.

Todo: core special pages
2009-06-07 15:02:12 +00:00

88 lines
2.5 KiB
PHP

<?php
/**
* Class containing static functions for working with
* logs of patrol events
*
* @author Rob Church <robchur@gmail.com>
*/
class PatrolLog {
/**
* Record a log event for a change being patrolled
*
* @param mixed $change Change identifier or RecentChange object
* @param bool $auto Was this patrol event automatic?
*/
public static function record( $rc, $auto = false ) {
if( !( $rc instanceof RecentChange ) ) {
$rc = RecentChange::newFromId( $rc );
if( !is_object( $rc ) )
return false;
}
$title = Title::makeTitleSafe( $rc->getAttribute( 'rc_namespace' ), $rc->getAttribute( 'rc_title' ) );
if( is_object( $title ) ) {
$params = self::buildParams( $rc, $auto );
$log = new LogPage( 'patrol', false, $auto ? "skipUDP" : "UDP" ); # False suppresses RC entries
$log->addEntry( 'patrol', $title, '', $params );
return true;
}
return false;
}
/**
* Generate the log action text corresponding to a patrol log item
*
* @param Title $title Title of the page that was patrolled
* @param array $params Log parameters (from logging.log_params)
* @param Skin $skin Skin to use for building links, etc.
* @return string
*/
public static function makeActionText( $title, $params, $skin ) {
list( $cur, /* $prev */, $auto ) = $params;
if( is_object( $skin ) ) {
# Standard link to the page in question
$link = $skin->link( $title );
if( $title->exists() ) {
# Generate a diff link
$query = array(
'oldid' => $cur,
'diff' => 'prev'
);
$diff = $skin->link(
$title,
htmlspecialchars( wfMsg( 'patrol-log-diff', $cur ) ),
array(),
$query,
array( 'known', 'noclasses' )
);
} else {
# Don't bother with a diff link, it's useless
$diff = htmlspecialchars( wfMsg( 'patrol-log-diff', $cur ) );
}
# Indicate whether or not the patrolling was automatic
$auto = $auto ? wfMsgHtml( 'patrol-log-auto' ) : '';
# Put it all together
return wfMsgHtml( 'patrol-log-line', $diff, $link, $auto );
} else {
$text = $title->getPrefixedText();
return wfMsgForContent( 'patrol-log-line', wfMsgHtml('patrol-log-diff',$cur), "[[$text]]", '' );
}
}
/**
* Prepare log parameters for a patrolled change
*
* @param RecentChange $change RecentChange to represent
* @param bool $auto Whether the patrol event was automatic
* @return array
*/
private static function buildParams( $change, $auto ) {
return array(
$change->getAttribute( 'rc_this_oldid' ),
$change->getAttribute( 'rc_last_oldid' ),
(int)$auto
);
}
}