includes/pageutils.php
changeset 372 5bd429428101
parent 361 35ed07abc99e
child 391 85f91037cd4f
equal deleted inserted replaced
371:dc6026376919 372:5bd429428101
    19    * Tell if a username is used or not.
    19    * Tell if a username is used or not.
    20    * @param $name the name to check for
    20    * @param $name the name to check for
    21    * @return string
    21    * @return string
    22    */
    22    */
    23   
    23   
    24   function checkusername($name)
    24   public static function checkusername($name)
    25   {
    25   {
    26     global $db, $session, $paths, $template, $plugins; // Common objects
    26     global $db, $session, $paths, $template, $plugins; // Common objects
    27     $name = str_replace('_', ' ', $name);
    27     $name = str_replace('_', ' ', $name);
    28     $q = $db->sql_query('SELECT username FROM ' . table_prefix.'users WHERE username=\'' . $db->escape(rawurldecode($name)) . '\'');
    28     $q = $db->sql_query('SELECT username FROM ' . table_prefix.'users WHERE username=\'' . $db->escape(rawurldecode($name)) . '\'');
    29     if ( !$q )
    29     if ( !$q )
    45    * @param $page the full page id (Namespace:Pagename)
    45    * @param $page the full page id (Namespace:Pagename)
    46    * @return string
    46    * @return string
    47    * @todo (DONE) Make it require a password (just for security purposes)
    47    * @todo (DONE) Make it require a password (just for security purposes)
    48    */
    48    */
    49    
    49    
    50   function getsource($page, $password = false)
    50   public static function getsource($page, $password = false)
    51   {
    51   {
    52     global $db, $session, $paths, $template, $plugins; // Common objects
    52     global $db, $session, $paths, $template, $plugins; // Common objects
    53     if(!isset($paths->pages[$page]))
    53     if(!isset($paths->pages[$page]))
    54     {
    54     {
    55       return '';
    55       return '';
    93    * @param $page the full page id (Namespace:Pagename)
    93    * @param $page the full page id (Namespace:Pagename)
    94    * @param $send_headers true if the theme headers should be sent (still dependent on current page settings), false otherwise
    94    * @param $send_headers true if the theme headers should be sent (still dependent on current page settings), false otherwise
    95    * @return string
    95    * @return string
    96    */
    96    */
    97   
    97   
    98   function getpage($page, $send_headers = false, $hist_id = false)
    98   public static function getpage($page, $send_headers = false, $hist_id = false)
    99   {
    99   {
   100     die('PageUtils->getpage is deprecated.');
   100     die('PageUtils->getpage is deprecated.');
   101     global $db, $session, $paths, $template, $plugins; // Common objects
   101     global $db, $session, $paths, $template, $plugins; // Common objects
   102     ob_start();
   102     ob_start();
   103     $pid = RenderMan::strToPageID($page);
   103     $pid = RenderMan::strToPageID($page);
   326    * @param $namespace the namespace
   326    * @param $namespace the namespace
   327    * @param $message the text to save
   327    * @param $message the text to save
   328    * @return string
   328    * @return string
   329    */
   329    */
   330    
   330    
   331   function savepage($page_id, $namespace, $message, $summary = 'No edit summary given', $minor = false)
   331   public static function savepage($page_id, $namespace, $message, $summary = 'No edit summary given', $minor = false)
   332   {
   332   {
   333     global $db, $session, $paths, $template, $plugins; // Common objects
   333     global $db, $session, $paths, $template, $plugins; // Common objects
   334     $uid = sha1(microtime());
   334     $uid = sha1(microtime());
   335     $pname = $paths->nslist[$namespace] . $page_id;
   335     $pname = $paths->nslist[$namespace] . $page_id;
   336     
   336     
   397    * @param string $page_id
   397    * @param string $page_id
   398    * @param string $namespace
   398    * @param string $namespace
   399    * @return bool true on success, false on failure
   399    * @return bool true on success, false on failure
   400    */
   400    */
   401   
   401   
   402   function createPage($page_id, $namespace, $name = false, $visible = 1)
   402   public static function createPage($page_id, $namespace, $name = false, $visible = 1)
   403   {
   403   {
   404     global $db, $session, $paths, $template, $plugins; // Common objects
   404     global $db, $session, $paths, $template, $plugins; // Common objects
   405     if(in_array($namespace, Array('Special', 'Admin')))
   405     if(in_array($namespace, Array('Special', 'Admin')))
   406     {
   406     {
   407       // echo '<b>Notice:</b> PageUtils::createPage: You can\'t create a special page in the database<br />';
   407       // echo '<b>Notice:</b> PageUtils::createPage: You can\'t create a special page in the database<br />';
   492    * @param $namespace string the namespace
   492    * @param $namespace string the namespace
   493    * @param $level int level of protection - 0 is off, 1 is full, 2 is semi
   493    * @param $level int level of protection - 0 is off, 1 is full, 2 is semi
   494    * @param $reason string why the page is being (un)protected
   494    * @param $reason string why the page is being (un)protected
   495    * @return string - "good" on success, in all other cases, an error string (on query failure, calls $db->_die() )
   495    * @return string - "good" on success, in all other cases, an error string (on query failure, calls $db->_die() )
   496    */
   496    */
   497   function protect($page_id, $namespace, $level, $reason)
   497   public static function protect($page_id, $namespace, $level, $reason)
   498   {
   498   {
   499     global $db, $session, $paths, $template, $plugins; // Common objects
   499     global $db, $session, $paths, $template, $plugins; // Common objects
   500     
   500     
   501     $pname = $paths->nslist[$namespace] . $page_id;
   501     $pname = $paths->nslist[$namespace] . $page_id;
   502     $wiki = ( ( $paths->pages[$pname]['wiki_mode'] == 2 && getConfig('wiki_mode') == '1') || $paths->pages[$pname]['wiki_mode'] == 1) ? true : false;
   502     $wiki = ( ( $paths->pages[$pname]['wiki_mode'] == 2 && getConfig('wiki_mode') == '1') || $paths->pages[$pname]['wiki_mode'] == 1) ? true : false;
   546    * @param $page_id the page ID
   546    * @param $page_id the page ID
   547    * @param $namespace the namespace
   547    * @param $namespace the namespace
   548    * @return string
   548    * @return string
   549    */
   549    */
   550   
   550   
   551   function histlist($page_id, $namespace)
   551   public static function histlist($page_id, $namespace)
   552   {
   552   {
   553     global $db, $session, $paths, $template, $plugins; // Common objects
   553     global $db, $session, $paths, $template, $plugins; // Common objects
   554     global $lang;
   554     global $lang;
   555     
   555     
   556     if(!$session->get_permissions('history_view'))
   556     if(!$session->get_permissions('history_view'))
   739    * Rolls back a logged action
   739    * Rolls back a logged action
   740    * @param $id the time ID, a.k.a. the primary key in the logs table
   740    * @param $id the time ID, a.k.a. the primary key in the logs table
   741    * @return string
   741    * @return string
   742    */
   742    */
   743    
   743    
   744   function rollback($id)
   744   public static function rollback($id)
   745   {
   745   {
   746     global $db, $session, $paths, $template, $plugins; // Common objects
   746     global $db, $session, $paths, $template, $plugins; // Common objects
   747     if ( !$session->get_permissions('history_rollback') )
   747     if ( !$session->get_permissions('history_rollback') )
   748     {
   748     {
   749       return('You are not authorized to perform rollbacks.');
   749       return('You are not authorized to perform rollbacks.');
   906    * @param $subject the subject line of the comment
   906    * @param $subject the subject line of the comment
   907    * @param $text the comment text
   907    * @param $text the comment text
   908    * @return string javascript code
   908    * @return string javascript code
   909    */
   909    */
   910    
   910    
   911   function addcomment($page_id, $namespace, $name, $subject, $text, $captcha_code = false, $captcha_id = false)
   911   public static function addcomment($page_id, $namespace, $name, $subject, $text, $captcha_code = false, $captcha_id = false)
   912   {
   912   {
   913     global $db, $session, $paths, $template, $plugins; // Common objects
   913     global $db, $session, $paths, $template, $plugins; // Common objects
   914     $_ob = '';
   914     $_ob = '';
   915     if(!$session->get_permissions('post_comments'))
   915     if(!$session->get_permissions('post_comments'))
   916       return 'Access denied';
   916       return 'Access denied';
   941    * @param $_ob text to prepend to output, used by PageUtils::addcomment
   941    * @param $_ob text to prepend to output, used by PageUtils::addcomment
   942    * @return array
   942    * @return array
   943    * @access private
   943    * @access private
   944    */
   944    */
   945    
   945    
   946   function comments_raw($page_id, $namespace, $action = false, $flags = Array(), $_ob = '')
   946   public static function comments_raw($page_id, $namespace, $action = false, $flags = Array(), $_ob = '')
   947   {
   947   {
   948     global $db, $session, $paths, $template, $plugins; // Common objects
   948     global $db, $session, $paths, $template, $plugins; // Common objects
   949     global $lang;
   949     global $lang;
   950     
   950     
   951     $pname = $paths->nslist[$namespace] . $page_id;
   951     $pname = $paths->nslist[$namespace] . $page_id;
  1200    * @param $flags additional info for $action, shouldn't be used except when deleting/approving comments, etc.
  1200    * @param $flags additional info for $action, shouldn't be used except when deleting/approving comments, etc.
  1201    * @param $_ob text to prepend to output, used by PageUtils::addcomment
  1201    * @param $_ob text to prepend to output, used by PageUtils::addcomment
  1202    * @return string
  1202    * @return string
  1203    */
  1203    */
  1204    
  1204    
  1205   function comments($page_id, $namespace, $action = false, $id = -1, $_ob = '')
  1205   public static function comments($page_id, $namespace, $action = false, $id = -1, $_ob = '')
  1206   {
  1206   {
  1207     global $db, $session, $paths, $template, $plugins; // Common objects
  1207     global $db, $session, $paths, $template, $plugins; // Common objects
  1208     $r = PageUtils::comments_raw($page_id, $namespace, $action, $id, $_ob);
  1208     $r = PageUtils::comments_raw($page_id, $namespace, $action, $id, $_ob);
  1209     return $r[0];
  1209     return $r[0];
  1210   }
  1210   }
  1217    * @param $flags additional info for $action, shouldn't be used except when deleting/approving comments, etc.
  1217    * @param $flags additional info for $action, shouldn't be used except when deleting/approving comments, etc.
  1218    * @param $_ob text to prepend to output, used by PageUtils::addcomment
  1218    * @param $_ob text to prepend to output, used by PageUtils::addcomment
  1219    * @return string
  1219    * @return string
  1220    */
  1220    */
  1221   
  1221   
  1222   function comments_html($page_id, $namespace, $action = false, $id = -1, $_ob = '')
  1222   public static function comments_html($page_id, $namespace, $action = false, $id = -1, $_ob = '')
  1223   {
  1223   {
  1224     global $db, $session, $paths, $template, $plugins; // Common objects
  1224     global $db, $session, $paths, $template, $plugins; // Common objects
  1225     $r = PageUtils::comments_raw($page_id, $namespace, $action, $id, $_ob);
  1225     $r = PageUtils::comments_raw($page_id, $namespace, $action, $id, $_ob);
  1226     return $r[1];
  1226     return $r[1];
  1227   }
  1227   }
  1236    * @param $old_text the old text, unprocessed and identical to the value in the DB
  1236    * @param $old_text the old text, unprocessed and identical to the value in the DB
  1237    * @param $id the javascript list ID, used internally by the client-side app
  1237    * @param $id the javascript list ID, used internally by the client-side app
  1238    * @return string
  1238    * @return string
  1239    */
  1239    */
  1240   
  1240   
  1241   function savecomment($page_id, $namespace, $subject, $text, $old_subject, $old_text, $id = -1)
  1241   public static function savecomment($page_id, $namespace, $subject, $text, $old_subject, $old_text, $id = -1)
  1242   {
  1242   {
  1243     global $db, $session, $paths, $template, $plugins; // Common objects
  1243     global $db, $session, $paths, $template, $plugins; // Common objects
  1244     if(!$session->get_permissions('edit_comments'))
  1244     if(!$session->get_permissions('edit_comments'))
  1245       return 'result="BAD";error="Access denied"';
  1245       return 'result="BAD";error="Access denied"';
  1246     // Avoid SQL injection
  1246     // Avoid SQL injection
  1287    * @param $text new text
  1287    * @param $text new text
  1288    * @param $id the comment ID (primary key in enano_comments table)
  1288    * @param $id the comment ID (primary key in enano_comments table)
  1289    * @return string
  1289    * @return string
  1290    */
  1290    */
  1291   
  1291   
  1292   function savecomment_neater($page_id, $namespace, $subject, $text, $id)
  1292   public static function savecomment_neater($page_id, $namespace, $subject, $text, $id)
  1293   {
  1293   {
  1294     global $db, $session, $paths, $template, $plugins; // Common objects
  1294     global $db, $session, $paths, $template, $plugins; // Common objects
  1295     if(!is_int($id)) die('PageUtils::savecomment: $id is not an integer, aborting for safety');
  1295     if(!is_int($id)) die('PageUtils::savecomment: $id is not an integer, aborting for safety');
  1296     if(!$session->get_permissions('edit_comments'))
  1296     if(!$session->get_permissions('edit_comments'))
  1297       return 'Access denied';
  1297       return 'Access denied';
  1328    * @param $text the text of the comment to be deleted
  1328    * @param $text the text of the comment to be deleted
  1329    * @param $id the javascript list ID, used internally by the client-side app
  1329    * @param $id the javascript list ID, used internally by the client-side app
  1330    * @return string
  1330    * @return string
  1331    */
  1331    */
  1332   
  1332   
  1333   function deletecomment($page_id, $namespace, $name, $subj, $text, $id)
  1333   public static function deletecomment($page_id, $namespace, $name, $subj, $text, $id)
  1334   {
  1334   {
  1335     global $db, $session, $paths, $template, $plugins; // Common objects
  1335     global $db, $session, $paths, $template, $plugins; // Common objects
  1336     
  1336     
  1337     if(!$session->get_permissions('edit_comments'))
  1337     if(!$session->get_permissions('edit_comments'))
  1338       return 'alert("Access to delete/edit comments is denied");';
  1338       return 'alert("Access to delete/edit comments is denied");';
  1365    * @param $namespace the namespace
  1365    * @param $namespace the namespace
  1366    * @param $id the comment ID (primary key)
  1366    * @param $id the comment ID (primary key)
  1367    * @return string
  1367    * @return string
  1368    */
  1368    */
  1369   
  1369   
  1370   function deletecomment_neater($page_id, $namespace, $id)
  1370   public static function deletecomment_neater($page_id, $namespace, $id)
  1371   {
  1371   {
  1372     global $db, $session, $paths, $template, $plugins; // Common objects
  1372     global $db, $session, $paths, $template, $plugins; // Common objects
  1373     
  1373     
  1374     if(!preg_match('#^([0-9]+)$#', (string)$id)) die('$_GET[id] is improperly formed.');
  1374     if(!preg_match('#^([0-9]+)$#', (string)$id)) die('$_GET[id] is improperly formed.');
  1375     
  1375     
  1399    * @param $namespace the namespace
  1399    * @param $namespace the namespace
  1400    * @param $name the new name for the page
  1400    * @param $name the new name for the page
  1401    * @return string error string or success message
  1401    * @return string error string or success message
  1402    */
  1402    */
  1403    
  1403    
  1404   function rename($page_id, $namespace, $name)
  1404   public static function rename($page_id, $namespace, $name)
  1405   {
  1405   {
  1406     global $db, $session, $paths, $template, $plugins; // Common objects
  1406     global $db, $session, $paths, $template, $plugins; // Common objects
  1407     global $lang;
  1407     global $lang;
  1408     
  1408     
  1409     $pname = $paths->nslist[$namespace] . $page_id;
  1409     $pname = $paths->nslist[$namespace] . $page_id;
  1447    * @param $page_id the page ID
  1447    * @param $page_id the page ID
  1448    * @param $namespace the namespace
  1448    * @param $namespace the namespace
  1449    * @return string error/success string
  1449    * @return string error/success string
  1450    */
  1450    */
  1451    
  1451    
  1452   function flushlogs($page_id, $namespace)
  1452   public static function flushlogs($page_id, $namespace)
  1453   {
  1453   {
  1454     global $db, $session, $paths, $template, $plugins; // Common objects
  1454     global $db, $session, $paths, $template, $plugins; // Common objects
  1455     global $lang;
  1455     global $lang;
  1456     if ( !is_object($lang) && defined('IN_ENANO_INSTALL') )
  1456     if ( !is_object($lang) && defined('IN_ENANO_INSTALL') )
  1457     {
  1457     {
  1486    * @param string $namespace the condemned namespace
  1486    * @param string $namespace the condemned namespace
  1487    * @param string The reason for deleting the page in question
  1487    * @param string The reason for deleting the page in question
  1488    * @return string
  1488    * @return string
  1489    */
  1489    */
  1490    
  1490    
  1491   function deletepage($page_id, $namespace, $reason)
  1491   public static function deletepage($page_id, $namespace, $reason)
  1492   {
  1492   {
  1493     global $db, $session, $paths, $template, $plugins; // Common objects
  1493     global $db, $session, $paths, $template, $plugins; // Common objects
  1494     global $lang;
  1494     global $lang;
  1495     $perms = $session->fetch_page_acl($page_id, $namespace);
  1495     $perms = $session->fetch_page_acl($page_id, $namespace);
  1496     $x = trim($reason);
  1496     $x = trim($reason);
  1519    * @param $page_id the page ID
  1519    * @param $page_id the page ID
  1520    * @param $namespace the namespace
  1520    * @param $namespace the namespace
  1521    * @return string
  1521    * @return string
  1522    */
  1522    */
  1523    
  1523    
  1524   function delvote($page_id, $namespace)
  1524   public static function delvote($page_id, $namespace)
  1525   {
  1525   {
  1526     global $db, $session, $paths, $template, $plugins; // Common objects
  1526     global $db, $session, $paths, $template, $plugins; // Common objects
  1527     global $lang;
  1527     global $lang;
  1528     if ( !$session->get_permissions('vote_delete') )
  1528     if ( !$session->get_permissions('vote_delete') )
  1529     {
  1529     {
  1586    * @param $page_id the page ID
  1586    * @param $page_id the page ID
  1587    * @param $namespace the namespace
  1587    * @param $namespace the namespace
  1588    * @return string
  1588    * @return string
  1589    */
  1589    */
  1590   
  1590   
  1591   function resetdelvotes($page_id, $namespace)
  1591   public static function resetdelvotes($page_id, $namespace)
  1592   {
  1592   {
  1593     global $db, $session, $paths, $template, $plugins; // Common objects
  1593     global $db, $session, $paths, $template, $plugins; // Common objects
  1594     global $lang;
  1594     global $lang;
  1595     if(!$session->get_permissions('vote_reset'))
  1595     if(!$session->get_permissions('vote_reset'))
  1596     {
  1596     {
  1609    * Gets a list of styles for a given theme name. As of Banshee, this returns JSON.
  1609    * Gets a list of styles for a given theme name. As of Banshee, this returns JSON.
  1610    * @param $id the name of the directory for the theme
  1610    * @param $id the name of the directory for the theme
  1611    * @return string JSON string with an array containing a list of themes
  1611    * @return string JSON string with an array containing a list of themes
  1612    */
  1612    */
  1613    
  1613    
  1614   function getstyles()
  1614   public static function getstyles()
  1615   {
  1615   {
  1616     
  1616     
  1617     if ( !preg_match('/^([a-z0-9_-]+)$/', $_GET['id']) )
  1617     if ( !preg_match('/^([a-z0-9_-]+)$/', $_GET['id']) )
  1618       return enano_json_encode(false);
  1618       return enano_json_encode(false);
  1619     
  1619     
  1646    * @param $page_id the page ID
  1646    * @param $page_id the page ID
  1647    * @param $namespace the namespace
  1647    * @param $namespace the namespace
  1648    * @return string Javascript code
  1648    * @return string Javascript code
  1649    */
  1649    */
  1650    
  1650    
  1651   function catedit($page_id, $namespace)
  1651   public static function catedit($page_id, $namespace)
  1652   {
  1652   {
  1653     $d = PageUtils::catedit_raw($page_id, $namespace);
  1653     $d = PageUtils::catedit_raw($page_id, $namespace);
  1654     return $d[0] . ' /* BEGIN CONTENT */ document.getElementById("ajaxEditContainer").innerHTML = unescape(\''.rawurlencode($d[1]).'\');';
  1654     return $d[0] . ' /* BEGIN CONTENT */ document.getElementById("ajaxEditContainer").innerHTML = unescape(\''.rawurlencode($d[1]).'\');';
  1655   }
  1655   }
  1656   
  1656   
  1657   /**
  1657   /**
  1658    * Does the actual HTML/javascript generation for cat editing, but returns an array
  1658    * Does the actual HTML/javascript generation for cat editing, but returns an array
  1659    * @access private
  1659    * @access private
  1660    */
  1660    */
  1661    
  1661    
  1662   function catedit_raw($page_id, $namespace)
  1662   public static function catedit_raw($page_id, $namespace)
  1663   {
  1663   {
  1664     global $db, $session, $paths, $template, $plugins; // Common objects
  1664     global $db, $session, $paths, $template, $plugins; // Common objects
  1665     global $lang;
  1665     global $lang;
  1666     
  1666     
  1667     ob_start();
  1667     ob_start();
  1740    * @param $namespace string the namespace
  1740    * @param $namespace string the namespace
  1741    * @param $which_cats array associative array of categories to put the page in
  1741    * @param $which_cats array associative array of categories to put the page in
  1742    * @return string "GOOD" on success, error string on failure
  1742    * @return string "GOOD" on success, error string on failure
  1743    */
  1743    */
  1744   
  1744   
  1745   function catsave($page_id, $namespace, $which_cats)
  1745   public static function catsave($page_id, $namespace, $which_cats)
  1746   {
  1746   {
  1747     global $db, $session, $paths, $template, $plugins; // Common objects
  1747     global $db, $session, $paths, $template, $plugins; // Common objects
  1748     if(!$session->get_permissions('edit_cat')) return('Insufficient privileges to change category information');
  1748     if(!$session->get_permissions('edit_cat')) return('Insufficient privileges to change category information');
  1749     
  1749     
  1750     $page_perms = $session->fetch_page_acl($page_id, $namespace);
  1750     $page_perms = $session->fetch_page_acl($page_id, $namespace);
  1812    * @param $namespace string the namespace
  1812    * @param $namespace string the namespace
  1813    * @param $level int 0 for off, 1 for on, 2 for use global setting
  1813    * @param $level int 0 for off, 1 for on, 2 for use global setting
  1814    * @return string "GOOD" on success, error string on failure
  1814    * @return string "GOOD" on success, error string on failure
  1815    */
  1815    */
  1816   
  1816   
  1817   function setwikimode($page_id, $namespace, $level)
  1817   public static function setwikimode($page_id, $namespace, $level)
  1818   {
  1818   {
  1819     global $db, $session, $paths, $template, $plugins; // Common objects
  1819     global $db, $session, $paths, $template, $plugins; // Common objects
  1820     if(!$session->get_permissions('set_wiki_mode')) return('Insufficient access rights');
  1820     if(!$session->get_permissions('set_wiki_mode')) return('Insufficient access rights');
  1821     if ( !isset($level) || ( isset($level) && !preg_match('#^([0-2]){1}$#', (string)$level) ) )
  1821     if ( !isset($level) || ( isset($level) && !preg_match('#^([0-2]){1}$#', (string)$level) ) )
  1822     {
  1822     {
  1836    * @param $namespace string the namespace
  1836    * @param $namespace string the namespace
  1837    * @param $pass string the SHA1 hash of the password - if the password doesn't match the regex ^([0-9a-f]*){40,40}$ it will be sha1'ed
  1837    * @param $pass string the SHA1 hash of the password - if the password doesn't match the regex ^([0-9a-f]*){40,40}$ it will be sha1'ed
  1838    * @return string
  1838    * @return string
  1839    */
  1839    */
  1840   
  1840   
  1841   function setpass($page_id, $namespace, $pass)
  1841   public static function setpass($page_id, $namespace, $pass)
  1842   {
  1842   {
  1843     global $db, $session, $paths, $template, $plugins; // Common objects
  1843     global $db, $session, $paths, $template, $plugins; // Common objects
  1844     global $lang;
  1844     global $lang;
  1845     // Determine permissions
  1845     // Determine permissions
  1846     if($paths->pages[$paths->nslist[$namespace].$page_id]['password'] != '')
  1846     if($paths->pages[$paths->nslist[$namespace].$page_id]['password'] != '')
  1878    * Generates some preview HTML
  1878    * Generates some preview HTML
  1879    * @param $text string the wikitext to use
  1879    * @param $text string the wikitext to use
  1880    * @return string
  1880    * @return string
  1881    */
  1881    */
  1882    
  1882    
  1883   function genPreview($text)
  1883   public static function genPreview($text)
  1884   {
  1884   {
  1885     global $lang;
  1885     global $lang;
  1886     $ret = '<div class="info-box">' . $lang->get('editor_preview_blurb') . '</div><div style="background-color: #F8F8F8; padding: 10px; border: 1px dashed #406080; max-height: 250px; overflow: auto; margin: 10px 0;">';
  1886     $ret = '<div class="info-box">' . $lang->get('editor_preview_blurb') . '</div><div style="background-color: #F8F8F8; padding: 10px; border: 1px dashed #406080; max-height: 250px; overflow: auto; margin: 10px 0;">';
  1887     $text = RenderMan::render(RenderMan::preprocess_text($text, false, false));
  1887     $text = RenderMan::render(RenderMan::preprocess_text($text, false, false));
  1888     ob_start();
  1888     ob_start();
  1899    * @param string $text the inner HTML
  1899    * @param string $text the inner HTML
  1900    * @param int $height Optional - the maximum height. Defaults to 250.
  1900    * @param int $height Optional - the maximum height. Defaults to 250.
  1901    * @return string
  1901    * @return string
  1902    */
  1902    */
  1903    
  1903    
  1904   function scrollBox($text, $height = 250)
  1904   public static function scrollBox($text, $height = 250)
  1905   {
  1905   {
  1906     return '<div style="background-color: #F8F8F8; padding: 10px; border: 1px dashed #406080; max-height: '.(string)intval($height).'px; overflow: auto; margin: 1em 0 1em 1em;">' . $text . '</div>';
  1906     return '<div style="background-color: #F8F8F8; padding: 10px; border: 1px dashed #406080; max-height: '.(string)intval($height).'px; overflow: auto; margin: 1em 0 1em 1em;">' . $text . '</div>';
  1907   }
  1907   }
  1908   
  1908   
  1909   /**
  1909   /**
  1913    * @param $id1 the time ID of the first revision
  1913    * @param $id1 the time ID of the first revision
  1914    * @param $id2 the time ID of the second revision
  1914    * @param $id2 the time ID of the second revision
  1915    * @return string XHTML-formatted diff
  1915    * @return string XHTML-formatted diff
  1916    */
  1916    */
  1917    
  1917    
  1918   function pagediff($page_id, $namespace, $id1, $id2)
  1918   public static function pagediff($page_id, $namespace, $id1, $id2)
  1919   {
  1919   {
  1920     global $db, $session, $paths, $template, $plugins; // Common objects
  1920     global $db, $session, $paths, $template, $plugins; // Common objects
  1921     global $lang;
  1921     global $lang;
  1922     if(!$session->get_permissions('history_view'))
  1922     if(!$session->get_permissions('history_view'))
  1923       return $lang->get('etc_access_denied');
  1923       return $lang->get('etc_access_denied');
  1950    * Gets ACL information about the selected page for target type X and target ID Y.
  1950    * Gets ACL information about the selected page for target type X and target ID Y.
  1951    * @param array $parms What to select. This is an array purely for JSON compatibility. It should be an associative array with keys target_type and target_id.
  1951    * @param array $parms What to select. This is an array purely for JSON compatibility. It should be an associative array with keys target_type and target_id.
  1952    * @return array
  1952    * @return array
  1953    */
  1953    */
  1954    
  1954    
  1955   function acl_editor($parms = Array())
  1955   public static function acl_editor($parms = Array())
  1956   {
  1956   {
  1957     global $db, $session, $paths, $template, $plugins; // Common objects
  1957     global $db, $session, $paths, $template, $plugins; // Common objects
  1958     global $lang;
  1958     global $lang;
  1959     
  1959     
  1960     if(!$session->get_permissions('edit_acl') && $session->user_level < USER_LEVEL_ADMIN)
  1960     if(!$session->get_permissions('edit_acl') && $session->user_level < USER_LEVEL_ADMIN)
  2192    * Same as PageUtils::acl_editor(), but the parms are a JSON string instead of an array. This also returns a JSON string.
  2192    * Same as PageUtils::acl_editor(), but the parms are a JSON string instead of an array. This also returns a JSON string.
  2193    * @param string $parms Same as PageUtils::acl_editor/$parms, but should be a valid JSON string.
  2193    * @param string $parms Same as PageUtils::acl_editor/$parms, but should be a valid JSON string.
  2194    * @return string
  2194    * @return string
  2195    */
  2195    */
  2196    
  2196    
  2197   function acl_json($parms = '{ }')
  2197   public static function acl_json($parms = '{ }')
  2198   {
  2198   {
  2199     global $db, $session, $paths, $template, $plugins; // Common objects
  2199     global $db, $session, $paths, $template, $plugins; // Common objects
  2200     $parms = enano_json_decode($parms);
  2200     $parms = enano_json_decode($parms);
  2201     $ret = PageUtils::acl_editor($parms);
  2201     $ret = PageUtils::acl_editor($parms);
  2202     $ret = enano_json_encode($ret);
  2202     $ret = enano_json_encode($ret);
  2206   /**
  2206   /**
  2207    * A non-Javascript frontend for the ACL API.
  2207    * A non-Javascript frontend for the ACL API.
  2208    * @param array The request data, if any, this should be in the format required by PageUtils::acl_editor()
  2208    * @param array The request data, if any, this should be in the format required by PageUtils::acl_editor()
  2209    */
  2209    */
  2210    
  2210    
  2211   function aclmanager($parms)
  2211   public static function aclmanager($parms)
  2212   {
  2212   {
  2213     global $db, $session, $paths, $template, $plugins; // Common objects
  2213     global $db, $session, $paths, $template, $plugins; // Common objects
  2214     global $lang;
  2214     global $lang;
  2215     ob_start();
  2215     ob_start();
  2216     // Convenience
  2216     // Convenience
  2398    * @param array The posted data
  2398    * @param array The posted data
  2399    * @return array
  2399    * @return array
  2400    * @access private
  2400    * @access private
  2401    */
  2401    */
  2402    
  2402    
  2403   function acl_preprocess($parms)
  2403   public static function acl_preprocess($parms)
  2404   {
  2404   {
  2405     if ( !isset($parms['mode']) )
  2405     if ( !isset($parms['mode']) )
  2406       // Nothing to do
  2406       // Nothing to do
  2407       return $parms;
  2407       return $parms;
  2408     switch ( $parms['mode'] )
  2408     switch ( $parms['mode'] )
  2443     }
  2443     }
  2444     
  2444     
  2445     return $parms;
  2445     return $parms;
  2446   }
  2446   }
  2447   
  2447   
  2448   function acl_postprocess($response)
  2448   public static function acl_postprocess($response)
  2449   {
  2449   {
  2450     if(!isset($response['mode']))
  2450     if(!isset($response['mode']))
  2451     {
  2451     {
  2452       if ( isset($response['groups']) )
  2452       if ( isset($response['groups']) )
  2453         $response['mode'] = 'stage1';
  2453         $response['mode'] = 'stage1';