4require_once __DIR__ .
'/Maintenance.php';
25 parent::__construct();
27 $this->
addDescription(
'Add a site definition into the sites table.' );
29 $this->
addArg(
'globalid',
'The global id of the site to add, e.g. "wikipedia".',
true );
30 $this->
addArg(
'group',
'In which group this site should be sorted in.',
true );
31 $this->
addOption(
'language',
'The language code of the site, e.g. "de".',
false,
true );
32 $this->
addOption(
'interwiki-id',
'The interwiki ID of the site.',
false,
true );
33 $this->
addOption(
'navigation-id',
'The navigation ID of the site.',
false,
true );
34 $this->
addOption(
'pagepath',
'The URL to pages of this site, e.g.' .
35 ' https://example.com/wiki/\$1.',
false,
true );
36 $this->
addOption(
'filepath',
'The URL to files of this site, e.g. https://example' .
37 '.com/w/\$1.',
false,
true );
46 if ( method_exists( $siteStore,
'reset' ) ) {
51 $globalId = $this->
getArg( 0 );
52 $group = $this->
getArg( 1 );
53 $language = $this->
getOption(
'language' );
54 $interwikiId = $this->
getOption(
'interwiki-id' );
55 $navigationId = $this->
getOption(
'navigation-id' );
56 $pagepath = $this->
getOption(
'pagepath' );
57 $filepath = $this->
getOption(
'filepath' );
59 if ( !is_string( $globalId ) || !is_string( $group ) ) {
60 $this->
fatalError(
'Arguments globalid and group need to be strings.' );
63 if ( $siteStore->getSite( $globalId ) !==
null ) {
64 $this->
fatalError(
"Site with global id $globalId already exists." );
68 $site->setGlobalId( $globalId );
69 $site->setGroup( $group );
70 if ( $language !==
null ) {
71 $site->setLanguageCode( $language );
73 if ( $interwikiId !==
null ) {
74 $site->addInterwikiId( $interwikiId );
76 if ( $navigationId !==
null ) {
77 $site->addNavigationId( $navigationId );
79 if ( $pagepath !==
null ) {
80 $site->setPagePath( $pagepath );
82 if ( $filepath !==
null ) {
83 $site->setFilePath( $filepath );
86 $siteStore->saveSites( [ $site ] );
88 if ( method_exists( $siteStore,
'reset' ) ) {
94 'Done. Reload the web server and other long-running PHP processes '
95 .
"to refresh the local-server cache of the sites table.\n"
102require_once RUN_MAINTENANCE_IF_MAIN;
Maintenance script for adding a site definition into the sites table.
__construct()
Default constructor.
execute()
Imports the site described by the parameters (see self::__construct()) passed to this maintenance scc...
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
addArg( $arg, $description, $required=true, $multi=false)
Add some args that are needed.
getArg( $argId=0, $default=null)
Get an argument.
output( $out, $channel=null)
Throw some output to the user.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
getServiceContainer()
Returns the main service container.
addDescription( $text)
Set the description text.