Revert "Revert "ApiEditPage: Show existing watchlist expiry if status
is not being changed.""
This reverts commit 149e99f072.
It's not necessary to change the constructor now, the module is already
using service locator to fetch RevisionLookup and ContentHandlerFactory.
The WatchedItemStore can also be gotten from there, voiding the need for
altering the constructor now. As Daniel said in T259960#6380471 dependency
injection for API modules is good but not urgent.
Bug: T261030
Bug: T264200
Change-Id: I16aa942cc800cd66a2cd538680a02b10cb0b1bfe
This commit is contained in:
parent
e3d4f1db9b
commit
30b947ad5f
2 changed files with 39 additions and 6 deletions
|
|
@ -366,7 +366,6 @@ class ApiEditPage extends ApiBase {
|
|||
}
|
||||
|
||||
$watch = $this->getWatchlistValue( $params['watchlist'], $titleObj, $user );
|
||||
$watchlistExpiry = $params['watchlistexpiry'] ?? null;
|
||||
|
||||
// Deprecated parameters
|
||||
if ( $params['watch'] ) {
|
||||
|
|
@ -376,9 +375,10 @@ class ApiEditPage extends ApiBase {
|
|||
}
|
||||
|
||||
if ( $watch ) {
|
||||
$requestArray['wpWatchthis'] = '';
|
||||
$requestArray['wpWatchthis'] = true;
|
||||
$watchlistExpiry = $this->getExpiryFromParams( $params );
|
||||
|
||||
if ( $this->watchlistExpiryEnabled && $watchlistExpiry ) {
|
||||
if ( $watchlistExpiry ) {
|
||||
$requestArray['wpWatchlistExpiry'] = $watchlistExpiry;
|
||||
}
|
||||
}
|
||||
|
|
@ -496,10 +496,17 @@ class ApiEditPage extends ApiBase {
|
|||
}
|
||||
|
||||
if ( $watch ) {
|
||||
$r['watched'] = $status->isOK();
|
||||
$r['watched'] = true;
|
||||
|
||||
if ( $this->watchlistExpiryEnabled ) {
|
||||
$r['watchlistexpiry'] = ApiResult::formatExpiry( $watchlistExpiry );
|
||||
$watchedItemStore = MediaWikiServices::getInstance()->getWatchedItemStore();
|
||||
$watchlistExpiry = $this->getWatchlistExpiry(
|
||||
$watchedItemStore,
|
||||
$titleObj,
|
||||
$user
|
||||
);
|
||||
|
||||
if ( $watchlistExpiry ) {
|
||||
$r['watchlistexpiry'] = $watchlistExpiry;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -140,4 +140,30 @@ trait ApiWatchlistTrait {
|
|||
|
||||
return $watchlistExpiry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get existing expiry from the database.
|
||||
*
|
||||
* @param WatchedItemStoreInterface $store
|
||||
* @param Title $title
|
||||
* @param User $user The user to get the expiry for.
|
||||
* @return string|null
|
||||
*/
|
||||
protected function getWatchlistExpiry(
|
||||
WatchedItemStoreInterface $store,
|
||||
Title $title,
|
||||
User $user
|
||||
): ?string {
|
||||
$watchedItem = $store->getWatchedItem( $user, $title );
|
||||
|
||||
if ( $watchedItem ) {
|
||||
$expiry = $watchedItem->getExpiry();
|
||||
|
||||
if ( $expiry !== null ) {
|
||||
return ApiResult::formatExpiry( $expiry );
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue