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 
50  private $actorMigration;
51 
54 
56  private $namespaceInfo;
57 
59  private $userNameUtils;
60 
63 
74  public function __construct(
83  ) {
84  parent::__construct( 'DeletedContributions', 'deletedhistory' );
85  $this->permissionManager = $permissionManager;
86  $this->loadBalancer = $loadBalancer;
87  $this->commentStore = $commentStore;
88  $this->actorMigration = $actorMigration;
89  $this->revisionFactory = $revisionFactory;
90  $this->namespaceInfo = $namespaceInfo;
91  $this->userNameUtils = $userNameUtils;
92  $this->userNamePrefixSearch = $userNamePrefixSearch;
93  }
94 
101  public function execute( $par ) {
102  $this->setHeaders();
103  $this->outputHeader();
104  $this->checkPermissions();
105  $this->addHelpLink( 'Help:User contributions' );
106 
107  $opts = new FormOptions();
108 
109  $opts->add( 'target', '' );
110  $opts->add( 'namespace', '' );
111  $opts->add( 'limit', 20 );
112 
113  $opts->fetchValuesFromRequest( $this->getRequest() );
114  $opts->validateIntBounds( 'limit', 0, $this->getConfig()->get( 'QueryPageDefaultLimit' ) );
115 
116  if ( $par !== null ) {
117  // Beautify the username
118  $par = $this->userNameUtils->getCanonical( $par, UserNameUtils::RIGOR_NONE );
119  $opts->setValue( 'target', (string)$par );
120  }
121 
122  $ns = $opts->getValue( 'namespace' );
123  if ( $ns !== null && $ns !== '' ) {
124  $opts->setValue( 'namespace', intval( $ns ) );
125  }
126 
127  $this->mOpts = $opts;
128 
129  $target = trim( $opts->getValue( 'target' ) );
130  if ( !strlen( $target ) ) {
131  $this->getForm();
132 
133  return;
134  }
135 
136  $userObj = User::newFromName( $target, false );
137  if ( !$userObj ) {
138  $this->getForm();
139 
140  return;
141  }
142  $this->getSkin()->setRelevantUser( $userObj );
143 
144  $target = $userObj->getName();
145 
146  $out = $this->getOutput();
147  $out->addSubtitle( $this->getSubTitle( $userObj ) );
148  $out->setHTMLTitle( $this->msg(
149  'pagetitle',
150  $this->msg( 'deletedcontributions-title', $target )->plain()
151  )->inContentLanguage() );
152 
153  $this->getForm();
154 
155  $pager = new DeletedContribsPager(
156  $this->getContext(),
157  $target,
158  $opts->getValue( 'namespace' ),
159  $this->getLinkRenderer(),
160  $this->getHookContainer(),
161  $this->permissionManager,
162  $this->loadBalancer,
163  $this->commentStore,
164  $this->actorMigration,
165  $this->revisionFactory
166  );
167  if ( !$pager->getNumRows() ) {
168  $out->addWikiMsg( 'nocontribs' );
169 
170  return;
171  }
172 
173  # Show a message about replica DB lag, if applicable
174  $lag = $pager->getDatabase()->getSessionLagStatus()['lag'];
175  if ( $lag > 0 ) {
176  $out->showLagWarning( $lag );
177  }
178 
179  $out->addHTML(
180  '<p>' . $pager->getNavigationBar() . '</p>' .
181  $pager->getBody() .
182  '<p>' . $pager->getNavigationBar() . '</p>' );
183 
184  # If there were contributions, and it was a valid user or IP, show
185  # the appropriate "footer" message - WHOIS tools, etc.
186  $message = IPUtils::isIPAddress( $target ) ?
187  'sp-contributions-footer-anon' :
188  'sp-contributions-footer';
189 
190  if ( !$this->msg( $message )->isDisabled() ) {
191  $out->wrapWikiMsg(
192  "<div class='mw-contributions-footer'>\n$1\n</div>",
193  [ $message, $target ]
194  );
195  }
196  }
197 
203  private function getSubTitle( $userObj ) {
204  $linkRenderer = $this->getLinkRenderer();
205  if ( $userObj->isAnon() ) {
206  $user = htmlspecialchars( $userObj->getName() );
207  } else {
208  $user = $linkRenderer->makeLink( $userObj->getUserPage(), $userObj->getName() );
209  }
210  $links = '';
211  $nt = $userObj->getUserPage();
212  $talk = $nt->getTalkPage();
213  if ( $talk ) {
215  $this,
216  $userObj,
217  $this->permissionManager,
218  $this->getHookRunner()
219  );
220 
221  $contributionsLink = $linkRenderer->makeKnownLink(
222  SpecialPage::getTitleFor( 'Contributions', $nt->getDBkey() ),
223  $this->msg( 'sp-deletedcontributions-contribs' )->text()
224  );
225  if ( isset( $tools['deletedcontribs'] ) ) {
226  // Swap out the deletedcontribs link for our contribs one
227  $tools = wfArrayInsertAfter(
228  $tools, [ 'contribs' => $contributionsLink ], 'deletedcontribs' );
229  unset( $tools['deletedcontribs'] );
230  } else {
231  $tools['contribs'] = $contributionsLink;
232  }
233 
234  $links = $this->getLanguage()->pipeList( $tools );
235 
236  // Show a note if the user is blocked and display the last block log entry.
237  $block = DatabaseBlock::newFromTarget( $userObj, $userObj );
238  if ( $block !== null && $block->getType() != DatabaseBlock::TYPE_AUTO ) {
239  if ( $block->getType() == DatabaseBlock::TYPE_RANGE ) {
240  $nt = $this->namespaceInfo->getCanonicalName( NS_USER ) . ':' . $block->getTarget();
241  }
242 
243  // LogEventsList::showLogExtract() wants the first parameter by ref
244  $out = $this->getOutput();
246  $out,
247  'block',
248  $nt,
249  '',
250  [
251  'lim' => 1,
252  'showIfEmpty' => false,
253  'msgKey' => [
254  'sp-contributions-blocked-notice',
255  $userObj->getName() # Support GENDER in 'sp-contributions-blocked-notice'
256  ],
257  'offset' => '' # don't use $this->getRequest() parameter offset
258  ]
259  );
260  }
261  }
262 
263  return $this->msg( 'contribsub2' )->rawParams( $user, $links )->params( $userObj->getName() );
264  }
265 
269  private function getForm() {
270  $opts = $this->mOpts;
271 
272  $formDescriptor = [
273  'target' => [
274  'type' => 'user',
275  'name' => 'target',
276  'label-message' => 'sp-contributions-username',
277  'default' => $opts->getValue( 'target' ),
278  'ipallowed' => true,
279  ],
280 
281  'namespace' => [
282  'type' => 'namespaceselect',
283  'name' => 'namespace',
284  'label-message' => 'namespace',
285  'all' => '',
286  ],
287  ];
288 
289  HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() )
290  ->setWrapperLegendMsg( 'sp-contributions-search' )
291  ->setSubmitTextMsg( 'sp-contributions-submit' )
292  // prevent setting subpage and 'target' parameter at the same time
293  ->setAction( $this->getPageTitle()->getLocalURL() )
294  ->setMethod( 'get' )
295  ->prepareForm()
296  ->displayForm( false );
297  }
298 
307  public function prefixSearchSubpages( $search, $limit, $offset ) {
308  $search = $this->userNameUtils->getCanonical( $search );
309  if ( !$search ) {
310  // No prefix suggestion for invalid user
311  return [];
312  }
313  // Autocomplete subpage as user list - public to allow caching
314  return $this->userNamePrefixSearch
315  ->search( UserNamePrefixSearch::AUDIENCE_PUBLIC, $search, $limit, $offset );
316  }
317 
318  protected function getGroupName() {
319  return 'users';
320  }
321 }
SpecialPage\$linkRenderer
LinkRenderer null $linkRenderer
Definition: SpecialPage.php:79
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:209
SpecialPage\msg
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:900
SpecialDeletedContributions\$actorMigration
ActorMigration $actorMigration
Definition: SpecialDeletedContributions.php:50
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:788
DeletedContribsPager
Definition: DeletedContribsPager.php:35
SpecialDeletedContributions\$permissionManager
PermissionManager $permissionManager
Definition: SpecialDeletedContributions.php:41
SpecialPage\checkPermissions
checkPermissions()
Checks if userCanExecute, and if not throws a PermissionsError.
Definition: SpecialPage.php:356
SpecialDeletedContributions\$userNameUtils
UserNameUtils $userNameUtils
Definition: SpecialDeletedContributions.php:59
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:558
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:106
SpecialPage\getSkin
getSkin()
Shortcut to get the skin being used for this instance.
Definition: SpecialPage.php:808
SpecialPage\getLanguage
getLanguage()
Shortcut to get user's language.
Definition: SpecialPage.php:818
ActorMigration
This class handles the logic for the actor table migration and should always be used in lieu of direc...
Definition: ActorMigration.php:41
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:499
MediaWiki\Block\DatabaseBlock
A DatabaseBlock (unlike a SystemBlock) is stored in the database, may give rise to autoblocks and may...
Definition: DatabaseBlock.php:50
SpecialPage\addHelpLink
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Definition: SpecialPage.php:936
SpecialDeletedContributions\$revisionFactory
RevisionFactory $revisionFactory
Definition: SpecialDeletedContributions.php:53
SpecialPage\getHookRunner
getHookRunner()
Definition: SpecialPage.php:1083
SpecialPage\getConfig
getConfig()
Shortcut to get main config object.
Definition: SpecialPage.php:866
SpecialDeletedContributions\getSubTitle
getSubTitle( $userObj)
Generates the subheading with links.
Definition: SpecialDeletedContributions.php:203
SpecialDeletedContributions\execute
execute( $par)
Special page "deleted user contributions".
Definition: SpecialDeletedContributions.php:101
SpecialDeletedContributions\__construct
__construct(PermissionManager $permissionManager, ILoadBalancer $loadBalancer, CommentStore $commentStore, ActorMigration $actorMigration, RevisionFactory $revisionFactory, NamespaceInfo $namespaceInfo, UserNameUtils $userNameUtils, UserNamePrefixSearch $userNamePrefixSearch)
Definition: SpecialDeletedContributions.php:74
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:616
LogEventsList\showLogExtract
static showLogExtract(&$out, $types=[], $page='', $user='', $param=[])
Show log extract.
Definition: LogEventsList.php:612
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:762
SpecialDeletedContributions\$userNamePrefixSearch
UserNamePrefixSearch $userNamePrefixSearch
Definition: SpecialDeletedContributions.php:62
MediaWiki\Permissions\PermissionManager
A service class for checking permissions To obtain an instance, use MediaWikiServices::getInstance()-...
Definition: PermissionManager.php:51
SpecialDeletedContributions
Implements Special:DeletedContributions to display archived revisions.
Definition: SpecialDeletedContributions.php:36
SpecialPage
Parent class for all special pages.
Definition: SpecialPage.php:42
SpecialPage\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition: SpecialPage.php:778
NS_USER
const NS_USER
Definition: Defines.php:65
SpecialPage\getLinkRenderer
getLinkRenderer()
Definition: SpecialPage.php:1016
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:269
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:707
Wikimedia\Rdbms\ILoadBalancer
Database cluster connection, tracking, load balancing, and transaction manager interface.
Definition: ILoadBalancer.php:81
SpecialDeletedContributions\$namespaceInfo
NamespaceInfo $namespaceInfo
Definition: SpecialDeletedContributions.php:56