예제 #1
0
 function renamePages(&$dbi, &$request, $pages, $from, $to, $updatelinks = false, $createredirect = false)
 {
     $result = HTML::div();
     $ul = HTML::ul();
     $count = 0;
     $post_args = $request->getArg('admin_rename');
     $options = array('regex' => isset($post_args['regex']) ? $post_args['regex'] : null, 'icase' => isset($post_args['icase']) ? $post_args['icase'] : null);
     foreach ($pages as $name) {
         if ($newname = $this->renameHelper($name, $from, $to, $options) and $newname != $name) {
             if ($dbi->isWikiPage($newname)) {
                 $ul->pushContent(HTML::li(fmt("Page '%s' already exists. Ignored.", WikiLink($newname))));
             } elseif (!mayAccessPage('edit', $name)) {
                 $ul->pushContent(HTML::li(fmt("Access denied to rename page '%s'.", WikiLink($name))));
             } elseif ($dbi->renamePage($name, $newname, $updatelinks)) {
                 /* not yet implemented for all backends */
                 $page = $dbi->getPage($newname);
                 $current = $page->getCurrentRevision();
                 $version = $current->getVersion();
                 $meta = $current->_data;
                 $text = $current->getPackedContent();
                 $meta['summary'] = sprintf(_("Renamed page from '%s' to '%s'"), $name, $newname);
                 $meta['is_minor_edit'] = 1;
                 $meta['author'] = $request->_user->UserName();
                 unset($meta['mtime']);
                 // force new date
                 $page->save($text, $version + 1, $meta);
                 if ($createredirect) {
                     $page = $dbi->getPage($name);
                     $text = "<<RedirectTo page=\"" . $newname . "\">>";
                     $meta['summary'] = sprintf(_("Renaming created redirect page from '%s' to '%s'"), $name, $newname);
                     $meta['is_minor_edit'] = 0;
                     $meta['author'] = $request->_user->UserName();
                     $page->save($text, 1, $meta);
                 }
                 $ul->pushContent(HTML::li(fmt("Renamed page '%s' to '%s'.", $name, WikiLink($newname))));
                 $count++;
             } else {
                 $ul->pushContent(HTML::li(fmt("Couldn't rename page '%s' to '%s'.", $name, $newname)));
             }
         } else {
             $ul->pushContent(HTML::li(fmt("Couldn't rename page '%s' to '%s'.", $name, $newname)));
         }
     }
     if ($count) {
         $dbi->touch();
         $result->setAttr('class', 'feedback');
         if ($count == 1) {
             $result->pushContent(HTML::p("One page has been permanently renamed:"));
         } else {
             $result->pushContent(HTML::p(fmt("%s pages have been permanently renamed:", $count)));
         }
         $result->pushContent($ul);
         return $result;
     } else {
         $result->setAttr('class', 'error');
         $result->pushContent(HTML::p(fmt("No pages renamed.")));
         $result->pushContent($ul);
         return $result;
     }
 }
예제 #2
0
 function renamePages(&$dbi, &$request, $pages, $from, $to, $updatelinks = false)
 {
     $ul = HTML::ul();
     $count = 0;
     $post_args = $request->getArg('admin_rename');
     $options = array('regex' => @$post_args['regex'], 'icase' => @$post_args['icase']);
     foreach ($pages as $name) {
         if ($newname = $this->renameHelper($name, $from, $to, $options) and $newname != $name) {
             if ($dbi->isWikiPage($newname)) {
                 $ul->pushContent(HTML::li(fmt("Page %s already exists. Ignored.", WikiLink($newname))));
             } elseif (!mayAccessPage('change', $name)) {
                 $ul->pushContent(HTML::li(fmt("Access denied to change page '%s'.", WikiLink($name))));
             } elseif ($dbi->renamePage($name, $newname, $updatelinks)) {
                 /* not yet implemented for all backends */
                 $ul->pushContent(HTML::li(fmt("Renamed page '%s' to '%s'.", $name, WikiLink($newname))));
                 $count++;
             } else {
                 $ul->pushContent(HTML::li(fmt("Couldn't rename page '%s' to '%s'.", $name, $newname)));
             }
         } else {
             $ul->pushContent(HTML::li(fmt("Couldn't rename page '%s' to '%s'.", $name, $newname)));
         }
     }
     if ($count) {
         $dbi->touch();
         return HTML($ul, HTML::p(fmt("%s pages have been permanently renamed.", $count)));
     } else {
         return HTML($ul, HTML::p(fmt("No pages renamed.")));
     }
 }
예제 #3
0
 function chownPages(&$dbi, &$request, $pages, $newowner)
 {
     $ul = HTML::ul();
     $count = 0;
     foreach ($pages as $name) {
         $page = $dbi->getPage($name);
         if ($owner = $page->getOwner() and $newowner != $owner) {
             if (!mayAccessPage('change', $name)) {
                 $ul->pushContent(HTML::li(fmt("Access denied to change page '%s'.", WikiLink($name))));
             } else {
                 $page->set('owner', $newowner);
                 if ($page->get('owner') === $newowner) {
                     $ul->pushContent(HTML::li(fmt("Chown page '%s' to '%s'.", WikiLink($name), WikiLink($newowner))));
                     $count++;
                 } else {
                     $ul->pushContent(HTML::li(fmt("Couldn't chown page '%s' to '%s'.", WikiLink($name), $newowner)));
                 }
             }
         }
     }
     if ($count) {
         $dbi->touch();
         return HTML($ul, HTML::p(fmt("%s pages have been permanently changed.", $count)));
     } else {
         return HTML($ul, HTML::p(fmt("No pages changed.")));
     }
 }
예제 #4
0
 function removePages(&$request, $pages)
 {
     $result = HTML::div();
     $ul = HTML::ul();
     $dbi = $request->getDbh();
     $count = 0;
     foreach ($pages as $name) {
         $name = str_replace(array('%5B', '%5D'), array('[', ']'), $name);
         if (mayAccessPage('remove', $name)) {
             $dbi->deletePage($name);
             $ul->pushContent(HTML::li(fmt("Removed page '%s' successfully.", $name)));
             $count++;
         } else {
             $ul->pushContent(HTML::li(fmt("Didn't remove page '%s'. Access denied.", $name)));
         }
     }
     if ($count) {
         $dbi->touch();
         $result->setAttr('class', 'feedback');
         if ($count == 1) {
             $result->pushContent(HTML::p("One page has been permanently removed:"));
         } else {
             $result->pushContent(HTML::p(fmt("%s pages have been permanently removed:", $count)));
         }
         $result->pushContent($ul);
         return $result;
     } else {
         $result->setAttr('class', 'error');
         $result->pushContent(HTML::p("No pages removed."));
         return $result;
     }
 }
