NewUsersLogFormatter.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 new user log entries.
  27. *
  28. * @since 1.19
  29. */
  30. class NewUsersLogFormatter extends LogFormatter {
  31. protected function getMessageParameters() {
  32. $params = parent::getMessageParameters();
  33. $subtype = $this->entry->getSubtype();
  34. if ( $subtype === 'create2' || $subtype === 'byemail' ) {
  35. if ( isset( $params[3] ) ) {
  36. $target = User::newFromId( $params[3] );
  37. } else {
  38. $target = User::newFromName( $this->entry->getTarget()->getText(), false );
  39. }
  40. $params[2] = Message::rawParam( $this->makeUserLink( $target ) );
  41. $params[3] = $target->getName();
  42. }
  43. return $params;
  44. }
  45. public function getComment() {
  46. $timestamp = wfTimestamp( TS_MW, $this->entry->getTimestamp() );
  47. if ( $timestamp < '20080129000000' ) {
  48. # Suppress $comment from old entries (before 2008-01-29),
  49. # not needed and can contain incorrect links
  50. return '';
  51. }
  52. return parent::getComment();
  53. }
  54. public function getPreloadTitles() {
  55. $subtype = $this->entry->getSubtype();
  56. if ( $subtype === 'create2' || $subtype === 'byemail' ) {
  57. // add the user talk to LinkBatch for the userLink
  58. return [ Title::makeTitle( NS_USER_TALK, $this->entry->getTarget()->getText() ) ];
  59. }
  60. return [];
  61. }
  62. }