# HG changeset patch # User Dan # Date 1182905324 14400 # Node ID d0314575e2f0ddf837a4f3f46166c914d84cae98 # Parent 663fcf5287266b13d61f55b913c5f351135dd665 More preliminary l10n work; userpage portal style basics implemented diff -r 663fcf528726 -r d0314575e2f0 TODO --- a/TODO Tue Jun 26 17:28:18 2007 -0400 +++ b/TODO Tue Jun 26 20:48:44 2007 -0400 @@ -17,7 +17,7 @@ [x] Possibly add these fields: AIM, Yahoo, MSN, XMPP messenger icons, then homepage, location, occupation, hobbies, allow public e-mail display [ ] Put it in a user_extra table and have an option to enable or disable these fields in the admin panel [Y] Delay until RC3 or Banshee? - [ ] When added, put a box on the user page that shows the information + [x] When added, put a box on the user page that shows the information [x] Fix "this page" bug in ACL editor [x] The problem itself got fixed BUT there seem to be deeper problems related to scope selection This needs to be FIXED and WORKING PERFECTLY in Banshee! diff -r 663fcf528726 -r d0314575e2f0 ajax.php --- a/ajax.php Tue Jun 26 17:28:18 2007 -0400 +++ b/ajax.php Tue Jun 26 20:48:44 2007 -0400 @@ -123,6 +123,10 @@ $c = 0; $u = Array(); $n = Array(); + + $name = sanitize_page_id($name); + $name = str_replace('_', ' ', $name); + for($i=0;$ipages)/2;$i++) { if( ( diff -r 663fcf528726 -r d0314575e2f0 includes/clientside/static/dropdown.js --- a/includes/clientside/static/dropdown.js Tue Jun 26 17:28:18 2007 -0400 +++ b/includes/clientside/static/dropdown.js Tue Jun 26 20:48:44 2007 -0400 @@ -191,7 +191,14 @@ { a.className = ''; - slideIn(ul); + if ( jBox_slide_enable ) + { + slideIn(ul); + } + else + { + ul.style.display = 'none'; + } } diff -r 663fcf528726 -r d0314575e2f0 includes/functions.php --- a/includes/functions.php Tue Jun 26 17:28:18 2007 -0400 +++ b/includes/functions.php Tue Jun 26 20:48:44 2007 -0400 @@ -11,63 +11,148 @@ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. */ - -function getConfig($n) { + +/** + * Fetch a value from the site configuration. + * @param string The identifier of the value ("site_name" etc.) + * @return string Configuration value, or bool(false) if the value is not set + */ + +function getConfig($n) +{ global $enano_config; - if(isset($enano_config[$n])) return $enano_config[$n]; - else return false; + if ( isset( $enano_config[ $n ] ) ) + { + return $enano_config[$n]; + } + else + { + return false; + } } -function setConfig($n, $v) { +/** + * Update or change a configuration value. + * @param string The identifier of the value ("site_name" etc.) + * @param string The new value + * @return null + */ + +function setConfig($n, $v) +{ + global $enano_config, $db; $enano_config[$n] = $v; $v = $db->escape($v); - $e=$db->sql_query('DELETE FROM '.table_prefix.'config WHERE config_name=\''.$n.'\';'); - if(!$e) $db->_die('Error during generic setConfig() call row deletion.'); - $e=$db->sql_query('INSERT INTO '.table_prefix.'config(config_name, config_value) VALUES(\''.$n.'\', \''.$v.'\')'); - if(!$e) $db->_die('Error during generic setConfig() call row insertion.'); + + $e = $db->sql_query('DELETE FROM '.table_prefix.'config WHERE config_name=\''.$n.'\';'); + if ( !$e ) + { + $db->_die('Error during generic setConfig() call row deletion.'); + } + + $e = $db->sql_query('INSERT INTO '.table_prefix.'config(config_name, config_value) VALUES(\''.$n.'\', \''.$v.'\')'); + if ( !$e ) + { + $db->_die('Error during generic setConfig() call row insertion.'); + } } +/** + * Create a URI for an internal link. + * @param string The full identifier of the page to link to (Special:Administration) + * @param string The GET query string to append + * @param bool If true, perform htmlspecialchars() on the return value to make it HTML-safe + * @return string + */ + function makeUrl($t, $query = false, $escape = false) { global $db, $session, $paths, $template, $plugins; // Common objects $flags = ''; $sep = urlSeparator; - if(isset($_GET['printable'])) { $flags .= $sep.'printable'; $sep = '&'; } - if(isset($_GET['theme'])) { $flags .= $sep.'theme='.$session->theme; $sep = '&'; } - if(isset($_GET['style'])) { $flags .= $sep.'style='.$session->style; $sep = '&'; } + if ( isset($_GET['printable'] ) ) + { + $flags .= $sep . 'printable=yes'; + $sep = '&'; + } + if ( isset($_GET['theme'] ) ) + { + $flags .= $sep . 'theme='.$session->theme; + $sep = '&'; + } + if ( isset($_GET['style'] ) ) { + $flags .= $sep . 'style='.$session->style; + $sep = '&'; + } + $url = $session->append_sid(contentPath.$t.$flags); if($query) { $sep = strstr($url, '?') ? '&' : '?'; $url = $url . $sep . $query; } + return ($escape) ? htmlspecialchars($url) : $url; } +/** + * Create a URI for an internal link, and be namespace-friendly. Watch out for this one because it's different from most other Enano functions, in that the namespace is the first parameter. + * @param string The namespace ID + * @param string The page ID + * @param string The GET query string to append + * @param bool If true, perform htmlspecialchars() on the return value to make it HTML-safe + * @return string + */ + function makeUrlNS($n, $t, $query = false, $escape = false) { global $db, $session, $paths, $template, $plugins; // Common objects $flags = ''; - if(defined('ENANO_BASE_CLASSES_INITIALIZED')) $sep = urlSeparator; - else $sep = (strstr($_SERVER['REQUEST_URI'], '?')) ? '&' : '?'; - if(isset($_GET['printable'])) { $flags .= $sep.'printable'; $sep = '&'; } - if(isset($_GET['theme'])) { $flags .= $sep.'theme='.$session->theme; $sep = '&'; } - if(isset($_GET['style'])) { $flags .= $sep.'style='.$session->style; $sep = '&'; } if(defined('ENANO_BASE_CLASSES_INITIALIZED')) { - $url = contentPath.$paths->nslist[$n].$t.$flags; + $sep = urlSeparator; } else { - $url = contentPath.$n.':'.$t.$flags; + $sep = (strstr($_SERVER['REQUEST_URI'], '?')) ? '&' : '?'; + } + if ( isset( $_GET['printable'] ) ) { + $flags .= $sep . 'printable'; + $sep = '&'; + } + if ( isset( $_GET['theme'] ) ) + { + $flags .= $sep . 'theme='.$session->theme; + $sep = '&'; + } + if ( isset( $_GET['style'] ) ) + { + $flags .= $sep . 'style='.$session->style; + $sep = '&'; + } + + if(defined('ENANO_BASE_CLASSES_INITIALIZED')) + { + $url = contentPath . $paths->nslist[$n] . $t . $flags; + } + else + { + // If the path manager hasn't been initted yet, take an educated guess at what the URI should be + $url = contentPath . $n . ':' . $t . $flags; } if($query) { - if(strstr($url, '?')) $sep = '&'; - else $sep = '?'; + if(strstr($url, '?')) + { + $sep = '&'; + } + else + { + $sep = '?'; + } $url = $url . $sep . $query . $flags; } @@ -79,25 +164,62 @@ return ($escape) ? htmlspecialchars($url) : $url; } +/** + * Create a URI for an internal link, be namespace-friendly, and add http://hostname/scriptpath to the beginning if possible. Watch out for this one because it's different from most other Enano functions, in that the namespace is the first parameter. + * @param string The namespace ID + * @param string The page ID + * @param string The GET query string to append + * @param bool If true, perform htmlspecialchars() on the return value to make it HTML-safe + * @return string + */ + function makeUrlComplete($n, $t, $query = false, $escape = false) { global $db, $session, $paths, $template, $plugins; // Common objects $flags = ''; - if(defined('ENANO_BASE_CLASSES_INITIALIZED')) $sep = urlSeparator; - else $sep = (strstr($_SERVER['REQUEST_URI'], '?')) ? '&' : '?'; - if(isset($_GET['printable'])) { $flags .= $sep.'printable'; $sep = '&'; } - if(isset($_GET['theme'])) { $flags .= $sep.'theme='.$session->theme; $sep = '&'; } - if(isset($_GET['style'])) { $flags .= $sep.'style='.$session->style; $sep = '&'; } - if(defined('ENANO_BASE_CLASSES_INITIALIZED')) $url = $session->append_sid(contentPath.$paths->nslist[$n].$t.$flags); - else $url = contentPath.$n.':'.$t.$flags; + + if(defined('ENANO_BASE_CLASSES_INITIALIZED')) + { + $sep = urlSeparator; + } + else + { + $sep = (strstr($_SERVER['REQUEST_URI'], '?')) ? '&' : '?'; + } + if ( isset( $_GET['printable'] ) ) { + $flags .= $sep . 'printable'; + $sep = '&'; + } + if ( isset( $_GET['theme'] ) ) + { + $flags .= $sep . 'theme='.$session->theme; + $sep = '&'; + } + if ( isset( $_GET['style'] ) ) + { + $flags .= $sep . 'style='.$session->style; + $sep = '&'; + } + + if(defined('ENANO_BASE_CLASSES_INITIALIZED')) + { + $url = $session->append_sid(contentPath . $paths->nslist[$n] . $t . $flags); + } + else + { + // If the path manager hasn't been initted yet, take an educated guess at what the URI should be + $url = contentPath . $n . ':' . $t . $flags; + } if($query) { if(strstr($url, '?')) $sep = '&'; else $sep = '?'; $url = $url . $sep . $query . $flags; } + $baseprot = 'http' . ( isset($_SERVER['HTTPS']) ? 's' : '' ) . '://' . $_SERVER['HTTP_HOST']; $url = $baseprot . $url; + return ($escape) ? htmlspecialchars($url) : $url; } @@ -141,14 +263,38 @@ // Removed wikiFormat() from here, replaced with RenderMan::render +/** + * Tell me if the page exists or not. + * @param string the full page ID (Special:Administration) of the page to check for + * @return bool True if the page exists, false otherwise + */ + function isPage($p) { global $db, $session, $paths, $template, $plugins; // Common objects - if(isset($paths->pages[$p])) return true; - $d = RenderMan::strToPageID($p); - if($d[1] != 'Special' && $d[1] != 'Template' && $d[1] != 'Admin') return false; - $a = explode('/', $p); - if(isset($paths->pages[$a[0]])) return true; - else return false; + + // Try the easy way first ;-) + if ( isset( $paths->pages[ $p ] ) ) + { + return true; + } + + // Special case for Special, Template, and Admin pages that can't have slashes in their URIs + $ns_test = RenderMan::strToPageID( $p ); + + if($ns_test[1] != 'Special' && $ns_test[1] != 'Template' && $ns_test[1] != 'Admin') + { + return false; + } + + $particles = explode('/', $p); + if ( isset ( $paths->pages[ $particles[ 0 ] ] ) ) + { + return true; + } + else + { + return false; + } } function arrayItemUp($arr, $keyname) { diff -r 663fcf528726 -r d0314575e2f0 includes/pageprocess.php --- a/includes/pageprocess.php Tue Jun 26 17:28:18 2007 -0400 +++ b/includes/pageprocess.php Tue Jun 26 20:48:44 2007 -0400 @@ -464,15 +464,17 @@ $page_name = ( isset($paths->pages[$this->page_id]) ) ? $paths->pages[$this->page_id]['name'] : $this->page_id; } - if ( $page_name == str_replace('_', ' ', $this->page_id) || $page_name == $paths->nslist['User'] . str_replace('_', ' ', $this->page_id) ) + $target_username = strtr($page_name, + Array( + '_' => ' ', + '<' => '<', + '>' => '>' + )); + + $target_username = preg_replace('/^' . preg_quote($paths->nslist['User']) . '/', '', $target_username); + + if ( ( $page_name == str_replace('_', ' ', $this->page_id) || $page_name == $paths->nslist['User'] . str_replace('_', ' ', $this->page_id) ) || !$this->page_exists ) { - $target_username = strtr($page_name, - Array( - '_' => ' ', - '<' => '<', - '>' => '>' - )); - $target_username = preg_replace('/^' . preg_quote($paths->nslist['User']) . '/', '', $target_username); $page_name = "$target_username's user page"; } else @@ -483,27 +485,155 @@ $template->tpl_strings['PAGE_NAME'] = htmlspecialchars($page_name); + $q = $db->sql_query('SELECT u.username, u.user_id AS authoritative_uid, u.real_name, u.email, u.reg_time, x.*, COUNT(c.comment_id) AS n_comments + FROM '.table_prefix.'users u + LEFT JOIN '.table_prefix.'users_extra AS x + ON ( u.user_id = x.user_id OR x.user_id IS NULL ) + LEFT JOIN '.table_prefix.'comments AS c + ON ( ( c.user_id=u.user_id AND c.approved=1 ) OR ( c.comment_id IS NULL AND c.approved IS NULL ) ) + WHERE u.username=\'' . $db->escape($target_username) . '\' + GROUP BY u.user_id;'); + if ( !$q ) + $db->_die(); + + $user_exists = true; + + if ( $db->numrows() < 1 ) + { + $user_exists = false; + } + else + { + $userdata = $db->fetchrow(); + if ( $userdata['authoritative_uid'] == 1 ) + { + // Hide data for anonymous user + $user_exists = false; + unset($userdata); + } + } + $this->header(); // if ( $send_headers ) // { - display_page_headers(); + // display_page_headers(); // } // Start left sidebar: basic user info, latest comments + if ( $user_exists ): + echo ''; - echo '
'; + echo '
'; echo '
'; + // // Main part of sidebar + // + + // Basic user info + + echo ''; + echo ''; + echo ''; + + if ( !empty($userdata['real_name']) ) + { + echo ''; + } + + // Comments + + echo ''; + $q = $db->sql_query('SELECT page_id, namespace, subject, time FROM '.table_prefix.'comments WHERE name=\'' . $db->escape($target_username) . '\' AND approved=1 ORDER BY time DESC LIMIT 5;'); + if ( !$q ) + $db->_die(); + + $comments = Array(); + $no_comments = false; + + if ( $row = $db->fetchrow() ) + { + do + { + $row['time'] = date('F d, Y', $row['time']); + $comments[] = $row; + } + while ( $row = $db->fetchrow() ); + } + else + { + $no_comments = true; + } + + echo ''; echo '
All about ' . htmlspecialchars($target_username) . '
Joined: ' . date('F d, Y h:i a', $userdata['reg_time']) . '
Total comments: ' . $userdata['n_comments'] . '
Real name: ' . htmlspecialchars($userdata['real_name']) . '
' . htmlspecialchars($target_username) . '\'s latest comments
'; + echo '
'; + + echo ''; + $class = 'row1'; + + $tpl = ' + + '; + $parser = $template->makeParserText($tpl); + + if ( count($comments) > 0 ) + { + foreach ( $comments as $comment ) + { + $c_page_id = $paths->nslist[ $comment['namespace'] ] . sanitize_page_id($comment['page_id']); + if ( isset($paths->pages[ $c_page_id ]) ) + { + $parser->assign_bool(array( + 'page_exists' => true + )); + $page_title = $paths->pages[ $c_page_id ]['name']; + } + else + { + $parser->assign_bool(array( + 'page_exists' => false + )); + $page_title = htmlspecialchars(dirtify_page_id($c_page_id)); + } + $parser->assign_vars(array( + 'CLASS' => $class, + 'PAGE_LINK' => makeUrlNS($comment['namespace'], sanitize_page_id($comment['page_id'])), + 'PAGE' => $page_title, + 'SUBJECT' => $comment['subject'], + 'DATE' => $comment['time'], + 'COMMENT_LINK' => makeUrlNS($comment['namespace'], sanitize_page_id($comment['page_id']), 'do=comments', true) + )); + $class = ( $class == 'row3' ) ? 'row1' : 'row3'; + echo $parser->run(); + } + } + else + { + echo ''; + } + echo '
+ class="wikilink-nonexistent">{PAGE}
+ Posted {DATE}
+ {SUBJECT} +
This user has not posted any comments.
'; + + echo '
'; + echo '
'; - echo '
'; + echo ''; + + else: + + // Nothing for now + + endif; // User's own content @@ -516,26 +646,108 @@ } else { - $this->err_page_not_existent(); + $this->err_page_not_existent(true); } // Right sidebar - echo ''; + if ( $user_exists ): + + echo ''; echo '
'; + // // Main part of sidebar - + // + + // Contact information + + echo ''; + + $class = 'row3'; + + if ( $userdata['email_public'] == 1 ) + { + $class = ( $class == 'row1' ) ? 'row3' : 'row1'; + global $email; + $email_link = $email->encryptEmail($userdata['email']); + echo ''; + } + + $class = ( $class == 'row1' ) ? 'row3' : 'row1'; + if ( $session->user_logged_in ) + { + echo ''; + } + else + { + echo ''; + } + + if ( !empty($userdata['user_aim']) ) + { + $class = ( $class == 'row1' ) ? 'row3' : 'row1'; + echo ''; + } + + if ( !empty($userdata['user_yahoo']) ) + { + $class = ( $class == 'row1' ) ? 'row3' : 'row1'; + echo ''; + } + + if ( !empty($userdata['user_msn']) ) + { + $class = ( $class == 'row1' ) ? 'row3' : 'row1'; + $email_link = $email->encryptEmail($userdata['user_msn']); + echo ''; + } + + if ( !empty($userdata['user_xmpp']) ) + { + $class = ( $class == 'row1' ) ? 'row3' : 'row1'; + $email_link = $email->encryptEmail($userdata['user_xmpp']); + echo ''; + } + + // Real life + + echo ''; + + if ( !empty($userdata['user_location']) ) + { + $class = ( $class == 'row1' ) ? 'row3' : 'row1'; + echo ''; + } + + if ( !empty($userdata['user_job']) ) + { + $class = ( $class == 'row1' ) ? 'row3' : 'row1'; + echo ''; + } + + if ( !empty($userdata['user_hobbies']) ) + { + $class = ( $class == 'row1' ) ? 'row3' : 'row1'; + echo ''; + } + echo '
Get in touch
E-mail address: ' . $email_link . '
Send ' . htmlspecialchars($target_username) . ' a Private Message!
You could send ' . htmlspecialchars($target_username) . ' a private message if you were logged in.
AIM: ' . htmlspecialchars($userdata['user_aim']) . '
Yahoo! IM: ' . htmlspecialchars($userdata['user_yahoo']) . '
WLM: ' . $email_link . '
XMPP/Jabber: ' . $email_link . '
' . htmlspecialchars($target_username) . ' in real life
Location: ' . htmlspecialchars($userdata['user_location']) . '
Job/occupation: ' . htmlspecialchars($userdata['user_job']) . '
Enjoys: ' . htmlspecialchars($userdata['user_hobbies']) . '
'; echo '
'; + else: + + echo '

