Update git submodules
[mediawiki.git] / maintenance / addSite.php
blob45f322eeafbcb89834e0ba858c138309fd856bcf
1 <?php
3 require_once __DIR__ . '/Maintenance.php';
5 /**
6 * Maintenance script for adding a site definition into the sites table.
8 * The sites table is cached in the local-server cache,
9 * so you should reload your webserver and other long-running MediaWiki
10 * PHP processes after running this script.
12 * @since 1.29
14 * @license GPL-2.0-or-later
15 * @author Florian Schmidt
17 class AddSite extends Maintenance {
19 public function __construct() {
20 parent::__construct();
22 $this->addDescription( 'Add a site definition into the sites table.' );
24 $this->addArg( 'globalid', 'The global id of the site to add, e.g. "wikipedia".', true );
25 $this->addArg( 'group', 'In which group this site should be sorted in.', true );
26 $this->addOption( 'language', 'The language code of the site, e.g. "de".', false, true );
27 $this->addOption( 'interwiki-id', 'The interwiki ID of the site.', false, true );
28 $this->addOption( 'navigation-id', 'The navigation ID of the site.', false, true );
29 $this->addOption( 'pagepath', 'The URL to pages of this site, e.g.' .
30 ' https://example.com/wiki/\$1.', false, true );
31 $this->addOption( 'filepath', 'The URL to files of this site, e.g. https://example' .
32 '.com/w/\$1.', false, true );
35 /**
36 * Imports the site described by the parameters (see self::__construct()) passed to this
37 * maintenance sccript into the sites table of MediaWiki.
38 * @return bool
40 public function execute() {
41 $siteStore = $this->getServiceContainer()->getSiteStore();
42 if ( method_exists( $siteStore, 'reset' ) ) {
43 // @phan-suppress-next-line PhanUndeclaredMethod
44 $siteStore->reset();
47 $globalId = $this->getArg( 0 );
48 $group = $this->getArg( 1 );
49 $language = $this->getOption( 'language' );
50 $interwikiId = $this->getOption( 'interwiki-id' );
51 $navigationId = $this->getOption( 'navigation-id' );
52 $pagepath = $this->getOption( 'pagepath' );
53 $filepath = $this->getOption( 'filepath' );
55 if ( !is_string( $globalId ) || !is_string( $group ) ) {
56 $this->error( 'Arguments globalid and group need to be strings.' );
57 return false;
60 if ( $siteStore->getSite( $globalId ) !== null ) {
61 $this->error( "Site with global id $globalId already exists." );
62 return false;
65 $site = new MediaWikiSite();
66 $site->setGlobalId( $globalId );
67 $site->setGroup( $group );
68 if ( $language !== null ) {
69 $site->setLanguageCode( $language );
71 if ( $interwikiId !== null ) {
72 $site->addInterwikiId( $interwikiId );
74 if ( $navigationId !== null ) {
75 $site->addNavigationId( $navigationId );
77 if ( $pagepath !== null ) {
78 $site->setPagePath( $pagepath );
80 if ( $filepath !== null ) {
81 $site->setFilePath( $filepath );
84 $siteStore->saveSites( [ $site ] );
86 if ( method_exists( $siteStore, 'reset' ) ) {
87 // @phan-suppress-next-line PhanUndeclaredMethod
88 $siteStore->reset();
91 $this->output(
92 'Done. Reload the web server and other long-running PHP processes '
93 . "to refresh the local-server cache of the sites table.\n"
98 $maintClass = AddSite::class;
99 require_once RUN_MAINTENANCE_IF_MAIN;