function PurgePage(&$request) { global $WikiTheme; $page = $request->getPage(); $pagelink = WikiLink($page); if ($request->getArg('cancel')) { $request->redirect(WikiURL($page)); // noreturn } $current = $page->getCurrentRevision(); if (!$current or !($version = $current->getVersion())) { $html = HTML::p(array('class' => 'error'), _("Sorry, this page does not exist.")); } elseif (!$request->isPost() || !$request->getArg('verify')) { $purgeB = Button('submit:verify', _("Purge Page"), 'wikiadmin'); $cancelB = Button('submit:cancel', _("Cancel"), 'button'); // use generic wiki button look $fieldset = HTML::fieldset(HTML::p(fmt("You are about to purge '%s'!", $pagelink)), HTML::form(array('method' => 'post', 'action' => $request->getPostURL()), HiddenInputs(array('currentversion' => $version, 'pagename' => $page->getName(), 'action' => 'purge')), HTML::div(array('class' => 'toolbar'), $purgeB, $WikiTheme->getButtonSeparator(), $cancelB))); $sample = HTML::div(array('class' => 'transclusion')); // simple and fast preview expanding only newlines foreach (explode("\n", firstNWordsOfContent(100, $current->getPackedContent())) as $s) { $sample->pushContent($s, HTML::br()); } $html = HTML($fieldset, HTML::div(array('class' => 'wikitext'), $sample)); } elseif ($request->getArg('currentversion') != $version) { $html = HTML(HTML::p(array('class' => 'error'), _("Someone has edited the page!")), HTML::p(fmt("Since you started the purge process, someone has saved a new version of %s. Please check to make sure you still want to permanently purge the page from the database.", $pagelink))); } else { // Real purge. $pagename = $page->getName(); $dbi = $request->getDbh(); $dbi->purgePage($pagename); $dbi->touch(); $html = HTML::div(array('class' => 'feedback'), fmt("Purged page '%s' successfully.", $pagename)); } GeneratePage($html, _("Purge Page")); }
function RemovePage(&$request) { global $WikiTheme; $page = $request->getPage(); $pagelink = WikiLink($page); if ($request->getArg('cancel')) { $request->redirect(WikiURL($page)); // noreturn } $current = $page->getCurrentRevision(); if (!$current or !($version = $current->getVersion())) { $html = HTML(HTML::h2(_("Already deleted")), HTML::p(_("Sorry, this page is not in the database."))); } elseif (!$request->isPost() || !$request->getArg('verify')) { $removeB = Button('submit:verify', _("Remove Page"), 'wikiadmin'); $cancelB = Button('submit:cancel', _("Cancel"), 'button'); // use generic wiki button look $html = HTML(HTML::h2(fmt("You are about to remove '%s'!", $pagelink)), HTML::form(array('method' => 'post', 'action' => $request->getPostURL()), HiddenInputs(array('currentversion' => $version, 'pagename' => $page->getName(), 'action' => 'remove')), HTML::div(array('class' => 'toolbar'), $removeB, $WikiTheme->getButtonSeparator(), $cancelB)), HTML::hr()); $sample = HTML::div(array('class' => 'transclusion')); // simple and fast preview expanding only newlines foreach (explode("\n", firstNWordsOfContent(100, $current->getPackedContent())) as $s) { $sample->pushContent($s, HTML::br()); } $html->pushContent(HTML::div(array('class' => 'wikitext'), $sample)); } elseif ($request->getArg('currentversion') != $version) { $html = HTML(HTML::h2(_("Someone has edited the page!")), HTML::p(fmt("Since you started the deletion process, someone has saved a new version of %s. Please check to make sure you still want to permanently remove the page from the database.", $pagelink))); } else { // Codendi specific: remove the deleted wiki page from ProjectWantedPages $projectPageName = 'ProjectWantedPages'; $pagename = $page->getName(); $dbi = $request->getDbh(); require_once PHPWIKI_DIR . "/lib/loadsave.php"; $pagehandle = $dbi->getPage($projectPageName); if ($pagehandle->exists()) { // don't replace default contents $current = $pagehandle->getCurrentRevision(); $version = $current->getVersion(); $text = $current->getPackedContent(); $meta = $current->_data; } $text = str_replace("* [{$pagename}]", "", $text); $meta['summary'] = $GLOBALS['Language']->getText('wiki_lib_wikipagewrap', 'page_added', array($pagename)); $meta['author'] = user_getname(); $pagehandle->save($text, $version + 1, $meta); //Codendi specific: remove permissions for this page @codenditodo: may be transferable otherwhere. require_once 'common/wiki/lib/WikiPage.class.php'; $wiki_page = new WikiPage(GROUP_ID, $_REQUEST['pagename']); $wiki_page->resetPermissions(); // Real delete. //$pagename = $page->getName(); $dbi = $request->getDbh(); $dbi->deletePage($pagename); $dbi->touch(); $link = HTML::a(array('href' => 'javascript:history.go(-2)'), _("Back to the previous page.")); $html = HTML(HTML::h2(fmt("Removed page '%s' successfully.", $pagename)), HTML::div($link), HTML::hr()); } GeneratePage($html, _("Remove Page")); }
/** * handles the arguments: section, sectionhead, lines, words, bytes, * for UnfoldSubpages, IncludePage, ... */ function extractParts($c, $pagename, $args) { extract($args); if ($section) { $c = extractSection($section, $c, $pagename, $quiet, $sectionhead); } if ($lines) { $c = array_slice($c, 0, $lines); $c[] = sprintf(_(" ... first %d lines"), $bytes); } if ($words) { $c = firstNWordsOfContent($words, $c); } if ($bytes) { $ct = implode("\n", $c); // one string if (strlen($ct) > $bytes) { $ct = substr($c, 0, $bytes); $c = array($ct, sprintf(_(" ... first %d bytes"), $bytes)); } } $ct = implode("\n", $c); // one string return $ct; }
function run($dbi, $argstr, &$request, $basepage) { extract($this->getArgs($argstr, $request)); 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"), $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(); if ($section) { $c = extractSection($section, $c, $page, $quiet, $sectionhead); } if ($lines) { $c = array_slice($c, 0, $lines); } if ($words) { $c = firstNWordsOfContent($words, $c); } array_push($included_pages, $page); include_once 'lib/BlockParser.php'; $content = TransformText(implode("\n", $c), $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)); }
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; } // trap any remaining nonexistant subpages if ($page->exists()) { $r = $page->getCurrentRevision(); $c = $r->getContent(); // array of lines // trap recursive redirects if (preg_match('/<' . '\\?plugin\\s+RedirectTo\\s+page=(\\w+)\\s+\\?' . '>/', implode("\n", $c), $m)) { if (in_array($m[1], $included_pages)) { if (!$quiet) { $content->pushContent(HTML::p(sprintf(_("recursive inclusion of page %s ignored"), $cpagename . ' => ' . $m[1]))); } continue; } } if ($section) { $c = extractSection($section, $c, $cpagename, $quiet, $sectionhead); } if ($lines) { $c = array_slice($c, 0, $lines) . sprintf(_(" ... first %d lines"), $bytes); } if ($words) { $c = firstNWordsOfContent($words, $c); } if ($bytes) { if (strlen($c) > $bytes) { $c = substr($c, 0, $bytes) . sprintf(_(" ... first %d bytes"), $bytes); } } $ct = implode("\n", $c); // one string 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 (!$cpagename) { return $this->error(sprintf(_("%s has no subpages defined."), $pagename)); } return $content; }