Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Community
WSSlots
Commits
0db7ef7f
Commit
0db7ef7f
authored
Aug 17, 2022
by
Marijn van Wezel
❤
Browse files
Merge branch '4.1.0' into 'master'
Merge 'add-read-api' branch See merge request
!9
parents
a2e7f2c4
d5fcde8d
Pipeline
#4157
passed with stages
in 27 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
extension.json
View file @
0db7ef7f
{
"name"
:
"WSSlots"
,
"version"
:
"4.
0
.0"
,
"version"
:
"4.
1
.0"
,
"namemsg"
:
"wsslots-extensionname"
,
"url"
:
"https://wikibase-solutions.com"
,
"type"
:
"other"
,
...
...
@@ -58,8 +58,9 @@
}
},
"APIModules"
:
{
"editslot"
:
"WSSlots
\\
ApiEditSlot"
,
"parsetemplates"
:
"WSSlots
\\
ApiParseTemplates"
"parsetemplates"
:
"WSSlots
\\
API
\\
ApiParseTemplates"
,
"editslot"
:
"WSSlots
\\
API
\\
ApiEditSlot"
,
"readslot"
:
"WSSlots
\\
API
\\
ApiReadSlot"
},
"manifest_version"
:
2
,
"load_composer_autoloader"
:
true
...
...
i18n/en.json
View file @
0db7ef7f
...
...
@@ -21,7 +21,13 @@
"apihelp-parsetemplates-param-pageid"
:
"Page ID of the page to parse. Cannot be used together with title or oldid."
,
"apihelp-parsetemplates-param-oldid"
:
"Revision ID of the content to parse. Cannot be used together with title or pageid."
,
"apihelp-parsetemplates-param-slot"
:
"The name of the slot to parse."
,
"apihelp-readslot-summary"
:
"Read slots on pages."
,
"apihelp-readslot-param-title"
:
"Title of the page to read. Cannot be used together with pageid."
,
"apihelp-readslot-param-pageid"
:
"Page ID of the page to read. Cannot be used together with title."
,
"apihelp-readslot-param-slot"
:
"The name of the slot to read."
,
"wsslots-apierror-unknownslot"
:
"Unknown slot '$1'."
,
"wsslots-apierror-slotdoesnotexist"
:
"The slot '$1' does not exist on page '$2'."
,
"wsslots-apierror-nottext"
:
"The content model '$1' cannot be returned, because it is not text."
,
"wsslots-error-invalid-wikipage-object"
:
"The given WikiPage object is not valid, since it does not have a Title."
,
"tag-wsslots-slot-edit"
:
"Metadata slot edit"
,
"tag-wsslots-slot-edit-description"
:
"Edit made using WSSlots"
...
...
src/ApiEditSlot.php
→
src/
API/
ApiEditSlot.php
View file @
0db7ef7f
<?php
namespace
WSSlots
;
namespace
WSSlots
\API
;
use
ApiBase
;
use
ApiMain
;
use
ApiUsageException
;
use
MediaWiki\Storage\SlotRecord
;
use
MWContentSerializationException
;
use
MWException
;
use
Title
;
use
User
;
use
Wikimedia\ParamValidator\ParamValidator
;
use
WikiPage
;
use
WSSlots\Logger
;
use
WSSlots\WSSlots
;
/**
* A slot-aware module that allows for editing and creating pages.
...
...
src/ApiParseTemplates.php
→
src/
API/
ApiParseTemplates.php
View file @
0db7ef7f
<?php
namespace
WSSlots
;
namespace
WSSlots
\API
;
use
ApiBase
;
use
ApiUsageException
;
...
...
src/API/ApiReadSlot.php
0 → 100644
View file @
0db7ef7f
<?php
namespace
WSSlots\API
;
use
ApiBase
;
use
ApiQueryBase
;
use
ApiUsageException
;
use
MediaWiki\Storage\SlotRecord
;
use
MWException
;
use
TextContent
;
use
Wikimedia\ParamValidator\ParamValidator
;
use
WSSlots\WSSlots
;
/**
* A slot-aware module that allows for reading pages.
*/
class
ApiReadSlot
extends
ApiBase
{
/**
* @inheritDoc
*
* @throws ApiUsageException
* @throws MWException
*/
public
function
execute
()
{
$this
->
useTransactionalTimeLimit
();
$params
=
$this
->
extractRequestParams
();
$wikiPage
=
$this
->
getTitleOrPageId
(
$params
);
$title
=
$wikiPage
->
getTitle
();
// Check if we are allowed to read this page
$this
->
checkTitleUserPermissions
(
$title
,
'read'
,
[
'autoblock'
=>
true
]
);
$content
=
WSSlots
::
getSlotContent
(
$wikiPage
,
$params
[
"slot"
]
);
if
(
$content
===
null
)
{
$this
->
dieWithError
(
wfMessage
(
"wsslots-apierror-slotdoesnotexist"
,
$params
[
'slot'
],
$title
->
getFullText
()
),
"slotdoesnotexist"
);
}
if
(
!
$content
instanceof
TextContent
)
{
$this
->
dieWithError
(
wfMessage
(
"wsslots-apierror-nottext"
,
$content
->
getModel
()
),
"nottext"
);
}
$this
->
getResult
()
->
addValue
(
null
,
'result'
,
$content
->
getText
()
);
}
/**
* @inheritDoc
*/
public
function
isReadMode
():
bool
{
return
false
;
}
/**
* @inheritDoc
*/
public
function
getAllowedParams
():
array
{
return
[
'title'
=>
[
ApiBase
::
PARAM_TYPE
=>
'string'
],
'pageid'
=>
[
ApiBase
::
PARAM_TYPE
=>
'integer'
],
'slot'
=>
[
ApiBase
::
PARAM_TYPE
=>
'text'
,
ParamValidator
::
PARAM_DEFAULT
=>
SlotRecord
::
MAIN
]
];
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment