PatrolLog.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * Class containing static functions for working with
  4. * logs of patrol events
  5. *
  6. * @author Rob Church <robchur@gmail.com>
  7. */
  8. class PatrolLog {
  9. /**
  10. * Record a log event for a change being patrolled
  11. *
  12. * @param mixed $change Change identifier or RecentChange object
  13. * @param bool $auto Was this patrol event automatic?
  14. */
  15. public static function record( $rc, $auto = false ) {
  16. if( !( $rc instanceof RecentChange ) ) {
  17. $rc = RecentChange::newFromId( $rc );
  18. if( !is_object( $rc ) )
  19. return false;
  20. }
  21. $title = Title::makeTitleSafe( $rc->getAttribute( 'rc_namespace' ), $rc->getAttribute( 'rc_title' ) );
  22. if( is_object( $title ) ) {
  23. $params = self::buildParams( $rc, $auto );
  24. $log = new LogPage( 'patrol', false, $auto ? "skipUDP" : "UDP" ); # False suppresses RC entries
  25. $log->addEntry( 'patrol', $title, '', $params );
  26. return true;
  27. }
  28. return false;
  29. }
  30. /**
  31. * Generate the log action text corresponding to a patrol log item
  32. *
  33. * @param Title $title Title of the page that was patrolled
  34. * @param array $params Log parameters (from logging.log_params)
  35. * @param Skin $skin Skin to use for building links, etc.
  36. * @return string
  37. */
  38. public static function makeActionText( $title, $params, $skin ) {
  39. list( $cur, /* $prev */, $auto ) = $params;
  40. if( is_object( $skin ) ) {
  41. # Standard link to the page in question
  42. $link = $skin->makeLinkObj( $title );
  43. if( $title->exists() ) {
  44. # Generate a diff link
  45. $bits[] = 'oldid=' . urlencode( $cur );
  46. $bits[] = 'diff=prev';
  47. $bits = implode( '&', $bits );
  48. $diff = $skin->makeKnownLinkObj( $title, htmlspecialchars( wfMsg( 'patrol-log-diff', $cur ) ), $bits );
  49. } else {
  50. # Don't bother with a diff link, it's useless
  51. $diff = htmlspecialchars( wfMsg( 'patrol-log-diff', $cur ) );
  52. }
  53. # Indicate whether or not the patrolling was automatic
  54. $auto = $auto ? wfMsgHtml( 'patrol-log-auto' ) : '';
  55. # Put it all together
  56. return wfMsgHtml( 'patrol-log-line', $diff, $link, $auto );
  57. } else {
  58. $text = $title->getPrefixedText();
  59. return wfMsgForContent( 'patrol-log-line', wfMsgHtml('patrol-log-diff',$cur), "[[$text]]", '' );
  60. }
  61. }
  62. /**
  63. * Prepare log parameters for a patrolled change
  64. *
  65. * @param RecentChange $change RecentChange to represent
  66. * @param bool $auto Whether the patrol event was automatic
  67. * @return array
  68. */
  69. private static function buildParams( $change, $auto ) {
  70. return array(
  71. $change->getAttribute( 'rc_this_oldid' ),
  72. $change->getAttribute( 'rc_last_oldid' ),
  73. (int)$auto
  74. );
  75. }
  76. }