예제 #5
0
 function chmarkupPages(&$dbi, &$request, $pages, $newmarkup)
 {
     $result = HTML::div();
     $ul = HTML::ul();
     $count = 0;
     foreach ($pages as $name) {
         $page = $dbi->getPage($name);
         $current = $page->getCurrentRevision();
         $markup = $current->get('markup');
         if (!$markup or $newmarkup != $markup) {
             if (!mayAccessPage('change', $name)) {
                 $result->setAttr('class', 'error');
                 $result->pushContent(HTML::p(fmt("Access denied to change page '%s'.", WikiLink($name))));
             } else {
                 $version = $current->getVersion();
                 $meta = $current->_data;
                 $meta['markup'] = $newmarkup;
                 // convert text?
                 $text = $current->getPackedContent();
                 $meta['summary'] = sprintf(_("Change markup type from %s to %s"), $markup, $newmarkup);
                 $meta['is_minor_edit'] = 1;
                 $meta['author'] = $request->_user->UserName();
                 unset($meta['mtime']);
                 // force new date
                 $page->save($text, $version + 1, $meta);
                 $current = $page->getCurrentRevision();
                 if ($current->get('markup') === $newmarkup) {
                     $ul->pushContent(HTML::li(fmt("change page '%s' to markup type '%s'.", WikiLink($name), $newmarkup)));
                     $count++;
                 } else {
                     $ul->pushContent(HTML::li(fmt("Couldn't change page '%s' to markup type '%s'.", WikiLink($name), $newmarkup)));
                 }
             }
         }
     }
     if ($count) {
         $dbi->touch();
         $result->setAttr('class', 'feedback');
         if ($count == 1) {
             $result->pushContent(HTML::p("One page has been permanently changed:"));
         } else {
             $result->pushContent(HTML::p(fmt("%s pages have been permanently changed:", $count)));
         }
         $result->pushContent($ul);
         return $result;
     } else {
         $result->setAttr('class', 'error');
         $result->pushContent(HTML::p("No pages changed."));
         return $result;
     }
 }
예제 #6
0
 function chownPages(&$dbi, &$request, $pages, $newowner)
 {
     $result = HTML::div();
     $ul = HTML::ul();
     $count = 0;
     foreach ($pages as $name) {
         $page = $dbi->getPage($name);
         $current = $page->getCurrentRevision();
         if ($owner = $page->getOwner() and $newowner != $owner) {
             if (!mayAccessPage('change', $name)) {
                 $ul->pushContent(HTML::li(fmt("Access denied to change page '%s'.", WikiLink($name))));
             } else {
                 $version = $current->getVersion();
                 $meta = $current->_data;
                 $text = $current->getPackedContent();
                 $meta['summary'] = "Change page owner from '" . $owner . "' to '" . $newowner . "'";
                 $meta['is_minor_edit'] = 1;
                 $meta['author'] = $request->_user->UserName();
                 unset($meta['mtime']);
                 // force new date
                 $page->set('owner', $newowner);
                 $page->save($text, $version + 1, $meta);
                 if ($page->get('owner') === $newowner) {
                     $ul->pushContent(HTML::li(fmt("Change owner of page '%s' to '%s'.", WikiLink($name), WikiLink($newowner))));
                     $count++;
                 } else {
                     $ul->pushContent(HTML::li(fmt("Could not change owner of page '%s' to '%s'.", WikiLink($name), $newowner)));
                 }
             }
         }
     }
     if ($count) {
         $dbi->touch();
         $result->setAttr('class', 'feedback');
         if ($count == 1) {
             $result->pushContent(HTML::p("One page has been permanently changed:"));
         } else {
             $result->pushContent(HTML::p(fmt("%s pages have been permanently changed:", $count)));
         }
         $result->pushContent($ul);
         return $result;
     } else {
         $result->setAttr('class', 'error');
         $result->pushContent(HTML::p("No pages changed."));
         return $result;
     }
 }
예제 #7
0
 function setExternalPages(&$dbi, &$request, $pages)
 {
     $result = HTML::div();
     $ul = HTML::ul();
     $count = 0;
     foreach ($pages as $name) {
         $page = $dbi->getPage($name);
         $current = $page->getCurrentRevision();
         $external = $current->get('external');
         if (!$external) {
             $external = 0;
         }
         $external = (bool) $external;
         if (!$external) {
             if (!mayAccessPage('change', $name)) {
                 $result->setAttr('class', 'error');
                 $result->pushContent(HTML::p(fmt("Access denied to change page '%s'.", WikiLink($name))));
             } else {
                 $version = $current->getVersion();
                 $page->set('external', (bool) 1);
                 $ul->pushContent(HTML::li(fmt("change page '%s' to external.", WikiLink($name))));
                 $count++;
             }
         }
     }
     if ($count) {
         $dbi->touch();
         $result->setAttr('class', 'feedback');
         if ($count == 1) {
             $result->pushContent(HTML::p("One page has been permanently changed:"));
         } else {
             $result->pushContent(HTML::p(fmt("%s pages have been permanently changed:", $count)));
         }
         $result->pushContent($ul);
         return $result;
     } else {
         $result->setAttr('class', 'error');
         $result->pushContent(HTML::p("No pages changed."));
         return $result;
     }
 }
예제 #8
0
 function chmarkupPages(&$dbi, &$request, $pages, $newmarkup)
 {
     $ul = HTML::ul();
     $count = 0;
     foreach ($pages as $name) {
         $page = $dbi->getPage($name);
         $current = $page->getCurrentRevision();
         $markup = $current->get('markup');
         if (!$markup or $newmarkup != $markup) {
             if (!mayAccessPage('change', $name)) {
                 $ul->pushContent(HTML::li(fmt("Access denied to change page '%s'.", WikiLink($name))));
             } else {
                 $version = $current->getVersion();
                 $meta = $current->_data;
                 $meta['markup'] = $newmarkup;
                 // convert text?
                 $text = $current->getPackedContent();
                 $meta['summary'] = sprintf(_("WikiAdminMarkup from %s to %s"), $markup, $newmarkup);
                 $page->save($text, $version + 1, $meta);
                 $current = $page->getCurrentRevision();
                 if ($current->get('markup') === $newmarkup) {
                     $ul->pushContent(HTML::li(fmt("change page '%s' to markup type '%s'.", WikiLink($name), $newmarkup)));
                     $count++;
                 } else {
                     $ul->pushContent(HTML::li(fmt("Couldn't change page '%s' to markup type '%s'.", WikiLink($name), $newmarkup)));
                 }
             }
         }
     }
     if ($count) {
         $dbi->touch();
         return HTML($ul, HTML::p(fmt("%s pages have been permanently changed.", $count)));
     } else {
         return HTML($ul, HTML::p(fmt("No pages changed.")));
     }
 }
