@webship.co/workspace-mediawiki 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +241 -2
- package/ai/agents/mediawiki-site-builder.md +104 -0
- package/ai/agents/mediawiki-tester.md +108 -0
- package/ai/commands/mediawiki-test.md +75 -0
- package/ai/prompts/mediawiki-build-and-test.md +26 -0
- package/ai/prompts/mediawiki-scenarios-for-an-area.md +25 -0
- package/ai/skills/mediawiki-scenarios/SKILL.md +85 -0
- package/ai/skills/mediawiki-scenarios/examples/administration.feature +16 -0
- package/ai/skills/mediawiki-scenarios/examples/editing.feature +25 -0
- package/ai/skills/mediawiki-scenarios/examples/reading-and-search.feature +41 -0
- package/commands/cmd-mediawiki-project.sh +32 -0
- package/commands/cmd-tools-mediawiki-maintenance.sh +26 -0
- package/dist/src/index.d.ts +29 -0
- package/dist/src/index.js +53 -0
- package/dist/src/index.js.map +1 -0
- package/features/mediawiki.feature +36 -0
- package/package.json +95 -4
- package/scripts/args/arg-mediawiki-maintenance.sh +25 -0
- package/scripts/args/arg-mediawiki.sh +29 -0
- package/scripts/functions/fun-mediawiki.sh +437 -0
- package/testing/site.feature +48 -0
|
@@ -0,0 +1,437 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
# MediaWiki for the Webship Workspace: build a wiki from the release tarball, run its maintenance
|
|
4
|
+
# scripts, add its default accounts, and wire its step pack into the testing setup.
|
|
5
|
+
#
|
|
6
|
+
# Placed by `plugins.sh --install mediawiki` in core/scripts/plugins/mediawiki/functions/, where
|
|
7
|
+
# bootstrap sources it after the core's own functions. Everything runs in the project's container
|
|
8
|
+
# (DDEV by default: `ddev exec php maintenance/run.php …`), never on the host. DDEV has no project
|
|
9
|
+
# type of its own for MediaWiki: a project is of type php with the wiki at the docroot, and the
|
|
10
|
+
# plugin knows it by its files (maintenance/run.php and the MW_VERSION of includes/Defines.php).
|
|
11
|
+
# The installer writes the wiki's database settings into LocalSettings.php from the container's own
|
|
12
|
+
# values (db, db, db on the host db), and nothing personal.
|
|
13
|
+
#
|
|
14
|
+
# Four names are the ones the core's tools look for:
|
|
15
|
+
# set_mediawiki_users the default accounts (cmd-tools-add-users.sh <project> mediawiki)
|
|
16
|
+
# add_mediawiki_users create them in the wiki (the same tool, and --add-users of the builder)
|
|
17
|
+
# cancel_mediawiki_users cancel them (cmd-tools-cancel-users.sh <project> mediawiki)
|
|
18
|
+
# testing_configure_mediawiki the step pack in the testing stack (cmd-tools-testing.sh <project>)
|
|
19
|
+
|
|
20
|
+
# The step pack a wiki is tested with, and the release line it is required at.
|
|
21
|
+
readonly MEDIAWIKI_STEPS_PACKAGE='@webship-js/mediawiki-steps';
|
|
22
|
+
readonly MEDIAWIKI_STEPS_VERSION='^2.0.0';
|
|
23
|
+
# The release the builder installs when --mediawiki-version is not given: the current stable one.
|
|
24
|
+
readonly MEDIAWIKI_DEFAULT_RELEASE='1.46.2';
|
|
25
|
+
|
|
26
|
+
# The default accounts, the ones a scenario logs in as: one per kind of account a wiki tells apart.
|
|
27
|
+
# Accounts are configuration, made once on the wiki with the maintenance script createAndPromote; a
|
|
28
|
+
# test suite never creates or deletes one.
|
|
29
|
+
# administrator sysop and bureaucrat: protects, deletes, restores, blocks
|
|
30
|
+
# editor the "confirmed" group: the rights of an established account at once
|
|
31
|
+
# reader no group: a new account, refused the pages protected for established accounts
|
|
32
|
+
function set_mediawiki_users() {
|
|
33
|
+
users=(administrator editor reader);
|
|
34
|
+
local user ;
|
|
35
|
+
for user in "${users[@]}" ; do
|
|
36
|
+
printf -v "user_${user}_name" '%s' "${user}" ;
|
|
37
|
+
printf -v "user_${user}_mail" '%s' "${user}@example.com" ;
|
|
38
|
+
printf -v "user_${user}_password" '%s' 'dD.123123ddd' ;
|
|
39
|
+
done
|
|
40
|
+
user_administrator_role='sysop,bureaucrat' ;
|
|
41
|
+
user_editor_role='confirmed' ;
|
|
42
|
+
user_reader_role='' ;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
# Is this folder a MediaWiki project? A container project with the maintenance runner of the release
|
|
46
|
+
# and the version it defines.
|
|
47
|
+
function mediawiki_is_project() {
|
|
48
|
+
local project_path="$1";
|
|
49
|
+
[ -f "${project_path}/.ddev/config.yaml" ] && [ -f "${project_path}/maintenance/run.php" ] \
|
|
50
|
+
&& grep -q "define( 'MW_VERSION'" "${project_path}/includes/Defines.php" 2>/dev/null ;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
# The release of the wiki in the current folder.
|
|
54
|
+
function mediawiki_version() {
|
|
55
|
+
sed -n "s/^define( 'MW_VERSION', '\(.*\)' );/\1/p" includes/Defines.php 2>/dev/null ;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
# Is the wiki of the current folder installed (it has its LocalSettings.php)?
|
|
59
|
+
function mediawiki_installed() {
|
|
60
|
+
[ -f LocalSettings.php ] ;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
# Go to the project a tool was asked about, or say why not.
|
|
64
|
+
function mediawiki_enter_project() {
|
|
65
|
+
local project_path="${WORKSPACE_ROOT}/${doc_name}/${PROJECT_NAME}";
|
|
66
|
+
if [ ! -d "${project_path}" ] ; then
|
|
67
|
+
echo "No project ${PROJECT_NAME} in ${WORKSPACE_ROOT}/${doc_name}." ;
|
|
68
|
+
return 1 ;
|
|
69
|
+
fi
|
|
70
|
+
if ! mediawiki_is_project "${project_path}" ; then
|
|
71
|
+
echo "${doc_name}/${PROJECT_NAME} is not a MediaWiki project (it has no maintenance/run.php and includes/Defines.php of the release)." ;
|
|
72
|
+
return 1 ;
|
|
73
|
+
fi
|
|
74
|
+
cd "${project_path}" || return 1 ;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
# A maintenance script of the wiki, in the container, with stdin closed.
|
|
78
|
+
function mediawiki_maintenance() {
|
|
79
|
+
ddev exec php maintenance/run.php "$@" < /dev/null ;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
# The settings the builder adds to LocalSettings.php after the installer wrote it: uploads, the
|
|
83
|
+
# "confirmed" group with the autoconfirm thresholds of large public wikis, the job queue as a
|
|
84
|
+
# service, the object cache and the sessions in the database.
|
|
85
|
+
function mediawiki_write_settings() {
|
|
86
|
+
cat >> LocalSettings.php <<'PHPEOF'
|
|
87
|
+
|
|
88
|
+
# Added by the Webship Workspace (cmd-mediawiki-project.sh).
|
|
89
|
+
# Uploads, for the upload form (Special:Upload).
|
|
90
|
+
$wgEnableUploads = true;
|
|
91
|
+
# A new account earns the rights of an established one ("autoconfirmed") after 4 days and
|
|
92
|
+
# 10 edits, as on large public wikis; the "confirmed" group gives those rights at once.
|
|
93
|
+
$wgAutoConfirmAge = 4 * 86400;
|
|
94
|
+
$wgAutoConfirmCount = 10;
|
|
95
|
+
$wgGroupPermissions['confirmed']['autoconfirmed'] = true;
|
|
96
|
+
$wgGroupPermissions['confirmed']['editsemiprotected'] = true;
|
|
97
|
+
# The job queue runs as a service of the container (.ddev/config.mediawiki-jobs.yaml).
|
|
98
|
+
$wgJobRunRate = 0;
|
|
99
|
+
# The object cache and the sessions in the database: the maintenance scripts and the job
|
|
100
|
+
# runner share them with the web requests, and a restart keeps the sessions.
|
|
101
|
+
$wgMainCacheType = CACHE_DB;
|
|
102
|
+
$wgSessionCacheType = CACHE_DB;
|
|
103
|
+
PHPEOF
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
# The rule MediaWiki documents for nginx, so that rest.php/v1/... reaches the REST API (the search
|
|
107
|
+
# suggestions and the visual editor use it), and the job queue as a service of the web container.
|
|
108
|
+
function mediawiki_write_container_config() {
|
|
109
|
+
mkdir -p .ddev/nginx ;
|
|
110
|
+
cat > .ddev/nginx/mediawiki-rest.conf <<'NGINXEOF'
|
|
111
|
+
# The REST API of the wiki (rest.php/v1/...): the rule MediaWiki documents for nginx.
|
|
112
|
+
location /rest.php/ {
|
|
113
|
+
try_files $uri $uri/ /rest.php?$query_string;
|
|
114
|
+
}
|
|
115
|
+
NGINXEOF
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function mediawiki_write_jobs_service() {
|
|
119
|
+
cat > .ddev/config.mediawiki-jobs.yaml <<'JOBSEOF'
|
|
120
|
+
# The job queue of the wiki as a service of the web container (added by the Webship Workspace).
|
|
121
|
+
web_extra_daemons:
|
|
122
|
+
- name: "mediawiki-jobs"
|
|
123
|
+
command: "php maintenance/run.php runJobs --wait --maxtime=3600 --memory-limit=256M"
|
|
124
|
+
directory: /var/www/html
|
|
125
|
+
JOBSEOF
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
# Write one account: create it, or give it back its password; add its groups; set its address;
|
|
129
|
+
# lift a block on it. createAndPromote --force cannot set the address of an account that is there,
|
|
130
|
+
# so resetUserEmail does.
|
|
131
|
+
function mediawiki_write_account() {
|
|
132
|
+
local name="$1" mail="$2" password="$3" groups="$4" ;
|
|
133
|
+
local flags=() group ;
|
|
134
|
+
for group in ${groups//,/ } ; do
|
|
135
|
+
case "${group}" in
|
|
136
|
+
sysop) flags+=(--sysop) ;;
|
|
137
|
+
bureaucrat) flags+=(--bureaucrat) ;;
|
|
138
|
+
interface-admin) flags+=(--interface-admin) ;;
|
|
139
|
+
bot) flags+=(--bot) ;;
|
|
140
|
+
*) flags+=(--custom-groups="${group}") ;;
|
|
141
|
+
esac
|
|
142
|
+
done
|
|
143
|
+
mediawiki_maintenance createAndPromote --force "${flags[@]}" "${name}" "${password}" > /dev/null || return 1 ;
|
|
144
|
+
[ -n "${mail}" ] && { mediawiki_maintenance resetUserEmail --no-reset-password "${name}" "${mail}" > /dev/null || return 1 ; } ;
|
|
145
|
+
printf '%s\n' "${name}" | ddev exec php maintenance/run.php blockUsers --unblock --performer="Maintenance script" --reason="Account given back by the Webship Workspace" > /dev/null 2>&1 ;
|
|
146
|
+
return 0 ;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
# The accounts of the wiki: name, address, groups, and whether a block is on it.
|
|
150
|
+
function mediawiki_list_accounts() {
|
|
151
|
+
mediawiki_maintenance sql --json --query "SELECT u.user_name AS name, u.user_email AS mail, (SELECT GROUP_CONCAT(ug_group) FROM user_groups WHERE ug_user = u.user_id) AS user_group_list, (SELECT COUNT(*) FROM block_target bt WHERE bt.bt_user = u.user_id) AS blocked FROM user u WHERE u.user_name NOT IN ('MediaWiki default', 'Maintenance script') ORDER BY u.user_id" 2>/dev/null \
|
|
152
|
+
| python3 -c '
|
|
153
|
+
import json, sys
|
|
154
|
+
try:
|
|
155
|
+
rows = json.load(sys.stdin)
|
|
156
|
+
except ValueError:
|
|
157
|
+
rows = []
|
|
158
|
+
for r in rows:
|
|
159
|
+
print(" %s <%s> %s%s" % (r.get("name"), r.get("mail") or "no address", r.get("user_group_list") or "no group", " (blocked)" if str(r.get("blocked")) not in ("0", "None") else ""))
|
|
160
|
+
' ;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
# Build a wiki from nothing: the container, the release tarball, and with --install the wiki
|
|
164
|
+
# installed by its own installer, the workspace account as its first account.
|
|
165
|
+
function mediawiki_build() {
|
|
166
|
+
trim_project_name ;
|
|
167
|
+
local base_url="https://${PROJECT_NAME}.ddev.site" ;
|
|
168
|
+
local release="${MEDIAWIKI_VERSION:-${site_mediawiki_version:-${MEDIAWIKI_DEFAULT_RELEASE}}}" ;
|
|
169
|
+
local major ;
|
|
170
|
+
major="$(echo "${release}" | cut -d. -f1,2)" ;
|
|
171
|
+
local php_version="${PHP_VERSION:-${site_php_version:-}}" ;
|
|
172
|
+
local extensions='WikiEditor,CategoryTree,Cite' ;
|
|
173
|
+
[ "${VISUAL_EDITOR}" == 'yes' ] && extensions="WikiEditor,VisualEditor,CategoryTree,Cite" ;
|
|
174
|
+
|
|
175
|
+
cd ${WORKSPACE_ROOT}/${doc_name} || exit 1 ;
|
|
176
|
+
|
|
177
|
+
drop_database ;
|
|
178
|
+
rm -rf "${PROJECT_NAME}" ;
|
|
179
|
+
mkdir -p "${PROJECT_NAME}" ;
|
|
180
|
+
cd ${WORKSPACE_ROOT}/${doc_name}/${PROJECT_NAME} || exit 1 ;
|
|
181
|
+
|
|
182
|
+
# DDEV has no project type for the wiki: php, the wiki at the docroot.
|
|
183
|
+
ddev config --project-type=php --docroot="" --project-name=${PROJECT_NAME} \
|
|
184
|
+
--nodejs-version=$(ddev_nodejs_version) ${php_version:+--php-version=${php_version}} --auto || exit 1 ;
|
|
185
|
+
mediawiki_write_container_config ;
|
|
186
|
+
ddev_up start -y || exit 1 ;
|
|
187
|
+
|
|
188
|
+
# The release tarball from the release server, unpacked at the docroot in the container.
|
|
189
|
+
ddev exec "curl -sSfL https://releases.wikimedia.org/mediawiki/${major}/mediawiki-${release}.tar.gz | tar -xz --strip-components=1" < /dev/null \
|
|
190
|
+
|| { echo "The release ${release} could not be downloaded from releases.wikimedia.org." ; exit 1 ; } ;
|
|
191
|
+
|
|
192
|
+
if [ "${INSTALL}" == 'yes' ] ; then
|
|
193
|
+
# The installer of the release on the container's database; the workspace account is the
|
|
194
|
+
# wiki's first account (sysop, bureaucrat, interface-admin).
|
|
195
|
+
mediawiki_maintenance install --server="${base_url}" --scriptpath= \
|
|
196
|
+
--dbtype=mysql --dbserver=db --dbname=db --dbuser=db --dbpass=db --installdbuser=db --installdbpass=db \
|
|
197
|
+
--lang=en --pass="${account_pass}" --extensions="${extensions}" \
|
|
198
|
+
"${doc_name} ${PROJECT_NAME}" "${account_name}" || { echo "The installer of the wiki failed." ; exit 1 ; } ;
|
|
199
|
+
mediawiki_write_settings ;
|
|
200
|
+
mediawiki_maintenance resetUserEmail --no-reset-password "${account_name}" "${account_mail}" > /dev/null ;
|
|
201
|
+
printf 'Confirmed users' | ddev exec php maintenance/run.php edit --user="${account_name}" --summary="The name of the confirmed group" "MediaWiki:Group-confirmed" > /dev/null ;
|
|
202
|
+
printf 'confirmed user' | ddev exec php maintenance/run.php edit --user="${account_name}" --summary="The name of a member of the confirmed group" "MediaWiki:Group-confirmed-member" > /dev/null ;
|
|
203
|
+
if [ "${ADD_USERS}" == 'yes' ] ; then
|
|
204
|
+
set_mediawiki_users ;
|
|
205
|
+
add_mediawiki_users ;
|
|
206
|
+
cd ${WORKSPACE_ROOT}/${doc_name}/${PROJECT_NAME} || exit 1 ;
|
|
207
|
+
fi
|
|
208
|
+
# The job queue as a service: it needs the installed wiki, and starts with this restart.
|
|
209
|
+
mediawiki_write_jobs_service ;
|
|
210
|
+
ddev restart || exit 1 ;
|
|
211
|
+
elif [ "${ADD_USERS}" == 'yes' ] ; then
|
|
212
|
+
echo "--add-users needs --install: there is no wiki to add accounts to yet." ;
|
|
213
|
+
fi
|
|
214
|
+
|
|
215
|
+
local version ;
|
|
216
|
+
version="$(mediawiki_version)" ;
|
|
217
|
+
if [ "${INSTALL}" == 'yes' ] ; then
|
|
218
|
+
local with='' ;
|
|
219
|
+
[ "${VISUAL_EDITOR}" == 'yes' ] && with=' with the visual editor' ;
|
|
220
|
+
echo "${doc_name} ${PROJECT_NAME} has been installed: MediaWiki ${version}${with}.";
|
|
221
|
+
echo "Go to ${base_url}/index.php?title=Special:UserLogin and log in as ${account_name}";
|
|
222
|
+
else
|
|
223
|
+
echo "${doc_name} ${PROJECT_NAME} is ready: MediaWiki ${version}, not installed. Install it with its installer at ${base_url}/mw-config/ or build again with --install.";
|
|
224
|
+
echo "Go to ${base_url}";
|
|
225
|
+
fi
|
|
226
|
+
|
|
227
|
+
if [ "${LAUNCH}" == 'yes' ] ; then
|
|
228
|
+
ddev launch ;
|
|
229
|
+
fi
|
|
230
|
+
|
|
231
|
+
cd ${WORKSPACE_ROOT}/${doc_name};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
# Create the default accounts in the wiki. An account that is already there gets its password,
|
|
235
|
+
# groups and address back, and a block on it is lifted. The list is loaded by the caller
|
|
236
|
+
# (set_mediawiki_users): the core's add_users, the builder, the maintenance tool.
|
|
237
|
+
function add_mediawiki_users() {
|
|
238
|
+
mediawiki_enter_project || return 1 ;
|
|
239
|
+
if ! mediawiki_installed ; then
|
|
240
|
+
echo " The wiki is not installed yet: build it with --install first." ;
|
|
241
|
+
cd ${WORKSPACE_ROOT}/${doc_name}; return 1 ;
|
|
242
|
+
fi
|
|
243
|
+
local user user_name user_mail user_password user_role rc=0 ;
|
|
244
|
+
for user in "${users[@]}" ; do
|
|
245
|
+
user_name="user_${user}_name"; user_mail="user_${user}_mail";
|
|
246
|
+
user_password="user_${user}_password"; user_role="user_${user}_role";
|
|
247
|
+
|
|
248
|
+
echo " ---------------------------------------------------------------- ";
|
|
249
|
+
echo " User name: ${!user_name}";
|
|
250
|
+
echo " User mail: ${!user_mail}";
|
|
251
|
+
echo " User password: ${!user_password}";
|
|
252
|
+
echo " User groups: ${!user_role:-(none)}";
|
|
253
|
+
echo " ================================================================= ";
|
|
254
|
+
|
|
255
|
+
mediawiki_write_account "${!user_name}" "${!user_mail}" "${!user_password}" "${!user_role}" || rc=1 ;
|
|
256
|
+
done
|
|
257
|
+
cd ${WORKSPACE_ROOT}/${doc_name};
|
|
258
|
+
return ${rc} ;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
# Cancel the default accounts. A wiki never deletes an account (its edits keep their author): a
|
|
262
|
+
# cancelled account is blocked without end and gets a random password, so nobody logs in with it;
|
|
263
|
+
# add_mediawiki_users gives it back.
|
|
264
|
+
function cancel_mediawiki_users() {
|
|
265
|
+
mediawiki_enter_project || return 1 ;
|
|
266
|
+
local user user_name names="" ;
|
|
267
|
+
for user in "${users[@]}" ; do
|
|
268
|
+
user_name="user_${user}_name";
|
|
269
|
+
echo " ---------------------------------------------------------------- ";
|
|
270
|
+
echo " User name: ${!user_name}";
|
|
271
|
+
echo " ================================================================= ";
|
|
272
|
+
names="${names}${!user_name}"$'\n' ;
|
|
273
|
+
mediawiki_maintenance changePassword --user="${!user_name}" --password="$(head -c 24 /dev/urandom | base64 | tr -dc 'A-Za-z0-9' | head -c 24)Aa1!" > /dev/null ;
|
|
274
|
+
mediawiki_maintenance invalidateUserSessions --user="${!user_name}" > /dev/null 2>&1 ;
|
|
275
|
+
done
|
|
276
|
+
printf '%s' "${names}" | ddev exec php maintenance/run.php blockUsers --expiry=infinite --performer="Maintenance script" --reason="Account cancelled by the Webship Workspace" ;
|
|
277
|
+
local rc=$? ;
|
|
278
|
+
cd ${WORKSPACE_ROOT}/${doc_name};
|
|
279
|
+
return ${rc} ;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
# What cmd-tools-mediawiki-maintenance.sh does: the first of --run, --update, --jobs, --add-users,
|
|
283
|
+
# --cancel-users that was asked for; with none of them, what the wiki is.
|
|
284
|
+
function mediawiki_maintenance_tool() {
|
|
285
|
+
trim_project_name ;
|
|
286
|
+
mediawiki_enter_project || exit 1 ;
|
|
287
|
+
|
|
288
|
+
if ! ddev describe -j 2>/dev/null | grep -q '"status":"running"' ; then
|
|
289
|
+
ddev start -y || exit 1 ;
|
|
290
|
+
fi
|
|
291
|
+
|
|
292
|
+
if [ ! "${RUN}" == '_none_' ] ; then
|
|
293
|
+
# Unquoted on purpose: --run "showJobs --group" is a script and its arguments.
|
|
294
|
+
ddev exec php maintenance/run.php ${RUN} < /dev/null ;
|
|
295
|
+
exit $? ;
|
|
296
|
+
fi
|
|
297
|
+
|
|
298
|
+
if [ "${UPDATE}" == 'yes' ] ; then
|
|
299
|
+
mediawiki_maintenance update --quick ;
|
|
300
|
+
elif [ "${JOBS}" == 'yes' ] ; then
|
|
301
|
+
mediawiki_maintenance runJobs ;
|
|
302
|
+
elif [ "${ADD_USERS}" == 'yes' ] ; then
|
|
303
|
+
set_mediawiki_users ;
|
|
304
|
+
add_mediawiki_users ;
|
|
305
|
+
elif [ "${CANCEL_USERS}" == 'yes' ] ; then
|
|
306
|
+
set_mediawiki_users ;
|
|
307
|
+
cancel_mediawiki_users ;
|
|
308
|
+
else
|
|
309
|
+
echo "${doc_name}/${PROJECT_NAME}: MediaWiki $(mediawiki_version) at https://${PROJECT_NAME}.ddev.site" ;
|
|
310
|
+
if mediawiki_installed ; then
|
|
311
|
+
echo " Extensions: $(sed -nE "s/^wfLoadExtension\( '([^']+)'.*/\1/p" LocalSettings.php | tr '\n' ' ')" ;
|
|
312
|
+
echo "" ; echo "Accounts:" ;
|
|
313
|
+
mediawiki_list_accounts ;
|
|
314
|
+
else
|
|
315
|
+
echo " Not installed: build it again with --install." ;
|
|
316
|
+
fi
|
|
317
|
+
fi
|
|
318
|
+
cd ${WORKSPACE_ROOT}/${doc_name};
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
# The step pack in the testing stack of a MediaWiki project. The core's testing_configure calls this
|
|
322
|
+
# in the project folder once webship-js is scaffolded and before the dependencies are installed;
|
|
323
|
+
# for a project that is not a wiki it changes nothing.
|
|
324
|
+
#
|
|
325
|
+
# It adds the pack to package.json, lists its step definitions in cucumber.js after webship-js's
|
|
326
|
+
# own, gives cucumber.js the users registry of the default accounts (a handle a scenario reads,
|
|
327
|
+
# mapped to an account; never the workspace account), the handle the test-page steps work as
|
|
328
|
+
# (wikiAdmin) and the tags that keep the pack's assertions that must fail out of a normal run, and
|
|
329
|
+
# writes a first feature when the project has none of its own. Every part is skipped when it is
|
|
330
|
+
# already there, so a second run adds what the first missed and never resets a suite.
|
|
331
|
+
function testing_configure_mediawiki() {
|
|
332
|
+
local project_path="$1";
|
|
333
|
+
mediawiki_is_project "${project_path}" || return 0 ;
|
|
334
|
+
if [ ! -f "${project_path}/cucumber.js" ] || [ ! -f "${project_path}/package.json" ] ; then
|
|
335
|
+
echo " MediaWiki: cucumber.js is not here yet — run the testing setup again once webship-js is scaffolded." ;
|
|
336
|
+
return 1 ;
|
|
337
|
+
fi
|
|
338
|
+
|
|
339
|
+
echo "Adding the MediaWiki step pack (${MEDIAWIKI_STEPS_PACKAGE} ${MEDIAWIKI_STEPS_VERSION}).";
|
|
340
|
+
set_mediawiki_users ;
|
|
341
|
+
local registry="" user user_name user_mail user_password ;
|
|
342
|
+
for user in "${users[@]}" ; do
|
|
343
|
+
user_name="user_${user}_name"; user_mail="user_${user}_mail"; user_password="user_${user}_password";
|
|
344
|
+
registry="${registry}${user}|${!user_mail}|${!user_password}|${!user_name}"$'\n' ;
|
|
345
|
+
done
|
|
346
|
+
|
|
347
|
+
python3 - "${project_path}" "${MEDIAWIKI_STEPS_PACKAGE}" "${MEDIAWIKI_STEPS_VERSION}" 'MEDIAWIKI' "${registry}" <<'PYEOF' || return 1
|
|
348
|
+
import json, re, sys
|
|
349
|
+
|
|
350
|
+
project, pack, version, prefix, registry = sys.argv[1:6]
|
|
351
|
+
|
|
352
|
+
# package.json: the pack as a dev dependency, at the release line this plugin was proven on.
|
|
353
|
+
pkg_file = project + '/package.json'
|
|
354
|
+
pkg = json.load(open(pkg_file))
|
|
355
|
+
if pack not in pkg.get('dependencies', {}) and pack not in pkg.get('devDependencies', {}):
|
|
356
|
+
pkg.setdefault('devDependencies', {})[pack] = version
|
|
357
|
+
open(pkg_file, 'w').write(json.dumps(pkg, indent=4) + '\n')
|
|
358
|
+
print(' package.json: %s %s' % (pack, version))
|
|
359
|
+
|
|
360
|
+
# cucumber.js: the pack's step definitions after webship-js's own, the users registry, the handle the
|
|
361
|
+
# test-page steps work as, and the tags of the pack's lane.
|
|
362
|
+
cucumber_file = project + '/cucumber.js'
|
|
363
|
+
src = open(cucumber_file).read()
|
|
364
|
+
before = src
|
|
365
|
+
|
|
366
|
+
if ('node_modules/%s/' % pack) not in src:
|
|
367
|
+
line = "'node_modules/%s/tests/step-definitions/**/*.js'," % pack
|
|
368
|
+
core = re.search(r"^([ \t]*)'node_modules/webship-js/tests/step-definitions/[^']*',.*$", src, re.M)
|
|
369
|
+
opening = re.search(r"^([ \t]*)require:[ \t]*\[[ \t]*$", src, re.M)
|
|
370
|
+
if core:
|
|
371
|
+
src = src[:core.end()] + '\n' + core.group(1) + line + src[core.end():]
|
|
372
|
+
elif opening:
|
|
373
|
+
src = src[:opening.end()] + '\n' + opening.group(1) + ' ' + line + src[opening.end():]
|
|
374
|
+
else:
|
|
375
|
+
sys.exit(" cucumber.js has no require list this can add to. Add this line to it:\n " + line)
|
|
376
|
+
print(' cucumber.js: the step definitions of %s' % pack)
|
|
377
|
+
|
|
378
|
+
if not re.search(r"^[ \t]*tags:", src, re.M):
|
|
379
|
+
default = re.search(r"^([ \t]*)default:[ \t]*\{[ \t]*$", src, re.M)
|
|
380
|
+
if default:
|
|
381
|
+
pad = default.group(1) + ' '
|
|
382
|
+
block = [
|
|
383
|
+
pad + "// The pack's assertions that must fail are no part of a normal run.",
|
|
384
|
+
pad + "tags: process.env.CUCUMBER_TAGS || 'not @wip and not @must-fail',",
|
|
385
|
+
]
|
|
386
|
+
src = src[:default.end()] + '\n' + '\n'.join(block) + src[default.end():]
|
|
387
|
+
print(' cucumber.js: the tags that keep the assertions that must fail out of a normal run')
|
|
388
|
+
|
|
389
|
+
world = re.search(r"^([ \t]*)worldParameters:[ \t]*\{[ \t]*$", src, re.M)
|
|
390
|
+
if not world:
|
|
391
|
+
sys.exit(" cucumber.js has no worldParameters block to add the users registry to.")
|
|
392
|
+
pad = world.group(1) + ' '
|
|
393
|
+
additions = []
|
|
394
|
+
if not re.search(r"^[ \t]*wikiAdmin:", src, re.M):
|
|
395
|
+
additions += [
|
|
396
|
+
pad + "// The account the test-page steps make and delete the test pages as, through the wiki's API.",
|
|
397
|
+
pad + "wikiAdmin: process.env.WIKI_ADMIN || 'administrator',",
|
|
398
|
+
]
|
|
399
|
+
if not re.search(r"^[ \t]*users:[ \t]*\{", src, re.M):
|
|
400
|
+
rows = [r.split('|') for r in registry.splitlines() if r.strip()]
|
|
401
|
+
additions += [
|
|
402
|
+
pad + "// The users registry: a handle a scenario reads, mapped to an account of this wiki (the default",
|
|
403
|
+
pad + "// accounts: cmd-tools-mediawiki-maintenance.sh --add-users). Override one with %s_<HANDLE>_USERNAME," % prefix,
|
|
404
|
+
pad + "// %s_<HANDLE>_PASSWORD and %s_<HANDLE>_EMAIL." % (prefix, prefix),
|
|
405
|
+
pad + "users: {",
|
|
406
|
+
]
|
|
407
|
+
for handle, email, password, name in rows:
|
|
408
|
+
env = '%s_%s' % (prefix, handle.upper())
|
|
409
|
+
additions.append(pad + " %s: { username: process.env.%s_USERNAME || '%s', password: process.env.%s_PASSWORD || '%s', email: process.env.%s_EMAIL || '%s' }," % (handle, env, name, env, password, env, email))
|
|
410
|
+
additions.append(pad + "},")
|
|
411
|
+
print(' cucumber.js: the users registry (%s)' % ', '.join(r[0] for r in rows))
|
|
412
|
+
if additions:
|
|
413
|
+
src = src[:world.end()] + '\n' + '\n'.join(additions) + src[world.end():]
|
|
414
|
+
|
|
415
|
+
if src != before:
|
|
416
|
+
open(cucumber_file, 'w').write(src)
|
|
417
|
+
PYEOF
|
|
418
|
+
|
|
419
|
+
# A first feature, when the project has none for the wiki yet: the main page, the login page,
|
|
420
|
+
# each default account, a refused login, the refusal of a protected page.
|
|
421
|
+
local feature="${WORKSPACE_SCRIPTS}/plugins/mediawiki/site.feature" ;
|
|
422
|
+
if [ -f "${feature}" ] && [ ! -f "${project_path}/tests/features/site.feature" ] ; then
|
|
423
|
+
mkdir -p "${project_path}/tests/features" && cp "${feature}" "${project_path}/tests/features/site.feature" \
|
|
424
|
+
&& echo " tests/features/site.feature: a first feature for the wiki" ;
|
|
425
|
+
fi
|
|
426
|
+
|
|
427
|
+
# The scenarios log in as the default accounts: make sure an installed wiki has them.
|
|
428
|
+
if ( cd "${project_path}" && mediawiki_installed ) ; then
|
|
429
|
+
if ( add_mediawiki_users > /dev/null 2>&1 ) ; then
|
|
430
|
+
echo " the default accounts are on the wiki (${users[*]})" ;
|
|
431
|
+
else
|
|
432
|
+
echo " The default accounts could not be written: is the wiki installed (bash cmd-mediawiki-project.sh ${PROJECT_NAME} --install)?" ;
|
|
433
|
+
fi
|
|
434
|
+
else
|
|
435
|
+
echo " The wiki is not installed: the scenarios that log in need a wiki built with --install." ;
|
|
436
|
+
fi
|
|
437
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
Feature: The wiki answers and its accounts work
|
|
2
|
+
As the owner of the wiki
|
|
3
|
+
I want the main page, the login and each default account to work
|
|
4
|
+
So that a build that came out broken is caught before anything else is tested
|
|
5
|
+
|
|
6
|
+
# Placed by the workspace's testing setup as a starting point: it is yours to change.
|
|
7
|
+
# The accounts are the default ones (cmd-tools-mediawiki-maintenance.sh --add-users); a scenario logs in
|
|
8
|
+
# by a handle of the users registry in cucumber.js, so no password is written here. A test page is made
|
|
9
|
+
# through the wiki's API as the "administrator" account and deleted after the scenario.
|
|
10
|
+
|
|
11
|
+
@critical
|
|
12
|
+
Scenario: The main page is served
|
|
13
|
+
Given I am an anonymous user
|
|
14
|
+
When I open the page "Main Page"
|
|
15
|
+
Then I should see the page "Main Page"
|
|
16
|
+
And the scripts of the page should all load
|
|
17
|
+
|
|
18
|
+
Scenario Outline: The <account> account logs in
|
|
19
|
+
Given I am an anonymous user
|
|
20
|
+
When I log in as "<account>" with the login form
|
|
21
|
+
Then I should be logged in as "<account>"
|
|
22
|
+
|
|
23
|
+
Examples:
|
|
24
|
+
| account |
|
|
25
|
+
| administrator |
|
|
26
|
+
| editor |
|
|
27
|
+
| reader |
|
|
28
|
+
|
|
29
|
+
Scenario: A wrong password is refused
|
|
30
|
+
Given I am an anonymous user
|
|
31
|
+
When I log in with the user name "No such account here" and the password "Wrong-password-1"
|
|
32
|
+
Then the login should be refused with "Incorrect username or password entered. Please try again."
|
|
33
|
+
And nobody should be logged in
|
|
34
|
+
|
|
35
|
+
Scenario: A page protected for established accounts refuses the new account
|
|
36
|
+
Given the page "Site test page" has the text "A page only established accounts edit."
|
|
37
|
+
And the page "Site test page" is protected so that only autoconfirmed users can edit it
|
|
38
|
+
And I am a logged in user with the "reader" user
|
|
39
|
+
Then editing the page "Site test page" should be refused with "This page has been protected to prevent editing or other actions."
|
|
40
|
+
|
|
41
|
+
Scenario: The editor saves a page
|
|
42
|
+
Given the page "Site test page" has the text "A page to change."
|
|
43
|
+
And I am a logged in user with the "editor" user
|
|
44
|
+
When I edit the page "Site test page"
|
|
45
|
+
And I add the wikitext "A line from the editor."
|
|
46
|
+
And I save the page with the summary "A first edit"
|
|
47
|
+
Then the edit should be saved
|
|
48
|
+
And the page text should contain "A line from the editor."
|