22 private $wikiPageFactory;
32 return [
'services',
'extension-tables' ];
38 $status = Status::newGood();
39 foreach ( $pages as $pageInfo ) {
40 $status->merge( $this->createPage( $pageInfo ) );
53 private function createPage( array $pageInfo ) {
54 if ( isset( $pageInfo[
'title'] ) ) {
55 $titleText = $pageInfo[
'title'];
56 } elseif ( isset( $pageInfo[
'titlemsg'] ) ) {
57 $titleText =
wfMessage( $pageInfo[
'titlemsg'] )->inContentLanguage()->text();
59 throw new \InvalidArgumentException(
60 'InstallerInitialPages is missing title/titlemsg' );
62 $title = $this->pageStore->getPageByText( $titleText );
63 $status = Status::newGood();
65 $status->warning(
'config-install-mainpage-failed',
'invalid title' );
68 if ( $title->getId() ) {
69 $status->warning(
'config-install-mainpage-exists', $titleText );
72 $page = $this->wikiPageFactory->newFromTitle( $title );
74 if ( isset( $pageInfo[
'text'] ) ) {
75 $text = $pageInfo[
'text'];
76 } elseif ( isset( $pageInfo[
'textmsg'] ) ) {
77 $text =
wfMessage( $pageInfo[
'textmsg'] )->inContentLanguage()->text();
79 throw new \InvalidArgumentException(
80 'InstallerInitialPages is missing text/textmsg' );
82 $text = $this->replaceVariables( $text );
84 $content =
new WikitextContent( $text );
87 $updater = $page->newPageUpdater( User::newSystemUser(
'MediaWiki default' ) );
89 ->setContent( SlotRecord::MAIN, $content )
91 CommentStoreComment::newUnsavedComment(
'' )
93 $status = $updater->getStatus();
94 }
catch ( \Exception $e ) {
96 $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] );