function run($dbi, $argstr, &$request, $basepage) { $args = $this->getArgs($argstr, $request); extract($args); if ($debug) { $timer = new DebugTimer(); } $group = $request->getGroup(); if (method_exists($group, '_allUsers')) { $allusers = $group->_allUsers(); } else { $allusers = array(); } $args['count'] = count($allusers); // deleted pages show up as version 0. $pagelist = new PageList($info, $exclude, $args); if (!$noheader) { $pagelist->setCaption(_("Authenticated users on this wiki (%d total):")); } if ($include_empty and empty($info)) { $pagelist->_addColumn('version'); } list($offset, $pagesize) = $pagelist->limit($args['limit']); if (!$pagesize) { $pagelist->addPageList($allusers); } else { for ($i = $offset; $i < $offset + $pagesize - 1; $i++) { if ($i >= $args['count']) { break; } $pagelist->addPage($allusers[$i]); } } /* $page_iter = $dbi->getAllPages($include_empty, $sortby, $limit); while ($page = $page_iter->next()) { if ($page->isUserPage($include_empty)) $pagelist->addPage($page); } */ if ($debug) { return HTML($pagelist, HTML::p(fmt("Elapsed time: %s s", $timer->getStats()))); } else { return $pagelist; } }
function run($dbi, $argstr, &$request, $basepage) { $args = $this->getArgs($argstr, $request); extract($args); // There's probably a more efficient way to do this (eg a // tailored SQL query via the backend, but this does the job $allpages_iter = $dbi->getAllPages($include_empty); $pages = array(); while ($page = $allpages_iter->next()) { $links_iter = $page->getBackLinks(); // Test for absence of backlinks. If a page is linked to // only by itself, it is still an orphan $parent = $links_iter->next(); if (!$parent or $parent->getName() == $page->getName() and !$links_iter->next()) { $pages[] = $page; } } $args['count'] = count($pages); $pagelist = new PageList($info, $exclude, $args); if (!$noheader) { $pagelist->setCaption(_("Orphaned Pages in this wiki (%d total):")); } // deleted pages show up as version 0. if ($include_empty) { $pagelist->_addColumn('version'); } list($offset, $pagesize) = $pagelist->limit($args['limit']); if (!$pagesize) { $pagelist->addPageList($pages); } else { for ($i = $offset; $i < $offset + $pagesize - 1; $i++) { if ($i >= $args['count']) { break; } $pagelist->addPage($pages[$i]); } } return $pagelist; }
function run($dbi, $argstr, &$request, $basepage) { global $DBParams; //$request->setArg('nocache','1'); extract($this->getArgs($argstr, $request)); if (!$alias) { return $this->error(_("No DSN alias for SqlResult.ini specified")); } $sql = $this->_sql; // apply custom filters if ($where and strstr($sql, "%%where%%")) { $sql = str_replace("%%where%%", $where, $sql); } // TODO: use a SQL construction library? if ($limit) { $pagelist = new PageList(); $limit = $pagelist->limit($limit); if (strstr($sql, "%%limit%%")) { $sql = str_replace("%%limit%%", $limit, $sql); } else { if (strstr($sql, "LIMIT")) { $sql = preg_replace("/LIMIT\\s+[\\d,]+\\s+/m", "LIMIT " . $limit . " ", $sql); } } } if (strstr($sql, "%%sortby%%")) { if (!$sortby) { $sql = preg_replace("/ORDER BY .*%%sortby%%\\s/m", "", $sql); } else { $sql = str_replace("%%sortby%%", $sortby, $sql); } } elseif (PageList::sortby($sortby, 'db')) { // add sorting: support paging sortby links if (preg_match("/\\sORDER\\s/", $sql)) { $sql = preg_replace("/ORDER BY\\s\\S+\\s/m", "ORDER BY " . PageList::sortby($sortby, 'db'), $sql); } else { $sql .= " ORDER BY " . PageList::sortby($sortby, 'db'); } } $inidsn = $this->getDsn($alias); if (!$inidsn) { return $this->error(sprintf(_("No DSN for alias %s in SqlResult.ini found"), $alias)); } // adodb or pear? adodb as default, since we distribute per default it. // for pear there may be overrides. // TODO: native PDO support (for now we use ADODB) if ($DBParams['dbtype'] == 'SQL') { $dbh = DB::connect($inidsn); $all = $dbh->getAll($sql); if (DB::isError($all)) { return $this->error($all->getMessage() . ' ' . $all->userinfo); } } else { // unless PearDB use the included ADODB, regardless if dba, file or PDO, ... if ($DBParams['dbtype'] != 'ADODB') { // require_once('lib/WikiDB/adodb/adodb-errorhandler.inc.php'); require_once 'lib/WikiDB/adodb/adodb.inc.php'; } $parsed = parseDSN($inidsn); $dbh =& ADONewConnection($parsed['phptype']); $conn = $dbh->Connect($parsed['hostspec'], $parsed['username'], $parsed['password'], $parsed['database']); if (!$conn) { return $this->error($dbh->errorMsg()); } $GLOBALS['ADODB_FETCH_MODE'] = ADODB_FETCH_ASSOC; $dbh->SetFetchMode(ADODB_FETCH_ASSOC); $all = $dbh->getAll($sql); $GLOBALS['ADODB_FETCH_MODE'] = ADODB_FETCH_NUM; $dbh->SetFetchMode(ADODB_FETCH_NUM); if (!$all) { return $this->error($dbh->errorMsg()); } } $args = array(); if ($limit) { // fill paging vars (see PageList) $args = $pagelist->pagingTokens(count($all), count($all[0]), $limit); if (!$args) { $args = array(); } } if ($template) { $args = array_merge(array('SqlResult' => $all, 'ordered' => $ordered, 'where' => $where, 'sortby' => $sortby, 'limit' => $limit), $args); // paging params override given params return Template($template, $args); } else { if ($ordered) { $html = HTML::ol(array('class' => 'sqlresult')); if ($all) { foreach ($all as $row) { $html->pushContent(HTML::li(array('class' => $i++ % 2 ? 'evenrow' : 'oddrow'), $row[0])); } } } else { $html = HTML::table(array('class' => 'sqlresult')); $i = 0; if ($all) { foreach ($all as $row) { $tr = HTML::tr(array('class' => $i++ % 2 ? 'evenrow' : 'oddrow')); if ($row) { foreach ($row as $col) { $tr->pushContent(HTML::td($col)); } } $html->pushContent($tr); } } } } // do paging via pagelink template if (!empty($args['NUMPAGES'])) { $paging = Template("pagelink", $args); $html = $table->pushContent(HTML::thead($paging), HTML::tbody($html), HTML::tfoot($paging)); } if (0 and DEBUG) { // test deferred error/warning/notice collapsing trigger_error("test notice", E_USER_NOTICE); trigger_error("test warning", E_USER_WARNING); } return $html; }
function run($dbi, $argstr, &$request, $basepage) { $args = $this->getArgs($argstr, $request); if (!empty($args['exclude_from'])) { $args['exclude_from'] = is_string($args['exclude_from']) ? explodePageList($args['exclude_from']) : $args['exclude_from']; } // <! plugin-list !> extract($args); if ($page == _("WantedPages")) { $page = ""; } // There's probably a more memory-efficient way to do this (eg // a tailored SQL query via the backend, but this gets the job // done. // TODO: Move this to backend/dumb/WantedPagesIter.php if (!$page) { $GLOBALS['WikiTheme']->addPageListColumn(array('wanted' => array('_PageList_Column_WantedPages_wanted', 'custom:wanted', _("Wanted From"), 'left'))); } $pagelist = new PageList($page ? '' : 'pagename,wanted', $exclude, $args); // search button? $pagelist->_wpagelist = array(); if (!$page) { list($offset, $maxcount) = $pagelist->limit($limit); $wanted_iter = $dbi->wantedPages($exclude_from, $exclude, $sortby, $limit); while ($row = $wanted_iter->next()) { $wanted = $row['pagename']; $wantedfrom = $row['wantedfrom']; // ignore duplicates: if (empty($pagelist->_wpagelist[$wanted])) { $pagelist->addPage($wanted); } $pagelist->_wpagelist[$wanted][] = $wantedfrom; } $wanted_iter->free(); // update limit, but it's still a hack. $pagelist->_options['limit'] = "{$offset}," . min($pagelist->getTotal(), $maxcount); } elseif ($dbi->isWikiPage($page)) { //only get WantedPages links for one page $page_handle = $dbi->getPage($page); $links = $page_handle->getPageLinks(true); // include_empty while ($link_handle = $links->next()) { if (!$dbi->isWikiPage($linkname = $link_handle->getName())) { $pagelist->addPage($linkname); //if (!array_key_exists($linkname, $this->_wpagelist)) $pagelist->_wpagelist[$linkname][] = 1; } } } /* if ($sortby) { ksort($this->_wpagelist); arsort($this->_wpagelist); }*/ if (!$noheader) { if ($page) { $pagelist->setCaption(sprintf(_("Wanted Pages for %s:"), $page)); } else { $pagelist->setCaption(sprintf(_("Wanted Pages in this wiki:"))); } } // reference obviously doesn't work, so force an update to add _wpagelist to parentobj if (isset($pagelist->_columns[1]) and $pagelist->_columns[1]->_field == 'wanted') { $pagelist->_columns[1]->parentobj =& $pagelist; } return $pagelist; }