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' ) {
82 if ( $content ===
null ) {
83 if ( ( $preload ===
null || $preload ===
'' ) && $section ===
'new' ) {
85 $preload =
'MediaWiki:addsection-preload';
87 $content = $this->getPreloadedContentFromParams( $page, $performer, $preload, $preloadParams );
89 $title = Title::newFromPageIdentity( $page );
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 );
142 $contentModel = $contextTitle->getContentModel();
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 ) {
156 $msg =
wfMessage( MessageCache::normalizeKey( $title->getText() ) );
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();
215 $content = $converted;
217 return $this->transform( $content, $title, $preloadParams );
220 private function transform(
222 PageReference $title,
223 array $preloadParams = []
225 return $this->contentTransformer->preloadTransform(
229 ParserOptions::newFromAnon(),
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
__construct(IContentHandlerFactory $contentHandlerFactory, WikiPageFactory $wikiPageFactory, RedirectLookup $redirectLookup, SpecialPageFactory $specialPageFactory, ContentTransformer $contentTransformer, HookContainer $hookContainer)
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...