Diskussion:WP2Wiki
aus TruBlus Wiki
Note understanding
- Sorry, got no english version yet, will be added in the near future. If u have questions, I can answer them here. --Trublu 17:05, 3. Nov. 2006 (CET)
Quick question
Hey there! My ISP has my wordpress and mediawiki stuff in two different databases (mwki and wrdp1) with two different users (mwki@'localhost' and wrdp1@'localhost'). I don't have much experience with php, being mostly a perl programmer, so I was wondering if you had a solution already for that.
- Kyle (kyle@mannaheim.org)
- Nope, sorry. My solution totally relies on the fact that both installations use the same database (since I use Mediawikis internal access mechanisms to access Wordpress). --Trublu 10:49, 30. Mai 2007 (CEST)
- I just looked into my source to estimate the need changes and I think that it can be done without much problems, I'll try to do that later on. --Trublu 10:54, 30. Mai 2007 (CEST)
Thanx
That'd be awesome, if you get around to it. I'd like to see how the changes are applied as a learning experience for myself.
Adapted
Trublu,
I took a stab at it, and it seems to work. Tossing this out to you to have a look:
[[SNIP]]
// $dbr =& wfGetDB( DB_SLAVE );
// $page = $dbr->tableName( 'wp_posts' );
$login="dbase_login_name"; // replace with privileged userid for Wordpress database
$password="password"; // replace with password for database
$database="databasename"; // replace with name of mysql database
$dbh=mysql_connect ("localhost", $login, $password) or die ('I cannot connect to the database because: ' . mysql_error());
$dbp=mysql_select_db ( $database );
$sql = 'SELECT post_title, post_date, post_content, guid FROM wp_posts order by post_date desc limit '
. $par_count
. " ";
// SELECT * FROM `wp_post2cat`,`wp_posts` WHERE `ID` = wp_post2cat.post_id
//AND wp_post2cat.category_id = 8 OR `ID` = wp_post2cat.post_id AND
//wp_post2cat.category_id = 3 ORDER BY post_date DESC
// $res = $dbr->query( $sql ); // replaced this line with next
$res = mysql_query( $sql );
$totrows = mysql_num_rows($res);
$out = "";
// while( $row = $dbh->fetchObject($res) )
// {
// $out .= makeListItem($row);
// }
for($x=0;$x<$totrows;$x++){
$result_row = mysql_fetch_row($res); //grabs the first (or next) array of results
$title = $result_row[0]; // title
$date = $result_row[1]; // date
$text = $result_row[2]; // text
$guid = $result_row[3]; // guid
$out .= makeListItem($title,$date,$text,$guid);
}
$wgOut->addWikiText($out);
}
// **********************************************************
// Expanded parameters below, rather than passing object...
// Also changed method lookups to parameter variables...
// i.e. $row->guid to $guid
// **********************************************************
function makeListItem( $title,$date,$text,$guid ) {
global $par_text, $par_lines;
// text parsing
$text = preg_replace("/<img[^>]*>/s","",$text); // Added because I have images in my wordpress articles
$text = preg_replace("/\n?<!--more-->.*/s", "",$text);
$text = preg_replace("/<a.*href=\"(.*)\".*>(.*)<\/a>/U", "[$1 $2]", $text);
$text = preg_replace("/((.*\. )).*$/sU","$2...",$text);
$text = str_replace("\n","\n:",$text);
// Date
$parts = explode(" ",$date);
$dates = explode("-", $parts[0]);
$times = explode(":", $parts[1]);
$date = $dates[2] . "." . $dates[1] . "." . $dates[0];
$out = wfMsgForContent('wp2wikitemplate',$date,$guid,$title);
if ($par_text == True) {
$out = $out . "\n:" . wfMsgForContent('wp2wikitemplateText',$text,$guid) . "<br/>\n";
}
return $out;
}
[[SNIP]]
- Seems to be correct. Do you have this working somewhere? --Trublu 17:12, 6. Jun. 2007 (CEST)