예제 #9
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     $args = $this->getArgs($argstr, $request);
     extract($args);
     if ($page) {
         // Expand relative page names.
         $page = new WikiPageName($page, $basepage);
         $page = $page->name;
     }
     if (!$page) {
         return $this->error(_("no page specified"));
     }
     // A page can include itself once (this is needed, e.g.,  when editing
     // TextFormattingRules).
     static $included_pages = array();
     if (in_array($page, $included_pages)) {
         return $this->error(sprintf(_("recursive inclusion of page %s ignored"), $page));
     }
     // Check if page exists
     if (!$dbi->isWikiPage($page)) {
         return $this->error(sprintf(_("Page '%s' does not exist"), $page));
     }
     // Check if user is allowed to get the Page.
     if (!mayAccessPage('view', $page)) {
         return $this->error(sprintf(_("Illegal inclusion of page %s: no read access"), $page));
     }
     $p = $dbi->getPage($page);
     if ($rev) {
         $r = $p->getRevision($rev);
         if (!$r) {
             return $this->error(sprintf(_("%s(%d): no such revision"), $page, $rev));
         }
     } else {
         $r = $p->getCurrentRevision();
     }
     $c = $r->getContent();
     // follow redirects
     if (preg_match('/<' . '\\?plugin\\s+RedirectTo\\s+page=(\\S+)\\s*\\?' . '>/', implode("\n", $c), $m) or preg_match('/<' . '\\?plugin\\s+RedirectTo\\s+page=(.*?)\\s*\\?' . '>/', implode("\n", $c), $m) or preg_match('/<<\\s*RedirectTo\\s+page=(\\S+)\\s*>>/', implode("\n", $c), $m) or preg_match('/<<\\s*RedirectTo\\s+page="(.*?)"\\s*>>/', implode("\n", $c), $m)) {
         // Strip quotes (simple or double) from page name if any
         if (string_starts_with($m[1], "'") or string_starts_with($m[1], "\"")) {
             $m[1] = substr($m[1], 1, -1);
         }
         // trap recursive redirects
         if (in_array($m[1], $included_pages)) {
             return $this->error(sprintf(_("recursive inclusion of page %s ignored"), $page . ' => ' . $m[1]));
         }
         $page = $m[1];
         $p = $dbi->getPage($page);
         $r = $p->getCurrentRevision();
         $c = $r->getContent();
         // array of lines
     }
     $ct = $this->extractParts($c, $page, $args);
     // exclude from expansion
     if (preg_match('/<noinclude>.+<\\/noinclude>/s', $ct)) {
         $ct = preg_replace("/<noinclude>.+?<\\/noinclude>/s", "", $ct);
     }
     // only in expansion
     $ct = preg_replace("/<includeonly>(.+)<\\/includeonly>/s", "\\1", $ct);
     array_push($included_pages, $page);
     include_once 'lib/BlockParser.php';
     $content = TransformText($ct, $r->get('markup'), $page);
     array_pop($included_pages);
     if ($quiet) {
         return $content;
     }
     return HTML(HTML::p(array('class' => 'transclusion-title'), fmt("Included from %s", WikiLink($page))), HTML::div(array('class' => 'transclusion'), false, $content));
 }
예제 #10
0
 function setaclPages(&$request, $pages, $acl)
 {
     $result = HTML::div();
     $count = 0;
     $dbi =& $request->_dbi;
     // check new_group and new_perm
     if (isset($acl['_add_group'])) {
         //add groups with perm
         foreach ($acl['_add_group'] as $access => $dummy) {
             $group = $acl['_new_group'][$access];
             $acl[$access][$group] = isset($acl['_new_perm'][$access]) ? 1 : 0;
         }
         unset($acl['_add_group']);
     }
     unset($acl['_new_group']);
     unset($acl['_new_perm']);
     if (isset($acl['_del_group'])) {
         //del groups with perm
         foreach ($acl['_del_group'] as $access => $del) {
             while (list($group, $dummy) = each($del)) {
                 unset($acl[$access][$group]);
             }
         }
         unset($acl['_del_group']);
     }
     if ($perm = new PagePermission($acl)) {
         $perm->sanify();
         foreach ($pages as $pagename) {
             // check if unchanged? we need a deep array_equal
             $page = $dbi->getPage($pagename);
             $oldperm = getPagePermissions($page);
             if ($oldperm) {
                 $oldperm->sanify();
             }
             if ($oldperm and $perm->equal($oldperm->perm)) {
                 $result->setAttr('class', 'error');
                 $result->pushContent(HTML::p(fmt("ACL not changed for page '%s'.", $pagename)));
             } elseif (mayAccessPage('change', $pagename)) {
                 setPagePermissions($page, $perm);
                 $result->setAttr('class', 'feedback');
                 $result->pushContent(HTML::p(fmt("ACL changed for page '%s'", $pagename)));
                 $result->pushContent(HTML::p(fmt("from '%s'", $oldperm ? $oldperm->asAclLines() : "None")));
                 $result->pushContent(HTML::p(fmt("to '%s'.", $perm->asAclLines())));
                 // Create new revision so that ACL change appears in history.
                 $current = $page->getCurrentRevision();
                 $version = $current->getVersion();
                 $meta = $current->_data;
                 $text = $current->getPackedContent();
                 $meta['summary'] = sprintf(_("ACL changed for page '%s' from '%s' to '%s'."), $pagename, $oldperm ? $oldperm->asAclLines() : "None", $perm->asAclLines());
                 $meta['is_minor_edit'] = 1;
                 $meta['author'] = $request->_user->UserName();
                 unset($meta['mtime']);
                 // force new date
                 $page->save($text, $version + 1, $meta);
                 $count++;
             } else {
                 $result->setAttr('class', 'error');
                 $result->pushContent(HTML::p(fmt("Access denied to change page '%s'.", $pagename)));
             }
         }
     } else {
         $result->pushContent(HTML::p(fmt("Invalid ACL")));
     }
     if ($count) {
         $dbi->touch();
         $result->setAttr('class', 'feedback');
         if ($count > 1) {
             $result->pushContent(HTML::p(fmt("%s pages have been changed.", $count)));
         }
     } else {
         $result->setAttr('class', 'error');
         $result->pushContent(HTML::p(fmt("No pages changed.")));
     }
     return $result;
 }
예제 #11
0
 function linkUnknownWikiWord($wikiword, $linktext = '')
 {
     global $request;
     // Get rid of anchors on unknown wikiwords
     if (isa($wikiword, 'WikiPageName')) {
         $default_text = $wikiword->shortName;
         $wikiword = $wikiword->name;
     } else {
         $default_text = $wikiword;
     }
     if ($this->DUMP_MODE) {
         // HTML, PDF or XML
         $link = HTML::u(empty($linktext) ? $wikiword : $linktext);
         $link->addTooltip(sprintf(_("Empty link to: %s"), $wikiword));
         $link->setAttr('class', empty($linktext) ? 'wikiunknown' : 'named-wikiunknown');
         return $link;
     } else {
         // if AnonEditUnknownLinks show "?" only users which are allowed to edit this page
         if (!$this->_anonEditUnknownLinks and (!$request->_user->isSignedIn() or !mayAccessPage('edit', $request->getArg('pagename')))) {
             $text = HTML::span(empty($linktext) ? $wikiword : $linktext);
             $text->setAttr('class', empty($linktext) ? 'wikiunknown' : 'named-wikiunknown');
             return $text;
         } else {
             $url = WikiURL($wikiword, array('action' => 'create'));
             $button = $this->makeButton('?', $url);
             $button->addTooltip(sprintf(_("Create: %s"), $wikiword));
         }
     }
     $link = HTML::span();
     if (!empty($linktext)) {
         $link->pushContent(HTML::u($linktext));
         $link->setAttr('class', 'named-wikiunknown');
     } else {
         $link->pushContent(HTML::u($this->maybeSplitWikiWord($default_text)));
         $link->setAttr('class', 'wikiunknown');
     }
     if (!isa($button, "ImageButton")) {
         $button->setAttr('rel', 'nofollow');
     }
     $link->pushContent($button);
     if ($request->getPref('googleLink')) {
         $gbutton = $this->makeButton('G', "http://www.google.com/search?q=" . urlencode($wikiword));
         $gbutton->addTooltip(sprintf(_("Google:%s"), $wikiword));
         $link->pushContent($gbutton);
     }
     if ($request->getArg('frame')) {
         $link->setAttr('target', '_top');
     }
     return $link;
 }