Additional information: user "' . htmlspecialchars($target_username) . '" does not exist.

'; + + endif; + // if ( $send_headers ) // { - display_page_footers(); + // display_page_footers(); // } $this->send_headers = $send_headers; @@ -601,14 +813,22 @@ * @access private */ - function err_page_not_existent() + function err_page_not_existent($userpage = false) { global $db, $session, $paths, $template, $plugins; // Common objects $this->header(); header('HTTP/1.1 404 Not Found'); - echo '

There is no page with this title yet.

-

You have requested a page that doesn\'t exist yet.'; + if ( $userpage ) + { + echo '

There is no page with this title yet.

+

This user has not created his or her user page yet.'; + } + else + { + echo '

There is no page with this title yet.

+

You have requested a page that doesn\'t exist yet.'; + } if ( $session->get_permissions('create_page') ) { echo ' You can create this page, or return to the homepage.'; diff -r 663fcf528726 -r d0314575e2f0 includes/template.php --- a/includes/template.php Tue Jun 26 17:28:18 2007 -0400 +++ b/includes/template.php Tue Jun 26 20:48:44 2007 -0400 @@ -647,11 +647,13 @@ $urlname_clean = str_replace('\'', '\\\'', str_replace('\\', '\\\\', dirtify_page_id($paths->fullpage))); $urlname_clean = strtr( $urlname_clean, array( '<' => '<', '>' => '>' ) ); + $urlname_jssafe = sanitize_page_id($paths->fullpage); + // Generate the dynamic javascript vars $js_dynamic = '