function isValidName($userid = false) { if (!$userid) { $userid = $this->_userid; } $WikiPageName = new WikiPageName($userid); return $WikiPageName->isValid() and $userid === $WikiPageName->name; }
/** * The main() function which generates a zip archive of a PhpWiki. * * If $include_archive is false, only the current version of each page * is included in the zip file; otherwise all archived versions are * included as well. */ function MakeWikiZip(&$request) { if ($request->getArg('include') == 'all') { $zipname = WIKI_NAME . _("FullDump") . date('Ymd-Hi') . '.zip'; $include_archive = true; } else { $zipname = WIKI_NAME . _("LatestSnapshot") . date('Ymd-Hi') . '.zip'; $include_archive = false; } $zip = new ZipWriter("Created by PhpWiki " . PHPWIKI_VERSION, $zipname); /* ignore fatals in plugins */ if (check_php_version(4, 1)) { global $ErrorManager; $ErrorManager->pushErrorHandler(new WikiFunctionCb('_dump_error_handler')); } $dbi =& $request->_dbi; $thispage = $request->getArg('pagename'); // for "Return to ..." if ($exclude = $request->getArg('exclude')) { // exclude which pagenames $excludeList = explodePageList($exclude); } else { $excludeList = array(); } if ($pages = $request->getArg('pages')) { // which pagenames if ($pages == '[]') { // current page $pages = $thispage; } $page_iter = new WikiDB_Array_PageIterator(explodePageList($pages)); } else { $page_iter = $dbi->getAllPages(false, false, false, $excludeList); } $request_args = $request->args; $timeout = !$request->getArg('start_debug') ? 30 : 240; while ($page = $page_iter->next()) { $request->args = $request_args; // some plugins might change them (esp. on POST) longer_timeout($timeout); // Reset watchdog $current = $page->getCurrentRevision(); if ($current->getVersion() == 0) { continue; } $pagename = $page->getName(); $wpn = new WikiPageName($pagename); if (!$wpn->isValid()) { continue; } if (in_array($page->getName(), $excludeList)) { continue; } $attrib = array('mtime' => $current->get('mtime'), 'is_ascii' => 1); if ($page->get('locked')) { $attrib['write_protected'] = 1; } if ($include_archive) { $content = MailifyPage($page, 0); } else { $content = MailifyPage($page); } $zip->addRegularFile(FilenameForPage($pagename), $content, $attrib); } $zip->finish(); if (check_php_version(4, 1)) { global $ErrorManager; $ErrorManager->popErrorHandler(); } }
function LinkPhpwikiURL($url, $text = '', $basepage = false) { $args = array(); if (!preg_match('/^ phpwiki: ([^?]*) [?]? (.*) $/x', $url, $m)) { return HTML::span(array('class' => 'error'), _("BAD phpwiki: URL")); } if ($m[1]) { $pagename = urldecode($m[1]); } $qargs = $m[2]; if (empty($pagename) && preg_match('/^(diff|edit|links|info)=([^&]+)$/', $qargs, $m)) { // Convert old style links (to not break diff links in // RecentChanges). $pagename = urldecode($m[2]); $args = array("action" => $m[1]); } else { $args = SplitQueryArgs($qargs); } if (empty($pagename)) { $pagename = $GLOBALS['request']->getArg('pagename'); } if (isset($args['action']) && $args['action'] == 'browse') { unset($args['action']); } /*FIXME: if (empty($args['action'])) $class = 'wikilink'; else if (is_safe_action($args['action'])) $class = 'wikiaction'; */ if (empty($args['action']) || is_safe_action($args['action'])) { $class = 'wikiaction'; } else { // Don't allow administrative links on unlocked pages. $dbi = $GLOBALS['request']->getDbh(); $page = $dbi->getPage($basepage ? $basepage : $pagename); if (!$page->get('locked')) { return HTML::span(array('class' => 'wikiunsafe'), HTML::u(_("Lock page to enable link"))); } $class = 'wikiadmin'; } if (!$text) { $text = HTML::span(array('class' => 'rawurl'), $url); } $wikipage = new WikiPageName($pagename); if (!$wikipage->isValid()) { global $WikiTheme; return $WikiTheme->linkBadWikiWord($wikipage, $url); } return HTML::a(array('href' => WikiURL($pagename, $args), 'class' => $class), $text); }
/** * Make a link to a wiki page (in this wiki). * * This is a convenience function. * * @param mixed $page_or_rev * Can be:<dl> * <dt>A string</dt><dd>The page to link to.</dd> * <dt>A WikiDB_Page object</dt><dd>The page to link to.</dd> * <dt>A WikiDB_PageRevision object</dt><dd>A specific version of the page to link to.</dd> * </dl> * * @param string $type * One of:<dl> * <dt>'unknown'</dt><dd>Make link appropriate for a non-existant page.</dd> * <dt>'known'</dt><dd>Make link appropriate for an existing page.</dd> * <dt>'auto'</dt><dd>Either 'unknown' or 'known' as appropriate.</dd> * <dt>'button'</dt><dd>Make a button-style link.</dd> * <dt>'if_known'</dt><dd>Only linkify if page exists.</dd> * </dl> * Unless $type of of the latter form, the link will be of class 'wiki', 'wikiunknown', * 'named-wiki', or 'named-wikiunknown', as appropriate. * * @param mixed $label (string or XmlContent object) * Label for the link. If not given, defaults to the page name. * * @return XmlContent The link */ function WikiLink($page_or_rev, $type = 'known', $label = false) { global $WikiTheme, $request; if ($type == 'button') { return $WikiTheme->makeLinkButton($page_or_rev, $label); } $version = false; if (isa($page_or_rev, 'WikiDB_PageRevision')) { $version = $page_or_rev->getVersion(); if ($page_or_rev->isCurrent()) { $version = false; } $page = $page_or_rev->getPage(); $pagename = $page->getName(); $wikipage = $pagename; $exists = true; } elseif (isa($page_or_rev, 'WikiDB_Page')) { $page = $page_or_rev; $pagename = $page->getName(); $wikipage = $pagename; } elseif (isa($page_or_rev, 'WikiPageName')) { $wikipage = $page_or_rev; $pagename = $wikipage->name; if (!$wikipage->isValid('strict')) { return $WikiTheme->linkBadWikiWord($wikipage, $label); } } else { $wikipage = new WikiPageName($page_or_rev, $request->getPage()); $pagename = $wikipage->name; if (!$wikipage->isValid('strict')) { return $WikiTheme->linkBadWikiWord($wikipage, $label); } } if ($type == 'auto' or $type == 'if_known') { if (isset($page)) { $exists = $page->exists(); } else { $dbi =& $request->_dbi; $exists = $dbi->isWikiPage($wikipage->name); } } elseif ($type == 'unknown') { $exists = false; } else { $exists = true; } // FIXME: this should be somewhere else, if really needed. // WikiLink makes A link, not a string of fancy ones. // (I think that the fancy split links are just confusing.) // Todo: test external ImageLinks http://some/images/next.gif if (isa($wikipage, 'WikiPageName') and !$label and strchr(substr($wikipage->shortName, 1), SUBPAGE_SEPARATOR)) { $parts = explode(SUBPAGE_SEPARATOR, $wikipage->shortName); $last_part = array_pop($parts); $sep = ''; $link = HTML::span(); foreach ($parts as $part) { $path[] = $part; $parent = join(SUBPAGE_SEPARATOR, $path); if ($WikiTheme->_autosplitWikiWords) { $part = " " . $part; } if ($part) { $link->pushContent($WikiTheme->linkExistingWikiWord($parent, $sep . $part)); } $sep = $WikiTheme->_autosplitWikiWords ? ' ' . SUBPAGE_SEPARATOR : SUBPAGE_SEPARATOR; } if ($exists) { $link->pushContent($WikiTheme->linkExistingWikiWord($wikipage, $sep . $last_part, $version)); } else { $link->pushContent($WikiTheme->linkUnknownWikiWord($wikipage, $sep . $last_part)); } return $link; } if ($exists) { return $WikiTheme->linkExistingWikiWord($wikipage, $label, $version); } elseif ($type == 'if_known') { if (!$label && isa($wikipage, 'WikiPageName')) { $label = $wikipage->shortName; } return HTML($label ? $label : $pagename); } else { return $WikiTheme->linkUnknownWikiWord($wikipage, $label); } }
function getPagename($basepage) { list($moniker, $page) = explode(":", $this->_link, 2); $page = new WikiPageName($page, $basepage); if ($page->isValid()) { return $page->name; } else { return false; } }
function _do_purge_bad_pagenames(&$request, $args) { // FIXME: this should be moved into WikiDB::normalize() or something... $dbi = $request->getDbh(); $count = 0; $list = HTML::ol(array('align' => 'left')); $pages = $dbi->getAllPages('include_empty'); // Do we really want the empty ones too? while ($page = $pages->next()) { $pagename = $page->getName(); $wpn = new WikiPageName($pagename); if (!$wpn->isValid()) { $dbi->purgePage($pagename); $list->pushContent(HTML::li($pagename)); $count++; } } $pages->free(); if (!$count) { return _("No pages with bad names had to be deleted."); } else { return HTML(fmt("Deleted %s pages with invalid names:", $count), HTML::div(array('align' => 'left'), $list)); } }
function expand($basepage, &$markup) { $this->_basepage = $basepage; $label = isset($this->_label) ? $this->_label : false; $anchor = isset($this->_anchor) ? (string) $this->_anchor : ''; $page = new WikiPageName($this->_page, $basepage, $anchor); if ($page->isValid()) { return WikiLink($page, 'auto', $label); } else { return HTML($label); } }