예제 #12
0
파일: SOAP.php 프로젝트: hugcoday/wiki
function getCurrentRevision($pagename, $credentials = false)
{
    global $server;
    checkCredentials($server, $credentials, 'view', $pagename);
    if (!mayAccessPage('view', $pagename)) {
        $server->fault(401, '', "no permission");
    }
    $dbi = WikiDB::open($GLOBALS['DBParams']);
    $page = $dbi->getPage($pagename);
    $rev = $page->getCurrentRevision();
    $version = $current->getVersion();
    return (double) $version;
}
예제 #13
0
 function setaclPages(&$request, $pages, $acl)
 {
     $ul = HTML::ul();
     $count = 0;
     $dbi =& $request->_dbi;
     // check new_group and new_perm
     if (isset($acl['_add_group'])) {
         //add groups with perm
         foreach ($acl['_add_group'] as $access => $dummy) {
             $group = $acl['_new_group'][$access];
             $acl[$access][$group] = isset($acl['_new_perm'][$access]) ? 1 : 0;
         }
         unset($acl['_add_group']);
     }
     unset($acl['_new_group']);
     unset($acl['_new_perm']);
     if (isset($acl['_del_group'])) {
         //del groups with perm
         foreach ($acl['_del_group'] as $access => $del) {
             while (list($group, $dummy) = each($del)) {
                 unset($acl[$access][$group]);
             }
         }
         unset($acl['_del_group']);
     }
     if ($perm = new PagePermission($acl)) {
         $perm->sanify();
         foreach ($pages as $pagename) {
             // check if unchanged? we need a deep array_equal
             $page = $dbi->getPage($pagename);
             $oldperm = getPagePermissions($page);
             if ($oldperm) {
                 $oldperm->sanify();
             }
             if ($oldperm and $perm->equal($oldperm->perm)) {
                 // (serialize($oldperm->perm) == serialize($perm->perm))
                 $ul->pushContent(HTML::li(fmt("ACL not changed for page '%s'.", $pagename)));
             } elseif (mayAccessPage('change', $pagename)) {
                 setPagePermissions($page, $perm);
                 $ul->pushContent(HTML::li(fmt("ACL changed for page '%s'.", $pagename)));
                 $count++;
             } else {
                 $ul->pushContent(HTML::li(fmt("Access denied to change page '%s'.", $pagename)));
             }
         }
     } else {
         $ul->pushContent(HTML::li(fmt("Invalid ACL")));
     }
     if ($count) {
         $dbi->touch();
         return HTML($ul, HTML::p(fmt("%s pages have been changed.", $count)));
     } else {
         return HTML($ul, HTML::p(fmt("No pages changed.")));
     }
 }
예제 #14
0
 function searchReplacePages(&$dbi, &$request, $pages, $from, $to)
 {
     if (empty($from)) {
         return HTML::p(HTML::strong(fmt("Error: Empty search string.")));
     }
     $ul = HTML::ul();
     $count = 0;
     $post_args = $request->getArg('admin_replace');
     $case_exact = !empty($post_args['case_exact']);
     $regex = !empty($post_args['regex']);
     foreach ($pages as $pagename) {
         if (!mayAccessPage('edit', $pagename)) {
             $ul->pushContent(HTML::li(fmt("Access denied to change page '%s'.", $pagename)));
         } elseif ($result = $this->replaceHelper($dbi, $pagename, $from, $to, $case_exact, $regex)) {
             $ul->pushContent(HTML::li(fmt("Replaced '%s' with '%s' in page '%s'.", $from, $to, WikiLink($pagename))));
             $count++;
         } else {
             $ul->pushContent(HTML::li(fmt("Search string '%s' not found in content of page '%s'.", $from, WikiLink($pagename))));
         }
     }
     if ($count) {
         $dbi->touch();
         return HTML($ul, HTML::p(fmt("%s pages changed.", $count)));
     } else {
         return HTML($ul, HTML::p(fmt("No pages changed.")));
     }
 }
예제 #15
0
 function format()
 {
     header("Content-type: application/rdf+xml; charset=UTF-8");
     echo $this->pre_ns_buffer;
     echo ">\n";
     $first = true;
     $dbi = $this->_request->_dbi;
     /* Elements per page:
     	   out-links internal, out-links external
     	   backlinks
     	   relations
     	   attributes
     	*/
     foreach ($this->_pagelist->_pages as $page) {
         $relation = new TextSearchQuery("*");
         foreach (array('linkto', 'linkfrom', 'relation', 'attribute') as $linktype) {
             $linkiter = $dbi->linkSearch($pages, $search, $linktype, $relation);
         }
         while ($link = $linkiter->next()) {
             if (mayAccessPage('view', $rev->_pagename)) {
                 $linkto->addItem($this->item_properties($rev), $this->pageURI($rev));
                 if ($first) {
                     $this->setValidators($rev);
                 }
                 $first = false;
             }
         }
     }
     echo $this->post_ns_buffer;
     echo "</rdf:RDF>\n";
 }
예제 #16
0
 function format($changes)
 {
     global $request;
     include_once 'lib/RssWriter.php';
     $rss = new AtomFeed();
     // "channel" is called "feed" in atom
     $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
     extract($this->_args);
     $title = WIKI_NAME;
     $description = $this->title();
     if ($category) {
         $title = $category;
     } elseif ($pagematch) {
         $title = $pagematch;
     }
     $feed_props = array('title' => $description, 'link' => array('rel' => "alternate", 'type' => "text/html", 'href' => $rc_url), 'id' => md5($rc_url), 'modified' => Iso8601DateTime(time()), 'generator' => 'PhpWiki-' . PHPWIKI_VERSION, 'tagline' => '');
     $rss->feed($feed_props);
     $first = true;
     while ($rev = $changes->next()) {
         // enforce view permission
         if (mayAccessPage('view', $rev->_pagename)) {
             $props = $this->item_properties($rev);
             $rss->addItem($props, false, $this->pageURI($rev));
             if ($first) {
                 $this->setValidators($rev);
             }
             $first = false;
         }
     }
     $request->discardOutput();
     $rss->finish();
     //header("Content-Type: application/atom; charset=" . $GLOBALS['charset']);
     printf("\n<!-- Generated by PhpWiki-%s -->\n", PHPWIKI_VERSION);
     // Flush errors in comment, otherwise it's invalid XML.
     global $ErrorManager;
     if ($errors = $ErrorManager->getPostponedErrorsAsHTML()) {
         printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
     }
     $request->finish();
     // NORETURN!!!!
 }
