*
 * @file
 * @ingroup Maintenance
 * @author Rob Church <*****@*****.**>
 */
$options = array('help', 'nooverwrite', 'norc');
$optionsWithArgs = array('title', 'user', 'comment');
require_once __DIR__ . '/commandLine.inc';
echo "Import Text File\n\n";
if (count($args) < 1 || isset($options['help'])) {
    showHelp();
} else {
    $filename = $args[0];
    echo "Using {$filename}...";
    if (is_file($filename)) {
        $title = isset($options['title']) ? $options['title'] : titleFromFilename($filename);
        $title = Title::newFromURL($title);
        if (is_object($title)) {
            echo "\nUsing title '" . $title->getPrefixedText() . "'...";
            if (!$title->exists() || !isset($options['nooverwrite'])) {
                $text = file_get_contents($filename);
                $user = isset($options['user']) ? $options['user'] : '******';
                $user = User::newFromName($user);
                if (is_object($user)) {
                    echo "\nUsing username '" . $user->getName() . "'...";
                    $wgUser =& $user;
                    $comment = isset($options['comment']) ? $options['comment'] : 'Importing text file';
                    $flags = 0 | (isset($options['norc']) ? EDIT_SUPPRESS_RC : 0);
                    echo "\nPerforming edit...";
                    $page = WikiPage::factory($title);
                    $content = ContentHandler::makeContent($text, $title);
Example #2
0
if (!isset($options['help']) || !$options['help']) {
    # Check file existence
    $filename = $args[0];
    echo "Using file '{$filename}'...";
    if (file_exists($filename)) {
        echo "found.\n";
        # Work out the title for the page
        if (isset($option['title']) || trim($options['title']) != '') {
            $titleText = $options['title'];
            # Use the supplied title
            echo "Using title '{$titleText}'...";
            $title = Title::newFromText($options['title']);
        } else {
            # Attempt to make a title out of the filename
            echo "Using title from filename...";
            $title = titleFromFilename($filename);
        }
        # Check the title's valid
        if (!is_null($title) && is_object($title)) {
            echo "ok.\n";
            # Read in the text
            $text = file_get_contents($filename);
            # Check the supplied user and fall back to a default if needed
            if (isset($options['user']) && trim($options['user']) != '') {
                $username = $options['user'];
            } else {
                $username = '******';
            }
            echo "Using user '{$username}'...";
            $user = User::newFromName($username);
            # Check the user's valid