PatrolLogFormatter.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
  23. * @since 1.22
  24. */
  25. use MediaWiki\MediaWikiServices;
  26. /**
  27. * This class formats patrol log entries.
  28. *
  29. * @since 1.19
  30. */
  31. class PatrolLogFormatter extends LogFormatter {
  32. protected function getMessageKey() {
  33. $params = $this->getMessageParameters();
  34. if ( isset( $params[5] ) && $params[5] ) {
  35. $key = 'logentry-patrol-patrol-auto';
  36. } else {
  37. $key = 'logentry-patrol-patrol';
  38. }
  39. return $key;
  40. }
  41. protected function getMessageParameters() {
  42. $params = parent::getMessageParameters();
  43. $target = $this->entry->getTarget();
  44. $oldid = $params[3];
  45. $revision = $this->context->getLanguage()->formatNum( $oldid, true );
  46. if ( $this->plaintext ) {
  47. $revlink = $revision;
  48. } elseif ( $target->exists() ) {
  49. $query = [
  50. 'oldid' => $oldid,
  51. 'diff' => 'prev'
  52. ];
  53. $revlink = MediaWikiServices::getInstance()->getLinkRenderer()->makeLink(
  54. $target, $revision, [], $query );
  55. } else {
  56. $revlink = htmlspecialchars( $revision );
  57. }
  58. $params[3] = Message::rawParam( $revlink );
  59. return $params;
  60. }
  61. protected function getParametersForApi() {
  62. $entry = $this->entry;
  63. $params = $entry->getParameters();
  64. static $map = [
  65. '4:number:curid',
  66. '5:number:previd',
  67. '6:bool:auto',
  68. '4::curid' => '4:number:curid',
  69. '5::previd' => '5:number:previd',
  70. '6::auto' => '6:bool:auto',
  71. ];
  72. foreach ( $map as $index => $key ) {
  73. if ( isset( $params[$index] ) ) {
  74. $params[$key] = $params[$index];
  75. unset( $params[$index] );
  76. }
  77. }
  78. return $params;
  79. }
  80. }