2009-05-29 118 views
3

我正在嘗試編寫一個腳本,該腳本將在MediaWiki中創建一個用戶,以便我可以運行批處理作業以導入一系列用戶。將用戶添加到MediaWiki的腳本

我正在使用mediawiki-1.12.0。

我從一個論壇的代碼,但它看起來並不像它具有1.12的作品(它是1.13)

$name = 'Username'; #Username (MUST start with a capital letter) 
$pass = 'password'; #Password (plaintext, will be hashed later down) 
$email = 'email'; #Email (automatically gets confirmed after the creation process) 
$path = "/path/to/mediawiki"; 
putenv("MW_INSTALL_PATH={$path}"); 
require_once("{$path}/includes/WebStart.php"); 
$pass = User::crypt($pass); 
$user = User::createNew($name, array('password' => $pass, 'email' => $email)); 
$user->confirmEmail(); 
$user->saveSettings(); 
$ssUpdate = new SiteStatsUpdate(0, 0, 0, 0, 1); 
$ssUpdate->doUpdate(); 

謝謝!

回答

5

maintenance/中有createAndPromote腳本,它創建用戶帳戶並授予管理員權限。你可以調整它來刪除權限部分。

或者,您可以查看ImportUsers擴展。

3

我用這對Mediawiki的1.7,它的工作很適合我:

#!/usr/bin/php 
## Add a user to Mediawiki 

<?php 

    $domain = 'example.com'; 
    $mwpath = '/docs/www-wiki'; 

    if ($argc < 3) { 
     die("Missing arguments.\n" 
      ."Usage: $0 USER PASSWORD\n"); 
    } 
    $user = $argv[1]; 
    $pass = $argv[2]; 

    print "Add user $user with password $pass [y/N]?\n"; 
    $ans = fgets(STDIN,256); 
    if (! preg_match('/^[yY]/', $ans)) { 
     print "Canceled.\n"; 
     exit; 
    } 

    $user = ucfirst(strtolower($user)); // maybe unneeded, because handled in MW functions? 


    # Adapted from http://www.mwusers.com/forums/showthread.php?9788-Create-new-user-in-database&p=42931&viewfull=1#post42931 

    $path = $mwpath; 
    putenv("MW_INSTALL_PATH={$path}"); 

    #require_once ("{$path}/includes/WebStart.php"); // for version >= 1.14 ? 

    # My version 1.7 doesn't have WebStart.php. 
    # It seems to work by including the following lines found in index.php 
    # Some are probably not needed, but I don't want to do more testing 
    define('MEDIAWIKI', true); 
    require_once('./includes/Defines.php'); 
    require_once('./LocalSettings.php'); 
    require_once('includes/Setup.php'); 
    require_once("includes/Wiki.php"); 
    $mediaWiki = new MediaWiki(); 


    $mwuser=User::newFromName($user); 

    if (! is_object($mwuser)) { 
     die("Invalid user!\n"); 
    } 

    $mwuser->addToDatabase(); // don't we need a return value to check? 
    $mwuser->setPassword($pass); 
    $mwuser->setEmail(strtolower($user) . '@' . $domain); 
    $mwuser->confirmEmail(); 

    #$mwuser->setRealName($_POST["nome"]); 
    #$mwuser->addGroup($_POST["grupo"]); 

    $mwuser->saveSettings(); // no return value? 
    $ssUpdate = new SiteStatsUpdate(0, 0, 0, 0, 1); 
    $ssUpdate->doUpdate(); 
?> 

我猜你的問題也是在你的腳本,它並沒有在你的Mediawiki的版本存在使用WebStart.php的。