Skip to content

Commit

Permalink
Use named FmtArgs for field title context.
Browse files Browse the repository at this point in the history
  • Loading branch information
kohler committed Oct 16, 2023
1 parent d0877f6 commit c3714f2
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 31 deletions.
16 changes: 9 additions & 7 deletions etc/msgs.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

["field", "title", "Title"],
["field", "submission", "Submission"],
["field", "submission", "Draft submission", ["$1"]],
["field", "submission", "Draft submission", ["{draft}"]],
["field/edit", "submission", "Submission"],
["field/edit", "submission", "Submission (optional)", ["{required}=0"]],
["field/plural", "submission", "Submissions"],
Expand All @@ -51,14 +51,16 @@
["field", "abstract", "Abstract"],
["field/edit", "abstract", "Abstract (optional)", ["{required}=0"]],
["field", "authors", "Authors"],
["field", "authors", "Author", ["$1=1"]],
["field/edit", "authors", "Author", ["opt.maxAuthors=1"]],
["field/missing", "authors", "Author", ["opt.maxAuthors=1"]],
["field", "authors", "Author", ["{count}=1"]],
["field/edit", "authors", "Author", ["{max}=1"]],
["field/missing", "authors", "Author", ["{max}=1"]],
["field", "nonblind", "Anonymous submission"],
["field", "contacts", "Contacts"],
["field", "contacts", "Contact", ["$1=1"]],
["field", "contacts", "Contact", ["{count}=1"]],
["field", "topics", "Topics"],
["field", "topics", "Topic", ["$1=1"]],
["field", "topics", "Topic", ["{count}=1"]],
["field/edit", "topics", "Topic", ["{max}=1"]],
["field/missing", "topics", "Topic", ["{max}=1"]],
["field", "pc_conflicts", "PC conflicts"],
["field", "collaborators", "Collaborators"],
["field", "collaborators", "Other conflicts", ["setting.sub_pcconf"]],
Expand All @@ -68,7 +70,7 @@
["field_description/edit", "authors", "<0>List the authors, including email addresses and affiliations."],
["field_description/edit", "authors", "<0>List the authors, including email addresses and affiliations. Submission is anonymous, so reviewers will not see author information.", ["setting.sub_blind=2"]],
["field_description/edit", "authors", "<0>List the authors, including email addresses and affiliations. Reviewers will see author information only after submitting a review.", ["setting.sub_blind=3"]],
["field_description/edit", "authors", "", ["opt.maxAuthors=1"]],
["field_description/edit", "authors", "", ["{max}=1"]],
["field_description/edit", "authors", "<0>Submission is anonymous, so reviewers will not see author information.", ["opt.maxAuthors=1", "setting.sub_blind=2"]],
["field_description/edit", "authors", "<0>Reviewers will see author information only after submitting a review.", ["opt.maxAuthors=1", "setting.sub_blind=3"]],
["field_description/edit", "contacts", "<0>These users can view and edit the submission. All listed authors with site accounts are contacts. You can add contacts who aren’t in the author list or create accounts for authors who haven’t yet signed in."],
Expand Down
4 changes: 2 additions & 2 deletions src/listactions/la_getabstracts.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ private static function render_abstract($fr, $prow, $user, $o) {
private static function render_authors($fr, $prow, $user, $o) {
if ($user->can_view_authors($prow)
&& ($alist = $prow->author_list())) {
$fr->title = $o->title(count($alist));
$fr->title = $o->title(new FmtArg("count", count($alist)));
$fr->set_text("");
foreach ($alist as $i => $au) {
$marker = ($i || count($alist) > 1 ? ($i + 1) . ". " : "");
Expand All @@ -33,7 +33,7 @@ private static function render_authors($fr, $prow, $user, $o) {
* @param PaperOption $o */
private static function render_topics($fr, $prow, $user, $o) {
if (($tlist = $prow->topic_map())) {
$fr->title = $o->title(count($tlist));
$fr->title = $o->title(new FmtArg("count", count($tlist)));
$fr->set_text("");
foreach ($tlist as $t) {
$fr->value .= prefix_word_wrap("* ", $t, 2, self::WIDTH);
Expand Down
4 changes: 4 additions & 0 deletions src/options/o_authors.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,10 @@ function print_web_edit(PaperTable $pt, $ov, $reqov) {
echo "</template></div></div>\n\n";
}

function field_fmt_context() {
return [new FmtArg("max", $this->max_count)];
}

function render(FieldRender $fr, PaperValue $ov) {
if ($fr->want(FieldRender::CFPAGE)) {
$fr->table->render_authors($fr, $this);
Expand Down
8 changes: 3 additions & 5 deletions src/options/o_checkboxesbase.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ function interests($user) {
}


/** @param FieldRender $fr */
function render_default_description($fr) {
$this->conf->fmt()->render_ci($fr, "field_description/edit", $this->formid,
new FmtArg("min", $this->min_count), new FmtArg("max", $this->max_count));
function field_fmt_context() {
return [new FmtArg("min", $this->min_count), new FmtArg("max", $this->max_count)];
}


Expand Down Expand Up @@ -244,7 +242,7 @@ function render(FieldRender $fr, PaperValue $ov) {
$ts[] = "{$t}\">{$x}</li>";
$lenclass = TopicSet::max_topici_lenclass($lenclass, $tname);
}
$fr->title = $this->title(count($ts));
$fr->title = $this->title(new FmtArg("count", count($ts)));
$fr->set_html("<ul class=\"topict topict-{$lenclass}\">" . join("", $ts) . '</ul>');
$fr->value_long = true;
}
Expand Down
28 changes: 16 additions & 12 deletions src/paperoption.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,23 +312,27 @@ static function make_readable_formid($s) {
}
}

/** @return string */
function title($context = null) {
/** @return list<FmtArg> */
function field_fmt_context() {
return [];
}
/** @param FmtArg ...$context
* @return string */
function title(...$context) {
if ($this->title) {
return $this->title;
} else if ($context === null) {
return $this->conf->_ci("field", $this->formid);
} else {
return $this->conf->_ci("field", $this->formid, $context);
return $this->conf->_ci("field", $this->formid, ...$context, ...$this->field_fmt_context());
}
}
/** @return string */
function title_html($context = null) {
return htmlspecialchars($this->title($context));
/** @param FmtArg ...$context
* @return string */
function title_html(...$context) {
return htmlspecialchars($this->title(...$context));
}
/** @return string */
function plural_title() {
return $this->title ?? $this->conf->_ci("field/plural", $this->formid);
return $this->title ?? $this->conf->_ci("field/plural", $this->formid, ...$this->field_fmt_context());
}
/** @param ?PaperInfo $prow
* @return string */
Expand All @@ -339,11 +343,11 @@ function edit_title($prow = null) {
* @return string */
function default_edit_title($prow = null) {
$req = $this->required > 0 && (!$prow || $this->test_required($prow));
return $this->conf->_ci("field/edit", $this->formid, new FmtArg("required", $req));
return $this->conf->_ci("field/edit", $this->formid, new FmtArg("required", $req), ...$this->field_fmt_context());
}
/** @return string */
function missing_title() {
return $this->title ?? $this->conf->_ci("field/missing", $this->formid);
return $this->title ?? $this->conf->_ci("field/missing", $this->formid, ...$this->field_fmt_context());
}

/** @param FieldRender $fr */
Expand All @@ -359,7 +363,7 @@ function render_description($fr) {
}
/** @param FieldRender $fr */
function render_default_description($fr) {
$this->conf->fmt()->render_ci($fr, "field_description/edit", $this->formid);
$this->conf->fmt()->render_ci($fr, "field_description/edit", $this->formid, ...$this->field_fmt_context());
}

/** @return AbbreviationMatcher */
Expand Down
10 changes: 5 additions & 5 deletions src/papertable.php
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ function render_submission(FieldRender $fr, $o) {
if ($dtype === DTYPE_FINAL) {
$dhtml = $this->conf->option_by_id($dtype)->title_html();
} else {
$dhtml = $o->title_html($this->prow->timeSubmitted == 0);
$dhtml = $o->title_html(new FmtArg("draft", $this->prow->timeSubmitted == 0));
}
$s = $doc->link_html("<span class=\"pavfn\">{$dhtml}</span>", DocumentInfo::L_REQUIREFORMAT);
$fr->value .= "<p class=\"pgsm\">{$s}{$stamps}</p>";
Expand Down Expand Up @@ -997,7 +997,7 @@ function render_authors(FieldRender $fr, PaperOption $o) {
$vas = $this->user->view_authors_state($this->prow);
if ($vas === 0) {
$fr->value = '<div class="pg">'
. $this->papt("authors", $o->title_html(0))
. $this->papt("authors", $o->title_html())
. '<div class="pavb"><i>Hidden</i></div>'
. "</div>\n\n";
return;
Expand All @@ -1007,7 +1007,7 @@ function render_authors(FieldRender $fr, PaperOption $o) {
list($aulist, $contacts) = $this->_analyze_authors();

// "author" or "authors"?
$auname = $o->title_html(count($aulist));
$auname = $o->title_html(new FmtArg("count", count($aulist)));
if ($vas === 1) {
$auname .= " <span class=\"n\">(deanonymized)</span>";
} else if ($this->user->act_author_view($this->prow)) {
Expand Down Expand Up @@ -1035,7 +1035,7 @@ function render_authors(FieldRender $fr, PaperOption $o) {
$fr->value .= '<button type="button" class="q ui js-aufoldup" title="Toggle author display" aria-expanded="' . ($this->foldmap[8] ? "false" : "true") . '">';
}
if ($vas === 1) {
$fr->value .= '<span class="fn8">' . $o->title_html(0) . '</span><span class="fx8">';
$fr->value .= '<span class="fn8">' . $o->title_html() . '</span><span class="fx8">';
}
if ($this->allow_folds) {
$fr->value .= expander(null, 9);
Expand Down Expand Up @@ -1094,7 +1094,7 @@ function render_authors(FieldRender $fr, PaperOption $o) {
|| $this->prow->timeSubmitted <= 0)) {
$contacts_option = $this->conf->option_by_id(PaperOption::CONTACTSID);
$fr->value .= '<div class="pg fx9' . ($vas > 1 ? "" : " fx8") . '">'
. $this->papt("contacts", $contacts_option->title_html(count($contacts)))
. $this->papt("contacts", $contacts_option->title_html(new FmtArg("count", $contacts)))
. '<div class="pavb">'
. $this->authorData($contacts, "col", $this->user)
. "</div></div>\n\n";
Expand Down

0 comments on commit c3714f2

Please sign in to comment.