aboutsummaryrefslogtreecommitdiffstats
path: root/includes/api
diff options
context:
space:
mode:
authorAmmar Abdulhamid <ammarpad@yahoo.com>2020-08-23 01:28:34 +0100
committerAmmar Abdulhamid <ammarpad@yahoo.com>2020-09-29 16:20:20 +0100
commit07e547f47cae761489a33e9ebb8a9b108298f34e (patch)
tree04da4a227c70c61afb3152ba6fca29f62e58c6dc /includes/api
parentfcd843b5aad0c6df91537b1a8c21bb3f2be1af7d (diff)
downloadmediawikicore-07e547f47cae761489a33e9ebb8a9b108298f34e.tar.gz
mediawikicore-07e547f47cae761489a33e9ebb8a9b108298f34e.zip
ApiEditPage: Show existing watchlist expiry if status is not being changed.
Bug: T261030 Change-Id: I795db12aefeffb1cfbbe2ab00fbb19444df7d37b
Diffstat (limited to 'includes/api')
-rw-r--r--includes/api/ApiEditPage.php29
-rw-r--r--includes/api/ApiMain.php7
-rw-r--r--includes/api/ApiWatchlistTrait.php26
3 files changed, 54 insertions, 8 deletions
diff --git a/includes/api/ApiEditPage.php b/includes/api/ApiEditPage.php
index b327520d2f47..b9b27fbd22b7 100644
--- a/includes/api/ApiEditPage.php
+++ b/includes/api/ApiEditPage.php
@@ -38,11 +38,20 @@ class ApiEditPage extends ApiBase {
use ApiWatchlistTrait;
- public function __construct( ApiMain $mainModule, $moduleName, $modulePrefix = '' ) {
+ /** @var WatchedItemStoreInterface */
+ private $watchedItemStore;
+
+ public function __construct(
+ ApiMain $mainModule,
+ $moduleName,
+ WatchedItemStore $watchedItemStore,
+ $modulePrefix = ''
+ ) {
parent::__construct( $mainModule, $moduleName, $modulePrefix );
$this->watchlistExpiryEnabled = $this->getConfig()->get( 'WatchlistExpiry' );
$this->watchlistMaxDuration = $this->getConfig()->get( 'WatchlistExpiryMaxDuration' );
+ $this->watchedItemStore = $watchedItemStore;
}
public function execute() {
@@ -370,7 +379,6 @@ class ApiEditPage extends ApiBase {
}
$watch = $this->getWatchlistValue( $params['watchlist'], $titleObj, $user );
- $watchlistExpiry = $params['watchlistexpiry'] ?? null;
// Deprecated parameters
if ( $params['watch'] ) {
@@ -380,9 +388,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;
}
}
@@ -500,10 +509,16 @@ class ApiEditPage extends ApiBase {
}
if ( $watch ) {
- $r['watched'] = $status->isOK();
+ $r['watched'] = true;
- if ( $this->watchlistExpiryEnabled ) {
- $r['watchlistexpiry'] = ApiResult::formatExpiry( $watchlistExpiry );
+ $watchlistExpiry = $this->getWatchlistExpiry(
+ $this->watchedItemStore,
+ $titleObj,
+ $user
+ );
+
+ if ( $watchlistExpiry ) {
+ $r['watchlistexpiry'] = $watchlistExpiry;
}
}
break;
diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php
index a91113bef8d6..641f2820565a 100644
--- a/includes/api/ApiMain.php
+++ b/includes/api/ApiMain.php
@@ -111,7 +111,12 @@ class ApiMain extends ApiBase {
]
],
'move' => ApiMove::class,
- 'edit' => ApiEditPage::class,
+ 'edit' => [
+ 'class' => ApiEditPage::class,
+ 'services' => [
+ 'WatchedItemStore'
+ ],
+ ],
'upload' => ApiUpload::class,
'filerevert' => ApiFileRevert::class,
'emailuser' => ApiEmailUser::class,
diff --git a/includes/api/ApiWatchlistTrait.php b/includes/api/ApiWatchlistTrait.php
index 675414e3c8da..1ab84d48afb1 100644
--- a/includes/api/ApiWatchlistTrait.php
+++ b/includes/api/ApiWatchlistTrait.php
@@ -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;
+ }
}