Avoid SpecialPage::getConfig in constructor on Special:Watchlist/EditWatchlist

The context source is not set at this point and the global request is
used and logged:
SpecialPage::getContext called and $mContext is null. Using
RequestContext::getMain(); for sanity

Change-Id: Ia1ce0a6f379dfeaa76d831d169ed97c059c48533
This commit is contained in:
Umherirrender 2021-04-19 22:19:13 +02:00
parent f60ea069ba
commit 23144f495a
2 changed files with 7 additions and 18 deletions

View file

@ -77,9 +77,6 @@ class SpecialEditWatchlist extends UnlistedSpecialPage {
/** @var WatchlistManager */
private $watchlistManager;
/** @var bool Watchlist Expiry flag */
private $isWatchlistExpiryEnabled;
/**
* @param WatchedItemStoreInterface|null $watchedItemStore
* @param TitleParser|null $titleParser
@ -108,7 +105,6 @@ class SpecialEditWatchlist extends UnlistedSpecialPage {
$this->nsInfo = $nsInfo ?? $services->getNamespaceInfo();
$this->wikiPageFactory = $wikiPageFactory ?? $services->getWikiPageFactory();
$this->watchlistManager = $watchlistManager ?? $services->getWatchlistManager();
$this->isWatchlistExpiryEnabled = $this->getConfig()->get( 'WatchlistExpiry' );
}
public function doesWrites() {
@ -439,7 +435,7 @@ class SpecialEditWatchlist extends UnlistedSpecialPage {
$titles = [];
$options = [ 'sort' => WatchedItemStore::SORT_ASC ];
if ( $this->isWatchlistExpiryEnabled ) {
if ( $this->getConfig()->get( 'WatchlistExpiry' ) ) {
$options[ 'sortByExpiry'] = true;
}
@ -736,7 +732,7 @@ class SpecialEditWatchlist extends UnlistedSpecialPage {
}
$watchlistExpiringMessage = '';
if ( $this->isWatchlistExpiryEnabled && $expiryDaysText ) {
if ( $this->getConfig()->get( 'WatchlistExpiry' ) && $expiryDaysText ) {
$watchlistExpiringMessage = Html::element(
'span',
[ 'class' => 'mw-watchlistexpiry-msg' ],

View file

@ -39,9 +39,6 @@ class SpecialWatchlist extends ChangesListSpecialPage {
protected static $limitPreferenceName = 'wllimit';
protected static $collapsedPreferenceName = 'rcfilters-wl-collapsed';
/** @var float|int */
private $maxDays;
/** @var WatchedItemStoreInterface */
private $watchedItemStore;
@ -54,9 +51,6 @@ class SpecialWatchlist extends ChangesListSpecialPage {
/** @var UserOptionsLookup */
private $userOptionsLookup;
/** @var bool Watchlist Expiry flag */
private $isWatchlistExpiryEnabled;
/**
* @param WatchedItemStoreInterface $watchedItemStore
* @param WatchlistManager $watchlistManager
@ -75,8 +69,6 @@ class SpecialWatchlist extends ChangesListSpecialPage {
$this->watchlistManager = $watchlistManager;
$this->loadBalancer = $loadBalancer;
$this->userOptionsLookup = $userOptionsLookup;
$this->maxDays = $this->getConfig()->get( 'RCMaxAge' ) / ( 3600 * 24 );
$this->isWatchlistExpiryEnabled = $this->getConfig()->get( 'WatchlistExpiry' );
}
public function doesWrites() {
@ -406,7 +398,7 @@ class SpecialWatchlist extends ChangesListSpecialPage {
$join_conds
);
if ( $this->isWatchlistExpiryEnabled ) {
if ( $this->getConfig()->get( 'WatchlistExpiry' ) ) {
$tables[] = 'watchlist_expiry';
$fields[] = 'we_expiry';
$join_conds['watchlist_expiry'] = [ 'LEFT JOIN', 'wl_id = we_item' ];
@ -544,7 +536,7 @@ class SpecialWatchlist extends ChangesListSpecialPage {
$unwatchTooltipMessage = 'tooltip-ca-unwatch';
$diffInDays = null;
// Check if the watchlist expiry flag is enabled to show new tooltip message
if ( $this->isWatchlistExpiryEnabled ) {
if ( $this->getConfig()->get( 'WatchlistExpiry' ) ) {
$watchedItem = $this->watchedItemStore->getWatchedItem( $this->getUser(), $rc->getTitle() );
if ( $watchedItem instanceof WatchedItem && $watchedItem->getExpiry() !== null ) {
$diffInDays = $watchedItem->getExpiryInDays();
@ -797,8 +789,9 @@ class SpecialWatchlist extends ChangesListSpecialPage {
private function cutoffselector( $options ) {
$selected = (float)$options['days'];
$maxDays = $this->getConfig()->get( 'RCMaxAge' ) / ( 3600 * 24 );
if ( $selected <= 0 ) {
$selected = $this->maxDays;
$selected = $maxDays;
}
$selectedHours = round( $selected * 24 );
@ -812,7 +805,7 @@ class SpecialWatchlist extends ChangesListSpecialPage {
72,
168,
24 * (float)$this->userOptionsLookup->getOption( $this->getUser(), 'watchlistdays', 0 ),
24 * $this->maxDays,
24 * $maxDays,
$selectedHours
] ) );
asort( $hours );