Example #1
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     extract($this->getArgs($argstr, $request));
     if (!$lang) {
         return $this->error(_("This internal action page cannot viewed.") . "\n" . _("You can only use it via the _WikiTranslation plugin."));
     }
     $this->lang = $lang;
     //action=save
     if (!empty($translate) and isset($translate['submit']) and $request->isPost()) {
         $trans = $translate["content"];
         if (empty($trans) or $trans == $pagename) {
             $header = HTML(HTML::h2(_("Translation Error!")), HTML::p(_("Your translated text is either empty or equal to the untranslated text. Please try again.")));
         } else {
             //save translation in a users subpage
             $user = $request->getUser();
             $homepage = $user->_HomePagehandle;
             $transpagename = $homepage->getName() . SUBPAGE_SEPARATOR . _("ContributedTranslations");
             $page = $dbi->getPage($transpagename);
             $current = $page->getCurrentRevision();
             $version = $current->getVersion();
             if ($version) {
                 $text = $current->getPackedContent() . "\n";
                 $meta = $current->_data;
             } else {
                 $text = '';
                 $meta = array('markup' => 2.0, 'author' => $user->getId());
             }
             $text .= $user->getId() . " " . Iso8601DateTime() . "\n" . "* " . sprintf(_("Translate '%s' to '%s' in *%s*"), $pagename, $trans, $lang);
             $text .= "\n  <verbatim>locale/po/{$lang}.po:\n  msgid \"" . $pagename . "\"\n  msgstr \"" . $trans . "\"\n  </verbatim>";
             $meta['summary'] = sprintf(_("Translate %s to %s in %s"), substr($pagename, 0, 15), substr($trans, 0, 15), $lang);
             $page->save($text, $version + 1, $meta);
             // TODO: admin notification
             return HTML(HTML::h2(_("Thanks for adding this translation!")), HTML::p(fmt("Your translated text doesn't yet appear in this %s, but the Administrator will pick it up and add to the installation.", WIKI_NAME)), fmt("Your translation is stored in %s", WikiLink($transpagename)));
         }
     }
     $trans = $this->translate($pagename, $lang, 'en');
     //Todo: google lookup or at least a google lookup button.
     if (isset($header)) {
         $header = HTML($header, fmt("From english to %s: ", HTML::strong($lang)));
     } else {
         $header = fmt("From english to %s: ", HTML::strong($lang));
     }
     $button_label = _("Translate");
     $buttons = HTML::p(Button('submit:translate[submit]', $button_label, 'wikiadmin'), Button('submit:translate[cancel]', _("Cancel"), 'button'));
     return HTML::form(array('action' => $request->getPostURL(), 'method' => 'post'), $header, HTML::textarea(array('class' => 'wikiedit', 'name' => 'translate[content]', 'id' => 'translate[content]', 'rows' => 4, 'cols' => $request->getPref('editWidth'), 'wrap' => 'virtual'), $trans), HiddenInputs($request->getArgs(), false, array('translate')), HiddenInputs(array('translate[action]' => $pagename, 'require_authority_for_post' => WIKIAUTH_BOGO)), $buttons);
 }
Example #2
0
 function format($changes)
 {
     global $request;
     include_once 'lib/RssWriter.php';
     $rss = new AtomFeed();
     // "channel" is called "feed" in atom
     $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
     extract($this->_args);
     $title = WIKI_NAME;
     $description = $this->title();
     if ($category) {
         $title = $category;
     } elseif ($pagematch) {
         $title = $pagematch;
     }
     $feed_props = array('title' => $description, 'link' => array('rel' => "alternate", 'type' => "text/html", 'href' => $rc_url), 'id' => md5($rc_url), 'modified' => Iso8601DateTime(time()), 'generator' => 'PhpWiki-' . PHPWIKI_VERSION, 'tagline' => '');
     $rss->feed($feed_props);
     $first = true;
     while ($rev = $changes->next()) {
         // enforce view permission
         if (mayAccessPage('view', $rev->_pagename)) {
             $props = $this->item_properties($rev);
             $rss->addItem($props, false, $this->pageURI($rev));
             if ($first) {
                 $this->setValidators($rev);
             }
             $first = false;
         }
     }
     $request->discardOutput();
     $rss->finish();
     //header("Content-Type: application/atom; charset=" . $GLOBALS['charset']);
     printf("\n<!-- Generated by PhpWiki-%s -->\n", PHPWIKI_VERSION);
     // Flush errors in comment, otherwise it's invalid XML.
     global $ErrorManager;
     if ($errors = $ErrorManager->getPostponedErrorsAsHTML()) {
         printf("\n<!-- PHP Warnings:\n%s-->\n", AsXML($errors));
     }
     $request->finish();
     // NORETURN!!!!
 }
