Revision [17829]

This is an old revision of WikkaBlog made by JavaWoman on 2007-12-12 12:38:21.

 

This page is copied from the TonExtraWiki where it was first developed for wakka 0.1.2 & the code published (changes to work with wikka might well be necessary). Copy to this wiki is done in recognition that some code developed in the past (such as happened at WakkaWiki) has been "lost" to general wiki users when the site was shut down & a wish for that not to happen again.

Wiki Add

(also see [WikifyingTheBlog] (see original site @ TonExtraWiki) and [MTPluginWiki] (now see below where code is added))

This is a plugin I wrote for Wordpress. It crossposts blogpostings to the Wakka-Wiki (and easily adaptable to Wikka Wiki), and adds links to the blogpost pointing to both the normal view and edit view of the wikipage.

What do you have to do in Wordpress:

The code is Public Domain, feel free to use, add and adapt.

So here's the code:
<?php 
/* 
Plugin Name: Wikiadd 
Plugin URI: http://www.zylstra.org/extra/wakka.php?wakka=WikiAdd 
Description: Will crosspost wordpress posts to a wiki as well 
Version: 1.0 
Author: Ton Zijlstra 
Author URI: http://www.zylstra.org/blog 
*/ 
function wiki_link($post_ID) {
	global $wpdb, $tableposts, $tablepost2cat;
	//function called from index
	//this function creates links to the wiki on the weblogpages

	//check if the wiki category was set, which means the post has to be wiki_linked
	$wiki_cat = 15 ; // change this to the id number of your category you want to be wikified
	$query2 = "SELECT category_id FROM $tablepost2cat WHERE post_id = $post_ID AND category_id = $wiki_cat";
	$exists = $wpdb->get_var($query2);
	
	if (!empty($exists)) {
		// construct links one to see wikipage, one to edit, get post title first
		$query3 = "SELECT post_title FROM $tableposts WHERE ID = $post_ID";
		$wiki_title = $wpdb->get_var($query3);

		// in the wiki_title spaces will be replaced by capping the next letter
		$title_array = str_word_count($wiki_title,1);
		$wiki_title = "";
		$numElement = count($title_array);
		for ($pointer = 0; $pointer < $numElement; $pointer ++) {
			$wiki_title = $wiki_title . ucfirst($title_array[$pointer]);
		}
		// construct the links
		$wiki_url = "http://yourdomain.com/wakka/wakka.php?wakka="; // put the base url of your wiki here
		$wiki_see = $wiki_url . $wiki_title;
		$wiki_edit = $wiki_url . $wiki_title . "/edit";

		// print the links to the page
		echo("<a href='".$wiki_see."'>WikiGoSee</a>  |  <a href='".$wiki_edit."'>WikiWorkOnThis</a>");

	}
	return $post_ID;
}

function wiki_add($post_ID) {
	global $wpdb, $tableposts, $tablepost2cat;
	//this function adds the blogpost to the wiki-database
	
	//check if the wiki category was set, which means the post has to be wikified
	$wiki_cat = 15 ; // change this to the id number of the category to be wikified
	$query2 = "SELECT category_id FROM $tablepost2cat WHERE post_id = $post_ID AND category_id = $wiki_cat";
	$exists = $wpdb->get_var($query2);
	
	if (!empty($exists)) {
		// wiki is a category so proceed
		// wikifying means 2 steps, 1 alter the original content to include links to the posting
		// and step 2 add the wiki-page
		
		// Step 1 Alter the original content to include links to the posting
		
		//get content of post from database
		$query1 = "SELECT post_content FROM $tableposts WHERE ID = $post_ID";
		$original_content = $wpdb->get_var($query1);
		

		// construct link to post
		$query3 = "SELECT post_title FROM $tableposts WHERE ID = $post_ID";
		$wiki_title = $wpdb->get_var($query3);
		// add the title as link to the posting
		$post_link = "http://yourdomain.com/wordpress/index.php?p=" . $post_ID;
		$new_content = "====".$wiki_title."====\r\n".$original_content."\r\n\r\n **This post was blogged 
at**:[[".$post_link." your blogname]]";
		// now alter the wikititle to create a camelcase handle for it in the wiki
		// in the wiki_title spaces will be replaced by capping the next letter
		$title_array = str_word_count($wiki_title,1);
		$wiki_title = "";
		$numElement = count($title_array);
		for ($pointer = 0; $pointer < $numElement; $pointer ++) {
			$wiki_title = $wiki_title . ucfirst($title_array[$pointer]);
		}
		//construct date
		$blog_date = date(Y)."-".date(m)."-".date(d)." ".date(H).":".date(i).":".date(s);
		
		// approach database
		$user="username";
		$password="password";
		$database="database";
		mysql_connect(localhost,$user,$password);
		@mysql_select_db($database) or die( "Unable to select database");
		$query5 = "INSERT INTO extra_pages VALUES
 ('','$wiki_title','$blog_date','$new_content','','','Hydrogen blog','Y','','','')";
		mysql_query($query5); 
		mysql_close();
	} // end wiki is category
 	return $post_ID;
}
# Turn on the wikifying process. 
add_action('publish_post', 'wiki_add','0'); 
add_action('wikilinker', 'wiki_link');
?>


Wishlist for improvements:

check the wiki before adding a posting to see if the title already is in use
check if the wikified title of the original blogpost is within the 50 character limit allowed by the Wakka database



MT Plugin for Wakka Wiki

(also see WikifyingTheBlog and WikiAdd)

I am trying to create a plugin for MT (ver. 2.661) to be able to crosspost from MT to my Wiki.
This takes two actions: 1) upon publishing a MT-entry creating a corresponding page in the wiki if the category is 'wikify' and 2) upon rebuilding pages in MT to add links to the wiki when needed.

In the code displayed below I am currently trying to only do the latter, adding links to a posting in the blog. The former (making MT add entries to the wikka database, requires MT version 3 or higher, which I don't use yet. In lower versions this is not possible without digging into the MT core itself.)

This section of code works. When rebuilding a page it cycles through the categories associated with a posting, and if one of them equals "wikify" it will add links to the wiki at the end of a posting. This is done by adding <$MTWikifyThis$> to the index template within the MTEntry context.

package MT::Plugin::WikifyThis;
use MT::Template::Context;
use strict;
MT::Template::Context->add_tag(WikifyThis => sub { &wikifythis; } );

sub wikifythis {
	my $ctx = shift;
	my $wikify_entry = $ctx->stash ('entry');
	my $wikify_cats = $wikify_entry->categories;
	my $cats_number = scalar(@$wikify_cats);
	my $test = "no";
	my $pointer = 0;
	my $wikify_title = $wikify_entry->title;
	for ($pointer = 0; $pointer < $cats_number; $pointer ++) {
		if (@$wikify_cats[$pointer]->label eq "wikify") {
		$test = "yes";}
	}
	if ($test eq "yes") {
		my (@wikify_title_words, $word);
		@wikify_title_words = split(/ /,$wikify_title);
		my $wikified_title = "";
		foreach $word (@wikify_title_words) {
			$wikified_title = $wikified_title.ucfirst($word);
		}
		#build the links to the wiki-page
		my $wiki_baseurl = "http://www.zylstra.org/extra/wakka.php?wakka=";
		my $wiki_see = $wiki_baseurl.$wikified_title;
		my $wiki_edit = $wiki_baseurl.$wikified_title."/edit";
		my $result = " | <a href='".$wiki_see."'>WikiGoSee</a> | <a href='".$wiki_edit."'>WikiGoEdit</a>";
		return $result;
		
	}
	else {return '';}
}
1;
There are no comments on this page.
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki