MergeLogFormatter.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * Formatter for merge 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. * @license GPL-2.0-or-later
  22. * @since 1.25
  23. */
  24. use MediaWiki\MediaWikiServices;
  25. /**
  26. * This class formats merge log entries.
  27. *
  28. * @since 1.25
  29. */
  30. class MergeLogFormatter extends LogFormatter {
  31. public function getPreloadTitles() {
  32. $params = $this->extractParameters();
  33. return [ Title::newFromText( $params[3] ) ];
  34. }
  35. protected function getMessageParameters() {
  36. $params = parent::getMessageParameters();
  37. $oldname = $this->makePageLink( $this->entry->getTarget(), [ 'redirect' => 'no' ] );
  38. $newname = $this->makePageLink( Title::newFromText( $params[3] ) );
  39. $params[2] = Message::rawParam( $oldname );
  40. $params[3] = Message::rawParam( $newname );
  41. $params[4] = $this->context->getLanguage()
  42. ->userTimeAndDate( $params[4], $this->context->getUser() );
  43. return $params;
  44. }
  45. public function getActionLinks() {
  46. if ( $this->entry->isDeleted( LogPage::DELETED_ACTION ) // Action is hidden
  47. || !MediaWikiServices::getInstance()
  48. ->getPermissionManager()
  49. ->userHasRight( $this->context->getUser(), 'mergehistory' )
  50. ) {
  51. return '';
  52. }
  53. // Show unmerge link
  54. $params = $this->extractParameters();
  55. $revert = $this->getLinkRenderer()->makeKnownLink(
  56. SpecialPage::getTitleFor( 'MergeHistory' ),
  57. $this->msg( 'revertmerge' )->text(),
  58. [],
  59. [
  60. 'target' => $params[3],
  61. 'dest' => $this->entry->getTarget()->getPrefixedDBkey(),
  62. 'mergepoint' => $params[4],
  63. 'submitted' => 1 // show the revisions immediately
  64. ]
  65. );
  66. return $this->msg( 'parentheses' )->rawParams( $revert )->escaped();
  67. }
  68. protected function getParametersForApi() {
  69. $entry = $this->entry;
  70. $params = $entry->getParameters();
  71. static $map = [
  72. '4:title:dest',
  73. '5:timestamp:mergepoint',
  74. '4::dest' => '4:title:dest',
  75. '5::mergepoint' => '5:timestamp:mergepoint',
  76. ];
  77. foreach ( $map as $index => $key ) {
  78. if ( isset( $params[$index] ) ) {
  79. $params[$key] = $params[$index];
  80. unset( $params[$index] );
  81. }
  82. }
  83. return $params;
  84. }
  85. }