예제 #17
0
파일: Diff.php 프로젝트: hugcoday/wiki
 function run($dbi, $argstr, &$request, $basepage)
 {
     extract($this->getArgs($argstr, $request));
     if (is_array($versions)) {
         // Version selection from pageinfo.php display:
         rsort($versions);
         list($version, $previous) = $versions;
     }
     // Check if user is allowed to get the Page.
     if (!mayAccessPage('view', $pagename)) {
         return $this->error(sprintf(_("Illegal access to page %s: no read access"), $pagename));
     }
     // abort if page doesn't exist
     $page = $request->getPage($pagename);
     $current = $page->getCurrentRevision();
     if ($current->getVersion() < 1) {
         $html = HTML(HTML::p(fmt("I'm sorry, there is no such page as %s.", WikiLink($pagename, 'unknown'))));
         return $html;
         //early return
     }
     if ($version) {
         if (!($new = $page->getRevision($version))) {
             NoSuchRevision($request, $page, $version);
         }
         $new_version = fmt("version %d", $version);
     } else {
         $new = $current;
         $new_version = _("current version");
     }
     if (preg_match('/^\\d+$/', $previous)) {
         if (!($old = $page->getRevision($previous))) {
             NoSuchRevision($request, $page, $previous);
         }
         $old_version = fmt("version %d", $previous);
         $others = array('major', 'minor', 'author');
     } else {
         switch ($previous) {
             case 'author':
                 $old = $new;
                 while ($old = $page->getRevisionBefore($old)) {
                     if ($old->get('author') != $new->get('author')) {
                         break;
                     }
                 }
                 $old_version = _("revision by previous author");
                 $others = array('major', 'minor');
                 break;
             case 'minor':
                 $previous = 'minor';
                 $old = $page->getRevisionBefore($new);
                 $old_version = _("previous revision");
                 $others = array('major', 'author');
                 break;
             case 'major':
             default:
                 $old = $new;
                 while ($old && $old->get('is_minor_edit')) {
                     $old = $page->getRevisionBefore($old);
                 }
                 if ($old) {
                     $old = $page->getRevisionBefore($old);
                 }
                 $old_version = _("predecessor to the previous major change");
                 $others = array('minor', 'author');
                 break;
         }
     }
     $new_link = WikiLink($new, '', $new_version);
     $old_link = $old ? WikiLink($old, '', $old_version) : $old_version;
     $page_link = WikiLink($page);
     $html = HTML(HTML::p(fmt("Differences between %s and %s of %s.", $new_link, $old_link, $page_link)));
     $otherdiffs = HTML::p(_("Other diffs:"));
     $label = array('major' => _("Previous Major Revision"), 'minor' => _("Previous Revision"), 'author' => _("Previous Author"));
     foreach ($others as $other) {
         $args = array('pagename' => $pagename, 'previous' => $other);
         if ($version) {
             $args['version'] = $version;
         }
         if (count($otherdiffs->getContent()) > 1) {
             $otherdiffs->pushContent(", ");
         } else {
             $otherdiffs->pushContent(" ");
         }
         $otherdiffs->pushContent(Button($args, $label[$other]));
     }
     $html->pushContent($otherdiffs);
     if ($old and $old->getVersion() == 0) {
         $old = false;
     }
     $html->pushContent(HTML::Table($this->PageInfoRow(_("Newer page:"), $new, $request), $this->PageInfoRow(_("Older page:"), $old, $request)));
     if ($new && $old) {
         $diff = new Diff($old->getContent(), $new->getContent());
         if ($diff->isEmpty()) {
             $html->pushContent(HTML::hr(), HTML::p(_("Content of versions "), $old->getVersion(), _(" and "), $new->getVersion(), _(" is identical.")));
             // If two consecutive versions have the same content, it is because the page was
             // renamed, or metadata changed: ACL, owner, markup.
             // We give the reason by printing the summary.
             if ($new->getVersion() - $old->getVersion() == 1) {
                 $html->pushContent(HTML::p(_("Version "), $new->getVersion(), _(" was created because: "), $new->get('summary')));
             }
         } else {
             $fmt = new HtmlUnifiedDiffFormatter();
             $html->pushContent($fmt->format($diff));
         }
     }
     return $html;
 }
예제 #18
0
 /**
  * Take a PageList_Page object, and return an HTML object to display
  * it in a table or list row.
  */
 function _renderPageRow(&$page_handle, $i = 0)
 {
     $page_handle = $this->_getPageFromHandle($page_handle);
     //FIXME. only on sf.net
     if (!is_object($page_handle)) {
         trigger_error("PageList: Invalid page_handle {$page_handle}", E_USER_WARNING);
         return;
     }
     if (!isset($page_handle) or empty($page_handle) or !empty($this->_excluded_pages) and in_array($page_handle->getName(), $this->_excluded_pages)) {
         return;
     }
     // exclude page.
     // enforce view permission
     if (!mayAccessPage('view', $page_handle->getName())) {
         return;
     }
     $group = (int) ($i / $this->_group_rows);
     $class = $group % 2 ? 'oddrow' : 'evenrow';
     $revision_handle = false;
     $this->_maxlen = max($this->_maxlen, strlen($page_handle->getName()));
     if (count($this->_columns) > 1) {
         $row = HTML::tr(array('class' => $class));
         foreach ($this->_columns as $col) {
             $row->pushContent($col->format($this, $page_handle, $revision_handle));
         }
     } else {
         $col = $this->_columns[0];
         $row = $col->_getValue($page_handle, $revision_handle);
     }
     return $row;
 }
예제 #19
0
 function searchReplacePages(&$dbi, &$request, $pages, $from, $to)
 {
     if (empty($from)) {
         return HTML::p(HTML::strong(fmt("Error: Empty search string.")));
     }
     $result = HTML::div();
     $ul = HTML::ul();
     $count = 0;
     $post_args = $request->getArg('admin_replace');
     $case_exact = !empty($post_args['case_exact']);
     $regex = !empty($post_args['regex']);
     foreach ($pages as $pagename) {
         if (!mayAccessPage('edit', $pagename)) {
             $ul->pushContent(HTML::li(fmt("Access denied to change page '%s'.", $pagename)));
         } elseif ($this->replaceHelper($dbi, $request, $pagename, $from, $to, $case_exact, $regex)) {
             $ul->pushContent(HTML::li(fmt("Replaced '%s' with '%s' in page '%s'.", $from, $to, WikiLink($pagename))));
             $count++;
         }
     }
     if ($count) {
         $dbi->touch();
         $result->setAttr('class', 'feedback');
         if ($count == 1) {
             $result->pushContent(HTML::p("One page has been permanently changed:"));
         } else {
             $result->pushContent(HTML::p(fmt("%s pages have been permanently changed:", $count)));
         }
         $result->pushContent($ul);
     } else {
         $result->setAttr('class', 'error');
         $result->pushContent(HTML::p("No pages changed."));
     }
     return $result;
 }
