Wiki Management:Upload Instructions: Difference between revisions
Minor update - troubleshooting guide: Uploading Documentation to Wiki (24 sections) (wiki management) |
Updated documentation from markdown files |
||
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
This guide explains how to upload the documentation files to your MediaWiki instance. | This guide explains how to upload the documentation files to your MediaWiki instance. | ||
| Line 48: | Line 46: | ||
'''Delete orphaned wiki pages''' (pages that no longer have corresponding local files): | '''Delete orphaned wiki pages''' (pages that no longer have corresponding local files): | ||
<pre class="lang-bash"> | <pre class="lang-bash"> | ||
= Preview what would be deleted (dry run - recommended first) = | == Preview what would be deleted (dry run - recommended first) == | ||
python3 /root/wiki_manager.py --delete-orphaned --dry-run | python3 /root/wiki_manager.py --delete-orphaned --dry-run | ||
= Actually delete orphaned pages (with confirmation) = | == Actually delete orphaned pages (with confirmation) == | ||
python3 /root/wiki_manager.py --delete-orphaned | python3 /root/wiki_manager.py --delete-orphaned | ||
= Delete orphaned pages without confirmation (non-interactive) = | == Delete orphaned pages without confirmation (non-interactive) == | ||
python3 /root/wiki_manager.py --delete-orphaned -y | python3 /root/wiki_manager.py --delete-orphaned -y | ||
</pre> | </pre> | ||
| Line 69: | Line 67: | ||
The <code>--delete-orphaned</code> feature helps you clean up these old pages: | The <code>--delete-orphaned</code> feature helps you clean up these old pages: | ||
= '''Finds orphaned pages''': Automatically searches for all <code>Documentation:</code> pages on the wiki and compares them with your local files = | ==== '''Finds orphaned pages''': Automatically searches for all <code>Documentation:</code> pages on the wiki and compares them with your local files ==== | ||
= '''Shows what would be deleted''': Lists all orphaned pages with their content length = | == '''Shows what would be deleted''': Lists all orphaned pages with their content length == | ||
= '''Safety features''': = | == '''Safety features''': == | ||
* Use <code>--dry-run</code> first to preview what would be deleted | * Use <code>--dry-run</code> first to preview what would be deleted | ||
| Line 81: | Line 79: | ||
<pre class="lang-bash"> | <pre class="lang-bash"> | ||
= 1. First, preview what would be deleted = | == 1. First, preview what would be deleted == | ||
python3 /root/wiki_manager.py --delete-orphaned --dry-run | python3 /root/wiki_manager.py --delete-orphaned --dry-run | ||
= 2. If the list looks correct, actually delete them = | == 2. If the list looks correct, actually delete them == | ||
python3 /root/wiki_manager.py --delete-orphaned -y | python3 /root/wiki_manager.py --delete-orphaned -y | ||
= 3. Upload the new restructured documentation = | == 3. Upload the new restructured documentation == | ||
python3 /root/wiki_manager.py --upload --update-main-page | python3 /root/wiki_manager.py --upload --update-main-page | ||
</pre> | </pre> | ||
| Line 145: | Line 143: | ||
<pre class="lang-bash"> | <pre class="lang-bash"> | ||
= Upload with auto-generated comments = | == Upload with auto-generated comments == | ||
python3 /root/wiki_manager.py --upload --auto-comment | python3 /root/wiki_manager.py --upload --auto-comment | ||
= Upload with custom comment and update main page = | == Upload with custom comment and update main page == | ||
python3 /root/wiki_manager.py --upload --update-main-page --comment "Major documentation update" | python3 /root/wiki_manager.py --upload --update-main-page --comment "Major documentation update" | ||
= Upload with custom comment in non-interactive mode = | == Upload with custom comment in non-interactive mode == | ||
python3 /root/wiki_manager.py --upload --comment "Quick fix" -y | python3 /root/wiki_manager.py --upload --comment "Quick fix" -y | ||
</pre> | </pre> | ||
| Line 158: | Line 156: | ||
The unified wiki manager script: | The unified wiki manager script: | ||
= Automatically discovers all documentation files in the <code>/root/documentation/</code> directory = | ==== Automatically discovers all documentation files in the <code>/root/documentation/</code> directory ==== | ||
= Converts markdown files to MediaWiki wikitext format = | == Converts markdown files to MediaWiki wikitext format == | ||
= Maps files to wiki pages based on folder structure: = | == Maps files to wiki pages based on folder structure: == | ||
* <code>getting-started/*.md</code> → <code>Documentation:Page_Name</code> (e.g., <code>getting-started/system-overview/index.md</code> → <code>Documentation:Index</code>) | * <code>getting-started/*.md</code> → <code>Documentation:Page_Name</code> (e.g., <code>getting-started/system-overview/index.md</code> → <code>Documentation:Index</code>) | ||
| Line 169: | Line 167: | ||
* <code>wiki-management/*.md</code> → <code>Documentation:Page_Name</code> (e.g., <code>wiki-management/upload-instructions.md</code> → <code>Documentation:Upload Instructions</code>) | * <code>wiki-management/*.md</code> → <code>Documentation:Page_Name</code> (e.g., <code>wiki-management/upload-instructions.md</code> → <code>Documentation:Upload Instructions</code>) | ||
= Uploads all documentation pages to the wiki = | == Uploads all documentation pages to the wiki == | ||
= Can update the Main Page with links to all documentation = | == Can update the Main Page with links to all documentation == | ||
= Can identify and delete orphaned wiki pages (pages without corresponding local files) = | == Can identify and delete orphaned wiki pages (pages without corresponding local files) == | ||
=== Customizing Wiki URL === | === Customizing Wiki URL === | ||
| Line 185: | Line 183: | ||
=== Step 1: Access the Wiki === | === Step 1: Access the Wiki === | ||
= Navigate to your wiki: [https://wiki.jb-vpn.uk/index.php?title=Main_Page https://wiki.jb-vpn.uk/index.php?title=Main_Page] = | ==== Navigate to your wiki: [https://wiki.jb-vpn.uk/index.php?title=Main_Page https://wiki.jb-vpn.uk/index.php?title=Main_Page] ==== | ||
= Log in with your MediaWiki account = | == Log in with your MediaWiki account == | ||
=== Step 2: Create the Documentation Namespace === | === Step 2: Create the Documentation Namespace === | ||
= Go to: [https://wiki.jb-vpn.uk/index.php?title=Special:CreatePage https://wiki.jb-vpn.uk/index.php?title=Special:CreatePage] = | ==== Go to: [https://wiki.jb-vpn.uk/index.php?title=Special:CreatePage https://wiki.jb-vpn.uk/index.php?title=Special:CreatePage] ==== | ||
= Create a page named <code>Documentation:Index</code> = | == Create a page named <code>Documentation:Index</code> == | ||
= Or navigate directly: [https://wiki.jb-vpn.uk/index.php?title=Documentation:Index&action=edit https://wiki.jb-vpn.uk/index.php?title=Documentation:Index&action=edit] = | == Or navigate directly: [https://wiki.jb-vpn.uk/index.php?title=Documentation:Index&action=edit https://wiki.jb-vpn.uk/index.php?title=Documentation:Index&action=edit] == | ||
=== Step 3: Convert and Paste Content === | === Step 3: Convert and Paste Content === | ||
| Line 198: | Line 196: | ||
For each documentation file: | For each documentation file: | ||
= '''Read the markdown file''': = | ==== '''Read the markdown file''': ==== | ||
<pre class="lang-bash"> | <pre class="lang-bash"> | ||
cat /root/documentation/index.md | cat /root/documentation/index.md | ||
</pre> | </pre> | ||
= '''Manually convert key elements''': = | == '''Manually convert key elements''': == | ||
* <code># Header</code> → <code>= Header =</code> | * <code># Header</code> → <code>= Header =</code> | ||
| Line 218: | Line 216: | ||
* Code blocks: Wrap with </code><syntaxhighlight lang="bash"><code> and </code></syntaxhighlight><code> | * Code blocks: Wrap with </code><syntaxhighlight lang="bash"><code> and </code></syntaxhighlight><code> | ||
= '''Create the pages''': = | == '''Create the pages''': == | ||
* </code>Documentation:Index<code> (from </code>documentation/index.md<code>) | * </code>Documentation:Index<code> (from </code>documentation/index.md<code>) | ||
| Line 247: | Line 245: | ||
<pre class="lang-bash"> | <pre class="lang-bash"> | ||
WIKI_URL=" | WIKI_URL="https://wiki.jb-vpn.uk" | ||
USERNAME="your_username" | USERNAME="your_username" | ||
PASSWORD="your_password" | PASSWORD="your_password" | ||
= Get login token = | ==== Get login token ==== | ||
LOGIN_TOKEN=$(curl -s "$WIKI_URL/api.php?action=query&meta=tokens&type=login&format=json" | grep -oP '(?<="logintoken":")[^"]''' # Login | LOGIN_TOKEN=$(curl -s "$WIKI_URL/api.php?action=query&meta=tokens&type=login&format=json" | grep -oP '(?<="logintoken":")[^"]''' # Login | ||
LOGIN_RESULT=$(curl -s -c cookies.txt -b cookies.txt \ | LOGIN_RESULT=$(curl -s -c cookies.txt -b cookies.txt \ | ||
| Line 296: | Line 294: | ||
If login fails: | If login fails: | ||
= Verify your MediaWiki username and password = | ==== Verify your MediaWiki username and password ==== | ||
= Check that your account has edit permissions = | == Check that your account has edit permissions == | ||
= Ensure the wiki is accessible from the VPS = | == Ensure the wiki is accessible from the VPS == | ||
=== Connection Issues === | === Connection Issues === | ||
| Line 304: | Line 302: | ||
If you can't connect: | If you can't connect: | ||
<pre class="lang-bash"> | <pre class="lang-bash"> | ||
= Test connectivity = | ==== Test connectivity ==== | ||
curl -I https://wiki.jb-vpn.uk | curl -I https://wiki.jb-vpn.uk | ||
= Test API = | == Test API (public or local) == | ||
curl "http:// | curl "https://wiki.jb-vpn.uk/api.php?action=query&meta=siteinfo&format=json" | ||
curl "http://127.0.0.1:8010/api.php?action=query&meta=siteinfo&format=json" | |||
</pre> | </pre> | ||
| Line 336: | Line 334: | ||
<pre class="lang-bash"> | <pre class="lang-bash"> | ||
= 1. Preview orphaned pages that would be deleted = | ==== 1. Preview orphaned pages that would be deleted ==== | ||
python3 /root/wiki_manager.py --delete-orphaned --dry-run | python3 /root/wiki_manager.py --delete-orphaned --dry-run | ||
= 2. Delete orphaned pages (if the preview looks correct) = | == 2. Delete orphaned pages (if the preview looks correct) == | ||
python3 /root/wiki_manager.py --delete-orphaned -y | python3 /root/wiki_manager.py --delete-orphaned -y | ||
= 3. Upload all new/updated documentation = | == 3. Upload all new/updated documentation == | ||
python3 /root/wiki_manager.py --upload --auto-comment | python3 /root/wiki_manager.py --upload --auto-comment | ||
= 4. Update the Main Page with new documentation structure = | == 4. Update the Main Page with new documentation structure == | ||
python3 /root/wiki_manager.py --update-main-page | python3 /root/wiki_manager.py --update-main-page | ||
= Or do steps 3 and 4 together: = | == Or do steps 3 and 4 together: == | ||
python3 /root/wiki_manager.py --upload --update-main-page --auto-comment | python3 /root/wiki_manager.py --upload --update-main-page --auto-comment | ||
</pre> | </pre> | ||
Latest revision as of 14:04, 16 May 2026
This guide explains how to upload the documentation files to your MediaWiki instance.
Option 1: Automated Upload (Recommended)
[edit]Use the unified wiki manager script to automatically upload all documentation files.
Prerequisites
[edit]The script requires mwclient library, which should already be installed:
pip3 install --break-system-packages mwclient
Usage
[edit]First time setup - Store credentials:
python3 /root/wiki_manager.py --store-credentials
Upload all documentation files:
python3 /root/wiki_manager.py --upload
Update the Main Page with documentation links:
python3 /root/wiki_manager.py --update-main-page
Do both at once:
python3 /root/wiki_manager.py --upload --update-main-page
Check sync status:
python3 /root/wiki_manager.py --status
Sync changes from wiki to local files:
python3 /root/wiki_manager.py --sync
Delete orphaned wiki pages (pages that no longer have corresponding local files):
== Preview what would be deleted (dry run - recommended first) == python3 /root/wiki_manager.py --delete-orphaned --dry-run == Actually delete orphaned pages (with confirmation) == python3 /root/wiki_manager.py --delete-orphaned == Delete orphaned pages without confirmation (non-interactive) == python3 /root/wiki_manager.py --delete-orphaned -y
Upload new docs and delete old orphaned pages in one go:
python3 /root/wiki_manager.py --upload --delete-orphaned -y
Managing Orphaned Pages
[edit]When you restructure documentation (e.g., breaking large files into smaller sub-pages), old wiki pages may become "orphaned" - they exist on the wiki but no longer have corresponding local files.
The --delete-orphaned feature helps you clean up these old pages:
Finds orphaned pages: Automatically searches for all Documentation: pages on the wiki and compares them with your local files
[edit]Shows what would be deleted: Lists all orphaned pages with their content length
[edit]Safety features:
[edit] * Use --dry-run first to preview what would be deleted
* Requires confirmation (or use -y flag for non-interactive mode)
* Shows detailed information about each page before deletion
Example workflow after restructuring documentation:
== 1. First, preview what would be deleted == python3 /root/wiki_manager.py --delete-orphaned --dry-run == 2. If the list looks correct, actually delete them == python3 /root/wiki_manager.py --delete-orphaned -y == 3. Upload the new restructured documentation == python3 /root/wiki_manager.py --upload --update-main-page
Note: The script only deletes pages in the Documentation: namespace that don't have corresponding local files. It will never delete pages that still have local files, ensuring your active documentation is always preserved.
Customizing Upload Comments
[edit]By default, the script uses the comment "Uploaded documentation from markdown files" for all uploads. You can customize this behavior in two ways:
Option 1: Custom Comment
[edit]Use the --comment flag to specify a custom comment that will be used for all uploads:
python3 /root/wiki_manager.py --upload --comment "Updated documentation for v2.0"
This is useful when you want to provide a specific message for a batch of uploads, such as:
- Version updates:
--comment "Documentation update for version 2.1"
- Feature additions:
--comment "Added new SSH port forwarding documentation"
- Bug fixes:
--comment "Fixed formatting issues in configuration guides"
Option 2: Auto-Generated Comments
[edit]Use the --auto-comment flag to automatically generate meaningful comments based on the content of each file:
python3 /root/wiki_manager.py --upload --auto-comment
The auto-comment feature analyzes each file to generate contextual comments such as:
"Added configuration guide: SSH Port Forwarding (configuration)"
"Major update - troubleshooting guide: Port Forwarding Troubleshooting (3 sections) (troubleshooting)"
"Content added - overview: System Overview (getting started)"
The auto-comment generator:
- Detects document type (troubleshooting guide, configuration guide, overview, etc.)
- Identifies whether it's a new page or an update
- Compares with existing wiki content to detect changes (major update, content added, minor update)
- Extracts the document title from markdown headers
- Counts sections to provide context
- Categorizes based on file path
Note: The --comment flag takes precedence over --auto-comment. If both are specified, the custom comment will be used.
Examples:
== Upload with auto-generated comments == python3 /root/wiki_manager.py --upload --auto-comment == Upload with custom comment and update main page == python3 /root/wiki_manager.py --upload --update-main-page --comment "Major documentation update" == Upload with custom comment in non-interactive mode == python3 /root/wiki_manager.py --upload --comment "Quick fix" -y
What the Script Does
[edit]The unified wiki manager script:
Automatically discovers all documentation files in the /root/documentation/ directory
[edit]Converts markdown files to MediaWiki wikitext format
[edit]Maps files to wiki pages based on folder structure:
[edit]*getting-started/*.md→Documentation:Page_Name(e.g.,getting-started/system-overview/index.md→Documentation:Index)
*configuration/*.md→Documentation:Page_Name(e.g.,configuration/adding-services/step-by-step.md→Documentation:Step By Step)
*troubleshooting/*.md→Documentation:Page_Name(e.g.,troubleshooting/port-forwarding-troubleshooting.md→Documentation:Port Forwarding Troubleshooting)
*wiki-management/*.md→Documentation:Page_Name(e.g.,wiki-management/upload-instructions.md→Documentation:Upload Instructions)
Uploads all documentation pages to the wiki
[edit]Can update the Main Page with links to all documentation
[edit]Can identify and delete orphaned wiki pages (pages without corresponding local files)
[edit]Customizing Wiki URL
[edit]The script automatically detects the wiki URL. To specify a custom URL, edit the script or use environment variables.
Option 2: Manual Upload
[edit]If you prefer to upload manually or the script doesn't work:
Step 1: Access the Wiki
[edit]Navigate to your wiki: https://wiki.jb-vpn.uk/index.php?title=Main_Page
[edit]Log in with your MediaWiki account
[edit]Step 2: Create the Documentation Namespace
[edit]Create a page named Documentation:Index
[edit]Or navigate directly: https://wiki.jb-vpn.uk/index.php?title=Documentation:Index&action=edit
[edit]Step 3: Convert and Paste Content
[edit]For each documentation file:
Read the markdown file:
[edit]cat /root/documentation/index.md
Manually convert key elements:
[edit]*# Header→= Header =
*## Header→== Header ==
*### Header→=== Header ===
* Inline code: `code→code
*bold→bold
**italic*→*italic*
* Code blocks: Wrap with<syntaxhighlight lang="bash">and</syntaxhighlight>
Create the pages:
[edit]*Documentation:Index(fromdocumentation/index.md)
*Documentation:System_Overview(fromdocumentation/getting-started/system-overview.md)
*Documentation:Adding_Services(fromdocumentation/configuration/adding-services.md)
*Documentation:Current_Services(fromdocumentation/configuration/current-services.md)
Step 4: Add Navigation
[edit]Create a navigation template or update the main page to link to:
[Documentation Index](index.md)
[System Overview](System_Overview.md)
[Adding Services](Adding_Services.md)
[Current Services](Current_Services.md)
Option 3: Using MediaWiki API with curl
[edit]You can also use curl to upload via the MediaWiki API:
Step 1: Get Login Token
[edit]WIKI_URL="https://wiki.jb-vpn.uk"
USERNAME="your_username"
PASSWORD="your_password"
==== Get login token ====
LOGIN_TOKEN=$(curl -s "$WIKI_URL/api.php?action=query&meta=tokens&type=login&format=json" | grep -oP '(?<="logintoken":")[^"]''' # Login
LOGIN_RESULT=$(curl -s -c cookies.txt -b cookies.txt \
-d "action=login" \
-d "lgname=$USERNAME" \
-d "lgpassword=$PASSWORD" \
-d "lgtoken=$LOGIN_TOKEN" \
-d "format=json" \
"$WIKI_URL/api.php")
echo "Login: $LOGIN_RESULT"
Step 2: Get Edit Token
[edit]EDIT_TOKEN=$(curl -s -b cookies.txt \
"$WIKI_URL/api.php?action=query&meta=tokens&format=json" | \
grep -oP '(?<="csrftoken":")[^"])''')
Step 3: Upload Page
[edit]PAGE_NAME="Documentation:Index"
CONTENT=$(cat /root/documentation/index.md | sed 's/#/=/g') # Basic conversion
curl -s -b cookies.txt \
-d "action=edit" \
-d "title=$PAGE_NAME" \
-d "text=$CONTENT" \
-d "token=$EDIT_TOKEN" \
-d "format=json" \
"$WIKI_URL/api.php"
Note: This method requires manual markdown-to-wikitext conversion and is more complex.
Troubleshooting
[edit]Script Authentication Issues
[edit]If login fails:
Verify your MediaWiki username and password
[edit]Check that your account has edit permissions
[edit]Ensure the wiki is accessible from the VPS
[edit]Connection Issues
[edit]If you can't connect:
==== Test connectivity ====
curl -I https://wiki.jb-vpn.uk
== Test API (public or local) ==
curl "https://wiki.jb-vpn.uk/api.php?action=query&meta=siteinfo&format=json"
curl "http://127.0.0.1:8010/api.php?action=query&meta=siteinfo&format=json"
Permission Issues
[edit]Ensure your MediaWiki account has:
editpermission
createpage` permission (if pages don't exist)
Updating the Main Page
[edit]To update the Main Page with links to all documentation:
python3 /root/wiki_manager.py --update-main-page
This will add a comprehensive list of all documentation pages to the Main Page.
Complete Workflow Example
[edit]Here's a complete example workflow for restructuring documentation:
==== 1. Preview orphaned pages that would be deleted ==== python3 /root/wiki_manager.py --delete-orphaned --dry-run == 2. Delete orphaned pages (if the preview looks correct) == python3 /root/wiki_manager.py --delete-orphaned -y == 3. Upload all new/updated documentation == python3 /root/wiki_manager.py --upload --auto-comment == 4. Update the Main Page with new documentation structure == python3 /root/wiki_manager.py --update-main-page == Or do steps 3 and 4 together: == python3 /root/wiki_manager.py --upload --update-main-page --auto-comment