mod.php, pages.php: pass the context to the mod pages

This commit is contained in:
Zankaria 2024-08-15 17:05:43 +02:00 committed by Zankaria
parent cb71e00b50
commit 7ef2d42bb0
2 changed files with 80 additions and 77 deletions

View file

@ -1,9 +1,9 @@
<?php <?php
/* /*
* Copyright (c) 2010-2013 Tinyboard Development Group * Copyright (c) 2010-2013 Tinyboard Development Group
*/ */
use Vichan\Context;
use Vichan\Functions\Format;
use Vichan\Functions\Net; use Vichan\Functions\Net;
use function Vichan\Functions\Net\decode_cursor; use function Vichan\Functions\Net\decode_cursor;
@ -45,7 +45,7 @@ function clone_wrapped_with_exist_check($clonefn, $src, $dest) {
} }
} }
function mod_login($redirect = false) { function mod_login(Context $ctx, $redirect = false) {
global $config; global $config;
$args = []; $args = [];
@ -81,22 +81,22 @@ function mod_login($redirect = false) {
mod_page(_('Login'), 'mod/login.html', $args); mod_page(_('Login'), 'mod/login.html', $args);
} }
function mod_confirm($request) { function mod_confirm(Context $ctx, $request) {
$args = array('request' => $request, 'token' => make_secure_link_token($request)); $args = [ 'request' => $request, 'token' => make_secure_link_token($request) ];
if(isset($_GET['thread'])) { if(isset($_GET['thread'])) {
$args['rest'] = 'thread=' . $_GET['thread']; $args['rest'] = 'thread=' . $_GET['thread'];
} }
mod_page(_('Confirm action'), 'mod/confirm.html', $args); mod_page(_('Confirm action'), 'mod/confirm.html', $args);
} }
function mod_logout() { function mod_logout(Context $ctx) {
global $config; global $config;
destroyCookies(); destroyCookies();
header('Location: ?/', true, $config['redirect_http']); header('Location: ?/', true, $config['redirect_http']);
} }
function mod_dashboard() { function mod_dashboard(Context $ctx) {
global $config, $mod; global $config, $mod;
$args = []; $args = [];
@ -190,7 +190,7 @@ function mod_dashboard() {
mod_page(_('Dashboard'), 'mod/dashboard.html', $args); mod_page(_('Dashboard'), 'mod/dashboard.html', $args);
} }
function mod_search_redirect() { function mod_search_redirect(Context $ctx) {
global $config; global $config;
if (!hasPermission($config['mod']['search'])) if (!hasPermission($config['mod']['search']))
@ -213,7 +213,7 @@ function mod_search_redirect() {
} }
} }
function mod_search($type, $search_query_escaped, $page_no = 1) { function mod_search(Context $ctx, $type, $search_query_escaped, $page_no = 1) {
global $pdo, $config; global $pdo, $config;
if (!hasPermission($config['mod']['search'])) if (!hasPermission($config['mod']['search']))
@ -368,7 +368,7 @@ function mod_search($type, $search_query_escaped, $page_no = 1) {
)); ));
} }
function mod_edit_board($boardName) { function mod_edit_board(Context $ctx, $boardName) {
global $board, $config; global $board, $config;
if (!openBoard($boardName)) if (!openBoard($boardName))
@ -470,7 +470,7 @@ function mod_edit_board($boardName) {
} }
} }
function mod_new_board() { function mod_new_board(Context $ctx) {
global $config, $board; global $config, $board;
if (!hasPermission($config['mod']['newboard'])) if (!hasPermission($config['mod']['newboard']))
@ -536,7 +536,7 @@ function mod_new_board() {
mod_page(_('New board'), 'mod/board.html', array('new' => true, 'token' => make_secure_link_token('new-board'))); mod_page(_('New board'), 'mod/board.html', array('new' => true, 'token' => make_secure_link_token('new-board')));
} }
function mod_noticeboard($page_no = 1) { function mod_noticeboard(Context $ctx, $page_no = 1) {
global $config, $pdo, $mod; global $config, $pdo, $mod;
if ($page_no < 1) if ($page_no < 1)
@ -591,7 +591,7 @@ function mod_noticeboard($page_no = 1) {
)); ));
} }
function mod_noticeboard_delete($id) { function mod_noticeboard_delete(Context $ctx, $id) {
global $config; global $config;
if (!hasPermission($config['mod']['noticeboard_delete'])) if (!hasPermission($config['mod']['noticeboard_delete']))
@ -609,7 +609,7 @@ function mod_noticeboard_delete($id) {
header('Location: ?/noticeboard', true, $config['redirect_http']); header('Location: ?/noticeboard', true, $config['redirect_http']);
} }
function mod_news($page_no = 1) { function mod_news(Context $ctx, $page_no = 1) {
global $config, $pdo, $mod; global $config, $pdo, $mod;
if ($page_no < 1) if ($page_no < 1)
@ -656,7 +656,7 @@ function mod_news($page_no = 1) {
mod_page(_('News'), 'mod/news.html', array('news' => $news, 'count' => $count, 'token' => make_secure_link_token('edit_news'))); mod_page(_('News'), 'mod/news.html', array('news' => $news, 'count' => $count, 'token' => make_secure_link_token('edit_news')));
} }
function mod_news_delete($id) { function mod_news_delete(Context $ctx, $id) {
global $config; global $config;
if (!hasPermission($config['mod']['news_delete'])) if (!hasPermission($config['mod']['news_delete']))
@ -671,7 +671,7 @@ function mod_news_delete($id) {
header('Location: ?/edit_news', true, $config['redirect_http']); header('Location: ?/edit_news', true, $config['redirect_http']);
} }
function mod_log($page_no = 1) { function mod_log(Context $ctx, $page_no = 1) {
global $config; global $config;
if ($page_no < 1) if ($page_no < 1)
@ -696,7 +696,7 @@ function mod_log($page_no = 1) {
mod_page(_('Moderation log'), 'mod/log.html', array('logs' => $logs, 'count' => $count)); mod_page(_('Moderation log'), 'mod/log.html', array('logs' => $logs, 'count' => $count));
} }
function mod_user_log($username, $page_no = 1) { function mod_user_log(Context $ctx, $username, $page_no = 1) {
global $config; global $config;
if ($page_no < 1) if ($page_no < 1)
@ -733,7 +733,7 @@ function protect_ip($entry) {
return preg_replace(array($ipv4_link_regex, $ipv6_link_regex), "xxxx", $entry); return preg_replace(array($ipv4_link_regex, $ipv6_link_regex), "xxxx", $entry);
} }
function mod_board_log($board, $page_no = 1, $hide_names = false, $public = false) { function mod_board_log(Context $ctx, $board, $page_no = 1, $hide_names = false, $public = false) {
global $config; global $config;
if ($page_no < 1) if ($page_no < 1)
@ -766,8 +766,8 @@ function mod_board_log($board, $page_no = 1, $hide_names = false, $public = fals
mod_page(_('Board log'), 'mod/log.html', array('logs' => $logs, 'count' => $count, 'board' => $board, 'hide_names' => $hide_names, 'public' => $public)); mod_page(_('Board log'), 'mod/log.html', array('logs' => $logs, 'count' => $count, 'board' => $board, 'hide_names' => $hide_names, 'public' => $public));
} }
function mod_view_catalog($boardName) { function mod_view_catalog(Context $ctx, $boardName) {
global $config, $mod; global $config;
require_once($config['dir']['themes'].'/catalog/theme.php'); require_once($config['dir']['themes'].'/catalog/theme.php');
$settings = []; $settings = [];
$settings['boards'] = $boardName; $settings['boards'] = $boardName;
@ -798,7 +798,7 @@ function mod_view_catalog($boardName) {
} }
} }
function mod_view_board($boardName, $page_no = 1) { function mod_view_board(Context $ctx, $boardName, $page_no = 1) {
global $config, $mod; global $config, $mod;
if (!openBoard($boardName)){ if (!openBoard($boardName)){
@ -829,7 +829,7 @@ function mod_view_board($boardName, $page_no = 1) {
echo Element('index.html', $page); echo Element('index.html', $page);
} }
function mod_view_thread($boardName, $thread) { function mod_view_thread(Context $ctx, $boardName, $thread) {
global $config, $mod; global $config, $mod;
if (!openBoard($boardName)) if (!openBoard($boardName))
@ -839,7 +839,7 @@ function mod_view_thread($boardName, $thread) {
echo $page; echo $page;
} }
function mod_view_thread50($boardName, $thread) { function mod_view_thread50(Context $ctx, $boardName, $thread) {
global $config, $mod; global $config, $mod;
if (!openBoard($boardName)) if (!openBoard($boardName))
@ -849,7 +849,7 @@ function mod_view_thread50($boardName, $thread) {
echo $page; echo $page;
} }
function mod_ip_remove_note($ip, $id) { function mod_ip_remove_note(Context $ctx, $ip, $id) {
global $config, $mod; global $config, $mod;
if (!hasPermission($config['mod']['remove_notes'])) if (!hasPermission($config['mod']['remove_notes']))
@ -868,7 +868,7 @@ function mod_ip_remove_note($ip, $id) {
header('Location: ?/IP/' . $ip . '#notes', true, $config['redirect_http']); header('Location: ?/IP/' . $ip . '#notes', true, $config['redirect_http']);
} }
function mod_ip($ip, string $encoded_cursor = '') { function mod_ip(Context $ctx, $ip, string $encoded_cursor = '') {
global $config, $mod; global $config, $mod;
if (filter_var($ip, FILTER_VALIDATE_IP) === false) if (filter_var($ip, FILTER_VALIDATE_IP) === false)
@ -1078,7 +1078,7 @@ function mod_ban() {
header('Location: ?/', true, $config['redirect_http']); header('Location: ?/', true, $config['redirect_http']);
} }
function mod_warning() { function mod_warning(Context $ctx) {
global $config; global $config;
if (!hasPermission($config['mod']['warning'])) if (!hasPermission($config['mod']['warning']))
@ -1095,7 +1095,7 @@ function mod_warning() {
header('Location: ?/', true, $config['redirect_http']); header('Location: ?/', true, $config['redirect_http']);
} }
function mod_bans() { function mod_bans(Context $ctx) {
global $config; global $config;
global $mod; global $mod;
@ -1130,7 +1130,7 @@ function mod_bans() {
)); ));
} }
function mod_bans_json() { function mod_bans_json(Context $ctx) {
global $config, $mod; global $config, $mod;
if (!hasPermission($config['mod']['ban'])) if (!hasPermission($config['mod']['ban']))
@ -1142,7 +1142,7 @@ function mod_bans_json() {
Bans::stream_json(false, false, !hasPermission($config['mod']['view_banstaff']), $mod['boards']); Bans::stream_json(false, false, !hasPermission($config['mod']['view_banstaff']), $mod['boards']);
} }
function mod_ban_appeals() { function mod_ban_appeals(Context $ctx) {
global $config, $board; global $config, $board;
if (!hasPermission($config['mod']['view_ban_appeals'])) if (!hasPermission($config['mod']['view_ban_appeals']))
@ -1224,7 +1224,7 @@ function mod_ban_appeals() {
)); ));
} }
function mod_lock($board, $unlock, $post) { function mod_lock(Context $ctx, $board, $unlock, $post) {
global $config; global $config;
if (!openBoard($board)) if (!openBoard($board))
@ -1260,7 +1260,7 @@ function mod_lock($board, $unlock, $post) {
event('lock', $post); event('lock', $post);
} }
function mod_sticky($board, $unsticky, $post) { function mod_sticky(Context $ctx, $board, $unsticky, $post) {
global $config; global $config;
if (!openBoard($board)) if (!openBoard($board))
@ -1284,7 +1284,7 @@ function mod_sticky($board, $unsticky, $post) {
header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']); header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']);
} }
function mod_cycle($board, $uncycle, $post) { function mod_cycle(Context $ctx, $board, $uncycle, $post) {
global $config; global $config;
if (!openBoard($board)) if (!openBoard($board))
@ -1306,7 +1306,7 @@ function mod_cycle($board, $uncycle, $post) {
header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']); header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']);
} }
function mod_bumplock($board, $unbumplock, $post) { function mod_bumplock(Context $ctx, $board, $unbumplock, $post) {
global $config; global $config;
if (!openBoard($board)) if (!openBoard($board))
@ -1328,8 +1328,8 @@ function mod_bumplock($board, $unbumplock, $post) {
header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']); header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']);
} }
function mod_move_reply($originBoard, $postID) { function mod_move_reply(Context $ctx, $originBoard, $postID) {
global $board, $config, $mod; global $board, $config;
if (!openBoard($originBoard)) if (!openBoard($originBoard))
error($config['error']['noboard']); error($config['error']['noboard']);
@ -1432,8 +1432,8 @@ function mod_move_reply($originBoard, $postID) {
} }
function mod_move($originBoard, $postID) { function mod_move(Context $ctx, $originBoard, $postID) {
global $board, $config, $mod, $pdo; global $board, $config, $pdo;
if (!openBoard($originBoard)) if (!openBoard($originBoard))
error($config['error']['noboard']); error($config['error']['noboard']);
@ -1657,8 +1657,9 @@ function mod_merge($originBoard, $postID) {
$query = prepare(sprintf('SELECT * FROM ``posts_%s`` WHERE `id` = :id AND `thread` IS NULL', $originBoard)); $query = prepare(sprintf('SELECT * FROM ``posts_%s`` WHERE `id` = :id AND `thread` IS NULL', $originBoard));
$query->bindValue(':id', $postID); $query->bindValue(':id', $postID);
$query->execute() or error(db_error($query)); $query->execute() or error(db_error($query));
if (!$post = $query->fetch(PDO::FETCH_ASSOC)) if (!$post = $query->fetch(PDO::FETCH_ASSOC)) {
error($config['error']['404']); error($config['error']['404']);
}
$sourceOp = ""; $sourceOp = "";
if ($post['thread']){ if ($post['thread']){
$sourceOp = $post['thread']; $sourceOp = $post['thread'];
@ -1886,7 +1887,7 @@ function mod_merge($originBoard, $postID) {
mod_page(_('Merge thread'), 'mod/merge.html', array('post' => $postID, 'board' => $originBoard, 'boards' => $boards, 'token' => $security_token)); mod_page(_('Merge thread'), 'mod/merge.html', array('post' => $postID, 'board' => $originBoard, 'boards' => $boards, 'token' => $security_token));
} }
function mod_ban_post($board, $delete, $post, $token = false) { function mod_ban_post(Context $ctx, $board, $delete, $post, $token = false) {
global $config, $mod; global $config, $mod;
if (!openBoard($board)) if (!openBoard($board))
@ -2009,7 +2010,7 @@ function mod_ban_post($board, $delete, $post, $token = false) {
mod_page(_('New ban'), 'mod/ban_form.html', $args); mod_page(_('New ban'), 'mod/ban_form.html', $args);
} }
function mod_warning_post($board,$post, $token = false) { function mod_warning_post(Context $ctx, $board, $post, $token = false) {
global $config, $mod; global $config, $mod;
if (!openBoard($board)) if (!openBoard($board))
@ -2109,8 +2110,8 @@ function mod_warning_post($board,$post, $token = false) {
mod_page(_('New warning'), 'mod/warning_form.html', $args); mod_page(_('New warning'), 'mod/warning_form.html', $args);
} }
function mod_edit_post($board, $edit_raw_html, $postID) { function mod_edit_post(Context $ctx, $board, $edit_raw_html, $postID) {
global $config, $mod; global $config;
if (!openBoard($board)) if (!openBoard($board))
error($config['error']['noboard']); error($config['error']['noboard']);
@ -2186,8 +2187,8 @@ function mod_edit_post($board, $edit_raw_html, $postID) {
} }
} }
function mod_delete($board, $post) { function mod_delete(Context $ctx, $board, $post) {
global $config, $mod; global $config;
if (!openBoard($board)) if (!openBoard($board))
error($config['error']['noboard']); error($config['error']['noboard']);
@ -2252,8 +2253,8 @@ function mod_delete($board, $post) {
} }
} }
function mod_deletefile($board, $post, $file) { function mod_deletefile(Context $ctx, $board, $post, $file) {
global $config, $mod; global $config;
if (!openBoard($board)) if (!openBoard($board))
error($config['error']['noboard']); error($config['error']['noboard']);
@ -2275,8 +2276,8 @@ function mod_deletefile($board, $post, $file) {
header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']); header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']);
} }
function mod_spoiler_image($board, $post, $file) { function mod_spoiler_image(Context $ctx, $board, $post, $file) {
global $config, $mod; global $config;
if (!openBoard($board)) if (!openBoard($board))
error($config['error']['noboard']); error($config['error']['noboard']);
@ -2320,8 +2321,8 @@ function mod_spoiler_image($board, $post, $file) {
header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']); header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']);
} }
function mod_deletebyip($boardName, $post, $global = false) { function mod_deletebyip(Context $ctx, $boardName, $post, $global = false) {
global $config, $mod, $board; global $config, $board;
$global = (bool)$global; $global = (bool)$global;
@ -2442,7 +2443,7 @@ function mod_deletebyip($boardName, $post, $global = false) {
header('Location: ?/' . sprintf($config['board_path'], $boardName) . $config['file_index'], true, $config['redirect_http']); header('Location: ?/' . sprintf($config['board_path'], $boardName) . $config['file_index'], true, $config['redirect_http']);
} }
function mod_user($uid) { function mod_user(Context $ctx, $uid) {
global $config, $mod; global $config, $mod;
if (!hasPermission($config['mod']['editusers']) && !(hasPermission($config['mod']['change_password']) && $uid == $mod['id'])) if (!hasPermission($config['mod']['editusers']) && !(hasPermission($config['mod']['change_password']) && $uid == $mod['id']))
@ -2567,7 +2568,7 @@ function mod_user($uid) {
)); ));
} }
function mod_user_new() { function mod_user_new(Context $ctx) {
global $pdo, $config; global $pdo, $config;
if (!hasPermission($config['mod']['createusers'])) if (!hasPermission($config['mod']['createusers']))
@ -2620,7 +2621,7 @@ function mod_user_new() {
} }
function mod_users() { function mod_users(Context $ctx) {
global $config; global $config;
if (!hasPermission($config['mod']['manageusers'])) if (!hasPermission($config['mod']['manageusers']))
@ -2641,7 +2642,7 @@ function mod_users() {
mod_page(sprintf('%s (%d)', _('Manage users'), count($users)), 'mod/users.html', array('users' => $users)); mod_page(sprintf('%s (%d)', _('Manage users'), count($users)), 'mod/users.html', array('users' => $users));
} }
function mod_user_promote($uid, $action) { function mod_user_promote(Context $ctx, $uid, $action) {
global $config; global $config;
if (!hasPermission($config['mod']['promoteusers'])) if (!hasPermission($config['mod']['promoteusers']))
@ -2684,7 +2685,7 @@ function mod_user_promote($uid, $action) {
header('Location: ?/users', true, $config['redirect_http']); header('Location: ?/users', true, $config['redirect_http']);
} }
function mod_pm($id, $reply = false) { function mod_pm(Context $ctx, $id, $reply = false) {
global $mod, $config; global $mod, $config;
if ($reply && !hasPermission($config['mod']['create_pm'])) if ($reply && !hasPermission($config['mod']['create_pm']))
@ -2739,7 +2740,7 @@ function mod_pm($id, $reply = false) {
} }
} }
function mod_inbox() { function mod_inbox(Context $ctx) {
global $config, $mod; global $config, $mod;
$query = prepare('SELECT `unread`,``pms``.`id`, `time`, `sender`, `to`, `message`, `username` FROM ``pms`` LEFT JOIN ``mods`` ON ``mods``.`id` = `sender` WHERE `to` = :mod ORDER BY `unread` DESC, `time` DESC'); $query = prepare('SELECT `unread`,``pms``.`id`, `time`, `sender`, `to`, `message`, `username` FROM ``pms`` LEFT JOIN ``mods`` ON ``mods``.`id` = `sender` WHERE `to` = :mod ORDER BY `unread` DESC, `time` DESC');
@ -2763,7 +2764,7 @@ function mod_inbox() {
} }
function mod_new_pm($username) { function mod_new_pm(Context $ctx, $username) {
global $config, $mod; global $config, $mod;
if (!hasPermission($config['mod']['create_pm'])) if (!hasPermission($config['mod']['create_pm']))
@ -2811,7 +2812,7 @@ function mod_new_pm($username) {
)); ));
} }
function mod_rebuild() { function mod_rebuild(Context $ctx) {
global $config, $twig; global $config, $twig;
if (!hasPermission($config['mod']['rebuild'])) if (!hasPermission($config['mod']['rebuild']))
@ -2883,7 +2884,7 @@ function mod_rebuild() {
)); ));
} }
function mod_reports() { function mod_reports(Context $ctx) {
global $config, $mod; global $config, $mod;
if (!hasPermission($config['mod']['reports'])) if (!hasPermission($config['mod']['reports']))
@ -2987,7 +2988,7 @@ function mod_reports() {
); );
} }
function mod_report_dismiss($id, $all = false) { function mod_report_dismiss(Context $ctx, $id, $all = false) {
global $config; global $config;
$query = prepare("SELECT `post`, `board`, `ip` FROM ``reports`` WHERE `id` = :id"); $query = prepare("SELECT `post`, `board`, `ip` FROM ``reports`` WHERE `id` = :id");
@ -3024,7 +3025,7 @@ function mod_report_dismiss($id, $all = false) {
header('Location: ?/reports', true, $config['redirect_http']); header('Location: ?/reports', true, $config['redirect_http']);
} }
function mod_recent_posts($lim,$board_list = false,$json=false) { function mod_recent_posts(Context $ctx, $lim, $board_list = false, $json = false) {
global $config, $mod, $pdo; global $config, $mod, $pdo;
if (!hasPermission($config['mod']['recent'])) if (!hasPermission($config['mod']['recent']))
@ -3122,7 +3123,7 @@ function mod_recent_posts($lim,$board_list = false,$json=false) {
} }
} }
function mod_config($board_config = false) { function mod_config(Context $ctx, $board_config = false) {
global $config, $mod, $board; global $config, $mod, $board;
if ($board_config && !openBoard($board_config)) if ($board_config && !openBoard($board_config))
@ -3262,7 +3263,7 @@ function mod_config($board_config = false) {
)); ));
} }
function mod_themes_list() { function mod_themes_list(Context $ctx) {
global $config; global $config;
if (!hasPermission($config['mod']['themes'])) if (!hasPermission($config['mod']['themes']))
@ -3296,7 +3297,7 @@ function mod_themes_list() {
)); ));
} }
function mod_theme_configure($theme_name) { function mod_theme_configure(Context $ctx, $theme_name) {
global $config; global $config;
if (!hasPermission($config['mod']['themes'])) if (!hasPermission($config['mod']['themes']))
@ -3378,7 +3379,7 @@ function mod_theme_configure($theme_name) {
)); ));
} }
function mod_theme_uninstall($theme_name) { function mod_theme_uninstall(Context $ctx, $theme_name) {
global $config; global $config;
if (!hasPermission($config['mod']['themes'])) if (!hasPermission($config['mod']['themes']))
@ -3395,7 +3396,7 @@ function mod_theme_uninstall($theme_name) {
header('Location: ?/themes', true, $config['redirect_http']); header('Location: ?/themes', true, $config['redirect_http']);
} }
function mod_theme_rebuild($theme_name) { function mod_theme_rebuild(Context $ctx, $theme_name) {
global $config; global $config;
if (!hasPermission($config['mod']['themes'])) if (!hasPermission($config['mod']['themes']))
@ -3436,15 +3437,15 @@ function delete_page_base($page = '', $board = false) {
header('Location: ?/edit_pages' . ($board ? ('/' . $board) : ''), true, $config['redirect_http']); header('Location: ?/edit_pages' . ($board ? ('/' . $board) : ''), true, $config['redirect_http']);
} }
function mod_delete_page($page = '') { function mod_delete_page(Context $ctx, $page = '') {
delete_page_base($page); delete_page_base($ctx, $page);
} }
function mod_delete_page_board($page = '', $board = false) { function mod_delete_page_board(Context $ctx, $page = '', $board = false) {
delete_page_base($page, $board); delete_page_base($ctx, $page, $board);
} }
function mod_edit_page($id) { function mod_edit_page(Context $ctx, $id) {
global $config, $mod, $board; global $config, $mod, $board;
$query = prepare('SELECT * FROM ``pages`` WHERE `id` = :id'); $query = prepare('SELECT * FROM ``pages`` WHERE `id` = :id');
@ -3515,7 +3516,7 @@ function mod_edit_page($id) {
mod_page(sprintf(_('Editing static page: %s'), $page['name']), 'mod/edit_page.html', array('page' => $page, 'token' => make_secure_link_token("edit_page/$id"), 'content' => prettify_textarea($content), 'board' => $board)); mod_page(sprintf(_('Editing static page: %s'), $page['name']), 'mod/edit_page.html', array('page' => $page, 'token' => make_secure_link_token("edit_page/$id"), 'content' => prettify_textarea($content), 'board' => $board));
} }
function mod_pages($board = false) { function mod_pages(Context $ctx, $board = false) {
global $config, $mod, $pdo; global $config, $mod, $pdo;
if (empty($board)) if (empty($board))
@ -3569,7 +3570,7 @@ function mod_pages($board = false) {
mod_page(_('Pages'), 'mod/pages.html', array('pages' => $pages, 'token' => make_secure_link_token('edit_pages' . ($board ? ('/' . $board) : '')), 'board' => $board)); mod_page(_('Pages'), 'mod/pages.html', array('pages' => $pages, 'token' => make_secure_link_token('edit_pages' . ($board ? ('/' . $board) : '')), 'board' => $board));
} }
function mod_debug_antispam() { function mod_debug_antispam(Context $ctx) {
global $pdo, $config; global $pdo, $config;
$args = []; $args = [];
@ -3606,7 +3607,7 @@ function mod_debug_antispam() {
mod_page(_('Debug: Anti-spam'), 'mod/debug/antispam.html', $args); mod_page(_('Debug: Anti-spam'), 'mod/debug/antispam.html', $args);
} }
function mod_debug_recent_posts() { function mod_debug_recent_posts(Context $ctx) {
global $pdo, $config; global $pdo, $config;
$limit = 500; $limit = 500;
@ -3640,7 +3641,7 @@ function mod_debug_recent_posts() {
mod_page(_('Debug: Recent posts'), 'mod/debug/recent_posts.html', array('posts' => $posts, 'flood_posts' => $flood_posts)); mod_page(_('Debug: Recent posts'), 'mod/debug/recent_posts.html', array('posts' => $posts, 'flood_posts' => $flood_posts));
} }
function mod_debug_sql() { function mod_debug_sql(Context $ctx) {
global $config; global $config;
if (!hasPermission($config['mod']['debug_sql'])) if (!hasPermission($config['mod']['debug_sql']))

View file

@ -148,9 +148,11 @@ foreach ($pages as $key => $callback) {
} }
$pages = $new_pages; $pages = $new_pages;
$ctx = Vichan\build_context($config);
foreach ($pages as $uri => $handler) { foreach ($pages as $uri => $handler) {
if (preg_match($uri, $query, $matches)) { if (preg_match($uri, $query, $matches)) {
$matches = array_slice($matches, 1); $matches[0] = $ctx; // Replace the text captured by the full pattern with a reference to the context.
if (isset($matches['board'])) { if (isset($matches['board'])) {
$board_match = $matches['board']; $board_match = $matches['board'];