예제 #20
0
파일: CreateToc.php 프로젝트: hugcoday/wiki
 function run($dbi, $argstr, &$request, $basepage)
 {
     global $WikiTheme;
     extract($this->getArgs($argstr, $request));
     if ($pagename) {
         // Expand relative page names.
         $page = new WikiPageName($pagename, $basepage);
         $pagename = $page->name;
     }
     if (!$pagename) {
         return $this->error(_("no page specified"));
     }
     if (isBrowserIE() and browserDetect("Mac")) {
         $jshide = 0;
     }
     if ($notoc or $liststyle == 'ol') {
         $with_counter = 1;
     }
     // Check if user is allowed to get the Page.
     if (!mayAccessPage('view', $pagename)) {
         return $this->error(sprintf(_("Illegal access to page %s: no read access"), $pagename));
     }
     $page = $dbi->getPage($pagename);
     $current = $page->getCurrentRevision();
     //FIXME: I suspect this only to crash with Apache2
     if (!$current->get('markup') or $current->get('markup') < 2) {
         if (in_array(php_sapi_name(), array('apache2handler', 'apache2filter'))) {
             trigger_error(_("CreateToc disabled for old markup"), E_USER_WARNING);
             return '';
         }
     }
     $content = $current->getContent();
     $html = HTML::div(array('class' => 'toc', 'id' => GenerateId("toc")));
     if ($notoc) {
         $html->setAttr('style', 'display:none;');
     }
     if ($position == "left" or $position == "right") {
         $html->setAttr('style', 'float:' . $position . '; width:' . $width . ';');
     }
     $toclistid = GenerateId("toclist");
     $list = HTML::div(array('id' => $toclistid, 'class' => 'toclist'));
     if (!strstr($headers, ",")) {
         $headers = array($headers);
     } else {
         $headers = explode(",", $headers);
     }
     $levels = array();
     foreach ($headers as $h) {
         //replace !!! with level 1, ...
         if (strstr($h, "!")) {
             $hcount = substr_count($h, '!');
             $level = min(max(1, $hcount), 3);
             $levels[] = $level;
         } else {
             $level = min(max(1, (int) $h), 5);
             $levels[] = $level;
         }
     }
     if (TOC_FULL_SYNTAX) {
         require_once "lib/InlineParser.php";
     }
     if ($headers = $this->extractHeaders($content, $dbi->_markup, $with_toclink, $with_counter, $levels, $firstlevelstyle, $basepage)) {
         foreach ($headers as $h) {
             // proper heading indent
             $level = $h['level'];
             $indent = $level - 1;
             $link = new WikiPageName($pagename, $page, $h['anchor']);
             $li = WikiLink($link, 'known', $h['text']);
             // Hack to suppress pagename before #
             // $li->_attr["href"] = strstr($li->_attr["href"], '#');
             $list->pushContent(HTML::p(HTML::raw(str_repeat($indentstr, $indent)), $li));
         }
     }
     $list->setAttr('style', 'display:' . ($jshide ? 'none;' : 'block;'));
     $open = DATA_PATH . '/' . $WikiTheme->_findFile("images/folderArrowOpen.png");
     $close = DATA_PATH . '/' . $WikiTheme->_findFile("images/folderArrowClosed.png");
     if ($noheader) {
     } else {
         $toctoggleid = GenerateId("toctoggle");
         if ($extracollapse) {
             $toclink = HTML(_("Table of Contents"), " ", HTML::a(array('id' => 'TOC')), HTML::img(array('id' => $toctoggleid, 'class' => 'wikiaction', 'title' => _("Click to display to TOC"), 'onclick' => "toggletoc(this, '" . $open . "', '" . $close . "', '" . $toclistid . "')", 'alt' => 'toctoggle', 'src' => $jshide ? $close : $open)));
         } else {
             $toclink = HTML::a(array('id' => 'TOC', 'class' => 'wikiaction', 'title' => _("Click to display"), 'onclick' => "toggletoc(this, '" . $open . "', '" . $close . "', '" . $toclistid . "')"), _("Table of Contents"), HTML::span(array('style' => 'display:none', 'id' => $toctoggleid), " "));
         }
         $html->pushContent(HTML::p(array('class' => 'toctitle'), $toclink));
     }
     $html->pushContent($list);
     if (count($headers) == 0) {
         // Do not display an empty TOC
         $html->setAttr('style', 'display:none;');
     }
     return $html;
 }
예제 #21
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     static $included_pages = false;
     if (!$included_pages) {
         $included_pages = array($basepage);
     }
     $args = $this->getArgs($argstr, $request);
     extract($args);
     $query = new TextSearchQuery($pagename . SUBPAGE_SEPARATOR . '*', true, 'glob');
     $subpages = $dbi->titleSearch($query, $sortby, $limit, $exclude);
     //if ($sortby)
     //    $subpages = $subpages->applyFilters(array('sortby' => $sortby, 'limit' => $limit, 'exclude' => $exclude));
     //$subpages = explodePageList($pagename . SUBPAGE_SEPARATOR . '*', false,
     //                            $sortby, $limit, $exclude);
     if (is_string($exclude) and !is_array($exclude)) {
         $exclude = PageList::explodePageList($exclude, false, false, $limit);
     }
     $content = HTML();
     include_once 'lib/BlockParser.php';
     $i = 0;
     while ($page = $subpages->next()) {
         $cpagename = $page->getName();
         if ($maxpages and $i++ > $maxpages) {
             return $content;
         }
         if (in_array($cpagename, $exclude)) {
             continue;
         }
         // A page cannot include itself. Avoid doublettes.
         if (in_array($cpagename, $included_pages)) {
             $content->pushContent(HTML::p(sprintf(_("recursive inclusion of page %s ignored"), $cpagename)));
             continue;
         }
         // Check if user is allowed to get the Page.
         if (!mayAccessPage('view', $cpagename)) {
             return $this->error(sprintf(_("Illegal inclusion of page %s: no read access"), $cpagename));
         }
         // trap any remaining nonexistant subpages
         if ($page->exists()) {
             $r = $page->getCurrentRevision();
             $c = $r->getContent();
             // array of lines
             // follow redirects
             if (preg_match('/<' . '\\?plugin\\s+RedirectTo\\s+page=(\\S+)\\s*\\?' . '>/', implode("\n", $c), $m) or preg_match('/<' . '\\?plugin\\s+RedirectTo\\s+page=(.*?)\\s*\\?' . '>/', implode("\n", $c), $m) or preg_match('/<<\\s*RedirectTo\\s+page=(\\S+)\\s*>>/', implode("\n", $c), $m) or preg_match('/<<\\s*RedirectTo\\s+page="(.*?)"\\s*>>/', implode("\n", $c), $m)) {
                 // Strip quotes (simple or double) from page name if any
                 if (string_starts_with($m[1], "'") or string_starts_with($m[1], "\"")) {
                     $m[1] = substr($m[1], 1, -1);
                 }
                 // trap recursive redirects
                 if (in_array($m[1], $included_pages)) {
                     if (!$quiet) {
                         $content->pushContent(HTML::p(sprintf(_("recursive inclusion of page %s ignored"), $cpagename . ' => ' . $m[1])));
                     }
                     continue;
                 }
                 $cpagename = $m[1];
                 // Check if user is allowed to get the Page.
                 if (!mayAccessPage('view', $cpagename)) {
                     return $this->error(sprintf(_("Illegal inclusion of page %s: no read access"), $cpagename));
                 }
                 $page = $dbi->getPage($cpagename);
                 $r = $page->getCurrentRevision();
                 $c = $r->getContent();
                 // array of lines
             }
             // moved to IncludePage
             $ct = $this->extractParts($c, $cpagename, $args);
             array_push($included_pages, $cpagename);
             if ($smalltitle) {
                 $pname = array_pop(explode(SUBPAGE_SEPARATOR, $cpagename));
                 // get last subpage name
                 // Use _("%s: %s") instead of .": ". for French punctuation
                 $ct = TransformText(sprintf(_("%s: %s"), "[{$pname}|{$cpagename}]", $ct), $r->get('markup'), $cpagename);
             } else {
                 $ct = TransformText($ct, $r->get('markup'), $cpagename);
             }
             array_pop($included_pages);
             if (!$smalltitle) {
                 $content->pushContent(HTML::p(array('class' => $quiet ? '' : 'transclusion-title'), fmt("Included from %s:", WikiLink($cpagename))));
             }
             $content->pushContent(HTML(HTML::div(array('class' => $quiet ? '' : 'transclusion'), false, $ct)));
         }
     }
     if (!isset($cpagename)) {
         return $this->error(sprintf(_("%s has no subpages defined."), $pagename));
     }
     return $content;
 }
