Recent Changes - Search:

Cookbook

PmWiki

pmwiki.org

GetRidOfMain

Summary: How to get rid of "Main" group, i.e. all pages in "Main" are accessible and accessed directly in the wiki root
Version: 1.0
Prerequisites:
Status:
Maintainer:
Categories: Administration Links
Discussion: GetRidOfMain-Talk

Questions answered by this recipe

Is there a way to further improve the CleanUrls recipe by getting rid of the "Main" group?
This means that all the items in the "Main" group should be available, linked, and displayed as if they were in the root directory. Instead of "www.server.com/Main/Information" one would have "www.server.com/Information" etc.
This might be especially appealing to people who use PmWiki as their web site engine.

Description

Add this to your local/config.php:

## add default group (Main) to page search path 
$PagePathFmt = array(
      '{$Group}.$1',           # page in current group
      '{$DefaultGroup}.$1',    # page in default group (Main)
      '$1.$1',                 # group home page
      '$1.{$DefaultName}',     # group home page
);
SDV($DefaultPage, 'Main.HomePage');
$pagename = MakePageName($DefaultPage, $pagename);

## reformat page urls to omit default group (Main)
$EnablePathInfo = 1;
$FmtPV['$PageUrl'] = 'PUE(($group==$GLOBALS["DefaultGroup"])
                            ? (($name==$GLOBALS["DefaultName"]) ? "$ScriptUrl/" : "$ScriptUrl/$name")
                              : "$ScriptUrl/$group/$name")';
$FmtP["!\\\$ScriptUrl/$DefaultGroup/!"] = '$ScriptUrl/';

If you are using the Index File method in CleanUrls Add this to your local/config.php instead:

######################################
# Eliminate "index.php" & "pmwiki.php" from Urls, 
# You may already have the next 2 lines in your config.php if you have previously set up CleanURLs
$EnablePathInfo = 0;
$ScriptUrl = dirname($ScriptUrl)."/";
######################################
# get rid of "Main." from Urls
$PagePathFmt = array(
           '{$Group}.$1',           # page in current group
           '{$DefaultGroup}.$1',    # page in default group (Main)
           '$1.$1',                 # group home page
           '$1.{$DefaultName}',     # group home page
    );

   SDV($DefaultPage, 'Main.HomePage');
   $pagename = MakePageName($DefaultPage, $pagename);

    $FmtPV['$PageUrl'] = 'PUE(($group==$GLOBALS["DefaultGroup"])
                                 ? "$ScriptUrl/$name"
                                   : "$ScriptUrl/$group/$name")';
######################################

Notes

If you change the $DefaultGroup to something other than 'Main' then the RecentChanges will continue to refer to Main.RecentChanges and any broken link pointing to [$DefaultGroup.Something] will bring up an edit page for Main.Something. Because of this, I recommend that anyone using this code, only use it with $DefaultGroup = 'Main'.

This is no longer true. I modified the code above so that your 'Main' group can be whatever you like:
  from
  $pagename = MakePageName('Main.HomePage', $pagename);
  to
  $pagename = MakePageName($DefaultPage, $pagename);

Fix for links to non-existing pages

This fix requires apache2's mod_rewrite. I have only tested it in conjunction with CleanUrls' URL Rewriting Example 3, but it should be extendible to other cases.

In the .htaccess file described by CleanUrls' URL Rewriting Example 3, replace:

# Send requests to pmwiki.php, appending the query string part.
RewriteRule ^([A-Z0-9\xa0-\xff].*)$ pmwiki.php?n=$1  [QSA,L]

with:

#Send single name pages to pmwiki.php?n=Main.$1
RewriteRule ^([A-Z0-9\xa0-\xff][^\.\/]*(\?.*)?)$ pmwiki.php?n=Main.$1  [QSA,L]
# Send requests to pmwiki.php, appending the query string part.
RewriteRule ^([A-Z0-9\xa0-\xff].*)$ pmwiki.php?n=$1  [QSA,L]

Note: A <Directory "/path/to/wiki"> ... </Directory> section of httpd.conf or your site config can be used instead of '.htaccess'

Release Notes

If the recipe has multiple releases, then release notes can be placed here. Note that it's often easier for people to work with "release dates" instead of "version numbers".

See Also

  • SEO
  • CleanUrls Enable URLs that are shorter (without .php) and/or look like paths to wiki pages.

Contributors

Pm
Jared
AndyG
SMaddox

Comments

See discussion at GetRidOfMain-Talk

User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.

Edit - History - Print - Recent Changes - Search
Page last modified on October 20, 2013, at 08:06 PM