3  * This script generates a SQLite database for a MediaWiki version 1.19.0
 
   4  * You must specify the login of the admin (argument 1) and its
 
   5  * password (argument 2) and the folder where the database file
 
   6  * is located (absolute path in argument 3).
 
   7  * It is used by the script install-wiki.sh in order to make easy the
 
   8  * installation of a MediaWiki.
 
  10  * In order to generate a SQLite database file, MediaWiki ask the user
 
  11  * to submit some forms in its web browser. This script simulates this
 
  12  * behavior though the functions <get> and <submit>
 
  15 $argc = $_SERVER['argc'];
 
  16 $argv = $_SERVER['argv'];
 
  23 $url = 'http://localhost:'.$port.'/wiki/mw-config/index.php';
 
  24 $db_dir = urlencode($tmp);
 
  25 $tmp_cookie = tempnam($tmp, "COOKIE_");
 
  27  * Fetches a page with cURL.
 
  29 function get($page_name = "") {
 
  32         if ($page_name != "") {
 
  33                 $page_name_add = '?page='.$page_name;
 
  35         $url = $GLOBALS['url'].$page_name_add;
 
  36         $tmp_cookie = $GLOBALS['tmp_cookie'];
 
  37         curl_setopt($curl, CURLOPT_COOKIEJAR, $tmp_cookie);
 
  38         curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
 
  39         curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
 
  40         curl_setopt($curl, CURLOPT_COOKIEFILE, $tmp_cookie);
 
  41         curl_setopt($curl, CURLOPT_HEADER, true);
 
  42         curl_setopt($curl, CURLOPT_URL, $url);
 
  44         $page = curl_exec($curl);
 
  46                 die("Could not get page: $url\n");
 
  53  * Submits a form with cURL.
 
  55 function submit($page_name, $option = "") {
 
  57         $datapost = 'submit-continue=Continue+%E2%86%92';
 
  59                 $datapost = $option.'&'.$datapost;
 
  61         $url = $GLOBALS['url'].'?page='.$page_name;
 
  62         $tmp_cookie = $GLOBALS['tmp_cookie'];
 
  63         curl_setopt($curl, CURLOPT_URL, $url);
 
  64         curl_setopt($curl, CURLOPT_POST, true);
 
  65         curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
 
  66         curl_setopt($curl, CURLOPT_POSTFIELDS, $datapost);
 
  67         curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
 
  68         curl_setopt($curl, CURLOPT_COOKIEJAR, $tmp_cookie);
 
  69         curl_setopt($curl, CURLOPT_COOKIEFILE, $tmp_cookie);
 
  71         $page = curl_exec($curl);
 
  73                 die("Could not get page: $url\n");
 
  80  * Here starts this script: simulates the behavior of the user
 
  81  * submitting forms to generates the database file.
 
  82  * Note this simulation was made for the MediaWiki version 1.19.0,
 
  83  * we can't assume it works with other versions.
 
  88 if (!preg_match('/input type="hidden" value="([0-9]+)" name="LanguageRequestTime"/',
 
  90         echo "Unexpected content for page downloaded:\n";
 
  94 $timestamp = $matches[1];
 
  95 $language = "LanguageRequestTime=$timestamp&uselang=en&ContLang=en";
 
  96 $page = submit('Language', $language);
 
 100 $db_config = 'DBType=sqlite';
 
 101 $db_config = $db_config.'&sqlite_wgSQLiteDataDir='.$db_dir;
 
 102 $db_config = $db_config.'&sqlite_wgDBname='.$argv[1];
 
 103 submit('DBConnect', $db_config);
 
 105 $wiki_config = 'config_wgSitename=TEST';
 
 106 $wiki_config = $wiki_config.'&config__NamespaceType=site-name';
 
 107 $wiki_config = $wiki_config.'&config_wgMetaNamespace=MyWiki';
 
 108 $wiki_config = $wiki_config.'&config__AdminName='.$login;
 
 110 $wiki_config = $wiki_config.'&config__AdminPassword='.$pass;
 
 111 $wiki_config = $wiki_config.'&config__AdminPassword2='.$pass;
 
 113 $wiki_config = $wiki_config.'&wiki__configEmail=email%40email.org';
 
 114 $wiki_config = $wiki_config.'&config__SkipOptional=skip';
 
 115 submit('Name', $wiki_config);