MediaWiki Word Count Tab

November 24th, 2007 @ 06:26:34 am, by Tara Email , 430 words, 468 views   English (US)  

Categories: Notes, Projects

My National Novel Writing Month project just passed the 40k mark, and I find that I'm in need of a little structure. I know basically what I want for my final two 5k chapters. I have to line a few ducks first, though.

I slowly started putting everything into a wiki last week. Then, yesterday, when I crossed the 40k word barrier, I sped up the process so I could finish. At first I went with Wikka Wiki. It has a cute, handy, and easy to implement word count action. Copy the code. Paste it into a new document. Name the document and upload it to the right directory. Done. Wikka Wikki has ease of plugins down to a science.

However, my first love is MediaWiki. So I did a fair bit of digging and came across a reasonable little word count hack for MediaWiki page content. Thanks to Kishore Asokan.

MediaWiki Article Word Count

<?
// 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 on the page
$totalwords=count($exploded);
}

?>

I played with the code a bit, but eventually left it as it was. The code is not perfect. It doesn't give an exact word count, but neither do most word processors. What I get is a very reasonable estimate.

I stuck it on a tab in the MonoBook skin and love it.

MediaWiki Word Count Tab


Here's how:

  1. Download and install MediaWiki, if you haven't already.

  2. Assuming you use the MonoBook skin for MediaWiki, open: skins/MonoBook.php

  3. Around line 124, find:

    <?php
    echo htmlspecialchars($tab['text']) ?></a></li>
        <?php         } ?>
            </ul>
        </div>


  4. Insert two line breaks immediately after <?php } ?> but before <ul>.

  5. At the first new line break, copy and paste the MediaWiki Article Word Count code above.

  6. At the second new line break, add a little formatting and a label to fit the word count into a cute, little tab:

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


  7. 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.


Drive (novel)
First draft 80% complete

Categories

November 2007
Sun Mon Tue Wed Thu Fri Sat
 << < Current> >>
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30  

Linkblog

Comics

Podcasts

Web Design Resources

Writing Resources

User Functions

Syndication

Who's Online?

  • Guest Users: 7
andy unknown joseph homework vasant barber betty file mozart baritone finite euclid laura herbert erica kristin trivial sensor new linda xyzzy mutant tape rachel aztecs alias allison garfield tammy larkin fender chat manager kristine edwina key collins lois signature einstein light admin trails nutrition renee puppet hiawatha michelle jean emerald sandra tracy samantha marvin tuttle olivia cshrc simon inna chester persona zmodem emily carole weenie morley bsd mack pluto ferrari tiffany charming innocuous finite samantha smother maggot janie