22 private $wikiPageFactory;
34 return [
'services',
'extension-tables' ];
40 $status = Status::newGood();
41 foreach ( $pages as $pageInfo ) {
42 $status->merge( $this->createPage( $pageInfo ) );
55 private function createPage( array $pageInfo ) {
56 if ( isset( $pageInfo[
'title'] ) ) {
57 $titleText = $pageInfo[
'title'];
58 } elseif ( isset( $pageInfo[
'titlemsg'] ) ) {
59 $titleText =
wfMessage( $pageInfo[
'titlemsg'] )->inContentLanguage()->text();
61 throw new \InvalidArgumentException(
62 'InstallerInitialPages is missing title/titlemsg' );
64 $title = $this->pageStore->getPageByText( $titleText );
65 $status = Status::newGood();
67 $status->warning(
'config-install-mainpage-failed',
'invalid title' );
70 if ( $title->getId() ) {
71 $status->warning(
'config-install-mainpage-exists', $titleText );
74 $page = $this->wikiPageFactory->newFromTitle( $title );
76 if ( isset( $pageInfo[
'text'] ) ) {
77 $text = $pageInfo[
'text'];
78 } elseif ( isset( $pageInfo[
'textmsg'] ) ) {
79 $text =
wfMessage( $pageInfo[
'textmsg'] )->inContentLanguage()->text();
81 throw new \InvalidArgumentException(
82 'InstallerInitialPages is missing text/textmsg' );
84 $text = $this->replaceVariables( $text );
86 $content =
new WikitextContent( $text );
89 $updater = $page->newPageUpdater( User::newSystemUser(
'MediaWiki default' ) );
91 ->setContent( SlotRecord::MAIN, $content )
93 CommentStoreComment::newUnsavedComment(
'' )
95 $status = $updater->getStatus();
96 }
catch ( \Exception $e ) {
98 $status->fatal(
'config-install-mainpage-failed', $e->__toString() );
107 private function initServices( MediaWikiServices $services ) {
108 $this->wikiPageFactory = $services->getWikiPageFactory();
109 $this->pageStore = $services->getPageStore();
118 private function replaceVariables(
string $text ): string {
119 $text = preg_replace_callback(
120 '/\{\{ *InstallerOption: *(\w+) *}}/',
121 function ( $match ) {
122 return (
string)$this->getOption( $match[1] );
126 $text = preg_replace_callback(
127 '/\{\{ *InstallerConfig: *(\w+) *}}/',
128 function ( $match ) {
129 return (
string)$this->getConfigVar( $match[1] );