예제 #22
0
function putPage($params)
{
    global $request;
    $ParamPageName = $params->getParam(0);
    $ParamContent = $params->getParam(1);
    $pagename = short_string_decode($ParamPageName->scalarval());
    $content = short_string_decode($ParamContent->scalarval());
    $passwd = '';
    if (count($params->params) > 2) {
        $ParamAuthor = $params->getParam(2);
        $userid = short_string_decode($ParamAuthor->scalarval());
        if (count($params->params) > 3) {
            $ParamPassword = $params->getParam(3);
            $passwd = short_string_decode($ParamPassword->scalarval());
        }
    } else {
        $userid = $request->_user->_userid;
    }
    $request->_user = _getUser($userid);
    $request->_user->_group = $request->getGroup();
    $request->_user->AuthCheck($userid, $passwd);
    if (!mayAccessPage('edit', $pagename)) {
        return new xmlrpcresp(new xmlrpcval(array('code' => new xmlrpcval(401, "int"), 'version' => new xmlrpcval(0, "int"), 'message' => short_string("no permission for " . $request->_user->UserName())), "struct"));
    }
    $now = time();
    $dbh = $request->getDbh();
    $page = $dbh->getPage($pagename);
    $current = $page->getCurrentRevision();
    $content = trim($content);
    $version = $current->getVersion();
    // $version = -1 will force create a new version
    if ($current->getPackedContent() != $content) {
        $init_meta = array('ctime' => $now, 'creator' => $userid, 'creator_id' => $userid);
        $version_meta = array('author' => $userid, 'author_id' => $userid, 'markup' => 2.0, 'summary' => isset($summary) ? $summary : _("xml-rpc change"), 'mtime' => $now, 'pagetype' => 'wikitext', 'wikitext' => $init_meta);
        $version++;
        $res = $page->save($content, $version, $version_meta);
        if ($res) {
            $message = "Page {$pagename} version {$version} created";
        } else {
            $message = "Problem creating version {$version} of page {$pagename}";
        }
    } else {
        $res = 0;
        $message = $message = "Page {$pagename} unchanged";
    }
    return new xmlrpcresp(new xmlrpcval(array('code' => new xmlrpcval($res ? 200 : 400, "int"), 'version' => new xmlrpcval($version, "int"), 'message' => short_string($message)), "struct"));
}
예제 #23
0
 function format($changes)
 {
     include_once 'lib/RssWriter2.php';
     $rss = new RssWriter2();
     $rss->channel($this->channel_properties());
     if ($props = $this->cloud_properties()) {
         $rss->cloud($props);
     }
     if ($props = $this->image_properties()) {
         $rss->image($props);
     }
     if ($props = $this->textinput_properties()) {
         $rss->textinput($props);
     }
     $first = true;
     while ($rev = $changes->next()) {
         // enforce view permission
         if (mayAccessPage('view', $rev->_pagename)) {
             $rss->addItem($this->item_properties($rev), $this->pageURI($rev));
             if ($first) {
                 $this->setValidators($rev);
             }
             $first = false;
         }
     }
     global $request;
     $request->discardOutput();
     $rss->finish();
     printf("\n<!-- Generated by PhpWiki-%s:\n%s-->\n", PHPWIKI_VERSION, $GLOBALS['RCS_IDS']);
     // Flush errors in comment, otherwise it's invalid XML.
     global $ErrorManager;
     if ($errors = $ErrorManager->getPostponedErrorsAsHTML()) {
         printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
     }
     $request->finish();
     // NORETURN!!!!
 }
예제 #24
0
 function revertPages(&$request, $pages)
 {
     $ul = HTML::ul();
     $dbi = $request->getDbh();
     $count = 0;
     foreach ($pages as $name) {
         $name = str_replace(array('%5B', '%5D'), array('[', ']'), $name);
         if (mayAccessPage('remove', $name)) {
             $version = $dbi->revertPage($name);
             $ul->pushContent(HTML::li(fmt("Reverted page '%s' to version '%s'.", $name, $version)));
             $count++;
         } else {
             $ul->pushContent(HTML::li(fmt("Didn't revert page '%s'. Access denied.", $name)));
         }
     }
     if ($count) {
         $dbi->touch();
     }
     return HTML($ul, HTML::p(fmt("%d pages have been reverted.", $count)));
 }
