Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F6193781
Page.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
Page.js
View Options
/**
* A small helper for reading, editing, and deleting MediaWiki pages via the API.
*
* It wraps common actions and handles CSRF tokens automatically when needed.
*/
export
class
Pages
{
constructor
(
{
request
,
session
,
summary
,
auth
}
)
{
this
.
request
=
request
;
this
.
session
=
session
;
this
.
defaultSummary
=
summary
;
this
.
auth
=
auth
;
}
/**
* Read a page’s current wikitext.
*
* @param {string} title - Exact page title (e.g. "Project:Sandbox").
* @return {Promise<Object>} MediaWiki API response containing revision content.
*/
async
read
(
title
)
{
const
params
=
{
action
:
'query'
,
prop
:
'revisions'
,
rvprop
:
'content'
,
rvslots
:
'main'
,
titles
:
title
,
redirects
:
'true'
};
return
this
.
request
(
params
);
}
/**
* Create or edit a page.
*
* Automatically fetches a CSRF token if it's not available
*
* @param {string} title - Page title to edit.
* @param {string} text - Full wikitext to save.
* @param {string} [summary] - Edit summary. Falls back to the default summary.
* @return {Promise<Object>} MediaWiki API response for the edit action.
*/
async
edit
(
title
,
text
,
summary
)
{
if
(
!
this
.
session
.
csrfToken
)
{
await
this
.
auth
.
getEditToken
();
}
return
this
.
request
(
{
action
:
'edit'
,
title
,
text
,
summary
:
summary
||
this
.
defaultSummary
,
bot
:
true
,
token
:
this
.
session
.
csrfToken
}
);
}
/**
* Delete a page.
*
* Automatically fetches a CSRF token if it's not available.
*
* @param {string} title - Page title to delete.
* @param {string} reason - Deletion reason. Falls back to the default summary.
* @return {Promise<Object>} MediaWiki API response for the delete action.
*/
async
delete
(
title
,
reason
)
{
if
(
!
this
.
session
.
csrfToken
)
{
await
this
.
auth
.
getEditToken
();
}
return
this
.
request
(
{
action
:
'delete'
,
title
,
reason
:
reason
||
this
.
defaultSummary
,
token
:
this
.
session
.
csrfToken
}
);
}
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Oct 9 2026, 23:13 (7 w, 2 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
37/16/0ce6922a9447836ebb3f45057e3f
Default Alt Text
Page.js (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment