MoveLogFormatter.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. /**
  3. * Formatter for move 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. use MediaWiki\MediaWikiServices;
  26. /**
  27. * This class formats move log entries.
  28. *
  29. * @since 1.19
  30. */
  31. class MoveLogFormatter extends LogFormatter {
  32. public function getPreloadTitles() {
  33. $params = $this->extractParameters();
  34. return [ Title::newFromText( $params[3] ) ];
  35. }
  36. protected function getMessageKey() {
  37. $key = parent::getMessageKey();
  38. $params = $this->extractParameters();
  39. if ( isset( $params[4] ) && $params[4] === '1' ) {
  40. // Messages: logentry-move-move-noredirect, logentry-move-move_redir-noredirect
  41. $key .= '-noredirect';
  42. }
  43. return $key;
  44. }
  45. protected function getMessageParameters() {
  46. $params = parent::getMessageParameters();
  47. $oldname = $this->makePageLink( $this->entry->getTarget(), [ 'redirect' => 'no' ] );
  48. $newname = $this->makePageLink( Title::newFromText( $params[3] ) );
  49. $params[2] = Message::rawParam( $oldname );
  50. $params[3] = Message::rawParam( $newname );
  51. unset( $params[4] ); // handled in getMessageKey
  52. return $params;
  53. }
  54. public function getActionLinks() {
  55. if ( $this->entry->isDeleted( LogPage::DELETED_ACTION ) // Action is hidden
  56. || $this->entry->getSubtype() !== 'move'
  57. || !MediaWikiServices::getInstance()
  58. ->getPermissionManager()
  59. ->userHasRight( $this->context->getUser(), 'move' )
  60. ) {
  61. return '';
  62. }
  63. $params = $this->extractParameters();
  64. $destTitle = Title::newFromText( $params[3] );
  65. if ( !$destTitle ) {
  66. return '';
  67. }
  68. $revert = $this->getLinkRenderer()->makeKnownLink(
  69. SpecialPage::getTitleFor( 'Movepage' ),
  70. $this->msg( 'revertmove' )->text(),
  71. [],
  72. [
  73. 'wpOldTitle' => $destTitle->getPrefixedDBkey(),
  74. 'wpNewTitle' => $this->entry->getTarget()->getPrefixedDBkey(),
  75. 'wpReason' => $this->msg( 'revertmove' )->inContentLanguage()->text(),
  76. 'wpMovetalk' => 0
  77. ]
  78. );
  79. return $this->msg( 'parentheses' )->rawParams( $revert )->escaped();
  80. }
  81. protected function getParametersForApi() {
  82. $entry = $this->entry;
  83. $params = $entry->getParameters();
  84. static $map = [
  85. '4:title:target',
  86. '5:bool:suppressredirect',
  87. '4::target' => '4:title:target',
  88. '5::noredir' => '5:bool:suppressredirect',
  89. ];
  90. foreach ( $map as $index => $key ) {
  91. if ( isset( $params[$index] ) ) {
  92. $params[$key] = $params[$index];
  93. unset( $params[$index] );
  94. }
  95. }
  96. if ( !isset( $params['5:bool:suppressredirect'] ) ) {
  97. $params['5:bool:suppressredirect'] = false;
  98. }
  99. return $params;
  100. }
  101. }