I need to migrate MediaWiki data into wikitools, how it can be done?

Found only this:
http://cwgordon.com/how-to-create-a-wiki-with-drupal#comment-1780
Any better way of doing that?
It's worth to implement it into wikitools module?

Comments

kenorb’s picture

TimelessDomain’s picture

subscribing

kenorb’s picture

Here is example block of code you can use to connect to mediawiki database from Drupal:
http://api.drupal.org/api/drupal/includes--database.inc/function/db_set_...
I'll post the full code soon.

kenorb’s picture

Category: feature » support
Status: Needs work » Active
/**
 * Convert wikimedia content into nodes
 *   Dependencies: mediawikiauth module
 * 
 */
function wikitools_migrate_wikimedia_content($ctype = 'wiki') {
  // load database current configuration
  global $db_url;
  if (is_string($db_url)) {
    $db_url = array('default' => $db_url);
    $prevdb = end(explode('/', current($db_url)));
  }

  // load mediawikiauth configuration
  $all_vals = array();
  $wikicount = variable_get('mediawiki_wikicount', 1);

  ini_set("max_execution", 600); // set time limit to 10 min, increase if necessary
  for ($i=1; $i<=$wikicount; $i++) { // for each wiki configured in mediawikiauth
    $db_name = variable_get("mediawiki_dbname_$i", '') . variable_get("mediawiki_dbprefix_$i", '');
    $db_url[$db_name] = substr($db_url['default'], 0, -strlen($prevdb)) . $db_name;
    if (db_set_active($db_name)) {
      $result = db_query("SELECT page_title as title, old_text as text, page_latest FROM `page`, `text`, revision WHERE page_latest = rev_id AND rev_text_id = old_id AND page_is_new = 0 order by page_title, page_latest DESC");
      db_set_active();
      while ($page = db_fetch_object($result)) {
        $node = new stdClass();
        $node->type = $ctype;
        $node->title = html_entity_decode(str_replace('_', ' ', $page->title), ENT_QUOTES, 'UTF-8');
        $node->body = html_entity_decode($page->text, ENT_QUOTES, 'UTF-8');
        // $node->format = 8; // SET your sequence of configured input format (like: flexifilter)
        node_save($node);
        if ($node->nid) {
          $wikipath = htmlspecialchars_decode(urldecode(wikitools_wikilink_drupal_path($node->title)), ENT_QUOTES);
          path_set_alias('node/'. $node->nid, urldecode($wikipath)); // add new wiki alias, workaround for: #239370
          drupal_set_message(t("Mediawiki page %title migrated successfully into Drupal the node (node: <a href='!url'>%nid</a>).",
            array('%title' => $node->title, '!url' => url('node/' . $node->nid), '%nid' => $node->nid)), 'status');
        } else {
          drupal_set_message(t("Mediawiki page %title not migrated, because the node couldn't be saved properly.",
            array('%title' => $node->title), 'error'));
        }
      }
    } else { // Never executed because of Drupal core issue: #1189212
      drupal_set_message(t("Can't migrate WikiMedia content, because database `%s` doesn't exists. Check your configuration."), 'error');
    }
  }
  drupal_set_message(t('WikiMedia migration completed.'));
}

Make sure as well that you have the right database name in your MediaWiki Auth configuration (admin/settings/mediawikiauth).
Make sure as well that Drupal db user has access to that database.

kenorb’s picture

Category: support » feature
Status: Active » Needs work
TimelessDomain’s picture

Category: support » feature
Status: Active » Needs work

Thank you kenorb for working on this! Do you plan on launching it as a module? or can you provide a patch to integrate this with wikitools?

kenorb’s picture

Hi,
Probably not.
I was only working on this one week and I'm not planing further development.
This function is used only for one time migration, so as separate module it will be not much usage of it and it will be another non-maintained module.
It will be good to be part of some existing module related to Mediawiki functionality.
I think Wikitools module will be the best for it.
I.e. we can include it into some include file like: wikitools.migrate.inc and load it on demand (some option from settings).
I used that function from hook_update that it was part of next release process.

kenorb’s picture

Issue summary: View changes
Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.