MediaWiki  master
SpecialDeletedContributions.php
Go to the documentation of this file.
1 <?php
30 use Wikimedia\IPUtils;
32 
39  protected $mOpts;
40 
43 
45  private $loadBalancer;
46 
48  private $commentStore;
49 
52 
54  private $namespaceInfo;
55 
57  private $userFactory;
58 
60  private $userNameUtils;
61 
64 
75  public function __construct(
84  ) {
85  parent::__construct( 'DeletedContributions', 'deletedhistory' );
86  $this->permissionManager = $permissionManager;
87  $this->loadBalancer = $loadBalancer;
88  $this->commentStore = $commentStore;
89  $this->revisionFactory = $revisionFactory;
90  $this->namespaceInfo = $namespaceInfo;
91  $this->userFactory = $userFactory;
92  $this->userNameUtils = $userNameUtils;
93  $this->userNamePrefixSearch = $userNamePrefixSearch;
94  }
95 
102  public function execute( $par ) {
103  $this->setHeaders();
104  $this->outputHeader();
105  $this->checkPermissions();
106  $out = $this->getOutput();
107  $out->addModuleStyles( 'mediawiki.interface.helpers.styles' );
108  $this->addHelpLink( 'Help:User contributions' );
109 
110  $opts = new FormOptions();
111 
112  $opts->add( 'target', '' );
113  $opts->add( 'namespace', '' );
114  $opts->add( 'limit', 20 );
115 
116  $opts->fetchValuesFromRequest( $this->getRequest() );
117  $opts->validateIntBounds( 'limit', 0, $this->getConfig()->get( 'QueryPageDefaultLimit' ) );
118 
119  if ( $par !== null ) {
120  // Beautify the username
121  $par = $this->userNameUtils->getCanonical( $par, UserNameUtils::RIGOR_NONE );
122  $opts->setValue( 'target', (string)$par );
123  }
124 
125  $ns = $opts->getValue( 'namespace' );
126  if ( $ns !== null && $ns !== '' ) {
127  $opts->setValue( 'namespace', intval( $ns ) );
128  }
129 
130  $this->mOpts = $opts;
131 
132  $target = trim( $opts->getValue( 'target' ) );
133  if ( !strlen( $target ) ) {
134  $this->getForm();
135 
136  return;
137  }
138 
139  $userObj = $this->userFactory->newFromName( $target, UserFactory::RIGOR_NONE );
140  if ( !$userObj ) {
141  $this->getForm();
142 
143  return;
144  }
145  $this->getSkin()->setRelevantUser( $userObj );
146 
147  $target = $userObj->getName();
148 
149  $out->addSubtitle( $this->getSubTitle( $userObj ) );
150  $out->setPageTitle( $this->msg( 'deletedcontributions-title', $target ) );
151 
152  $this->getForm();
153 
154  $pager = new DeletedContribsPager(
155  $this->getContext(),
156  $target,
157  $opts->getValue( 'namespace' ),
158  $this->getLinkRenderer(),
159  $this->getHookContainer(),
160  $this->loadBalancer,
161  $this->commentStore,
162  $this->revisionFactory
163  );
164  if ( !$pager->getNumRows() ) {
165  $out->addWikiMsg( 'nocontribs' );
166 
167  return;
168  }
169 
170  # Show a message about replica DB lag, if applicable
171  $lag = $pager->getDatabase()->getSessionLagStatus()['lag'];
172  if ( $lag > 0 ) {
173  $out->showLagWarning( $lag );
174  }
175 
176  $out->addHTML(
177  '<p>' . $pager->getNavigationBar() . '</p>' .
178  $pager->getBody() .
179  '<p>' . $pager->getNavigationBar() . '</p>' );
180 
181  # If there were contributions, and it was a valid user or IP, show
182  # the appropriate "footer" message - WHOIS tools, etc.
183  $message = IPUtils::isIPAddress( $target ) ?
184  'sp-contributions-footer-anon' :
185  'sp-contributions-footer';
186 
187  if ( !$this->msg( $message )->isDisabled() ) {
188  $out->wrapWikiMsg(
189  "<div class='mw-contributions-footer'>\n$1\n</div>",
190  [ $message, $target ]
191  );
192  }
193  }
194 
200  private function getSubTitle( $userObj ) {
201  $linkRenderer = $this->getLinkRenderer();
202  if ( $userObj->isAnon() ) {
203  $user = htmlspecialchars( $userObj->getName() );
204  } else {
205  $user = $linkRenderer->makeLink( $userObj->getUserPage(), $userObj->getName() );
206  }
207  $links = '';
208  $nt = $userObj->getUserPage();
209  $talk = $nt->getTalkPage();
210  if ( $talk ) {
212  $this,
213  $userObj,
214  $this->permissionManager,
215  $this->getHookRunner()
216  );
217 
218  $contributionsLink = $linkRenderer->makeKnownLink(
219  SpecialPage::getTitleFor( 'Contributions', $nt->getDBkey() ),
220  $this->msg( 'sp-deletedcontributions-contribs' )->text()
221  );
222  if ( isset( $tools['deletedcontribs'] ) ) {
223  // Swap out the deletedcontribs link for our contribs one
224  $tools = wfArrayInsertAfter(
225  $tools, [ 'contribs' => $contributionsLink ], 'deletedcontribs' );
226  unset( $tools['deletedcontribs'] );
227  } else {
228  $tools['contribs'] = $contributionsLink;
229  }
230 
231  $links = $this->getLanguage()->pipeList( $tools );
232 
233  // Show a note if the user is blocked and display the last block log entry.
234  $block = DatabaseBlock::newFromTarget( $userObj, $userObj );
235  if ( $block !== null && $block->getType() != DatabaseBlock::TYPE_AUTO ) {
236  if ( $block->getType() == DatabaseBlock::TYPE_RANGE ) {
237  $nt = $this->namespaceInfo->getCanonicalName( NS_USER )
238  . ':' . $block->getTargetName();
239  }
240 
241  // LogEventsList::showLogExtract() wants the first parameter by ref
242  $out = $this->getOutput();
244  $out,
245  'block',
246  $nt,
247  '',
248  [
249  'lim' => 1,
250  'showIfEmpty' => false,
251  'msgKey' => [
252  'sp-contributions-blocked-notice',
253  $userObj->getName() # Support GENDER in 'sp-contributions-blocked-notice'
254  ],
255  'offset' => '' # don't use $this->getRequest() parameter offset
256  ]
257  );
258  }
259  }
260 
261  return $this->msg( 'contribsub2' )->rawParams( $user, $links )->params( $userObj->getName() );
262  }
263 
267  private function getForm() {
268  $opts = $this->mOpts;
269 
270  $formDescriptor = [
271  'target' => [
272  'type' => 'user',
273  'name' => 'target',
274  'label-message' => 'sp-contributions-username',
275  'default' => $opts->getValue( 'target' ),
276  'ipallowed' => true,
277  ],
278 
279  'namespace' => [
280  'type' => 'namespaceselect',
281  'name' => 'namespace',
282  'label-message' => 'namespace',
283  'all' => '',
284  ],
285  ];
286 
287  HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() )
288  ->setWrapperLegendMsg( 'sp-contributions-search' )
289  ->setSubmitTextMsg( 'sp-contributions-submit' )
290  // prevent setting subpage and 'target' parameter at the same time
291  ->setAction( $this->getPageTitle()->getLocalURL() )
292  ->setMethod( 'get' )
293  ->prepareForm()
294  ->displayForm( false );
295  }
296 
305  public function prefixSearchSubpages( $search, $limit, $offset ) {
306  $search = $this->userNameUtils->getCanonical( $search );
307  if ( !$search ) {
308  // No prefix suggestion for invalid user
309  return [];
310  }
311  // Autocomplete subpage as user list - public to allow caching
312  return $this->userNamePrefixSearch
313  ->search( UserNamePrefixSearch::AUDIENCE_PUBLIC, $search, $limit, $offset );
314  }
315 
316  protected function getGroupName() {
317  return 'users';
318  }
319 }
SpecialPage\$linkRenderer
LinkRenderer null $linkRenderer
Definition: SpecialPage.php:80
SpecialDeletedContributions\$mOpts
FormOptions $mOpts
Definition: SpecialDeletedContributions.php:39
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:936
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:814
DeletedContribsPager
Definition: DeletedContribsPager.php:34
SpecialDeletedContributions\$permissionManager
PermissionManager $permissionManager
Definition: SpecialDeletedContributions.php:42
SpecialPage\checkPermissions
checkPermissions()
Checks if userCanExecute, and if not throws a PermissionsError.
Definition: SpecialPage.php:382
SpecialDeletedContributions\$userNameUtils
UserNameUtils $userNameUtils
Definition: SpecialDeletedContributions.php:60
CommentStore
Handle database storage of comments such as edit summaries and log reasons.
Definition: CommentStore.php:42
MediaWiki\Revision\RevisionFactory
Service for constructing RevisionRecord objects.
Definition: RevisionFactory.php:37
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:131
SpecialPage\getSkin
getSkin()
Shortcut to get the skin being used for this instance.
Definition: SpecialPage.php:844
SpecialPage\getLanguage
getLanguage()
Shortcut to get user's language.
Definition: SpecialPage.php:854
SpecialDeletedContributions\$loadBalancer
ILoadBalancer $loadBalancer
Definition: SpecialDeletedContributions.php:45
SpecialContributions\getUserLinks
static getUserLinks(SpecialPage $sp, User $target, PermissionManager $permissionManager=null, HookRunner $hookRunner=null)
Links to different places.
Definition: SpecialContributions.php:526
MediaWiki\Block\DatabaseBlock
A DatabaseBlock (unlike a SystemBlock) is stored in the database, may give rise to autoblocks and may...
Definition: DatabaseBlock.php:51
SpecialPage\addHelpLink
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Definition: SpecialPage.php:972
SpecialDeletedContributions\$revisionFactory
RevisionFactory $revisionFactory
Definition: SpecialDeletedContributions.php:51
SpecialPage\getHookRunner
getHookRunner()
Definition: SpecialPage.php:1119
SpecialPage\getConfig
getConfig()
Shortcut to get main config object.
Definition: SpecialPage.php:902
SpecialDeletedContributions\getSubTitle
getSubTitle( $userObj)
Generates the subheading with links.
Definition: SpecialDeletedContributions.php:200
SpecialDeletedContributions\execute
execute( $par)
Special page "deleted user contributions".
Definition: SpecialDeletedContributions.php:102
MediaWiki\User\UserNamePrefixSearch
Handles searching prefixes of user names.
Definition: UserNamePrefixSearch.php:39
SpecialDeletedContributions\$commentStore
CommentStore $commentStore
Definition: SpecialDeletedContributions.php:48
SpecialPage\setHeaders
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
Definition: SpecialPage.php:642
SpecialDeletedContributions\__construct
__construct(PermissionManager $permissionManager, ILoadBalancer $loadBalancer, CommentStore $commentStore, RevisionFactory $revisionFactory, NamespaceInfo $namespaceInfo, UserFactory $userFactory, UserNameUtils $userNameUtils, UserNamePrefixSearch $userNamePrefixSearch)
Definition: SpecialDeletedContributions.php:75
LogEventsList\showLogExtract
static showLogExtract(&$out, $types=[], $page='', $user='', $param=[])
Show log extract.
Definition: LogEventsList.php:597
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:788
SpecialDeletedContributions\$userNamePrefixSearch
UserNamePrefixSearch $userNamePrefixSearch
Definition: SpecialDeletedContributions.php:63
MediaWiki\Permissions\PermissionManager
A service class for checking permissions To obtain an instance, use MediaWikiServices::getInstance()-...
Definition: PermissionManager.php:52
SpecialDeletedContributions\$userFactory
UserFactory $userFactory
Definition: SpecialDeletedContributions.php:57
SpecialDeletedContributions
Implements Special:DeletedContributions to display archived revisions.
Definition: SpecialDeletedContributions.php:37
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:804
NS_USER
const NS_USER
Definition: Defines.php:66
SpecialPage\getLinkRenderer
getLinkRenderer()
Definition: SpecialPage.php:1052
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:267
MediaWiki\User\UserFactory
Creates User objects.
Definition: UserFactory.php:41
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:733
Wikimedia\Rdbms\ILoadBalancer
Database cluster connection, tracking, load balancing, and transaction manager interface.
Definition: ILoadBalancer.php:81
SpecialDeletedContributions\$namespaceInfo
NamespaceInfo $namespaceInfo
Definition: SpecialDeletedContributions.php:54