MediaWiki  REL1_31
addSite.php
Go to the documentation of this file.
1 <?php
2 
4 
5 $basePath = getenv( 'MW_INSTALL_PATH' ) !== false ? getenv( 'MW_INSTALL_PATH' ) : __DIR__ . '/..';
6 
7 require_once $basePath . '/maintenance/Maintenance.php';
8 
17 class AddSite extends Maintenance {
18 
19  public function __construct() {
20  $this->addDescription( 'Add a site definition into the sites table.' );
21 
22  $this->addArg( 'globalid', 'The global id of the site to add, e.g. "wikipedia".', true );
23  $this->addArg( 'group', 'In which group this site should be sorted in.', true );
24  $this->addOption( 'language', 'The language code of the site, e.g. "de".', false, true );
25  $this->addOption( 'interwiki-id', 'The interwiki ID of the site.', false, true );
26  $this->addOption( 'navigation-id', 'The navigation ID of the site.', false, true );
27  $this->addOption( 'pagepath', 'The URL to pages of this site, e.g.' .
28  ' https://example.com/wiki/\$1.', false, true );
29  $this->addOption( 'filepath', 'The URL to files of this site, e.g. https://example' .
30  '.com/w/\$1.', false, true );
31 
32  parent::__construct();
33  }
34 
40  public function execute() {
41  $siteStore = MediaWikiServices::getInstance()->getSiteStore();
42  $siteStore->reset();
43 
44  $globalId = $this->getArg( 0 );
45  $group = $this->getArg( 1 );
46  $language = $this->getOption( 'language' );
47  $interwikiId = $this->getOption( 'interwiki-id' );
48  $navigationId = $this->getOption( 'navigation-id' );
49  $pagepath = $this->getOption( 'pagepath' );
50  $filepath = $this->getOption( 'filepath' );
51 
52  if ( !is_string( $globalId ) || !is_string( $group ) ) {
53  echo "Arguments globalid and group need to be strings.\n";
54  return false;
55  }
56 
57  if ( $siteStore->getSite( $globalId ) !== null ) {
58  echo "Site with global id $globalId already exists.\n";
59  return false;
60  }
61 
62  $site = new MediaWikiSite();
63  $site->setGlobalId( $globalId );
64  $site->setGroup( $group );
65  if ( $language !== null ) {
66  $site->setLanguageCode( $language );
67  }
68  if ( $interwikiId !== null ) {
69  $site->addInterwikiId( $interwikiId );
70  }
71  if ( $navigationId !== null ) {
72  $site->addNavigationId( $navigationId );
73  }
74  if ( $pagepath !== null ) {
75  $site->setPagePath( $pagepath );
76  }
77  if ( $filepath !== null ) {
78  $site->setFilePath( $filepath );
79  }
80 
81  $siteStore->saveSites( [ $site ] );
82 
83  if ( method_exists( $siteStore, 'reset' ) ) {
84  $siteStore->reset();
85  }
86 
87  echo "Done.\n";
88  }
89 }
90 
92 require_once RUN_MAINTENANCE_IF_MAIN;
$maintClass
$maintClass
Definition: addSite.php:91
use
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Definition: APACHE-LICENSE-2.0.txt:10
AddSite\__construct
__construct()
Default constructor.
Definition: addSite.php:19
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:291
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: maintenance.txt:39
AddSite
Maintenance script for adding a site definition into the sites table.
Definition: addSite.php:17
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:37
AddSite\execute
execute()
Imports the site described by the parameters (see self::__construct()) passed to this maintenance scc...
Definition: addSite.php:40
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
Definition: Maintenance.php:219
Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition: Maintenance.php:254
Maintenance\addArg
addArg( $arg, $description, $required=true)
Add some args that are needed.
Definition: Maintenance.php:271
$basePath
$basePath
Definition: addSite.php:5
MediaWikiSite
Class representing a MediaWiki site.
Definition: MediaWikiSite.php:38
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:56
MediaWikiServices
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Definition: injection.txt:25
Maintenance\getArg
getArg( $argId=0, $default=null)
Get an argument.
Definition: Maintenance.php:310