Changeset 756

Show
Ignore:
Timestamp:
10/16/2007 07:54:24 AM (3 years ago)
Author:
JavaWoman
Message:

Important change:

  • fix for conversion of leading spaces to tabs (did not work at start of document); copied from online version

This change may need to be migrated to trunk; possibly some refinement possible, but at least this works.

Other changes:

  • fixes for notices
  • cleanup for coding guidelines
  • Unix line endings
  • updates in comments and docblock
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/1.1.6.4/handlers/page/edit.php

    r747 r756  
    66 * @subpackage  Page 
    77 * @version             $Id$ 
    8  * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 
     8 * @license             http://www.gnu.org/copyleft/gpl.html GNU General Public License 
    99 * @filesource 
    1010 * 
     
    1313 * @author              {@link http://wikkawiki.org/DotMG Mahefa Randimbisoa} (bugfixes) 
    1414 * 
    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; 
    4039 * @todo        replace $_REQUEST with either $_GET or $_POST (or both if really 
    4140 *                      necessary) - #312 => NOT CLEAR here what to do; see also #449 
    4241 */ 
    4342 
     43/**#@+ 
     44 * Default value. 
     45 */ 
     46if (!defined('VALID_PAGENAME_PATTERN')) define ('VALID_PAGENAME_PATTERN', '/^[A-Za-zÄÖÜßäöü]+[A-Za-z0-9ÄÖÜßäöü]*$/s'); //TODO use central regex library 
     47if (!defined('MAX_TAG_LENGTH')) define ('MAX_TAG_LENGTH', 75); 
     48if (!defined('MAX_EDIT_NOTE_LENGTH')) define ('MAX_EDIT_NOTE_LENGTH', 50); 
    4449/** 
    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 */ 
    5652if (!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 */ 
     58if (!defined('PREVIEW_HEADER')) define('PREVIEW_HEADER', 'Preview'); 
     59if (!defined('LABEL_EDIT_NOTE')) define('LABEL_EDIT_NOTE', 'Please add a note on your edit'); 
     60if (!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.'); 
     61if (!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.'); 
     62if (!defined('ERROR_MISSING_EDIT_NOTE')) define('ERROR_MISSING_EDIT_NOTE', 'MISSING EDIT NOTE: Please fill in an edit note!'); 
     63if (!defined('ERROR_TAG_TOO_LONG')) define('ERROR_TAG_TOO_LONG', 'Tag too long! %d characters max.'); 
     64if (!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.'); 
     65if (!defined('MESSAGE_AUTO_RESIZE')) define('MESSAGE_AUTO_RESIZE', 'Clicking on %s will automatically truncate the tag to the correct size'); 
     66if (!defined('INPUT_SUBMIT_PREVIEW')) define('INPUT_SUBMIT_PREVIEW', 'Preview'); 
     67if (!defined('INPUT_SUBMIT_STORE')) define('INPUT_SUBMIT_STORE', 'Store'); 
     68if (!defined('INPUT_SUBMIT_REEDIT')) define('INPUT_SUBMIT_REEDIT', 'Re-edit'); 
     69if (!defined('INPUT_BUTTON_CANCEL')) define('INPUT_BUTTON_CANCEL', 'Cancel'); 
     70if (!defined('INPUT_SUBMIT_RENAME')) define('INPUT_SUBMIT_RENAME', 'Rename'); 
     71if (!defined('ACCESSKEY_STORE')) define('ACCESSKEY_STORE', 's'); 
     72if (!defined('ACCESSKEY_REEDIT')) define('ACCESSKEY_REEDIT', 'r'); 
     73if (!defined('ACCESSKEY_PREVIEW')) define('ACCESSKEY_PREVIEW', 'p'); 
     74if (!defined('SHOWCODE_LINK')) define('SHOWCODE_LINK', 'View formatting code for this page'); 
     75if (!defined('SHOWCODE_LINK_TITLE')) define('SHOWCODE_LINK_TITLE', 'Click to view page formatting code'); 
     76/**#@-*/ 
    7377 
    7478//initialization 
    7579$error = ''; 
    7680$highlight_note = ''; 
     81$note = ''; 
    7782$ondblclick = ''; //#123 
    7883if (isset($_POST['submit']) && ($_POST['submit'] == 'Preview') && ($user = $this->GetUser()) && ($user['doubleclickedit'] != 'N')) 
     
    9297{ 
    9398        $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        } 
    97105        if ($_POST) 
    98106        { 
    99107                // 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 
    101109                $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                } 
    105119                // 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                } 
    108124                // only if saving: 
    109125                if ($_POST['submit'] == 'Store') 
     
    117133                                } 
    118134                        } 
    119                         // check for edit note 
     135                        // check for edit note if required 
    120136                        if (($this->config['require_edit_note'] == 1) && $_POST['note'] == '') 
    121137                        { 
     
    153169        if (isset($_POST['previous'])) $previous = $_POST['previous']; 
    154170        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 
    158182        if ($result = mysql_query("describe ".$this->config['table_prefix']."pages tag")) { 
    159183                $field = mysql_fetch_assoc($result); 
     
    170194                $preview_buttons = '<hr />'."\n"; 
    171195                // We need to escape ALL entity refs before display so we display them _as_ entities instead of interpreting them 
    172                 // so we use htmlspecialchars on the edit note (as on the body) 
     196                // so we use hsc_secure() on the edit note (as on the body) 
    173197                if ($this->config['require_edit_note'] != 2) //check if edit_notes are enabled 
    174198                { 
     
    187211                        '<input type="hidden" name="previous" value="'.$previous.'" />'."\n". 
    188212                        // We need to escape ALL entity refs before display so we display them _as_ entities instead of interpreting them 
    189                         // hence htmlspecialchars() instead of htmlspecialchars_ent() which UNescapes entities! 
     213                        // hence hsc_secure() instead of htmlspecialchars_ent() which UNescapes entities! 
    190214                        // JW/2007-02-20: why is this? wouldn't it be  easier for the person editing to show actual characters instead of entities? 
    191215                        '<input type="hidden" name="body" value="'.$this->hsc_secure($body).'" />'."\n";        #427 
     
    197221        elseif (!$this->page && strlen($this->tag) > $maxtaglen) 
    198222        { 
    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); 
    200225                $output  = '<em class="error">'.sprintf(ERROR_TAG_TOO_LONG, $maxtaglen).'</em><br />'."\n"; 
    201226                $output .= sprintf(MESSAGE_AUTO_RESIZE, INPUT_SUBMIT_RENAME).'<br /><br />'."\n"; 
     
    209234        { 
    210235                // display form 
    211                 if ($error) 
     236                if (!empty($error)) 
    212237                { 
    213238                        $output .= '<em class="error">'.$error.'</em>'."\n"; 
     
    231256                // add Edit note 
    232257                // We need to escape ALL entity refs before display so we display them _as_ entities instead of interpreting them 
    233                 // so we use htmlspecialchars on the edit note (as on the body) 
     258                // so we use hsc_secure on the edit note (as on the body) 
    234259                if ($this->config['require_edit_note'] != 2) //check if edit_notes are enabled 
    235260                { 
     
    252277else 
    253278{ 
    254         $message =      '<em>'.ERROR_NO_WRITE_ACCESS.'</em><br />'."\n". 
     279        $message = '<em>'.ERROR_NO_WRITE_ACCESS.'</em><br />'."\n". 
    255280                        "<br />\n". 
    256281                        '<a href="'.$this->Href('showcode').'" title="'.SHOWCODE_LINK_TITLE.'">'.SHOWCODE_LINK.'</a>'.