Example #3
0
 function channel_properties()
 {
     global $request;
     $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
     return array('title' => WIKI_NAME, 'link' => $rc_url, 'description' => _("RecentChanges"), 'dc:date' => Iso8601DateTime(time()), 'dc:language' => $GLOBALS['LANG']);
     /* FIXME: other things one might like in <channel>:
      * sy:updateFrequency
      * sy:updatePeriod
      * sy:updateBase
      * dc:subject
      * dc:publisher
      * dc:language
      * dc:rights
      * rss091:language
      * rss091:managingEditor
      * rss091:webmaster
      * rss091:lastBuildDate
      * rss091:copyright
      */
 }
Example #4
0
 function _parseMap($text)
 {
     if (!preg_match_all("/^\\s*(\\S+)\\s+(.+)\$/m", $text, $matches, PREG_SET_ORDER)) {
         return false;
     }
     foreach ($matches as $m) {
         $map[$m[1]] = $m[2];
     }
     // Add virtual monikers Upload: Talk: User:
     // and expand special variables %u, %b, %d
     // Upload: Should be expanded later to user-specific upload dirs.
     // In the Upload plugin, not here: Upload:ReiniUrban/uploaded-file.png
     if (empty($map['Upload'])) {
         $map['Upload'] = getUploadDataPath();
     }
     // User:ReiniUrban => ReiniUrban or Users/ReiniUrban
     // Can be easily overriden by a customized InterWikiMap:
     //   User Users/%s
     if (empty($map["User"])) {
         $map["User"] = "******";
     }
     // Talk:PageName => PageName/Discussion as default, which might be overridden
     if (empty($map["Talk"])) {
         $pagename = $GLOBALS['request']->getArg('pagename');
         // against PageName/Discussion/Discussion
         if (string_ends_with($pagename, SUBPAGE_SEPARATOR . _("Discussion"))) {
             $map["Talk"] = "%s";
         } else {
             $map["Talk"] = "%s" . SUBPAGE_SEPARATOR . _("Discussion");
         }
     }
     foreach (array('Upload', 'User', 'Talk') as $special) {
         // Expand special variables:
         //   %u => username
         //   %b => wikibaseurl
         //   %d => iso8601 DateTime
         // %s is expanded later to the pagename
         if (strstr($map[$special], '%u')) {
             $map[$special] = str_replace($map[$special], '%u', $GLOBALS['request']->_user->_userid);
         }
         if (strstr($map[$special], '%b')) {
             $map[$special] = str_replace($map[$special], '%b', PHPWIKI_BASE_URL);
         }
         if (strstr($map[$special], '%d')) {
             $map[$special] = str_replace($map[$special], '%d', Iso8601DateTime());
         }
     }
     // Maybe add other monikers also - SemanticWeb link predicates
     // Should they be defined in a RDF? (strict mode)
     // Or should the SemanticWeb lib add it by itself?
     // (adding only a subset dependent on the context = model)
     return $map;
 }
Example #5
0
 /**
  * Send udiff for a changed page to multiple users.
  * See rename and remove methods also
  */
 function sendPageChangeNotification(&$wikitext, $version, &$meta)
 {
     global $request;
     if (@is_array($request->_deferredPageChangeNotification)) {
         // collapse multiple changes (loaddir) into one email
         $request->_deferredPageChangeNotification[] = array($this->pagename, $this->emails, $this->userids);
         return;
     }
     $backend =& $request->_dbi->_backend;
     $subject = _("Page change") . ' ' . $this->pagename;
     $previous = $backend->get_previous_version($this->pagename, $version);
     if (!isset($meta['mtime'])) {
         $meta['mtime'] = time();
     }
     if ($previous) {
         $difflink = WikiURL($this->pagename, array('action' => 'diff'), true);
         $cache =& $request->_dbi->_cache;
         $this_content = explode("\n", $wikitext);
         $prevdata = $cache->get_versiondata($this->pagename, $previous, true);
         if (empty($prevdata['%content'])) {
             $prevdata = $backend->get_versiondata($this->pagename, $previous, true);
         }
         $other_content = explode("\n", $prevdata['%content']);
         include_once "lib/difflib.php";
         $diff2 = new Diff($other_content, $this_content);
         //$context_lines = max(4, count($other_content) + 1,
         //                     count($this_content) + 1);
         $fmt = new UnifiedDiffFormatter();
         $content = $this->pagename . " " . $previous . " " . Iso8601DateTime($prevdata['mtime']) . "\n";
         $content .= $this->pagename . " " . $version . " " . Iso8601DateTime($meta['mtime']) . "\n";
         $content .= $fmt->format($diff2);
     } else {
         $difflink = WikiURL($this->pagename, array(), true);
         $content = $this->pagename . " " . $version . " " . Iso8601DateTime($meta['mtime']) . "\n";
         $content .= _("New page");
         $content .= "\n\n";
         $content .= $wikitext;
     }
     $editedby = sprintf(_("Edited by: %s"), $this->from);
     $summary = sprintf(_("Summary: %s"), $meta['summary']);
     $this->sendMail($subject, $editedby . "\n" . $summary . "\n" . $difflink . "\n\n" . $content);
 }
