Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F7427188
ApiDiscussionToolsSubscribe.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
ApiDiscussionToolsSubscribe.php
View Options
<?php
namespace
MediaWiki\Extension\DiscussionTools
;
use
MediaWiki\Api\ApiBase
;
use
MediaWiki\Api\ApiMain
;
use
MediaWiki\Api\ApiUsageException
;
use
MediaWiki\Title\Title
;
use
Wikimedia\ParamValidator\ParamValidator
;
class
ApiDiscussionToolsSubscribe
extends
ApiBase
{
private
SubscriptionStore
$subscriptionStore
;
public
function
__construct
(
ApiMain
$main
,
string
$name
,
SubscriptionStore
$subscriptionStore
)
{
parent
::
__construct
(
$main
,
$name
);
$this
->
subscriptionStore
=
$subscriptionStore
;
}
/**
* @inheritDoc
* @throws ApiUsageException
*/
public
function
execute
()
{
$user
=
$this
->
getUser
();
if
(
!
$user
->
isNamed
()
)
{
$this
->
dieWithError
(
'apierror-mustbeloggedin-generic'
,
'notloggedin'
);
}
$params
=
$this
->
extractRequestParams
();
$title
=
Title
::
newFromText
(
$params
[
'page'
]
);
$result
=
null
;
if
(
!
$title
)
{
$this
->
dieWithError
(
[
'apierror-invalidtitle'
,
wfEscapeWikiText
(
$params
[
'page'
]
)
]
);
}
$commentName
=
$params
[
'commentname'
];
$subscribe
=
$params
[
'subscribe'
];
if
(
$subscribe
)
{
$success
=
$this
->
subscriptionStore
->
addSubscriptionForUser
(
$user
,
$title
,
$commentName
);
if
(
!
$success
)
{
$this
->
dieWithError
(
'apierror-discussiontools-subscription-failed-add'
,
'subscription-failed'
);
}
}
else
{
$success
=
$this
->
subscriptionStore
->
removeSubscriptionForUser
(
$user
,
$commentName
);
if
(
!
$success
)
{
$this
->
dieWithError
(
'apierror-discussiontools-subscription-failed-remove'
,
'subscription-failed'
);
}
}
$result
=
[
'page'
=>
$title
,
'commentname'
=>
$commentName
,
'subscribe'
=>
$subscribe
,
];
$this
->
getResult
()->
addValue
(
null
,
$this
->
getModuleName
(),
$result
);
}
/**
* @inheritDoc
*/
public
function
getAllowedParams
()
{
return
[
'page'
=>
[
ParamValidator
::
PARAM_REQUIRED
=>
true
,
],
'token'
=>
[
ParamValidator
::
PARAM_REQUIRED
=>
true
,
],
'commentname'
=>
[
ParamValidator
::
PARAM_REQUIRED
=>
true
,
],
'subscribe'
=>
[
ParamValidator
::
PARAM_TYPE
=>
'boolean'
,
ParamValidator
::
PARAM_REQUIRED
=>
true
,
],
];
}
/**
* @inheritDoc
*/
public
function
needsToken
()
{
return
'csrf'
;
}
/**
* @inheritDoc
*/
public
function
isWriteMode
()
{
return
true
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, Nov 22, 08:50 (17 h, 32 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
3f/0f/540ef1ae267c4d800fb3d3e8d0a3
Default Alt Text
ApiDiscussionToolsSubscribe.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment