[pmwiki-users] Wiki Stub detection

Patrick R. Michaud pmichaud at pobox.com
Fri Feb 17 16:40:48 CST 2006


On Thu, Feb 16, 2006 at 10:13:22PM -0800, Comit wrote:
> Would it possible, using the conditional markups + groupfooter, to write a 
> markup that can detect if there's less than, say, 5 lines in an article, and 
> if true, print a sentence that basically says it's a stub article?

The following adds an "(:if stub:)" conditional:

    function IsStub($pagename) {
      $p = ReadPage($pagename, READPAGE_CURRENT);
      return substr_count($p['text'], "\n") < 5;
    }
    
    $Conditions['stub'] = "IsStub(\$pagename)";

With this enabled, you can do:

    (:if stub:)
    This is a page stub.
    (:if:)

and it will display the contents if the current page has fewer than
five lines of markup.   (Note that "current page" is the page
being displayed, which might not be the same as the page containing
the (:if stub:) markup.)

Pm




More information about the pmwiki-users mailing list