Example #6
0
 /**
  * Send udiff for a changed page to multiple users.
  * See rename and remove methods also
  */
 function sendPageChangeNotification(&$wikitext, $version, $meta, $emails, $userids)
 {
     global $request;
     if (@is_array($request->_deferredPageChangeNotification)) {
         // collapse multiple changes (loaddir) into one email
         $request->_deferredPageChangeNotification[] = array($this->_pagename, $emails, $userids);
         return;
     }
     $backend =& $this->_wikidb->_backend;
     //$backend = &$request->_dbi->_backend;
     $subject = _("Page change") . ' ' . $this->_pagename;
     $previous = $backend->get_previous_version($this->_pagename, $version);
     if (!isset($meta['mtime'])) {
         $meta['mtime'] = time();
     }
     if ($previous) {
         $difflink = WikiURL($this->_pagename, array('action' => 'diff'), true);
         $difflink .= "&versions%5b%5d=" . $previous . "&versions%5b%5d=" . $version;
         $cache =& $this->_wikidb->_cache;
         //$cache = &$request->_dbi->_cache;
         $this_content = explode("\n", $wikitext);
         $prevdata = $cache->get_versiondata($this->_pagename, $previous, true);
         if (empty($prevdata['%content'])) {
             $prevdata = $backend->get_versiondata($this->_pagename, $previous, true);
         }
         $other_content = explode("\n", $prevdata['%content']);
         include_once "lib/difflib.php";
         $diff2 = new Diff($other_content, $this_content);
         //$context_lines = max(4, count($other_content) + 1,
         //                     count($this_content) + 1);
         $fmt = new UnifiedDiffFormatter();
         $content = $this->_pagename . " " . $previous . " " . Iso8601DateTime($prevdata['mtime']) . "\n";
         $content .= $this->_pagename . " " . $version . " " . Iso8601DateTime($meta['mtime']) . "\n";
         $content .= $fmt->format($diff2);
     } else {
         $difflink = WikiURL($this->_pagename, array(), true);
         $content = $this->_pagename . " " . $version . " " . Iso8601DateTime($meta['mtime']) . "\n";
         $content .= _("New page");
     }
     // Codendi specific
     $from = user_getemail(user_getid());
     $body = $subject . "\n" . sprintf(_("Edited by: %s"), $from) . "\n" . $difflink;
     $m = new Mail();
     $m->setFrom($from);
     $m->setSubject("[" . WIKI_NAME . "] " . $subject);
     $m->setBcc(join(',', $emails));
     $m->setBody($body);
     if ($m->send()) {
         trigger_error(sprintf(_("PageChange Notification of %s sent to %s"), $this->_pagename, join(',', $userids)), E_USER_NOTICE);
     } else {
         trigger_error(sprintf(_("PageChange Notification Error: Couldn't send %s to %s"), $this->_pagename, join(',', $userids)), E_USER_WARNING);
     }
 }
