function WikiDB_backend_dumb_WantedPagesIter(&$backend, &$all_pages, $exclude = '', $sortby = false, $limit = false) { $this->_allpages = $all_pages; $this->_allpages_array = $all_pages->asArray(); $this->_backend =& $backend; if (!is_array($exclude)) { $this->exclude = $exclude ? PageList::explodePageList($exclude) : array(); } else { $this->exclude = $exclude; } }
function WikiDB_backend_dumb_WantedPagesIter(&$backend, &$all_pages, $exclude = '', $sortby = '', $limit = '') { $this->_allpages = $all_pages; $this->_allpages_array = $all_pages->asArray(); $this->_backend =& $backend; if (!is_array($exclude)) { $this->exclude = $exclude ? PageList::explodePageList($exclude) : array(); } else { $this->exclude = $exclude; } $this->sortby = $sortby; // ignored if ($limit) { // extract from,count from limit list($this->from, $this->limit) = $backend->limit($limit); } else { $this->limit = 0; $this->from = 0; } $this->pos = 0; $this->pagelinks = array(); }
/** * Apply filters for options like 'sortby', 'limit', 'exclude' * for simple queries like titleSearch, where the backend is not ready yet. * Since iteration is usually destructive for SQL results, * we have to generate a copy. */ function applyFilters($options = false) { if (!$options) { $options = $this->_options; } if (isset($options['sortby'])) { $array = array(); /* this is destructive */ while ($page = $this->next()) { $result[] = $page->getName(); } $this->_doSort($array, $options['sortby']); } /* the rest is not destructive. * reconstruct a new iterator */ $pagenames = array(); $i = 0; if (isset($options['limit'])) { $limit = $options['limit']; } else { $limit = 0; } if (isset($options['exclude'])) { $exclude = $options['exclude']; } if (is_string($exclude) and !is_array($exclude)) { $exclude = PageList::explodePageList($exclude, false, false, $limit); } foreach ($array as $pagename) { if ($limit and $i++ > $limit) { return new WikiDB_Array_PageIterator($pagenames); } if (!empty($exclude) and !in_array($pagename, $exclude)) { $pagenames[] = $pagename; } elseif (empty($exclude)) { $pagenames[] = $pagename; } } return new WikiDB_Array_PageIterator($pagenames); }
function explodePageList($input, $include_empty = false, $sortby = 'pagename', $limit = '', $exclude = '') { include_once "lib/PageList.php"; return PageList::explodePageList($input, $include_empty, $sortby, $limit, $exclude); }
function run($dbi, $argstr, &$request, $basepage) { $this->args = $this->getArgs($argstr, $request); extract($this->args); $this->request =& $request; if (!$from_lang) { $from_lang = $request->getPref('lang'); } if (!$from_lang) { $from_lang = $GLOBALS['LANG']; } $this->lang = $from_lang; if (empty($languages)) { $available_languages = listAvailableLanguages(); if ($from_lang == 'en') { // "en" is always the first. array_shift($available_languages); } // put from_lang to the very end. if (in_array($from_lang, $available_languages)) { $languages = $available_languages; } else { $languages = array_merge($available_languages, array($from_lang)); } } elseif (strstr($languages, ',')) { $languages = explode(',', $languages); } else { $languages = array($languages); } if (in_array('zh', $languages) or in_array('ja', $languages)) { // If the current charset != utf-8 the text will not be displayed correctly. // But here we cannot change the header anymore. So we can decide to ignore them, // or display them with all the errors. //FIXME: do iconv the ob if ($GLOBALS['charset'] != 'utf-8' and !defined('NEED_ICONV_TO')) { define('NEED_ICONV_TO', 'utf-8'); //either the extension or external //$GLOBALS['charset'] = 'utf-8'; } } $to_lang = $languages[0]; if (!empty($string) and count($languages) == 1) { return $this->translate($string, $to_lang, $from_lang); } if (!empty($page)) { $pagename = $page; if ($dbi->isWikiPage($pagename)) { $url = ''; // google can only translate from english and french if (in_array($from_lang, array('en', 'fr'))) { $url = "http://translate.google.com/translate"; $url .= "?langpair=" . urlencode($from_lang . "|" . $to_lang); $url .= "&u=" . urlencode(WikiURL($pagename, false, true)); } // redirect or transclude? if ($url) { return $request->redirect($url); } return HTML(fmt("TODO: Google can only translate from english and french. Find a translation service for %s to language %s", WikiURL($pagename, false, true), $to_lang)); } else { return $this->error(fmt("%s is empty", $pagename)); } } $pagelist = new PageList('', $exclude, $this->args); $pagelist->_columns[0]->_heading = "{$from_lang}"; foreach ($languages as $lang) { if ($lang == $from_lang) { continue; } $field = "custom:{$lang}"; $pagelist->addColumnObject(new _PageList_Column_customlang($field, $from_lang, $this)); } if (!empty($string)) { $pagelist->addPage($string); return $pagelist; } switch ($what) { case 'allpages': $pagelist->addPages($dbi->getAllPages($include_empty, $sortby, $limit, $exclude)); break; case 'pages': // not all pages, only the pgsrc pages if (!is_array($exclude)) { $exclude = $pagelist->explodePageList($exclude, false, $sortby, $limit, $exclude); } $path = FindLocalizedFile(WIKI_PGSRC); $pgsrc = new fileSet($path); foreach ($pgsrc->getFiles($exclude, $sortby, $limit) as $pagename) { $pagename = urldecode($pagename); if (substr($pagename, -1, 1) == '~') { continue; } if (in_array($pagename, $exclude)) { continue; } // exclude page. if ($match != '*' and !glob_match($match, $pagename)) { continue; } $page_handle = $dbi->getPage($pagename); $pagelist->addPage($page_handle); } break; case 'wikiwords': if (!isset($this->_locales[$from_lang])) { $this->init_locale($from_lang); } $locale =& $this->_locales[$from_lang]; if (is_array($locale)) { $count = 0; foreach ($locale as $from => $to) { if ($match != '*' and !glob_match($match, $from)) { continue; } if (isWikiWord($from)) { $count++; $pagelist->addPage($from); if ($limit and $count > $limit) { break; } } } } break; // all Button texts, which need a localized .png // where to get them from? templates/*.tmpl: Button() // and WikiLink(?,'button') // navbar links, actionpages, and admin requests // all Button texts, which need a localized .png // where to get them from? templates/*.tmpl: Button() // and WikiLink(?,'button') // navbar links, actionpages, and admin requests case 'buttons': $buttons = $GLOBALS['AllActionPages']; $fileset = new FileSet(FindFile("themes/MacOSX/buttons/en"), "*.png"); foreach ($fileset->getFiles() as $file) { $b = urldecode(substr($file, 0, -4)); if (!in_array($b, $buttons)) { $buttons[] = $b; } } $count = 0; foreach ($buttons as $button) { $pagelist->addPage($button); if ($limit and ++$count > $limit) { break; } } break; } return $pagelist; }
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; }
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; }