function run($dbi, $argstr, &$request, $basepage) { //if ($request->getArg('action') != 'browse') // return $this->disabled("(action != 'browse')"); $args = $this->getArgs($argstr, $request); $this->_args = $args; extract($args); $this->preSelectS($args, $request); $info = $args['info']; $this->debug = $args['debug']; // array_multisort($this->_list, SORT_NUMERIC, SORT_DESC); $pagename = $request->getArg('pagename'); // GetUrlToSelf() with all given params //$uri = $GLOBALS['HTTP_SERVER_VARS']['REQUEST_URI']; // without s would be better. //$uri = $request->getURLtoSelf();//false, array('verify')); $form = HTML::form(array('action' => $request->getPostURL(), 'method' => 'POST')); if ($request->getArg('WikiAdminSelect') == _("Go")) { $p = false; } else { $p = $request->getArg('p'); } //$p = @$GLOBALS['HTTP_POST_VARS']['p']; $form->pushContent(HTML::p(array('class' => 'wikitext'), _("Select: "), HTML::input(array('type' => 'text', 'name' => 's', 'value' => $args['s'])), HTML::input(array('type' => 'submit', 'name' => 'WikiAdminSelect', 'value' => _("Go"))))); if ($request->isPost() && !$request->getArg('wikiadmin') && !empty($p)) { $this->_list = array(); // List all selected pages again. foreach ($p as $page => $name) { $this->_list[$name] = 1; } } elseif ($request->isPost() and $request->_user->isAdmin() and !empty($p) and $request->getArg('action') == 'WikiAdminSelect' and $request->getArg('wikiadmin')) { // handle external plugin $loader = new WikiPluginLoader(); $a = array_keys($request->getArg('wikiadmin')); $plugin_action = $a[0]; $single_arg_plugins = array("Remove"); if (in_array($plugin_action, $single_arg_plugins)) { $plugin = $loader->getPlugin($plugin_action); $ul = HTML::ul(); foreach ($p as $page => $name) { $plugin_args = "run_page={$name}"; $request->setArg($plugin_action, 1); $request->setArg('p', array($page => $name)); // if the plugin requires more args than the pagename, // then this plugin will not return. (Rename, SearchReplace, ...) $action_result = $plugin->run($dbi, $plugin_args, $request, $basepage); $ul->pushContent(HTML::li(fmt("Selected page '%s' passed to '%s'.", $name, $select))); $ul->pushContent(HTML::ul(HTML::li($action_result))); } } else { // redirect to the plugin page. // in which page is this plugin? $plugin_action = preg_replace("/^WikiAdmin/", "", $plugin_action); $args = array(); foreach ($p as $page => $x) { $args["p[{$page}]"] = 1; } header("Location: " . WikiURL(_("PhpWikiAdministration") . "/" . _($plugin_action), $args, 1)); exit; } } elseif (empty($args['s'])) { // List all pages to select from. $this->_list = $this->collectPages($this->_list, $dbi, $args['sortby'], $args['limit']); } $pagelist = new PageList_Selectable($info, $args['exclude'], $args); $pagelist->addPageList($this->_list); $form->pushContent($pagelist->getContent()); foreach ($args as $k => $v) { if (!in_array($k, array('s', 'WikiAdminSelect', 'action', 'verify'))) { $form->pushContent(HiddenInputs(array($k => $v))); } // plugin params } /* foreach ($_GET as $k => $v) { if (!in_array($k,array('s','WikiAdminSelect','action'))) $form->pushContent(HiddenInputs(array($k => $v))); // debugging params, ... } */ if (!$request->getArg('verify')) { $form->pushContent(HTML::input(array('type' => 'hidden', 'name' => 'action', 'value' => 'verify'))); $form->pushContent(Button('submit:verify', _("Select pages"), 'wikiadmin'), Button('submit:cancel', _("Cancel"), 'button')); } else { global $WikiTheme; $form->pushContent(HTML::input(array('type' => 'hidden', 'name' => 'action', 'value' => 'WikiAdminSelect'))); // Add the Buttons for all registered WikiAdmin plugins $plugin_dir = 'lib/plugin'; if (defined('PHPWIKI_DIR')) { $plugin_dir = PHPWIKI_DIR . "/{$plugin_dir}"; } $fs = new fileSet($plugin_dir, 'WikiAdmin*.php'); $actions = $fs->getFiles(); foreach ($actions as $f) { $f = preg_replace('/.php$/', '', $f); $s = preg_replace('/^WikiAdmin/', '', $f); if (!in_array($s, array("Select", "Utils"))) { // disable Select and Utils $form->pushContent(Button("submit:wikiadmin[{$f}]", _($s), "wikiadmin")); $form->pushContent($WikiTheme->getButtonSeparator()); } } $form->pushContent(Button('submit:cancel', _("Cancel"), 'button')); } if (!$request->getArg('select')) { return $form; } else { //return $action_result; } }
/** * fromFile - read pictures & descriptions (separated by ;) * from $src and return it in array $photos * * @param string $src path to dir or textfile (local or remote) * @param array $photos * @return string Error when bad url or file couldn't be opened */ function fromFile($src, &$photos, $webpath = '') { $src_bak = $src; //there has a big security hole... as loading config/config.ini ! if (!preg_match('/(\\.csv|\\.jpg|\\.jpeg|\\.png|\\.gif|\\/)$/', $src)) { return $this->error(_("File extension for csv file has to be '.csv'")); } if (!IsSafeURL($src)) { return $this->error(_("Bad url in src: remove all of <, >, \"")); } if (preg_match('/^(http|ftp|https):\\/\\//i', $src)) { $contents = url_get_contents($src); $web_location = 1; } else { $web_location = 0; } if (!file_exists($src) and @file_exists(PHPWIKI_DIR . "/{$src}")) { $src = PHPWIKI_DIR . "/{$src}"; } // check if src is a directory if (file_exists($src) and filetype($src) == 'dir') { //all images $list = array(); foreach (array('jpeg', 'jpg', 'png', 'gif') as $ext) { $fileset = new fileSet($src, "*.{$ext}"); $list = array_merge($list, $fileset->getFiles()); } // convert dirname($src) (local fs path) to web path natcasesort($list); if (!$webpath) { // assume relative src. default: "themes/Hawaiian/images/pictures" $webpath = DATA_PATH . '/' . $src_bak; } foreach ($list as $file) { // convert local path to webpath $photos[] = array("src" => $file, "name" => $webpath . "/{$file}", "name_tile" => $src . "/{$file}", "src" => $src . "/{$file}", "desc" => ""); } return; } // check if $src is an image foreach (array('jpeg', 'jpg', 'png', 'gif') as $ext) { if (preg_match("/\\.{$ext}\$/", $src)) { if (!file_exists($src) and @file_exists(PHPWIKI_DIR . "/{$src}")) { $src = PHPWIKI_DIR . "/{$src}"; } if ($web_location == 1 and !empty($contents)) { $photos[] = array("src" => $src, "name" => $src, "name_tile" => $src, "src" => $src, "desc" => ""); return; } if (!file_exists($src)) { return $this->error(fmt("Unable to find src='%s'", $src)); } $photos[] = array("src" => $src, "name" => "../" . $src, "name_tile" => $src, "src" => $src, "desc" => ""); return; } } if ($web_location == 0) { $fp = @fopen($src, "r"); if (!$fp) { return $this->error(fmt("Unable to read src='%s'", $src)); } while ($data = fgetcsv($fp, 1024, ';')) { if (count($data) == 0 || empty($data[0]) || preg_match('/^#/', $data[0]) || preg_match('/^[[:space:]]*$/', $data[0])) { continue; } if (empty($data[1])) { $data[1] = ''; } $photos[] = array("name" => dirname($src) . "/" . trim($data[0]), "location" => "../" . dirname($src) . "/" . trim($data[0]), "desc" => trim($data[1]), "name_tile" => dirname($src) . "/" . trim($data[0])); } fclose($fp); } elseif ($web_location == 1) { //TODO: checks if the file is an image $contents = preg_split('/\\n/', $contents); while (list($key, $value) = each($contents)) { $data = preg_split('/\\;/', $value); if (count($data) == 0 || empty($data[0]) || preg_match('/^#/', $data[0]) || preg_match('/^[[:space:]]*$/', $data[0])) { continue; } if (empty($data[1])) { $data[1] = ''; } $photos[] = array("name" => dirname($src) . "/" . trim($data[0]), "src" => dirname($src) . "/" . trim($data[0]), "desc" => trim($data[1]), "name_tile" => dirname($src) . "/" . trim($data[0])); } } }
function imagePulldown($query, $case_exact = false, $regex = 'auto') { global $WikiTheme; $image_dir = getUploadFilePath(); $pd = new fileSet($image_dir, '*'); $images = $pd->getFiles(); unset($pd); if (UPLOAD_USERDIR) { $image_dir .= "/" . $request->_user->_userid; $pd = new fileSet($image_dir, '*'); $images = array_merge($images, $pd->getFiles()); unset($pd); } sort($images); if (!empty($images)) { $image_js = ''; foreach ($images as $image) { // Select only image and video files if (is_image($image) or is_video($image)) { $image_js .= ",['{$image}','{{" . $image . "}}']"; } } $image_js = substr($image_js, 1); $more_buttons = HTML::img(array('class' => "toolbar", 'id' => 'tb-images', 'src' => $WikiTheme->getImageURL("ed_image.png"), 'title' => _("Add Image or Video"), 'alt' => _("Add Image or Video"), 'onclick' => "showPulldown('" . _("Insert Image or Video") . "',[" . $image_js . "],'" . _("Insert") . "','" . _("Close") . "','tb-images')")); return HTML("\n", $more_buttons); } return ''; }
function CheckPgsrcUpdate(&$request, $checkonly = false) { echo "<h3>", _("check for necessary pgsrc updates"), "</h3>\n"; $dbi = $request->getDbh(); $path = FindLocalizedFile(WIKI_PGSRC); $pgsrc = new fileSet($path); // fixme: verification, ... $isHomePage = false; foreach ($pgsrc->getFiles() as $filename) { if (substr($filename, -1, 1) == '~') { continue; } $pagename = urldecode($filename); // don't ever update the HomePage if (defined(HOME_PAGE)) { if ($pagename == HOME_PAGE) { $isHomePage = true; } else { if ($pagename == _("HomePage")) { $isHomePage = true; } } } if ($pagename == "HomePage") { $isHomePage = true; } if ($isHomePage) { echo "{$path}/{$pagename}: ", _("always skip the HomePage."), _(" skipped"), ".<br />\n"; $isHomePage = false; continue; } if (!isActionPage($filename)) { doPgsrcUpdate($request, $pagename, $path, $filename, $checkonly); } } return; }
function listPlugins($credentials = false) { global $server; checkCredentials($server, $credentials, 'change', _("HomePage")); $plugin_dir = 'lib/plugin'; if (defined('PHPWIKI_DIR')) { $plugin_dir = PHPWIKI_DIR . "/{$plugin_dir}"; } $pd = new fileSet($plugin_dir, '*.php'); $plugins = $pd->getFiles(); unset($pd); sort($plugins); $RetArray = array(); if (!empty($plugins)) { require_once "lib/WikiPlugin.php"; $w = new WikiPluginLoader(); foreach ($plugins as $plugin) { $pluginName = str_replace(".php", "", $plugin); $p = $w->getPlugin($pluginName, false); // second arg? // trap php files which aren't WikiPlugin~s: wikiplugin + wikiplugin_cached only if (strtolower(substr(get_parent_class($p), 0, 10)) == 'wikiplugin') { $RetArray[] = $pluginName; } } } return $RetArray; }
function _generateTableBody(&$info, &$dbi, &$request, &$table) { $plugin_dir = 'lib/plugin'; if (defined('PHPWIKI_DIR')) { $plugin_dir = PHPWIKI_DIR . "/{$plugin_dir}"; } $pd = new fileSet($plugin_dir, '*.php'); $plugins = $pd->getFiles(); unset($pd); sort($plugins); // table body $tbody = HTML::tbody(); $row_no = 0; $w = new WikiPluginLoader(); foreach ($plugins as $pluginName) { // instantiate a plugin $pluginName = str_replace(".php", "", $pluginName); $temppluginclass = "<? plugin {$pluginName} ?>"; // hackish $p = $w->getPlugin($pluginName, false); // second arg? // trap php files which aren't WikiPlugin~s if (!strtolower(substr(get_parent_class($p), 0, 10)) == 'wikiplugin') { // Security: Hide names of extraneous files within // plugin dir from non-admins. if ($request->_user->isAdmin()) { trigger_error(sprintf(_("%s does not appear to be a WikiPlugin."), $pluginName . ".php")); } continue; // skip this non WikiPlugin file } $desc = $p->getDescription(); $ver = $p->getVersion(); $arguments = $p->getArgumentsDescription(); unset($p); //done querying plugin object, release from memory // This section was largely improved by Pierrick Meignen: // make a link if an actionpage exists $pluginNamelink = $pluginName; $pluginDocPageName = $pluginName . "Plugin"; $pluginDocPageNamelink = false; $localizedPluginName = ''; $localizedPluginDocPageName = ''; if ($GLOBALS['LANG'] != "en") { if (_($pluginName) != $pluginName) { $localizedPluginName = _($pluginName); } if ($localizedPluginName && $dbi->isWikiPage($localizedPluginName)) { $pluginDocPageNamelink = WikiLink($localizedPluginName, 'if_known'); } if (_($pluginDocPageName) != $pluginDocPageName) { $localizedPluginDocPageName = _($pluginDocPageName); } if ($localizedPluginDocPageName && $dbi->isWikiPage($localizedPluginDocPageName)) { $pluginDocPageNamelink = WikiLink($localizedPluginDocPageName, 'if_known'); } } else { $pluginNamelink = WikiLink($pluginName, 'if_known'); if ($dbi->isWikiPage($pluginDocPageName)) { $pluginDocPageNamelink = WikiLink($pluginDocPageName, 'if_known'); } } // highlight alternate rows $row_no++; $group = (int) ($row_no / 1); //_group_rows $class = $group % 2 ? 'evenrow' : 'oddrow'; // generate table row $tr = HTML::tr(array('class' => $class)); if ($pluginDocPageNamelink) { // plugin has a description page 'PluginName' . 'Plugin' $tr->pushContent(HTML::td($pluginNamelink, HTML::br(), $pluginDocPageNamelink)); $pluginDocPageNamelink = false; } else { // plugin just has an actionpage $tr->pushContent(HTML::td($pluginNamelink)); } $tr->pushContent(HTML::td($ver), HTML::td($desc)); if ($info == 'args') { // add Arguments column $style = array('style' => 'font-family:monospace;font-size:smaller'); $tr->pushContent(HTML::td($style, $arguments)); } $tbody->pushContent($tr); } $table->pushContent($tbody); }
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 listPlugins($params) { $plugin_dir = 'lib/plugin'; if (defined('PHPWIKI_DIR')) { $plugin_dir = PHPWIKI_DIR . "/{$plugin_dir}"; } $pd = new fileSet($plugin_dir, '*.php'); $plugins = $pd->getFiles(); unset($pd); sort($plugins); $RetArray = array(); if (!empty($plugins)) { require_once "lib/WikiPlugin.php"; $w = new WikiPluginLoader(); foreach ($plugins as $plugin) { $pluginName = str_replace(".php", "", $plugin); $p = $w->getPlugin($pluginName, false); // second arg? // trap php files which aren't WikiPlugin~s: wikiplugin + wikiplugin_cached only if (strtolower(substr(get_parent_class($p), 0, 10)) == 'wikiplugin') { $RetArray[] = short_string($pluginName); } } } return new xmlrpcresp(new xmlrpcval($RetArray, "array")); }
function CheckPgsrcUpdate() { // Check some theme specific pgsrc files (blog, wikilens, fusionforge, custom). // We check theme specific pgsrc first in case the page is present in both // theme specific and global pgsrc global $WikiTheme; $path = $WikiTheme->file("pgsrc"); // TBD: the call to fileSet prints a warning: // Notice: Unable to open directory 'themes/MonoBook/pgsrc' for reading $pgsrc = new fileSet($path); if ($pgsrc->getFiles()) { echo "<h3>", sprintf(_("Check for necessary theme %s updates"), "pgsrc"), "</h3>\n"; foreach ($pgsrc->getFiles() as $filename) { if (substr($filename, -1, 1) == '~') { continue; } if (substr($filename, -5, 5) == '.orig') { continue; } $pagename = urldecode($filename); $this->doPgsrcUpdate($pagename, $path, $filename); } } echo "<h3>", sprintf(_("Check for necessary %s updates"), "pgsrc"), "</h3>\n"; if ($this->db_version < 1030.12200612) { echo "<h4>", _("rename to Help: pages"), "</h4>\n"; } $path = FindLocalizedFile(WIKI_PGSRC); $pgsrc = new fileSet($path); // fixme: verification, ... foreach ($pgsrc->getFiles() as $filename) { if (substr($filename, -1, 1) == '~') { continue; } if (substr($filename, -5, 5) == '.orig') { continue; } $pagename = urldecode($filename); if (!isActionPage($filename)) { // There're a lot of now unneeded pages around. // At first rename the BlaPlugin pages to Help/<pagename> and then to the update. if ($this->db_version < 1030.12200612) { $this->_rename_to_help_page($pagename); } $this->doPgsrcUpdate($pagename, $path, $filename); } } }
function pluginPulldown() { global $WikiTheme; $plugin_dir = 'lib/plugin'; if (defined('PHPWIKI_DIR')) { $plugin_dir = PHPWIKI_DIR . "/{$plugin_dir}"; } $pd = new fileSet($plugin_dir, '*.php'); $plugins = $pd->getFiles(); unset($pd); sort($plugins); if (!empty($plugins)) { $plugin_js = ''; require_once "lib/WikiPlugin.php"; $w = new WikiPluginLoader(); foreach ($plugins as $plugin) { $pluginName = str_replace(".php", "", $plugin); $p = $w->getPlugin($pluginName, false); // second arg? // trap php files which aren't WikiPlugin~s if (strtolower(substr(get_parent_class($p), 0, 10)) == 'wikiplugin') { $plugin_args = ''; $desc = $p->getArgumentsDescription(); $src = array("\n", '"', "'", '|', '[', ']', '\\'); $replace = array('%0A', '%22', '%27', '%7C', '%5B', '%5D', '%5C'); $desc = str_replace("<br />", ' ', $desc->asXML()); if ($desc) { $plugin_args = '\\n' . str_replace($src, $replace, $desc); } $toinsert = "%0A<?plugin " . $pluginName . $plugin_args . "?>"; // args? $plugin_js .= ",['{$pluginName}','{$toinsert}']"; } } $plugin_js = substr($plugin_js, 1); $more_buttons = HTML::img(array('class' => "toolbar", 'src' => $WikiTheme->getImageURL("ed_plugins.png"), 'title' => _("AddPlugin"), 'alt' => _("AddPlugin"), 'onclick' => "showPulldown('" . _("Insert Plugin (double-click)") . "',[" . $plugin_js . "],'" . _("Insert") . "','" . _("Close") . "')")); return HTML("\n", $more_buttons); } return ''; }