request = &$request; $this->user = $request->getUser(); $this->page = $request->getPage(); $this->current = $this->page->getCurrentRevision(false); // HACKish short circuit to browse on action=create if ($request->getArg('action') == 'create') { if (! $this->current->hasDefaultContents()) $request->redirect(WikiURL($this->page->getName())); // noreturn } $this->meta = array('author' => $this->user->getId(), 'author_id' => $this->user->getAuthenticatedId(), 'mtime' => time()); $this->tokens = array(); $version = $request->getArg('version'); if ($version !== false) { $this->selected = $this->page->getRevision($version); $this->version = $version; } else { $this->version = $this->current->getVersion(); $this->selected = $this->page->getRevision($this->version); } if ($this->_restoreState()) { $this->_initialEdit = false; } else { $this->_initializeState(); $this->_initialEdit = true; // The edit request has specified some initial content from a template if ( ($template = $request->getArg('template')) and $request->_dbi->isWikiPage($template)) { $page = $request->_dbi->getPage($template); $current = $page->getCurrentRevision(); $this->_content = $current->getPackedContent(); } elseif ($initial_content = $request->getArg('initial_content')) { $this->_content = $initial_content; $this->_redirect_to = $request->getArg('save_and_redirect_to'); } } if (!headers_sent()) header("Content-Type: text/html; charset=" . $GLOBALS['charset']); } function editPage () { global $WikiTheme; $saveFailed = false; $tokens = &$this->tokens; if (! $this->canEdit()) { if ($this->isInitialEdit()) return $this->viewSource(); $tokens['PAGE_LOCKED_MESSAGE'] = $this->getLockedMessage(); } elseif ($this->request->getArg('save_and_redirect_to') != "") { if ($this->savePage()) { // noreturn $this->request->redirect(WikiURL($this->request->getArg('save_and_redirect_to'))); return true; // Page saved. } $saveFailed = true; } elseif ($this->editaction == 'save') { if ($this->savePage()) { return true; // Page saved. } $saveFailed = true; } if ($saveFailed || $this->isConcurrentUpdate()) { // Get the text of the original page, and the two conflicting edits // The diff3 class takes arrays as input. So retrieve content as // an array, or convert it as necesary. $orig = $this->page->getRevision($this->_currentVersion); // FIXME: what if _currentVersion has be deleted? $orig_content = $orig->getContent(); $this_content = explode("\n", $this->_content); $other_content = $this->current->getContent(); include_once("lib/diff3.php"); $diff = new diff3($orig_content, $this_content, $other_content); $output = $diff->merged_output(_("Your version"), _("Other version")); // Set the content of the textarea to the merged diff // output, and update the version $this->_content = implode ("\n", $output); $this->_currentVersion = $this->current->getVersion(); $this->version = $this->_currentVersion; $unresolved = $diff->ConflictingBlocks; $tokens['CONCURRENT_UPDATE_MESSAGE'] = $this->getConflictMessage($unresolved); } if ($this->editaction == 'preview') $tokens['PREVIEW_CONTENT'] = $this->getPreview(); // FIXME: convert to _MESSAGE? // FIXME: NOT_CURRENT_MESSAGE? $tokens = array_merge($tokens, $this->getFormElements()); //FIXME: enable Undo button for all other buttons also, not only the search/replace button if (defined('JS_SEARCHREPLACE') and JS_SEARCHREPLACE) { $tokens['JS_SEARCHREPLACE'] = 1; $undo_btn = $WikiTheme->getImageURL("ed_undo.gif"); $undo_d_btn = $WikiTheme->getImageURL("ed_undo_d.gif"); // JS_SEARCHREPLACE from walterzorn.de $WikiTheme->addMoreHeaders(Javascript(" var f, sr_undo, replacewin, undo_buffer=new Array(), undo_buffer_index=0; function define_f() { f=document.getElementById('editpage'); f.editarea=document.getElementById('edit[content]'); sr_undo=document.getElementById('sr_undo'); undo_enable(false); f.editarea.focus(); } function undo_enable(bool) { if (bool) { sr_undo.src='".$undo_btn."'; sr_undo.alt='" ._("Undo") ."'; sr_undo.disabled = false; } else { sr_undo.src='".$undo_d_btn."'; sr_undo.alt='" ._("Undo disabled") ."'; sr_undo.disabled = true; if(sr_undo.blur) sr_undo.blur(); } } function replace() { replacewin = window.open('','','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,height=90,width=450'); replacewin.window.document.write('" ._("Search & Replace") ."
'+'" ._("Search") .":
'+' " ._("Replace with") .":
   
