Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pinc/ProjectTransition.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1227,7 +1227,7 @@ function proj_would_go_to_PP_out(Project $project, ProjectTransition $transition
function round_to_PP_avail_collateral(Project $old_project, Project $project, ProjectTransition $transition, string $who): void
{
$from_round = get_Round_for_project_state($transition->from_state);
generate_post_files($project, $from_round->id, 'LE', false, '');
generate_post_files($project, $from_round, 'LE', false, '');

// Always notify the PM
configure_gettext_for_user($project->username);
Expand Down Expand Up @@ -1285,7 +1285,7 @@ function to_PP_available_collateral(Project $old_project, Project $project, Proj
function round_to_PP_out_collateral(Project $old_project, Project $project, ProjectTransition $transition, string $who): void
{
$from_round = get_Round_for_project_state($transition->from_state);
generate_post_files($project, $from_round->id, 'LE', false, '');
generate_post_files($project, $from_round, 'LE', false, '');

// The project has been checked out to someone for PPing.
// We want to notify the PPer and the PM,
Expand Down
36 changes: 13 additions & 23 deletions pinc/post_files.inc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ include_once($relPath.'wordcheck_engine.inc');
*/
function generate_post_files(
Project $project,
string $limit_round_id,
Round|stdclass $limit_round,
string $which_text,
bool $include_proofers,
string $base_extra
Expand Down Expand Up @@ -41,7 +41,7 @@ function generate_post_files(
}
}

$pages_res = page_info_query($project->projectid, $limit_round_id, $which_text);
$pages_res = page_info_query($project, $limit_round, $which_text);

// Join all the page texts into a plain text file...
$plain_path = "{$pathbase}.txt";
Expand All @@ -67,27 +67,22 @@ function generate_post_files(
*/
function generate_interim_file(
Project $project,
string $limit_round_id,
Round|stdclass $limit_round,
string $which_text,
bool $include_proofers
): void {
if (!$project->pages_table_exists) {
throw new Exception(_("Project table not found, it may have been deleted or archived."));
}

$filename = $project->projectid;
if ('[OCR]' == $limit_round_id) {
$filename .= '_OCR';
$filename = $project->projectid . '_' . $limit_round->id;
if ('EQ' == $which_text) {
$filename .= '_saved';
} else {
$filename .= '_' . $limit_round_id;
if ('EQ' == $which_text) {
$filename .= '_saved';
} else {
$filename .= '_latest';
}
$filename .= '_latest';
}

$pages_res = page_info_query($project->projectid, $limit_round_id, $which_text);
$pages_res = page_info_query($project, $limit_round, $which_text);

// join the page texts together
$filedata = join_proofed_text($pages_res, $include_proofers, null);
Expand Down Expand Up @@ -221,18 +216,13 @@ function join_proofed_text(mysqli_result $pages_res, bool $include_proofers, $fp

// -----------------------------------------------------------------------------

function page_info_query(string $projectid, string $limit_round_id, string $which_text): mysqli_result
function page_info_query(Project $project, Round|stdclass $limit_round, string $which_text): mysqli_result
{
if ($limit_round_id == '[OCR]') { // somewhat kludgey
if ($limit_round->id == 'OCR') {
// doesn't matter what $which_text is.
$text_column_expr = 'master_text';
$text_column_expr = $limit_round->text_column_name;
$user_fields = "";
} else {
$limit_round = get_Round_for_round_id($limit_round_id);
if (is_null($limit_round)) {
throw new UnexpectedValueException("'$limit_round_id' is not a valid round-id\n");
}

if ($which_text == 'EQ') {
// For each page, fetch the text (if any) saved in the selected round.
$text_column_expr = $limit_round->text_column_name;
Expand Down Expand Up @@ -284,12 +274,12 @@ function page_info_query(string $projectid, string $limit_round_id, string $whic

$res = DPDatabase::query("
SELECT $text_column_expr, image $user_fields
FROM $projectid
FROM $project->projectid
ORDER BY image
", throw_on_failure: false);

if (!$res) {
throw new Exception("Could not get $limit_round_id text for $projectid");
throw new Exception("Could not get {$limit_round->id} text for {$project->projectid}");
}

/** @var mysqli_result $res -- mysqli_query("SELECT") never returns true */
Expand Down
2 changes: 1 addition & 1 deletion pinc/project_quick_check.inc
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ function _test_project_for_bad_bytes(string $projectid): PQCResult
return new PQCResult($name, $description, $status, $summary, $details);
}

$pages_res = page_info_query($projectid, 'F2', 'LE');
$pages_res = page_info_query($project, Rounds::get_by_id('F2'), 'LE');

$page_details_url = "$code_url/tools/project_manager/page_detail.php?project=$projectid";
$details_for_this_project = "
Expand Down
4 changes: 2 additions & 2 deletions project.php
Original file line number Diff line number Diff line change
Expand Up @@ -1533,7 +1533,7 @@ function do_post_files(): void
echo "<input type='hidden' name='projectid' value='$projectid'>\n";

if (isset($highest_round_id)) {
echo "<input type='radio' name='round_id' value='[OCR]'>[OCR]&nbsp;\n";
echo "<input type='radio' name='round_id' value='OCR'>OCR&nbsp;\n";
foreach (Rounds::get_all() as $round) {
$checked = ($round->id == $highest_round_id ? 'CHECKED' : '');
echo "<input type='radio' name='round_id' value='$round->id' $checked>$round->id&nbsp;\n";
Expand All @@ -1542,7 +1542,7 @@ function do_post_files(): void
}
}
} else {
echo "<input type='radio' name='round_id' value='[OCR]' CHECKED>[OCR]&nbsp;\n";
echo "<input type='radio' name='round_id' value='OCR' CHECKED>OCR&nbsp;\n";
}
echo "<br>";

Expand Down
21 changes: 9 additions & 12 deletions tools/project_manager/generate_post_files.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@
include_once($relPath.'slim_header.inc');
include_once($relPath.'post_files.inc');

$valid_round_ids = Rounds::get_ids();
array_unshift($valid_round_ids, '[OCR]');

$projectid = get_projectID_param($_REQUEST, 'projectid');
$round_id = get_enumerated_param($_REQUEST, 'round_id', null, $valid_round_ids);
$round = get_round_or_ocr_param($_REQUEST, 'round_id');
$which_text = get_enumerated_param($_REQUEST, 'which_text', null, ['EQ', 'LE']);
$include_proofers = get_integer_param($_REQUEST, 'include_proofers', 0, 0, 1);
$save_files = get_integer_param($_REQUEST, 'save_files', 0, 0, 1);
$include_proofers = get_bool_param($_REQUEST, 'include_proofers', false);
$save_files = get_bool_param($_REQUEST, 'save_files', false);

$errors = [];

Expand Down Expand Up @@ -45,10 +42,10 @@
try {
if ($save_files) {
flush();
generate_post_files($project, $round_id, $which_text, (bool) $include_proofers, '');
generate_post_files($project, $round, $which_text, $include_proofers, '');
echo "<p>" . _("Done.") . "</p>";
} else {
generate_interim_file($project, $round_id, $which_text, (bool) $include_proofers);
generate_interim_file($project, $round, $which_text, $include_proofers);
}
} catch (Exception $exception) {
$errors[] = $exception->getMessage();
Expand All @@ -66,7 +63,7 @@

function output_page_header(Project $project): void
{
global $round_id, $which_text, $include_proofers, $save_files;
global $round, $which_text, $include_proofers, $save_files;

// Allow this function to be called multiple times but only output
// the contents once.
Expand All @@ -82,9 +79,9 @@ function output_page_header(Project $project): void
echo "<p>" . sprintf(_("Generating files for '%s'."), html_safe($project->nameofwork)) . "</p>";
echo "<pre>";
echo "projectid = $project->projectid\n";
echo "round_id = $round_id\n";
echo "round_id = $round->id\n";
echo "which_text = $which_text\n";
echo "include_proofers = $include_proofers\n";
echo "save_files = $save_files\n";
echo "include_proofers = " . ($include_proofers ? 1 : 0) . "\n";
echo "save_files = " . ($save_files ? 1 : 0) . "\n";
echo "</pre>";
}
2 changes: 1 addition & 1 deletion tools/project_manager/show_adhoc_word_details.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ function _get_adhoc_word_list(string $projectid, array $queryWords): array
$messages = [];

// get the latest project text of all pages up to last possible round
$pages_res = page_info_query($projectid, Rounds::get_last()->id, 'LE');
$pages_res = page_info_query(new Project($projectid), Rounds::get_last(), 'LE');
$page_texts = get_page_texts($pages_res);

// now run it through WordCheck
Expand Down
2 changes: 1 addition & 1 deletion tools/project_manager/show_all_good_word_suggestions.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ function _get_all_suggestions_word_list(string $projectid, int $time_cutoff): ar
}

// get the latest project text of all pages up to last possible round
$pages_res = page_info_query($projectid, Rounds::get_last()->id, 'LE');
$pages_res = page_info_query(new Project($projectid), Rounds::get_last(), 'LE');
$all_words_w_freq = get_distinct_words_in_text(get_page_texts($pages_res));

// get the number of suggestion occurrences
Expand Down
2 changes: 1 addition & 1 deletion tools/project_manager/show_current_flagged_words.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
function _get_current_flagged_word_list(string $projectid): array
{
// get the latest project text of all pages up to last possible round
$pages_res = page_info_query($projectid, Rounds::get_last()->id, 'LE');
$pages_res = page_info_query(new Project($projectid), Rounds::get_last(), 'LE');
$page_texts = get_page_texts($pages_res);

// now run it through WordCheck
Expand Down
2 changes: 1 addition & 1 deletion tools/project_manager/show_good_word_suggestions.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ function _get_suggestions_word_list(string $projectid, int $timeCutoff): array
$project_bad_words = load_project_bad_words($projectid);

// get the latest project text of all pages up to last possible round
$pages_res = page_info_query($projectid, Rounds::get_last()->id, 'LE');
$pages_res = page_info_query(new Project($projectid), Rounds::get_last(), 'LE');
$all_words_w_freq = get_distinct_words_in_text(get_page_texts($pages_res));

// array to hold all words
Expand Down
2 changes: 1 addition & 1 deletion tools/project_manager/show_project_possible_bad_words.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function _get_possible_bad_word_list(string $projectid): array
$messages = [];

// get the latest project text of all pages up to last possible round
$pages_res = page_info_query($projectid, Rounds::get_last()->id, 'LE');
$pages_res = page_info_query(new Project($projectid), Rounds::get_last(), 'LE');
$all_words_w_freq = get_distinct_words_in_text(get_page_texts($pages_res));

// load site word lists for project languages
Expand Down
4 changes: 2 additions & 2 deletions tools/project_manager/show_project_stealth_scannos.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ function _get_stealth_scanno_word_list(string $projectid): array
// instead of just the OCR round, edit_project_word_lists.php should
// be updated to allow this page to be accessed for those type-in
// projects with no OCR text.
$pages_res = page_info_query($projectid, '[OCR]', 'LE');
$pages_res = page_info_query(new Project($projectid), get_OCR_pseudoround(), 'LE');
$all_page_text = get_page_texts($pages_res);
// remove any formatting tags and add a final \r\n to each page-text
// to ensure that there is whitespace between pages so they don't run together
Expand All @@ -193,7 +193,7 @@ function _get_stealth_scanno_word_list(string $projectid): array
}

// get the latest project text of all pages up to last possible round
$pages_res = page_info_query($projectid, Rounds::get_last()->id, 'LE');
$pages_res = page_info_query(new Project($projectid), Rounds::get_last(), 'LE');
$all_page_text = get_page_texts($pages_res);
// remove any formatting tags and add a final \r\n to each page-text
// to ensure that there is whitespace between pages so they don't run together
Expand Down
4 changes: 2 additions & 2 deletions tools/project_manager/show_project_wordcheck_stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
// load bad words for the site for this project
$site_bad_words = load_site_bad_words_given_project($projectid);

$pages_res = page_info_query($projectid, Rounds::get_last()->id, 'LE');
$pages_res = page_info_query($project, Rounds::get_last(), 'LE');

// get the entire text
$page_texts = get_page_texts($pages_res);
Expand Down Expand Up @@ -57,7 +57,7 @@

// now run it again except we're going to count the words per page
// this time through
$pages_res = page_info_query($projectid, Rounds::get_last()->id, 'LE');
$pages_res = page_info_query($project, Rounds::get_last(), 'LE');
$page_stats = [];
// iterate through all the pages gathering stats
while (($row = page_info_fetch($pages_res)) !== false) {
Expand Down
14 changes: 7 additions & 7 deletions tools/project_manager/show_word_context.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@

set_time_limit(0); // no time limit

$projectid = get_projectID_param($_GET, 'projectid');
$project = new Project(get_projectID_param($_GET, 'projectid'));
$encWord = @$_GET["word"];
$word = rtrim(decode_word($encWord));

enforce_edit_authorization($projectid);
enforce_edit_authorization($project->projectid);

$wordInstances = get_integer_param($_GET, 'wordInstances', 20, 0, MAX_WORD_INSTANCES);

$details = json_encode([
"projectid" => $projectid,
"projectid" => $project->projectid,
'storageKey' => 'show_word_context',
], JSON_THROW_ON_ERROR);

Expand All @@ -38,13 +38,13 @@
echo "<div class='overflow-auto'>";
echo "<div style='padding: 0.5em;'>";

$project_name = get_project_name($projectid);
$project_name = get_project_name($project->projectid);
echo "<h2>";
echo sprintf(
// TRANSLATORS: %1$s is a word and %2$s is a project name.
_("Context for '%1\$s' in %2\$s"),
$word,
$project_name
$project->nameofwork
);
echo "</h2>";

Expand All @@ -53,7 +53,7 @@
echo "</p>";

echo "<form method='GET' id='wordInstancesForm'>";
echo "<input type='hidden' name='projectid' value='$projectid'>";
echo "<input type='hidden' name='projectid' value='$project->projectid'>";
echo "<input type='hidden' name='word' value='$encWord'>";
echo "<label for='wordInstancesSelect'>" . _("Number of word context results: ") . "</label>";
echo "<select id='wordInstancesSelect' name='wordInstances' style='margin-left: 2px;'>";
Expand All @@ -64,7 +64,7 @@
echo "</form>";


$pages_res = page_info_query($projectid, Rounds::get_last()->id, 'LE');
$pages_res = page_info_query($project, Rounds::get_last(), 'LE');
// iterate through all the pages until we find $wordInstances of the word
// we're looking for
$foundInstances = 0;
Expand Down