1
+ − 1
<?php
+ − 2
/*
+ − 3
* Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 4
* Version 1.0 (Banshee)
1
+ − 5
* Copyright (C) 2006-2007 Dan Fuhry
+ − 6
* pageutils.php - a class that handles raw page manipulations, used mostly by AJAX requests or their old-fashioned form-based counterparts
+ − 7
*
+ − 8
* This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
+ − 9
* as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
+ − 10
*
+ − 11
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ − 12
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
+ − 13
*/
+ − 14
+ − 15
class PageUtils {
+ − 16
+ − 17
/**
+ − 18
* List possible username completions
+ − 19
* @param $name the name to check for
+ − 20
* @return array
+ − 21
*/
+ − 22
+ − 23
function checkusername($name)
+ − 24
{
+ − 25
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 26
$q = $db->sql_query('SELECT username FROM '.table_prefix.'users WHERE username=\''.$db->escape(rawurldecode($name)).'\'');
+ − 27
if(!$q) die(mysql_error());
+ − 28
if($db->numrows() < 1) { $db->free_result(); return('good'); }
+ − 29
else { $db->free_result(); return('bad'); }
+ − 30
}
+ − 31
+ − 32
/**
+ − 33
* Get the wiki formatting source for a page
+ − 34
* @param $page the full page id (Namespace:Pagename)
+ − 35
* @return string
+ − 36
* @todo (DONE) Make it require a password (just for security purposes)
+ − 37
*/
+ − 38
+ − 39
function getsource($page, $password = false)
+ − 40
{
+ − 41
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 42
if(!isset($paths->pages[$page]))
+ − 43
{
+ − 44
return '';
+ − 45
}
+ − 46
+ − 47
if(strlen($paths->pages[$page]['password']) == 40)
+ − 48
{
+ − 49
if(!$password || ( $password != $paths->pages[$page]['password']))
+ − 50
{
+ − 51
return 'invalid_password';
+ − 52
}
+ − 53
}
+ − 54
+ − 55
if(!$session->get_permissions('view_source')) // Dependencies handle this for us - this also checks for read privileges
+ − 56
return 'access_denied';
+ − 57
$pid = RenderMan::strToPageID($page);
+ − 58
if($pid[1] == 'Special' || $pid[1] == 'Admin')
+ − 59
{
+ − 60
die('This type of page ('.$paths->nslist[$pid[1]].') cannot be edited because the page source code is not stored in the database.');
+ − 61
}
+ − 62
+ − 63
$e = $db->sql_query('SELECT page_text,char_tag FROM '.table_prefix.'page_text WHERE page_id=\''.$pid[0].'\' AND namespace=\''.$pid[1].'\'');
+ − 64
if ( !$e )
+ − 65
{
+ − 66
$db->_die('The page text could not be selected.');
+ − 67
}
+ − 68
if( $db->numrows() < 1 )
+ − 69
{
+ − 70
return ''; //$db->_die('There were no rows in the text table that matched the page text query.');
+ − 71
}
+ − 72
+ − 73
$r = $db->fetchrow();
+ − 74
$db->free_result();
+ − 75
$message = $r['page_text'];
+ − 76
+ − 77
return htmlspecialchars($message);
+ − 78
}
+ − 79
+ − 80
/**
+ − 81
* Basically a frontend to RenderMan::getPage(), with the ability to send valid data for nonexistent pages
+ − 82
* @param $page the full page id (Namespace:Pagename)
+ − 83
* @param $send_headers true if the theme headers should be sent (still dependent on current page settings), false otherwise
+ − 84
* @return string
+ − 85
*/
+ − 86
+ − 87
function getpage($page, $send_headers = false, $hist_id = false)
+ − 88
{
+ − 89
die('PageUtils->getpage is deprecated.');
+ − 90
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 91
ob_start();
+ − 92
$pid = RenderMan::strToPageID($page);
+ − 93
//die('<pre>'.print_r($pid, true).'</pre>');
+ − 94
if(isset($paths->pages[$page]['password']) && strlen($paths->pages[$page]['password']) == 40)
+ − 95
{
+ − 96
password_prompt($page);
+ − 97
}
+ − 98
if(isset($paths->pages[$page]))
+ − 99
{
+ − 100
doStats($pid[0], $pid[1]);
+ − 101
}
+ − 102
if($paths->custom_page || $pid[1] == 'Special')
+ − 103
{
+ − 104
// If we don't have access to the page, get out and quick!
+ − 105
if(!$session->get_permissions('read') && $pid[0] != 'Login' && $pid[0] != 'Register')
+ − 106
{
+ − 107
$template->tpl_strings['PAGE_NAME'] = 'Access denied';
+ − 108
+ − 109
if ( $send_headers )
+ − 110
{
+ − 111
$template->header();
+ − 112
}
+ − 113
+ − 114
echo '<div class="error-box"><b>Access to this page is denied.</b><br />This may be because you are not logged in or you have not met certain criteria for viewing this page.</div>';
+ − 115
+ − 116
if ( $send_headers )
+ − 117
{
+ − 118
$template->footer();
+ − 119
}
+ − 120
+ − 121
$r = ob_get_contents();
+ − 122
ob_end_clean();
+ − 123
return $r;
+ − 124
}
+ − 125
+ − 126
$fname = 'page_'.$pid[1].'_'.$paths->pages[$page]['urlname_nons'];
+ − 127
@call_user_func($fname);
+ − 128
+ − 129
}
+ − 130
else if ( $pid[1] == 'Admin' )
+ − 131
{
+ − 132
// If we don't have access to the page, get out and quick!
+ − 133
if(!$session->get_permissions('read'))
+ − 134
{
+ − 135
$template->tpl_strings['PAGE_NAME'] = 'Access denied';
+ − 136
if ( $send_headers )
+ − 137
{
+ − 138
$template->header();
+ − 139
}
+ − 140
echo '<div class="error-box"><b>Access to this page is denied.</b><br />This may be because you are not logged in or you have not met certain criteria for viewing this page.</div>';
+ − 141
if ( $send_headers )
+ − 142
{
+ − 143
$template->footer();
+ − 144
}
+ − 145
$r = ob_get_contents();
+ − 146
ob_end_clean();
+ − 147
return $r;
+ − 148
}
+ − 149
+ − 150
$fname = 'page_'.$pid[1].'_'.$pid[0];
+ − 151
if ( !function_exists($fname) )
+ − 152
{
+ − 153
$title = 'Page backend not found';
+ − 154
$message = "The administration page you are looking for was properly registered using the page API, but the backend function
+ − 155
(<tt>$fname</tt>) was not found. If this is a plugin page, then this is almost certainly a bug with the plugin.";
+ − 156
if ( $send_headers )
+ − 157
{
+ − 158
die_friendly($title, "<p>$message</p>");
+ − 159
}
+ − 160
else
+ − 161
{
+ − 162
echo "<h2>$title</h2>\n<p>$message</p>";
+ − 163
}
+ − 164
}
+ − 165
@call_user_func($fname);
+ − 166
}
+ − 167
else if ( !isset( $paths->pages[$page] ) )
+ − 168
{
+ − 169
ob_start();
+ − 170
$code = $plugins->setHook('page_not_found');
+ − 171
foreach ( $code as $cmd )
+ − 172
{
+ − 173
eval($cmd);
+ − 174
}
+ − 175
$text = ob_get_contents();
+ − 176
if ( $text != '' )
+ − 177
{
+ − 178
ob_end_clean();
+ − 179
return $text;
+ − 180
}
+ − 181
$template->header();
+ − 182
if($m = $paths->sysmsg('Page_not_found'))
+ − 183
{
+ − 184
eval('?>'.RenderMan::render($m));
+ − 185
}
+ − 186
else
+ − 187
{
+ − 188
header('HTTP/1.1 404 Not Found');
+ − 189
echo '<h3>There is no page with this title yet.</h3>
+ − 190
<p>You have requested a page that doesn\'t exist yet.';
+ − 191
if($session->get_permissions('create_page')) echo ' You can <a href="'.makeUrl($paths->page, 'do=edit', true).'" onclick="ajaxEditor(); return false;">create this page</a>, or return to the <a href="'.makeUrl(getConfig('main_page')).'">homepage</a>.';
+ − 192
else echo ' Return to the <a href="'.makeUrl(getConfig('main_page')).'">homepage</a>.</p>';
+ − 193
if($session->get_permissions('history_rollback')) {
+ − 194
$e = $db->sql_query('SELECT * FROM '.table_prefix.'logs WHERE action=\'delete\' AND page_id=\''.$paths->cpage['urlname_nons'].'\' AND namespace=\''.$pid[1].'\' ORDER BY time_id DESC;');
+ − 195
if(!$e) $db->_die('The deletion log could not be selected.');
+ − 196
if($db->numrows() > 0) {
+ − 197
$r = $db->fetchrow();
+ − 198
echo '<p>This page also appears to have some log entries in the database - it seems that it was deleted on '.$r['date_string'].'. You can probably <a href="'.makeUrl($paths->page, 'do=rollback&id='.$r['time_id']).'" onclick="ajaxRollback(\''.$r['time_id'].'\'); return false;">roll back</a> the deletion.</p>';
+ − 199
}
+ − 200
$db->free_result();
+ − 201
}
+ − 202
echo '<p>
+ − 203
HTTP Error: 404 Not Found
+ − 204
</p>';
+ − 205
}
+ − 206
$template->footer();
+ − 207
}
+ − 208
else
+ − 209
{
+ − 210
+ − 211
// If we don't have access to the page, get out and quick!
+ − 212
if(!$session->get_permissions('read'))
+ − 213
{
+ − 214
$template->tpl_strings['PAGE_NAME'] = 'Access denied';
+ − 215
if($send_headers) $template->header();
+ − 216
echo '<div class="error-box"><b>Access to this page is denied.</b><br />This may be because you are not logged in or you have not met certain criteria for viewing this page.</div>';
+ − 217
if($send_headers) $template->footer();
+ − 218
$r = ob_get_contents();
+ − 219
ob_end_clean();
+ − 220
return $r;
+ − 221
}
+ − 222
+ − 223
ob_start();
+ − 224
$code = $plugins->setHook('page_custom_handler');
+ − 225
foreach ( $code as $cmd )
+ − 226
{
+ − 227
eval($cmd);
+ − 228
}
+ − 229
$text = ob_get_contents();
+ − 230
if ( $text != '' )
+ − 231
{
+ − 232
ob_end_clean();
+ − 233
return $text;
+ − 234
}
+ − 235
+ − 236
if($hist_id) {
+ − 237
$e = $db->sql_query('SELECT page_text,date_string,char_tag FROM '.table_prefix.'logs WHERE page_id=\''.$paths->pages[$page]['urlname_nons'].'\' AND namespace=\''.$pid[1].'\' AND log_type=\'page\' AND action=\'edit\' AND time_id='.$db->escape($hist_id).'');
+ − 238
if($db->numrows() < 1)
+ − 239
{
+ − 240
$db->_die('There were no rows in the text table that matched the page text query.');
+ − 241
}
+ − 242
$r = $db->fetchrow();
+ − 243
$db->free_result();
+ − 244
$message = '<div class="info-box" style="margin-left: 0; margin-top: 5px;"><b>Notice:</b><br />The page you are viewing was archived on '.$r['date_string'].'.<br /><a href="'.makeUrl($page).'" onclick="ajaxReset(); return false;">View current version</a> | <a href="'.makeUrl($page, 'do=rollback&id='.$hist_id).'" onclick="ajaxRollback(\''.$hist_id.'\')">Restore this version</a></div><br />'.RenderMan::render($r['page_text']);
+ − 245
+ − 246
if( !$paths->pages[$page]['special'] )
+ − 247
{
+ − 248
if($send_headers)
+ − 249
{
+ − 250
$template->header();
+ − 251
}
+ − 252
display_page_headers();
+ − 253
}
+ − 254
+ − 255
eval('?>'.$message);
+ − 256
+ − 257
if( !$paths->pages[$page]['special'] )
+ − 258
{
+ − 259
display_page_footers();
+ − 260
if($send_headers)
+ − 261
{
+ − 262
$template->footer();
+ − 263
}
+ − 264
}
+ − 265
+ − 266
} else {
+ − 267
if(!$paths->pages[$page]['special'])
+ − 268
{
+ − 269
$message = RenderMan::getPage($paths->pages[$page]['urlname_nons'], $pid[1]);
+ − 270
}
+ − 271
else
+ − 272
{
+ − 273
$message = RenderMan::getPage($paths->pages[$page]['urlname_nons'], $pid[1], 0, false, false, false, false);
+ − 274
}
+ − 275
// This line is used to debug wikiformatted code
+ − 276
// die('<pre>'.htmlspecialchars($message).'</pre>');
+ − 277
+ − 278
if( !$paths->pages[$page]['special'] )
+ − 279
{
+ − 280
if($send_headers)
+ − 281
{
+ − 282
$template->header();
+ − 283
}
+ − 284
display_page_headers();
+ − 285
}
+ − 286
+ − 287
// This is it, this is what all of Enano has been working up to...
+ − 288
+ − 289
eval('?>'.$message);
+ − 290
+ − 291
if( !$paths->pages[$page]['special'] )
+ − 292
{
+ − 293
display_page_footers();
+ − 294
if($send_headers)
+ − 295
{
+ − 296
$template->footer();
+ − 297
}
+ − 298
}
+ − 299
}
+ − 300
}
+ − 301
$ret = ob_get_contents();
+ − 302
ob_end_clean();
+ − 303
return $ret;
+ − 304
}
+ − 305
+ − 306
/**
+ − 307
* Writes page data to the database, after verifying permissions and running the XSS filter
+ − 308
* @param $page_id the page ID
+ − 309
* @param $namespace the namespace
+ − 310
* @param $message the text to save
+ − 311
* @return string
+ − 312
*/
+ − 313
+ − 314
function savepage($page_id, $namespace, $message, $summary = 'No edit summary given', $minor = false)
+ − 315
{
+ − 316
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 317
$uid = sha1(microtime());
+ − 318
$pname = $paths->nslist[$namespace] . $page_id;
+ − 319
+ − 320
if(!$session->get_permissions('edit_page'))
+ − 321
return 'Access to edit pages is denied.';
+ − 322
+ − 323
if(!isset($paths->pages[$pname]))
+ − 324
{
+ − 325
if(!PageUtils::createPage($page_id, $namespace))
+ − 326
return 'The page did not exist, and I was not able to create it. Permissions problem?';
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 327
$paths->page_exists = true;
1
+ − 328
}
+ − 329
+ − 330
$prot = ( ( $paths->pages[$pname]['protected'] == 2 && $session->user_logged_in && $session->reg_time + 60*60*24*4 < time() ) || $paths->pages[$pname]['protected'] == 1) ? true : false;
+ − 331
$wiki = ( ( $paths->pages[$pname]['wiki_mode'] == 2 && getConfig('wiki_mode') == '1') || $paths->pages[$pname]['wiki_mode'] == 1) ? true : false;
+ − 332
if(($prot || !$wiki) && $session->user_level < USER_LEVEL_ADMIN ) return('You are not authorized to edit this page.');
+ − 333
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 334
// Strip potentially harmful tags and PHP from the message, dependent upon permissions settings
1
+ − 335
$message = RenderMan::preprocess_text($message, false, false);
+ − 336
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 337
$msg = $db->escape($message);
1
+ − 338
+ − 339
$minor = $minor ? 'true' : 'false';
+ − 340
$q='INSERT INTO '.table_prefix.'logs(log_type,action,time_id,date_string,page_id,namespace,page_text,char_tag,author,edit_summary,minor_edit) VALUES(\'page\', \'edit\', '.time().', \''.date('d M Y h:i a').'\', \''.$paths->cpage['urlname_nons'].'\', \''.$paths->namespace.'\', \''.$msg.'\', \''.$uid.'\', \''.$session->username.'\', \''.$db->escape(htmlspecialchars($summary)).'\', '.$minor.');';
+ − 341
if(!$db->sql_query($q)) $db->_die('The history (log) entry could not be inserted into the logs table.');
+ − 342
+ − 343
$q = 'UPDATE '.table_prefix.'page_text SET page_text=\''.$msg.'\',char_tag=\''.$uid.'\' WHERE page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\';';
+ − 344
$e = $db->sql_query($q);
+ − 345
if(!$e) $db->_die('Enano was unable to save the page contents. Your changes have been lost <tt>:\'(</tt>.');
+ − 346
+ − 347
$paths->rebuild_page_index($page_id, $namespace);
+ − 348
+ − 349
return 'good';
+ − 350
}
+ − 351
+ − 352
/**
+ − 353
* Creates a page, both in memory and in the database.
+ − 354
* @param string $page_id
+ − 355
* @param string $namespace
+ − 356
* @return bool true on success, false on failure
+ − 357
*/
+ − 358
+ − 359
function createPage($page_id, $namespace, $name = false, $visible = 1)
+ − 360
{
+ − 361
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 362
if(in_array($namespace, Array('Special', 'Admin')))
+ − 363
{
+ − 364
// echo '<b>Notice:</b> PageUtils::createPage: You can\'t create a special page in the database<br />';
+ − 365
return false; // Can't create a special page
+ − 366
}
+ − 367
+ − 368
if(!isset($paths->nslist[$namespace]))
+ − 369
{
+ − 370
// echo '<b>Notice:</b> PageUtils::createPage: Couldn\'t look up the namespace<br />';
+ − 371
return false; // Couldn't look up namespace
+ − 372
}
+ − 373
+ − 374
$pname = $paths->nslist[$namespace] . $page_id;
+ − 375
if(isset($paths->pages[$pname]))
+ − 376
{
+ − 377
// echo '<b>Notice:</b> PageUtils::createPage: Page already exists<br />';
+ − 378
return false; // Page already exists
+ − 379
}
+ − 380
+ − 381
if(!$session->get_permissions('create_page'))
+ − 382
{
+ − 383
// echo '<b>Notice:</b> PageUtils::createPage: Not authorized to create pages<br />';
+ − 384
return false; // Access denied
+ − 385
}
+ − 386
+ − 387
if($session->user_level < USER_LEVEL_ADMIN && $namespace == 'System')
+ − 388
{
+ − 389
// echo '<b>Notice:</b> PageUtils::createPage: Not authorized to create system messages<br />';
+ − 390
return false; // Not authorized to create system messages
+ − 391
}
+ − 392
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 393
$page_id = dirtify_page_id($page_id);
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 394
1
+ − 395
if ( !$name )
+ − 396
$name = str_replace('_', ' ', $page_id);
+ − 397
$regex = '#^([A-z0-9 _\-\.\/\!\@\(\)]*)$#is';
+ − 398
if(!preg_match($regex, $page))
+ − 399
{
+ − 400
//echo '<b>Notice:</b> PageUtils::createPage: Name contains invalid characters<br />';
+ − 401
return false; // Name contains invalid characters
+ − 402
}
+ − 403
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 404
$page_id = sanitize_page_id( $page_id );
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 405
1
+ − 406
$prot = ( $namespace == 'System' ) ? 1 : 0;
+ − 407
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 408
$page_data = Array(
1
+ − 409
'name'=>$name,
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 410
'urlname'=>$page_id,
1
+ − 411
'namespace'=>$namespace,
+ − 412
'special'=>0,'visible'=>1,'comments_on'=>0,'protected'=>$prot,'delvotes'=>0,'delvote_ips'=>'','wiki_mode'=>2,
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 413
);
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 414
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 415
// die('PageUtils::createpage: Creating page with this data:<pre>' . print_r($page_data, true) . '</pre>');
1
+ − 416
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 417
$paths->add_page($page_data);
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 418
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 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.');');
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 420
$qb = $db->sql_query('INSERT INTO '.table_prefix.'page_text(page_id,namespace) VALUES(\''.$db->escape($page_id).'\', \''.$namespace.'\');');
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 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.'\');');
1
+ − 422
+ − 423
if($qa && $qb && $qc)
+ − 424
return true;
+ − 425
else
+ − 426
{
+ − 427
echo $db->get_error();
+ − 428
return false;
+ − 429
}
+ − 430
}
+ − 431
+ − 432
/**
+ − 433
* Sets the protection level on a page.
+ − 434
* @param $page_id string the page ID
+ − 435
* @param $namespace string the namespace
+ − 436
* @param $level int level of protection - 0 is off, 1 is full, 2 is semi
+ − 437
* @param $reason string why the page is being (un)protected
+ − 438
* @return string - "good" on success, in all other cases, an error string (on query failure, calls $db->_die() )
+ − 439
*/
+ − 440
function protect($page_id, $namespace, $level, $reason)
+ − 441
{
+ − 442
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 443
+ − 444
$pname = $paths->nslist[$namespace] . $page_id;
+ − 445
$wiki = ( ( $paths->pages[$pname]['wiki_mode'] == 2 && getConfig('wiki_mode') == '1') || $paths->pages[$pname]['wiki_mode'] == 1) ? true : false;
+ − 446
$prot = ( ( $paths->pages[$pname]['protected'] == 2 && $session->user_logged_in && $session->reg_time + 60*60*24*4 < time() ) || $paths->pages[$pname]['protected'] == 1) ? true : false;
+ − 447
+ − 448
if(!$session->get_permissions('protect')) return('Insufficient access rights');
+ − 449
if(!$wiki) return('Page protection only has an effect when Wiki Mode is enabled.');
+ − 450
if(!preg_match('#^([0-9]+){1}$#', (string)$level)) return('Invalid $level parameter.');
+ − 451
+ − 452
if($reason!='NO_REASON') {
+ − 453
switch($level)
+ − 454
{
+ − 455
case 0:
+ − 456
$q = 'INSERT INTO '.table_prefix.'logs(time_id,date_string,log_type,action,author,page_id,namespace,edit_summary) VALUES('.time().', \''.date('d M Y h:i a').'\', \'page\', \'unprot\', \''.$session->username.'\', \''.$page_id.'\', \''.$namespace.'\', \''.$db->escape(htmlspecialchars($reason)).'\');';
+ − 457
break;
+ − 458
case 1:
+ − 459
$q = 'INSERT INTO '.table_prefix.'logs(time_id,date_string,log_type,action,author,page_id,namespace,edit_summary) VALUES('.time().', \''.date('d M Y h:i a').'\', \'page\', \'prot\', \''.$session->username.'\', \''.$page_id.'\', \''.$namespace.'\', \''.$db->escape(htmlspecialchars($reason)).'\');';
+ − 460
break;
+ − 461
case 2:
+ − 462
$q = 'INSERT INTO '.table_prefix.'logs(time_id,date_string,log_type,action,author,page_id,namespace,edit_summary) VALUES('.time().', \''.date('d M Y h:i a').'\', \'page\', \'semiprot\', \''.$session->username.'\', \''.$page_id.'\', \''.$namespace.'\', \''.$db->escape(htmlspecialchars($reason)).'\');';
+ − 463
break;
+ − 464
default:
+ − 465
return 'PageUtils::protect(): Invalid value for $level';
+ − 466
break;
+ − 467
}
+ − 468
if(!$db->sql_query($q)) $db->_die('The log entry for the page protection could not be inserted.');
+ − 469
}
+ − 470
+ − 471
$q = $db->sql_query('UPDATE '.table_prefix.'pages SET protected='.$_POST['level'].' WHERE urlname=\''.$page_id.'\' AND namespace=\''.$namespace.'\';');
+ − 472
if(!$q) $db->_die('The pages table was not updated.');
+ − 473
+ − 474
return('good');
+ − 475
}
+ − 476
+ − 477
/**
+ − 478
* Generates an HTML table with history information in it.
+ − 479
* @param $page_id the page ID
+ − 480
* @param $namespace the namespace
+ − 481
* @return string
+ − 482
*/
+ − 483
+ − 484
function histlist($page_id, $namespace)
+ − 485
{
+ − 486
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 487
+ − 488
if(!$session->get_permissions('history_view'))
+ − 489
return 'Access denied';
+ − 490
+ − 491
ob_start();
+ − 492
+ − 493
$pname = $paths->nslist[$namespace] . $page_id;
+ − 494
$wiki = ( ( $paths->pages[$pname]['wiki_mode'] == 2 && getConfig('wiki_mode') == '1') || $paths->pages[$pname]['wiki_mode'] == 1) ? true : false;
+ − 495
$prot = ( ( $paths->pages[$pname]['protected'] == 2 && $session->user_logged_in && $session->reg_time + 60*60*24*4 < time() ) || $paths->pages[$pname]['protected'] == 1) ? true : false;
+ − 496
+ − 497
$q = 'SELECT time_id,date_string,page_id,namespace,author,edit_summary,minor_edit FROM '.table_prefix.'logs WHERE log_type=\'page\' AND action=\'edit\' AND page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\' ORDER BY time_id DESC;';
+ − 498
if(!$db->sql_query($q)) $db->_die('The history data for the page "'.$paths->cpage['name'].'" could not be selected.');
+ − 499
echo 'History of edits and actions<h3>Edits:</h3>';
+ − 500
$numrows = $db->numrows();
+ − 501
if($numrows < 1) echo 'No history entries in this category.';
+ − 502
else
+ − 503
{
+ − 504
+ − 505
echo '<form action="'.makeUrlNS($namespace, $page_id, 'do=diff').'" onsubmit="ajaxHistDiff(); return false;" method="get">
+ − 506
<input type="submit" value="Compare selected revisions" />
+ − 507
<br /><span> </span>
+ − 508
<div class="tblholder">
+ − 509
<table border="0" width="100%" cellspacing="1" cellpadding="4">
+ − 510
<tr>
+ − 511
<th colspan="2">Diff</th>
+ − 512
<th>Date/time</th>
+ − 513
<th>User</th>
+ − 514
<th>Edit summary</th>
+ − 515
<th>Minor</th>
+ − 516
<th colspan="3">Actions</th>
+ − 517
</tr>'."\n"."\n";
+ − 518
$cls = 'row2';
+ − 519
$ticker = 0;
+ − 520
+ − 521
while($r = $db->fetchrow()) {
+ − 522
+ − 523
$ticker++;
+ − 524
+ − 525
if($cls == 'row2') $cls = 'row1';
+ − 526
else $cls = 'row2';
+ − 527
+ − 528
echo '<tr>'."\n";
+ − 529
+ − 530
// Diff selection
+ − 531
if($ticker == 1)
+ − 532
{
+ − 533
$s1 = '';
+ − 534
$s2 = 'checked="checked" ';
+ − 535
}
+ − 536
elseif($ticker == 2)
+ − 537
{
+ − 538
$s1 = 'checked="checked" ';
+ − 539
$s2 = '';
+ − 540
}
+ − 541
else
+ − 542
{
+ − 543
$s1 = '';
+ − 544
$s2 = '';
+ − 545
}
+ − 546
if($ticker > 1) echo '<td class="'.$cls.'" style="padding: 0;"><input '.$s1.'name="diff1" type="radio" value="'.$r['time_id'].'" id="diff1_'.$r['time_id'].'" class="clsDiff1Radio" onclick="selectDiff1Button(this);" /></td>'."\n"; else echo '<td class="'.$cls.'"></td>';
+ − 547
if($ticker < $numrows) echo '<td class="'.$cls.'" style="padding: 0;"><input '.$s2.'name="diff2" type="radio" value="'.$r['time_id'].'" id="diff2_'.$r['time_id'].'" class="clsDiff2Radio" onclick="selectDiff2Button(this);" /></td>'."\n"; else echo '<td class="'.$cls.'"></td>';
+ − 548
+ − 549
// Date and time
+ − 550
echo '<td class="'.$cls.'">'.$r['date_string'].'</td class="'.$cls.'">'."\n";
+ − 551
+ − 552
// User
+ − 553
if($session->get_permissions('mod_misc') && preg_match('#^([0-9]*){1,3}\.([0-9]*){1,3}\.([0-9]*){1,3}\.([0-9]*){1,3}$#', $r['author'])) $rc = ' style="cursor: pointer;" title="Click cell background for reverse DNS info" onclick="ajaxReverseDNS(this, \''.$r['author'].'\');"';
+ − 554
else $rc = '';
+ − 555
echo '<td class="'.$cls.'"'.$rc.'><a href="'.makeUrlNS('User', $r['author']).'" ';
+ − 556
if(!isPage($paths->nslist['User'] . $r['author'])) echo 'class="wikilink-nonexistent"';
+ − 557
echo '>'.$r['author'].'</a></td class="'.$cls.'">'."\n";
+ − 558
+ − 559
// Edit summary
+ − 560
echo '<td class="'.$cls.'">'.$r['edit_summary'].'</td>'."\n";
+ − 561
+ − 562
// Minor edit
+ − 563
echo '<td class="'.$cls.'" style="text-align: center;">'. (( $r['minor_edit'] ) ? 'M' : '' ) .'</td>'."\n";
+ − 564
+ − 565
// Actions!
+ − 566
echo '<td class="'.$cls.'" style="text-align: center;"><a href="'.makeUrlNS($namespace, $page_id, 'oldid='.$r['time_id']).'" onclick="ajaxHistView(\''.$r['time_id'].'\'); return false;">View revision</a></td>'."\n";
+ − 567
echo '<td class="'.$cls.'" style="text-align: center;"><a href="'.makeUrl($paths->nslist['Special'].'Contributions/'.$r['author']).'">View user contribs</a></td>'."\n";
+ − 568
echo '<td class="'.$cls.'" style="text-align: center;"><a href="'.makeUrlNS($namespace, $page_id, 'do=rollback&id='.$r['time_id']).'" onclick="ajaxRollback(\''.$r['time_id'].'\'); return false;">Revert to this revision</a></td>'."\n";
+ − 569
+ − 570
echo '</tr>'."\n"."\n";
+ − 571
+ − 572
}
+ − 573
echo '</table>
+ − 574
</div>
+ − 575
<br />
+ − 576
<input type="hidden" name="do" value="diff" />
+ − 577
<input type="submit" value="Compare selected revisions" />
+ − 578
</form>
+ − 579
<script type="text/javascript">buildDiffList();</script>';
+ − 580
}
+ − 581
$db->free_result();
+ − 582
echo '<h3>Other changes:</h3>';
+ − 583
$q = 'SELECT time_id,action,date_string,page_id,namespace,author,edit_summary,minor_edit FROM '.table_prefix.'logs WHERE log_type=\'page\' AND action!=\'edit\' AND page_id=\''.$paths->cpage['urlname_nons'].'\' AND namespace=\''.$paths->namespace.'\' ORDER BY time_id DESC;';
+ − 584
if(!$db->sql_query($q)) $db->_die('The history data for the page "'.$paths->cpage['name'].'" could not be selected.');
+ − 585
if($db->numrows() < 1) echo 'No history entries in this category.';
+ − 586
else {
+ − 587
+ − 588
echo '<div class="tblholder"><table border="0" width="100%" cellspacing="1" cellpadding="4"><tr><th>Date/time</th><th>User</th><th>Minor</th><th>Action taken</th><th>Extra info</th><th colspan="2"></th></tr>';
+ − 589
$cls = 'row2';
+ − 590
while($r = $db->fetchrow()) {
+ − 591
+ − 592
if($cls == 'row2') $cls = 'row1';
+ − 593
else $cls = 'row2';
+ − 594
+ − 595
echo '<tr>';
+ − 596
+ − 597
// Date and time
+ − 598
echo '<td class="'.$cls.'">'.$r['date_string'].'</td class="'.$cls.'">';
+ − 599
+ − 600
// User
+ − 601
echo '<td class="'.$cls.'"><a href="'.makeUrlNS('User', $r['author']).'" ';
+ − 602
if(!isPage($paths->nslist['User'] . $r['author'])) echo 'class="wikilink-nonexistent"';
+ − 603
echo '>'.$r['author'].'</a></td class="'.$cls.'">';
+ − 604
+ − 605
+ − 606
// Minor edit
+ − 607
echo '<td class="'.$cls.'" style="text-align: center;">'. (( $r['minor_edit'] ) ? 'M' : '' ) .'</td>';
+ − 608
+ − 609
// Action taken
+ − 610
echo '<td class="'.$cls.'">';
+ − 611
if ($r['action']=='prot') echo 'Protected page</td><td class="'.$cls.'">Reason: '.$r['edit_summary'];
+ − 612
elseif($r['action']=='unprot') echo 'Unprotected page</td><td class="'.$cls.'">Reason: '.$r['edit_summary'];
+ − 613
elseif($r['action']=='semiprot') echo 'Semi-protected page</td><td class="'.$cls.'">Reason: '.$r['edit_summary'];
+ − 614
elseif($r['action']=='rename') echo 'Renamed page</td><td class="'.$cls.'">Old title: '.$r['edit_summary'];
+ − 615
elseif($r['action']=='create') echo 'Created page</td><td class="'.$cls.'">';
28
+ − 616
elseif($r['action']=='delete') echo 'Deleted page</td><td class="'.$cls.'">Reason: '.$r['edit_summary'];
1
+ − 617
elseif($r['action']=='reupload') echo 'Uploaded new file version</td><td class="'.$cls.'">Reason: '.$r['edit_summary'];
+ − 618
echo '</td>';
+ − 619
+ − 620
// Actions!
+ − 621
echo '<td class="'.$cls.'" style="text-align: center;"><a href="'.makeUrl($paths->nslist['Special'].'Contributions/'.$r['author']).'">View user contribs</a></td>';
+ − 622
echo '<td class="'.$cls.'" style="text-align: center;"><a href="'.makeUrlNS($namespace, $page_id, 'do=rollback&id='.$r['time_id']).'" onclick="ajaxRollback(\''.$r['time_id'].'\'); return false;">Revert action</a></td>';
+ − 623
+ − 624
//echo '(<a href="#" onclick="ajaxRollback(\''.$r['time_id'].'\'); return false;">rollback</a>) <i>'.$r['date_string'].'</i> '.$r['author'].' (<a href="'.makeUrl($paths->nslist['User'].$r['author']).'">Userpage</a>, <a href="'.makeUrl($paths->nslist['Special'].'Contributions/'.$r['author']).'">Contrib</a>): ';
+ − 625
+ − 626
if($r['minor_edit']) echo '<b> - minor edit</b>';
+ − 627
echo '<br />';
+ − 628
+ − 629
echo '</tr>';
+ − 630
}
+ − 631
echo '</table></div>';
+ − 632
}
+ − 633
$db->free_result();
+ − 634
$ret = ob_get_contents();
+ − 635
ob_end_clean();
+ − 636
return $ret;
+ − 637
}
+ − 638
+ − 639
/**
+ − 640
* Rolls back a logged action
+ − 641
* @param $id the time ID, a.k.a. the primary key in the logs table
+ − 642
* @return string
+ − 643
*/
+ − 644
+ − 645
function rollback($id)
+ − 646
{
+ − 647
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 648
if(!$session->get_permissions('history_rollback')) return('You are not authorized to perform rollbacks.');
+ − 649
if(!preg_match('#^([0-9]+)$#', (string)$id)) return('The value "id" on the query string must be an integer.');
+ − 650
$e = $db->sql_query('SELECT log_type,action,date_string,page_id,namespace,page_text,char_tag,author,edit_summary FROM '.table_prefix.'logs WHERE time_id='.$id.';');
+ − 651
if(!$e) $db->_die('The rollback data could not be selected.');
+ − 652
$rb = $db->fetchrow();
+ − 653
$db->free_result();
+ − 654
switch($rb['log_type']) {
+ − 655
case "page":
+ − 656
switch($rb['action']) {
+ − 657
case "edit":
+ − 658
$t = $db->escape($rb['page_text']);
+ − 659
$e = $db->sql_query('UPDATE '.table_prefix.'page_text SET page_text=\''.$t.'\',char_tag=\''.$rb['char_tag'].'\' WHERE page_id=\''.$rb['page_id'].'\' AND namespace=\''.$rb['namespace'].'\'');
+ − 660
if(!$e) return("An error occurred during the rollback operation.\nMySQL said: ".mysql_error()."\n\nSQL backtrace:\n".$db->sql_backtrace());
+ − 661
else return('The page "'.$paths->pages[$paths->nslist[$rb['namespace']].$rb['page_id']]['name'].'" has been rolled back to the state it was in on '.$rb['date_string'].'.');
+ − 662
break;
+ − 663
case "rename":
+ − 664
$t = $db->escape($rb['edit_summary']);
+ − 665
$e = $db->sql_query('UPDATE '.table_prefix.'pages SET name=\''.$t.'\' WHERE urlname=\''.$rb['page_id'].'\' AND namespace=\''.$rb['namespace'].'\'');
+ − 666
if(!$e) return("An error occurred during the rollback operation.\nMySQL said: ".mysql_error()."\n\nSQL backtrace:\n".$db->sql_backtrace());
+ − 667
else return('The page "'.$paths->pages[$paths->nslist[$rb['namespace']].$rb['page_id']]['name'].'" has been rolled back to the name it had ("'.$rb['edit_summary'].'") before '.$rb['date_string'].'.');
+ − 668
break;
+ − 669
case "prot":
+ − 670
$e = $db->sql_query('UPDATE '.table_prefix.'pages SET protected=0 WHERE urlname=\''.$rb['page_id'].'\' AND namespace=\''.$rb['namespace'].'\'');
+ − 671
if(!$e) return("An error occurred during the rollback operation.\nMySQL said: ".mysql_error()."\n\nSQL backtrace:\n".$db->sql_backtrace());
+ − 672
else return('The page "'.$paths->pages[$paths->nslist[$rb['namespace']].$rb['page_id']]['name'].'" has been unprotected according to the log created at '.$rb['date_string'].'.');
+ − 673
break;
+ − 674
case "semiprot":
+ − 675
$e = $db->sql_query('UPDATE '.table_prefix.'pages SET protected=0 WHERE urlname=\''.$rb['page_id'].'\' AND namespace=\''.$rb['namespace'].'\'');
+ − 676
if(!$e) return("An error occurred during the rollback operation.\nMySQL said: ".mysql_error()."\n\nSQL backtrace:\n".$db->sql_backtrace());
+ − 677
else return('The page "'.$paths->pages[$paths->nslist[$rb['namespace']].$rb['page_id']]['name'].'" has been unprotected according to the log created at '.$rb['date_string'].'.');
+ − 678
break;
+ − 679
case "unprot":
+ − 680
$e = $db->sql_query('UPDATE '.table_prefix.'pages SET protected=1 WHERE urlname=\''.$rb['page_id'].'\' AND namespace=\''.$rb['namespace'].'\'');
+ − 681
if(!$e) return("An error occurred during the rollback operation.\nMySQL said: ".mysql_error()."\n\nSQL backtrace:\n".$db->sql_backtrace());
+ − 682
else return('The page "'.$paths->pages[$paths->nslist[$rb['namespace']].$rb['page_id']]['name'].'" has been protected according to the log created at '.$rb['date_string'].'.');
+ − 683
break;
+ − 684
case "delete":
+ − 685
if(!$session->get_permissions('history_rollback_extra')) return('Administrative privileges are required for page undeletion.');
+ − 686
if(isset($paths->pages[$paths->cpage['urlname']])) return('You cannot raise a dead page that is alive.');
+ − 687
$name = str_replace('_', ' ', $rb['page_id']);
+ − 688
$e = $db->sql_query('INSERT INTO '.table_prefix.'pages(name,urlname,namespace) VALUES( \''.$name.'\', \''.$rb['page_id'].'\',\''.$rb['namespace'].'\' )');if(!$e) return("An error occurred during the rollback operation.\nMySQL said: ".mysql_error()."\n\nSQL backtrace:\n".$db->sql_backtrace());
+ − 689
$e = $db->sql_query('SELECT page_text,char_tag FROM '.table_prefix.'logs WHERE page_id=\''.$rb['page_id'].'\' AND namespace=\''.$rb['namespace'].'\' AND log_type=\'page\' AND action=\'edit\' ORDER BY time_id DESC;'); if(!$e) return("An error occurred during the rollback operation.\nMySQL said: ".mysql_error()."\n\nSQL backtrace:\n".$db->sql_backtrace());
+ − 690
$r = $db->fetchrow();
+ − 691
$e = $db->sql_query('INSERT INTO '.table_prefix.'page_text(page_id,namespace,page_text,char_tag) VALUES(\''.$rb['page_id'].'\',\''.$rb['namespace'].'\',\''.$db->escape($r['page_text']).'\',\''.$r['char_tag'].'\')'); if(!$e) return("An error occurred during the rollback operation.\nMySQL said: ".mysql_error()."\n\nSQL backtrace:\n".$db->sql_backtrace());
+ − 692
return('The page "'.$name.'" has been undeleted according to the log created at '.$rb['date_string'].'.');
+ − 693
break;
+ − 694
case "reupload":
+ − 695
if(!$session->get_permissions('history_rollbacks_extra')) return('Administrative privileges are required for file rollbacks.');
+ − 696
$newtime = time();
+ − 697
$newdate = date('d M Y h:i a');
+ − 698
if(!$db->sql_query('UPDATE '.table_prefix.'logs SET time_id='.$newtime.',date_string=\''.$newdate.'\' WHERE time_id='.$id)) return('Error during query: '.mysql_error());
+ − 699
if(!$db->sql_query('UPDATE '.table_prefix.'files SET time_id='.$newtime.' WHERE time_id='.$id)) return('Error during query: '.mysql_error());
+ − 700
return('The file has been rolled back to the version uploaded on '.date('d M Y h:i a', (int)$id).'.');
+ − 701
break;
+ − 702
default:
+ − 703
return('Rollback of the action "'.$rb['action'].'" is not yet supported.');
+ − 704
break;
+ − 705
}
+ − 706
break;
+ − 707
case "security":
+ − 708
case "login":
+ − 709
return('A '.$rb['log_type'].'-related log entry cannot be rolled back.');
+ − 710
break;
+ − 711
default:
+ − 712
return('Unknown log entry type: "'.$rb['log_type'].'"');
+ − 713
}
+ − 714
}
+ − 715
+ − 716
/**
+ − 717
* Posts a comment.
+ − 718
* @param $page_id the page ID
+ − 719
* @param $namespace the namespace
+ − 720
* @param $name the name of the person posting, defaults to current username/IP
+ − 721
* @param $subject the subject line of the comment
+ − 722
* @param $text the comment text
+ − 723
* @return string javascript code
+ − 724
*/
+ − 725
+ − 726
function addcomment($page_id, $namespace, $name, $subject, $text, $captcha_code = false, $captcha_id = false)
+ − 727
{
+ − 728
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 729
$_ob = '';
+ − 730
if(!$session->get_permissions('post_comments'))
+ − 731
return 'Access denied';
+ − 732
if(getConfig('comments_need_login') == '2' && !$session->user_logged_in) _die('Access denied to post comments: you need to be logged in first.');
+ − 733
if(getConfig('comments_need_login') == '1' && !$session->user_logged_in)
+ − 734
{
+ − 735
if(!$captcha_code || !$captcha_id) _die('BUG: PageUtils::addcomment: no CAPTCHA data passed to method');
+ − 736
$result = $session->get_captcha($captcha_id);
+ − 737
if($captcha_code != $result) _die('The confirmation code you entered was incorrect.');
+ − 738
}
+ − 739
$text = RenderMan::preprocess_text($text);
+ − 740
$name = $session->user_logged_in ? RenderMan::preprocess_text($session->username) : RenderMan::preprocess_text($name);
+ − 741
$subj = RenderMan::preprocess_text($subject);
+ − 742
if(getConfig('approve_comments')=='1') $appr = '0'; else $appr = '1';
+ − 743
$q = 'INSERT INTO '.table_prefix.'comments(page_id,namespace,subject,comment_data,name,user_id,approved,time) VALUES(\''.$page_id.'\',\''.$namespace.'\',\''.$subj.'\',\''.$text.'\',\''.$name.'\','.$session->user_id.','.$appr.','.time().')';
+ − 744
$e = $db->sql_query($q);
+ − 745
if(!$e) die('alert(unescape(\''.rawurlencode('Error inserting comment data: '.mysql_error().'\n\nQuery:\n'.$q).'\'))');
+ − 746
else $_ob .= '<div class="info-box">Your comment has been posted.</div>';
+ − 747
return PageUtils::comments($page_id, $namespace, false, Array(), $_ob);
+ − 748
}
+ − 749
+ − 750
/**
+ − 751
* Generates partly-compiled HTML/Javascript code to be eval'ed by the user's browser to display comments
+ − 752
* @param $page_id the page ID
+ − 753
* @param $namespace the namespace
+ − 754
* @param $action administrative action to perform, default is false
+ − 755
* @param $flags additional info for $action, shouldn't be used except when deleting/approving comments, etc.
+ − 756
* @param $_ob text to prepend to output, used by PageUtils::addcomment
+ − 757
* @return array
+ − 758
* @access private
+ − 759
*/
+ − 760
+ − 761
function comments_raw($page_id, $namespace, $action = false, $flags = Array(), $_ob = '')
+ − 762
{
+ − 763
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 764
+ − 765
$pname = $paths->nslist[$namespace] . $page_id;
+ − 766
+ − 767
ob_start();
+ − 768
+ − 769
if($action && $session->get_permissions('mod_comments')) // Nip hacking attempts in the bud
+ − 770
{
+ − 771
switch($action) {
+ − 772
case "delete":
+ − 773
if(isset($flags['id']))
+ − 774
{
+ − 775
$q = 'DELETE FROM '.table_prefix.'comments WHERE page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\' AND comment_id='.intval($flags['id']).' LIMIT 1;';
+ − 776
} else {
+ − 777
$n = $db->escape($flags['name']);
+ − 778
$s = $db->escape($flags['subj']);
+ − 779
$t = $db->escape($flags['text']);
+ − 780
$q = 'DELETE FROM '.table_prefix.'comments WHERE page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\' AND name=\''.$n.'\' AND subject=\''.$s.'\' AND comment_data=\''.$t.'\' LIMIT 1;';
+ − 781
}
+ − 782
$e=$db->sql_query($q);
+ − 783
if(!$e) die('alert(unesape(\''.rawurlencode('Error during query: '.mysql_error().'\n\nQuery:\n'.$q).'\'));');
+ − 784
break;
+ − 785
case "approve":
+ − 786
if(isset($flags['id']))
+ − 787
{
+ − 788
$where = 'comment_id='.intval($flags['id']);
+ − 789
} else {
+ − 790
$n = $db->escape($flags['name']);
+ − 791
$s = $db->escape($flags['subj']);
+ − 792
$t = $db->escape($flags['text']);
+ − 793
$where = 'name=\''.$n.'\' AND subject=\''.$s.'\' AND comment_data=\''.$t.'\'';
+ − 794
}
+ − 795
$q = 'SELECT approved FROM '.table_prefix.'comments WHERE page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\' AND '.$where.' LIMIT 1;';
+ − 796
$e = $db->sql_query($q);
+ − 797
if(!$e) die('alert(unesape(\''.rawurlencode('Error selecting approval status: '.mysql_error().'\n\nQuery:\n'.$q).'\'));');
+ − 798
$r = $db->fetchrow();
+ − 799
$db->free_result();
+ − 800
$a = ( $r['approved'] ) ? '0' : '1';
+ − 801
$q = 'UPDATE '.table_prefix.'comments SET approved='.$a.' WHERE page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\' AND '.$where.';';
+ − 802
$e=$db->sql_query($q);
+ − 803
if(!$e) die('alert(unesape(\''.rawurlencode('Error during query: '.mysql_error().'\n\nQuery:\n'.$q).'\'));');
+ − 804
if($a=='1') $v = 'Unapprove';
+ − 805
else $v = 'Approve';
+ − 806
echo 'document.getElementById("mdgApproveLink'.$_GET['id'].'").innerHTML="'.$v.'";';
+ − 807
break;
+ − 808
}
+ − 809
}
+ − 810
+ − 811
if(!defined('ENANO_TEMPLATE_LOADED'))
+ − 812
{
+ − 813
$template->load_theme($session->theme, $session->style);
+ − 814
}
+ − 815
+ − 816
$tpl = $template->makeParser('comment.tpl');
+ − 817
+ − 818
$e = $db->sql_query('SELECT * FROM '.table_prefix.'comments WHERE page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\' AND approved=0;');
+ − 819
if(!$e) $db->_die('The comment text data could not be selected.');
+ − 820
$num_unapp = $db->numrows();
+ − 821
$db->free_result();
+ − 822
$e = $db->sql_query('SELECT * FROM '.table_prefix.'comments WHERE page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\' AND approved=1;');
+ − 823
if(!$e) $db->_die('The comment text data could not be selected.');
+ − 824
$num_app = $db->numrows();
+ − 825
$db->free_result();
+ − 826
$lq = $db->sql_query('SELECT c.comment_id,c.subject,c.name,c.comment_data,c.approved,c.time,c.user_id,u.user_level,u.signature
+ − 827
FROM '.table_prefix.'comments AS c
+ − 828
LEFT JOIN '.table_prefix.'users AS u
+ − 829
ON c.user_id=u.user_id
+ − 830
WHERE page_id=\''.$page_id.'\'
+ − 831
AND namespace=\''.$namespace.'\' ORDER BY c.time ASC;');
+ − 832
if(!$lq) _die('The comment text data could not be selected. '.mysql_error());
+ − 833
$_ob .= '<h3>Article Comments</h3>';
+ − 834
$n = ( $session->get_permissions('mod_comments')) ? $db->numrows() : $num_app;
+ − 835
if($n==1) $s = 'is '.$n.' comment'; else $s = 'are '.$n.' comments';
+ − 836
if($n < 1)
+ − 837
{
+ − 838
$_ob .= '<p>There are currently no comments on this '.strtolower($namespace).'';
+ − 839
if($namespace != 'Article') $_ob .= ' page';
+ − 840
$_ob .= '.</p>';
+ − 841
} else $_ob .= '<p>There '.$s.' on this article.</p>';
+ − 842
if($session->get_permissions('mod_comments') && $num_unapp > 0) $_ob .= ' <span style="color: #D84308">'.$num_unapp.' of those are unapproved.</span>';
+ − 843
elseif(!$session->get_permissions('mod_comments') && $num_unapp > 0) { $u = ($num_unapp == 1) ? "is $num_unapp comment" : "are $num_unapp comments"; $_ob .= ' However, there ' . $u . ' awating approval.'; }
+ − 844
$list = 'list = { ';
+ − 845
// _die(htmlspecialchars($ttext));
+ − 846
$i = -1;
+ − 847
while($row = $db->fetchrow($lq))
+ − 848
{
+ − 849
$i++;
+ − 850
$strings = Array();
+ − 851
$bool = Array();
+ − 852
if($session->get_permissions('mod_comments') || $row['approved']) {
+ − 853
$list .= $i . ' : { \'comment\' : unescape(\''.rawurlencode($row['comment_data']).'\'), \'name\' : unescape(\''.rawurlencode($row['name']).'\'), \'subject\' : unescape(\''.rawurlencode($row['subject']).'\'), }, ';
+ − 854
+ − 855
// Comment ID (used in the Javascript apps)
+ − 856
$strings['ID'] = (string)$i;
+ − 857
+ − 858
// Determine the name, and whether to link to the user page or not
+ − 859
$name = '';
+ − 860
if($row['user_id'] > 0) $name .= '<a href="'.makeUrlNS('User', str_replace(' ', '_', $row['name'])).'">';
+ − 861
$name .= $row['name'];
+ − 862
if($row['user_id'] > 0) $name .= '</a>';
+ − 863
$strings['NAME'] = $name; unset($name);
+ − 864
+ − 865
// Subject
+ − 866
$s = $row['subject'];
+ − 867
if(!$row['approved']) $s .= ' <span style="color: #D84308">(Unapproved)</span>';
+ − 868
$strings['SUBJECT'] = $s;
+ − 869
+ − 870
// Date and time
+ − 871
$strings['DATETIME'] = date('F d, Y h:i a', $row['time']);
+ − 872
+ − 873
// User level
+ − 874
switch($row['user_level'])
+ − 875
{
+ − 876
default:
+ − 877
case USER_LEVEL_GUEST:
+ − 878
$l = 'Guest';
+ − 879
break;
+ − 880
case USER_LEVEL_MEMBER:
+ − 881
$l = 'Member';
+ − 882
break;
+ − 883
case USER_LEVEL_MOD:
+ − 884
$l = 'Moderator';
+ − 885
break;
+ − 886
case USER_LEVEL_ADMIN:
+ − 887
$l = 'Administrator';
+ − 888
break;
+ − 889
}
+ − 890
$strings['USER_LEVEL'] = $l; unset($l);
+ − 891
+ − 892
// The actual comment data
+ − 893
$strings['DATA'] = RenderMan::render($row['comment_data']);
+ − 894
+ − 895
if($session->get_permissions('edit_comments'))
+ − 896
{
+ − 897
// Edit link
+ − 898
$strings['EDIT_LINK'] = '<a href="'.makeUrlNS($namespace, $page_id, 'do=comments&sub=editcomment&id='.$row['comment_id']).'" onclick="editComment(\''.$i.'\'); return false;" id="editbtn_'.$i.'">edit</a>';
+ − 899
+ − 900
// Delete link
+ − 901
$strings['DELETE_LINK'] = '<a href="'.makeUrlNS($namespace, $page_id, 'do=comments&sub=deletecomment&id='.$row['comment_id']).'" onclick="ajaxDeleteComment(\''.$i.'\'); return false;">delete</a>';
+ − 902
}
+ − 903
else
+ − 904
{
+ − 905
// Edit link
+ − 906
$strings['EDIT_LINK'] = '';
+ − 907
+ − 908
// Delete link
+ − 909
$strings['DELETE_LINK'] = '';
+ − 910
}
+ − 911
+ − 912
// Send PM link
+ − 913
$strings['SEND_PM_LINK'] = ( $session->user_logged_in && $row['user_id'] > 0 ) ? '<a href="'.makeUrlNS('Special', 'PrivateMessages/Compose/To/'.$row['name']).'">Send private message</a><br />' : '';
+ − 914
+ − 915
// Add Buddy link
+ − 916
$strings['ADD_BUDDY_LINK'] = ( $session->user_logged_in && $row['user_id'] > 0 ) ? '<a href="'.makeUrlNS('Special', 'PrivateMessages/FriendList/Add/'.$row['name']).'">Add to buddy list</a>' : '';
+ − 917
+ − 918
// Mod links
+ − 919
$applink = '';
+ − 920
$applink .= '<a href="'.makeUrlNS($namespace, $page_id, 'do=comments&sub=admin&action=approve&id='.$row['comment_id']).'" onclick="ajaxCommentAdmin(\'approve\', \''.$i.'\'); return false;" id="mdgApproveLink'.$i.'">';
+ − 921
if($row['approved']) $applink .= 'Unapprove';
+ − 922
else $applink .= 'Approve';
+ − 923
$applink .= '</a>';
+ − 924
$strings['MOD_APPROVE_LINK'] = $applink; unset($applink);
+ − 925
$strings['MOD_DELETE_LINK'] = '<a href="'.makeUrlNS($namespace, $page_id, 'do=comments&sub=admin&action=delete&id='.$row['comment_id']).'" onclick="ajaxCommentAdmin(\'delete\', \''.$i.'\'); return false;">Delete</a>';
+ − 926
+ − 927
// Signature
+ − 928
$strings['SIGNATURE'] = '';
+ − 929
if($row['signature'] != '') $strings['SIGNATURE'] = RenderMan::render($row['signature']);
+ − 930
+ − 931
$bool['auth_mod'] = ($session->get_permissions('mod_comments')) ? true : false;
+ − 932
$bool['can_edit'] = ( ( $session->user_logged_in && $row['name'] == $session->username && $session->get_permissions('edit_comments') ) || $session->get_permissions('mod_comments') ) ? true : false;
+ − 933
$bool['signature'] = ( $strings['SIGNATURE'] == '' ) ? false : true;
+ − 934
+ − 935
// Done processing and compiling, now let's cook it into HTML
+ − 936
$tpl->assign_vars($strings);
+ − 937
$tpl->assign_bool($bool);
+ − 938
$_ob .= $tpl->run();
+ − 939
}
+ − 940
}
+ − 941
if(getConfig('comments_need_login') != '2' || $session->user_logged_in)
+ − 942
{
+ − 943
if(!$session->get_permissions('post_comments'))
+ − 944
{
+ − 945
$_ob .= '<h3>Got something to say?</h3><p>Access to post comments on this page is denied.</p>';
+ − 946
}
+ − 947
else
+ − 948
{
+ − 949
$_ob .= '<h3>Got something to say?</h3>If you have comments or suggestions on this article, you can shout it out here.';
+ − 950
if(getConfig('approve_comments')=='1') $_ob .= ' Before your comment will be visible to the public, a moderator will have to approve it.';
+ − 951
if(getConfig('comments_need_login') == '1' && !$session->user_logged_in) $_ob .= ' Because you are not logged in, you will need to enter a visual confirmation before your comment will be posted.';
+ − 952
$sn = $session->user_logged_in ? $session->username . '<input name="name" id="mdgScreenName" type="hidden" value="'.$session->username.'" />' : '<input name="name" id="mdgScreenName" type="text" size="35" />';
+ − 953
$_ob .= ' <a href="#" id="mdgCommentFormLink" style="display: none;" onclick="document.getElementById(\'mdgCommentForm\').style.display=\'block\';this.style.display=\'none\';return false;">Leave a comment...</a>
+ − 954
<div id="mdgCommentForm">
+ − 955
<h3>Comment form</h3>
+ − 956
<form action="'.makeUrlNS($namespace, $page_id, 'do=comments&sub=postcomment').'" method="post" style="margin-left: 1em">
+ − 957
<table border="0">
+ − 958
<tr><td>Your name or screen name:</td><td>'.$sn.'</td></tr>
+ − 959
<tr><td>Comment subject:</td><td><input name="subj" id="mdgSubject" type="text" size="35" /></td></tr>';
+ − 960
if(getConfig('comments_need_login') == '1' && !$session->user_logged_in)
+ − 961
{
+ − 962
$session->kill_captcha();
+ − 963
$captcha = $session->make_captcha();
+ − 964
$_ob .= '<tr><td>Visual confirmation:<br /><small>Please enter the code you see on the right.</small></td><td><img src="'.makeUrlNS('Special', 'Captcha/'.$captcha).'" alt="Visual confirmation" style="cursor: pointer;" onclick="this.src = \''.makeUrlNS("Special", "Captcha/".$captcha).'/\'+Math.floor(Math.random() * 100000);" /><input name="captcha_id" id="mdgCaptchaID" type="hidden" value="'.$captcha.'" /><br />Code: <input name="captcha_input" id="mdgCaptchaInput" type="text" size="10" /><br /><small><script type="text/javascript">document.write("If you can\'t read the code, click on the image to generate a new one.");</script><noscript>If you can\'t read the code, please refresh this page to generate a new one.</noscript></small></td></tr>';
+ − 965
}
+ − 966
$_ob .= '
+ − 967
<tr><td valign="top">Comment text:<br />(most HTML will be stripped)</td><td><textarea name="text" id="mdgCommentArea" rows="10" cols="40"></textarea></td></tr>
+ − 968
<tr><td colspan="2" style="text-align: center;"><input type="submit" value="Submit Comment" /></td></tr>
+ − 969
</table>
+ − 970
</form>
+ − 971
</div>';
+ − 972
}
+ − 973
} else {
+ − 974
$_ob .= '<h3>Got something to say?</h3><p>You need to be logged in to post comments. <a href="'.makeUrlNS('Special', 'Login/'.$pname.'%2523comments').'">Log in</a></p>';
+ − 975
}
+ − 976
$list .= '};';
+ − 977
echo 'document.getElementById(\'ajaxEditContainer\').innerHTML = unescape(\''. rawurlencode($_ob) .'\');
+ − 978
' . $list;
+ − 979
echo 'Fat.fade_all(); document.getElementById(\'mdgCommentForm\').style.display = \'none\'; document.getElementById(\'mdgCommentFormLink\').style.display="inline";';
+ − 980
+ − 981
$ret = ob_get_contents();
+ − 982
ob_end_clean();
+ − 983
return Array($ret, $_ob);
+ − 984
+ − 985
}
+ − 986
+ − 987
/**
+ − 988
* Generates ready-to-execute Javascript code to be eval'ed by the user's browser to display comments
+ − 989
* @param $page_id the page ID
+ − 990
* @param $namespace the namespace
+ − 991
* @param $action administrative action to perform, default is false
+ − 992
* @param $flags additional info for $action, shouldn't be used except when deleting/approving comments, etc.
+ − 993
* @param $_ob text to prepend to output, used by PageUtils::addcomment
+ − 994
* @return string
+ − 995
*/
+ − 996
+ − 997
function comments($page_id, $namespace, $action = false, $id = -1, $_ob = '')
+ − 998
{
+ − 999
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 1000
$r = PageUtils::comments_raw($page_id, $namespace, $action, $id, $_ob);
+ − 1001
return $r[0];
+ − 1002
}
+ − 1003
+ − 1004
/**
+ − 1005
* Generates HTML code for comments - used in browser compatibility mode
+ − 1006
* @param $page_id the page ID
+ − 1007
* @param $namespace the namespace
+ − 1008
* @param $action administrative action to perform, default is false
+ − 1009
* @param $flags additional info for $action, shouldn't be used except when deleting/approving comments, etc.
+ − 1010
* @param $_ob text to prepend to output, used by PageUtils::addcomment
+ − 1011
* @return string
+ − 1012
*/
+ − 1013
+ − 1014
function comments_html($page_id, $namespace, $action = false, $id = -1, $_ob = '')
+ − 1015
{
+ − 1016
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 1017
$r = PageUtils::comments_raw($page_id, $namespace, $action, $id, $_ob);
+ − 1018
return $r[1];
+ − 1019
}
+ − 1020
+ − 1021
/**
+ − 1022
* Updates comment data.
+ − 1023
* @param $page_id the page ID
+ − 1024
* @param $namespace the namespace
+ − 1025
* @param $subject new subject
+ − 1026
* @param $text new text
+ − 1027
* @param $old_subject the old subject, unprocessed and identical to the value in the DB
+ − 1028
* @param $old_text the old text, unprocessed and identical to the value in the DB
+ − 1029
* @param $id the javascript list ID, used internally by the client-side app
+ − 1030
* @return string
+ − 1031
*/
+ − 1032
+ − 1033
function savecomment($page_id, $namespace, $subject, $text, $old_subject, $old_text, $id = -1)
+ − 1034
{
+ − 1035
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 1036
if(!$session->get_permissions('edit_comments'))
+ − 1037
return 'result="BAD";error="Access denied"';
+ − 1038
// Avoid SQL injection
+ − 1039
$old_text = $db->escape($old_text);
+ − 1040
$old_subject = $db->escape($old_subject);
+ − 1041
// Safety check - username/login
+ − 1042
if(!$session->get_permissions('mod_comments')) // allow mods to edit comments
+ − 1043
{
+ − 1044
if(!$session->user_logged_in) _die('AJAX comment save safety check failed because you are not logged in. Sometimes this can happen because you are using a browser that does not send cookies as part of AJAX requests.<br /><br />Please log in and try again.');
+ − 1045
$q = 'SELECT c.name FROM '.table_prefix.'comments c, '.table_prefix.'users u WHERE comment_data=\''.$old_text.'\' AND subject=\''.$old_subject.'\' AND page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\' AND u.user_id=c.user_id;';
+ − 1046
$s = $db->sql_query($q);
+ − 1047
if(!$s) _die('SQL error during safety check: '.mysql_error().'<br /><br />Attempted SQL:<br /><pre>'.htmlspecialchars($q).'</pre>');
+ − 1048
$r = $db->fetchrow($s);
+ − 1049
$db->free_result();
+ − 1050
if($db->numrows() < 1 || $r['name'] != $session->username) _die('Safety check failed, probably due to a hacking attempt.');
+ − 1051
}
+ − 1052
$s = RenderMan::preprocess_text($subject);
+ − 1053
$t = RenderMan::preprocess_text($text);
+ − 1054
$sql = 'UPDATE '.table_prefix.'comments SET subject=\''.$s.'\',comment_data=\''.$t.'\' WHERE comment_data=\''.$old_text.'\' AND subject=\''.$old_subject.'\' AND page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\'';
+ − 1055
$result = $db->sql_query($sql);
+ − 1056
if($result)
+ − 1057
{
+ − 1058
return 'result="GOOD";
+ − 1059
list['.$id.'][\'subject\'] = unescape(\''.str_replace('%5Cn', '%0A', rawurlencode(str_replace('{{EnAnO:Newline}}', '\\n', stripslashes(str_replace('\\n', '{{EnAnO:Newline}}', $s))))).'\');
+ − 1060
list['.$id.'][\'comment\'] = unescape(\''.str_replace('%5Cn', '%0A', rawurlencode(str_replace('{{EnAnO:Newline}}', '\\n', stripslashes(str_replace('\\n', '{{EnAnO:Newline}}', $t))))).'\'); id = '.$id.';
+ − 1061
s = unescape(\''.rawurlencode($s).'\');
+ − 1062
t = unescape(\''.str_replace('%5Cn', '<br \\/>', rawurlencode(RenderMan::render(str_replace('{{EnAnO:Newline}}', "\n", stripslashes(str_replace('\\n', '{{EnAnO:Newline}}', $t)))))).'\');';
+ − 1063
}
+ − 1064
else
+ − 1065
{
+ − 1066
return 'result="BAD"; error=unescape("'.rawurlencode('Enano encountered a problem whilst saving the comment.
+ − 1067
Performed SQL:
+ − 1068
'.$sql.'
+ − 1069
+ − 1070
Error returned by MySQL: '.mysql_error()).'");';
+ − 1071
}
+ − 1072
}
+ − 1073
+ − 1074
/**
+ − 1075
* Updates comment data using the comment_id column instead of the old, messy way
+ − 1076
* @param $page_id the page ID
+ − 1077
* @param $namespace the namespace
+ − 1078
* @param $subject new subject
+ − 1079
* @param $text new text
+ − 1080
* @param $id the comment ID (primary key in enano_comments table)
+ − 1081
* @return string
+ − 1082
*/
+ − 1083
+ − 1084
function savecomment_neater($page_id, $namespace, $subject, $text, $id)
+ − 1085
{
+ − 1086
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 1087
if(!is_int($id)) die('PageUtils::savecomment: $id is not an integer, aborting for safety');
+ − 1088
if(!$session->get_permissions('edit_comments'))
+ − 1089
return 'Access denied';
+ − 1090
// Safety check - username/login
+ − 1091
if(!$session->get_permissions('mod_comments')) // allow mods to edit comments
+ − 1092
{
+ − 1093
if(!$session->user_logged_in) _die('AJAX comment save safety check failed because you are not logged in. Sometimes this can happen because you are using a browser that does not send cookies as part of AJAX requests.<br /><br />Please log in and try again.');
+ − 1094
$q = 'SELECT c.name FROM '.table_prefix.'comments c, '.table_prefix.'users u WHERE comment_id='.$id.' AND page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\' AND u.user_id=c.user_id;';
+ − 1095
$s = $db->sql_query($q);
+ − 1096
if(!$s) _die('SQL error during safety check: '.mysql_error().'<br /><br />Attempted SQL:<br /><pre>'.htmlspecialchars($q).'</pre>');
+ − 1097
$r = $db->fetchrow($s);
+ − 1098
if($db->numrows() < 1 || $r['name'] != $session->username) _die('Safety check failed, probably due to a hacking attempt.');
+ − 1099
$db->free_result();
+ − 1100
}
+ − 1101
$s = RenderMan::preprocess_text($subject);
+ − 1102
$t = RenderMan::preprocess_text($text);
+ − 1103
$sql = 'UPDATE '.table_prefix.'comments SET subject=\''.$s.'\',comment_data=\''.$t.'\' WHERE comment_id='.$id.' AND page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\'';
+ − 1104
$result = $db->sql_query($sql);
+ − 1105
if($result)
+ − 1106
return 'good';
+ − 1107
else return 'Enano encountered a problem whilst saving the comment.
+ − 1108
Performed SQL:
+ − 1109
'.$sql.'
+ − 1110
+ − 1111
Error returned by MySQL: '.mysql_error();
+ − 1112
}
+ − 1113
+ − 1114
/**
+ − 1115
* Deletes a comment.
+ − 1116
* @param $page_id the page ID
+ − 1117
* @param $namespace the namespace
+ − 1118
* @param $name the name the user posted under
+ − 1119
* @param $subj the subject of the comment to be deleted
+ − 1120
* @param $text the text of the comment to be deleted
+ − 1121
* @param $id the javascript list ID, used internally by the client-side app
+ − 1122
* @return string
+ − 1123
*/
+ − 1124
+ − 1125
function deletecomment($page_id, $namespace, $name, $subj, $text, $id)
+ − 1126
{
+ − 1127
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 1128
+ − 1129
if(!$session->get_permissions('edit_comments'))
+ − 1130
return 'alert("Access to delete/edit comments is denied");';
+ − 1131
+ − 1132
if(!preg_match('#^([0-9]+)$#', (string)$id)) die('$_GET[id] is improperly formed.');
+ − 1133
$n = $db->escape($name);
+ − 1134
$s = $db->escape($subj);
+ − 1135
$t = $db->escape($text);
+ − 1136
+ − 1137
// Safety check - username/login
+ − 1138
if(!$session->get_permissions('mod_comments')) // allows mods to delete comments
+ − 1139
{
+ − 1140
if(!$session->user_logged_in) _die('AJAX comment save safety check failed because you are not logged in. Sometimes this can happen because you are using a browser that does not send cookies as part of AJAX requests.<br /><br />Please log in and try again.');
+ − 1141
$q = 'SELECT c.name FROM '.table_prefix.'comments c, '.table_prefix.'users u WHERE comment_data=\''.$t.'\' AND subject=\''.$s.'\' AND page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\' AND u.user_id=c.user_id;';
+ − 1142
$s = $db->sql_query($q);
+ − 1143
if(!$s) _die('SQL error during safety check: '.mysql_error().'<br /><br />Attempted SQL:<br /><pre>'.htmlspecialchars($q).'</pre>');
+ − 1144
$r = $db->fetchrow($s);
+ − 1145
if($db->numrows() < 1 || $r['name'] != $session->username) _die('Safety check failed, probably due to a hacking attempt.');
+ − 1146
$db->free_result();
+ − 1147
}
+ − 1148
$q = 'DELETE FROM '.table_prefix.'comments WHERE page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\' AND name=\''.$n.'\' AND subject=\''.$s.'\' AND comment_data=\''.$t.'\' LIMIT 1;';
+ − 1149
$e=$db->sql_query($q);
+ − 1150
if(!$e) return('alert(unesape(\''.rawurlencode('Error during query: '.mysql_error().'\n\nQuery:\n'.$q).'\'));');
+ − 1151
return('good');
+ − 1152
}
+ − 1153
+ − 1154
/**
+ − 1155
* Deletes a comment in a cleaner fashion.
+ − 1156
* @param $page_id the page ID
+ − 1157
* @param $namespace the namespace
+ − 1158
* @param $id the comment ID (primary key)
+ − 1159
* @return string
+ − 1160
*/
+ − 1161
+ − 1162
function deletecomment_neater($page_id, $namespace, $id)
+ − 1163
{
+ − 1164
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 1165
+ − 1166
if(!preg_match('#^([0-9]+)$#', (string)$id)) die('$_GET[id] is improperly formed.');
+ − 1167
+ − 1168
if(!$session->get_permissions('edit_comments'))
+ − 1169
return 'alert("Access to delete/edit comments is denied");';
+ − 1170
+ − 1171
// Safety check - username/login
+ − 1172
if(!$session->get_permissions('mod_comments')) // allows mods to delete comments
+ − 1173
{
+ − 1174
if(!$session->user_logged_in) _die('AJAX comment save safety check failed because you are not logged in. Sometimes this can happen because you are using a browser that does not send cookies as part of AJAX requests.<br /><br />Please log in and try again.');
+ − 1175
$q = 'SELECT c.name FROM '.table_prefix.'comments c, '.table_prefix.'users u WHERE comment_id='.$id.' AND page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\' AND u.user_id=c.user_id;';
+ − 1176
$s = $db->sql_query($q);
+ − 1177
if(!$s) _die('SQL error during safety check: '.mysql_error().'<br /><br />Attempted SQL:<br /><pre>'.htmlspecialchars($q).'</pre>');
+ − 1178
$r = $db->fetchrow($s);
+ − 1179
if($db->numrows() < 1 || $r['name'] != $session->username) _die('Safety check failed, probably due to a hacking attempt.');
+ − 1180
$db->free_result();
+ − 1181
}
+ − 1182
$q = 'DELETE FROM '.table_prefix.'comments WHERE page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\' AND comment_id='.$id.' LIMIT 1;';
+ − 1183
$e=$db->sql_query($q);
+ − 1184
if(!$e) return('alert(unesape(\''.rawurlencode('Error during query: '.mysql_error().'\n\nQuery:\n'.$q).'\'));');
+ − 1185
return('good');
+ − 1186
}
+ − 1187
+ − 1188
/**
+ − 1189
* Renames a page.
+ − 1190
* @param $page_id the page ID
+ − 1191
* @param $namespace the namespace
+ − 1192
* @param $name the new name for the page
+ − 1193
* @return string error string or success message
+ − 1194
*/
+ − 1195
+ − 1196
function rename($page_id, $namespace, $name)
+ − 1197
{
+ − 1198
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 1199
+ − 1200
$pname = $paths->nslist[$namespace] . $page_id;
+ − 1201
+ − 1202
$prot = ( ( $paths->pages[$pname]['protected'] == 2 && $session->user_logged_in && $session->reg_time + 60*60*24*4 < time() ) || $paths->pages[$pname]['protected'] == 1) ? true : false;
+ − 1203
$wiki = ( ( $paths->pages[$pname]['wiki_mode'] == 2 && getConfig('wiki_mode') == '1') || $paths->pages[$pname]['wiki_mode'] == 1) ? true : false;
+ − 1204
15
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 1205
if( empty($name))
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 1206
{
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 1207
die('Name is too short');
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 1208
}
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 1209
if( ( $session->get_permissions('rename') && ( ( $prot && $session->get_permissions('even_when_protected') ) || !$prot ) ) && ( $paths->namespace != 'Special' && $paths->namespace != 'Admin' ))
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 1210
{
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 1211
$e = $db->sql_query('INSERT INTO '.table_prefix.'logs(time_id,date_string,log_type,action,page_id,namespace,author,edit_summary) VALUES('.time().', \''.date('d M Y h:i a').'\', \'page\', \'rename\', \''.$db->escape($paths->cpage['urlname_nons']).'\', \''.$paths->namespace.'\', \''.$db->escape($session->username).'\', \''.$db->escape($paths->cpage['name']).'\')');
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 1212
if ( !$e )
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 1213
{
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 1214
$db->_die('The page title could not be updated.');
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 1215
}
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 1216
$e = $db->sql_query('UPDATE '.table_prefix.'pages SET name=\''.$db->escape($name).'\' WHERE urlname=\''.$db->escape($page_id).'\' AND namespace=\''.$db->escape($namespace).'\';');
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 1217
if ( !$e )
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 1218
{
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 1219
$db->_die('The page title could not be updated.');
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 1220
}
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 1221
else
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 1222
{
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 1223
return('The page "'.$paths->pages[$pname]['name'].'" has been renamed to "'.$name.'". You are encouraged to leave a comment explaining your action.' . "\n\n" . 'You will see the change take effect the next time you reload this page.');
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 1224
}
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 1225
}
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 1226
else
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 1227
{
1
+ − 1228
return('Access is denied.');
+ − 1229
}
+ − 1230
}
+ − 1231
+ − 1232
/**
+ − 1233
* Flushes (clears) the action logs for a given page
+ − 1234
* @param $page_id the page ID
+ − 1235
* @param $namespace the namespace
+ − 1236
* @return string error/success string
+ − 1237
*/
+ − 1238
+ − 1239
function flushlogs($page_id, $namespace)
+ − 1240
{
+ − 1241
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 1242
if(!$session->get_permissions('clear_logs')) die('Administrative privileges are required to flush logs, you loser.');
32
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1243
$e = $db->sql_query('DELETE FROM '.table_prefix.'logs WHERE page_id=\''.$db->escape($page_id).'\' AND namespace=\''.$db->escape($namespace).'\';');
1
+ − 1244
if(!$e) $db->_die('The log entries could not be deleted.');
32
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1245
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1246
// If the page exists, make a backup of it in case it gets spammed/vandalized
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1247
// If not, the admin's probably deleting a trash page
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1248
if ( isset($paths->pages[ $paths->nslist[$namespace] . $page_id ]) )
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1249
{
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1250
$e = $db->sql_query('SELECT page_text,char_tag FROM '.table_prefix.'page_text WHERE page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\';');
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1251
if(!$e) $db->_die('The current page text could not be selected; as a result, creating the backup of the page failed. Please make a backup copy of the page by clicking Edit this page and then clicking Save Changes.');
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1252
$row = $db->fetchrow();
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1253
$db->free_result();
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1254
$q='INSERT INTO '.table_prefix.'logs(log_type,action,time_id,date_string,page_id,namespace,page_text,char_tag,author,edit_summary,minor_edit) VALUES(\'page\', \'edit\', '.time().', \''.date('d M Y h:i a').'\', \''.$page_id.'\', \''.$namespace.'\', \''.$db->escape($row['page_text']).'\', \''.$row['char_tag'].'\', \''.$session->username.'\', \''."Automatic backup created when logs were purged".'\', '.'false'.');';
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1255
if(!$db->sql_query($q)) $db->_die('The history (log) entry could not be inserted into the logs table.');
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1256
}
1
+ − 1257
return('The logs for this page have been cleared. A backup of this page has been added to the logs table so that this page can be restored in case of vandalism or spam later.');
+ − 1258
}
+ − 1259
+ − 1260
/**
+ − 1261
* Deletes a page.
28
+ − 1262
* @param string $page_id the condemned page ID
+ − 1263
* @param string $namespace the condemned namespace
+ − 1264
* @param string The reason for deleting the page in question
1
+ − 1265
* @return string
+ − 1266
*/
+ − 1267
28
+ − 1268
function deletepage($page_id, $namespace, $reason)
1
+ − 1269
{
+ − 1270
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 1271
$perms = $session->fetch_page_acl($page_id, $namespace);
28
+ − 1272
$x = trim($reason);
+ − 1273
if ( empty($x) )
+ − 1274
{
+ − 1275
return 'Invalid reason for deletion passed';
+ − 1276
}
+ − 1277
if(!$perms->get_permissions('delete_page')) return('Administrative privileges are required to delete pages, you loser.');
+ − 1278
$e = $db->sql_query('INSERT INTO '.table_prefix.'logs(time_id,date_string,log_type,action,page_id,namespace,author,edit_summary) VALUES('.time().', \''.date('d M Y h:i a').'\', \'page\', \'delete\', \''.$page_id.'\', \''.$namespace.'\', \''.$session->username.'\', \'' . $db->escape(htmlspecialchars($reason)) . '\')');
1
+ − 1279
if(!$e) $db->_die('The page log entry could not be inserted.');
+ − 1280
$e = $db->sql_query('DELETE FROM '.table_prefix.'categories WHERE page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\'');
+ − 1281
if(!$e) $db->_die('The page categorization entries could not be deleted.');
+ − 1282
$e = $db->sql_query('DELETE FROM '.table_prefix.'comments WHERE page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\'');
+ − 1283
if(!$e) $db->_die('The page comments could not be deleted.');
+ − 1284
$e = $db->sql_query('DELETE FROM '.table_prefix.'page_text WHERE page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\'');
+ − 1285
if(!$e) $db->_die('The page text entry could not be deleted.');
+ − 1286
$e = $db->sql_query('DELETE FROM '.table_prefix.'pages WHERE urlname=\''.$page_id.'\' AND namespace=\''.$namespace.'\'');
+ − 1287
if(!$e) $db->_die('The page entry could not be deleted.');
+ − 1288
$e = $db->sql_query('DELETE FROM '.table_prefix.'files WHERE page_id=\''.$page_id.'\'');
+ − 1289
if(!$e) $db->_die('The file entry could not be deleted.');
+ − 1290
return('This page has been deleted. Note that there is still a log of edits and actions in the database, and anyone with admin rights can raise this page from the dead unless the log is cleared. If the deleted file is an image, there may still be cached thumbnails of it in the cache/ directory, which is inaccessible to users.');
+ − 1291
}
+ − 1292
+ − 1293
/**
+ − 1294
* Increments the deletion votes for a page by 1, and adds the current username/IP to the list of users that have voted for the page to prevent dual-voting
+ − 1295
* @param $page_id the page ID
+ − 1296
* @param $namespace the namespace
+ − 1297
* @return string
+ − 1298
*/
+ − 1299
+ − 1300
function delvote($page_id, $namespace)
+ − 1301
{
+ − 1302
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 1303
if(!$session->get_permissions('vote_delete'))
+ − 1304
return 'Access denied';
+ − 1305
$pname = $paths->nslist[$namespace] . $page_id;
+ − 1306
$cv = $paths->pages[$pname]['delvotes'];
+ − 1307
$ips = $paths->pages[$pname]['delvote_ips'];
+ − 1308
$ips = explode('|', $ips);
+ − 1309
if(in_array($_SERVER['REMOTE_ADDR'], $ips)) return('It appears that you have already voted to have this page deleted.');
+ − 1310
if($session->user_logged_in)
+ − 1311
if(in_array($session->username, $ips))
+ − 1312
return('It appears that you have already voted to have this page deleted.');
+ − 1313
$ips[] = $_SERVER['REMOTE_ADDR'];
+ − 1314
if($session->user_logged_in) $ips[] = $session->username;
+ − 1315
$ips = implode('|', $ips);
+ − 1316
$ips = substr($ips, 1, strlen($ips));
+ − 1317
$cv++;
+ − 1318
$q = 'UPDATE '.table_prefix.'pages SET delvotes='.$cv.',delvote_ips=\''.$ips.'\' WHERE urlname=\''.$page_id.'\' AND namespace=\''.$namespace.'\'';
+ − 1319
$w = $db->sql_query($q);
+ − 1320
if(!$w) return("Error updating pages table: ".mysql_error()."\n\nAttemped SQL:\n".$q);
+ − 1321
return('Your vote to have this page deleted has been cast.'."\nYou are encouraged to leave a comment explaining the reason for your vote.");
+ − 1322
}
+ − 1323
+ − 1324
/**
+ − 1325
* Resets the number of votes against a page to 0.
+ − 1326
* @param $page_id the page ID
+ − 1327
* @param $namespace the namespace
+ − 1328
* @return string
+ − 1329
*/
+ − 1330
+ − 1331
function resetdelvotes($page_id, $namespace)
+ − 1332
{
+ − 1333
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 1334
if(!$session->get_permissions('vote_reset')) die('You need moderator rights in order to do this, stinkin\' hacker.');
+ − 1335
$q = 'UPDATE '.table_prefix.'pages SET delvotes=0,delvote_ips=\'\' WHERE urlname=\''.$page_id.'\' AND namespace=\''.$namespace.'\'';
+ − 1336
$e = $db->sql_query($q);
+ − 1337
if(!$e) $db->_die('The number of delete votes was not reset.');
+ − 1338
else return('The number of votes for having this page deleted has been reset to zero.');
+ − 1339
}
+ − 1340
+ − 1341
/**
29
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
diff
changeset
+ − 1342
* Gets a list of styles for a given theme name. As of Banshee, this returns JSON.
1
+ − 1343
* @param $id the name of the directory for the theme
29
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
diff
changeset
+ − 1344
* @return string JSON string with an array containing a list of themes
1
+ − 1345
*/
+ − 1346
+ − 1347
function getstyles()
+ − 1348
{
29
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
diff
changeset
+ − 1349
$json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
diff
changeset
+ − 1350
1
+ − 1351
$dir = './themes/'.$_GET['id'].'/css/';
+ − 1352
$list = Array();
+ − 1353
// Open a known directory, and proceed to read its contents
+ − 1354
if (is_dir($dir)) {
+ − 1355
if ($dh = opendir($dir)) {
+ − 1356
while (($file = readdir($dh)) !== false) {
+ − 1357
if(preg_match('#^(.*?)\.css$#is', $file) && $file != '_printable.css') { // _printable.css should be included with every theme
+ − 1358
// it should be a copy of the original style, but
+ − 1359
// mostly black and white
+ − 1360
// Note to self: document this
+ − 1361
$list[] = substr($file, 0, strlen($file)-4);
+ − 1362
}
+ − 1363
}
+ − 1364
closedir($dh);
+ − 1365
}
+ − 1366
}
29
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
diff
changeset
+ − 1367
else
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
diff
changeset
+ − 1368
{
39
c83ff194977a
Changed animation on flying message boxes; bugfix for "Array" response in theme changer; added diff CSS to enano-shared; allowed spaces in username during install
Dan
diff
changeset
+ − 1369
return($json->encode(Array('mode' => 'error', 'error' => $dir.' is not a dir')));
29
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
diff
changeset
+ − 1370
}
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
diff
changeset
+ − 1371
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
diff
changeset
+ − 1372
return $json->encode($list);
1
+ − 1373
}
+ − 1374
+ − 1375
/**
+ − 1376
* Assembles a Javascript app with category information
+ − 1377
* @param $page_id the page ID
+ − 1378
* @param $namespace the namespace
+ − 1379
* @return string Javascript code
+ − 1380
*/
+ − 1381
+ − 1382
function catedit($page_id, $namespace)
+ − 1383
{
+ − 1384
$d = PageUtils::catedit_raw($page_id, $namespace);
+ − 1385
return $d[0] . ' /* BEGIN CONTENT */ document.getElementById("ajaxEditContainer").innerHTML = unescape(\''.rawurlencode($d[1]).'\');';
+ − 1386
}
+ − 1387
+ − 1388
/**
+ − 1389
* Does the actual HTML/javascript generation for cat editing, but returns an array
+ − 1390
* @access private
+ − 1391
*/
+ − 1392
+ − 1393
function catedit_raw($page_id, $namespace)
+ − 1394
{
+ − 1395
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 1396
ob_start();
+ − 1397
$_ob = '';
+ − 1398
$e = $db->sql_query('SELECT category_id FROM '.table_prefix.'categories WHERE page_id=\''.$paths->cpage['urlname_nons'].'\' AND namespace=\''.$paths->namespace.'\'');
+ − 1399
if(!$e) jsdie('Error selecting category information for current page: '.mysql_error());
+ − 1400
$cat_current = Array();
+ − 1401
while($r = $db->fetchrow())
+ − 1402
{
+ − 1403
$cat_current[] = $r;
+ − 1404
}
+ − 1405
$db->free_result();
+ − 1406
$cat_all = Array();
+ − 1407
for($i=0;$i<sizeof($paths->pages)/2;$i++)
+ − 1408
{
+ − 1409
if($paths->pages[$i]['namespace']=='Category') $cat_all[] = $paths->pages[$i];
+ − 1410
}
+ − 1411
+ − 1412
// Make $cat_all an associative array, like $paths->pages
+ − 1413
$sz = sizeof($cat_all);
+ − 1414
for($i=0;$i<$sz;$i++)
+ − 1415
{
+ − 1416
$cat_all[$cat_all[$i]['urlname_nons']] = $cat_all[$i];
+ − 1417
}
+ − 1418
// Now, the "zipper" function - join the list of categories with the list of cats that this page is a part of
+ − 1419
$cat_info = $cat_all;
+ − 1420
for($i=0;$i<sizeof($cat_current);$i++)
+ − 1421
{
+ − 1422
$un = $cat_current[$i]['category_id'];
+ − 1423
$cat_info[$un]['member'] = true;
+ − 1424
}
+ − 1425
// Now copy the information we just set into the numerically named keys
+ − 1426
for($i=0;$i<sizeof($cat_info)/2;$i++)
+ − 1427
{
+ − 1428
$un = $cat_info[$i]['urlname_nons'];
+ − 1429
$cat_info[$i] = $cat_info[$un];
+ − 1430
}
+ − 1431
+ − 1432
echo 'catlist = new Array();'; // Initialize the client-side category list
+ − 1433
$_ob .= '<h3>Select which categories this page should be included in.</h3>
+ − 1434
<form name="mdgCatForm" action="'.makeUrlNS($namespace, $page_id, 'do=catedit').'" method="post">';
+ − 1435
if ( sizeof($cat_info) < 1 )
+ − 1436
{
+ − 1437
$_ob .= '<p>There are no categories on this site yet.</p>';
+ − 1438
}
+ − 1439
for ( $i = 0; $i < sizeof($cat_info) / 2; $i++ )
+ − 1440
{
+ − 1441
// Protection code added 1/3/07
+ − 1442
// Updated 3/4/07
+ − 1443
$is_prot = false;
+ − 1444
$perms = $session->fetch_page_acl($cat_info[$i]['urlname_nons'], 'Category');
+ − 1445
if ( !$session->get_permissions('edit_cat') || !$perms->get_permissions('edit_cat') ||
+ − 1446
( $cat_info[$i]['really_protected'] && !$perms->get_permissions('even_when_protected') ) )
+ − 1447
$is_prot = true;
+ − 1448
$prot = ( $is_prot ) ? ' disabled="disabled" ' : '';
+ − 1449
$prottext = ( $is_prot ) ? ' <img alt="(protected)" width="16" height="16" src="'.scriptPath.'/images/lock16.png" />' : '';
+ − 1450
echo 'catlist['.$i.'] = \''.$cat_info[$i]['urlname_nons'].'\';';
+ − 1451
$_ob .= '<span class="catCheck"><input '.$prot.' name="'.$cat_info[$i]['urlname_nons'].'" id="mdgCat_'.$cat_info[$i]['urlname_nons'].'" type="checkbox"';
+ − 1452
if(isset($cat_info[$i]['member'])) $_ob .= ' checked="checked"';
+ − 1453
$_ob .= '/> <label for="mdgCat_'.$cat_info[$i]['urlname_nons'].'">'.$cat_info[$i]['name'].$prottext.'</label></span><br />';
+ − 1454
}
+ − 1455
+ − 1456
$disabled = ( sizeof($cat_info) < 1 ) ? 'disabled="disabled"' : '';
+ − 1457
+ − 1458
$_ob .= '<div style="border-top: 1px solid #CCC; padding-top: 5px; margin-top: 10px;"><input name="__enanoSaveButton" ' . $disabled . ' style="font-weight: bold;" type="submit" onclick="ajaxCatSave(); return false;" value="Save changes" /> <input name="__enanoCatCancel" type="submit" onclick="ajaxReset(); return false;" value="Cancel" /></div></form>';
+ − 1459
+ − 1460
$cont = ob_get_contents();
+ − 1461
ob_end_clean();
+ − 1462
return Array($cont, $_ob);
+ − 1463
}
+ − 1464
+ − 1465
/**
+ − 1466
* Saves category information
+ − 1467
* WARNING: If $which_cats is empty, all the category information for the selected page will be nuked!
+ − 1468
* @param $page_id string the page ID
+ − 1469
* @param $namespace string the namespace
+ − 1470
* @param $which_cats array associative array of categories to put the page in
+ − 1471
* @return string "GOOD" on success, error string on failure
+ − 1472
*/
+ − 1473
+ − 1474
function catsave($page_id, $namespace, $which_cats)
+ − 1475
{
+ − 1476
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 1477
if(!$session->get_permissions('edit_cat')) return('Insufficient privileges to change category information');
+ − 1478
+ − 1479
$page_perms = $session->fetch_page_acl($page_id, $namespace);
+ − 1480
$page_data =& $paths->pages[$paths->nslist[$namespace].$page_id];
+ − 1481
+ − 1482
$cat_all = Array();
+ − 1483
for($i=0;$i<sizeof($paths->pages)/2;$i++)
+ − 1484
{
+ − 1485
if($paths->pages[$i]['namespace']=='Category') $cat_all[] = $paths->pages[$i];
+ − 1486
}
+ − 1487
+ − 1488
// Make $cat_all an associative array, like $paths->pages
+ − 1489
$sz = sizeof($cat_all);
+ − 1490
for($i=0;$i<$sz;$i++)
+ − 1491
{
+ − 1492
$cat_all[$cat_all[$i]['urlname_nons']] = $cat_all[$i];
+ − 1493
}
+ − 1494
+ − 1495
$rowlist = Array();
+ − 1496
+ − 1497
for($i=0;$i<sizeof($cat_all)/2;$i++)
+ − 1498
{
+ − 1499
$auth = true;
+ − 1500
$perms = $session->fetch_page_acl($cat_all[$i]['urlname_nons'], 'Category');
+ − 1501
if ( !$session->get_permissions('edit_cat') || !$perms->get_permissions('edit_cat') ||
+ − 1502
( $cat_all[$i]['really_protected'] && !$perms->get_permissions('even_when_protected') ) ||
+ − 1503
( !$page_perms->get_permissions('even_when_protected') && $page_data['protected'] == '1' ) )
+ − 1504
$auth = false;
+ − 1505
if(!$auth)
+ − 1506
{
+ − 1507
// Find out if the page is currently in the category
+ − 1508
$q = $db->sql_query('SELECT * FROM '.table_prefix.'categories WHERE page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\';');
+ − 1509
if(!$q)
+ − 1510
return 'MySQL error: '.$db->get_error();
+ − 1511
if($db->numrows() > 0)
+ − 1512
{
+ − 1513
$auth = true;
+ − 1514
$which_cats[$cat_all[$i]['urlname_nons']] = true; // Force the category to stay in its current state
+ − 1515
}
+ − 1516
$db->free_result();
+ − 1517
}
+ − 1518
if(isset($which_cats[$cat_all[$i]['urlname_nons']]) && $which_cats[$cat_all[$i]['urlname_nons']] == true /* for clarity ;-) */ && $auth ) $rowlist[] = '(\''.$page_id.'\', \''.$namespace.'\', \''.$cat_all[$i]['urlname_nons'].'\')';
+ − 1519
}
+ − 1520
if(sizeof($rowlist) > 0)
+ − 1521
{
+ − 1522
$val = implode(',', $rowlist);
+ − 1523
$q = 'INSERT INTO '.table_prefix.'categories(page_id,namespace,category_id) VALUES' . $val . ';';
+ − 1524
$e = $db->sql_query('DELETE FROM '.table_prefix.'categories WHERE page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\';');
+ − 1525
if(!$e) $db->_die('The old category data could not be deleted.');
+ − 1526
$e = $db->sql_query($q);
+ − 1527
if(!$e) $db->_die('The new category data could not be inserted.');
+ − 1528
return('GOOD');
+ − 1529
}
+ − 1530
else
+ − 1531
{
+ − 1532
$e = $db->sql_query('DELETE FROM '.table_prefix.'categories WHERE page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\';');
+ − 1533
if(!$e) $db->_die('The old category data could not be deleted.');
+ − 1534
return('GOOD');
+ − 1535
}
+ − 1536
}
+ − 1537
+ − 1538
/**
+ − 1539
* Sets the wiki mode level for a page.
+ − 1540
* @param $page_id string the page ID
+ − 1541
* @param $namespace string the namespace
+ − 1542
* @param $level int 0 for off, 1 for on, 2 for use global setting
+ − 1543
* @return string "GOOD" on success, error string on failure
+ − 1544
*/
+ − 1545
+ − 1546
function setwikimode($page_id, $namespace, $level)
+ − 1547
{
+ − 1548
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 1549
if(!$session->get_permissions('set_wiki_mode')) return('Insufficient access rights');
+ − 1550
if(!isset($level) || (isset($level) && !preg_match('#^([0-2]){1}$#', (string)$level))) return('Invalid mode string');
+ − 1551
$q = $db->sql_query('UPDATE '.table_prefix.'pages SET wiki_mode='.$level.' WHERE urlname=\''.$page_id.'\' AND namespace=\''.$namespace.'\';');
+ − 1552
if(!$q) return('Error during update query: '.mysql_error()."\n\nSQL Backtrace:\n".$db->sql_backtrace());
+ − 1553
return('GOOD');
+ − 1554
}
+ − 1555
+ − 1556
/**
+ − 1557
* Sets the access password for a page.
+ − 1558
* @param $page_id string the page ID
+ − 1559
* @param $namespace string the namespace
+ − 1560
* @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
+ − 1561
* @return string
+ − 1562
*/
+ − 1563
+ − 1564
function setpass($page_id, $namespace, $pass)
+ − 1565
{
+ − 1566
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 1567
// Determine permissions
+ − 1568
if($paths->pages[$paths->nslist[$namespace].$page_id]['password'] != '')
+ − 1569
$a = $session->get_permissions('password_reset');
+ − 1570
else
+ − 1571
$a = $session->get_permissions('password_set');
+ − 1572
if(!$a)
+ − 1573
return 'Access is denied';
+ − 1574
if(!isset($pass)) return('Password was not set on URL');
+ − 1575
$p = $pass;
+ − 1576
if(!preg_match('#([0-9a-f]){40,40}#', $p)) $p = sha1($p);
+ − 1577
if($p=='da39a3ee5e6b4b0d3255bfef95601890afd80709') $p = '';
+ − 1578
$e = $db->sql_query('UPDATE '.table_prefix.'pages SET password=\''.$p.'\' WHERE urlname=\''.$page_id.'\' AND namespace=\''.$namespace.'\';');
+ − 1579
if(!$e) die('PageUtils::setpass(): Error during update query: '.mysql_error()."\n\nSQL Backtrace:\n".$db->sql_backtrace());
+ − 1580
if($p=='') return('The password for this page has been disabled.');
+ − 1581
else return('The password for this page has been set.');
+ − 1582
}
+ − 1583
+ − 1584
/**
+ − 1585
* Generates some preview HTML
+ − 1586
* @param $text string the wikitext to use
+ − 1587
* @return string
+ − 1588
*/
+ − 1589
+ − 1590
function genPreview($text)
+ − 1591
{
+ − 1592
return '<div class="info-box"><b>Reminder:</b> This is only a preview - your changes to this page have not yet been saved.</div><div style="background-color: #F8F8F8; padding: 10px; border: 1px dashed #406080; max-height: 250px; overflow: auto; margin: 1em 0 1em 1em;">'.RenderMan::render(RenderMan::preprocess_text($text, false, false)).'</div>';
+ − 1593
}
+ − 1594
+ − 1595
/**
+ − 1596
* Makes a scrollable box
+ − 1597
* @param string $text the inner HTML
+ − 1598
* @param int $height Optional - the maximum height. Defaults to 250.
+ − 1599
* @return string
+ − 1600
*/
+ − 1601
+ − 1602
function scrollBox($text, $height = 250)
+ − 1603
{
+ − 1604
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>';
+ − 1605
}
+ − 1606
+ − 1607
/**
+ − 1608
* Generates a diff summary between two page revisions.
+ − 1609
* @param $page_id the page ID
+ − 1610
* @param $namespace the namespace
+ − 1611
* @param $id1 the time ID of the first revision
+ − 1612
* @param $id2 the time ID of the second revision
+ − 1613
* @return string XHTML-formatted diff
+ − 1614
*/
+ − 1615
+ − 1616
function pagediff($page_id, $namespace, $id1, $id2)
+ − 1617
{
+ − 1618
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 1619
if(!$session->get_permissions('history_view'))
+ − 1620
return 'Access denied';
+ − 1621
if(!preg_match('#^([0-9]+)$#', (string)$id1) ||
+ − 1622
!preg_match('#^([0-9]+)$#', (string)$id2 )) return 'SQL injection attempt';
+ − 1623
// OK we made it through security
+ − 1624
// Safest way to make sure we don't end up with the revisions in wrong columns is to make 2 queries
+ − 1625
if(!$q1 = $db->sql_query('SELECT page_text,char_tag,author,edit_summary FROM '.table_prefix.'logs WHERE time_id='.$id1.' AND log_type=\'page\' AND action=\'edit\' AND page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\';')) return 'MySQL error: '.mysql_error();
+ − 1626
if(!$q2 = $db->sql_query('SELECT page_text,char_tag,author,edit_summary FROM '.table_prefix.'logs WHERE time_id='.$id2.' AND log_type=\'page\' AND action=\'edit\' AND page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\';')) return 'MySQL error: '.mysql_error();
+ − 1627
$row1 = $db->fetchrow($q1);
+ − 1628
$db->free_result($q1);
+ − 1629
$row2 = $db->fetchrow($q2);
+ − 1630
$db->free_result($q2);
+ − 1631
if(sizeof($row1) < 1 || sizeof($row2) < 2) return 'Couldn\'t find any rows that matched the query. The time ID probably doesn\'t exist in the logs table.';
+ − 1632
$text1 = $row1['page_text'];
+ − 1633
$text2 = $row2['page_text'];
+ − 1634
$time1 = date('F d, Y h:i a', $id1);
+ − 1635
$time2 = date('F d, Y h:i a', $id2);
+ − 1636
$_ob = "
+ − 1637
<p>Comparing revisions: {$time1} → {$time2}</p>
+ − 1638
";
+ − 1639
// Free some memory
+ − 1640
unset($row1, $row2, $q1, $q2);
+ − 1641
+ − 1642
$_ob .= RenderMan::diff($text1, $text2);
+ − 1643
return $_ob;
+ − 1644
}
+ − 1645
+ − 1646
/**
+ − 1647
* Gets ACL information about the selected page for target type X and target ID Y.
+ − 1648
* @param string $page_id The page ID
+ − 1649
* @param string $namespace The namespace
+ − 1650
* @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.
+ − 1651
* @return array
+ − 1652
*/
+ − 1653
+ − 1654
function acl_editor($parms = Array())
+ − 1655
{
+ − 1656
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 1657
if(!$session->get_permissions('edit_acl') && $session->user_level < USER_LEVEL_ADMIN)
40
+ − 1658
{
+ − 1659
return Array(
+ − 1660
'mode' => 'error',
+ − 1661
'error' => 'You are not authorized to view or edit access control lists.'
+ − 1662
);
+ − 1663
}
1
+ − 1664
$parms['page_id'] = ( isset($parms['page_id']) ) ? $parms['page_id'] : false;
+ − 1665
$parms['namespace'] = ( isset($parms['namespace']) ) ? $parms['namespace'] : false;
+ − 1666
$page_id =& $parms['page_id'];
+ − 1667
$namespace =& $parms['namespace'];
+ − 1668
$page_where_clause = ( empty($page_id) || empty($namespace) ) ? 'AND a.page_id IS NULL AND a.namespace IS NULL' : 'AND a.page_id=\''.$db->escape($page_id).'\' AND a.namespace=\''.$db->escape($namespace).'\'';
+ − 1669
$page_where_clause_lite = ( empty($page_id) || empty($namespace) ) ? 'AND page_id IS NULL AND namespace IS NULL' : 'AND page_id=\''.$db->escape($page_id).'\' AND namespace=\''.$db->escape($namespace).'\'';
+ − 1670
//die(print_r($page_id,true));
+ − 1671
$template->load_theme();
+ − 1672
// $perms_obj = $session->fetch_page_acl($page_id, $namespace);
+ − 1673
$perms_obj =& $session;
+ − 1674
$return = Array();
+ − 1675
if ( !file_exists(ENANO_ROOT . '/themes/' . $session->theme . '/acledit.tpl') )
+ − 1676
{
+ − 1677
return Array(
+ − 1678
'mode' => 'error',
+ − 1679
'error' => 'It seems that (a) the file acledit.tpl is missing from these theme, and (b) the JSON response is working.',
+ − 1680
);
+ − 1681
}
+ − 1682
$return['template'] = $template->extract_vars('acledit.tpl');
+ − 1683
$return['page_id'] = $page_id;
+ − 1684
$return['namespace'] = $namespace;
+ − 1685
if(isset($parms['mode']))
+ − 1686
{
+ − 1687
switch($parms['mode'])
+ − 1688
{
+ − 1689
case 'listgroups':
+ − 1690
$return['groups'] = Array();
+ − 1691
$q = $db->sql_query('SELECT group_id,group_name FROM '.table_prefix.'groups ORDER BY group_name ASC;');
+ − 1692
while($row = $db->fetchrow())
+ − 1693
{
+ − 1694
$return['groups'][] = Array(
+ − 1695
'id' => $row['group_id'],
+ − 1696
'name' => $row['group_name'],
+ − 1697
);
+ − 1698
}
+ − 1699
$db->free_result();
+ − 1700
break;
+ − 1701
case 'seltarget':
+ − 1702
$return['mode'] = 'seltarget';
+ − 1703
$return['acl_types'] = $perms_obj->acl_types;
+ − 1704
$return['acl_deps'] = $perms_obj->acl_deps;
+ − 1705
$return['acl_descs'] = $perms_obj->acl_descs;
+ − 1706
$return['target_type'] = $parms['target_type'];
+ − 1707
$return['target_id'] = $parms['target_id'];
+ − 1708
switch($parms['target_type'])
+ − 1709
{
+ − 1710
case ACL_TYPE_USER:
+ − 1711
$q = $db->sql_query('SELECT a.rules,u.user_id FROM '.table_prefix.'users AS u
+ − 1712
LEFT JOIN '.table_prefix.'acl AS a
+ − 1713
ON a.target_id=u.user_id
+ − 1714
WHERE a.target_type='.ACL_TYPE_USER.'
+ − 1715
AND u.username=\''.$db->escape($parms['target_id']).'\'
+ − 1716
'.$page_where_clause.';');
+ − 1717
if(!$q)
+ − 1718
return(Array('mode'=>'error','error'=>mysql_error()));
+ − 1719
if($db->numrows() < 1)
+ − 1720
{
+ − 1721
$return['type'] = 'new';
+ − 1722
$q = $db->sql_query('SELECT user_id FROM '.table_prefix.'users WHERE username=\''.$db->escape($parms['target_id']).'\';');
+ − 1723
if(!$q)
+ − 1724
return(Array('mode'=>'error','error'=>mysql_error()));
+ − 1725
if($db->numrows() < 1)
+ − 1726
return Array('mode'=>'error','error'=>'The username you entered was not found.');
+ − 1727
$row = $db->fetchrow();
+ − 1728
$return['target_name'] = $return['target_id'];
+ − 1729
$return['target_id'] = intval($row['user_id']);
+ − 1730
$return['current_perms'] = $session->acl_types;
+ − 1731
}
+ − 1732
else
+ − 1733
{
+ − 1734
$return['type'] = 'edit';
+ − 1735
$row = $db->fetchrow();
+ − 1736
$return['target_name'] = $return['target_id'];
+ − 1737
$return['target_id'] = intval($row['user_id']);
+ − 1738
$return['current_perms'] = $session->acl_merge($perms_obj->acl_types, $session->string_to_perm($row['rules']));
+ − 1739
}
+ − 1740
$db->free_result();
+ − 1741
// Eliminate types that don't apply to this namespace
+ − 1742
if ( $namespace )
+ − 1743
{
+ − 1744
foreach ( $return['current_perms'] AS $i => $perm )
+ − 1745
{
+ − 1746
if ( ( $page_id != null && $namespace != null ) && ( !in_array ( $namespace, $session->acl_scope[$i] ) && !in_array('All', $session->acl_scope[$i]) ) )
+ − 1747
{
+ − 1748
// echo "// SCOPE CONTROL: eliminating: $i\n";
+ − 1749
unset($return['current_perms'][$i]);
+ − 1750
unset($return['acl_types'][$i]);
+ − 1751
unset($return['acl_descs'][$i]);
+ − 1752
unset($return['acl_deps'][$i]);
+ − 1753
}
+ − 1754
}
+ − 1755
}
+ − 1756
break;
+ − 1757
case ACL_TYPE_GROUP:
+ − 1758
$q = $db->sql_query('SELECT a.rules,g.group_name,g.group_id FROM '.table_prefix.'groups AS g
+ − 1759
LEFT JOIN '.table_prefix.'acl AS a
+ − 1760
ON a.target_id=g.group_id
+ − 1761
WHERE a.target_type='.ACL_TYPE_GROUP.'
+ − 1762
AND g.group_id=\''.intval($parms['target_id']).'\'
+ − 1763
'.$page_where_clause.';');
+ − 1764
if(!$q)
+ − 1765
return(Array('mode'=>'error','error'=>mysql_error()));
+ − 1766
if($db->numrows() < 1)
+ − 1767
{
+ − 1768
$return['type'] = 'new';
+ − 1769
$q = $db->sql_query('SELECT group_id,group_name FROM '.table_prefix.'groups WHERE group_id=\''.intval($parms['target_id']).'\';');
+ − 1770
if(!$q)
+ − 1771
return(Array('mode'=>'error','error'=>mysql_error()));
+ − 1772
if($db->numrows() < 1)
+ − 1773
return Array('mode'=>'error','error'=>'The group ID you submitted is not valid.');
+ − 1774
$row = $db->fetchrow();
+ − 1775
$return['target_name'] = $row['group_name'];
+ − 1776
$return['target_id'] = intval($row['group_id']);
+ − 1777
$return['current_perms'] = $session->acl_types;
+ − 1778
}
+ − 1779
else
+ − 1780
{
+ − 1781
$return['type'] = 'edit';
+ − 1782
$row = $db->fetchrow();
+ − 1783
$return['target_name'] = $row['group_name'];
+ − 1784
$return['target_id'] = intval($row['group_id']);
+ − 1785
$return['current_perms'] = $session->acl_merge($session->acl_types, $session->string_to_perm($row['rules']));
+ − 1786
}
+ − 1787
$db->free_result();
+ − 1788
// Eliminate types that don't apply to this namespace
+ − 1789
if ( $namespace )
+ − 1790
{
+ − 1791
foreach ( $return['current_perms'] AS $i => $perm )
+ − 1792
{
+ − 1793
if ( ( $page_id != false && $namespace != false ) && ( !in_array ( $namespace, $session->acl_scope[$i] ) && !in_array('All', $session->acl_scope[$i]) ) )
+ − 1794
{
+ − 1795
// echo "// SCOPE CONTROL: eliminating: $i\n"; //; ".print_r($namespace,true).":".print_r($page_id,true)."\n";
+ − 1796
unset($return['current_perms'][$i]);
+ − 1797
unset($return['acl_types'][$i]);
+ − 1798
unset($return['acl_descs'][$i]);
+ − 1799
unset($return['acl_deps'][$i]);
+ − 1800
}
+ − 1801
}
+ − 1802
}
+ − 1803
//return Array('mode'=>'debug','text'=>print_r($return, true));
+ − 1804
break;
+ − 1805
default:
+ − 1806
return Array('mode'=>'error','error','Invalid ACL type ID');
+ − 1807
break;
+ − 1808
}
+ − 1809
return $return;
+ − 1810
break;
+ − 1811
case 'save_new':
+ − 1812
case 'save_edit':
19
5d003b6c9e89
Added demo mode functionality to various parts of Enano (unlocked only with a plugin) and fixed groups table
Dan
diff
changeset
+ − 1813
if ( defined('ENANO_DEMO_MODE') )
5d003b6c9e89
Added demo mode functionality to various parts of Enano (unlocked only with a plugin) and fixed groups table
Dan
diff
changeset
+ − 1814
{
5d003b6c9e89
Added demo mode functionality to various parts of Enano (unlocked only with a plugin) and fixed groups table
Dan
diff
changeset
+ − 1815
return Array('mode'=>'error','error'=>'Editing access control lists is disabled in the administration demo.');
5d003b6c9e89
Added demo mode functionality to various parts of Enano (unlocked only with a plugin) and fixed groups table
Dan
diff
changeset
+ − 1816
}
1
+ − 1817
$q = $db->sql_query('DELETE FROM '.table_prefix.'acl WHERE target_type='.intval($parms['target_type']).' AND target_id='.intval($parms['target_id']).'
+ − 1818
'.$page_where_clause_lite.';');
+ − 1819
if(!$q)
+ − 1820
return Array('mode'=>'error','error'=>mysql_error());
+ − 1821
$rules = $session->perm_to_string($parms['perms']);
+ − 1822
if ( sizeof ( $rules ) < 1 )
+ − 1823
{
+ − 1824
return array(
+ − 1825
'mode' => 'error',
+ − 1826
'error' => 'Supplied rule list has a length of zero'
+ − 1827
);
+ − 1828
}
+ − 1829
$q = ($page_id && $namespace) ? 'INSERT INTO '.table_prefix.'acl ( target_type, target_id, page_id, namespace, rules )
+ − 1830
VALUES( '.intval($parms['target_type']).', '.intval($parms['target_id']).', \''.$db->escape($page_id).'\', \''.$db->escape($namespace).'\', \''.$db->escape($rules).'\' )' :
+ − 1831
'INSERT INTO '.table_prefix.'acl ( target_type, target_id, rules )
+ − 1832
VALUES( '.intval($parms['target_type']).', '.intval($parms['target_id']).', \''.$db->escape($rules).'\' )';
+ − 1833
if(!$db->sql_query($q)) return Array('mode'=>'error','error'=>mysql_error());
+ − 1834
return Array(
+ − 1835
'mode' => 'success',
+ − 1836
'target_type' => $parms['target_type'],
+ − 1837
'target_id' => $parms['target_id'],
+ − 1838
'target_name' => $parms['target_name'],
+ − 1839
'page_id' => $page_id,
+ − 1840
'namespace' => $namespace,
+ − 1841
);
+ − 1842
break;
+ − 1843
case 'delete':
19
5d003b6c9e89
Added demo mode functionality to various parts of Enano (unlocked only with a plugin) and fixed groups table
Dan
diff
changeset
+ − 1844
if ( defined('ENANO_DEMO_MODE') )
5d003b6c9e89
Added demo mode functionality to various parts of Enano (unlocked only with a plugin) and fixed groups table
Dan
diff
changeset
+ − 1845
{
5d003b6c9e89
Added demo mode functionality to various parts of Enano (unlocked only with a plugin) and fixed groups table
Dan
diff
changeset
+ − 1846
return Array('mode'=>'error','error'=>'Editing access control lists is disabled in the administration demo.');
5d003b6c9e89
Added demo mode functionality to various parts of Enano (unlocked only with a plugin) and fixed groups table
Dan
diff
changeset
+ − 1847
}
1
+ − 1848
$q = $db->sql_query('DELETE FROM '.table_prefix.'acl WHERE target_type='.intval($parms['target_type']).' AND target_id='.intval($parms['target_id']).'
+ − 1849
'.$page_where_clause_lite.';');
+ − 1850
if(!$q)
+ − 1851
return Array('mode'=>'error','error'=>mysql_error());
+ − 1852
return Array(
+ − 1853
'mode' => 'delete',
+ − 1854
'target_type' => $parms['target_type'],
+ − 1855
'target_id' => $parms['target_id'],
+ − 1856
'target_name' => $parms['target_name'],
+ − 1857
'page_id' => $page_id,
+ − 1858
'namespace' => $namespace,
+ − 1859
);
+ − 1860
break;
+ − 1861
default:
+ − 1862
return Array('mode'=>'error','error'=>'Hacking attempt');
+ − 1863
break;
+ − 1864
}
+ − 1865
}
+ − 1866
return $return;
+ − 1867
}
+ − 1868
+ − 1869
/**
+ − 1870
* Same as PageUtils::acl_editor(), but the parms are a JSON string instead of an array. This also returns a JSON string.
+ − 1871
* @param string $parms Same as PageUtils::acl_editor/$parms, but should be a valid JSON string.
+ − 1872
* @return string
+ − 1873
*/
+ − 1874
+ − 1875
function acl_json($parms = '{ }')
+ − 1876
{
+ − 1877
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 1878
$json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
+ − 1879
$parms = $json->decode($parms);
+ − 1880
$ret = PageUtils::acl_editor($parms);
+ − 1881
$ret = $json->encode($ret);
+ − 1882
return $ret;
+ − 1883
}
+ − 1884
+ − 1885
/**
+ − 1886
* A non-Javascript frontend for the ACL API.
+ − 1887
* @param array The request data, if any, this should be in the format required by PageUtils::acl_editor()
+ − 1888
*/
+ − 1889
+ − 1890
function aclmanager($parms)
+ − 1891
{
+ − 1892
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 1893
ob_start();
+ − 1894
// Convenience
+ − 1895
$formstart = '<form
+ − 1896
action="' . makeUrl($paths->page, 'do=aclmanager', true) . '"
+ − 1897
method="post" enctype="multipart/form-data"
+ − 1898
onsubmit="if(!submitAuthorized) return false;"
+ − 1899
>';
+ − 1900
$formend = '</form>';
+ − 1901
$parms = PageUtils::acl_preprocess($parms);
+ − 1902
$response = PageUtils::acl_editor($parms);
+ − 1903
$response = PageUtils::acl_postprocess($response);
+ − 1904
+ − 1905
//die('<pre>' . htmlspecialchars(print_r($response, true)) . '</pre>');
+ − 1906
+ − 1907
switch($response['mode'])
+ − 1908
{
+ − 1909
case 'debug':
+ − 1910
echo '<pre>' . htmlspecialchars($response['text']) . '</pre>';
+ − 1911
break;
+ − 1912
case 'stage1':
+ − 1913
echo '<h3>Manage page access</h3>
+ − 1914
<p>Please select who should be affected by this access rule.</p>';
+ − 1915
echo $formstart;
+ − 1916
echo '<p><label><input type="radio" name="data[target_type]" value="' . ACL_TYPE_GROUP . '" checked="checked" /> A usergroup</label></p>
+ − 1917
<p><select name="data[target_id_grp]">';
+ − 1918
foreach ( $response['groups'] as $group )
+ − 1919
{
+ − 1920
echo '<option value="' . $group['id'] . '">' . $group['name'] . '</option>';
+ − 1921
}
+ − 1922
echo '</select></p>
+ − 1923
<p><label><input type="radio" name="data[target_type]" value="' . ACL_TYPE_USER . '" /> A specific user</label></p>
+ − 1924
<p>' . $template->username_field('data[target_id_user]') . '</p>
+ − 1925
<p>What should this access rule control?</p>
+ − 1926
<p><label><input name="data[scope]" value="only_this" type="radio" checked="checked" /> Only this page</p>
+ − 1927
<p><label><input name="data[scope]" value="entire_site" type="radio" /> The entire site</p>
+ − 1928
<div style="margin: 0 auto 0 0; text-align: right;">
+ − 1929
<input name="data[mode]" value="seltarget" type="hidden" />
+ − 1930
<input type="hidden" name="data[page_id]" value="' . $paths->cpage['urlname_nons'] . '" />
+ − 1931
<input type="hidden" name="data[namespace]" value="' . $paths->namespace . '" />
+ − 1932
<input type="submit" value="Next >" />
+ − 1933
</div>';
+ − 1934
echo $formend;
+ − 1935
break;
+ − 1936
case 'success':
+ − 1937
echo '<div class="info-box">
+ − 1938
<b>Permissions updated</b><br />
+ − 1939
The permissions for ' . $response['target_name'] . ' on this page have been updated successfully.<br />
+ − 1940
' . $formstart . '
+ − 1941
<input type="hidden" name="data[mode]" value="seltarget" />
+ − 1942
<input type="hidden" name="data[target_type]" value="' . $response['target_type'] . '" />
+ − 1943
<input type="hidden" name="data[target_id_user]" value="' . ( ( intval($response['target_type']) == ACL_TYPE_USER ) ? $response['target_name'] : $response['target_id'] ) .'" />
+ − 1944
<input type="hidden" name="data[target_id_grp]" value="' . ( ( intval($response['target_type']) == ACL_TYPE_USER ) ? $response['target_name'] : $response['target_id'] ) .'" />
+ − 1945
<input type="hidden" name="data[scope]" value="' . ( ( $response['page_id'] ) ? 'only_this' : 'entire_site' ) . '" />
+ − 1946
<input type="hidden" name="data[page_id]" value="' . ( ( $response['page_id'] ) ? $response['page_id'] : 'false' ) . '" />
+ − 1947
<input type="hidden" name="data[namespace]" value="' . ( ( $response['namespace'] ) ? $response['namespace'] : 'false' ) . '" />
+ − 1948
<input type="submit" value="Return to ACL editor" /> <input type="submit" name="data[act_go_stage1]" value="Return to user/scope selection" />
+ − 1949
' . $formend . '
+ − 1950
</div>';
+ − 1951
break;
+ − 1952
case 'delete':
+ − 1953
echo '<div class="info-box">
+ − 1954
<b>Rule deleted</b><br />
+ − 1955
The selected access rule has been successfully deleted.<br />
+ − 1956
' . $formstart . '
+ − 1957
<input type="hidden" name="data[mode]" value="seltarget" />
+ − 1958
<input type="hidden" name="data[target_type]" value="' . $response['target_type'] . '" />
+ − 1959
<input type="hidden" name="data[target_id_user]" value="' . ( ( intval($response['target_type']) == ACL_TYPE_USER ) ? $response['target_name'] : $response['target_id'] ) .'" />
+ − 1960
<input type="hidden" name="data[target_id_grp]" value="' . ( ( intval($response['target_type']) == ACL_TYPE_USER ) ? $response['target_name'] : $response['target_id'] ) .'" />
+ − 1961
<input type="hidden" name="data[scope]" value="' . ( ( $response['page_id'] ) ? 'only_this' : 'entire_site' ) . '" />
+ − 1962
<input type="hidden" name="data[page_id]" value="' . ( ( $response['page_id'] ) ? $response['page_id'] : 'false' ) . '" />
+ − 1963
<input type="hidden" name="data[namespace]" value="' . ( ( $response['namespace'] ) ? $response['namespace'] : 'false' ) . '" />
+ − 1964
<input type="submit" value="Return to ACL editor" /> <input type="submit" name="data[act_go_stage1]" value="Return to user/scope selection" />
+ − 1965
' . $formend . '
+ − 1966
</div>';
+ − 1967
break;
+ − 1968
case 'seltarget':
+ − 1969
if ( $response['type'] == 'edit' )
+ − 1970
{
+ − 1971
echo '<h3>Editing permissions</h3>';
+ − 1972
}
+ − 1973
else
+ − 1974
{
+ − 1975
echo '<h3>Create new rule</h3>';
+ − 1976
}
+ − 1977
$type = ( $response['target_type'] == ACL_TYPE_GROUP ) ? 'group' : 'user';
+ − 1978
$scope = ( $response['page_id'] ) ? 'this page' : 'this entire site';
+ − 1979
echo 'This panel allows you to edit what the '.$type.' "'.$response['target_name'].'" can do on <b>'.$scope.'</b>. Unless you set a permission to "Deny", these permissions may be overridden by other rules.';
+ − 1980
echo $formstart;
+ − 1981
$parser = $template->makeParserText( $response['template']['acl_field_begin'] );
+ − 1982
echo $parser->run();
+ − 1983
$parser = $template->makeParserText( $response['template']['acl_field_item'] );
+ − 1984
$cls = 'row2';
+ − 1985
foreach ( $response['acl_types'] as $acl_type => $value )
+ − 1986
{
+ − 1987
$vars = Array(
+ − 1988
'FIELD_DENY_CHECKED' => '',
+ − 1989
'FIELD_DISALLOW_CHECKED' => '',
+ − 1990
'FIELD_WIKIMODE_CHECKED' => '',
+ − 1991
'FIELD_ALLOW_CHECKED' => '',
+ − 1992
);
+ − 1993
$cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
+ − 1994
$vars['ROW_CLASS'] = $cls;
+ − 1995
+ − 1996
switch ( $response['current_perms'][$acl_type] )
+ − 1997
{
+ − 1998
case AUTH_ALLOW:
+ − 1999
$vars['FIELD_ALLOW_CHECKED'] = 'checked="checked"';
+ − 2000
break;
+ − 2001
case AUTH_WIKIMODE:
+ − 2002
$vars['FIELD_WIKIMODE_CHECKED'] = 'checked="checked"';
+ − 2003
break;
+ − 2004
case AUTH_DISALLOW:
+ − 2005
default:
+ − 2006
$vars['FIELD_DISALLOW_CHECKED'] = 'checked="checked"';
+ − 2007
break;
+ − 2008
case AUTH_DENY:
+ − 2009
$vars['FIELD_DENY_CHECKED'] = 'checked="checked"';
+ − 2010
break;
+ − 2011
}
+ − 2012
$vars['FIELD_NAME'] = 'data[perms][' . $acl_type . ']';
+ − 2013
$vars['FIELD_DESC'] = $response['acl_descs'][$acl_type];
+ − 2014
$parser->assign_vars($vars);
+ − 2015
echo $parser->run();
+ − 2016
}
+ − 2017
$parser = $template->makeParserText( $response['template']['acl_field_end'] );
+ − 2018
echo $parser->run();
+ − 2019
echo '<div style="margin: 10px auto 0 0; text-align: right;">
+ − 2020
<input name="data[mode]" value="save_' . $response['type'] . '" type="hidden" />
+ − 2021
<input type="hidden" name="data[page_id]" value="' . (( $response['page_id'] ) ? $response['page_id'] : 'false') . '" />
+ − 2022
<input type="hidden" name="data[namespace]" value="' . (( $response['namespace'] ) ? $response['namespace'] : 'false') . '" />
+ − 2023
<input type="hidden" name="data[target_type]" value="' . $response['target_type'] . '" />
+ − 2024
<input type="hidden" name="data[target_id]" value="' . $response['target_id'] . '" />
+ − 2025
<input type="hidden" name="data[target_name]" value="' . $response['target_name'] . '" />
+ − 2026
<input type="submit" value="Save changes" /> <input type="submit" name="data[act_delete_rule]" value="Delete rule" style="color: #AA0000;" onclick="return confirm(\'Do you really want to delete this ACL rule?\');" />
+ − 2027
</div>';
+ − 2028
echo $formend;
+ − 2029
break;
+ − 2030
case 'error':
+ − 2031
ob_end_clean();
+ − 2032
die_friendly('Error occurred', '<p>Error returned by permissions API:</p><pre>' . htmlspecialchars($response['error']) . '</pre>');
+ − 2033
break;
+ − 2034
}
+ − 2035
$ret = ob_get_contents();
+ − 2036
ob_end_clean();
+ − 2037
echo
+ − 2038
$template->getHeader() .
+ − 2039
$ret .
+ − 2040
$template->getFooter();
+ − 2041
}
+ − 2042
+ − 2043
/**
+ − 2044
* Preprocessor to turn the form-submitted data from the ACL editor into something the backend can handle
+ − 2045
* @param array The posted data
+ − 2046
* @return array
+ − 2047
* @access private
+ − 2048
*/
+ − 2049
+ − 2050
function acl_preprocess($parms)
+ − 2051
{
+ − 2052
if ( !isset($parms['mode']) )
+ − 2053
// Nothing to do
+ − 2054
return $parms;
+ − 2055
switch ( $parms['mode'] )
+ − 2056
{
+ − 2057
case 'seltarget':
+ − 2058
+ − 2059
// Who's affected?
+ − 2060
$parms['target_type'] = intval( $parms['target_type'] );
+ − 2061
$parms['target_id'] = ( $parms['target_type'] == ACL_TYPE_GROUP ) ? $parms['target_id_grp'] : $parms['target_id_user'];
+ − 2062
+ − 2063
case 'save_edit':
+ − 2064
case 'save_new':
+ − 2065
if ( isset($parms['act_delete_rule']) )
+ − 2066
{
+ − 2067
$parms['mode'] = 'delete';
+ − 2068
}
+ − 2069
+ − 2070
// Scope (just this page or entire site?)
+ − 2071
if ( $parms['scope'] == 'entire_site' || ( $parms['page_id'] == 'false' && $parms['namespace'] == 'false' ) )
+ − 2072
{
+ − 2073
$parms['page_id'] = false;
+ − 2074
$parms['namespace'] = false;
+ − 2075
}
+ − 2076
+ − 2077
break;
+ − 2078
}
+ − 2079
+ − 2080
if ( isset($parms['act_go_stage1']) )
+ − 2081
{
+ − 2082
$parms = array(
+ − 2083
'mode' => 'listgroups'
+ − 2084
);
+ − 2085
}
+ − 2086
+ − 2087
return $parms;
+ − 2088
}
+ − 2089
+ − 2090
function acl_postprocess($response)
+ − 2091
{
+ − 2092
if(!isset($response['mode']))
+ − 2093
{
+ − 2094
if ( isset($response['groups']) )
+ − 2095
$response['mode'] = 'stage1';
+ − 2096
else
+ − 2097
$response = Array(
+ − 2098
'mode' => 'error',
+ − 2099
'error' => 'Invalid action passed by API backend.',
+ − 2100
);
+ − 2101
}
+ − 2102
return $response;
+ − 2103
}
+ − 2104
+ − 2105
}
+ − 2106
+ − 2107
?>