'); replacewin.window.document.close(); return false; } function do_replace() { var txt=undo_buffer[undo_buffer_index]=f.editarea.value, ein=new RegExp(replacewin.document.forms[0].ein.value,'g'), aus=replacewin.document.forms[0].aus.value; if(ein==''||ein==null) { if (replacewin) replacewin.window.document.forms[0].ein.focus(); return; } var z_repl=txt.match(ein)? txt.match(ein).length : 0; txt=txt.replace(ein,aus); ein=ein.toString().substring(1,ein.toString().length-2); result(z_repl, 'Substring \"'+ein+'\" found '+z_repl+' times. Replace with \"'+aus+'\"?', txt, 'String \"'+ein+'\" not found.'); replacewin.window.focus(); replacewin.window.document.forms[0].ein.focus(); } function result(zahl,frage,txt,alert_txt) { if(zahl>0) { if(window.confirm(frage)==true) { f.editarea.value=txt; undo_buffer_index++; undo_enable(true); } } else alert(alert_txt); } function do_undo() { if(undo_buffer_index==0) return; else if(undo_buffer_index>0) { f.editarea.value=undo_buffer[undo_buffer_index-1]; undo_buffer[undo_buffer_index]=null; undo_buffer_index--; if(undo_buffer_index==0) { alert('Operation undone.'); undo_enable(false); } } } //save a snapshot in the undo buffer (unused) function speich() { undo_buffer[undo_buffer_index]=f.editarea.value; undo_buffer_index++; undo_enable(true); } ")); $WikiTheme->addMoreAttr('body'," onload='define_f()'"); } else { $WikiTheme->addMoreAttr('body',"document.getElementById('edit[content]').editarea.focus()"); } if (defined('ENABLE_EDIT_TOOLBAR') and ENABLE_EDIT_TOOLBAR) { $WikiTheme->addMoreHeaders(JavaScript('',array('src' => $WikiTheme->_findData("toolbar.js")))); $tokens['EDIT_TOOLBAR'] = $this->toolbar(); } else { $tokens['EDIT_TOOLBAR'] = ''; } return $this->output('editpage', _("Edit: %s")); } function toolbar () { global $WikiTheme; $toolarray = array( array( "image"=>"ed_format_bold.gif", "open"=>"*", "close"=>"*", "sample"=>_("Bold text"), "tip"=>_("Bold text")), array("image"=>"ed_format_italic.gif", "open"=>"_", "close"=>"_", "sample"=>_("Italic text"), "tip"=>_("Italic text")), array("image"=>"ed_pagelink.gif", "open"=>"[", "close"=>"]", "sample"=>_("optional label | PageName"), "tip"=>_("Link to page")), array("image"=>"ed_link.gif", "open"=>"[", "close"=>"]", "sample"=>_("optional label | http://www.example.com"), "tip"=>_("External link (remember http:// prefix)")), array("image"=>"ed_headline.gif", "open"=>"\\n!!! ", "close"=>"\\n", "sample"=>_("Headline text"), "tip"=>_("Level 1 headline")), array("image"=>"ed_image.gif", "open"=>"[ ", "close"=>" ]", "sample"=>_("Example.jpg"), "tip"=>_("Embedded image")), array("image"=>"ed_nowiki.gif", "open"=>"\\n\\\\n", "close"=>"\\n\\\\n", "sample"=>_("Insert non-formatted text here"), "tip"=>_("Ignore wiki formatting")), array("image"=>"ed_sig.gif", "open" => " --" . $GLOBALS['request']->_user->UserName(), "close" => "", "sample"=>"", "tip"=>_("Your signature")), array("image"=>"ed_hr.gif", "open"=>"\\n----\\n", "close"=>"", "sample"=>"", "tip"=>_("Horizontal line")) ); $toolbar = "document.writeln(\"
\");\n"; $btn = new SubmitImageButton(_("Save"), "edit[save]", 'toolbar', $WikiTheme->getImageURL("ed_save.gif")); $btn->addTooltip(_("Save")); $toolbar.='document.writeln("'.addslashes($btn->asXml()).'");'."\n"; $btn = new SubmitImageButton(_("Preview"), "edit[preview]", 'toolbar', $WikiTheme->getImageURL("ed_preview.gif")); $btn->addTooltip(_("Preview")); $toolbar.='document.writeln("'.addslashes($btn->asXml()).'");'."\n"; foreach ($toolarray as $tool) { $image = $WikiTheme->getImageURL($tool["image"]); $open = $tool["open"]; $close = $tool["close"]; $sample = addslashes( $tool["sample"] ); // Note that we use the tip both for the ALT tag and the TITLE tag of the image. // Older browsers show a "speedtip" type message only for ALT. // Ideally these should be different, realistically they // probably don't need to be. $tip = addslashes( $tool["tip"] ); $toolbar.="addButton('$image','$tip','$open','$close','$sample');\n"; } $toolbar.="addInfobox('" . addslashes( _("Click a button to get an example text") ) . "');\n"; if (defined('JS_SEARCHREPLACE') and JS_SEARCHREPLACE) { $undo_d_btn = $WikiTheme->getImageURL("ed_undo_d.gif"); //$redo_btn = $WikiTheme->getImageURL("ed_redo.gif"); $sr_btn = $WikiTheme->getImageURL("ed_replace.gif"); $sr_html = HTML(HTML::input(array('type' =>"image", 'class'=>"toolbar", 'id' =>"sr_undo", 'src' =>$undo_d_btn, 'title'=>_("Undo Search & Replace"), 'disabled'=>"disabled", 'value' =>"Undo", 'onfocus' =>"if(this.blur && undo_buffer_index==0) this.blur()", 'onclick' =>"do_undo()")), HTML::input(array('type' =>"image", 'class'=>"toolbar", 'src' => $sr_btn, 'title'=>_("Search & Replace"), 'onclick'=>"replace()"))); } else { $sr_html = ''; } // More: // Button to generate pagenames, display in extra window as pulldown and insert // Button to generate plugins, display in extra window as pulldown and insert // Button to generate categories, display in extra window as pulldown and insert $toolbar_end = "document.writeln(\"
\");"; // don't use document.write for replace, otherwise self.opener is not defined. if ($sr_html) return HTML(Javascript($toolbar), $sr_html, Javascript($toolbar_end)); else return HTML(Javascript($toolbar . $toolbar_end)); } function output ($template, $title_fs) { global $WikiTheme; $selected = &$this->selected; $current = &$this->current; if ($selected && $selected->getVersion() != $current->getVersion()) { $rev = $selected; $pagelink = WikiLink($selected); } else { $rev = $current; $pagelink = WikiLink($this->page); } $title = new FormattedText ($title_fs, $pagelink); if (USE_HTMLAREA and $template == 'editpage') { $WikiTheme->addMoreHeaders(Edit_HtmlArea_Head()); //$tokens['PAGE_SOURCE'] = Edit_HtmlArea_ConvertBefore($this->_content); } $template = Template($template, $this->tokens); GeneratePage($template, $title, $rev); return true; } function viewSource () { assert($this->isInitialEdit()); assert($this->selected); $this->tokens['PAGE_SOURCE'] = $this->_content; return $this->output('viewsource', _("View Source: %s")); } function updateLock() { if ((bool)$this->page->get('locked') == (bool)$this->locked) return false; // Not changed. if (!$this->user->isAdmin()) { // FIXME: some sort of message return false; // not allowed. } $this->page->set('locked', (bool)$this->locked); $this->tokens['LOCK_CHANGED_MSG'] = $this->locked ? _("Page now locked.") : _("Page now unlocked."); return true; // lock changed. } function savePage () { $request = &$this->request; if ($this->isUnchanged()) { // Allow admin lock/unlock even if // no text changes were made. if ($this->updateLock()) { $dbi = $request->getDbh(); $dbi->touch(); } // Save failed. No changes made. $this->_redirectToBrowsePage(); // user will probably not see the rest of this... include_once('lib/display.php'); // force browse of current version: $request->setArg('version', false); displayPage($request, 'nochanges'); return true; } $page = &$this->page; // Include any meta-data from original page version which // has not been explicitly updated. // (Except don't propagate pgsrc_version --- moot for now, // because at present it never gets into the db...) $meta = $this->selected->getMetaData(); unset($meta['pgsrc_version']); $meta = array_merge($meta, $this->meta); // Save new revision $this->_content = $this->getContent(); $newrevision = $page->save($this->_content, $this->_currentVersion + 1, $meta); if (!isa($newrevision, 'wikidb_pagerevision')) { // Save failed. (Concurrent updates). return false; } // New contents successfully saved... $this->updateLock(); // Clean out archived versions of this page. include_once('lib/ArchiveCleaner.php'); $cleaner = new ArchiveCleaner($GLOBALS['ExpireParams']); $cleaner->cleanPageRevisions($page); /* generate notification emails done in WikiDB::save to catch all direct calls (admin plugins) */ $dbi = $request->getDbh(); $warnings = $dbi->GenericWarnings(); $dbi->touch(); global $WikiTheme; if (empty($warnings) && ! $WikiTheme->getImageURL('signature')) { // Do redirect to browse page if no signature has // been defined. In this case, the user will most // likely not see the rest of the HTML we generate // (below). $this->_redirectToBrowsePage(); } // Force browse of current page version. $request->setArg('version', false); //$request->setArg('action', false); $template = Template('savepage', $this->tokens); $template->replace('CONTENT', $newrevision->getTransformedContent()); if (!empty($warnings)) $template->replace('WARNINGS', $warnings); $pagelink = WikiLink($page); GeneratePage($template, fmt("Saved: %s", $pagelink), $newrevision); return true; } function isConcurrentUpdate () { assert($this->current->getVersion() >= $this->_currentVersion); return $this->current->getVersion() != $this->_currentVersion; } function canEdit () { return !$this->page->get('locked') || $this->user->isAdmin(); } function isInitialEdit () { return $this->_initialEdit; } function isUnchanged () { $current = &$this->current; if ($this->meta['markup'] != $current->get('markup')) return false; return $this->_content == $current->getPackedContent(); } function getPreview () { include_once('lib/PageType.php'); $this->_content = $this->getContent(); return new TransformedText($this->page, $this->_content, $this->meta); } // possibly convert HTMLAREA content back to Wiki markup function getContent () { if (USE_HTMLAREA) { $xml_output = Edit_HtmlArea_ConvertAfter($this->_content); $this->_content = join("",$xml_output->_content); return $this->_content; } else { return $this->_content; } } function getLockedMessage () { return HTML(HTML::h2(_("Page Locked")), HTML::p(_("This page has been locked by the administrator so your changes can not be saved.")), HTML::p(_("(Copy your changes to the clipboard. You can try editing a different page or save your text in a text editor.)")), HTML::p(_("Sorry for the inconvenience."))); } function getConflictMessage ($unresolved = false) { /* xgettext only knows about c/c++ line-continuation strings it does not know about php's dot operator. We want to translate this entire paragraph as one string, of course. */ //$re_edit_link = Button('edit', _("Edit the new version"), $this->page); if ($unresolved) $message = HTML::p(fmt("Some of the changes could not automatically be combined. Please look for sections beginning with '%s', and ending with '%s'. You will need to edit those sections by hand before you click Save.", "<<<<<<< ". _("Your version"), ">>>>>>> ". _("Other version"))); else $message = HTML::p(_("Please check it through before saving.")); /*$steps = HTML::ol(HTML::li(_("Copy your changes to the clipboard or to another temporary place (e.g. text editor).")), HTML::li(fmt("%s of the page. You should now see the most current version of the page. Your changes are no longer there.", $re_edit_link)), HTML::li(_("Make changes to the file again. Paste your additions from the clipboard (or text editor).")), HTML::li(_("Save your updated changes."))); */ return HTML(HTML::h2(_("Conflicting Edits!")), HTML::p(_("In the time since you started editing this page, another user has saved a new version of it.")), HTML::p(_("Your changes can not be saved as they are, since doing so would overwrite the other author's changes. So, your changes and those of the other author have been combined. The result is shown below.")), $message); } function getTextArea () { $request = &$this->request; // wrap=virtual is not HTML4, but without it NS4 doesn't wrap // long lines $readonly = ! $this->canEdit(); // || $this->isConcurrentUpdate(); if (USE_HTMLAREA) { $html = $this->getPreview(); $this->_wikicontent = $this->_content; $this->_content = $html->asXML(); } /**