Fix @IndexOptions

Frank Betten reported that after installing the module for Permanent
Anchors the parameter permanentanchors has no effect and there's no
checkbox on the index page. The reason is that Permanent Anchors used
to add to @IndexOptions upon loading (InitModules), but commit
15263102 had moved the setting of @IndexOptions into InitVariables,
thus overwriting any changes made during InitModules. In order to have
an effect, @IndexOptions has to be modified via @MyInitVariables. All
of this is necessary because @IndexOptions uses translated strings and
these are themselves loaded via modules so setting @IndexOptions at
InitModules time can be too early. This was fixed with commit deec99c,
necessitating all these follow-up changes.
This commit is contained in:
Alex Schroeder
2019-01-24 22:22:26 +01:00
parent a67cac80f5
commit 65cfd93de9
3 changed files with 91 additions and 6 deletions

View File

@@ -312,9 +312,7 @@ resolved to the same target (the local page), which is unexpected.
# IndexOptions must be set in MyInitVariables for translations to
# work.
push(@MyInitVariables, sub {
push(@IndexOptions, ['near', T('Include near pages'), 0,
\&ListNearPages]);
});
push(@IndexOptions, ['near', T('Include near pages'), 0, \&ListNearPages])});
sub ListNearPages {
my %pages = %NearSource;

View File

@@ -262,12 +262,15 @@ Some user interface changes are required as well.
=item *
Allow the page index to list permanent anchors or not by setting
C<@IndexOptions>.
C<@IndexOptions>. Note that we need to delay setting this option until we're
sure that translations have loaded correctly, which is why we're setting
C<@IndexOptions> as part of running C<@MyInitVariables>.
=cut
push(@IndexOptions, ['permanentanchors', T('Include permanent anchors'),
1, sub { keys %PermanentAnchors }]);
push(@MyInitVariables, sub {
push(@IndexOptions, ['permanentanchors', T('Include permanent anchors'),
1, sub { keys %PermanentAnchors }])});
=item *

84
t/index.t Normal file
View File

@@ -0,0 +1,84 @@
# Copyright (C) 2019 Alex Schroeder <alex@gnu.org>
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
require './t/test.pl';
package OddMuse;
use Test::More tests => 23;
update_page('Test', 'Mu');
test_page(get_page('action=index'),
'Include normal pages', 'Test');
add_module('permanent-anchors.pl');
# create a page with a permanent anchor
update_page('Fix', '[::Moo]');
# the default is to include permanent anchors
$page = get_page('action=index');
test_page($page,
'Include normal pages',
'Include permanent anchors');
xpath_test($page, "//a[text()='Test']",
"//a[text()='Fix']",
"//a[text()='Moo']");
# we can exclude permanent anchors
$page = get_page('action=index permanentanchors=0');
xpath_test($page, "//a[text()='Test']",
"//a[text()='Fix']");
negative_xpath_test($page, "//a[text()='Moo']");
# or include them specifically
$page = get_page('action=index permanentanchors=1');
xpath_test($page, "//a[text()='Moo']");
# and exclude normal pages
$page = get_page('action=index pages=0 permanentanchors=1');
xpath_test($page, "//a[text()='Moo']");
negative_xpath_test($page,
"//a[text()='Test']",
"//a[text()='Fix']");
add_module('near-links.pl');
CreateDir($NearDir);
WriteStringToFile("$NearDir/EmacsWiki",
"Alex\n");
update_page('InterMap', " EmacsWiki http://www.emacswiki.org/wiki/%s\n",
'required', 0, 1);
update_page('NearMap', " EmacsWiki"
. " http://www.emacswiki.org/wiki?action=index;raw=1"
. " http://www.emacswiki.org/wiki?search=%s;raw=1;near=0\n",
'required', 0, 1);
# the default is to not include near links
$page = get_page('action=index');
test_page($page,
'Include normal pages',
'Include permanent anchors',
'Include near pages');
xpath_test($page, "//a[text()='Test']",
"//a[text()='Fix']",
"//a[text()='Moo']");
negative_xpath_test($page, "//a[text()='Alex']");
# we need to specifically include near links
$page = get_page('action=index near=1');
xpath_test($page, "//a[text()='Alex']");
# or we can specifically exclude near links
$page = get_page('action=index near=0');
negative_xpath_test($page, "//a[text()='Alex']");