changeset 326 | ab66d6d1f1f4 |
parent 314 | 474f8be55943 |
parent 325 | e17cc42d77cf |
child 328 | dc838fd61a06 |
314:474f8be55943 | 326:ab66d6d1f1f4 |
---|---|
1 <?php |
1 <?php |
2 |
2 |
3 /* |
3 /* |
4 * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between |
4 * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between |
5 * Version 1.1.1 |
5 * Version 1.0.3 (Dyrad) |
6 * pageprocess.php - intelligent retrieval of pages |
6 * pageprocess.php - intelligent retrieval of pages |
7 * Copyright (C) 2006-2007 Dan Fuhry |
7 * Copyright (C) 2006-2007 Dan Fuhry |
8 * |
8 * |
9 * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License |
9 * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License |
10 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. |
10 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. |
13 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. |
13 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. |
14 */ |
14 */ |
15 |
15 |
16 /** |
16 /** |
17 * Class to handle fetching page text (possibly from a cache) and formatting it. |
17 * Class to handle fetching page text (possibly from a cache) and formatting it. |
18 * As of 1.0.4, this also handles the fetching and editing of certain data for pages. |
|
18 * @package Enano |
19 * @package Enano |
19 * @subpackage UI |
20 * @subpackage UI |
20 * @copyright 2007 Dan Fuhry |
21 * @copyright 2007 Dan Fuhry |
21 * @license GNU General Public License <http://www.gnu.org/licenses/gpl.html> |
22 * @license GNU General Public License <http://www.gnu.org/licenses/gpl.html> |
22 */ |
23 */ |
109 |
110 |
110 var $debug = array( |
111 var $debug = array( |
111 'enable' => false, |
112 'enable' => false, |
112 'works' => false |
113 'works' => false |
113 ); |
114 ); |
115 |
|
116 /** |
|
117 * The list of errors raised in the class. |
|
118 * @var array |
|
119 */ |
|
120 |
|
121 var $_errors = array(); |
|
114 |
122 |
115 /** |
123 /** |
116 * Constructor. |
124 * Constructor. |
117 * @param string The page ID (urlname) of the page |
125 * @param string The page ID (urlname) of the page |
118 * @param string The namespace of the page |
126 * @param string The namespace of the page |
311 } |
319 } |
312 } |
320 } |
313 } |
321 } |
314 |
322 |
315 /** |
323 /** |
324 * Fetches the wikitext or HTML source for the page. |
|
325 * @return string |
|
326 */ |
|
327 |
|
328 function fetch_source() |
|
329 { |
|
330 if ( !$this->perms->get_permissions('view_source') ) |
|
331 { |
|
332 return false; |
|
333 } |
|
334 if ( !$this->page_exists ) |
|
335 { |
|
336 return ''; |
|
337 } |
|
338 return $this->fetch_text(); |
|
339 } |
|
340 |
|
341 /** |
|
342 * Updates the content of the page. |
|
343 * @param string The new text for the page |
|
344 * @param string A summary of edits made to the page. |
|
345 * @return bool True on success, false on failure |
|
346 */ |
|
347 |
|
348 function update_page($text, $edit_summary = false) |
|
349 { |
|
350 global $db, $session, $paths, $template, $plugins; // Common objects |
|
351 |
|
352 // Create the page if it doesn't exist |
|
353 if ( !$this->page_exists ) |
|
354 { |
|
355 if ( !$this->create_page() ) |
|
356 { |
|
357 return false; |
|
358 } |
|
359 } |
|
360 |
|
361 // |
|
362 // Validation |
|
363 // |
|
364 |
|
365 $page_id = $db->escape($this->page_id); |
|
366 $namespace = $db->escape($this->namespace); |
|
367 |
|
368 $q = $db->sql_query('SELECT protected FROM ' . table_prefix . "pages WHERE urlname='$page_id' AND namespace='$namespace';"); |
|
369 if ( !$q ) |
|
370 $db->_die('PageProcess updating page content'); |
|
371 if ( $db->numrows() < 1 ) |
|
372 { |
|
373 $this->raise_error('Page doesn\'t exist in the database'); |
|
374 return false; |
|
375 } |
|
376 |
|
377 // Do we have permission to edit the page? |
|
378 if ( !$this->perms->get_permissions('edit_page') ) |
|
379 { |
|
380 $this->raise_error('You do not have permission to edit this page.'); |
|
381 return false; |
|
382 } |
|
383 |
|
384 list($protection) = $db->fetchrow_num(); |
|
385 $db->free_result(); |
|
386 |
|
387 if ( $protection == 1 ) |
|
388 { |
|
389 // The page is protected - do we have permission to edit protected pages? |
|
390 if ( !$this->perms->get_permissions('even_when_protected') ) |
|
391 { |
|
392 $this->raise_error('This page is protected, and you do not have permission to edit protected pages.'); |
|
393 return false; |
|
394 } |
|
395 } |
|
396 else if ( $protection == 2 ) |
|
397 { |
|
398 // The page is semi-protected. |
|
399 if ( |
|
400 ( !$session->user_logged_in || // Is the user logged in? |
|
401 ( $session->user_logged_in && $session->reg_time + ( 4 * 86400 ) >= time() ) ) // If so, have they been registered for 4 days? |
|
402 && !$this->perms->get_permissions('even_when_protected') ) // And of course, is there an ACL that overrides semi-protection? |
|
403 { |
|
404 $this->raise_error('This page is protected, and you do not have permission to edit protected pages.'); |
|
405 return false; |
|
406 } |
|
407 } |
|
408 |
|
409 // Protection validated |
|
410 |
|
411 } |
|
412 |
|
413 /** |
|
414 * Creates the page if it doesn't already exist. |
|
415 * @return bool True on success, false on failure. |
|
416 */ |
|
417 |
|
418 function create_page() |
|
419 { |
|
420 global $db, $session, $paths, $template, $plugins; // Common objects |
|
421 |
|
422 // Do we have permission to create the page? |
|
423 if ( !$this->perms->get_permissions('create_page') ) |
|
424 { |
|
425 $this->raise_error('You do not have permission to create this page.'); |
|
426 return false; |
|
427 } |
|
428 |
|
429 // Does it already exist? |
|
430 if ( $this->page_exists ) |
|
431 { |
|
432 $this->raise_error('The page already exists.'); |
|
433 return false; |
|
434 } |
|
435 |
|
436 // It's not in there. Perform validation. |
|
437 |
|
438 // We can't create special, admin, or external pages. |
|
439 if ( $this->namespace == 'Special' || $this->namespace == 'Admin' || $this->namespace == 'Anonymous' ) |
|
440 { |
|
441 $this->raise_error('You cannot create Special or Admin pages - they can\'t be stored in the database.'); |
|
442 return false; |
|
443 } |
|
444 |
|
445 // Guess the proper title |
|
446 $name = dirtify_page_id($this->page_id); |
|
447 |
|
448 // Check for the restricted Project: prefix |
|
449 if ( substr($this->page_id, 0, 8) == 'Project:' ) |
|
450 { |
|
451 $this->raise_error('The prefix "Project:" is reserved for internal links and can\'t be used on a page name.'); |
|
452 return false; |
|
453 } |
|
454 |
|
455 // Validation successful - insert the page |
|
456 |
|
457 $metadata = array( |
|
458 'urlname' => $this->page_id, |
|
459 'namespace' => $this->namespace, |
|
460 'name' => $name, |
|
461 'special' => 0, |
|
462 'visible' => 1, |
|
463 'comments_on' => 1, |
|
464 'protected' => ( $this->namespace == 'System' ? 1 : 0 ), |
|
465 'delvotes' => 0, |
|
466 'delvote_ips' => serialize(array()), |
|
467 'wiki_mode' => 2 |
|
468 ); |
|
469 |
|
470 $paths->add_page($metadata); |
|
471 |
|
472 $page_id = $db->escape($this->page_id); |
|
473 $namespace = $db->escape($this->namespace); |
|
474 $name = $db->escape($name); |
|
475 $protect = ( $this->namespace == 'System' ) ? '1' : '0'; |
|
476 $blank_array = $db->escape(serialize(array())); |
|
477 |
|
478 // Query 1: Metadata entry |
|
479 $q = $db->sql_query('INSERT INTO ' . table_prefix . "pages(name, urlname, namespace, protected, delvotes, delvote_ips, wiki_mode)\n" |
|
480 . "VALUES ( '$name', '$page_id', '$namespace', $protect, 0, '$blank_array', 2 );"); |
|
481 if ( !$q ) |
|
482 $db->_die('PageProcessor page creation - metadata stage'); |
|
483 |
|
484 // Query 2: Text insertion |
|
485 $q = $db->sql_query('INSERT INTO ' . table_prefix . "page_text(page_id, namespace, page_text)\n" |
|
486 . "VALUES ( '$page_id', '$namespace', '' );"); |
|
487 if ( !$q ) |
|
488 $db->_die('PageProcessor page creation - text stage'); |
|
489 |
|
490 // Page created. We're good! |
|
491 return true; |
|
492 } |
|
493 |
|
494 /** |
|
316 * Sets internal variables. |
495 * Sets internal variables. |
317 * @access private |
496 * @access private |
318 */ |
497 */ |
319 |
498 |
320 function _setup($page_id, $namespace, $revision_id) |
499 function _setup($page_id, $namespace, $revision_id) |
335 { |
514 { |
336 $fname = "page_Admin_{$this->page_id}"; |
515 $fname = "page_Admin_{$this->page_id}"; |
337 } |
516 } |
338 |
517 |
339 // Does the page "exist"? |
518 // Does the page "exist"? |
340 if ( $paths->cpage['urlname_nons'] == $page_id && $paths->namespace == $namespace && !$paths->page_exists && ( $this->namespace != 'Admin' || ($this->namespace == 'Admin' && !function_exists($fname) ) ) ) |
519 if ( $paths->page_id == $page_id && $paths->namespace == $namespace && !$paths->page_exists && ( $this->namespace != 'Admin' || ($this->namespace == 'Admin' && !function_exists($fname) ) ) ) |
341 { |
520 { |
342 $this->page_exists = false; |
521 $this->page_exists = false; |
343 } |
522 } |
344 else if ( !isset( $paths->pages[ $paths->nslist[$namespace] . $page_id ] ) && ( $this->namespace == 'Admin' && !function_exists($fname) ) ) |
523 else if ( !isset( $paths->pages[ $paths->nslist[$namespace] . $page_id ] ) && ( $this->namespace == 'Admin' && !function_exists($fname) ) ) |
345 { |
524 { |
353 // Compatibility with older databases |
532 // Compatibility with older databases |
354 if ( strstr($this->page_id, '.2e') && !$this->page_exists ) |
533 if ( strstr($this->page_id, '.2e') && !$this->page_exists ) |
355 { |
534 { |
356 $page_id = str_replace('.2e', '.', $page_id); |
535 $page_id = str_replace('.2e', '.', $page_id); |
357 |
536 |
358 if ( $paths->cpage['urlname_nons'] == $page_id && $paths->namespace == $namespace && !$paths->page_exists && ( $this->namespace != 'Admin' || ($this->namespace == 'Admin' && !function_exists($fname) ) ) ) |
537 if ( $paths->page_id == $page_id && $paths->namespace == $namespace && !$paths->page_exists && ( $this->namespace != 'Admin' || ($this->namespace == 'Admin' && !function_exists($fname) ) ) ) |
359 { |
538 { |
360 $this->page_exists = false; |
539 $this->page_exists = false; |
361 } |
540 } |
362 else if ( !isset( $paths->pages[ $paths->nslist[$namespace] . $page_id ] ) && ( $this->namespace == 'Admin' && !function_exists($fname) ) ) |
541 else if ( !isset( $paths->pages[ $paths->nslist[$namespace] . $page_id ] ) && ( $this->namespace == 'Admin' && !function_exists($fname) ) ) |
363 { |
542 { |
455 display_page_headers(); |
634 display_page_headers(); |
456 } |
635 } |
457 |
636 |
458 if ( $this->revision_id ) |
637 if ( $this->revision_id ) |
459 { |
638 { |
460 echo '<div class="info-box" style="margin-left: 0; margin-top: 5px;"><b>Notice:</b><br />The page you are viewing was archived on '.date('F d, Y \a\t h:i a', $this->revision_id).'.<br /><a href="'.makeUrlNS($this->namespace, $this->page_id).'" onclick="ajaxReset(); return false;">View current version</a> | <a href="'.makeUrlNS($this->namespace, $this->pageid, 'do=rollback&id='.$this->revision_id).'" onclick="ajaxRollback(\''.$this->revision_id.'\')">Restore this version</a></div><br />'; |
639 echo '<div class="info-box" style="margin-left: 0; margin-top: 5px;"><b>Notice:</b><br />The page you are viewing was archived on '.date('F d, Y \a\t h:i a', $this->revision_id).'.<br /><a href="'.makeUrlNS($this->namespace, $this->page_id).'" onclick="ajaxReset(); return false;">View current version</a> | <a href="'.makeUrlNS($this->namespace, $this->page_id, 'do=rollback&id='.$this->revision_id).'" onclick="ajaxRollback(\''.$this->revision_id.'\')">Restore this version</a></div><br />'; |
461 } |
640 } |
462 |
641 |
463 if ( $redir_enabled ) |
642 if ( $redir_enabled ) |
464 { |
643 { |
465 echo $redir_html; |
644 echo $redir_html; |
626 { |
805 { |
627 global $db, $session, $paths, $template, $plugins; // Common objects |
806 global $db, $session, $paths, $template, $plugins; // Common objects |
628 global $email; |
807 global $email; |
629 |
808 |
630 $page_urlname = dirtify_page_id($this->page_id); |
809 $page_urlname = dirtify_page_id($this->page_id); |
631 if ( $this->page_id == $paths->cpage['urlname_nons'] && $this->namespace == $paths->namespace ) |
810 if ( $this->page_id == $paths->page_id && $this->namespace == $paths->namespace ) |
632 { |
811 { |
633 $page_name = ( isset($paths->cpage['name']) ) ? $paths->cpage['name'] : $this->page_id; |
812 $page_name = ( isset($paths->cpage['name']) ) ? $paths->cpage['name'] : $this->page_id; |
634 } |
813 } |
635 else |
814 else |
636 { |
815 { |
665 LEFT JOIN '.table_prefix.'users_extra AS x |
844 LEFT JOIN '.table_prefix.'users_extra AS x |
666 ON ( u.user_id = x.user_id OR x.user_id IS NULL ) |
845 ON ( u.user_id = x.user_id OR x.user_id IS NULL ) |
667 LEFT JOIN '.table_prefix.'comments AS c |
846 LEFT JOIN '.table_prefix.'comments AS c |
668 ON ( ( c.user_id=u.user_id AND c.name=u.username AND c.approved=1 ) OR ( c.comment_id IS NULL AND c.approved IS NULL ) ) |
847 ON ( ( c.user_id=u.user_id AND c.name=u.username AND c.approved=1 ) OR ( c.comment_id IS NULL AND c.approved IS NULL ) ) |
669 WHERE u.username=\'' . $db->escape($target_username) . '\' |
848 WHERE u.username=\'' . $db->escape($target_username) . '\' |
670 GROUP BY u.user_id;'); |
849 GROUP BY u.username, u.user_id, u.real_name, u.email, u.reg_time,x.user_id, x.user_aim, x.user_yahoo, x.user_msn, x.user_xmpp, x.user_homepage, x.user_location, x.user_job, x.user_hobbies, x.email_public;'); |
671 if ( !$q ) |
850 if ( !$q ) |
672 $db->_die(); |
851 $db->_die(); |
673 |
852 |
674 $user_exists = true; |
853 $user_exists = true; |
675 |
854 |
803 } |
982 } |
804 echo '</table>'; |
983 echo '</table>'; |
805 |
984 |
806 echo '</div>'; |
985 echo '</div>'; |
807 echo '</td></tr>'; |
986 echo '</td></tr>'; |
808 |
987 |
988 $code = $plugins->setHook('userpage_sidebar_left'); |
|
989 foreach ( $code as $cmd ) |
|
990 { |
|
991 eval($cmd); |
|
992 } |
|
993 |
|
809 echo ' </table> |
994 echo ' </table> |
810 </div>'; |
995 </div>'; |
811 |
996 |
812 echo '</td><td valign="top" style="padding: 0 10px;">'; |
997 echo '</td><td valign="top" style="padding: 0 10px;">'; |
813 |
998 |
917 |
1102 |
918 if ( empty($userdata['user_location']) && empty($userdata['user_job']) && empty($userdata['user_hobbies']) ) |
1103 if ( empty($userdata['user_location']) && empty($userdata['user_job']) && empty($userdata['user_hobbies']) ) |
919 { |
1104 { |
920 $class = ( $class == 'row1' ) ? 'row3' : 'row1'; |
1105 $class = ( $class == 'row1' ) ? 'row3' : 'row1'; |
921 echo '<tr><td class="'.$class.'">' . htmlspecialchars($target_username) . ' hasn\'t posted any real-life contact information.</td></tr>'; |
1106 echo '<tr><td class="'.$class.'">' . htmlspecialchars($target_username) . ' hasn\'t posted any real-life contact information.</td></tr>'; |
1107 } |
|
1108 |
|
1109 $code = $plugins->setHook('userpage_sidebar_right'); |
|
1110 foreach ( $code as $cmd ) |
|
1111 { |
|
1112 eval($cmd); |
|
922 } |
1113 } |
923 |
1114 |
924 echo ' </table> |
1115 echo ' </table> |
925 </div>'; |
1116 </div>'; |
926 |
1117 |
1245 |
1436 |
1246 exit; |
1437 exit; |
1247 |
1438 |
1248 } |
1439 } |
1249 |
1440 |
1441 /** |
|
1442 * Raises an error. |
|
1443 * @param string Error string |
|
1444 */ |
|
1445 |
|
1446 function raise_error($string) |
|
1447 { |
|
1448 if ( !is_string($string) ) |
|
1449 return false; |
|
1450 $this->_errors[] = $string; |
|
1451 } |
|
1452 |
|
1453 /** |
|
1454 * Retrieves the latest error from the error stack and returns it ('pops' the error stack) |
|
1455 * @return string |
|
1456 */ |
|
1457 |
|
1458 function pop_error() |
|
1459 { |
|
1460 if ( count($this->_errors) < 1 ) |
|
1461 return false; |
|
1462 return array_pop($this->_errors); |
|
1463 } |
|
1464 |
|
1250 } // class PageProcessor |
1465 } // class PageProcessor |
1251 |
1466 |
1252 ?> |
1467 ?> |