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 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, WikiPage $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, Article $article, string $contentModel, string $section,)
 Get the content of the wanted revision, without section extraction.
 
 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.
 

Detailed Description

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

Access: internal
Since
1.46

Definition at line 23 of file PageEditingHelper.php.

Constructor & Destructor Documentation

◆ __construct()

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

Definition at line 25 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 182 of file PageEditingHelper.php.

◆ getExpectedParentRevision()

MediaWiki\EditPage\PageEditingHelper::getExpectedParentRevision ( ?int $editRevId,
?string $editTime,
WikiPage $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 204 of file PageEditingHelper.php.

◆ getOriginalContent()

MediaWiki\EditPage\PageEditingHelper::getOriginalContent ( Authority $performer,
Article $article,
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
Article$article
string$contentModel
string$section

Definition at line 159 of file PageEditingHelper.php.

References MediaWiki\Page\Article\getPage().

◆ 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 55 of file PageEditingHelper.php.

◆ guessSectionName()

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

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

Definition at line 35 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 135 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 108 of file PageEditingHelper.php.


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