SpecialContributions.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  1. <?php
  2. /**
  3. * Implements Special:Contributions
  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. * @ingroup SpecialPage
  22. */
  23. use MediaWiki\Block\DatabaseBlock;
  24. use MediaWiki\MediaWikiServices;
  25. /**
  26. * Special:Contributions, show user contributions in a paged list
  27. *
  28. * @ingroup SpecialPage
  29. */
  30. class SpecialContributions extends IncludableSpecialPage {
  31. protected $opts;
  32. public function __construct() {
  33. parent::__construct( 'Contributions' );
  34. }
  35. public function execute( $par ) {
  36. $this->setHeaders();
  37. $this->outputHeader();
  38. $out = $this->getOutput();
  39. // Modules required for viewing the list of contributions (also when included on other pages)
  40. $out->addModuleStyles( [
  41. 'jquery.makeCollapsible.styles',
  42. 'mediawiki.interface.helpers.styles',
  43. 'mediawiki.special',
  44. 'mediawiki.special.changeslist',
  45. ] );
  46. $out->addModules( [
  47. 'mediawiki.special.recentchanges',
  48. // Certain skins e.g. Minerva might have disabled this module.
  49. 'mediawiki.page.ready'
  50. ] );
  51. $this->addHelpLink( 'Help:User contributions' );
  52. $this->opts = [];
  53. $request = $this->getRequest();
  54. $target = $par ?? $request->getVal( 'target' );
  55. $this->opts['deletedOnly'] = $request->getBool( 'deletedOnly' );
  56. if ( !strlen( $target ) ) {
  57. if ( !$this->including() ) {
  58. $out->addHTML( $this->getForm( $this->opts ) );
  59. }
  60. return;
  61. }
  62. $user = $this->getUser();
  63. $this->opts['limit'] = $request->getInt( 'limit', $user->getOption( 'rclimit' ) );
  64. $this->opts['target'] = $target;
  65. $this->opts['topOnly'] = $request->getBool( 'topOnly' );
  66. $this->opts['newOnly'] = $request->getBool( 'newOnly' );
  67. $this->opts['hideMinor'] = $request->getBool( 'hideMinor' );
  68. $id = 0;
  69. if ( ExternalUserNames::isExternal( $target ) ) {
  70. $userObj = User::newFromName( $target, false );
  71. if ( !$userObj ) {
  72. $out->addHTML( $this->getForm( $this->opts ) );
  73. return;
  74. }
  75. $out->addSubtitle( $this->contributionsSub( $userObj ) );
  76. $out->setHTMLTitle( $this->msg(
  77. 'pagetitle',
  78. $this->msg( 'contributions-title', $target )->plain()
  79. )->inContentLanguage() );
  80. } else {
  81. $nt = Title::makeTitleSafe( NS_USER, $target );
  82. if ( !$nt ) {
  83. $out->addHTML( $this->getForm( $this->opts ) );
  84. return;
  85. }
  86. $userObj = User::newFromName( $nt->getText(), false );
  87. if ( !$userObj ) {
  88. $out->addHTML( $this->getForm( $this->opts ) );
  89. return;
  90. }
  91. $id = $userObj->getId();
  92. $target = $nt->getText();
  93. $out->addSubtitle( $this->contributionsSub( $userObj ) );
  94. $out->setHTMLTitle( $this->msg(
  95. 'pagetitle',
  96. $this->msg( 'contributions-title', $target )->plain()
  97. )->inContentLanguage() );
  98. # For IP ranges, we want the contributionsSub, but not the skin-dependent
  99. # links under 'Tools', which may include irrelevant links like 'Logs'.
  100. if ( !IP::isValidRange( $target ) ) {
  101. $this->getSkin()->setRelevantUser( $userObj );
  102. }
  103. }
  104. $ns = $request->getVal( 'namespace', null );
  105. if ( $ns !== null && $ns !== '' && $ns !== 'all' ) {
  106. $this->opts['namespace'] = intval( $ns );
  107. } else {
  108. $this->opts['namespace'] = '';
  109. }
  110. // Backwards compatibility: Before using OOUI form the old HTML form had
  111. // fields for nsInvert and associated. These have now been replaced with the
  112. // wpFilters query string parameters. These are retained to keep old URIs working.
  113. $this->opts['associated'] = $request->getBool( 'associated' );
  114. $this->opts['nsInvert'] = (bool)$request->getVal( 'nsInvert' );
  115. $nsFilters = $request->getArray( 'wpfilters', null );
  116. if ( $nsFilters !== null ) {
  117. $this->opts['associated'] = in_array( 'associated', $nsFilters );
  118. $this->opts['nsInvert'] = in_array( 'nsInvert', $nsFilters );
  119. }
  120. $this->opts['tagfilter'] = (string)$request->getVal( 'tagfilter' );
  121. // Allows reverts to have the bot flag in recent changes. It is just here to
  122. // be passed in the form at the top of the page
  123. if ( MediaWikiServices::getInstance()
  124. ->getPermissionManager()
  125. ->userHasRight( $user, 'markbotedits' ) && $request->getBool( 'bot' )
  126. ) {
  127. $this->opts['bot'] = '1';
  128. }
  129. $skip = $request->getText( 'offset' ) || $request->getText( 'dir' ) == 'prev';
  130. # Offset overrides year/month selection
  131. if ( !$skip ) {
  132. $this->opts['year'] = $request->getVal( 'year' );
  133. $this->opts['month'] = $request->getVal( 'month' );
  134. $this->opts['start'] = $request->getVal( 'start' );
  135. $this->opts['end'] = $request->getVal( 'end' );
  136. }
  137. $this->opts = ContribsPager::processDateFilter( $this->opts );
  138. if ( $this->opts['namespace'] < NS_MAIN ) {
  139. $this->getOutput()->wrapWikiMsg(
  140. "<div class=\"mw-negative-namespace-not-supported error\">\n\$1\n</div>",
  141. [ 'negative-namespace-not-supported' ]
  142. );
  143. $out->addHTML( $this->getForm( $this->opts ) );
  144. return;
  145. }
  146. $feedType = $request->getVal( 'feed' );
  147. $feedParams = [
  148. 'action' => 'feedcontributions',
  149. 'user' => $target,
  150. ];
  151. if ( $this->opts['topOnly'] ) {
  152. $feedParams['toponly'] = true;
  153. }
  154. if ( $this->opts['newOnly'] ) {
  155. $feedParams['newonly'] = true;
  156. }
  157. if ( $this->opts['hideMinor'] ) {
  158. $feedParams['hideminor'] = true;
  159. }
  160. if ( $this->opts['deletedOnly'] ) {
  161. $feedParams['deletedonly'] = true;
  162. }
  163. if ( $this->opts['tagfilter'] !== '' ) {
  164. $feedParams['tagfilter'] = $this->opts['tagfilter'];
  165. }
  166. if ( $this->opts['namespace'] !== '' ) {
  167. $feedParams['namespace'] = $this->opts['namespace'];
  168. }
  169. // Don't use year and month for the feed URL, but pass them on if
  170. // we redirect to API (if $feedType is specified)
  171. if ( $feedType && $this->opts['year'] !== null ) {
  172. $feedParams['year'] = $this->opts['year'];
  173. }
  174. if ( $feedType && $this->opts['month'] !== null ) {
  175. $feedParams['month'] = $this->opts['month'];
  176. }
  177. if ( $feedType ) {
  178. // Maintain some level of backwards compatibility
  179. // If people request feeds using the old parameters, redirect to API
  180. $feedParams['feedformat'] = $feedType;
  181. $url = wfAppendQuery( wfScript( 'api' ), $feedParams );
  182. $out->redirect( $url, '301' );
  183. return;
  184. }
  185. // Add RSS/atom links
  186. $this->addFeedLinks( $feedParams );
  187. if ( Hooks::run( 'SpecialContributionsBeforeMainOutput', [ $id, $userObj, $this ] ) ) {
  188. $pager = new ContribsPager( $this->getContext(), [
  189. 'target' => $target,
  190. 'namespace' => $this->opts['namespace'],
  191. 'tagfilter' => $this->opts['tagfilter'],
  192. 'start' => $this->opts['start'],
  193. 'end' => $this->opts['end'],
  194. 'deletedOnly' => $this->opts['deletedOnly'],
  195. 'topOnly' => $this->opts['topOnly'],
  196. 'newOnly' => $this->opts['newOnly'],
  197. 'hideMinor' => $this->opts['hideMinor'],
  198. 'nsInvert' => $this->opts['nsInvert'],
  199. 'associated' => $this->opts['associated'],
  200. ], $this->getLinkRenderer() );
  201. if ( !$this->including() ) {
  202. $out->addHTML( $this->getForm( $this->opts ) );
  203. }
  204. if ( IP::isValidRange( $target ) && !$pager->isQueryableRange( $target ) ) {
  205. // Valid range, but outside CIDR limit.
  206. $limits = $this->getConfig()->get( 'RangeContributionsCIDRLimit' );
  207. $limit = $limits[ IP::isIPv4( $target ) ? 'IPv4' : 'IPv6' ];
  208. $out->addWikiMsg( 'sp-contributions-outofrange', $limit );
  209. } elseif ( !$pager->getNumRows() ) {
  210. $out->addWikiMsg( 'nocontribs', $target );
  211. } else {
  212. # Show a message about replica DB lag, if applicable
  213. $lag = $pager->getDatabase()->getSessionLagStatus()['lag'];
  214. if ( $lag > 0 ) {
  215. $out->showLagWarning( $lag );
  216. }
  217. $output = $pager->getBody();
  218. if ( !$this->including() ) {
  219. $output = $pager->getNavigationBar() .
  220. $output .
  221. $pager->getNavigationBar();
  222. }
  223. $out->addHTML( $output );
  224. }
  225. $out->preventClickjacking( $pager->getPreventClickjacking() );
  226. # Show the appropriate "footer" message - WHOIS tools, etc.
  227. if ( IP::isValidRange( $target ) ) {
  228. $message = 'sp-contributions-footer-anon-range';
  229. } elseif ( IP::isIPAddress( $target ) ) {
  230. $message = 'sp-contributions-footer-anon';
  231. } elseif ( $userObj->isAnon() ) {
  232. // No message for non-existing users
  233. $message = '';
  234. } else {
  235. $message = 'sp-contributions-footer';
  236. }
  237. if ( $message && !$this->including() && !$this->msg( $message, $target )->isDisabled() ) {
  238. $out->wrapWikiMsg(
  239. "<div class='mw-contributions-footer'>\n$1\n</div>",
  240. [ $message, $target ] );
  241. }
  242. }
  243. }
  244. /**
  245. * Generates the subheading with links
  246. * @param User $userObj User object for the target
  247. * @return string Appropriately-escaped HTML to be output literally
  248. * @todo FIXME: Almost the same as getSubTitle in SpecialDeletedContributions.php.
  249. * Could be combined.
  250. */
  251. protected function contributionsSub( $userObj ) {
  252. if ( $userObj->isAnon() ) {
  253. // Show a warning message that the user being searched for doesn't exist.
  254. // User::isIP returns true for IP address and usemod IPs like '123.123.123.xxx',
  255. // but returns false for IP ranges. We don't want to suggest either of these are
  256. // valid usernames which we would with the 'contributions-userdoesnotexist' message.
  257. if ( !User::isIP( $userObj->getName() ) && !$userObj->isIPRange() ) {
  258. $this->getOutput()->wrapWikiMsg(
  259. "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
  260. [
  261. 'contributions-userdoesnotexist',
  262. wfEscapeWikiText( $userObj->getName() ),
  263. ]
  264. );
  265. if ( !$this->including() ) {
  266. $this->getOutput()->setStatusCode( 404 );
  267. }
  268. }
  269. $user = htmlspecialchars( $userObj->getName() );
  270. } else {
  271. $user = $this->getLinkRenderer()->makeLink( $userObj->getUserPage(), $userObj->getName() );
  272. }
  273. $nt = $userObj->getUserPage();
  274. $talk = $userObj->getTalkPage();
  275. $links = '';
  276. if ( $talk ) {
  277. $tools = self::getUserLinks( $this, $userObj );
  278. $links = Html::openElement( 'span', [ 'class' => 'mw-changeslist-links' ] );
  279. foreach ( $tools as $tool ) {
  280. $links .= Html::rawElement( 'span', [], $tool ) . ' ';
  281. }
  282. $links = trim( $links ) . Html::closeElement( 'span' );
  283. // Show a note if the user is blocked and display the last block log entry.
  284. // Do not expose the autoblocks, since that may lead to a leak of accounts' IPs,
  285. // and also this will display a totally irrelevant log entry as a current block.
  286. if ( !$this->including() ) {
  287. // For IP ranges you must give DatabaseBlock::newFromTarget the CIDR string
  288. // and not a user object.
  289. if ( $userObj->isIPRange() ) {
  290. $block = DatabaseBlock::newFromTarget( $userObj->getName(), $userObj->getName() );
  291. } else {
  292. $block = DatabaseBlock::newFromTarget( $userObj, $userObj );
  293. }
  294. if ( !is_null( $block ) && $block->getType() != DatabaseBlock::TYPE_AUTO ) {
  295. if ( $block->getType() == DatabaseBlock::TYPE_RANGE ) {
  296. $nt = MediaWikiServices::getInstance()->getNamespaceInfo()->
  297. getCanonicalName( NS_USER ) . ':' . $block->getTarget();
  298. }
  299. $out = $this->getOutput(); // showLogExtract() wants first parameter by reference
  300. LogEventsList::showLogExtract(
  301. $out,
  302. 'block',
  303. $nt,
  304. '',
  305. [
  306. 'lim' => 1,
  307. 'showIfEmpty' => false,
  308. 'msgKey' => [
  309. $userObj->isAnon() ?
  310. 'sp-contributions-blocked-notice-anon' :
  311. 'sp-contributions-blocked-notice',
  312. $userObj->getName() # Support GENDER in 'sp-contributions-blocked-notice'
  313. ],
  314. 'offset' => '' # don't use WebRequest parameter offset
  315. ]
  316. );
  317. }
  318. }
  319. }
  320. return Html::rawElement( 'div', [ 'class' => 'mw-contributions-user-tools' ],
  321. $this->msg( 'contributions-subtitle' )->rawParams( $user )->params( $userObj->getName() )
  322. . ' ' . $links
  323. );
  324. }
  325. /**
  326. * Links to different places.
  327. *
  328. * @note This function is also called in DeletedContributionsPage
  329. * @param SpecialPage $sp SpecialPage instance, for context
  330. * @param User $target Target user object
  331. * @return array
  332. */
  333. public static function getUserLinks( SpecialPage $sp, User $target ) {
  334. $id = $target->getId();
  335. $username = $target->getName();
  336. $userpage = $target->getUserPage();
  337. $talkpage = $target->getTalkPage();
  338. $isIP = IP::isValid( $username );
  339. $isRange = IP::isValidRange( $username );
  340. $linkRenderer = $sp->getLinkRenderer();
  341. $tools = [];
  342. # No talk pages for IP ranges.
  343. if ( !$isRange ) {
  344. $tools['user-talk'] = $linkRenderer->makeLink(
  345. $talkpage,
  346. $sp->msg( 'sp-contributions-talk' )->text()
  347. );
  348. }
  349. # Block / Change block / Unblock links
  350. $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
  351. if ( $permissionManager->userHasRight( $sp->getUser(), 'block' ) ) {
  352. if ( $target->getBlock() && $target->getBlock()->getType() != DatabaseBlock::TYPE_AUTO ) {
  353. $tools['block'] = $linkRenderer->makeKnownLink( # Change block link
  354. SpecialPage::getTitleFor( 'Block', $username ),
  355. $sp->msg( 'change-blocklink' )->text()
  356. );
  357. $tools['unblock'] = $linkRenderer->makeKnownLink( # Unblock link
  358. SpecialPage::getTitleFor( 'Unblock', $username ),
  359. $sp->msg( 'unblocklink' )->text()
  360. );
  361. } else { # User is not blocked
  362. $tools['block'] = $linkRenderer->makeKnownLink( # Block link
  363. SpecialPage::getTitleFor( 'Block', $username ),
  364. $sp->msg( 'blocklink' )->text()
  365. );
  366. }
  367. }
  368. # Block log link
  369. $tools['log-block'] = $linkRenderer->makeKnownLink(
  370. SpecialPage::getTitleFor( 'Log', 'block' ),
  371. $sp->msg( 'sp-contributions-blocklog' )->text(),
  372. [],
  373. [ 'page' => $userpage->getPrefixedText() ]
  374. );
  375. # Suppression log link (T61120)
  376. if ( $permissionManager->userHasRight( $sp->getUser(), 'suppressionlog' ) ) {
  377. $tools['log-suppression'] = $linkRenderer->makeKnownLink(
  378. SpecialPage::getTitleFor( 'Log', 'suppress' ),
  379. $sp->msg( 'sp-contributions-suppresslog', $username )->text(),
  380. [],
  381. [ 'offender' => $username ]
  382. );
  383. }
  384. # Don't show some links for IP ranges
  385. if ( !$isRange ) {
  386. # Uploads: hide if IPs cannot upload (T220674)
  387. if ( !$isIP || $permissionManager->userHasRight( $target, 'upload' ) ) {
  388. $tools['uploads'] = $linkRenderer->makeKnownLink(
  389. SpecialPage::getTitleFor( 'Listfiles', $username ),
  390. $sp->msg( 'sp-contributions-uploads' )->text()
  391. );
  392. }
  393. # Other logs link
  394. # Todo: T146628
  395. $tools['logs'] = $linkRenderer->makeKnownLink(
  396. SpecialPage::getTitleFor( 'Log', $username ),
  397. $sp->msg( 'sp-contributions-logs' )->text()
  398. );
  399. # Add link to deleted user contributions for priviledged users
  400. # Todo: T183457
  401. if ( $permissionManager->userHasRight( $sp->getUser(), 'deletedhistory' ) ) {
  402. $tools['deletedcontribs'] = $linkRenderer->makeKnownLink(
  403. SpecialPage::getTitleFor( 'DeletedContributions', $username ),
  404. $sp->msg( 'sp-contributions-deleted', $username )->text()
  405. );
  406. }
  407. }
  408. # Add a link to change user rights for privileged users
  409. $userrightsPage = new UserrightsPage();
  410. $userrightsPage->setContext( $sp->getContext() );
  411. if ( $userrightsPage->userCanChangeRights( $target ) ) {
  412. $tools['userrights'] = $linkRenderer->makeKnownLink(
  413. SpecialPage::getTitleFor( 'Userrights', $username ),
  414. $sp->msg( 'sp-contributions-userrights', $username )->text()
  415. );
  416. }
  417. Hooks::run( 'ContributionsToolLinks', [ $id, $userpage, &$tools, $sp ] );
  418. return $tools;
  419. }
  420. /**
  421. * Generates the namespace selector form with hidden attributes.
  422. * @param array $pagerOptions with keys contribs, user, deletedOnly, limit, target, topOnly,
  423. * newOnly, hideMinor, namespace, associated, nsInvert, tagfilter, year, start, end
  424. * @return string HTML fragment
  425. */
  426. protected function getForm( array $pagerOptions ) {
  427. $this->opts['title'] = $this->getPageTitle()->getPrefixedText();
  428. // Modules required only for the form
  429. $this->getOutput()->addModules( [
  430. 'mediawiki.userSuggest',
  431. 'mediawiki.special.contributions',
  432. ] );
  433. $this->getOutput()->addModuleStyles( 'mediawiki.widgets.DateInputWidget.styles' );
  434. $this->getOutput()->enableOOUI();
  435. $fields = [];
  436. # Add hidden params for tracking except for parameters in $skipParameters
  437. $skipParameters = [
  438. 'namespace',
  439. 'nsInvert',
  440. 'deletedOnly',
  441. 'target',
  442. 'year',
  443. 'month',
  444. 'start',
  445. 'end',
  446. 'topOnly',
  447. 'newOnly',
  448. 'hideMinor',
  449. 'associated',
  450. 'tagfilter'
  451. ];
  452. foreach ( $this->opts as $name => $value ) {
  453. if ( in_array( $name, $skipParameters ) ) {
  454. continue;
  455. }
  456. $fields[$name] = [
  457. 'name' => $name,
  458. 'type' => 'hidden',
  459. 'default' => $value,
  460. ];
  461. }
  462. $target = $this->opts['target'] ?? null;
  463. $fields['target'] = [
  464. 'type' => 'text',
  465. 'cssclass' => 'mw-autocomplete-user mw-ui-input-inline mw-input',
  466. 'default' => $target ?
  467. str_replace( '_', ' ', $target ) : '' ,
  468. 'label' => $this->msg( 'sp-contributions-username' )->text(),
  469. 'name' => 'target',
  470. 'id' => 'mw-target-user-or-ip',
  471. 'size' => 40,
  472. 'autofocus' => !$target,
  473. 'section' => 'contribs-top',
  474. ];
  475. $ns = $this->opts['namespace'] ?? null;
  476. $fields['namespace'] = [
  477. 'type' => 'namespaceselect',
  478. 'label' => $this->msg( 'namespace' )->text(),
  479. 'name' => 'namespace',
  480. 'cssclass' => 'namespaceselector',
  481. 'default' => $ns,
  482. 'id' => 'namespace',
  483. 'section' => 'contribs-top',
  484. ];
  485. $request = $this->getRequest();
  486. $nsFilters = $request->getArray( 'wpfilters' );
  487. $fields['nsFilters'] = [
  488. 'class' => 'HTMLMultiSelectField',
  489. 'label' => '',
  490. 'name' => 'wpfilters',
  491. 'flatlist' => true,
  492. // Only shown when namespaces are selected.
  493. 'cssclass' => $ns === '' ?
  494. 'contribs-ns-filters mw-input-with-label mw-input-hidden' :
  495. 'contribs-ns-filters mw-input-with-label',
  496. // `contribs-ns-filters` class allows these fields to be toggled on/off by JavaScript.
  497. // See resources/src/mediawiki.special.recentchanges.js
  498. 'infusable' => true,
  499. 'options' => [
  500. $this->msg( 'invert' )->text() => 'nsInvert',
  501. $this->msg( 'namespace_association' )->text() => 'associated',
  502. ],
  503. 'default' => $nsFilters,
  504. 'section' => 'contribs-top',
  505. ];
  506. $fields['tagfilter'] = [
  507. 'type' => 'tagfilter',
  508. 'cssclass' => 'mw-tagfilter-input',
  509. 'id' => 'tagfilter',
  510. 'label-message' => [ 'tag-filter', 'parse' ],
  511. 'name' => 'tagfilter',
  512. 'size' => 20,
  513. 'section' => 'contribs-top',
  514. ];
  515. if ( MediaWikiServices::getInstance()
  516. ->getPermissionManager()
  517. ->userHasRight( $this->getUser(), 'deletedhistory' )
  518. ) {
  519. $fields['deletedOnly'] = [
  520. 'type' => 'check',
  521. 'id' => 'mw-show-deleted-only',
  522. 'label' => $this->msg( 'history-show-deleted' )->text(),
  523. 'name' => 'deletedOnly',
  524. 'section' => 'contribs-top',
  525. ];
  526. }
  527. $fields['topOnly'] = [
  528. 'type' => 'check',
  529. 'id' => 'mw-show-top-only',
  530. 'label' => $this->msg( 'sp-contributions-toponly' )->text(),
  531. 'name' => 'topOnly',
  532. 'section' => 'contribs-top',
  533. ];
  534. $fields['newOnly'] = [
  535. 'type' => 'check',
  536. 'id' => 'mw-show-new-only',
  537. 'label' => $this->msg( 'sp-contributions-newonly' )->text(),
  538. 'name' => 'newOnly',
  539. 'section' => 'contribs-top',
  540. ];
  541. $fields['hideMinor'] = [
  542. 'type' => 'check',
  543. 'cssclass' => 'mw-hide-minor-edits',
  544. 'id' => 'mw-show-new-only',
  545. 'label' => $this->msg( 'sp-contributions-hideminor' )->text(),
  546. 'name' => 'hideMinor',
  547. 'section' => 'contribs-top',
  548. ];
  549. // Allow additions at this point to the filters.
  550. $rawFilters = [];
  551. Hooks::run(
  552. 'SpecialContributions::getForm::filters',
  553. [ $this, &$rawFilters ]
  554. );
  555. foreach ( $rawFilters as $filter ) {
  556. // Backwards compatibility support for previous hook function signature.
  557. if ( is_string( $filter ) ) {
  558. $fields[] = [
  559. 'type' => 'info',
  560. 'default' => $filter,
  561. 'raw' => true,
  562. 'section' => 'contribs-top',
  563. ];
  564. wfDeprecated(
  565. __METHOD__ .
  566. ' returning string[]',
  567. '1.33'
  568. );
  569. } else {
  570. // Preferred append method.
  571. $fields[] = $filter;
  572. }
  573. }
  574. $fields['start'] = [
  575. 'type' => 'date',
  576. 'default' => '',
  577. 'id' => 'mw-date-start',
  578. 'label' => $this->msg( 'date-range-from' )->text(),
  579. 'name' => 'start',
  580. 'section' => 'contribs-date',
  581. ];
  582. $fields['end'] = [
  583. 'type' => 'date',
  584. 'default' => '',
  585. 'id' => 'mw-date-end',
  586. 'label' => $this->msg( 'date-range-to' )->text(),
  587. 'name' => 'end',
  588. 'section' => 'contribs-date',
  589. ];
  590. $htmlForm = HTMLForm::factory( 'ooui', $fields, $this->getContext() );
  591. $htmlForm
  592. ->setMethod( 'get' )
  593. // When offset is defined, the user is paging through results
  594. // so we hide the form by default to allow users to focus on browsing
  595. // rather than defining search parameters
  596. ->setCollapsibleOptions(
  597. ( $pagerOptions['target'] ?? null ) ||
  598. ( $pagerOptions['start'] ?? null ) ||
  599. ( $pagerOptions['end'] ?? null )
  600. )
  601. ->setAction( wfScript() )
  602. ->setSubmitText( $this->msg( 'sp-contributions-submit' )->text() )
  603. ->setWrapperLegend( $this->msg( 'sp-contributions-search' )->text() );
  604. $explain = $this->msg( 'sp-contributions-explain' );
  605. if ( !$explain->isBlank() ) {
  606. $htmlForm->addFooterText( "<p id='mw-sp-contributions-explain'>{$explain->parse()}</p>" );
  607. }
  608. $htmlForm->loadData();
  609. return $htmlForm->getHTML( false );
  610. }
  611. /**
  612. * Return an array of subpages beginning with $search that this special page will accept.
  613. *
  614. * @param string $search Prefix to search for
  615. * @param int $limit Maximum number of results to return (usually 10)
  616. * @param int $offset Number of results to skip (usually 0)
  617. * @return string[] Matching subpages
  618. */
  619. public function prefixSearchSubpages( $search, $limit, $offset ) {
  620. $user = User::newFromName( $search );
  621. if ( !$user ) {
  622. // No prefix suggestion for invalid user
  623. return [];
  624. }
  625. // Autocomplete subpage as user list - public to allow caching
  626. return UserNamePrefixSearch::search( 'public', $search, $limit, $offset );
  627. }
  628. protected function getGroupName() {
  629. return 'users';
  630. }
  631. }