Recent Changes - Search:

Cookbook

PmWiki

pmwiki.org

SharedPages

Summary: Share selected pages among several wikis on a common server, as in WikiFarms
Status: Stable
Prerequisites: pmwiki-2.1.beta10
Maintainer: Pm
Votes:

Description

The general approach to sharing pages is to create a special shared.d/ directory to hold the shared pages, and then configure the $WikiLibDirs variable to search the shared directory for pages. Then, move any pages to be shared from their normal wiki.d directory into the shared.d/ directory.

Normally the shared.d/ directory will go in the same directory of the main PmWiki installation, but any directory will work for this.

Sharing pages "read only"

To have shared pages that cannot be directly modified by any of the wikis, use a configuration such as:

    $WikiLibDirs = array(
      &$WikiDir,
      new PageStore('$FarmD/shared.d/$FullName'),
      new PageStore('$FarmD/wikilib.d/$FullName'));

The above can be placed in a wiki's local/config.php file, or it can go into a farm's local/farmconfig.php to cause all fields of the farm to use the shared pages.

Then, move any pages that are to be shared from a wiki.d/ directory into the shared.d/ directory. Any pages in the shared directory will then be visible to all of the wikis configured to use that directory.

However, when the shared.d/ directory is read-only as in the above, then any (field) wiki that modifies (edits) the shared page will place the page in its local wiki.d/ directory and use the local copy in preference to the shared copy.

Sharing writable pages

If we want a wiki to be able to write into the shared pages, then the configuration is slightly more complex:

    $LockFile = "$FarmD/shared.d/.flock";
    $WikiLibDirs = array(
      &$WikiDir,
      new PageStore('$FarmD/shared.d/$FullName', 1),
      new PageStore('$FarmD/wikilib.d/$FullName'));

We also have to make sure the shared.d/ directory is writable by the webserver -- usually chmod 777 shared.d/ will do it. The $LockFile setting is needed so that the different wikis sharing writable pages can coordinate edits. The "1" in the new PageStore(...) line tells PmWiki that this is a shared directory, and that PmWiki should go ahead and write the page into this directory if it already exists here.

As before, the above lines go into a local/config.php, or into local/farmconfig.php if the pages are to be shared by all fields in a farm.

Any pages to be shared should be moved from wiki.d/ into the shared.d/ directory.

You can have more than one writable shared directory. Notice that there is still only 1 $LockFile.

    $LockFile = "$FarmD/shared.d/.flock";
    $WikiLibDirs = array(
      &$WikiDir,
      new PageStore('$FarmD/shared.d/$FullName', 1),
      new PageStore('$FarmD/shared2.d/$FullName', 1),
      new PageStore('$FarmD/shared3.d/$FullName', 1),
      new PageStore('$FarmD/wikilib.d/$FullName'));

Sharing local.css files on the farm

You can use the farm's pub/css/ directory to share local.css files by redefining the $PageCSSListFmt variable in a field's config.php or the farm's farmconfig.php (for all fields).

Currently the pmwiki distribution of skins.php uses $PubDirUrl rather than $FarmPubDirUrl. You can locally configure it to look in FarmPubDir as well with:

 $PageCSSListFmt = array(
  '$FarmD/pub/css/local.css' => '$FarmPubDirUrl/css/local.css',
  '$FarmD/pub/css/$Group.css' => '$FarmPubDirUrl/css/$Group.css',
  '$FarmD/pub/css/$FullName.css' => '$FarmPubDirUrl/css/$FullName.css',
  'pub/css/local.css' => '$PubDirUrl/css/local.css',
  'pub/css/$Group.css' => '$PubDirUrl/css/$Group.css',
  'pub/css/$FullName.css' => '$PubDirUrl/css/$FullName.css');

Notes

Note that any passwords on shared pages are evaluated in the context of the wiki being accessed; i.e., as if the shared pages were stored locally in the wiki.

Comments

  • Is it possible to configure a Group to be shared? Currently I don't see how to create new pages in shared.d/ without creating them first in the local wiki and then moving them by hand.
I think it's possible to configure a group to be shared by setting $WikiDir in a per-group customization file for the group. But I haven't tried this yet. --Pm
        $WikiDir = new PageStore('$FarmD/shared.d/$FullName');
  • I tried this solution, but on the shared pages, the sidebar customizations are lost (not on unshared pages). Any idea as to the cause and/or cure?
Hi, I've written a quick recipe that creates the ?action=share and =unshare function. A very tiny script (ten real lines), that pushes the file from wiki.d to ../shared.d and vice versa in my farm. You still create the new page in a local wiki, but once the page is made you just run the ?action=share function to 'share' it. Running ?action=unshare moves the file out of the shared.d folder back to the local wiki. It's not much, but it addresses the problem without too much work. 2006-Jun-13 JacobMunoz
      <?php if (!defined('PmWiki')) exit();
     SDV($HandleActions['share'], 'HandleShare');
     SDV($HandleAuth['share'], 'edit');
     function HandleShare($pagename) {
        rename("wiki.d/$pagename","../shared.d/".basename($pagename));
        Redirect($pagename);  }
     SDV($HandleActions['unshare'], 'HandleUnshare');
     SDV($HandleAuth['unshare'], 'edit');
     function HandleUnshare($pagename) {
        rename("../shared.d/$pagename","wiki.d/".basename($pagename));
	 Redirect($pagename);  }
     ?> 
  • How do you set up a shared uploads/ dir? At the moment, shared pages that have attached images only retain the images in the local wiki. In the other wiki that shares the page the images are missing.
There's not really a way to do this yet, sorry. You might try using a custom InterMap link for files in a shared uploads directory. --Pm
  • Thanks. Ed Chadwick 2006-01-26.
  • Ed, if you don't care where the images are physically but want to still use them in pages in other wikis in your wikifarm, includefieldpage might work for you. 2006-06-01 --BJayaram
  • Is there any way to have multiple shared directories? I want one for my farm and one specifically just for a set of three wikis in the same farm. --GNUZoo
  • How can I use one shared page to show slightly different text depending on which field it's accessed from?
     ## (:if field1:) is true when hostname contains "field1"
     $Conditions['field1'] = (strpos($_SERVER['HTTP_HOST'], 'field1') !== false);

     ## (:if field2:) is true when hostname contains "field2"
     $Conditions['field2'] = (strpos($_SERVER['HTTP_HOST'], 'field2') !== false);
Then you can have conditionals like
     (:if field1:)
     This content is visible only to people accessing field1.mydomain.com.
     (:if field2:)
     This content is visible only to people accessing field2.mydomain.com
     (:if:)
     Everybody sees this.
  • Is there an easy way to automatically indicate on shared pages that they are shared? e.g. define a new conditional mark-up along the lines of the one above and put it in an all group header? Francis
  • I found that I needed to use double quotes and a backslash in front of $FullName in the PageStore() calls, as demonstrated in WikiFarmAlternative - I combined this with the share-unshare recipe above into sharedpages.phpΔ shi

See Also

Contributors

  • Pm, original text, 2005-12-05
Edit - History - Print - Recent Changes - Search
Page last modified on August 23, 2008, at 05:44 AM