예제 #25
0
파일: PageDump.php 프로젝트: hugcoday/wiki
 function run($dbi, $argstr, &$request, $basepage)
 {
     extract($this->getArgs($argstr, $request));
     // allow plugin-form
     if (!empty($s)) {
         $page = $s;
     }
     if (!$page) {
         return '';
     }
     if (!$dbi->isWikiPage($page)) {
         return fmt("Page %s not found.", WikiLink($page, 'unknown'));
     }
     // Check if user is allowed to get the Page.
     if (!mayAccessPage('view', $page)) {
         return $this->error(sprintf(_("Illegal access to page %s: no read access"), $page));
     }
     $p = $dbi->getPage($page);
     include_once "lib/loadsave.php";
     $mailified = MailifyPage($p, $format == 'backup' ? 99 : 1);
     // fixup_headers massages the page dump headers depending on
     // the 'format' argument, 'normal'(default) or 'forcvs'.
     //
     // Normal: Don't add X-Rcs-Id, add unique Message-Id, don't
     // strip any fields from Content-Type.
     //
     // ForCVS: Add empty X-Rcs-Id, strip attributes from
     // Content-Type field: "author", "version", "lastmodified",
     // "author_id", "hits".
     $this->pagename = $page;
     $this->generateMessageId($mailified);
     if ($format == 'forcvs') {
         $this->fixup_headers_forcvs($mailified);
     } else {
         // backup or normal
         $this->fixup_headers($mailified);
     }
     if ($download) {
         // TODO: we need a way to hook into the generated headers, to override
         // Content-Type, Set-Cookie, Cache-control, ...
         $request->discardOutput();
         // Hijack the http request from PhpWiki.
         ob_end_clean();
         // clean up after hijacking $request
         //ob_end_flush(); //debugging
         $filename = FilenameForPage($page);
         Header("Content-disposition: attachment; filename=\"" . $filename . "\"");
         // Read charset from generated page itself.
         // Inconsequential at the moment, since loadsave.php
         // always generates headers.
         $charset = $p->get('charset');
         if (!$charset) {
             $charset = $GLOBALS['charset'];
         }
         // We generate 3 Content-Type headers! first in loadsave,
         // then here and the mimified string $mailified also has it!
         // This one is correct and overwrites the others.
         Header("Content-Type: application/octet-stream; name=\"" . $filename . "\"; charset=\"" . $charset . "\"");
         $request->checkValidators();
         // let $request provide last modified & etag
         Header("Content-Id: <" . $this->MessageId . ">");
         // be nice to http keepalive~s
         Header("Content-Length: " . strlen($mailified));
         // Here comes our prepared mime file
         echo $mailified;
         exit;
         // noreturn! php exits.
         return;
     }
     // We are displaing inline preview in a WikiPage, so wrap the
     // text if it is too long--unless quoted-printable (TODO).
     $mailified = wordwrap($mailified, 70);
     $dlcvs = Button(array('action' => $this->getName(), 'format' => 'forcvs', 'download' => true), _("Download for CVS"), $page);
     $dl = Button(array('action' => $this->getName(), 'download' => true), _("Download for backup"), $page);
     $dlall = Button(array('action' => $this->getName(), 'format' => 'backup', 'download' => true), _("Download all revisions for backup"), $page);
     $h2 = HTML::h2(fmt("Preview: Page dump of %s", WikiLink($page, 'auto')));
     global $WikiTheme;
     if (!($Sep = $WikiTheme->getButtonSeparator())) {
         $Sep = " ";
     }
     if ($format == 'forcvs') {
         $desc = _("(formatted for PhpWiki developers as pgsrc template, not for backing up)");
         $altpreviewbuttons = HTML(Button(array('action' => $this->getName()), _("Preview as normal format"), $page), $Sep, Button(array('action' => $this->getName(), 'format' => 'backup'), _("Preview as backup format"), $page));
     } elseif ($format == 'backup') {
         $desc = _("(formatted for backing up: all revisions)");
         // all revisions
         $altpreviewbuttons = HTML(Button(array('action' => $this->getName(), 'format' => 'forcvs'), _("Preview as developer format"), $page), $Sep, Button(array('action' => $this->getName(), 'format' => ''), _("Preview as normal format"), $page));
     } else {
         $desc = _("(normal formatting: latest revision only)");
         $altpreviewbuttons = HTML(Button(array('action' => $this->getName(), 'format' => 'forcvs'), _("Preview as developer format"), $page), $Sep, Button(array('action' => $this->getName(), 'format' => 'backup'), _("Preview as backup format"), $page));
     }
     $warning = HTML(_("Please use one of the downloadable versions rather than copying and pasting from the above preview.") . " " . _("The wordwrap of the preview doesn't take nested markup or list indentation into consideration!") . " ", HTML::em(_("PhpWiki developers should manually inspect the downloaded file for nested markup before rewrapping with emacs and checking into CVS.")));
     return HTML($h2, HTML::em($desc), HTML::pre($mailified), $altpreviewbuttons, HTML::div(array('class' => 'errors'), HTML::strong(_("Warning:")), " ", $warning), $dl, $Sep, $dlall, $Sep, $dlcvs);
 }
예제 #26
0
파일: Template.php 프로젝트: hugcoday/wiki
 function run($dbi, $argstr, &$request, $basepage)
 {
     $this->vars = array();
     $args = $this->getArgs($argstr, $request);
     $vars = $args['vars'] ? $args['vars'] : $this->vars;
     $page = $args['page'];
     if ($page) {
         // Expand relative page names.
         $page = new WikiPageName($page, $basepage);
         $page = $page->name;
     }
     if (!$page) {
         return $this->error(_("no page specified"));
     }
     // If "Template:$page" exists, use it
     // else if "Template/$page" exists, use it
     // else use "$page"
     if ($dbi->isWikiPage("Template:" . $page)) {
         $page = "Template:" . $page;
     } elseif ($dbi->isWikiPage("Template/" . $page)) {
         $page = "Template/" . $page;
     }
     // Protect from recursive inclusion. A page can include itself once
     static $included_pages = array();
     if (in_array($page, $included_pages)) {
         return $this->error(sprintf(_("recursive inclusion of page %s"), $page));
     }
     // Check if page exists
     if (!$dbi->isWikiPage($page)) {
         return $this->error(sprintf(_("Page '%s' does not exist"), $page));
     }
     // Check if user is allowed to get the Page.
     if (!mayAccessPage('view', $page)) {
         return $this->error(sprintf(_("Illegal inclusion of page %s: no read access"), $page));
     }
     $p = $dbi->getPage($page);
     if ($args['rev']) {
         $r = $p->getRevision($args['rev']);
         if (!$r) {
             return $this->error(sprintf(_("%s(%d): no such revision"), $page, $args['rev']));
         }
     } else {
         $r = $p->getCurrentRevision();
     }
     $initial_content = $r->getPackedContent();
     $content = $r->getContent();
     // follow redirects
     if (preg_match('/<' . '\\?plugin\\s+RedirectTo\\s+page=(\\S+)\\s*\\?' . '>/', implode("\n", $content), $m) or preg_match('/<' . '\\?plugin\\s+RedirectTo\\s+page=(.*?)\\s*\\?' . '>/', implode("\n", $content), $m) or preg_match('/<<\\s*RedirectTo\\s+page=(\\S+)\\s*>>/', implode("\n", $content), $m) or preg_match('/<<\\s*RedirectTo\\s+page="(.*?)"\\s*>>/', implode("\n", $content), $m)) {
         // Strip quotes (simple or double) from page name if any
         if (string_starts_with($m[1], "'") or string_starts_with($m[1], "\"")) {
             $m[1] = substr($m[1], 1, -1);
         }
         // trap recursive redirects
         if (in_array($m[1], $included_pages)) {
             return $this->error(sprintf(_("recursive inclusion of page %s ignored"), $page . ' => ' . $m[1]));
         }
         $page = $m[1];
         $p = $dbi->getPage($page);
         $r = $p->getCurrentRevision();
         $initial_content = $r->getPackedContent();
     }
     if ($args['section']) {
         $c = explode("\n", $initial_content);
         $c = extractSection($args['section'], $c, $page, $quiet, $args['sectionhead']);
         $initial_content = implode("\n", $c);
     }
     // exclude from expansion
     if (preg_match('/<noinclude>.+<\\/noinclude>/s', $initial_content)) {
         $initial_content = preg_replace("/<noinclude>.+?<\\/noinclude>/s", "", $initial_content);
     }
     // only in expansion
     $initial_content = preg_replace("/<includeonly>(.+)<\\/includeonly>/s", "\\1", $initial_content);
     $this->doVariableExpansion($initial_content, $vars, $basepage, $request);
     array_push($included_pages, $page);
     // If content is single-line, call TransformInline, else call TransformText
     $initial_content = trim($initial_content, "\n");
     if (preg_match("/\n/", $initial_content)) {
         include_once 'lib/BlockParser.php';
         $content = TransformText($initial_content, $r->get('markup'), $page);
     } else {
         include_once 'lib/InlineParser.php';
         $content = TransformInline($initial_content, $r->get('markup'), $page);
     }
     array_pop($included_pages);
     return $content;
 }