Changeset 756
- Timestamp:
- 10/16/2007 07:54:24 AM (3 years ago)
- Files:
-
- 1 modified
-
branches/1.1.6.4/handlers/page/edit.php (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/1.1.6.4/handlers/page/edit.php
r747 r756 6 6 * @subpackage Page 7 7 * @version $Id$ 8 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License8 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 9 9 * @filesource 10 10 * … … 13 13 * @author {@link http://wikkawiki.org/DotMG Mahefa Randimbisoa} (bugfixes) 14 14 * 15 * @uses Config::$edit_buttons_position 16 * @uses Config::$require_edit_note 17 * @uses Config::$gui_editor 18 * @uses Wakka::ClearLinkTable() 19 * @uses Wakka::Footer() 20 * @uses Wakka::Format() 21 * @uses Wakka::FormClose() 22 * @uses Wakka::FormOpen() 23 * @uses Wakka::GetUser() 24 * @uses Wakka::GetUserName() 25 * @uses Wakka::HasAccess() 26 * @uses Wakka::Header() 27 * @uses Wakka::Href() 28 * @uses Wakka::htmlspecialchars_ent() 29 * @uses Wakka::hsc_secure() 30 * @uses Wakka::LoadSingle() 31 * @uses Wakka::Redirect() 32 * @uses Wakka::SavePage() 33 * @uses Wakka::StartLinkTracking() 34 * @uses Wakka::StopLinkTracking() 35 * @uses Wakka::WriteLinkTable() 36 * 37 * @todo move main <div> to templating class; 38 * @todo optimization using history.back(); 39 * @todo use central regex library for validation; 15 * @uses Config::$edit_buttons_position 16 * @uses Config::$require_edit_note 17 * @uses Config::$gui_editor 18 * @uses Wakka::ClearLinkTable() 19 * @uses Wakka::Footer() 20 * @uses Wakka::Format() 21 * @uses Wakka::FormClose() 22 * @uses Wakka::FormOpen() 23 * @uses Wakka::GetUser() 24 * @uses Wakka::GetUserName() 25 * @uses Wakka::HasAccess() 26 * @uses Wakka::Header() 27 * @uses Wakka::Href() 28 * @uses Wakka::htmlspecialchars_ent() 29 * @uses Wakka::hsc_secure() 30 * @uses Wakka::LoadSingle() 31 * @uses Wakka::Redirect() 32 * @uses Wakka::SavePage() 33 * @uses Wakka::StartLinkTracking() 34 * @uses Wakka::StopLinkTracking() 35 * @uses Wakka::WriteLinkTable() 36 * 37 * @todo optimization using history.back(); 38 * @todo use central regex library for validation; 40 39 * @todo replace $_REQUEST with either $_GET or $_POST (or both if really 41 40 * necessary) - #312 => NOT CLEAR here what to do; see also #449 42 41 */ 43 42 43 /**#@+ 44 * Default value. 45 */ 46 if (!defined('VALID_PAGENAME_PATTERN')) define ('VALID_PAGENAME_PATTERN', '/^[A-Za-zÄÖÜßäöü]+[A-Za-z0-9ÄÖÜßäöü]*$/s'); //TODO use central regex library 47 if (!defined('MAX_TAG_LENGTH')) define ('MAX_TAG_LENGTH', 75); 48 if (!defined('MAX_EDIT_NOTE_LENGTH')) define ('MAX_EDIT_NOTE_LENGTH', 50); 44 49 /** 45 * Defaults 46 */ 47 if(!defined('VALID_PAGENAME_PATTERN')) define ('VALID_PAGENAME_PATTERN', '/^[A-Za-zÄÖÜßäöü]+[A-Za-z0-9ÄÖÜßäöü]*$/s'); 48 if(!defined('MAX_TAG_LENGTH')) define ('MAX_TAG_LENGTH', 75); 49 if(!defined('MAX_EDIT_NOTE_LENGTH')) define ('MAX_EDIT_NOTE_LENGTH', 50); 50 51 /** 52 * i18n 53 */ 54 if(!defined('PREVIEW_HEADER')) define('PREVIEW_HEADER', 'Preview'); 55 if(!defined('LABEL_EDIT_NOTE')) define('LABEL_EDIT_NOTE', 'Please add a note on your edit'); 50 * Class attribute to enable styling as error. 51 */ 56 52 if (!defined('INPUT_ERROR_STYLE')) define('INPUT_ERROR_STYLE', 'class="highlight"'); 57 if(!defined('ERROR_INVALID_PAGENAME')) define('ERROR_INVALID_PAGENAME', 'This page name is invalid. Valid page names must start with a letter and contain only letters and numbers.'); 58 if(!defined('ERROR_OVERWRITE_ALERT')) define('ERROR_OVERWRITE_ALERT', 'OVERWRITE ALERT: This page was modified by someone else while you were editing it.<br /> Please copy your changes and re-edit this page.'); 59 if(!defined('ERROR_MISSING_EDIT_NOTE')) define('ERROR_MISSING_EDIT_NOTE', 'MISSING EDIT NOTE: Please fill in an edit note!'); 60 if(!defined('ERROR_TAG_TOO_LONG')) define('ERROR_TAG_TOO_LONG', 'Tag too long! %d characters max.'); 61 if(!defined('ERROR_NO_WRITE_ACCESS')) define('ERROR_NO_WRITE_ACCESS', 'You don\'t have write access to this page. You might need to register an account to be able to edit this page.'); 62 if(!defined('MESSAGE_AUTO_RESIZE')) define('MESSAGE_AUTO_RESIZE', 'Clicking on %s will automatically truncate the tag to the correct size'); 63 if(!defined('INPUT_SUBMIT_PREVIEW')) define('INPUT_SUBMIT_PREVIEW', 'Preview'); 64 if(!defined('INPUT_SUBMIT_STORE')) define('INPUT_SUBMIT_STORE', 'Store'); 65 if(!defined('INPUT_SUBMIT_REEDIT')) define('INPUT_SUBMIT_REEDIT', 'Re-edit'); 66 if(!defined('INPUT_BUTTON_CANCEL')) define('INPUT_BUTTON_CANCEL', 'Cancel'); 67 if(!defined('INPUT_SUBMIT_RENAME')) define('INPUT_SUBMIT_RENAME', 'Rename'); 68 if(!defined('ACCESSKEY_STORE')) define('ACCESSKEY_STORE', 's'); 69 if(!defined('ACCESSKEY_REEDIT')) define('ACCESSKEY_REEDIT', 'r'); 70 if(!defined('ACCESSKEY_PREVIEW')) define('ACCESSKEY_PREVIEW', 'p'); 71 if(!defined('SHOWCODE_LINK')) define('SHOWCODE_LINK', 'View formatting code for this page'); 72 if(!defined('SHOWCODE_LINK_TITLE')) define('SHOWCODE_LINK_TITLE', 'Click to view page formatting code'); 53 /**#@-*/ 54 55 /**#@+ 56 * Internationalization (i18n). 57 */ 58 if (!defined('PREVIEW_HEADER')) define('PREVIEW_HEADER', 'Preview'); 59 if (!defined('LABEL_EDIT_NOTE')) define('LABEL_EDIT_NOTE', 'Please add a note on your edit'); 60 if (!defined('ERROR_INVALID_PAGENAME')) define('ERROR_INVALID_PAGENAME', 'This page name is invalid. Valid page names must start with a letter and contain only letters and numbers.'); 61 if (!defined('ERROR_OVERWRITE_ALERT')) define('ERROR_OVERWRITE_ALERT', 'OVERWRITE ALERT: This page was modified by someone else while you were editing it.<br /> Please copy your changes and re-edit this page.'); 62 if (!defined('ERROR_MISSING_EDIT_NOTE')) define('ERROR_MISSING_EDIT_NOTE', 'MISSING EDIT NOTE: Please fill in an edit note!'); 63 if (!defined('ERROR_TAG_TOO_LONG')) define('ERROR_TAG_TOO_LONG', 'Tag too long! %d characters max.'); 64 if (!defined('ERROR_NO_WRITE_ACCESS')) define('ERROR_NO_WRITE_ACCESS', 'You don\'t have write access to this page. You might need to register an account to be able to edit this page.'); 65 if (!defined('MESSAGE_AUTO_RESIZE')) define('MESSAGE_AUTO_RESIZE', 'Clicking on %s will automatically truncate the tag to the correct size'); 66 if (!defined('INPUT_SUBMIT_PREVIEW')) define('INPUT_SUBMIT_PREVIEW', 'Preview'); 67 if (!defined('INPUT_SUBMIT_STORE')) define('INPUT_SUBMIT_STORE', 'Store'); 68 if (!defined('INPUT_SUBMIT_REEDIT')) define('INPUT_SUBMIT_REEDIT', 'Re-edit'); 69 if (!defined('INPUT_BUTTON_CANCEL')) define('INPUT_BUTTON_CANCEL', 'Cancel'); 70 if (!defined('INPUT_SUBMIT_RENAME')) define('INPUT_SUBMIT_RENAME', 'Rename'); 71 if (!defined('ACCESSKEY_STORE')) define('ACCESSKEY_STORE', 's'); 72 if (!defined('ACCESSKEY_REEDIT')) define('ACCESSKEY_REEDIT', 'r'); 73 if (!defined('ACCESSKEY_PREVIEW')) define('ACCESSKEY_PREVIEW', 'p'); 74 if (!defined('SHOWCODE_LINK')) define('SHOWCODE_LINK', 'View formatting code for this page'); 75 if (!defined('SHOWCODE_LINK_TITLE')) define('SHOWCODE_LINK_TITLE', 'Click to view page formatting code'); 76 /**#@-*/ 73 77 74 78 //initialization 75 79 $error = ''; 76 80 $highlight_note = ''; 81 $note = ''; 77 82 $ondblclick = ''; //#123 78 83 if (isset($_POST['submit']) && ($_POST['submit'] == 'Preview') && ($user = $this->GetUser()) && ($user['doubleclickedit'] != 'N')) … … 92 97 { 93 98 $newtag = $output = ''; 94 if (isset($_POST['newtag'])) $newtag = $_POST['newtag']; 95 if ($newtag !== '') $this->Redirect($this->Href('edit', $newtag)); 96 99 // rename action 100 if (isset($_POST['newtag'])) 101 { 102 $newtag = $_POST['newtag']; 103 if ($newtag !== '') $this->Redirect($this->Href('edit', $newtag)); 104 } 97 105 if ($_POST) 98 106 { 99 107 // strip CRLF line endings down to LF to achieve consistency ... plus it saves database space. 100 // Note: these codes must remain enclosed in double-quotes to work! 108 // Note: these codes must remain enclosed in double-quotes to work! -- JsnX 101 109 $body = str_replace("\r\n", "\n", $_POST['body']); 102 103 $body = preg_replace("/\n[ ]{4}/", "\n\t", $body); // @@@ FIXME: misses first line and multiple sets of four spaces 104 110 // replace each 4 consecutive spaces at the start of a line with a tab 111 #$body = preg_replace("/\n[ ]{4}/", "\n\t", $body); # @@@ FIXME: misses first line and multiple sets of four spaces - JW 2005-01-16 112 # JW FIXED 2005-07-12 113 $pattern = '/^(\t*) {4}/m'; # m modifier: match ^ at start of line *and* at start of string; 114 $replace = "$1\t"; 115 while (preg_match($pattern,$body)) 116 { 117 $body = preg_replace($pattern,$replace,$body); 118 } 105 119 // we don't need to escape here, we do that just before display (i.e., treat note just like body!) 106 $note = trim($_POST['note']); 107 120 if (isset($_POST['note'])) 121 { 122 $note = trim($_POST['note']); 123 } 108 124 // only if saving: 109 125 if ($_POST['submit'] == 'Store') … … 117 133 } 118 134 } 119 // check for edit note 135 // check for edit note if required 120 136 if (($this->config['require_edit_note'] == 1) && $_POST['note'] == '') 121 137 { … … 153 169 if (isset($_POST['previous'])) $previous = $_POST['previous']; 154 170 if (!isset($body)) $body = $this->page['body']; 155 $body = preg_replace("/\n[ ]{4}/", "\n\t", $body); // @@@ FIXME: misses first line and multiple sets of four spaces - JW 2005-01-16 156 157 171 // replace each 4 consecutive spaces at the start of a line with a tab 172 #$body = preg_replace("/\n[ ]{4}/", "\n\t", $body); # @@@ FIXME: misses first line and multiple sets of four spaces - JW 2005-01-16 173 # JW FIXED 2005-07-12 174 $pattern = '/^(\t*) {4}/m'; # m modifier: match ^ at start of line *and* at start of string; 175 $replace = "$1\t"; 176 while (preg_match($pattern,$body)) 177 { 178 $body = preg_replace($pattern,$replace,$body); 179 } 180 181 // derive maximum length for a page name from the table structure if possible 158 182 if ($result = mysql_query("describe ".$this->config['table_prefix']."pages tag")) { 159 183 $field = mysql_fetch_assoc($result); … … 170 194 $preview_buttons = '<hr />'."\n"; 171 195 // We need to escape ALL entity refs before display so we display them _as_ entities instead of interpreting them 172 // so we use h tmlspecialcharson the edit note (as on the body)196 // so we use hsc_secure() on the edit note (as on the body) 173 197 if ($this->config['require_edit_note'] != 2) //check if edit_notes are enabled 174 198 { … … 187 211 '<input type="hidden" name="previous" value="'.$previous.'" />'."\n". 188 212 // We need to escape ALL entity refs before display so we display them _as_ entities instead of interpreting them 189 // hence h tmlspecialchars() instead of htmlspecialchars_ent() which UNescapes entities!213 // hence hsc_secure() instead of htmlspecialchars_ent() which UNescapes entities! 190 214 // JW/2007-02-20: why is this? wouldn't it be easier for the person editing to show actual characters instead of entities? 191 215 '<input type="hidden" name="body" value="'.$this->hsc_secure($body).'" />'."\n"; #427 … … 197 221 elseif (!$this->page && strlen($this->tag) > $maxtaglen) 198 222 { 199 $this->tag = substr($this->tag, 0, $maxtaglen); // truncate tag to feed a backlinks-handler with the correct value. may be omitted. it only works if the link to a backlinks-handler is built in the footer. 223 // truncate tag to feed a backlinks-handler with the correct value. may be omited. it only works if the link to a backlinks-handler is built in the footer. 224 $this->tag = substr($this->tag, 0, $maxtaglen); 200 225 $output = '<em class="error">'.sprintf(ERROR_TAG_TOO_LONG, $maxtaglen).'</em><br />'."\n"; 201 226 $output .= sprintf(MESSAGE_AUTO_RESIZE, INPUT_SUBMIT_RENAME).'<br /><br />'."\n"; … … 209 234 { 210 235 // display form 211 if ( $error)236 if (!empty($error)) 212 237 { 213 238 $output .= '<em class="error">'.$error.'</em>'."\n"; … … 231 256 // add Edit note 232 257 // We need to escape ALL entity refs before display so we display them _as_ entities instead of interpreting them 233 // so we use h tmlspecialcharson the edit note (as on the body)258 // so we use hsc_secure on the edit note (as on the body) 234 259 if ($this->config['require_edit_note'] != 2) //check if edit_notes are enabled 235 260 { … … 252 277 else 253 278 { 254 $message = '<em>'.ERROR_NO_WRITE_ACCESS.'</em><br />'."\n".279 $message = '<em>'.ERROR_NO_WRITE_ACCESS.'</em><br />'."\n". 255 280 "<br />\n". 256 281 '<a href="'.$this->Href('showcode').'" title="'.SHOWCODE_LINK_TITLE.'">'.SHOWCODE_LINK.'</a>'.