includes/pageutils.php
changeset 112 008b1c42be72
parent 103 a8891e108c95
child 115 261f367623af
equal deleted inserted replaced
111:b348ace50bc7 112:008b1c42be72
   403     
   403     
   404     $page_id = sanitize_page_id( $page_id );
   404     $page_id = sanitize_page_id( $page_id );
   405     
   405     
   406     $prot = ( $namespace == 'System' ) ? 1 : 0;
   406     $prot = ( $namespace == 'System' ) ? 1 : 0;
   407     
   407     
       
   408     $ips = array(
       
   409       'ip' => array(),
       
   410       'u' => array()
       
   411       );
       
   412     
   408     $page_data = Array(
   413     $page_data = Array(
   409       'name'=>$name,
   414       'name'=>$name,
   410       'urlname'=>$page_id,
   415       'urlname'=>$page_id,
   411       'namespace'=>$namespace,
   416       'namespace'=>$namespace,
   412       'special'=>0,'visible'=>1,'comments_on'=>0,'protected'=>$prot,'delvotes'=>0,'delvote_ips'=>'','wiki_mode'=>2,
   417       'special'=>0,'visible'=>1,'comments_on'=>0,'protected'=>$prot,'delvotes'=>0,'delvote_ips'=>serialize($ips),'wiki_mode'=>2,
   413     );
   418     );
   414     
   419     
   415     // die('PageUtils::createpage: Creating page with this data:<pre>' . print_r($page_data, true) . '</pre>');
   420     // die('PageUtils::createpage: Creating page with this data:<pre>' . print_r($page_data, true) . '</pre>');
   416     
   421     
   417     $paths->add_page($page_data);
   422     $paths->add_page($page_data);
   418     
   423     
   419     $qa = $db->sql_query('INSERT INTO '.table_prefix.'pages(name,urlname,namespace,visible,protected) VALUES(\''.$db->escape($name).'\', \''.$db->escape($page_id).'\', \''.$namespace.'\', '. ( $visible ? '1' : '0' ) .', '.$prot.');');
   424     $qa = $db->sql_query('INSERT INTO '.table_prefix.'pages(name,urlname,namespace,visible,protected,delvote_ips) VALUES(\''.$db->escape($name).'\', \''.$db->escape($page_id).'\', \''.$namespace.'\', '. ( $visible ? '1' : '0' ) .', '.$prot.', \'' . $db->escape(serialize($ips)) . '\');');
   420     $qb = $db->sql_query('INSERT INTO '.table_prefix.'page_text(page_id,namespace) VALUES(\''.$db->escape($page_id).'\', \''.$namespace.'\');');
   425     $qb = $db->sql_query('INSERT INTO '.table_prefix.'page_text(page_id,namespace) VALUES(\''.$db->escape($page_id).'\', \''.$namespace.'\');');
   421     $qc = $db->sql_query('INSERT INTO '.table_prefix.'logs(time_id,date_string,log_type,action,author,page_id,namespace) VALUES('.time().', \''.date('d M Y h:i a').'\', \'page\', \'create\', \''.$session->username.'\', \''.$db->escape($page_id).'\', \''.$namespace.'\');');
   426     $qc = $db->sql_query('INSERT INTO '.table_prefix.'logs(time_id,date_string,log_type,action,author,page_id,namespace) VALUES('.time().', \''.date('d M Y h:i a').'\', \'page\', \'create\', \''.$session->username.'\', \''.$db->escape($page_id).'\', \''.$namespace.'\');');
   422     
   427     
   423     if($qa && $qb && $qc)
   428     if($qa && $qb && $qc)
   424       return true;
   429       return true;
  1300    */
  1305    */
  1301    
  1306    
  1302   function delvote($page_id, $namespace)
  1307   function delvote($page_id, $namespace)
  1303   {
  1308   {
  1304     global $db, $session, $paths, $template, $plugins; // Common objects
  1309     global $db, $session, $paths, $template, $plugins; // Common objects
  1305     if(!$session->get_permissions('vote_delete'))
  1310     if ( !$session->get_permissions('vote_delete') )
       
  1311     {
  1306       return 'Access denied';
  1312       return 'Access denied';
  1307     $pname = $paths->nslist[$namespace] . $page_id;
  1313     }
  1308     $cv = $paths->pages[$pname]['delvotes'];
  1314     
  1309     $ips = $paths->pages[$pname]['delvote_ips'];
  1315     if ( $namespace == 'Admin' || $namespace == 'Special' || $namespace == 'System' )
  1310     $ips = explode('|', $ips);
  1316     {
  1311     if(in_array($_SERVER['REMOTE_ADDR'], $ips)) return('It appears that you have already voted to have this page deleted.');
  1317       return 'Special pages and system messages can\'t be voted for deletion.';
  1312     if($session->user_logged_in)
  1318     }
  1313       if(in_array($session->username, $ips))
  1319     
  1314         return('It appears that you have already voted to have this page deleted.');
  1320     $pname = $paths->nslist[$namespace] . sanitize_page_id($page_id);
  1315     $ips[] = $_SERVER['REMOTE_ADDR'];
  1321     
  1316     if($session->user_logged_in) $ips[] = $session->username;
  1322     if ( !isset($paths->pages[$pname]) )
  1317     $ips = implode('|', $ips);
  1323     {
  1318     $ips = substr($ips, 1, strlen($ips));
  1324       return 'The page does not exist.';
       
  1325     }
       
  1326     
       
  1327     $cv  =& $paths->pages[$pname]['delvotes'];
       
  1328     $ips =  $paths->pages[$pname]['delvote_ips'];
       
  1329     
       
  1330     if ( empty($ips) )
       
  1331     {
       
  1332       $ips = array(
       
  1333         'ip' => array(),
       
  1334         'u' => array()
       
  1335         );
       
  1336     }
       
  1337     else
       
  1338     {
       
  1339       $ips = @unserialize($ips);
       
  1340       if ( !$ips )
       
  1341       {
       
  1342         $ips = array(
       
  1343         'ip' => array(),
       
  1344         'u' => array()
       
  1345         );
       
  1346       }
       
  1347     }
       
  1348     
       
  1349     if ( in_array($session->username, $ips['u']) || in_array($_SERVER['REMOTE_ADDR'], $ips['ip']) )
       
  1350     {
       
  1351       return 'It appears that you have already voted to have this page deleted.';
       
  1352     }
       
  1353     
       
  1354     $ips['u'][] = $session->username;
       
  1355     $ips['ip'][] = $_SERVER['REMOTE_ADDR'];
       
  1356     $ips = $db->escape( serialize($ips) );
       
  1357     
  1319     $cv++;
  1358     $cv++;
       
  1359     
  1320     $q = 'UPDATE '.table_prefix.'pages SET delvotes='.$cv.',delvote_ips=\''.$ips.'\' WHERE urlname=\''.$page_id.'\' AND namespace=\''.$namespace.'\'';
  1360     $q = 'UPDATE '.table_prefix.'pages SET delvotes='.$cv.',delvote_ips=\''.$ips.'\' WHERE urlname=\''.$page_id.'\' AND namespace=\''.$namespace.'\'';
  1321     $w = $db->sql_query($q);
  1361     $w = $db->sql_query($q);
  1322     if(!$w) return("Error updating pages table: ".mysql_error()."\n\nAttemped SQL:\n".$q);
  1362     
  1323     return('Your vote to have this page deleted has been cast.'."\nYou are encouraged to leave a comment explaining the reason for your vote.");
  1363     return 'Your vote to have this page deleted has been cast.'."\nYou are encouraged to leave a comment explaining the reason for your vote.";
  1324   }
  1364   }
  1325   
  1365   
  1326   /**
  1366   /**
  1327    * Resets the number of votes against a page to 0.
  1367    * Resets the number of votes against a page to 0.
  1328    * @param $page_id the page ID
  1368    * @param $page_id the page ID
  1332   
  1372   
  1333   function resetdelvotes($page_id, $namespace)
  1373   function resetdelvotes($page_id, $namespace)
  1334   {
  1374   {
  1335     global $db, $session, $paths, $template, $plugins; // Common objects
  1375     global $db, $session, $paths, $template, $plugins; // Common objects
  1336     if(!$session->get_permissions('vote_reset')) die('You need moderator rights in order to do this, stinkin\' hacker.');
  1376     if(!$session->get_permissions('vote_reset')) die('You need moderator rights in order to do this, stinkin\' hacker.');
  1337     $q = 'UPDATE '.table_prefix.'pages SET delvotes=0,delvote_ips=\'\' WHERE urlname=\''.$page_id.'\' AND namespace=\''.$namespace.'\'';
  1377     $q = 'UPDATE '.table_prefix.'pages SET delvotes=0,delvote_ips=\'' . $db->escape(serialize(array('ip'=>array(),'u'=>array()))) . '\' WHERE urlname=\''.$page_id.'\' AND namespace=\''.$namespace.'\'';
  1338     $e = $db->sql_query($q);
  1378     $e = $db->sql_query($q);
  1339     if(!$e) $db->_die('The number of delete votes was not reset.');
  1379     if(!$e) $db->_die('The number of delete votes was not reset.');
  1340     else return('The number of votes for having this page deleted has been reset to zero.');
  1380     else return('The number of votes for having this page deleted has been reset to zero.');
  1341   }
  1381   }
  1342   
  1382