<commit_before><?php
/**
 * This script adds a user to mediawiki. It is meant to initialize meza.
 *
 * Usage:
 *  no parameters
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 * http://www.gnu.org/copyleft/gpl.html
 *
 * @author <NAME>
 * @ingroup Maintenance
 */
require_once( '/opt/meza/htdocs/mediawiki/maintenance/Maintenance.php' );
class MezaUnifyUserTables extends Maintenance {

	public function __construct() {
		parent::__construct();

		$this->mDescription = "This combines all user tables into one. This is potentially very destructive. Make a backup first.";

		// addOption ($name, $description, $required=false, $withArg=false, $shortName=false)
		$this->addOption(
			'prime-wiki',
			'Wiki ID of prime wiki',
			true, true );

	}

	public function execute() {

		global $m_htdocs;

		if ( is_file( "$m_htdocs/__common/primewiki" ) ) {
			die( "A prime wiki is already set in $m_htdocs/__common/primewiki. You cannot run this script." );
		}

		// prime wiki ID and database name
		$primeWiki = trim( $this->getOption( "prime-wiki" ) );

		// all other wiki IDs
		$wikiIDs = array_slice( scandir( "$m_htdocs/wikis" ), 2 );

		// make array of all wiki database names, including prime wiki

		$wikiDBconnections[$primeWiki] = $this->getWikiDbConfig( $primeWiki );
		foreach ( $wikiIDs as $wikiID ) {
			$wikiDBconnections[$wikiID] = $this->getWikiDbConfig( $wikiID );
		}

		// FIXME: make the script check for the largest value
		$initialOffset = 10000; // make sure this is larger than your largest user ID


		// $idAndNameTables = array(
		// 	"archive"       => array( "idField" => "ar_user",  "userNameField" => "ar_user_text" ),
		// 	"filearchive"   => array( "idField" => "fa_user",  "userNameField" => "fa_user_text" ),
		// 	"image"         => array( "idField" => "img_user", "userNameField" => "img_user_text" ),
		// 	"logging"       => array( "idField" => "log_user", "userNameField" => "log_user_text" ),
		// 	"oldimage"      => array( "idField" => "oi_user",  "userNameField" => "oi_user_text" ),
		// 	"recentchanges" => array( "idField" => "rc_user",  "userNameField" => "rc_user_text" ),
		// 	"revision"      => array( "idField" => "rev_user", "userNameField" => "rev_user_text" ),
		// );


		$userTable = array( "idField" => "user_id", "userNameField" => "user_name" );

		$userColumnInfo = array(
			'user_name'         => 'b',
			'user_editcount'    => 'i',
			'user_touched'      => 'b',
			'user_registration' => 'b',
			'user_email'        => 'b',<commit_msg>fix wiki id selection<commit_after><?php
/**
 * This script adds a user to mediawiki. It is meant to initialize meza.
 *
 * Usage:
 *  no parameters
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 * http://www.gnu.org/copyleft/gpl.html
 *
 * @author <NAME>
 * @ingroup Maintenance
 */
require_once( '/opt/meza/htdocs/mediawiki/maintenance/Maintenance.php' );
class MezaUnifyUserTables extends Maintenance {

	public function __construct() {
		parent::__construct();

		$this->mDescription = "This combines all user tables into one. This is potentially very destructive. Make a backup first.";

		// addOption ($name, $description, $required=false, $withArg=false, $shortName=false)
		$this->addOption(
			'prime-wiki',
			'Wiki ID of prime wiki',
			true, true );

	}

	public function execute() {

		global $m_htdocs;

		if ( is_file( "$m_htdocs/__common/primewiki" ) ) {
			die( "A prime wiki is already set in $m_htdocs/__common/primewiki. You cannot run this script." );
		}

		// prime wiki ID and database name
		$primeWiki = trim( $this->getOption( "prime-wiki" ) );

		// all other wiki IDs
		$wikisDirectory = array_slice( scandir( "$m_htdocs/wikis" ), 2 );
		$wikiIDs = array();
		foreach( $wikisDirectory as $fileOrDir ) {
			if ( is_dir( "$m_htdocs/wikis/$fileOrDir" ) ) {
				$wikiIDs[] = $fileOrDir;
			}
		}
		unset( $wikisDirectory );


		// make array of all wiki database names, including prime wiki

		$wikiDBconnections[$primeWiki] = $this->getWikiDbConfig( $primeWiki );
		foreach ( $wikiIDs as $wikiID ) {
			$wikiDBconnections[$wikiID] = $this->getWikiDbConfig( $wikiID );
		}

		// FIXME: make the script check for the largest value
		$initialOffset = 10000; // make sure this is larger than your largest user ID


		// $idAndNameTables = array(
		// 	"archive"       => array( "idField" => "ar_user",  "userNameField" => "ar_user_text" ),
		// 	"filearchive"   => array( "idField" => "fa_user",  "userNameField" => "fa_user_text" ),
		// 	"image"         => array( "idField" => "img_user", "userNameField" => "img_user_text" ),
		// 	"logging"       => array( "idField" => "log_user", "userNameField" => "log_user_text" ),
		// 	"oldimage"      => array( "idField" => "oi_user",  "userNameField" => "oi_user_text" ),
		// 	"recentchanges" => array( "idField" => "rc_user",  "userNameField" => "rc_user_text" ),
		// 	"revision"      => array( "idField" => "rev_user", "userNameField" => "rev_user_text" ),
		// );


		$userTable = array( "idField" => "user_id", "userNameField" => "user_name" );

		$userColumnInfo = array(
			'user_name'         => 'b',
			'user_editcount'    => 'i',
			'user_touched'      => 'b',
			'user_registration' => 'b',
			'user_email'        => 'b',
{'fraction_non_alphanumeric': 0.14117826617826618, 'fraction_numerical': 0.005494505494505495, 'mean_word_length': 3.5538568450312717, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1332856', 'n_tokens_mistral': 2301, 'n_tokens_neox': 2098, 'n_words': 659}