[Pmwiki-users] PmWikiDataStore - Using a class for page file i/o.

Greg Morgan Cybie
Sun Mar 21 22:17:32 CST 2004


http://www.pmichaud.com/wiki/Development/PmWikiDataStore

I've just finished a patch for PmWiki that I was hoping to get included 
in the next release.
------------------------------------------------------------------------
I'm working on two add-ons for PmWiki 
<http://www.pmichaud.com/wiki/Development/PmWiki>

   1. XML-RPC <http://www.pmichaud.com/wiki/Development/XML-RPC> support
      using the vpwiki API.
   2. Allowing as an option to use an SQL database to store pages as
      opposed to the current file based method.

While writing the XML-RPC module I realized I was going to have 
duplicate most of the functionality in the handle_post function, if I 
wanted to update pages and keep the page revisions current. That and 
there's no way to override the existing ReadPage? 
<http://www.pmichaud.com/wiki/Development/ReadPage?action=edit> and 
WritePage? 
<http://www.pmichaud.com/wiki/Development/WritePage?action=edit> methods 
to allow for other means of storing pages. So what I did was create a 
class called WikiDataStore? 
<http://www.pmichaud.com/wiki/Development/WikiDataStore?action=edit>. 
The methods of which are as follows $WikiDataStore is an object that's a 
descendant of WikiDataStore? 
<http://www.pmichaud.com/wiki/Development/WikiDataStore?action=edit> (by 
default it's FileBasedWikiDataStore? 
<http://www.pmichaud.com/wiki/Development/FileBasedWikiDataStore?action=edit>) 


    * WikiDataStore?
      <http://www.pmichaud.com/wiki/Development/WikiDataStore?action=edit>

function PageExists? 
<http://www.pmichaud.com/wiki/Development/PageExists?action=edit> 
($pagename)
    $foo=$WikiDataStore->PageExists?
    <http://www.pmichaud.com/wiki/Development/PageExists?action=edit>($pagename)

    $foo=true = pages exists
    $foo=false= page does not exist 
function PageList? 
<http://www.pmichaud.com/wiki/Development/PageList?action=edit> ()
    $foo=$WikiDataStore->PageList?
    <http://www.pmichaud.com/wiki/Development/PageList?action=edit>();
    $foo will be an array of all pages on the wiki

    This should be used instead of using foreach to go through each file
    in |$WikiLibDirs|
    <http://www.pmichaud.com/wiki/PmWiki/BasicVariables#WikiLibDirs>. 
function GroupList? 
<http://www.pmichaud.com/wiki/Development/GroupList?action=edit>()
    $foo=$WikiDataStore->GroupList?
    <http://www.pmichaud.com/wiki/Development/GroupList?action=edit>();
    $foo will be an array of all groups on the wiki 
function LockPage? 
<http://www.pmichaud.com/wiki/Development/LockPage?action=edit> 
($op,$pagename=NULL)
    $WikiDataStore->LockPage?
    <http://www.pmichaud.com/wiki/Development/LockPage?action=edit>($op,$pagename)

    $op - see flock description in php manual for details
    $pagename - page being locked. For file system based wikis this is
    ignored. But this is here to allow for row level locking if an SQL
    based datastore is created. 
function ReadPage? 
<http://www.pmichaud.com/wiki/Development/ReadPage?action=edit> 
($pagename, $defaulttext=NULL)
    $page=$WikiDataStore->ReadPage?
    <http://www.pmichaud.com/wiki/Development/ReadPage?action=edit>($pagename,$defaulttext)

    This returns an associtive array containing the page information.
    $page['text'] = text for the wiki page.
    If the page does not exist, text is replaced with $defaulttext, if set.
    This method can be used by itself, or if the patched pmwiki.php is
    installed, the standard ReadPage?
    <http://www.pmichaud.com/wiki/Development/ReadPage?action=edit>
    function can be used. 
function WritePage? 
<http://www.pmichaud.com/wiki/Development/WritePage?action=edit> 
($pagename, $page)
    $WikiDataStore->WritePage?
    <http://www.pmichaud.com/wiki/Development/WritePage?action=edit>($pagename,$page)

    $pagename = page you are writing too.
    $page = associative array containing page information. (same as
    returned by ReadPage?
    <http://www.pmichaud.com/wiki/Development/ReadPage?action=edit>)
    This method can be used by itself, or if the patched pmwiki.php is
    installed, the standard WritePagefunction?
    <http://www.pmichaud.com/wiki/Development/WritePagefunction?action=edit>
    can be used. 
function PostPage? 
<http://www.pmichaud.com/wiki/Development/PostPage?action=edit> 
($pagename,$pagedata,$UserName=NULL,$Password=NULL)
    $WikiDataStore->PostPage?
    <http://www.pmichaud.com/wiki/Development/PostPage?action=edit>($pagename,$pagedata,$UserName,$Password)

    $pagename = page you are writing too.
    $pagedata = associative array containing new info for the page.
    $UserName = User Name of the person making the change
    $Password = Password

    This function handles the file I/O that's currently in the
    handle_post function. 

NOTE: $UserName & $Password not currently implemented.


  Changes made to existing modules

    * PmWiki.php
          o Defined new global variables.
                + $DataStoreLibrary - file name of file to include for
                  the datastore class.
                + $WikiDataStore - object that descends from
                  WikiDataStore?
                  <http://www.pmichaud.com/wiki/Development/WikiDataStore?action=edit>.
                  This object is used for all Page I/O
          o Modified ReadPage?
            <http://www.pmichaud.com/wiki/Development/ReadPage?action=edit>,WritePage?
            <http://www.pmichaud.com/wiki/Development/WritePage?action=edit>,PageExists?
            <http://www.pmichaud.com/wiki/Development/PageExists?action=edit>
            functions to use the WikiDataStore?
            <http://www.pmichaud.com/wiki/Development/WikiDataStore?action=edit>
            class functions of the same name.
          o Modified handle_post to use the PostPage?
            <http://www.pmichaud.com/wiki/Development/PostPage?action=edit>
            method in WikiDataStore?
            <http://www.pmichaud.com/wiki/Development/WikiDataStore?action=edit>

    * search.php
          o SearchResults?
            <http://www.pmichaud.com/wiki/Development/SearchResults?action=edit>
            function now uses a pagelist generated from
            $pagelist=$WikiDataStore->PageList?
            <http://www.pmichaud.com/wiki/Development/PageList?action=edit>();
            to get the list of pages to search.
    * refcount.php
          o PrintRefCount?
            <http://www.pmichaud.com/wiki/Development/PrintRefCount?action=edit>
            function also uses $WikiDataStore->PageList?
            <http://www.pmichaud.com/wiki/Development/PageList?action=edit>()
            and $WikiDataStore->GroupList?
            <http://www.pmichaud.com/wiki/Development/GroupList?action=edit>()
            to get the pages and groups to check.

$WikiDataStore=new FileBasedWikiDataStore? 
<http://www.pmichaud.com/wiki/Development/FileBasedWikiDataStore?action=edit>;
FileBasedWikiDataStore is a class which extends WikiDataStore to use the 
standard PmWiki data files.
 Attach:pmwikidatastore.zip 
<http://www.pmichaud.com/uploads/Development/pmwikidatastore.zip>

<http://www.pmichaud.com/uploads/Development/pmwikidatastore.zip>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://contra.vosn.net/pipermail/pmwiki-users_pmichaud.com/attachments/20040321/8b90b18d/attachment-0001.htm


More information about the pmwiki-users mailing list