MediaWiki master
MediaWiki\EditPage\PageEditingHelper Class Reference

Provides helper methods used by EditPage and a future editing backend (T157658). More...

Public Member Functions

 __construct (private readonly ServiceOptions $options, private readonly IContentHandlerFactory $contentHandlerFactory, private readonly ParserFactory $parserFactory, private readonly RevisionStore $revisionStore,)
 
 getCurrentContent (string $contentModel, WikiPage $page,)
 Get the current content of the page.
 
 getExpectedParentRevision (?int $editRevId, ?string $editTime, PageReference $page,)
 Returns the RevisionRecord corresponding to the revision that was current at the time editing was initiated on the client even if the edit was based on an old revision.
 
 getOriginalContent (Authority $performer, $page, ?RevisionRecord $revisionRecord, string $contentModel, string $section,)
 Get the content of the wanted revision, without section extraction.
 
 getSubmitButtonLabel (PageIdentity $page)
 Get the message key of the label for the button to save the page.
 
 getUndoContent (WikiPage $page, RevisionRecord $undoRev, RevisionRecord $oldRev, ?string &$error)
 Returns the result of a three-way merge when undoing changes.
 
 guessSectionName (string $text)
 Turns section name wikitext into anchors for use in HTTP redirects.
 
 isSupportedContentModel (string $modelId, bool $enableApiEditOverride,)
 Returns if the given content model is editable.
 
 toEditText (Content|null|false|string $content, ?string $contentFormat, bool $enableApiEditOverride,)
 Gets an editable textual representation of $content.
 

Public Attributes

const CONSTRUCTOR_OPTIONS
 

Detailed Description

Provides helper methods used by EditPage and a future editing backend (T157658).

Access: internal
Since
1.46

Definition at line 26 of file PageEditingHelper.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\EditPage\PageEditingHelper::__construct ( private readonly ServiceOptions $options,
private readonly IContentHandlerFactory $contentHandlerFactory,
private readonly ParserFactory $parserFactory,
private readonly RevisionStore $revisionStore )

Definition at line 32 of file PageEditingHelper.php.

Member Function Documentation

◆ getCurrentContent()

MediaWiki\EditPage\PageEditingHelper::getCurrentContent ( string $contentModel,
WikiPage $page )

Get the current content of the page.

This is basically similar to WikiPage::getContent( RevisionRecord::RAW ) except that when the page doesn't exist an empty content object is returned instead of null.

Definition at line 197 of file PageEditingHelper.php.

◆ getExpectedParentRevision()

MediaWiki\EditPage\PageEditingHelper::getExpectedParentRevision ( ?int $editRevId,
?string $editTime,
PageReference $page )

Returns the RevisionRecord corresponding to the revision that was current at the time editing was initiated on the client even if the edit was based on an old revision.

Returns
?RevisionRecord Latest revision when editing was initiated on the client

Definition at line 219 of file PageEditingHelper.php.

◆ getOriginalContent()

MediaWiki\EditPage\PageEditingHelper::getOriginalContent ( Authority $performer,
$page,
?RevisionRecord $revisionRecord,
string $contentModel,
string $section )

Get the content of the wanted revision, without section extraction.

The result of this function can be used to compare user's input with section replaced in its context (using WikiPage::replaceSectionAtRev()) to the original text of the edit.

This differs from Article::getContent() that when a missing revision is encountered the result will be null and not the 'missing-revision' message.

Parameters
Authority$performerto get the revision for
WikiPage$page
RevisionRecord | null$revisionRecord
string$contentModel
string$section

Definition at line 174 of file PageEditingHelper.php.

◆ getSubmitButtonLabel()

MediaWiki\EditPage\PageEditingHelper::getSubmitButtonLabel ( PageIdentity $page)

Get the message key of the label for the button to save the page.

Parameters
PageIdentity$pageThe page that's being edited.

Definition at line 244 of file PageEditingHelper.php.

◆ getUndoContent()

MediaWiki\EditPage\PageEditingHelper::getUndoContent ( WikiPage $page,
RevisionRecord $undoRev,
RevisionRecord $oldRev,
?string & $error )

Returns the result of a three-way merge when undoing changes.

Parameters
WikiPage$page
RevisionRecord$undoRevNewest revision being undone. Corresponds to undo URL parameter.
RevisionRecord$oldRevRevision that is being restored. Corresponds to undoafter URL parameter.
?string&$errorIf false is returned, this will be set to "norev" if the revision failed to load, or "failure" if the content handler failed to merge the required changes.

Definition at line 69 of file PageEditingHelper.php.

◆ guessSectionName()

MediaWiki\EditPage\PageEditingHelper::guessSectionName ( string $text)

Turns section name wikitext into anchors for use in HTTP redirects.

Returns
string An empty string if $text is empty; otherwise the section name as an anchor starting with '#'.

Definition at line 46 of file PageEditingHelper.php.

◆ isSupportedContentModel()

MediaWiki\EditPage\PageEditingHelper::isSupportedContentModel ( string $modelId,
bool $enableApiEditOverride )

Returns if the given content model is editable.

Parameters
string$modelIdThe ID of the content model to test. Use CONTENT_MODEL_XXX constants.
bool$enableApiEditOverride
Exceptions
UnknownContentModelExceptionIf $modelId has no known handler

Definition at line 149 of file PageEditingHelper.php.

◆ toEditText()

MediaWiki\EditPage\PageEditingHelper::toEditText ( Content|null|false|string $content,
?string $contentFormat,
bool $enableApiEditOverride )

Gets an editable textual representation of $content.

The textual representation can be turned by into a Content object by the EditPage::toEditContent() method.

If $content is null or false or a string, $content is returned unchanged.

If the given Content object is not of a type that can be edited using the text base EditPage, an exception will be raised. Set $enableApiEditOverride to true to allow editing of non-textual content.

Returns
string|null The editable text form of the content, or null if $content is not an instance of TextContent and $enableApiEditOverride is not true.
Exceptions
UnsupportedContentFormatException

Definition at line 122 of file PageEditingHelper.php.

Member Data Documentation

◆ CONSTRUCTOR_OPTIONS

const MediaWiki\EditPage\PageEditingHelper::CONSTRUCTOR_OPTIONS
Initial value:
= [
]
const EditSubmitButtonLabelPublish
Name constant for the EditSubmitButtonLabelPublish setting, for use with Config::get()

Definition at line 28 of file PageEditingHelper.php.


The documentation for this class was generated from the following file: