Memo
Imported from wiki page: WebsitePublic:Memo
Test Environment
- Wiki: Swissbit Wiki Development Environment
- Public content namespace:
WebsitePublic - Namespace ID:
3000 - Talk namespace:
3001 = WebsitePublic Talk - Export namespace:
3000only
1. Confirm MediaWiki API Endpoint
- Method: Special:Version → Entry point URLs →
api.php - Endpoint: MediaWiki API
- Verification: Run siteinfo test
- Result: PASS
The API returned MediaWiki site information in JSON format.
2. Create Dedicated Public Namespace
- Namespace:
WebsitePublic - Subpages: Enabled
- Content namespace: Enabled
- Visual editor: Enabled
- Example pages:
- Result: PASS
3. Confirm WebsitePublic Namespace ID
- API: Check namespace IDs
- Returned:
3000 = WebsitePublic3001 = WebsitePublic Talk
- Result: PASS
4. List All WebsitePublic Pages
- API: List WebsitePublic pages
- Returned pages:
- Result: PASS
5. Export Page as Wikitext
- Test page: WebsitePublic:ExportTest
- API: Export Wikitext
- Verified content:
- Text
- Lists
- Wiki tables
- Internal links
- External links
- SyntaxHighlight code blocks
- Result: PASS
6. Hide Site Notice on WebsitePublic Namespace
Hide site notice on WebsitePublic namespace
Location: MediaWiki:Common.css
Add:
body.ns-3000 #siteNotice {
display: none;
}
7.File access verification
wgUploadDirectory: /data/bluespice/images
wgUploadPath: /sbwikidevelop/images
Result: Direct file URLs are accessible without Wiki login.
Server-side API Access Test
WebsitePublic Page
Command:
curl -ks "https://sbwiki.swissbit.com/sbwikidevelop/api.php?action=parse&page=WebsitePublic%3AExportTest&prop=wikitext&format=json"
Expected result:
Wikitext is returned.
Normal User Page
Command:
curl -ks "https://sbwiki.swissbit.com/sbwikidevelop/api.php?action=parse&page=User%3ADaniel.Chen&prop=wikitext&format=json"
Expected result:
readapidenied You need read permission to use this module.
Wiki Export Service Account Configuration
Purpose:
Store the Wiki API service account credentials on the Wiki server for the automatic WebsitePublic export script.
Configuration folder:
/data/compose/wiki-export
Create folder and .env file:
sudo mkdir -p /data/compose/wiki-export sudo nano /data/compose/wiki-export/.env
File content:
WIKI_API_URL="https://sbwiki.swissbit.com/sbwikidevelop/api.php" WIKI_BOT_USER="Wiki export user00@wiki_export_user00" WIKI_BOT_PASSWORD="YOUR_BOT_PASSWORD"
Protect the credential file:
sudo chmod 600 /data/compose/wiki-export/.env sudo chown swissbit:swissbit /data/compose/wiki-export/.env
Verify permissions:
ls -l /data/compose/wiki-export/.env
Expected:
-rw------- 1 swissbit swissbit ...
Note:
The bot password should not be stored directly in the Python source code. The export script should load it from /data/compose/wiki-export/.env.
Wiki Website Export Service Account Test
Service Account
Account:
Wiki export user00
A dedicated local Wiki account is used for the automatic WebsitePublic export process.
Local login was enabled with:
$wgPluggableAuth_EnableLocalLogin = true;
Bot Password
A Bot Password was created for the service account.
The Bot Password is used for automated MediaWiki API authentication.
Note: Do not store the Bot Password directly in the export script.
Export Configuration
Location:
/data/compose/wiki-export/.env
Content:
WIKI_API_URL="https://sbwiki.swissbit.com/sbwikidevelop/api.php" WIKI_BOT_USER="Wiki export user00@wiki_export_user00" WIKI_BOT_PASSWORD="BOT_PASSWORD"
Protect the configuration file:
sudo chmod 600 /data/compose/wiki-export/.env sudo chown swissbit:swissbit /data/compose/wiki-export/.env
Verify permissions:
ls -l /data/compose/wiki-export/.env
Expected:
-rw------- 1 swissbit swissbit ...
Load Environment Variables
cd /data/compose/wiki-export set -a source .env set +a
Verify:
echo "$WIKI_API_URL" echo "$WIKI_BOT_USER"
Do not print WIKI_BOT_PASSWORD.
Get API Login Token
LOGIN_TOKEN=$(curl -ks -c /tmp/wiki_export_cookie.txt \ "$WIKI_API_URL?action=query&meta=tokens&type=login&format=json" \ | python3 -c "import sys,json; print(json.load(sys.stdin)['query']['tokens']['logintoken'])")
Optional verification:
echo "$LOGIN_TOKEN"
Login to MediaWiki API
curl -ks \ -b /tmp/wiki_export_cookie.txt \ -c /tmp/wiki_export_cookie.txt \ -X POST \ "$WIKI_API_URL" \ --data-urlencode "action=login" \ --data-urlencode "lgname=$WIKI_BOT_USER" \ --data-urlencode "lgpassword=$WIKI_BOT_PASSWORD" \ --data-urlencode "lgtoken=$LOGIN_TOKEN" \ --data-urlencode "format=json"
Result:
"result":"Success" "lguserid":151 "lgusername":"Wiki export user00"
Status: PASS
Export WebsitePublic Wikitext
After login, use the saved session cookie to retrieve the page.
curl -ks \ -b /tmp/wiki_export_cookie.txt \ "$WIKI_API_URL?action=parse&page=WebsitePublic%3AExportTest&prop=wikitext&format=json"
To display only the Wikitext:
curl -ks \ -b /tmp/wiki_export_cookie.txt \ "$WIKI_API_URL?action=parse&page=WebsitePublic%3AExportTest&prop=wikitext&format=json" \ | python3 -c "import sys,json; print(json.load(sys.stdin)['parse']['wikitext']['*'])"
Current Result
Bot Password API login: PASS WebsitePublic Wikitext export: To be verified
Authentication Flow
.env | v Bot Username / Password | v Get Login Token | v MediaWiki API Login | v Session Cookie | v WebsitePublic API Export