Wednesday, February 11, 2009

Writing Wiki Wednesday: Word Count



One thing important to all writers is word count. This is how we get paid, this is the measure of our productivity, this is the demon monkey upon our backs.

I've mentioned before a few times that I use a Personal Wiki to track my writing. Mine is based on Mediawiki running on the MoWeS Software from CHSoftware. I like the wiki because it allows me all the freedom of a word processor, plus the linkability of a wiki. I can track, organize and access all my notes and story ideas very easily. This week I give you another hack to improve your Writing Wiki.

I write stories in sections, generally no more than 4000 words a section, this keeps the wiki pages from getting too big. There are ways around size limits on wiki pages. Also I think ignoring the size limits actually has little consequence for a predominately text page, other than slow loading times. So for me each section is analogous to a chapter. At the top of each section, on the web page, is a little tab counting how many words on that page. Pretty handy.

More Below...


I really have this post over at Demented Kitty to thank for this trick. (And she thanks Kishore Asokan)

This is a simple way to get a word count off of wiki pages. Let's be clear, it's crude and will count almost everything on the page. If you really need a precise word count, just cut and paste into a word processor document, but this will give you a good indicator of where you are.

I had to make some changes to the code/instructions to get it to work on my wiki, this is due to some changes in the Mediawiki software since Demented Kitty's post. My version of Mediawiki is 1.13.1 - I've looked at the Monobook skin file for 1.13.3 and I think this should work.


MediaWiki Word Count Tab


Here's how:

1. This requires a Mediawiki software based Wiki 1.13.1 or later - tested against 1.13.1

2. To put this into your Monobook Skin, open: skins/MonoBook.php

3. Look for this big comment and block of code:


# We don't want to give the watch tab an accesskey if the
# page is being edited, because that conflicts with the
# accesskey on the watch checkbox. We also don't want to
# give the edit tab an accesskey, because that's fairly su-
# perfluous and conflicts with an accesskey (Ctrl-E) often
# used for editing in Safari.
if( in_array( $action, array( 'edit', 'submit' ) )
&& in_array( $key, array( 'edit', 'watch', 'unwatch' ))) {
echo $skin->tooltip( "ca-$key" );
} else {
echo $skin->tooltipAndAccesskey( "ca-$key" );
}
echo '>'.htmlspecialchars($tab['text']).'</a></li>';
} ?>



4. Paste the code from below the snip after the } ?> characters at the end of that section and before the next lines of:
  </ul>
</div>


------------------------------snip----------------------------



// Getting the total words count

global $wgUser, $wgArticle, $db;

//check if its an article

if($wgArticle && !$_GET['action']) {

$c=$wgArticle->getContent();

$stripped= strip_tags($c);

$exploded=explode(" ", $stripped);

//you can print this variable anywhere you want

$totalwords=count($exploded);

}

?>
<li><font color="red">&nbsp;
<?php echo $totalwords ;
?> words &nbsp;
</font></li>


-----------------------snip------------------------------

5. Save the skins/MonoBook.php file and upload it to your server.

When you finish, there should be a word count tab at the top of every article page. Some special pages will show the word count tab as well.



No comments: