Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions e2e/e2e_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,28 @@ def test_edit_page(page: Page, login):
expect(page.locator("text=My Second Edit")).to_be_visible()


def test_create_in_folder(page: Page, login):
"""Check that existing pages link to creating a new page in the same folder."""
page.goto("http://localhost:8080/en/Main%20Page")

create = page.locator("text=Create a new page")
expect(create).to_be_visible()
with page.expect_navigation():
create.click()
page.wait_for_url("http://localhost:8080/edit/en/")

expect(page.locator("[name=page]")).to_have_value("en/")
expect(page.locator("#create-hint")).to_be_visible()


def test_create_in_folder_without_login(page: Page):
"""Check that the create-in-folder link is hidden when not logged in."""
page.goto("http://localhost:8080/en/Main%20Page")

expect(page.locator("text=My Second Edit")).to_be_visible()
expect(page.locator("#create-in-folder")).to_have_count(0)


def test_rename_page(page: Page, login):
"""Check if we can rename the main page to something else."""
edit = page.locator("text=Edit Page")
Expand Down
13 changes: 13 additions & 0 deletions static/truewiki/truewiki.css
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,19 @@ h6:hover .anchor {
margin-top: 5px;
padding: 0 3px;
}
#create-in-folder {
background-color: #f9f9f9;
border: 1px solid #ddd;
clear: both;
font-size: 90%;
margin-top: 10px;
padding: 4px 10px;
}
#create-hint {
color: #555;
font-size: 80%;
margin: 0 0 4px 0;
}
#categories {
float: left;
}
Expand Down
1 change: 1 addition & 0 deletions templates/Edit.mediawiki
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
<h3>Edit page</h3>
|
<h3>Create new page</h3>
<p id="create-hint">Tip: to add sub-pages to this page later, end its name with "/Main Page", like "en/Bridges/Main Page".</p>
}}

<form method="post" accept-charset="utf-8" enctype="multipart/form-data">
Expand Down
5 changes: 5 additions & 0 deletions templates/Page.mediawiki
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@
<div id="content-footer">
{{footer}}
</div>
{{#if: {{{create_in_folder|}}}|
<div id="create-in-folder">
Missing something? <a href="/edit/{{urlencode:{{{create_in_folder}}}}}">Create a new page</a>
</div>
}}

{{{javascript}}}
</main>
Expand Down
9 changes: 8 additions & 1 deletion truewiki/views/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
from . import error
from .. import metadata
from ..content import breadcrumb
from ..wiki_page import WikiPage
from ..wiki_page import (
NAMESPACES,
WikiPage,
)
from ..wrapper import wrap_page

CACHE_PAGE_FOLDER = None
Expand All @@ -25,8 +28,12 @@ def _view(wiki_page, user, page: str) -> web.Response:
"display_name": user.display_name if user else "",
"user_settings_url": user.get_settings_url() if user else "",
"errors": len(wiki_page.errors) if wiki_page.errors else "",
"create_in_folder": "",
}

if user and "/" in page and page.split("/")[0] not in NAMESPACES and wiki_page.page_exists(page):
variables["create_in_folder"] = page.rsplit("/", 1)[0] + "/"

templates["language"] = wiki_page.add_language(page)
templates["footer"] = wiki_page.add_footer(page)
templates["content"] += wiki_page.add_content(page)
Expand Down