Example #7
0
 function add(&$request, $blog, $type = 'wikiblog')
 {
     $parent = $blog['pagename'];
     if (empty($parent)) {
         $prefix = "";
         // allow empty parent for default "Blog/day"
         $parent = HOME_PAGE;
     } else {
         $prefix = $parent . SUBPAGE_SEPARATOR;
     }
     //$request->finish(fmt("No pagename specified for %s",$type));
     $now = time();
     $dbi = $request->getDbh();
     $user = $request->getUser();
     /*
      * Page^H^H^H^H Blog meta-data
      * This method is reused for all attachable pagetypes: wikiblog, comment and wikiforum
      *
      * This is info that won't change for each revision.
      * Nevertheless, it's now stored in the revision meta-data.
      * Several reasons:
      *  o It's more convenient to have all information required
      *    to render a page revision in the revision meta-data.
      *  o We can avoid a race condition, since version meta-data
      *    updates are atomic with the version creation.
      */
     $blog_meta = array('ctime' => $now, 'creator' => $user->getId(), 'creator_id' => $user->getAuthenticatedId());
     // Version meta-data
     $summary = trim($blog['summary']);
     $version_meta = array('author' => $blog_meta['creator'], 'author_id' => $blog_meta['creator_id'], 'markup' => 2.0, 'summary' => $summary ? $summary : _("New comment."), 'mtime' => $now, 'pagetype' => $type, $type => $blog_meta);
     if ($type == 'comment') {
         unset($version_meta['summary']);
     }
     // Comment body.
     $body = trim($blog['body']);
     $saved = false;
     while (!$saved) {
         // Generate the page name.  For now, we use the format:
         //   Rootname/Blog/2003-01-11/14:03:02+00:00
         // This gives us natural chronological order when sorted
         // alphabetically. "Rootname/" is optional.
         $time = Iso8601DateTime();
         if ($type == 'wikiblog') {
             $pagename = "Blog";
         } elseif ($type == 'comment') {
             $pagename = "Comment";
         } elseif ($type == 'wikiforum') {
             $pagename = substr($summary, 0, 12);
         }
         // Check intermediate pages. If not existing they should RedirectTo the parent page.
         // Maybe add the BlogArchives plugin instead for the new interim subpage.
         $redirected = $prefix . $pagename;
         if (!$dbi->isWikiPage($redirected)) {
             require_once 'lib/loadsave.php';
             $pageinfo = array('pagename' => $redirected, 'content' => '<?plugin RedirectTo page=' . $parent . ' ?>', 'pagedata' => array(), 'versiondata' => array('author' => $blog_meta['creator']));
             SavePage($request, $pageinfo, '', '');
         }
         $redirected = $prefix . $pagename . SUBPAGE_SEPARATOR . preg_replace("/T.*/", "", "{$time}");
         if (!$dbi->isWikiPage($redirected)) {
             require_once 'lib/loadsave.php';
             $pageinfo = array('pagename' => $redirected, 'content' => '<?plugin RedirectTo page=' . $parent . ' ?>', 'pagedata' => array(), 'versiondata' => array('author' => $blog_meta['creator']));
             SavePage($request, $pageinfo, '', '');
         }
         $p = $dbi->getPage($prefix . $pagename . SUBPAGE_SEPARATOR . str_replace("T", SUBPAGE_SEPARATOR, "{$time}"));
         $pr = $p->getCurrentRevision();
         // Version should be zero.  If not, page already exists
         // so increment timestamp and try again.
         if ($pr->getVersion() > 0) {
             $now++;
             continue;
         }
         // FIXME: there's a slight, but currently unimportant
         // race condition here.  If someone else happens to
         // have just created a blog with the same name,
         // we'll have locked it before we discover that the name
         // is taken.
         /*
          * FIXME:  For now all blogs are locked.  It would be
          * nice to allow only the 'creator' to edit by default.
          */
         $p->set('locked', true);
         //lock by default
         $saved = $p->save($body, 1, $version_meta);
         $now++;
     }
     $dbi->touch();
     $request->redirect($request->getURLtoSelf());
     // noreturn
     // FIXME: when submit a comment from preview mode,
     // adds the comment properly but jumps to browse mode.
     // Any way to jump back to preview mode???
 }
Example #8
0
 function channel_properties()
 {
     global $request;
     $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
     $title = sprintf(_("%s: %s"), WIKI_NAME, SplitPagename($this->_args['page']));
     return array('title' => $title, 'dc:description' => _("History of changes."), 'link' => $rc_url, 'dc:date' => Iso8601DateTime(time()));
 }
