Topic on Manual talk:Sites table

Where would you use the custom script to add a site to the table?

2
Lwangaman (talkcontribs)

The page talks about using a custom script ("Insert wiki family (using Script)"). I have just used the populateSitesTable.php script running it once for each wiki ID, and it successfully populated the sites table for each language wiki with a list of default wiki sites. Now I think I need to add my own wiki to this list in order to be able to use the "add link" feature for any given page. Where would I use the suggested script? Do I create a php file somewhere? Or add this within another script such as addSite.php?

$sites = [];
foreach ( [ 'en', 'fr' ] as $langCode ) {
     $site = new MediaWikiSite();
     $site->setGlobalId( $langCode . 'mywiki' );
     $site->setGroup( 'mywiki' );
     $site->setLanguageCode( $langCode );
     $site->addInterwikiId( $langCode );
     $site->addNavigationId( $langCode );
     $site->setPath( MediaWikiSite::PATH_PAGE, "http://$langCode.mywiki.org/wiki/$1" );
     $site->setPath( MediaWikiSite::PATH_FILE, "http://$langCode.mywiki.org/w/$1" );           
     $sites[] = $site;
}
          
$sitesTable = SiteSQLStore::newInstance();
$sitesTable->clear(); // This will remove all previous entries from the table. Remove this call if you want to keep them.
$sitesTable->saveSites( $sites );

Obviously switching out "mywiki" with my own wiki namespace.

Lwangaman (talkcontribs)

I believe I have succeeded in completing this task. I created a file "addMyWikiFarm.php" in the maintenance folder with these contents:

 1 <?php
 2 class AddMyWikiFarm extends Maintenance {
 3 
 4 	public function __construct() {
 5 		$this->addDescription( 'Add my Custom Wiki Farm definitions into the sites table.' );
 6 
 7 		parent::__construct();
 8 	}
 9 
10 	/**
11 	 * Imports the sites of my Wiki Farm
12 	 * into the sites table of this MediaWiki installation.
13 	 * @return bool
14 	 */
15 	public function execute() {
16 		$siteStore = MediaWikiServices::getInstance()->getSiteStore();
17 		if ( method_exists( $siteStore, 'reset' ) ) {
18 			// @phan-suppress-next-line PhanUndeclaredMethod
19 			$siteStore->reset();
20 		}
21 
22         $sites = [];
23         foreach ( [ 'en', 'it' ] as $langCode ) {
24             $site = new MediaWikiSite();
25         	if ( $siteStore->getSite( $langCode . 'mywikisite' ) !== null ) {
26         		echo "Site with global id {$langCode}mywikisite already exists.\n";
27         		return false;
28         	}
29             $site->setGlobalId( $langCode . 'mywikisite' );
30             $site->setGroup( 'mywikifarm' );
31             $site->setLanguageCode( $langCode );
32             $site->addInterwikiId( $langCode );
33             $site->addNavigationId( $langCode );
34             $site->setPath( MediaWikiSite::PATH_PAGE, "https://pathto.mywikisitepages.com/$langCode/$1" );
35             $site->setPath( MediaWikiSite::PATH_FILE, "https://pathto.mywikisitescripts.com/$langCode/$1" );           
36             $sites[] = $site;
37         }
38                   
39         $siteStore->saveSites( $sites );
40 		if ( method_exists( $siteStore, 'reset' ) ) {
41 			// @phan-suppress-next-line PhanUndeclaredMethod
42 			$siteStore->reset();
43 		}
44 
45 		echo "Done.\n";
46 	}
47 }
48 
49 $maintClass = AddMyWikiFarm::class;
50 require_once RUN_MAINTENANCE_IF_MAIN;

Then I ran php maintenance/addmyWikiFarm.php --wiki WIKIID from the command line for each of my language wikis and the wikifarm language sites do seem to have been added to the sites table of these wikis. Am still trying to figure out how to get the "add link" on the sidebar to work for the interwiki...

Reply to "Where would you use the custom script to add a site to the table?"