Summary: Redirect action=source to display the unformatted markup within your skin
Version: 2009-03-01
Prerequisites: (developed and tested with 2.2.0-stable)
Status: stable
Maintainer: Tontyna
Categories: Layout


Ever wanted to see your page source within your skin? Instead of getting a text/plain page in the browser?

Then redirect action=source to a function that works almost like PmWiki's HandleBrowse() but instead of calling MarkupToHTML applies htmlspecialchars() to the page text.


Place the following code into your local/config.php

  $HandleActions["source"] = "HandleSourceInSkin";

  function HandleSourceInSkin($pagename, $auth = 'read') {
    global $HandleSourceFmt, $PageStartFmt, $PageEndFmt, $FmtV, $ShowSourceHeaderFmt;

    $page = RetrieveAuthPage($pagename, $auth, true, READPAGE_CURRENT);
    if (!$page) Abort("?cannot show source of $pagename");

    # heading
    SDV($ShowSourceHeaderFmt, "<h2 class='wikiaction'>$[ShowSource {\$FullName}]</h2>");
    # text
    if (PageExists($pagename)) {
      $text = @$page['text'];
      if (trim($text) == '') {
        $text= 'Page contains no text';
        $class.=' nosource';
    else {
      $text= "Page doesn't exist";
      $class.=' nosource';
    # wrap with <div>
    $FmtV['$PageText'] = "<div class='$class'>".str_replace("\n","<br />",htmlspecialchars($text))."</div>";
    SDV($HandleSourceFmt,array(&$PageStartFmt, &$ShowSourceHeaderFmt, '$PageText', &$PageEndFmt));


Define the CSS classes for the <div> wrap in your custom CSS in pub/css/local.css or in your skin's stylesheet. For example:

  #wikitext .sourcecode {
  #wikitext .nosource {
    margin:2em 0;
    border:2px dotted #800;


Of course you can customize the above function by using SDVs or XLPage Strings instead of fix texts.

Instead of redirecting action=source you can invent a new one e.g.

  $HandleActions["sourceinskin"] = "HandleSourceInSkin";

But why should you?

To make the redirected action available in your skin add something like that to your Site.PageActions:

  (:if ( ! action source ) :)
  * %item rel=nofollow class=source accesskey='$[ak_source]'%[[{*$FullName}?action=source | $[Source] ]]

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

  • (2009-03-01) Initial version

See Also



See discussion at HandleSourceInSkin-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.