Example #9
0
 function _approval_form(&$request, $args, $moderation, $pass = '******')
 {
     $header = HTML::h3(_("Please approve or reject this request:"));
     $loader = new WikiPluginLoader();
     $BackendInfo = $loader->getPlugin("_BackendInfo");
     $table = HTML::table(array('border' => 1, 'cellpadding' => 2, 'cellspacing' => 0));
     $content = $table;
     $diff = '';
     if ($moderation['args']['action'] == 'edit') {
         $pagename = $moderation['args']['pagename'];
         $p = $request->_dbi->getPage($pagename);
         $rev = $p->getCurrentRevision(true);
         $curr_content = $rev->getPackedContent();
         $new_content = $moderation['args']['edit']['content'];
         include_once "lib/difflib.php";
         $diff2 = new Diff($curr_content, $new_content);
         $fmt = new UnifiedDiffFormatter();
         $diff = $pagename . " Current Version " . Iso8601DateTime($p->get('mtime')) . "\n";
         $diff .= $pagename . " Edited Version " . Iso8601DateTime($moderation['timestamp']) . "\n";
         $diff .= $fmt->format($diff2);
     }
     $content->pushContent($BackendInfo->_showhash("Request", array('User' => $moderation['userid'], 'When' => CTime($moderation['timestamp']), 'Pagename' => $pagename, 'Action' => $moderation['args']['action'], 'Diff' => HTML::pre($diff))));
     $content_dbg = $table;
     $myargs = $args;
     $BackendInfo->_fixupData($myargs);
     $content_dbg->pushContent($BackendInfo->_showhash("raw request args", $myargs));
     $BackendInfo->_fixupData($moderation);
     $content_dbg->pushContent($BackendInfo->_showhash("raw moderation data", $moderation));
     $reason = HTML::div(_("Reason: "), HTML::textarea(array('name' => 'reason')));
     $approve = Button('submit:ModeratedPage[approve]', _("Approve"), $pass == 'approve' ? 'wikiadmin' : 'button');
     $reject = Button('submit:ModeratedPage[reject]', _("Reject"), $pass == 'reject' ? 'wikiadmin' : 'button');
     $args['action'] = _("ModeratedPage");
     return HTML::form(array('action' => $request->getPostURL(), 'method' => 'post'), $header, $content, HTML::p(""), $content_dbg, $reason, ENABLE_PAGEPERM ? '' : HiddenInputs(array('require_authority_for_post' => WIKIAUTH_ADMIN)), HiddenInputs($args), $pass == 'approve' ? HTML::p($approve, $reject) : HTML::p($reject, $approve));
 }
Example #10
0
 /**
  * Send udiff for a changed page to multiple users.
  * See rename and remove methods also
  */
 function sendPageChangeNotification(&$wikitext, $version, $meta, $emails, $userids)
 {
     global $request;
     if (@is_array($request->_deferredPageChangeNotification)) {
         // collapse multiple changes (loaddir) into one email
         $request->_deferredPageChangeNotification[] = array($this->_pagename, $emails, $userids);
         return;
     }
     $backend =& $this->_wikidb->_backend;
     //$backend = &$request->_dbi->_backend;
     $subject = _("Page change") . ' ' . urlencode($this->_pagename);
     $previous = $backend->get_previous_version($this->_pagename, $version);
     if (!isset($meta['mtime'])) {
         $meta['mtime'] = time();
     }
     if ($previous) {
         $difflink = WikiURL($this->_pagename, array('action' => 'diff'), true);
         $cache =& $this->_wikidb->_cache;
         //$cache = &$request->_dbi->_cache;
         $this_content = explode("\n", $wikitext);
         $prevdata = $cache->get_versiondata($this->_pagename, $previous, true);
         if (empty($prevdata['%content'])) {
             $prevdata = $backend->get_versiondata($this->_pagename, $previous, true);
         }
         $other_content = explode("\n", $prevdata['%content']);
         include_once "lib/difflib.php";
         $diff2 = new Diff($other_content, $this_content);
         //$context_lines = max(4, count($other_content) + 1,
         //                     count($this_content) + 1);
         $fmt = new UnifiedDiffFormatter();
         $content = $this->_pagename . " " . $previous . " " . Iso8601DateTime($prevdata['mtime']) . "\n";
         $content .= $this->_pagename . " " . $version . " " . Iso8601DateTime($meta['mtime']) . "\n";
         $content .= $fmt->format($diff2);
     } else {
         $difflink = WikiURL($this->_pagename, array(), true);
         $content = $this->_pagename . " " . $version . " " . Iso8601DateTime($meta['mtime']) . "\n";
         $content .= _("New page");
     }
     $from = $request->_user->getId();
     $editedby = sprintf(_("Edited by: %s"), $from);
     $emails = join(',', $emails);
     $headers = "From: {$from} <nobody>\r\n" . "Bcc: {$emails}\r\n" . "MIME-Version: 1.0\r\n" . "Content-Type: text/plain; charset=" . CHARSET . "; format=flowed\r\n" . "Content-Transfer-Encoding: 8bit";
     if (mail("<undisclosed-recipients>", "[" . WIKI_NAME . "] " . $subject, $subject . "\n" . $editedby . "\n" . $difflink . "\n\n" . $content, $headers)) {
         trigger_error(sprintf(_("PageChange Notification of %s sent to %s"), $this->_pagename, join(',', $userids)), E_USER_NOTICE);
     } else {
         trigger_error(sprintf(_("PageChange Notification Error: Couldn't send %s to %s"), $this->_pagename, join(',', $userids)), E_USER_WARNING);
     }
 }