3 namespace MediaWiki\EditPage;
20 use Wikimedia\Assert\Assert;
50 $this->contentHandlerFactory = $contentHandlerFactory;
51 $this->wikiPageFactory = $wikiPageFactory;
52 $this->redirectLookup = $redirectLookup;
53 $this->specialPageFactory = $specialPageFactory;
54 $this->contentTransformer = $contentTransformer;
55 $this->hookRunner =
new HookRunner( $hookContainer );
76 Assert::parameterElementType(
'string', $preloadParams,
'$preloadParams' );
79 if ( $section !==
'new' ) {
83 if ( ( $preload ===
null || $preload ===
'' ) && $section ===
'new' ) {
85 $preload =
'MediaWiki:addsection-preload';
87 $content = $this->getPreloadedContentFromParams( $page, $performer, $preload, $preloadParams );
90 if ( !$title->getArticleID() ) {
91 $contentModel = $title->getContentModel();
92 $contentHandler = $this->contentHandlerFactory->getContentHandler( $contentModel );
93 $contentFormat = $contentHandler->getDefaultFormat();
94 $text = $contentHandler->serializeContent(
$content, $contentFormat );
95 $this->hookRunner->onEditFormPreloadText( $text, $title );
96 $content = $contentHandler->unserializeContent( $text, $contentFormat );
112 $title =
Title::newFromPageIdentity( $page );
114 $contentHandler = $this->contentHandlerFactory->getContentHandler( $contentModel );
115 $contentFormat = $contentHandler->getDefaultFormat();
118 $text = $title->getDefaultMessageText();
119 if ( $text !==
false ) {
120 return $contentHandler->unserializeContent( $text, $contentFormat );
135 private function getPreloadedContentFromParams(
136 ProperPageIdentity $contextPage,
137 Authority $performer,
141 $contextTitle =
Title::newFromPageIdentity( $contextPage );
143 $handler = $this->contentHandlerFactory->getContentHandler( $contentModel );
146 if ( !$handler->supportsPreloadContent() || $preload ===
null || $preload ===
'' ) {
147 return $handler->makeEmptyContent();
150 $title = Title::newFromText( $preload );
152 if ( $title && $title->getNamespace() ==
NS_MEDIAWIKI ) {
158 if ( $msg->isDisabled() ) {
160 return $handler->makeEmptyContent();
163 return $this->transform(
164 $handler->unserializeContent( $msg
166 ->params( $preloadParams )
167 ->inContentLanguage()
176 $title = $this->getTargetTitleIfSpecialMyLanguage( $title );
178 # Check for existence to avoid getting MediaWiki:Noarticletext
179 if ( !$this->isPageExistingAndViewable( $title, $performer ) ) {
181 return $handler->makeEmptyContent();
184 $page = $this->wikiPageFactory->newFromTitle( $title );
185 if ( $page->isRedirect() ) {
186 $redirTarget = $this->redirectLookup->getRedirectTarget( $title );
187 $redirTarget = Title::castFromLinkTarget( $redirTarget );
189 if ( !$this->isPageExistingAndViewable( $redirTarget, $performer ) ) {
191 return $handler->makeEmptyContent();
193 $page = $this->wikiPageFactory->newFromTitle( $redirTarget );
196 $content = $page->getContent( RevisionRecord::RAW );
200 return $handler->makeEmptyContent();
203 if (
$content->getModel() !== $handler->getModelID() ) {
204 $converted =
$content->convert( $handler->getModelID() );
208 wfDebug(
"Attempt to preload incompatible content: " .
209 "can't convert " .
$content->getModel() .
210 " to " . $handler->getModelID() );
212 return $handler->makeEmptyContent();
217 return $this->transform(
$content, $title, $preloadParams );
220 private function transform(
222 PageReference $title,
223 array $preloadParams = []
225 return $this->contentTransformer->preloadTransform(
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
A service to transform content.
Provides the initial content of the edit box displayed in an edit form when creating a new page or a ...
__construct(IContentHandlerFactory $contentHandlerFactory, WikiPageFactory $wikiPageFactory, RedirectLookup $redirectLookup, SpecialPageFactory $specialPageFactory, ContentTransformer $contentTransformer, HookContainer $hookContainer)
getDefaultContent(ProperPageIdentity $page)
Get the content that is displayed when viewing a page that does not exist.
getPreloadedContent(ProperPageIdentity $page, Authority $performer, ?string $preload, array $preloadParams, ?string $section)
Get the initial content of the edit box displayed in an edit form when creating a new page or a new s...
Service for creating WikiPage objects.
Factory for handling the special page list and generating SpecialPage objects.
Cache messages that are defined by MediaWiki-namespace pages or by hooks.
static normalizeKey( $key)
Normalize message key input.
Set options of the Parser.
static newFromAnon()
Get a ParserOptions object for an anonymous user.
Base interface for representing page content.
Interface for a page that is (or could be, or used to be) an editable wiki page.
Service for resolving a wiki page redirect.