MediaWiki  master
SpecialDeletedContributions.php
Go to the documentation of this file.
1 <?php
29 use Wikimedia\IPUtils;
31 
38  protected $mOpts;
39 
42 
44  private $loadBalancer;
45 
47  private $commentStore;
48 
51 
53  private $namespaceInfo;
54 
56  private $userNameUtils;
57 
60 
70  public function __construct(
78  ) {
79  parent::__construct( 'DeletedContributions', 'deletedhistory' );
80  $this->permissionManager = $permissionManager;
81  $this->loadBalancer = $loadBalancer;
82  $this->commentStore = $commentStore;
83  $this->revisionFactory = $revisionFactory;
84  $this->namespaceInfo = $namespaceInfo;
85  $this->userNameUtils = $userNameUtils;
86  $this->userNamePrefixSearch = $userNamePrefixSearch;
87  }
88 
95  public function execute( $par ) {
96  $this->setHeaders();
97  $this->outputHeader();
98  $this->checkPermissions();
99  $this->addHelpLink( 'Help:User contributions' );
100 
101  $opts = new FormOptions();
102 
103  $opts->add( 'target', '' );
104  $opts->add( 'namespace', '' );
105  $opts->add( 'limit', 20 );
106 
107  $opts->fetchValuesFromRequest( $this->getRequest() );
108  $opts->validateIntBounds( 'limit', 0, $this->getConfig()->get( 'QueryPageDefaultLimit' ) );
109 
110  if ( $par !== null ) {
111  // Beautify the username
112  $par = $this->userNameUtils->getCanonical( $par, UserNameUtils::RIGOR_NONE );
113  $opts->setValue( 'target', (string)$par );
114  }
115 
116  $ns = $opts->getValue( 'namespace' );
117  if ( $ns !== null && $ns !== '' ) {
118  $opts->setValue( 'namespace', intval( $ns ) );
119  }
120 
121  $this->mOpts = $opts;
122 
123  $target = trim( $opts->getValue( 'target' ) );
124  if ( !strlen( $target ) ) {
125  $this->getForm();
126 
127  return;
128  }
129 
130  $userObj = User::newFromName( $target, false );
131  if ( !$userObj ) {
132  $this->getForm();
133 
134  return;
135  }
136  $this->getSkin()->setRelevantUser( $userObj );
137 
138  $target = $userObj->getName();
139 
140  $out = $this->getOutput();
141  $out->addSubtitle( $this->getSubTitle( $userObj ) );
142  $out->setPageTitle( $this->msg( 'deletedcontributions-title', $target ) );
143 
144  $this->getForm();
145 
146  $pager = new DeletedContribsPager(
147  $this->getContext(),
148  $target,
149  $opts->getValue( 'namespace' ),
150  $this->getLinkRenderer(),
151  $this->getHookContainer(),
152  $this->loadBalancer,
153  $this->commentStore,
154  $this->revisionFactory
155  );
156  if ( !$pager->getNumRows() ) {
157  $out->addWikiMsg( 'nocontribs' );
158 
159  return;
160  }
161 
162  # Show a message about replica DB lag, if applicable
163  $lag = $pager->getDatabase()->getSessionLagStatus()['lag'];
164  if ( $lag > 0 ) {
165  $out->showLagWarning( $lag );
166  }
167 
168  $out->addHTML(
169  '<p>' . $pager->getNavigationBar() . '</p>' .
170  $pager->getBody() .
171  '<p>' . $pager->getNavigationBar() . '</p>' );
172 
173  # If there were contributions, and it was a valid user or IP, show
174  # the appropriate "footer" message - WHOIS tools, etc.
175  $message = IPUtils::isIPAddress( $target ) ?
176  'sp-contributions-footer-anon' :
177  'sp-contributions-footer';
178 
179  if ( !$this->msg( $message )->isDisabled() ) {
180  $out->wrapWikiMsg(
181  "<div class='mw-contributions-footer'>\n$1\n</div>",
182  [ $message, $target ]
183  );
184  }
185  }
186 
192  private function getSubTitle( $userObj ) {
193  $linkRenderer = $this->getLinkRenderer();
194  if ( $userObj->isAnon() ) {
195  $user = htmlspecialchars( $userObj->getName() );
196  } else {
197  $user = $linkRenderer->makeLink( $userObj->getUserPage(), $userObj->getName() );
198  }
199  $links = '';
200  $nt = $userObj->getUserPage();
201  $talk = $nt->getTalkPage();
202  if ( $talk ) {
204  $this,
205  $userObj,
206  $this->permissionManager,
207  $this->getHookRunner()
208  );
209 
210  $contributionsLink = $linkRenderer->makeKnownLink(
211  SpecialPage::getTitleFor( 'Contributions', $nt->getDBkey() ),
212  $this->msg( 'sp-deletedcontributions-contribs' )->text()
213  );
214  if ( isset( $tools['deletedcontribs'] ) ) {
215  // Swap out the deletedcontribs link for our contribs one
216  $tools = wfArrayInsertAfter(
217  $tools, [ 'contribs' => $contributionsLink ], 'deletedcontribs' );
218  unset( $tools['deletedcontribs'] );
219  } else {
220  $tools['contribs'] = $contributionsLink;
221  }
222 
223  $links = $this->getLanguage()->pipeList( $tools );
224 
225  // Show a note if the user is blocked and display the last block log entry.
226  $block = DatabaseBlock::newFromTarget( $userObj, $userObj );
227  if ( $block !== null && $block->getType() != DatabaseBlock::TYPE_AUTO ) {
228  if ( $block->getType() == DatabaseBlock::TYPE_RANGE ) {
229  $nt = $this->namespaceInfo->getCanonicalName( NS_USER )
230  . ':' . $block->getTargetName();
231  }
232 
233  // LogEventsList::showLogExtract() wants the first parameter by ref
234  $out = $this->getOutput();
236  $out,
237  'block',
238  $nt,
239  '',
240  [
241  'lim' => 1,
242  'showIfEmpty' => false,
243  'msgKey' => [
244  'sp-contributions-blocked-notice',
245  $userObj->getName() # Support GENDER in 'sp-contributions-blocked-notice'
246  ],
247  'offset' => '' # don't use $this->getRequest() parameter offset
248  ]
249  );
250  }
251  }
252 
253  return $this->msg( 'contribsub2' )->rawParams( $user, $links )->params( $userObj->getName() );
254  }
255 
259  private function getForm() {
260  $opts = $this->mOpts;
261 
262  $formDescriptor = [
263  'target' => [
264  'type' => 'user',
265  'name' => 'target',
266  'label-message' => 'sp-contributions-username',
267  'default' => $opts->getValue( 'target' ),
268  'ipallowed' => true,
269  ],
270 
271  'namespace' => [
272  'type' => 'namespaceselect',
273  'name' => 'namespace',
274  'label-message' => 'namespace',
275  'all' => '',
276  ],
277  ];
278 
279  HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() )
280  ->setWrapperLegendMsg( 'sp-contributions-search' )
281  ->setSubmitTextMsg( 'sp-contributions-submit' )
282  // prevent setting subpage and 'target' parameter at the same time
283  ->setAction( $this->getPageTitle()->getLocalURL() )
284  ->setMethod( 'get' )
285  ->prepareForm()
286  ->displayForm( false );
287  }
288 
297  public function prefixSearchSubpages( $search, $limit, $offset ) {
298  $search = $this->userNameUtils->getCanonical( $search );
299  if ( !$search ) {
300  // No prefix suggestion for invalid user
301  return [];
302  }
303  // Autocomplete subpage as user list - public to allow caching
304  return $this->userNamePrefixSearch
305  ->search( UserNamePrefixSearch::AUDIENCE_PUBLIC, $search, $limit, $offset );
306  }
307 
308  protected function getGroupName() {
309  return 'users';
310  }
311 }
SpecialPage\$linkRenderer
LinkRenderer null $linkRenderer
Definition: SpecialPage.php:80
SpecialDeletedContributions\$mOpts
FormOptions $mOpts
Definition: SpecialDeletedContributions.php:38
wfArrayInsertAfter
wfArrayInsertAfter(array $array, array $insert, $after)
Insert array into another array after the specified KEY
Definition: GlobalFunctions.php:189
SpecialPage\msg
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:911
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:789
SpecialDeletedContributions\__construct
__construct(PermissionManager $permissionManager, ILoadBalancer $loadBalancer, CommentStore $commentStore, RevisionFactory $revisionFactory, NamespaceInfo $namespaceInfo, UserNameUtils $userNameUtils, UserNamePrefixSearch $userNamePrefixSearch)
Definition: SpecialDeletedContributions.php:70
DeletedContribsPager
Definition: DeletedContribsPager.php:34
SpecialDeletedContributions\$permissionManager
PermissionManager $permissionManager
Definition: SpecialDeletedContributions.php:41
SpecialPage\checkPermissions
checkPermissions()
Checks if userCanExecute, and if not throws a PermissionsError.
Definition: SpecialPage.php:357
SpecialDeletedContributions\$userNameUtils
UserNameUtils $userNameUtils
Definition: SpecialDeletedContributions.php:56
CommentStore
Handle database storage of comments such as edit summaries and log reasons.
Definition: CommentStore.php:42
User\newFromName
static newFromName( $name, $validate='valid')
Definition: User.php:592
MediaWiki\Revision\RevisionFactory
Service for constructing revision objects.
Definition: RevisionFactory.php:38
SpecialPage\getTitleFor
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
Definition: SpecialPage.php:107
SpecialPage\getSkin
getSkin()
Shortcut to get the skin being used for this instance.
Definition: SpecialPage.php:819
SpecialPage\getLanguage
getLanguage()
Shortcut to get user's language.
Definition: SpecialPage.php:829
SpecialDeletedContributions\$loadBalancer
ILoadBalancer $loadBalancer
Definition: SpecialDeletedContributions.php:44
SpecialContributions\getUserLinks
static getUserLinks(SpecialPage $sp, User $target, PermissionManager $permissionManager=null, HookRunner $hookRunner=null)
Links to different places.
Definition: SpecialContributions.php:504
MediaWiki\Block\DatabaseBlock
A DatabaseBlock (unlike a SystemBlock) is stored in the database, may give rise to autoblocks and may...
Definition: DatabaseBlock.php:52
SpecialPage\addHelpLink
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Definition: SpecialPage.php:947
SpecialDeletedContributions\$revisionFactory
RevisionFactory $revisionFactory
Definition: SpecialDeletedContributions.php:50
SpecialPage\getHookRunner
getHookRunner()
Definition: SpecialPage.php:1094
SpecialPage\getConfig
getConfig()
Shortcut to get main config object.
Definition: SpecialPage.php:877
SpecialDeletedContributions\getSubTitle
getSubTitle( $userObj)
Generates the subheading with links.
Definition: SpecialDeletedContributions.php:192
SpecialDeletedContributions\execute
execute( $par)
Special page "deleted user contributions".
Definition: SpecialDeletedContributions.php:95
MediaWiki\User\UserNamePrefixSearch
Handles searching prefixes of user names.
Definition: UserNamePrefixSearch.php:39
SpecialDeletedContributions\$commentStore
CommentStore $commentStore
Definition: SpecialDeletedContributions.php:47
SpecialPage\setHeaders
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
Definition: SpecialPage.php:617
LogEventsList\showLogExtract
static showLogExtract(&$out, $types=[], $page='', $user='', $param=[])
Show log extract.
Definition: LogEventsList.php:607
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:763
SpecialDeletedContributions\$userNamePrefixSearch
UserNamePrefixSearch $userNamePrefixSearch
Definition: SpecialDeletedContributions.php:59
MediaWiki\Permissions\PermissionManager
A service class for checking permissions To obtain an instance, use MediaWikiServices::getInstance()-...
Definition: PermissionManager.php:52
SpecialDeletedContributions
Implements Special:DeletedContributions to display archived revisions.
Definition: SpecialDeletedContributions.php:36
SpecialPage
Parent class for all special pages.
Definition: SpecialPage.php:43
SpecialPage\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition: SpecialPage.php:779
NS_USER
const NS_USER
Definition: Defines.php:66
SpecialPage\getLinkRenderer
getLinkRenderer()
Definition: SpecialPage.php:1027
MediaWiki\User\UserNameUtils
UserNameUtils service.
Definition: UserNameUtils.php:42
NamespaceInfo
This is a utility class for dealing with namespaces that encodes all the "magic" behaviors of them ba...
Definition: NamespaceInfo.php:35
FormOptions
Helper class to keep track of options when mixing links and form elements.
Definition: FormOptions.php:35
SpecialDeletedContributions\getForm
getForm()
Generates the namespace selector form with hidden attributes.
Definition: SpecialDeletedContributions.php:259
SpecialPage\outputHeader
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
Definition: SpecialPage.php:708
Wikimedia\Rdbms\ILoadBalancer
Database cluster connection, tracking, load balancing, and transaction manager interface.
Definition: ILoadBalancer.php:81
SpecialDeletedContributions\$namespaceInfo
NamespaceInfo $namespaceInfo
Definition: SpecialDeletedContributions.php:53