Move the check for if a Maintenance script supports --batch-size away from addDefault...
[lhc/web/wiklou.git] / maintenance / addwiki.php
index ad3b503..5ca3a0d 100644 (file)
@@ -1,4 +1,8 @@
 <?php
+/**
+ * @defgroup Wikimedia Wikimedia
+ */
+
 /**
  * Add a new wiki
  * Wikimedia specific!
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
  *
- * @defgroup Wikimedia Wikimedia
+ * @file
  * @ingroup Maintenance
  * @ingroup Wikimedia
  */
 
-require_once( dirname(__FILE__) . '/Maintenance.php' );
+require_once( dirname( __FILE__ ) . '/Maintenance.php' );
 
 class AddWiki extends Maintenance {
        public function __construct() {
+               global $wgNoDBParam;
+
                parent::__construct();
                $this->mDescription = "Add a new wiki to the family. Wikimedia specific!";
-               $this->addArg( 'language', 'Language code of new site' );
-               $this->addArg( 'site', 'Type of site' );
-               $this->addArg( 'dbname', 'Name of database to create' );
+               $this->addArg( 'language', 'Language code of new site, e.g. en' );
+               $this->addArg( 'site', 'Type of site, e.g. wikipedia' );
+               $this->addArg( 'dbname', 'Name of database to create, e.g. enwiki' );
+               $this->addArg( 'domain', 'Domain name of the wiki, e.g. en.wikipedia.org' );
+
+               $wgNoDBParam = true;
        }
 
-       protected function getDbType() {
+       public function getDbType() {
                return Maintenance::DB_ADMIN;
        }
 
        public function execute() {
-               global $IP, $wgLanguageNames, $wgDefaultExternalStore, $wgNoDBParam;
+               global $IP, $wgDefaultExternalStore, $wmfVersionNumber;
+               if ( !$wmfVersionNumber ) { // set in CommonSettings.php
+                       $this->error( '$wmfVersionNumber is not set, please use MWScript.php wrapper.', true );
+               }
 
-               $wgNoDBParam = true;
-               $lang = $this->getArg(0);
-               $site = $this->getArg(1);
-               $dbName = $this->getArg(2);
+               $lang = $this->getArg( 0 );
+               $site = $this->getArg( 1 );
+               $dbName = $this->getArg( 2 );
+               $domain = $this->getArg( 3 );
+               $languageNames = Language::getLanguageNames();
 
-               if ( !isset( $wgLanguageNames[$lang] ) ) {
-                       $this->error( "Language $lang not found in \$wgLanguageNames", true );
+               if ( !isset( $languageNames[$lang] ) ) {
+                       $this->error( "Language $lang not found in Names.php", true );
                }
-               $name = $wgLanguageNames[$lang];
+               $name = $languageNames[$lang];
 
                $dbw = wfGetDB( DB_MASTER );
                $common = "/home/wikipedia/common";
@@ -71,14 +84,18 @@ class AddWiki extends Maintenance {
                $dbw->sourceFile( "$IP/extensions/Oversight/hidden.sql" );
                $dbw->sourceFile( "$IP/extensions/GlobalBlocking/localdb_patches/setup-global_block_whitelist.sql" );
                $dbw->sourceFile( "$IP/extensions/AbuseFilter/abusefilter.tables.sql" );
-               $dbw->sourceFile( "$IP/extensions/UsabilityInitiative/PrefStats/PrefStats.sql" );
+               $dbw->sourceFile( "$IP/extensions/PrefStats/patches/PrefStats.sql" );
+               $dbw->sourceFile( "$IP/extensions/ProofreadPage/ProofreadPage.sql" );
+               $dbw->sourceFile( "$IP/extensions/ClickTracking/patches/ClickTrackingEvents.sql" );
+               $dbw->sourceFile( "$IP/extensions/ClickTracking/patches/ClickTracking.sql" );
+               $dbw->sourceFile( "$IP/extensions/UserDailyContribs/patches/UserDailyContribs.sql" );
 
                $dbw->query( "INSERT INTO site_stats(ss_row_id) VALUES (1)" );
 
                # Initialise external storage
                if ( is_array( $wgDefaultExternalStore ) ) {
                        $stores = $wgDefaultExternalStore;
-               } elseif ( $stores ) {
+               } elseif ( $wgDefaultExternalStore ) {
                        $stores = array( $wgDefaultExternalStore );
                } else {
                        $stores = array();
@@ -110,17 +127,16 @@ class AddWiki extends Maintenance {
                                $blobsFile = popen( $sedCmd, 'r' );
                                $extdb->sourceStream( $blobsFile );
                                pclose( $blobsFile );
-                               $extdb->immediateCommit();
+                               $extdb->commit();
                        }
                }
 
-               global $wgTitle, $wgArticle;
-               $wgTitle = Title::newFromText( wfMsgWeirdKey( "mainpage/$lang" ) );
-               $this->output( "Writing main page to " . $wgTitle->getPrefixedDBkey() . "\n" );
-               $wgArticle = new Article( $wgTitle );
+               $title = Title::newFromText( wfMessage( 'mainpage' )->inLanguage( $lang )->useDatabase( false )->plain() );
+               $this->output( "Writing main page to " . $title->getPrefixedDBkey() . "\n" );
+               $article = new Article( $title );
                $ucsite = ucfirst( $site );
 
-               $wgArticle->insertNewArticle( $this->getFirstArticle( $ucsite, $name ), '', false, false );
+               $article->doEdit( $this->getFirstArticle( $ucsite, $name ), '', EDIT_NEW | EDIT_AUTOSUMMARY );
 
                $this->output( "Adding to dblists\n" );
 
@@ -130,11 +146,28 @@ class AddWiki extends Maintenance {
                fclose( $file );
 
                # Update the sublists
-               shell_exec("cd $common && ./refresh-dblist");
+               shell_exec( "cd $common && ./refresh-dblist" );
+
+               # Add to wikiversions.dat
+               $file = fopen( "$common/wikiversions.dat", "a" );
+               fwrite( $file, "$dbName php-$wmfVersionNumber\n" );
+               fclose( $file );
+               # Rebuild wikiversions.cdb
+               shell_exec( "cd $common/multiversion && ./refreshWikiversionsCDB" );
 
-               #print "Constructing interwiki SQL\n";
+               # print "Constructing interwiki SQL\n";
                # Rebuild interwiki tables
-               #passthru( '/home/wikipedia/conf/interwiki/update' );
+               # passthru( '/home/wikipedia/conf/interwiki/update' );
+
+               $time = wfTimestamp( TS_RFC2822 );
+               // These arguments need to be escaped twice: once for echo and once for at
+               $escDbName = wfEscapeShellArg( wfEscapeShellArg( $dbName ) );
+               $escTime = wfEscapeShellArg( wfEscapeShellArg( $time ) );
+               $escUcsite = wfEscapeShellArg( wfEscapeShellArg( $ucsite ) );
+               $escName = wfEscapeShellArg( wfEscapeShellArg( $name ) );
+               $escLang = wfEscapeShellArg( wfEscapeShellArg( $lang ) );
+               $escDomain = wfEscapeShellArg( wfEscapeShellArg( $domain ) );
+               shell_exec( "echo notifyNewProjects $escDbName $escTime $escUcsite $escName $escLang $escDomain | at now + 15 minutes" );
 
                $this->output( "Script ended. You still have to:
        * Add any required settings in InitialiseSettings.php
@@ -142,306 +175,33 @@ class AddWiki extends Maintenance {
        * Run /home/wikipedia/conf/interwiki/update
        " );
        }
-       
+
        private function getFirstArticle( $ucsite, $name ) {
                return <<<EOT
-       ==This subdomain is reserved for the creation of a [[wikimedia:Our projects|$ucsite]] in '''[[w:en:{$name}|{$name}]]''' language==
-
-       * Please '''do not start editing''' this new site. This site has a test project on the [[incubator:|Wikimedia Incubator]] (or on the [[betawikiversity:|BetaWikiversity]] or on the [[oldwikisource:|Old Wikisource]]) and it will be imported to here.
-
-       * If you would like to help translating the interface to this language, please do not translate here, but go to [[translatewiki:|translatewiki]], a special wiki for translating the interface. That way everyone can use it on every wiki using the [[mw:|same software]].
-
-       * For information about how to edit and for other general help, see [[m:Help:Contents|Help on Wikimedia's Meta-Wiki]] or [[mw:Help:Contents|Help on MediaWiki.org]].
-
-       == Sister projects ==
-       <span class="plainlinks">
-       [http://www.wikipedia.org Wikipedia] |
-       [http://www.wiktionary.org Wiktonary] |
-       [http://www.wikibooks.org Wikibooks] |
-       [http://www.wikinews.org Wikinews] |
-       [http://www.wikiquote.org Wikiquote] |
-       [http://www.wikisource.org Wikisource]
-       [http://www.wikiversity.org Wikiversity]
-       </span>
-
-       See Wikimedia's [[m:|Meta-Wiki]] for the coordination of these projects.
-
-       [[aa:]]
-       [[ab:]]
-       [[ace:]]
-       [[af:]]
-       [[ak:]]
-       [[als:]]
-       [[am:]]
-       [[an:]]
-       [[ang:]]
-       [[ar:]]
-       [[arc:]]
-       [[arz:]]
-       [[as:]]
-       [[ast:]]
-       [[av:]]
-       [[ay:]]
-       [[az:]]
-       [[ba:]]
-       [[bar:]]
-       [[bat-smg:]]
-       [[bcl:]]
-       [[be:]]
-       [[be-x-old:]]
-       [[bg:]]
-       [[bh:]]
-       [[bi:]]
-       [[bm:]]
-       [[bn:]]
-       [[bo:]]
-       [[bpy:]]
-       [[br:]]
-       [[bs:]]
-       [[bug:]]
-       [[bxr:]]
-       [[ca:]]
-       [[cbk-zam:]]
-       [[cdo:]]
-       [[ce:]]
-       [[ceb:]]
-       [[ch:]]
-       [[cho:]]
-       [[chr:]]
-       [[chy:]]
-       [[ckb:]]
-       [[co:]]
-       [[cr:]]
-       [[crh:]]
-       [[cs:]]
-       [[csb:]]
-       [[cu:]]
-       [[cv:]]
-       [[cy:]]
-       [[cz:]]
-       [[da:]]
-       [[de:]]
-       [[diq:]]
-       [[dk:]]
-       [[dsb:]]
-       [[dv:]]
-       [[dz:]]
-       [[ee:]]
-       [[el:]]
-       [[eml:]]
-       [[en:]]
-       [[eo:]]
-       [[es:]]
-       [[et:]]
-       [[eu:]]
-       [[ext:]]
-       [[fa:]]
-       [[ff:]]
-       [[fi:]]
-       [[fiu-vro:]]
-       [[fj:]]
-       [[fo:]]
-       [[fr:]]
-       [[frp:]]
-       [[fur:]]
-       [[fy:]]
-       [[ga:]]
-       [[gan:]]
-       [[gd:]]
-       [[gl:]]
-       [[glk:]]
-       [[gn:]]
-       [[got:]]
-       [[gu:]]
-       [[gv:]]
-       [[ha:]]
-       [[hak:]]
-       [[haw:]]
-       [[he:]]
-       [[hi:]]
-       [[hif:]]
-       [[ho:]]
-       [[hr:]]
-       [[hsb:]]
-       [[ht:]]
-       [[hu:]]
-       [[hy:]]
-       [[hz:]]
-       [[ia:]]
-       [[id:]]
-       [[ie:]]
-       [[ig:]]
-       [[ii:]]
-       [[ik:]]
-       [[ilo:]]
-       [[io:]]
-       [[is:]]
-       [[it:]]
-       [[iu:]]
-       [[ja:]]
-       [[jbo:]]
-       [[jv:]]
-       [[ka:]]
-       [[kaa:]]
-       [[kab:]]
-       [[kg:]]
-       [[ki:]]
-       [[kj:]]
-       [[kk:]]
-       [[kl:]]
-       [[km:]]
-       [[kn:]]
-       [[ko:]]
-       [[kr:]]
-       [[ks:]]
-       [[ksh:]]
-       [[ku:]]
-       [[kv:]]
-       [[kw:]]
-       [[ky:]]
-       [[la:]]
-       [[lad:]]
-       [[lb:]]
-       [[lbe:]]
-       [[lg:]]
-       [[li:]]
-       [[lij:]]
-       [[lmo:]]
-       [[ln:]]
-       [[lo:]]
-       [[lt:]]
-       [[lv:]]
-       [[map-bms:]]
-       [[mdf:]]
-       [[mg:]]
-       [[mh:]]
-       [[mhr:]]
-       [[mi:]]
-       [[mk:]]
-       [[ml:]]
-       [[mn:]]
-       [[mo:]]
-       [[mr:]]
-       [[ms:]]
-       [[mt:]]
-       [[mus:]]
-       [[mwl:]]
-       [[my:]]
-       [[myv:]]
-       [[mzn:]]
-       [[na:]]
-       [[nan:]]
-       [[nap:]]
-       [[nds:]]
-       [[nds-nl:]]
-       [[ne:]]
-       [[new:]]
-       [[ng:]]
-       [[nl:]]
-       [[nn:]]
-       [[no:]]
-       [[nov:]]
-       [[nrm:]]
-       [[nv:]]
-       [[ny:]]
-       [[oc:]]
-       [[om:]]
-       [[or:]]
-       [[os:]]
-       [[pa:]]
-       [[pag:]]
-       [[pam:]]
-       [[pap:]]
-       [[pdc:]]
-       [[pi:]]
-       [[pih:]]
-       [[pl:]]
-       [[pms:]]
-       [[pnt:]]
-       [[pnb:]]
-       [[ps:]]
-       [[pt:]]
-       [[qu:]]
-       [[rm:]]
-       [[rmy:]]
-       [[rn:]]
-       [[ro:]]
-       [[roa-rup:]]
-       [[roa-tara:]]
-       [[ru:]]
-       [[rw:]]
-       [[sa:]]
-       [[sah:]]
-       [[sc:]]
-       [[scn:]]
-       [[sco:]]
-       [[sd:]]
-       [[se:]]
-       [[sg:]]
-       [[sh:]]
-       [[si:]]
-       [[simple:]]
-       [[sk:]]
-       [[sl:]]
-       [[sm:]]
-       [[sn:]]
-       [[so:]]
-       [[sq:]]
-       [[sr:]]
-       [[srn:]]
-       [[ss:]]
-       [[st:]]
-       [[stq:]]
-       [[su:]]
-       [[sv:]]
-       [[sw:]]
-       [[szl:]]
-       [[ta:]]
-       [[te:]]
-       [[tet:]]
-       [[tg:]]
-       [[th:]]
-       [[ti:]]
-       [[tk:]]
-       [[tl:]]
-       [[tn:]]
-       [[to:]]
-       [[tpi:]]
-       [[tr:]]
-       [[ts:]]
-       [[tt:]]
-       [[tum:]]
-       [[tw:]]
-       [[ty:]]
-       [[udm:]]
-       [[ug:]]
-       [[uk:]]
-       [[ur:]]
-       [[uz:]]
-       [[ve:]]
-       [[vec:]]
-       [[vi:]]
-       [[vls:]]
-       [[vo:]]
-       [[wa:]]
-       [[war:]]
-       [[wo:]]
-       [[wuu:]]
-       [[xal:]]
-       [[xh:]]
-       [[yi:]]
-       [[yo:]]
-       [[za:]]
-       [[zea:]]
-       [[zh:]]
-       [[zh-classical:]]
-       [[zh-min-nan:]]
-       [[zh-yue:]]
-       [[zu:]]
+==This subdomain is reserved for the creation of a [[wikimedia:Our projects|$ucsite]] in '''[[w:en:{$name}|{$name}]]''' language==
+
+* Please '''do not start editing''' this new site. This site has a test project on the [[incubator:|Wikimedia Incubator]] (or on the [[betawikiversity:|BetaWikiversity]] or on the [[oldwikisource:|Old Wikisource]]) and it will be imported to here.
+
+* If you would like to help translating the interface to this language, please do not translate here, but go to [[translatewiki:|translatewiki]], a special wiki for translating the interface. That way everyone can use it on every wiki using the [[mw:|same software]].
+
+* For information about how to edit and for other general help, see [[m:Help:Contents|Help on Wikimedia's Meta-Wiki]] or [[mw:Help:Contents|Help on MediaWiki.org]].
+
+== Sister projects ==
+<span class="plainlinks">
+[http://www.wikipedia.org Wikipedia] |
+[http://www.wiktionary.org Wiktonary] |
+[http://www.wikibooks.org Wikibooks] |
+[http://www.wikinews.org Wikinews] |
+[http://www.wikiquote.org Wikiquote] |
+[http://www.wikisource.org Wikisource]
+[http://www.wikiversity.org Wikiversity]
+</span>
+
+See Wikimedia's [[m:|Meta-Wiki]] for the coordination of these projects.
 
 EOT;
        }
 }
 
 $maintClass = "AddWiki";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );