ChangesListSpecialPage.php 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895
  1. <?php
  2. /**
  3. * Special page which uses a ChangesList to show query results.
  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\Logger\LoggerFactory;
  24. use Wikimedia\Rdbms\DBQueryTimeoutError;
  25. use Wikimedia\Rdbms\IResultWrapper;
  26. use Wikimedia\Rdbms\FakeResultWrapper;
  27. use Wikimedia\Rdbms\IDatabase;
  28. /**
  29. * Special page which uses a ChangesList to show query results.
  30. * @todo Way too many public functions, most of them should be protected
  31. *
  32. * @ingroup SpecialPage
  33. */
  34. abstract class ChangesListSpecialPage extends SpecialPage {
  35. /**
  36. * Maximum length of a tag description in UTF-8 characters.
  37. * Longer descriptions will be truncated.
  38. */
  39. const TAG_DESC_CHARACTER_LIMIT = 120;
  40. /**
  41. * Preference name for saved queries. Subclasses that use saved queries should override this.
  42. * @var string
  43. */
  44. protected static $savedQueriesPreferenceName;
  45. /**
  46. * Preference name for 'days'. Subclasses should override this.
  47. * @var string
  48. */
  49. protected static $daysPreferenceName;
  50. /**
  51. * Preference name for 'limit'. Subclasses should override this.
  52. * @var string
  53. */
  54. protected static $limitPreferenceName;
  55. /**
  56. * Preference name for collapsing the active filter display. Subclasses should override this.
  57. * @var string
  58. */
  59. protected static $collapsedPreferenceName;
  60. /** @var string */
  61. protected $rcSubpage;
  62. /** @var FormOptions */
  63. protected $rcOptions;
  64. // Order of both groups and filters is significant; first is top-most priority,
  65. // descending from there.
  66. // 'showHideSuffix' is a shortcut to and avoid spelling out
  67. // details specific to subclasses here.
  68. /**
  69. * Definition information for the filters and their groups
  70. *
  71. * The value is $groupDefinition, a parameter to the ChangesListFilterGroup constructor.
  72. * However, priority is dynamically added for the core groups, to ease maintenance.
  73. *
  74. * Groups are displayed to the user in the structured UI. However, if necessary,
  75. * all of the filters in a group can be configured to only display on the
  76. * unstuctured UI, in which case you don't need a group title.
  77. *
  78. * @var array $filterGroupDefinitions
  79. */
  80. private $filterGroupDefinitions;
  81. // Same format as filterGroupDefinitions, but for a single group (reviewStatus)
  82. // that is registered conditionally.
  83. private $legacyReviewStatusFilterGroupDefinition;
  84. // Single filter group registered conditionally
  85. private $reviewStatusFilterGroupDefinition;
  86. // Single filter group registered conditionally
  87. private $hideCategorizationFilterDefinition;
  88. /**
  89. * Filter groups, and their contained filters
  90. * This is an associative array (with group name as key) of ChangesListFilterGroup objects.
  91. *
  92. * @var array $filterGroups
  93. */
  94. protected $filterGroups = [];
  95. public function __construct( $name, $restriction ) {
  96. parent::__construct( $name, $restriction );
  97. $nonRevisionTypes = [ RC_LOG ];
  98. Hooks::run( 'SpecialWatchlistGetNonRevisionTypes', [ &$nonRevisionTypes ] );
  99. $this->filterGroupDefinitions = [
  100. [
  101. 'name' => 'registration',
  102. 'title' => 'rcfilters-filtergroup-registration',
  103. 'class' => ChangesListBooleanFilterGroup::class,
  104. 'filters' => [
  105. [
  106. 'name' => 'hideliu',
  107. // rcshowhideliu-show, rcshowhideliu-hide,
  108. // wlshowhideliu
  109. 'showHideSuffix' => 'showhideliu',
  110. 'default' => false,
  111. 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
  112. &$query_options, &$join_conds
  113. ) {
  114. $actorMigration = ActorMigration::newMigration();
  115. $actorQuery = $actorMigration->getJoin( 'rc_user' );
  116. $tables += $actorQuery['tables'];
  117. $join_conds += $actorQuery['joins'];
  118. $conds[] = $actorMigration->isAnon( $actorQuery['fields']['rc_user'] );
  119. },
  120. 'isReplacedInStructuredUi' => true,
  121. ],
  122. [
  123. 'name' => 'hideanons',
  124. // rcshowhideanons-show, rcshowhideanons-hide,
  125. // wlshowhideanons
  126. 'showHideSuffix' => 'showhideanons',
  127. 'default' => false,
  128. 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
  129. &$query_options, &$join_conds
  130. ) {
  131. $actorMigration = ActorMigration::newMigration();
  132. $actorQuery = $actorMigration->getJoin( 'rc_user' );
  133. $tables += $actorQuery['tables'];
  134. $join_conds += $actorQuery['joins'];
  135. $conds[] = $actorMigration->isNotAnon( $actorQuery['fields']['rc_user'] );
  136. },
  137. 'isReplacedInStructuredUi' => true,
  138. ]
  139. ],
  140. ],
  141. [
  142. 'name' => 'userExpLevel',
  143. 'title' => 'rcfilters-filtergroup-userExpLevel',
  144. 'class' => ChangesListStringOptionsFilterGroup::class,
  145. 'isFullCoverage' => true,
  146. 'filters' => [
  147. [
  148. 'name' => 'unregistered',
  149. 'label' => 'rcfilters-filter-user-experience-level-unregistered-label',
  150. 'description' => 'rcfilters-filter-user-experience-level-unregistered-description',
  151. 'cssClassSuffix' => 'user-unregistered',
  152. 'isRowApplicableCallable' => function ( $ctx, $rc ) {
  153. return !$rc->getAttribute( 'rc_user' );
  154. }
  155. ],
  156. [
  157. 'name' => 'registered',
  158. 'label' => 'rcfilters-filter-user-experience-level-registered-label',
  159. 'description' => 'rcfilters-filter-user-experience-level-registered-description',
  160. 'cssClassSuffix' => 'user-registered',
  161. 'isRowApplicableCallable' => function ( $ctx, $rc ) {
  162. return $rc->getAttribute( 'rc_user' );
  163. }
  164. ],
  165. [
  166. 'name' => 'newcomer',
  167. 'label' => 'rcfilters-filter-user-experience-level-newcomer-label',
  168. 'description' => 'rcfilters-filter-user-experience-level-newcomer-description',
  169. 'cssClassSuffix' => 'user-newcomer',
  170. 'isRowApplicableCallable' => function ( $ctx, $rc ) {
  171. $performer = $rc->getPerformer();
  172. return $performer && $performer->isLoggedIn() &&
  173. $performer->getExperienceLevel() === 'newcomer';
  174. }
  175. ],
  176. [
  177. 'name' => 'learner',
  178. 'label' => 'rcfilters-filter-user-experience-level-learner-label',
  179. 'description' => 'rcfilters-filter-user-experience-level-learner-description',
  180. 'cssClassSuffix' => 'user-learner',
  181. 'isRowApplicableCallable' => function ( $ctx, $rc ) {
  182. $performer = $rc->getPerformer();
  183. return $performer && $performer->isLoggedIn() &&
  184. $performer->getExperienceLevel() === 'learner';
  185. },
  186. ],
  187. [
  188. 'name' => 'experienced',
  189. 'label' => 'rcfilters-filter-user-experience-level-experienced-label',
  190. 'description' => 'rcfilters-filter-user-experience-level-experienced-description',
  191. 'cssClassSuffix' => 'user-experienced',
  192. 'isRowApplicableCallable' => function ( $ctx, $rc ) {
  193. $performer = $rc->getPerformer();
  194. return $performer && $performer->isLoggedIn() &&
  195. $performer->getExperienceLevel() === 'experienced';
  196. },
  197. ]
  198. ],
  199. 'default' => ChangesListStringOptionsFilterGroup::NONE,
  200. 'queryCallable' => [ $this, 'filterOnUserExperienceLevel' ],
  201. ],
  202. [
  203. 'name' => 'authorship',
  204. 'title' => 'rcfilters-filtergroup-authorship',
  205. 'class' => ChangesListBooleanFilterGroup::class,
  206. 'filters' => [
  207. [
  208. 'name' => 'hidemyself',
  209. 'label' => 'rcfilters-filter-editsbyself-label',
  210. 'description' => 'rcfilters-filter-editsbyself-description',
  211. // rcshowhidemine-show, rcshowhidemine-hide,
  212. // wlshowhidemine
  213. 'showHideSuffix' => 'showhidemine',
  214. 'default' => false,
  215. 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
  216. &$query_options, &$join_conds
  217. ) {
  218. $actorQuery = ActorMigration::newMigration()->getWhere( $dbr, 'rc_user', $ctx->getUser() );
  219. $tables += $actorQuery['tables'];
  220. $join_conds += $actorQuery['joins'];
  221. $conds[] = 'NOT(' . $actorQuery['conds'] . ')';
  222. },
  223. 'cssClassSuffix' => 'self',
  224. 'isRowApplicableCallable' => function ( $ctx, $rc ) {
  225. return $ctx->getUser()->equals( $rc->getPerformer() );
  226. },
  227. ],
  228. [
  229. 'name' => 'hidebyothers',
  230. 'label' => 'rcfilters-filter-editsbyother-label',
  231. 'description' => 'rcfilters-filter-editsbyother-description',
  232. 'default' => false,
  233. 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
  234. &$query_options, &$join_conds
  235. ) {
  236. $actorQuery = ActorMigration::newMigration()
  237. ->getWhere( $dbr, 'rc_user', $ctx->getUser(), false );
  238. $tables += $actorQuery['tables'];
  239. $join_conds += $actorQuery['joins'];
  240. $conds[] = $actorQuery['conds'];
  241. },
  242. 'cssClassSuffix' => 'others',
  243. 'isRowApplicableCallable' => function ( $ctx, $rc ) {
  244. return !$ctx->getUser()->equals( $rc->getPerformer() );
  245. },
  246. ]
  247. ]
  248. ],
  249. [
  250. 'name' => 'automated',
  251. 'title' => 'rcfilters-filtergroup-automated',
  252. 'class' => ChangesListBooleanFilterGroup::class,
  253. 'filters' => [
  254. [
  255. 'name' => 'hidebots',
  256. 'label' => 'rcfilters-filter-bots-label',
  257. 'description' => 'rcfilters-filter-bots-description',
  258. // rcshowhidebots-show, rcshowhidebots-hide,
  259. // wlshowhidebots
  260. 'showHideSuffix' => 'showhidebots',
  261. 'default' => false,
  262. 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
  263. &$query_options, &$join_conds
  264. ) {
  265. $conds['rc_bot'] = 0;
  266. },
  267. 'cssClassSuffix' => 'bot',
  268. 'isRowApplicableCallable' => function ( $ctx, $rc ) {
  269. return $rc->getAttribute( 'rc_bot' );
  270. },
  271. ],
  272. [
  273. 'name' => 'hidehumans',
  274. 'label' => 'rcfilters-filter-humans-label',
  275. 'description' => 'rcfilters-filter-humans-description',
  276. 'default' => false,
  277. 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
  278. &$query_options, &$join_conds
  279. ) {
  280. $conds['rc_bot'] = 1;
  281. },
  282. 'cssClassSuffix' => 'human',
  283. 'isRowApplicableCallable' => function ( $ctx, $rc ) {
  284. return !$rc->getAttribute( 'rc_bot' );
  285. },
  286. ]
  287. ]
  288. ],
  289. // significance (conditional)
  290. [
  291. 'name' => 'significance',
  292. 'title' => 'rcfilters-filtergroup-significance',
  293. 'class' => ChangesListBooleanFilterGroup::class,
  294. 'priority' => -6,
  295. 'filters' => [
  296. [
  297. 'name' => 'hideminor',
  298. 'label' => 'rcfilters-filter-minor-label',
  299. 'description' => 'rcfilters-filter-minor-description',
  300. // rcshowhideminor-show, rcshowhideminor-hide,
  301. // wlshowhideminor
  302. 'showHideSuffix' => 'showhideminor',
  303. 'default' => false,
  304. 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
  305. &$query_options, &$join_conds
  306. ) {
  307. $conds[] = 'rc_minor = 0';
  308. },
  309. 'cssClassSuffix' => 'minor',
  310. 'isRowApplicableCallable' => function ( $ctx, $rc ) {
  311. return $rc->getAttribute( 'rc_minor' );
  312. }
  313. ],
  314. [
  315. 'name' => 'hidemajor',
  316. 'label' => 'rcfilters-filter-major-label',
  317. 'description' => 'rcfilters-filter-major-description',
  318. 'default' => false,
  319. 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
  320. &$query_options, &$join_conds
  321. ) {
  322. $conds[] = 'rc_minor = 1';
  323. },
  324. 'cssClassSuffix' => 'major',
  325. 'isRowApplicableCallable' => function ( $ctx, $rc ) {
  326. return !$rc->getAttribute( 'rc_minor' );
  327. }
  328. ]
  329. ]
  330. ],
  331. [
  332. 'name' => 'lastRevision',
  333. 'title' => 'rcfilters-filtergroup-lastRevision',
  334. 'class' => ChangesListBooleanFilterGroup::class,
  335. 'priority' => -7,
  336. 'filters' => [
  337. [
  338. 'name' => 'hidelastrevision',
  339. 'label' => 'rcfilters-filter-lastrevision-label',
  340. 'description' => 'rcfilters-filter-lastrevision-description',
  341. 'default' => false,
  342. 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
  343. &$query_options, &$join_conds ) use ( $nonRevisionTypes ) {
  344. $conds[] = $dbr->makeList(
  345. [
  346. 'rc_this_oldid <> page_latest',
  347. 'rc_type' => $nonRevisionTypes,
  348. ],
  349. LIST_OR
  350. );
  351. },
  352. 'cssClassSuffix' => 'last',
  353. 'isRowApplicableCallable' => function ( $ctx, $rc ) {
  354. return $rc->getAttribute( 'rc_this_oldid' ) === $rc->getAttribute( 'page_latest' );
  355. }
  356. ],
  357. [
  358. 'name' => 'hidepreviousrevisions',
  359. 'label' => 'rcfilters-filter-previousrevision-label',
  360. 'description' => 'rcfilters-filter-previousrevision-description',
  361. 'default' => false,
  362. 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
  363. &$query_options, &$join_conds ) use ( $nonRevisionTypes ) {
  364. $conds[] = $dbr->makeList(
  365. [
  366. 'rc_this_oldid = page_latest',
  367. 'rc_type' => $nonRevisionTypes,
  368. ],
  369. LIST_OR
  370. );
  371. },
  372. 'cssClassSuffix' => 'previous',
  373. 'isRowApplicableCallable' => function ( $ctx, $rc ) {
  374. return $rc->getAttribute( 'rc_this_oldid' ) !== $rc->getAttribute( 'page_latest' );
  375. }
  376. ]
  377. ]
  378. ],
  379. // With extensions, there can be change types that will not be hidden by any of these.
  380. [
  381. 'name' => 'changeType',
  382. 'title' => 'rcfilters-filtergroup-changetype',
  383. 'class' => ChangesListBooleanFilterGroup::class,
  384. 'priority' => -8,
  385. 'filters' => [
  386. [
  387. 'name' => 'hidepageedits',
  388. 'label' => 'rcfilters-filter-pageedits-label',
  389. 'description' => 'rcfilters-filter-pageedits-description',
  390. 'default' => false,
  391. 'priority' => -2,
  392. 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
  393. &$query_options, &$join_conds
  394. ) {
  395. $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_EDIT );
  396. },
  397. 'cssClassSuffix' => 'src-mw-edit',
  398. 'isRowApplicableCallable' => function ( $ctx, $rc ) {
  399. return $rc->getAttribute( 'rc_source' ) === RecentChange::SRC_EDIT;
  400. },
  401. ],
  402. [
  403. 'name' => 'hidenewpages',
  404. 'label' => 'rcfilters-filter-newpages-label',
  405. 'description' => 'rcfilters-filter-newpages-description',
  406. 'default' => false,
  407. 'priority' => -3,
  408. 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
  409. &$query_options, &$join_conds
  410. ) {
  411. $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_NEW );
  412. },
  413. 'cssClassSuffix' => 'src-mw-new',
  414. 'isRowApplicableCallable' => function ( $ctx, $rc ) {
  415. return $rc->getAttribute( 'rc_source' ) === RecentChange::SRC_NEW;
  416. },
  417. ],
  418. // hidecategorization
  419. [
  420. 'name' => 'hidelog',
  421. 'label' => 'rcfilters-filter-logactions-label',
  422. 'description' => 'rcfilters-filter-logactions-description',
  423. 'default' => false,
  424. 'priority' => -5,
  425. 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
  426. &$query_options, &$join_conds
  427. ) {
  428. $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_LOG );
  429. },
  430. 'cssClassSuffix' => 'src-mw-log',
  431. 'isRowApplicableCallable' => function ( $ctx, $rc ) {
  432. return $rc->getAttribute( 'rc_source' ) === RecentChange::SRC_LOG;
  433. }
  434. ],
  435. ],
  436. ],
  437. ];
  438. $this->legacyReviewStatusFilterGroupDefinition = [
  439. [
  440. 'name' => 'legacyReviewStatus',
  441. 'title' => 'rcfilters-filtergroup-reviewstatus',
  442. 'class' => ChangesListBooleanFilterGroup::class,
  443. 'filters' => [
  444. [
  445. 'name' => 'hidepatrolled',
  446. // rcshowhidepatr-show, rcshowhidepatr-hide
  447. // wlshowhidepatr
  448. 'showHideSuffix' => 'showhidepatr',
  449. 'default' => false,
  450. 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
  451. &$query_options, &$join_conds
  452. ) {
  453. $conds['rc_patrolled'] = RecentChange::PRC_UNPATROLLED;
  454. },
  455. 'isReplacedInStructuredUi' => true,
  456. ],
  457. [
  458. 'name' => 'hideunpatrolled',
  459. 'default' => false,
  460. 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
  461. &$query_options, &$join_conds
  462. ) {
  463. $conds[] = 'rc_patrolled != ' . RecentChange::PRC_UNPATROLLED;
  464. },
  465. 'isReplacedInStructuredUi' => true,
  466. ],
  467. ],
  468. ]
  469. ];
  470. $this->reviewStatusFilterGroupDefinition = [
  471. [
  472. 'name' => 'reviewStatus',
  473. 'title' => 'rcfilters-filtergroup-reviewstatus',
  474. 'class' => ChangesListStringOptionsFilterGroup::class,
  475. 'isFullCoverage' => true,
  476. 'priority' => -5,
  477. 'filters' => [
  478. [
  479. 'name' => 'unpatrolled',
  480. 'label' => 'rcfilters-filter-reviewstatus-unpatrolled-label',
  481. 'description' => 'rcfilters-filter-reviewstatus-unpatrolled-description',
  482. 'cssClassSuffix' => 'reviewstatus-unpatrolled',
  483. 'isRowApplicableCallable' => function ( $ctx, $rc ) {
  484. return $rc->getAttribute( 'rc_patrolled' ) == RecentChange::PRC_UNPATROLLED;
  485. },
  486. ],
  487. [
  488. 'name' => 'manual',
  489. 'label' => 'rcfilters-filter-reviewstatus-manual-label',
  490. 'description' => 'rcfilters-filter-reviewstatus-manual-description',
  491. 'cssClassSuffix' => 'reviewstatus-manual',
  492. 'isRowApplicableCallable' => function ( $ctx, $rc ) {
  493. return $rc->getAttribute( 'rc_patrolled' ) == RecentChange::PRC_PATROLLED;
  494. },
  495. ],
  496. [
  497. 'name' => 'auto',
  498. 'label' => 'rcfilters-filter-reviewstatus-auto-label',
  499. 'description' => 'rcfilters-filter-reviewstatus-auto-description',
  500. 'cssClassSuffix' => 'reviewstatus-auto',
  501. 'isRowApplicableCallable' => function ( $ctx, $rc ) {
  502. return $rc->getAttribute( 'rc_patrolled' ) == RecentChange::PRC_AUTOPATROLLED;
  503. },
  504. ],
  505. ],
  506. 'default' => ChangesListStringOptionsFilterGroup::NONE,
  507. 'queryCallable' => function ( $specialPageClassName, $ctx, $dbr,
  508. &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selected
  509. ) {
  510. if ( $selected === [] ) {
  511. return;
  512. }
  513. $rcPatrolledValues = [
  514. 'unpatrolled' => RecentChange::PRC_UNPATROLLED,
  515. 'manual' => RecentChange::PRC_PATROLLED,
  516. 'auto' => RecentChange::PRC_AUTOPATROLLED,
  517. ];
  518. // e.g. rc_patrolled IN (0, 2)
  519. $conds['rc_patrolled'] = array_map( function ( $s ) use ( $rcPatrolledValues ) {
  520. return $rcPatrolledValues[ $s ];
  521. }, $selected );
  522. }
  523. ]
  524. ];
  525. $this->hideCategorizationFilterDefinition = [
  526. 'name' => 'hidecategorization',
  527. 'label' => 'rcfilters-filter-categorization-label',
  528. 'description' => 'rcfilters-filter-categorization-description',
  529. // rcshowhidecategorization-show, rcshowhidecategorization-hide.
  530. // wlshowhidecategorization
  531. 'showHideSuffix' => 'showhidecategorization',
  532. 'default' => false,
  533. 'priority' => -4,
  534. 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
  535. &$query_options, &$join_conds
  536. ) {
  537. $conds[] = 'rc_type != ' . $dbr->addQuotes( RC_CATEGORIZE );
  538. },
  539. 'cssClassSuffix' => 'src-mw-categorize',
  540. 'isRowApplicableCallable' => function ( $ctx, $rc ) {
  541. return $rc->getAttribute( 'rc_source' ) === RecentChange::SRC_CATEGORIZE;
  542. },
  543. ];
  544. }
  545. /**
  546. * Check if filters are in conflict and guaranteed to return no results.
  547. *
  548. * @return bool
  549. */
  550. protected function areFiltersInConflict() {
  551. $opts = $this->getOptions();
  552. /** @var ChangesListFilterGroup $group */
  553. foreach ( $this->getFilterGroups() as $group ) {
  554. if ( $group->getConflictingGroups() ) {
  555. wfLogWarning(
  556. $group->getName() .
  557. " specifies conflicts with other groups but these are not supported yet."
  558. );
  559. }
  560. /** @var ChangesListFilter $conflictingFilter */
  561. foreach ( $group->getConflictingFilters() as $conflictingFilter ) {
  562. if ( $conflictingFilter->activelyInConflictWithGroup( $group, $opts ) ) {
  563. return true;
  564. }
  565. }
  566. /** @var ChangesListFilter $filter */
  567. foreach ( $group->getFilters() as $filter ) {
  568. /** @var ChangesListFilter $conflictingFilter */
  569. foreach ( $filter->getConflictingFilters() as $conflictingFilter ) {
  570. if (
  571. $conflictingFilter->activelyInConflictWithFilter( $filter, $opts ) &&
  572. $filter->activelyInConflictWithFilter( $conflictingFilter, $opts )
  573. ) {
  574. return true;
  575. }
  576. }
  577. }
  578. }
  579. return false;
  580. }
  581. /**
  582. * Main execution point
  583. *
  584. * @param string $subpage
  585. */
  586. public function execute( $subpage ) {
  587. $this->rcSubpage = $subpage;
  588. $this->considerActionsForDefaultSavedQuery( $subpage );
  589. $opts = $this->getOptions();
  590. try {
  591. $rows = $this->getRows();
  592. if ( $rows === false ) {
  593. $rows = new FakeResultWrapper( [] );
  594. }
  595. // Used by Structured UI app to get results without MW chrome
  596. if ( $this->getRequest()->getVal( 'action' ) === 'render' ) {
  597. $this->getOutput()->setArticleBodyOnly( true );
  598. }
  599. // Used by "live update" and "view newest" to check
  600. // if there's new changes with minimal data transfer
  601. if ( $this->getRequest()->getBool( 'peek' ) ) {
  602. $code = $rows->numRows() > 0 ? 200 : 204;
  603. $this->getOutput()->setStatusCode( $code );
  604. if ( $this->getUser()->isAnon() !==
  605. $this->getRequest()->getFuzzyBool( 'isAnon' )
  606. ) {
  607. $this->getOutput()->setStatusCode( 205 );
  608. }
  609. return;
  610. }
  611. $batch = new LinkBatch;
  612. foreach ( $rows as $row ) {
  613. $batch->add( NS_USER, $row->rc_user_text );
  614. $batch->add( NS_USER_TALK, $row->rc_user_text );
  615. $batch->add( $row->rc_namespace, $row->rc_title );
  616. if ( $row->rc_source === RecentChange::SRC_LOG ) {
  617. $formatter = LogFormatter::newFromRow( $row );
  618. foreach ( $formatter->getPreloadTitles() as $title ) {
  619. $batch->addObj( $title );
  620. }
  621. }
  622. }
  623. $batch->execute();
  624. $this->setHeaders();
  625. $this->outputHeader();
  626. $this->addModules();
  627. $this->webOutput( $rows, $opts );
  628. $rows->free();
  629. } catch ( DBQueryTimeoutError $timeoutException ) {
  630. MWExceptionHandler::logException( $timeoutException );
  631. $this->setHeaders();
  632. $this->outputHeader();
  633. $this->addModules();
  634. $this->getOutput()->setStatusCode( 500 );
  635. $this->webOutputHeader( 0, $opts );
  636. $this->outputTimeout();
  637. }
  638. if ( $this->getConfig()->get( 'EnableWANCacheReaper' ) ) {
  639. // Clean up any bad page entries for titles showing up in RC
  640. DeferredUpdates::addUpdate( new WANCacheReapUpdate(
  641. $this->getDB(),
  642. LoggerFactory::getInstance( 'objectcache' )
  643. ) );
  644. }
  645. $this->includeRcFiltersApp();
  646. }
  647. /**
  648. * Check whether or not the page should load defaults, and if so, whether
  649. * a default saved query is relevant to be redirected to. If it is relevant,
  650. * redirect properly with all necessary query parameters.
  651. *
  652. * @param string $subpage
  653. */
  654. protected function considerActionsForDefaultSavedQuery( $subpage ) {
  655. if ( !$this->isStructuredFilterUiEnabled() || $this->including() ) {
  656. return;
  657. }
  658. $knownParams = $this->getRequest()->getValues(
  659. ...array_keys( $this->getOptions()->getAllValues() )
  660. );
  661. // HACK: Temporarily until we can properly define "sticky" filters and parameters,
  662. // we need to exclude several parameters we know should not be counted towards preventing
  663. // the loading of defaults.
  664. $excludedParams = [ 'limit' => '', 'days' => '', 'enhanced' => '', 'from' => '' ];
  665. $knownParams = array_diff_key( $knownParams, $excludedParams );
  666. if (
  667. // If there are NO known parameters in the URL request
  668. // (that are not excluded) then we need to check into loading
  669. // the default saved query
  670. count( $knownParams ) === 0
  671. ) {
  672. // Get the saved queries data and parse it
  673. $savedQueries = FormatJson::decode(
  674. $this->getUser()->getOption( static::$savedQueriesPreferenceName ),
  675. true
  676. );
  677. if ( $savedQueries && isset( $savedQueries[ 'default' ] ) ) {
  678. // Only load queries that are 'version' 2, since those
  679. // have parameter representation
  680. if ( isset( $savedQueries[ 'version' ] ) && $savedQueries[ 'version' ] === '2' ) {
  681. $savedQueryDefaultID = $savedQueries[ 'default' ];
  682. $defaultQuery = $savedQueries[ 'queries' ][ $savedQueryDefaultID ][ 'data' ];
  683. // Build the entire parameter list
  684. $query = array_merge(
  685. $defaultQuery[ 'params' ],
  686. $defaultQuery[ 'highlights' ],
  687. [
  688. 'urlversion' => '2',
  689. ]
  690. );
  691. // Add to the query any parameters that we may have ignored before
  692. // but are still valid and requested in the URL
  693. $query = array_merge( $this->getRequest()->getValues(), $query );
  694. unset( $query[ 'title' ] );
  695. $this->getOutput()->redirect( $this->getPageTitle( $subpage )->getCanonicalURL( $query ) );
  696. } else {
  697. // There's a default, but the version is not 2, and the server can't
  698. // actually recognize the query itself. This happens if it is before
  699. // the conversion, so we need to tell the UI to reload saved query as
  700. // it does the conversion to version 2
  701. $this->getOutput()->addJsConfigVars(
  702. 'wgStructuredChangeFiltersDefaultSavedQueryExists',
  703. true
  704. );
  705. // Add the class that tells the frontend it is still loading
  706. // another query
  707. $this->getOutput()->addBodyClasses( 'mw-rcfilters-ui-loading' );
  708. }
  709. }
  710. }
  711. }
  712. /**
  713. * Include the modules and configuration for the RCFilters app.
  714. * Conditional on the user having the feature enabled.
  715. *
  716. * If it is disabled, add a <body> class marking that
  717. */
  718. protected function includeRcFiltersApp() {
  719. $out = $this->getOutput();
  720. if ( $this->isStructuredFilterUiEnabled() && !$this->including() ) {
  721. $jsData = $this->getStructuredFilterJsData();
  722. $messages = [];
  723. foreach ( $jsData['messageKeys'] as $key ) {
  724. $messages[$key] = $this->msg( $key )->plain();
  725. }
  726. $out->addBodyClasses( 'mw-rcfilters-enabled' );
  727. $collapsed = $this->getUser()->getBoolOption( static::$collapsedPreferenceName );
  728. if ( $collapsed ) {
  729. $out->addBodyClasses( 'mw-rcfilters-collapsed' );
  730. }
  731. // These config and message exports should be moved into a ResourceLoader data module (T201574)
  732. $out->addJsConfigVars( 'wgStructuredChangeFilters', $jsData['groups'] );
  733. $out->addJsConfigVars( 'wgStructuredChangeFiltersMessages', $messages );
  734. $out->addJsConfigVars( 'wgStructuredChangeFiltersCollapsedState', $collapsed );
  735. $out->addJsConfigVars(
  736. 'wgRCFiltersChangeTags',
  737. $this->getChangeTagList()
  738. );
  739. $out->addJsConfigVars(
  740. 'StructuredChangeFiltersDisplayConfig',
  741. [
  742. 'maxDays' => (int)$this->getConfig()->get( 'RCMaxAge' ) / ( 24 * 3600 ), // Translate to days
  743. 'limitArray' => $this->getConfig()->get( 'RCLinkLimits' ),
  744. 'limitDefault' => $this->getDefaultLimit(),
  745. 'daysArray' => $this->getConfig()->get( 'RCLinkDays' ),
  746. 'daysDefault' => $this->getDefaultDays(),
  747. ]
  748. );
  749. $out->addJsConfigVars(
  750. 'wgStructuredChangeFiltersSavedQueriesPreferenceName',
  751. static::$savedQueriesPreferenceName
  752. );
  753. $out->addJsConfigVars(
  754. 'wgStructuredChangeFiltersLimitPreferenceName',
  755. static::$limitPreferenceName
  756. );
  757. $out->addJsConfigVars(
  758. 'wgStructuredChangeFiltersDaysPreferenceName',
  759. static::$daysPreferenceName
  760. );
  761. $out->addJsConfigVars(
  762. 'wgStructuredChangeFiltersCollapsedPreferenceName',
  763. static::$collapsedPreferenceName
  764. );
  765. $out->addJsConfigVars(
  766. 'StructuredChangeFiltersLiveUpdatePollingRate',
  767. $this->getConfig()->get( 'StructuredChangeFiltersLiveUpdatePollingRate' )
  768. );
  769. } else {
  770. $out->addBodyClasses( 'mw-rcfilters-disabled' );
  771. }
  772. }
  773. /**
  774. * Fetch the change tags list for the front end
  775. *
  776. * @return Array Tag data
  777. */
  778. protected function getChangeTagList() {
  779. $cache = ObjectCache::getMainWANInstance();
  780. $context = $this->getContext();
  781. return $cache->getWithSetCallback(
  782. $cache->makeKey( 'changeslistspecialpage-changetags', $context->getLanguage()->getCode() ),
  783. $cache::TTL_MINUTE * 10,
  784. function () use ( $context ) {
  785. $explicitlyDefinedTags = array_fill_keys( ChangeTags::listExplicitlyDefinedTags(), 0 );
  786. $softwareActivatedTags = array_fill_keys( ChangeTags::listSoftwareActivatedTags(), 0 );
  787. // Hit counts disabled for perf reasons, see T169997
  788. /*
  789. $tagStats = ChangeTags::tagUsageStatistics();
  790. $tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags, $tagStats );
  791. // Sort by hits
  792. arsort( $tagHitCounts );
  793. */
  794. $tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags );
  795. // Build the list and data
  796. $result = [];
  797. foreach ( $tagHitCounts as $tagName => $hits ) {
  798. if (
  799. // Only get active tags
  800. isset( $explicitlyDefinedTags[ $tagName ] ) ||
  801. isset( $softwareActivatedTags[ $tagName ] )
  802. ) {
  803. $result[] = [
  804. 'name' => $tagName,
  805. 'label' => Sanitizer::stripAllTags(
  806. ChangeTags::tagDescription( $tagName, $context )
  807. ),
  808. 'description' =>
  809. ChangeTags::truncateTagDescription(
  810. $tagName, self::TAG_DESC_CHARACTER_LIMIT, $context
  811. ),
  812. 'cssClass' => Sanitizer::escapeClass( 'mw-tag-' . $tagName ),
  813. 'hits' => $hits,
  814. ];
  815. }
  816. }
  817. // Instead of sorting by hit count (disabled, see above), sort by display name
  818. usort( $result, function ( $a, $b ) {
  819. return strcasecmp( $a['label'], $b['label'] );
  820. } );
  821. return $result;
  822. },
  823. [
  824. 'lockTSE' => 30
  825. ]
  826. );
  827. }
  828. /**
  829. * Add the "no results" message to the output
  830. */
  831. protected function outputNoResults() {
  832. $this->getOutput()->addHTML(
  833. '<div class="mw-changeslist-empty">' .
  834. $this->msg( 'recentchanges-noresult' )->parse() .
  835. '</div>'
  836. );
  837. }
  838. /**
  839. * Add the "timeout" message to the output
  840. */
  841. protected function outputTimeout() {
  842. $this->getOutput()->addHTML(
  843. '<div class="mw-changeslist-empty mw-changeslist-timeout">' .
  844. $this->msg( 'recentchanges-timeout' )->parse() .
  845. '</div>'
  846. );
  847. }
  848. /**
  849. * Get the database result for this special page instance. Used by ApiFeedRecentChanges.
  850. *
  851. * @return bool|IResultWrapper Result or false
  852. */
  853. public function getRows() {
  854. $opts = $this->getOptions();
  855. $tables = [];
  856. $fields = [];
  857. $conds = [];
  858. $query_options = [];
  859. $join_conds = [];
  860. $this->buildQuery( $tables, $fields, $conds, $query_options, $join_conds, $opts );
  861. return $this->doMainQuery( $tables, $fields, $conds, $query_options, $join_conds, $opts );
  862. }
  863. /**
  864. * Get the current FormOptions for this request
  865. *
  866. * @return FormOptions
  867. */
  868. public function getOptions() {
  869. if ( $this->rcOptions === null ) {
  870. $this->rcOptions = $this->setup( $this->rcSubpage );
  871. }
  872. return $this->rcOptions;
  873. }
  874. /**
  875. * Register all filters and their groups (including those from hooks), plus handle
  876. * conflicts and defaults.
  877. *
  878. * You might want to customize these in the same method, in subclasses. You can
  879. * call getFilterGroup to access a group, and (on the group) getFilter to access a
  880. * filter, then make necessary modfications to the filter or group (e.g. with
  881. * setDefault).
  882. */
  883. protected function registerFilters() {
  884. $this->registerFiltersFromDefinitions( $this->filterGroupDefinitions );
  885. // Make sure this is not being transcluded (we don't want to show this
  886. // information to all users just because the user that saves the edit can
  887. // patrol or is logged in)
  888. if ( !$this->including() && $this->getUser()->useRCPatrol() ) {
  889. $this->registerFiltersFromDefinitions( $this->legacyReviewStatusFilterGroupDefinition );
  890. $this->registerFiltersFromDefinitions( $this->reviewStatusFilterGroupDefinition );
  891. }
  892. $changeTypeGroup = $this->getFilterGroup( 'changeType' );
  893. if ( $this->getConfig()->get( 'RCWatchCategoryMembership' ) ) {
  894. $transformedHideCategorizationDef = $this->transformFilterDefinition(
  895. $this->hideCategorizationFilterDefinition
  896. );
  897. $transformedHideCategorizationDef['group'] = $changeTypeGroup;
  898. $hideCategorization = new ChangesListBooleanFilter(
  899. $transformedHideCategorizationDef
  900. );
  901. }
  902. Hooks::run( 'ChangesListSpecialPageStructuredFilters', [ $this ] );
  903. $this->registerFiltersFromDefinitions( [] );
  904. $userExperienceLevel = $this->getFilterGroup( 'userExpLevel' );
  905. $registered = $userExperienceLevel->getFilter( 'registered' );
  906. $registered->setAsSupersetOf( $userExperienceLevel->getFilter( 'newcomer' ) );
  907. $registered->setAsSupersetOf( $userExperienceLevel->getFilter( 'learner' ) );
  908. $registered->setAsSupersetOf( $userExperienceLevel->getFilter( 'experienced' ) );
  909. $categoryFilter = $changeTypeGroup->getFilter( 'hidecategorization' );
  910. $logactionsFilter = $changeTypeGroup->getFilter( 'hidelog' );
  911. $pagecreationFilter = $changeTypeGroup->getFilter( 'hidenewpages' );
  912. $significanceTypeGroup = $this->getFilterGroup( 'significance' );
  913. $hideMinorFilter = $significanceTypeGroup->getFilter( 'hideminor' );
  914. // categoryFilter is conditional; see registerFilters
  915. if ( $categoryFilter !== null ) {
  916. $hideMinorFilter->conflictsWith(
  917. $categoryFilter,
  918. 'rcfilters-hideminor-conflicts-typeofchange-global',
  919. 'rcfilters-hideminor-conflicts-typeofchange',
  920. 'rcfilters-typeofchange-conflicts-hideminor'
  921. );
  922. }
  923. $hideMinorFilter->conflictsWith(
  924. $logactionsFilter,
  925. 'rcfilters-hideminor-conflicts-typeofchange-global',
  926. 'rcfilters-hideminor-conflicts-typeofchange',
  927. 'rcfilters-typeofchange-conflicts-hideminor'
  928. );
  929. $hideMinorFilter->conflictsWith(
  930. $pagecreationFilter,
  931. 'rcfilters-hideminor-conflicts-typeofchange-global',
  932. 'rcfilters-hideminor-conflicts-typeofchange',
  933. 'rcfilters-typeofchange-conflicts-hideminor'
  934. );
  935. }
  936. /**
  937. * Transforms filter definition to prepare it for constructor.
  938. *
  939. * See overrides of this method as well.
  940. *
  941. * @param array $filterDefinition Original filter definition
  942. *
  943. * @return array Transformed definition
  944. */
  945. protected function transformFilterDefinition( array $filterDefinition ) {
  946. return $filterDefinition;
  947. }
  948. /**
  949. * Register filters from a definition object
  950. *
  951. * Array specifying groups and their filters; see Filter and
  952. * ChangesListFilterGroup constructors.
  953. *
  954. * There is light processing to simplify core maintenance.
  955. * @param array $definition
  956. */
  957. protected function registerFiltersFromDefinitions( array $definition ) {
  958. $autoFillPriority = -1;
  959. foreach ( $definition as $groupDefinition ) {
  960. if ( !isset( $groupDefinition['priority'] ) ) {
  961. $groupDefinition['priority'] = $autoFillPriority;
  962. } else {
  963. // If it's explicitly specified, start over the auto-fill
  964. $autoFillPriority = $groupDefinition['priority'];
  965. }
  966. $autoFillPriority--;
  967. $className = $groupDefinition['class'];
  968. unset( $groupDefinition['class'] );
  969. foreach ( $groupDefinition['filters'] as &$filterDefinition ) {
  970. $filterDefinition = $this->transformFilterDefinition( $filterDefinition );
  971. }
  972. $this->registerFilterGroup( new $className( $groupDefinition ) );
  973. }
  974. }
  975. /**
  976. * @return array The legacy show/hide toggle filters
  977. */
  978. protected function getLegacyShowHideFilters() {
  979. $filters = [];
  980. foreach ( $this->filterGroups as $group ) {
  981. if ( $group instanceof ChangesListBooleanFilterGroup ) {
  982. foreach ( $group->getFilters() as $key => $filter ) {
  983. if ( $filter->displaysOnUnstructuredUi( $this ) ) {
  984. $filters[ $key ] = $filter;
  985. }
  986. }
  987. }
  988. }
  989. return $filters;
  990. }
  991. /**
  992. * Register all the filters, including legacy hook-driven ones.
  993. * Then create a FormOptions object with options as specified by the user
  994. *
  995. * @param array $parameters
  996. *
  997. * @return FormOptions
  998. */
  999. public function setup( $parameters ) {
  1000. $this->registerFilters();
  1001. $opts = $this->getDefaultOptions();
  1002. $opts = $this->fetchOptionsFromRequest( $opts );
  1003. // Give precedence to subpage syntax
  1004. if ( $parameters !== null ) {
  1005. $this->parseParameters( $parameters, $opts );
  1006. }
  1007. $this->validateOptions( $opts );
  1008. return $opts;
  1009. }
  1010. /**
  1011. * Get a FormOptions object containing the default options. By default, returns
  1012. * some basic options. The filters listed explicitly here are overriden in this
  1013. * method, in subclasses, but most filters (e.g. hideminor, userExpLevel filters,
  1014. * and more) are structured. Structured filters are overriden in registerFilters.
  1015. * not here.
  1016. *
  1017. * @return FormOptions
  1018. */
  1019. public function getDefaultOptions() {
  1020. $opts = new FormOptions();
  1021. $structuredUI = $this->isStructuredFilterUiEnabled();
  1022. // If urlversion=2 is set, ignore the filter defaults and set them all to false/empty
  1023. $useDefaults = $this->getRequest()->getInt( 'urlversion' ) !== 2;
  1024. /** @var ChangesListFilterGroup $filterGroup */
  1025. foreach ( $this->filterGroups as $filterGroup ) {
  1026. $filterGroup->addOptions( $opts, $useDefaults, $structuredUI );
  1027. }
  1028. $opts->add( 'namespace', '', FormOptions::STRING );
  1029. $opts->add( 'invert', false );
  1030. $opts->add( 'associated', false );
  1031. $opts->add( 'urlversion', 1 );
  1032. $opts->add( 'tagfilter', '' );
  1033. $opts->add( 'days', $this->getDefaultDays(), FormOptions::FLOAT );
  1034. $opts->add( 'limit', $this->getDefaultLimit(), FormOptions::INT );
  1035. $opts->add( 'from', '' );
  1036. return $opts;
  1037. }
  1038. /**
  1039. * Register a structured changes list filter group
  1040. *
  1041. * @param ChangesListFilterGroup $group
  1042. */
  1043. public function registerFilterGroup( ChangesListFilterGroup $group ) {
  1044. $groupName = $group->getName();
  1045. $this->filterGroups[$groupName] = $group;
  1046. }
  1047. /**
  1048. * Gets the currently registered filters groups
  1049. *
  1050. * @return array Associative array of ChangesListFilterGroup objects, with group name as key
  1051. */
  1052. protected function getFilterGroups() {
  1053. return $this->filterGroups;
  1054. }
  1055. /**
  1056. * Gets a specified ChangesListFilterGroup by name
  1057. *
  1058. * @param string $groupName Name of group
  1059. *
  1060. * @return ChangesListFilterGroup|null Group, or null if not registered
  1061. */
  1062. public function getFilterGroup( $groupName ) {
  1063. return $this->filterGroups[$groupName] ?? null;
  1064. }
  1065. // Currently, this intentionally only includes filters that display
  1066. // in the structured UI. This can be changed easily, though, if we want
  1067. // to include data on filters that use the unstructured UI. messageKeys is a
  1068. // special top-level value, with the value being an array of the message keys to
  1069. // send to the client.
  1070. /**
  1071. * Gets structured filter information needed by JS
  1072. *
  1073. * @return array Associative array
  1074. * * array $return['groups'] Group data
  1075. * * array $return['messageKeys'] Array of message keys
  1076. */
  1077. public function getStructuredFilterJsData() {
  1078. $output = [
  1079. 'groups' => [],
  1080. 'messageKeys' => [],
  1081. ];
  1082. usort( $this->filterGroups, function ( $a, $b ) {
  1083. return $b->getPriority() <=> $a->getPriority();
  1084. } );
  1085. foreach ( $this->filterGroups as $groupName => $group ) {
  1086. $groupOutput = $group->getJsData( $this );
  1087. if ( $groupOutput !== null ) {
  1088. $output['messageKeys'] = array_merge(
  1089. $output['messageKeys'],
  1090. $groupOutput['messageKeys']
  1091. );
  1092. unset( $groupOutput['messageKeys'] );
  1093. $output['groups'][] = $groupOutput;
  1094. }
  1095. }
  1096. return $output;
  1097. }
  1098. /**
  1099. * Fetch values for a FormOptions object from the WebRequest associated with this instance.
  1100. *
  1101. * Intended for subclassing, e.g. to add a backwards-compatibility layer.
  1102. *
  1103. * @param FormOptions $opts
  1104. * @return FormOptions
  1105. */
  1106. protected function fetchOptionsFromRequest( $opts ) {
  1107. $opts->fetchValuesFromRequest( $this->getRequest() );
  1108. return $opts;
  1109. }
  1110. /**
  1111. * Process $par and put options found in $opts. Used when including the page.
  1112. *
  1113. * @param string $par
  1114. * @param FormOptions $opts
  1115. */
  1116. public function parseParameters( $par, FormOptions $opts ) {
  1117. $stringParameterNameSet = [];
  1118. $hideParameterNameSet = [];
  1119. // URL parameters can be per-group, like 'userExpLevel',
  1120. // or per-filter, like 'hideminor'.
  1121. foreach ( $this->filterGroups as $filterGroup ) {
  1122. if ( $filterGroup instanceof ChangesListStringOptionsFilterGroup ) {
  1123. $stringParameterNameSet[$filterGroup->getName()] = true;
  1124. } elseif ( $filterGroup instanceof ChangesListBooleanFilterGroup ) {
  1125. foreach ( $filterGroup->getFilters() as $filter ) {
  1126. $hideParameterNameSet[$filter->getName()] = true;
  1127. }
  1128. }
  1129. }
  1130. $bits = preg_split( '/\s*,\s*/', trim( $par ) );
  1131. foreach ( $bits as $bit ) {
  1132. $m = [];
  1133. if ( isset( $hideParameterNameSet[$bit] ) ) {
  1134. // hidefoo => hidefoo=true
  1135. $opts[$bit] = true;
  1136. } elseif ( isset( $hideParameterNameSet["hide$bit"] ) ) {
  1137. // foo => hidefoo=false
  1138. $opts["hide$bit"] = false;
  1139. } elseif ( preg_match( '/^(.*)=(.*)$/', $bit, $m ) ) {
  1140. if ( isset( $stringParameterNameSet[$m[1]] ) ) {
  1141. $opts[$m[1]] = $m[2];
  1142. }
  1143. }
  1144. }
  1145. }
  1146. /**
  1147. * Validate a FormOptions object generated by getDefaultOptions() with values already populated.
  1148. *
  1149. * @param FormOptions $opts
  1150. */
  1151. public function validateOptions( FormOptions $opts ) {
  1152. $isContradictory = $this->fixContradictoryOptions( $opts );
  1153. $isReplaced = $this->replaceOldOptions( $opts );
  1154. if ( $isContradictory || $isReplaced ) {
  1155. $query = wfArrayToCgi( $this->convertParamsForLink( $opts->getChangedValues() ) );
  1156. $this->getOutput()->redirect( $this->getPageTitle()->getCanonicalURL( $query ) );
  1157. }
  1158. $opts->validateIntBounds( 'limit', 0, 5000 );
  1159. $opts->validateBounds( 'days', 0, $this->getConfig()->get( 'RCMaxAge' ) / ( 3600 * 24 ) );
  1160. }
  1161. /**
  1162. * Fix invalid options by resetting pairs that should never appear together.
  1163. *
  1164. * @param FormOptions $opts
  1165. * @return bool True if any option was reset
  1166. */
  1167. private function fixContradictoryOptions( FormOptions $opts ) {
  1168. $fixed = $this->fixBackwardsCompatibilityOptions( $opts );
  1169. foreach ( $this->filterGroups as $filterGroup ) {
  1170. if ( $filterGroup instanceof ChangesListBooleanFilterGroup ) {
  1171. $filters = $filterGroup->getFilters();
  1172. if ( count( $filters ) === 1 ) {
  1173. // legacy boolean filters should not be considered
  1174. continue;
  1175. }
  1176. $allInGroupEnabled = array_reduce(
  1177. $filters,
  1178. function ( $carry, $filter ) use ( $opts ) {
  1179. return $carry && $opts[ $filter->getName() ];
  1180. },
  1181. /* initialValue */ count( $filters ) > 0
  1182. );
  1183. if ( $allInGroupEnabled ) {
  1184. foreach ( $filters as $filter ) {
  1185. $opts[ $filter->getName() ] = false;
  1186. }
  1187. $fixed = true;
  1188. }
  1189. }
  1190. }
  1191. return $fixed;
  1192. }
  1193. /**
  1194. * Fix a special case (hideanons=1 and hideliu=1) in a special way, for backwards
  1195. * compatibility.
  1196. *
  1197. * This is deprecated and may be removed.
  1198. *
  1199. * @param FormOptions $opts
  1200. * @return bool True if this change was mode
  1201. */
  1202. private function fixBackwardsCompatibilityOptions( FormOptions $opts ) {
  1203. if ( $opts['hideanons'] && $opts['hideliu'] ) {
  1204. $opts->reset( 'hideanons' );
  1205. if ( !$opts['hidebots'] ) {
  1206. $opts->reset( 'hideliu' );
  1207. $opts['hidehumans'] = 1;
  1208. }
  1209. return true;
  1210. }
  1211. return false;
  1212. }
  1213. /**
  1214. * Replace old options with their structured UI equivalents
  1215. *
  1216. * @param FormOptions $opts
  1217. * @return bool True if the change was made
  1218. */
  1219. public function replaceOldOptions( FormOptions $opts ) {
  1220. if ( !$this->isStructuredFilterUiEnabled() ) {
  1221. return false;
  1222. }
  1223. $changed = false;
  1224. // At this point 'hideanons' and 'hideliu' cannot be both true,
  1225. // because fixBackwardsCompatibilityOptions resets (at least) 'hideanons' in such case
  1226. if ( $opts[ 'hideanons' ] ) {
  1227. $opts->reset( 'hideanons' );
  1228. $opts[ 'userExpLevel' ] = 'registered';
  1229. $changed = true;
  1230. }
  1231. if ( $opts[ 'hideliu' ] ) {
  1232. $opts->reset( 'hideliu' );
  1233. $opts[ 'userExpLevel' ] = 'unregistered';
  1234. $changed = true;
  1235. }
  1236. if ( $this->getFilterGroup( 'legacyReviewStatus' ) ) {
  1237. if ( $opts[ 'hidepatrolled' ] ) {
  1238. $opts->reset( 'hidepatrolled' );
  1239. $opts[ 'reviewStatus' ] = 'unpatrolled';
  1240. $changed = true;
  1241. }
  1242. if ( $opts[ 'hideunpatrolled' ] ) {
  1243. $opts->reset( 'hideunpatrolled' );
  1244. $opts[ 'reviewStatus' ] = implode(
  1245. ChangesListStringOptionsFilterGroup::SEPARATOR,
  1246. [ 'manual', 'auto' ]
  1247. );
  1248. $changed = true;
  1249. }
  1250. }
  1251. return $changed;
  1252. }
  1253. /**
  1254. * Convert parameters values from true/false to 1/0
  1255. * so they are not omitted by wfArrayToCgi()
  1256. * Bug 36524
  1257. *
  1258. * @param array $params
  1259. * @return array
  1260. */
  1261. protected function convertParamsForLink( $params ) {
  1262. foreach ( $params as &$value ) {
  1263. if ( $value === false ) {
  1264. $value = '0';
  1265. }
  1266. }
  1267. unset( $value );
  1268. return $params;
  1269. }
  1270. /**
  1271. * Sets appropriate tables, fields, conditions, etc. depending on which filters
  1272. * the user requested.
  1273. *
  1274. * @param array &$tables Array of tables; see IDatabase::select $table
  1275. * @param array &$fields Array of fields; see IDatabase::select $vars
  1276. * @param array &$conds Array of conditions; see IDatabase::select $conds
  1277. * @param array &$query_options Array of query options; see IDatabase::select $options
  1278. * @param array &$join_conds Array of join conditions; see IDatabase::select $join_conds
  1279. * @param FormOptions $opts
  1280. */
  1281. protected function buildQuery( &$tables, &$fields, &$conds, &$query_options,
  1282. &$join_conds, FormOptions $opts
  1283. ) {
  1284. $dbr = $this->getDB();
  1285. $isStructuredUI = $this->isStructuredFilterUiEnabled();
  1286. /** @var ChangesListFilterGroup $filterGroup */
  1287. foreach ( $this->filterGroups as $filterGroup ) {
  1288. $filterGroup->modifyQuery( $dbr, $this, $tables, $fields, $conds,
  1289. $query_options, $join_conds, $opts, $isStructuredUI );
  1290. }
  1291. // Namespace filtering
  1292. if ( $opts[ 'namespace' ] !== '' ) {
  1293. $namespaces = explode( ';', $opts[ 'namespace' ] );
  1294. if ( $opts[ 'associated' ] ) {
  1295. $associatedNamespaces = array_map(
  1296. function ( $ns ) {
  1297. return MWNamespace::getAssociated( $ns );
  1298. },
  1299. $namespaces
  1300. );
  1301. $namespaces = array_unique( array_merge( $namespaces, $associatedNamespaces ) );
  1302. }
  1303. if ( count( $namespaces ) === 1 ) {
  1304. $operator = $opts[ 'invert' ] ? '!=' : '=';
  1305. $value = $dbr->addQuotes( reset( $namespaces ) );
  1306. } else {
  1307. $operator = $opts[ 'invert' ] ? 'NOT IN' : 'IN';
  1308. sort( $namespaces );
  1309. $value = '(' . $dbr->makeList( $namespaces ) . ')';
  1310. }
  1311. $conds[] = "rc_namespace $operator $value";
  1312. }
  1313. // Calculate cutoff
  1314. $cutoff_unixtime = time() - $opts['days'] * 3600 * 24;
  1315. $cutoff = $dbr->timestamp( $cutoff_unixtime );
  1316. $fromValid = preg_match( '/^[0-9]{14}$/', $opts['from'] );
  1317. if ( $fromValid && $opts['from'] > wfTimestamp( TS_MW, $cutoff ) ) {
  1318. $cutoff = $dbr->timestamp( $opts['from'] );
  1319. } else {
  1320. $opts->reset( 'from' );
  1321. }
  1322. $conds[] = 'rc_timestamp >= ' . $dbr->addQuotes( $cutoff );
  1323. }
  1324. /**
  1325. * Process the query
  1326. *
  1327. * @param array $tables Array of tables; see IDatabase::select $table
  1328. * @param array $fields Array of fields; see IDatabase::select $vars
  1329. * @param array $conds Array of conditions; see IDatabase::select $conds
  1330. * @param array $query_options Array of query options; see IDatabase::select $options
  1331. * @param array $join_conds Array of join conditions; see IDatabase::select $join_conds
  1332. * @param FormOptions $opts
  1333. * @return bool|IResultWrapper Result or false
  1334. */
  1335. protected function doMainQuery( $tables, $fields, $conds,
  1336. $query_options, $join_conds, FormOptions $opts
  1337. ) {
  1338. $rcQuery = RecentChange::getQueryInfo();
  1339. $tables = array_merge( $tables, $rcQuery['tables'] );
  1340. $fields = array_merge( $rcQuery['fields'], $fields );
  1341. $join_conds = array_merge( $join_conds, $rcQuery['joins'] );
  1342. ChangeTags::modifyDisplayQuery(
  1343. $tables,
  1344. $fields,
  1345. $conds,
  1346. $join_conds,
  1347. $query_options,
  1348. ''
  1349. );
  1350. if ( !$this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds,
  1351. $opts )
  1352. ) {
  1353. return false;
  1354. }
  1355. $dbr = $this->getDB();
  1356. return $dbr->select(
  1357. $tables,
  1358. $fields,
  1359. $conds,
  1360. __METHOD__,
  1361. $query_options,
  1362. $join_conds
  1363. );
  1364. }
  1365. protected function runMainQueryHook( &$tables, &$fields, &$conds,
  1366. &$query_options, &$join_conds, $opts
  1367. ) {
  1368. return Hooks::run(
  1369. 'ChangesListSpecialPageQuery',
  1370. [ $this->getName(), &$tables, &$fields, &$conds, &$query_options, &$join_conds, $opts ]
  1371. );
  1372. }
  1373. /**
  1374. * Return a IDatabase object for reading
  1375. *
  1376. * @return IDatabase
  1377. */
  1378. protected function getDB() {
  1379. return wfGetDB( DB_REPLICA );
  1380. }
  1381. /**
  1382. * Send header output to the OutputPage object, only called if not using feeds
  1383. *
  1384. * @param int $rowCount Number of database rows
  1385. * @param FormOptions $opts
  1386. */
  1387. private function webOutputHeader( $rowCount, $opts ) {
  1388. if ( !$this->including() ) {
  1389. $this->outputFeedLinks();
  1390. $this->doHeader( $opts, $rowCount );
  1391. }
  1392. }
  1393. /**
  1394. * Send output to the OutputPage object, only called if not used feeds
  1395. *
  1396. * @param IResultWrapper $rows Database rows
  1397. * @param FormOptions $opts
  1398. */
  1399. public function webOutput( $rows, $opts ) {
  1400. $this->webOutputHeader( $rows->numRows(), $opts );
  1401. $this->outputChangesList( $rows, $opts );
  1402. }
  1403. /**
  1404. * Output feed links.
  1405. */
  1406. public function outputFeedLinks() {
  1407. // nothing by default
  1408. }
  1409. /**
  1410. * Build and output the actual changes list.
  1411. *
  1412. * @param IResultWrapper $rows Database rows
  1413. * @param FormOptions $opts
  1414. */
  1415. abstract public function outputChangesList( $rows, $opts );
  1416. /**
  1417. * Set the text to be displayed above the changes
  1418. *
  1419. * @param FormOptions $opts
  1420. * @param int $numRows Number of rows in the result to show after this header
  1421. */
  1422. public function doHeader( $opts, $numRows ) {
  1423. $this->setTopText( $opts );
  1424. // @todo Lots of stuff should be done here.
  1425. $this->setBottomText( $opts );
  1426. }
  1427. /**
  1428. * Send the text to be displayed before the options. Should use $this->getOutput()->addWikiText()
  1429. * or similar methods to print the text.
  1430. *
  1431. * @param FormOptions $opts
  1432. */
  1433. public function setTopText( FormOptions $opts ) {
  1434. // nothing by default
  1435. }
  1436. /**
  1437. * Send the text to be displayed after the options. Should use $this->getOutput()->addWikiText()
  1438. * or similar methods to print the text.
  1439. *
  1440. * @param FormOptions $opts
  1441. */
  1442. public function setBottomText( FormOptions $opts ) {
  1443. // nothing by default
  1444. }
  1445. /**
  1446. * Get options to be displayed in a form
  1447. * @todo This should handle options returned by getDefaultOptions().
  1448. * @todo Not called by anything in this class (but is in subclasses), should be
  1449. * called by something… doHeader() maybe?
  1450. *
  1451. * @param FormOptions $opts
  1452. * @return array
  1453. */
  1454. public function getExtraOptions( $opts ) {
  1455. return [];
  1456. }
  1457. /**
  1458. * Return the legend displayed within the fieldset
  1459. *
  1460. * @return string
  1461. */
  1462. public function makeLegend() {
  1463. $context = $this->getContext();
  1464. $user = $context->getUser();
  1465. # The legend showing what the letters and stuff mean
  1466. $legend = Html::openElement( 'dl' ) . "\n";
  1467. # Iterates through them and gets the messages for both letter and tooltip
  1468. $legendItems = $context->getConfig()->get( 'RecentChangesFlags' );
  1469. if ( !( $user->useRCPatrol() || $user->useNPPatrol() ) ) {
  1470. unset( $legendItems['unpatrolled'] );
  1471. }
  1472. foreach ( $legendItems as $key => $item ) { # generate items of the legend
  1473. $label = $item['legend'] ?? $item['title'];
  1474. $letter = $item['letter'];
  1475. $cssClass = $item['class'] ?? $key;
  1476. $legend .= Html::element( 'dt',
  1477. [ 'class' => $cssClass ], $context->msg( $letter )->text()
  1478. ) . "\n" .
  1479. Html::rawElement( 'dd',
  1480. [ 'class' => Sanitizer::escapeClass( 'mw-changeslist-legend-' . $key ) ],
  1481. $context->msg( $label )->parse()
  1482. ) . "\n";
  1483. }
  1484. # (+-123)
  1485. $legend .= Html::rawElement( 'dt',
  1486. [ 'class' => 'mw-plusminus-pos' ],
  1487. $context->msg( 'recentchanges-legend-plusminus' )->parse()
  1488. ) . "\n";
  1489. $legend .= Html::element(
  1490. 'dd',
  1491. [ 'class' => 'mw-changeslist-legend-plusminus' ],
  1492. $context->msg( 'recentchanges-label-plusminus' )->text()
  1493. ) . "\n";
  1494. $legend .= Html::closeElement( 'dl' ) . "\n";
  1495. $legendHeading = $this->isStructuredFilterUiEnabled() ?
  1496. $context->msg( 'rcfilters-legend-heading' )->parse() :
  1497. $context->msg( 'recentchanges-legend-heading' )->parse();
  1498. # Collapsible
  1499. $collapsedState = $this->getRequest()->getCookie( 'changeslist-state' );
  1500. $collapsedClass = $collapsedState === 'collapsed' ? ' mw-collapsed' : '';
  1501. $legend =
  1502. '<div class="mw-changeslist-legend mw-collapsible' . $collapsedClass . '">' .
  1503. $legendHeading .
  1504. '<div class="mw-collapsible-content">' . $legend . '</div>' .
  1505. '</div>';
  1506. return $legend;
  1507. }
  1508. /**
  1509. * Add page-specific modules.
  1510. */
  1511. protected function addModules() {
  1512. $out = $this->getOutput();
  1513. // Styles and behavior for the legend box (see makeLegend())
  1514. $out->addModuleStyles( [
  1515. 'mediawiki.special.changeslist.legend',
  1516. 'mediawiki.special.changeslist',
  1517. ] );
  1518. $out->addModules( 'mediawiki.special.changeslist.legend.js' );
  1519. if ( $this->isStructuredFilterUiEnabled() && !$this->including() ) {
  1520. $out->addModules( 'mediawiki.rcfilters.filters.ui' );
  1521. $out->addModuleStyles( 'mediawiki.rcfilters.filters.base.styles' );
  1522. }
  1523. }
  1524. protected function getGroupName() {
  1525. return 'changes';
  1526. }
  1527. /**
  1528. * Filter on users' experience levels; this will not be called if nothing is
  1529. * selected.
  1530. *
  1531. * @param string $specialPageClassName Class name of current special page
  1532. * @param IContextSource $context Context, for e.g. user
  1533. * @param IDatabase $dbr Database, for addQuotes, makeList, and similar
  1534. * @param array &$tables Array of tables; see IDatabase::select $table
  1535. * @param array &$fields Array of fields; see IDatabase::select $vars
  1536. * @param array &$conds Array of conditions; see IDatabase::select $conds
  1537. * @param array &$query_options Array of query options; see IDatabase::select $options
  1538. * @param array &$join_conds Array of join conditions; see IDatabase::select $join_conds
  1539. * @param array $selectedExpLevels The allowed active values, sorted
  1540. * @param int $now Number of seconds since the UNIX epoch, or 0 if not given
  1541. * (optional)
  1542. */
  1543. public function filterOnUserExperienceLevel( $specialPageClassName, $context, $dbr,
  1544. &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedExpLevels, $now = 0
  1545. ) {
  1546. global $wgLearnerEdits,
  1547. $wgExperiencedUserEdits,
  1548. $wgLearnerMemberSince,
  1549. $wgExperiencedUserMemberSince;
  1550. $LEVEL_COUNT = 5;
  1551. // If all levels are selected, don't filter
  1552. if ( count( $selectedExpLevels ) === $LEVEL_COUNT ) {
  1553. return;
  1554. }
  1555. // both 'registered' and 'unregistered', experience levels, if any, are included in 'registered'
  1556. if (
  1557. in_array( 'registered', $selectedExpLevels ) &&
  1558. in_array( 'unregistered', $selectedExpLevels )
  1559. ) {
  1560. return;
  1561. }
  1562. $actorMigration = ActorMigration::newMigration();
  1563. $actorQuery = $actorMigration->getJoin( 'rc_user' );
  1564. $tables += $actorQuery['tables'];
  1565. $join_conds += $actorQuery['joins'];
  1566. // 'registered' but not 'unregistered', experience levels, if any, are included in 'registered'
  1567. if (
  1568. in_array( 'registered', $selectedExpLevels ) &&
  1569. !in_array( 'unregistered', $selectedExpLevels )
  1570. ) {
  1571. $conds[] = $actorMigration->isNotAnon( $actorQuery['fields']['rc_user'] );
  1572. return;
  1573. }
  1574. if ( $selectedExpLevels === [ 'unregistered' ] ) {
  1575. $conds[] = $actorMigration->isAnon( $actorQuery['fields']['rc_user'] );
  1576. return;
  1577. }
  1578. $tables[] = 'user';
  1579. $join_conds['user'] = [ 'LEFT JOIN', $actorQuery['fields']['rc_user'] . ' = user_id' ];
  1580. if ( $now === 0 ) {
  1581. $now = time();
  1582. }
  1583. $secondsPerDay = 86400;
  1584. $learnerCutoff = $now - $wgLearnerMemberSince * $secondsPerDay;
  1585. $experiencedUserCutoff = $now - $wgExperiencedUserMemberSince * $secondsPerDay;
  1586. $aboveNewcomer = $dbr->makeList(
  1587. [
  1588. 'user_editcount >= ' . intval( $wgLearnerEdits ),
  1589. 'user_registration <= ' . $dbr->addQuotes( $dbr->timestamp( $learnerCutoff ) ),
  1590. ],
  1591. IDatabase::LIST_AND
  1592. );
  1593. $aboveLearner = $dbr->makeList(
  1594. [
  1595. 'user_editcount >= ' . intval( $wgExperiencedUserEdits ),
  1596. 'user_registration <= ' .
  1597. $dbr->addQuotes( $dbr->timestamp( $experiencedUserCutoff ) ),
  1598. ],
  1599. IDatabase::LIST_AND
  1600. );
  1601. $conditions = [];
  1602. if ( in_array( 'unregistered', $selectedExpLevels ) ) {
  1603. $selectedExpLevels = array_diff( $selectedExpLevels, [ 'unregistered' ] );
  1604. $conditions[] = $actorMigration->isAnon( $actorQuery['fields']['rc_user'] );
  1605. }
  1606. if ( $selectedExpLevels === [ 'newcomer' ] ) {
  1607. $conditions[] = "NOT ( $aboveNewcomer )";
  1608. } elseif ( $selectedExpLevels === [ 'learner' ] ) {
  1609. $conditions[] = $dbr->makeList(
  1610. [ $aboveNewcomer, "NOT ( $aboveLearner )" ],
  1611. IDatabase::LIST_AND
  1612. );
  1613. } elseif ( $selectedExpLevels === [ 'experienced' ] ) {
  1614. $conditions[] = $aboveLearner;
  1615. } elseif ( $selectedExpLevels === [ 'learner', 'newcomer' ] ) {
  1616. $conditions[] = "NOT ( $aboveLearner )";
  1617. } elseif ( $selectedExpLevels === [ 'experienced', 'newcomer' ] ) {
  1618. $conditions[] = $dbr->makeList(
  1619. [ "NOT ( $aboveNewcomer )", $aboveLearner ],
  1620. IDatabase::LIST_OR
  1621. );
  1622. } elseif ( $selectedExpLevels === [ 'experienced', 'learner' ] ) {
  1623. $conditions[] = $aboveNewcomer;
  1624. } elseif ( $selectedExpLevels === [ 'experienced', 'learner', 'newcomer' ] ) {
  1625. $conditions[] = $actorMigration->isNotAnon( $actorQuery['fields']['rc_user'] );
  1626. }
  1627. if ( count( $conditions ) > 1 ) {
  1628. $conds[] = $dbr->makeList( $conditions, IDatabase::LIST_OR );
  1629. } elseif ( count( $conditions ) === 1 ) {
  1630. $conds[] = reset( $conditions );
  1631. }
  1632. }
  1633. /**
  1634. * Check whether the structured filter UI is enabled
  1635. *
  1636. * @return bool
  1637. */
  1638. public function isStructuredFilterUiEnabled() {
  1639. if ( $this->getRequest()->getBool( 'rcfilters' ) ) {
  1640. return true;
  1641. }
  1642. return static::checkStructuredFilterUiEnabled(
  1643. $this->getConfig(),
  1644. $this->getUser()
  1645. );
  1646. }
  1647. /**
  1648. * Check whether the structured filter UI is enabled by default (regardless of
  1649. * this particular user's setting)
  1650. *
  1651. * @return bool
  1652. */
  1653. public function isStructuredFilterUiEnabledByDefault() {
  1654. if ( $this->getConfig()->get( 'StructuredChangeFiltersShowPreference' ) ) {
  1655. return !$this->getUser()->getDefaultOption( 'rcenhancedfilters-disable' );
  1656. } else {
  1657. return $this->getUser()->getDefaultOption( 'rcenhancedfilters' );
  1658. }
  1659. }
  1660. /**
  1661. * Static method to check whether StructuredFilter UI is enabled for the given user
  1662. *
  1663. * @since 1.31
  1664. * @param Config $config
  1665. * @param User $user
  1666. * @return bool
  1667. */
  1668. public static function checkStructuredFilterUiEnabled( Config $config, User $user ) {
  1669. if ( $config->get( 'StructuredChangeFiltersShowPreference' ) ) {
  1670. return !$user->getOption( 'rcenhancedfilters-disable' );
  1671. } else {
  1672. return $user->getOption( 'rcenhancedfilters' );
  1673. }
  1674. }
  1675. /**
  1676. * Get the default value of the number of changes to display when loading
  1677. * the result set.
  1678. *
  1679. * @since 1.30
  1680. * @return int
  1681. */
  1682. public function getDefaultLimit() {
  1683. return $this->getUser()->getIntOption( static::$limitPreferenceName );
  1684. }
  1685. /**
  1686. * Get the default value of the number of days to display when loading
  1687. * the result set.
  1688. * Supports fractional values, and should be cast to a float.
  1689. *
  1690. * @since 1.30
  1691. * @return float
  1692. */
  1693. public function getDefaultDays() {
  1694. return floatval( $this->getUser()->getOption( static::$daysPreferenceName ) );
  1695. }
  1696. }