TagLogFormatter.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along
  14. * with this program; if not, write to the Free Software Foundation, Inc.,
  15. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. * http://www.gnu.org/copyleft/gpl.html
  17. */
  18. /**
  19. * This class formats tag log entries.
  20. *
  21. * Parameters (one-based indexes):
  22. * 4::revid
  23. * 5::logid
  24. * 6:list:tagsAdded
  25. * 7:number:tagsAddedCount
  26. * 8:list:tagsRemoved
  27. * 9:number:tagsRemovedCount
  28. *
  29. * @since 1.25
  30. */
  31. class TagLogFormatter extends LogFormatter {
  32. protected function getMessageParameters() {
  33. $params = parent::getMessageParameters();
  34. $isRevLink = !empty( $params[3] );
  35. if ( $isRevLink ) {
  36. $id = $params[3];
  37. $target = $this->entry->getTarget();
  38. $query = [
  39. 'oldid' => $id,
  40. 'diff' => 'prev'
  41. ];
  42. } else {
  43. $id = $params[4];
  44. $target = SpecialPage::getTitleValueFor( 'Log' );
  45. $query = [
  46. 'logid' => $id,
  47. ];
  48. }
  49. $formattedNumber = $this->context->getLanguage()->formatNum( $id, true );
  50. if ( $this->plaintext ) {
  51. $link = $formattedNumber;
  52. } elseif ( !$isRevLink || $target->exists() ) {
  53. $link = $this->getLinkRenderer()->makeKnownLink(
  54. $target, $formattedNumber, [], $query );
  55. } else {
  56. $link = htmlspecialchars( $formattedNumber );
  57. }
  58. if ( $isRevLink ) {
  59. $params[3] = Message::rawParam( $link );
  60. } else {
  61. $params[4] = Message::rawParam( $link );
  62. }
  63. return $params;
  64. }
  65. protected function getMessageKey() {
  66. $key = parent::getMessageKey();
  67. $params = $this->getMessageParameters();
  68. $add = ( isset( $params[6] ) && isset( $params[6]['num'] ) && $params[6]['num'] );
  69. $remove = ( isset( $params[8] ) && isset( $params[8]['num'] ) && $params[8]['num'] );
  70. $key .= ( $remove ? ( $add ? '' : '-remove' ) : '-add' );
  71. if ( isset( $params[3] ) && $params[3] ) {
  72. // Messages: logentry-tag-update-add-revision, logentry-tag-update-remove-revision,
  73. // logentry-tag-update-revision
  74. $key .= '-revision';
  75. } else {
  76. // Messages: logentry-tag-update-add-logentry, logentry-tag-update-remove-logentry,
  77. // logentry-tag-update-logentry
  78. $key .= '-logentry';
  79. }
  80. return $key;
  81. }
  82. }