PatrolLogFormatter.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * Formatter for new user log entries.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. * http://www.gnu.org/copyleft/gpl.html
  19. *
  20. * @file
  21. * @author Niklas Laxström
  22. * @license GPL-2.0-or-later
  23. * @since 1.22
  24. */
  25. /**
  26. * This class formats patrol log entries.
  27. *
  28. * @since 1.19
  29. */
  30. class PatrolLogFormatter extends LogFormatter {
  31. protected function getMessageKey() {
  32. $params = $this->getMessageParameters();
  33. if ( isset( $params[5] ) && $params[5] ) {
  34. $key = 'logentry-patrol-patrol-auto';
  35. } else {
  36. $key = 'logentry-patrol-patrol';
  37. }
  38. return $key;
  39. }
  40. protected function getMessageParameters() {
  41. $params = parent::getMessageParameters();
  42. $target = $this->entry->getTarget();
  43. $oldid = $params[3];
  44. $revision = $this->context->getLanguage()->formatNum( $oldid, true );
  45. if ( $this->plaintext ) {
  46. $revlink = $revision;
  47. } elseif ( $target->exists() ) {
  48. $query = [
  49. 'oldid' => $oldid,
  50. 'diff' => 'prev'
  51. ];
  52. $revlink = $this->getLinkRenderer()->makeLink( $target, $revision, [], $query );
  53. } else {
  54. $revlink = htmlspecialchars( $revision );
  55. }
  56. $params[3] = Message::rawParam( $revlink );
  57. return $params;
  58. }
  59. protected function getParametersForApi() {
  60. $entry = $this->entry;
  61. $params = $entry->getParameters();
  62. static $map = [
  63. '4:number:curid',
  64. '5:number:previd',
  65. '6:bool:auto',
  66. '4::curid' => '4:number:curid',
  67. '5::previd' => '5:number:previd',
  68. '6::auto' => '6:bool:auto',
  69. ];
  70. foreach ( $map as $index => $key ) {
  71. if ( isset( $params[$index] ) ) {
  72. $params[$key] = $params[$index];
  73. unset( $params[$index] );
  74. }
  75. }
  76. return $params;
  77. }
  78. }