Commit 064274a7 by Bridger Maxwell

Most of the wiki pages are now loading without errors.

parent baa2c068
...@@ -11,7 +11,7 @@ from mitxmako.shortcuts import render_to_response ...@@ -11,7 +11,7 @@ from mitxmako.shortcuts import render_to_response
from multicourse import multicourse_settings from multicourse import multicourse_settings
from models import Revision, Article, CreateArticleForm, RevisionFormWithTitle, RevisionForm from models import Revision, Article, Namespace, CreateArticleForm, RevisionFormWithTitle, RevisionForm
import wiki_settings import wiki_settings
def get_course(course_id): def get_course(course_id):
...@@ -20,6 +20,16 @@ def get_course(course_id): ...@@ -20,6 +20,16 @@ def get_course(course_id):
except KeyError: except KeyError:
raise Http404("Course not found") raise Http404("Course not found")
return course return course
def wiki_article_reverse(wiki_page, article, course, args=[], kwargs={}):
return reverse(wiki_page, kwargs=dict({'course_id': course.id, 'article_path' : article.get_path()}, **kwargs), args=args)
def wiki_namespace_reverse(wiki_page, namespace = None, course=None, args=[], kwargs={}):
kwargs=dict({'course_id' : course.id}, **kwargs)
if namespace:
kwargs['namespace'] = namespace
return reverse(wiki_page, kwargs=kwargs, args=args)
def view(request, course_id, article_path): def view(request, course_id, article_path):
course = get_course(course_id) course = get_course(course_id)
...@@ -37,6 +47,7 @@ def view(request, course_id, article_path): ...@@ -37,6 +47,7 @@ def view(request, course_id, article_path):
'wiki_current_revision_deleted' : not (article.current_revision.deleted == 0), 'wiki_current_revision_deleted' : not (article.current_revision.deleted == 0),
'wiki_title' : article.title + " - edX %s Wiki" % course.title, 'wiki_title' : article.title + " - edX %s Wiki" % course.title,
'course' : course, 'course' : course,
'namespace' : article.namespace.name,
} }
d.update(csrf(request)) d.update(csrf(request))
return render_to_response('simplewiki/simplewiki_view.html', d) return render_to_response('simplewiki/simplewiki_view.html', d)
...@@ -66,6 +77,7 @@ def view_revision(request, course_id, revision_number, article_path): ...@@ -66,6 +77,7 @@ def view_revision(request, course_id, revision_number, article_path):
'wiki_attachments_write': article.can_attach(request.user), 'wiki_attachments_write': article.can_attach(request.user),
'wiki_current_revision_deleted' : not (revision.deleted == 0), 'wiki_current_revision_deleted' : not (revision.deleted == 0),
'course' : course, 'course' : course,
'namespace' : article.namespace.name,
} }
d.update(csrf(request)) d.update(csrf(request))
return render_to_response('simplewiki/simplewiki_view.html', d) return render_to_response('simplewiki/simplewiki_view.html', d)
...@@ -82,80 +94,75 @@ def root_redirect(request, course_id): ...@@ -82,80 +94,75 @@ def root_redirect(request, course_id):
return HttpResponseRedirect(reverse('wiki_view', kwargs={'course_id' : course_id, 'article_path' : root.get_path()} )) return HttpResponseRedirect(reverse('wiki_view', kwargs={'course_id' : course_id, 'article_path' : root.get_path()} ))
def create(request, wiki_url): def create(request, course_id, article_path):
url_path = get_url_path(wiki_url) course = get_course(course_id)
if url_path != [] and url_path[0].startswith('_'): article_path_components = article_path.split('/')
d = {'wiki_err_keyword': True,
'wiki_url': '/'.join(url_path) }
d.update(csrf(request))
return render_to_response('simplewiki/simplewiki_error.html', d)
# Lookup path # Ensure the namespace exists
try: if not len(article_path_components) >= 1 or len(article_path_components[0]) == 0:
# Ensure that the path exists... d = {'wiki_err_no_namespace': True,
root = Article.get_root() 'course' : course}
# Remove root slug if present in path d.update(csrf(request))
if url_path and root.slug == url_path[0]: return render_to_response('simplewiki/simplewiki_error.html', d)
url_path = url_path[1:]
path = Article.get_url_reverse(url_path[:-1], root) namespace = None
if not path: try:
d = {'wiki_err_noparent': True, namespace = Namespace.objects.get(name__exact = article_path_components[0])
'wiki_url_parent': '/'.join(url_path[:-1]) } except Namespace.DoesNotExist, ValueError:
d.update(csrf(request)) d = {'wiki_err_bad_namespace': True,
return render_to_response('simplewiki/simplewiki_error.html', d) 'course' : course}
d.update(csrf(request))
return render_to_response('simplewiki/simplewiki_error.html', d)
perm_err = check_permissions(request, path[-1], check_locked=False, check_write=True, check_deleted=True) # See if the article already exists
if perm_err: article_slug = article_path_components[1] if len(article_path_components) >= 2 else ''
return perm_err #TODO: Make sure the slug only contains legal characters (which is already done a bit by the url regex)
# Ensure doesn't already exist
article = Article.get_url_reverse(url_path, root) try:
if article: existing_article = Article.objects.get(namespace = namespace, slug__exact = article_slug)
return HttpResponseRedirect(reverse('wiki_view', args=(article[-1].get_url(),))) #It already exists, so we just redirect to view the article
return HttpResponseRedirect(wiki_article_reverse("wiki_view", existing_article, course))
# TODO: Somehow this doesnt work... except Article.DoesNotExist:
#except ShouldHaveExactlyOneRootSlug, (e): #This is good. The article doesn't exist
except: pass
if Article.objects.filter(parent=None).count() > 0:
return HttpResponseRedirect(reverse('wiki_view', args=('/',))) #TODO: Once we have permissions for namespaces, we should check for create permissions
# Root not found... #check_permissions(request, #namespace#, check_locked=False, check_write=True, check_deleted=True)
path = []
url_path = [""]
if request.method == 'POST': if request.method == 'POST':
f = CreateArticleForm(request.POST) f = CreateArticleForm(request.POST)
if f.is_valid(): if f.is_valid():
article = Article() article = Article()
article.slug = url_path[-1] article.slug = article_slug
if not request.user.is_anonymous(): if not request.user.is_anonymous():
article.created_by = request.user article.created_by = request.user
article.title = f.cleaned_data.get('title') article.title = f.cleaned_data.get('title')
if path != []: article.namespace = namespace
article.parent = path[-1]
a = article.save() a = article.save()
new_revision = f.save(commit=False) new_revision = f.save(commit=False)
if not request.user.is_anonymous(): if not request.user.is_anonymous():
new_revision.revision_user = request.user new_revision.revision_user = request.user
new_revision.article = article new_revision.article = article
new_revision.save() new_revision.save()
import django.db as db
return HttpResponseRedirect(reverse('wiki_view', args=(article.get_url(),))) return HttpResponseRedirect(wiki_article_reverse("wiki_view", article, course))
else: else:
f = CreateArticleForm(initial={'title':request.GET.get('wiki_article_name', url_path[-1]), f = CreateArticleForm(initial={'title':request.GET.get('wiki_article_name', article_slug),
'contents':_('Headline\n===\n\n')}) 'contents':_('Headline\n===\n\n')})
d = {'wiki_form': f, d = {'wiki_form': f,
'wiki_write': True, 'wiki_write': True,
'create_article' : True, 'create_article' : True,
'course' : course,
} }
d.update(csrf(request)) d.update(csrf(request))
return render_to_response('simplewiki/simplewiki_edit.html', d) return render_to_response('simplewiki/simplewiki_edit.html', d)
def edit(request, course_id, slug, namespace = None): def edit(request, course_id, article_path):
(article, err) = get_article(request, slug, namespace if namespace else course_id ) course = get_course(course_id)
(article, err) = get_article(request, article_path, course )
if err: if err:
return err return err
...@@ -177,11 +184,11 @@ def edit(request, course_id, slug, namespace = None): ...@@ -177,11 +184,11 @@ def edit(request, course_id, slug, namespace = None):
if request.POST.__contains__('delete'): if request.POST.__contains__('delete'):
if (article.current_revision.deleted == 1): #This article has already been deleted. Redirect if (article.current_revision.deleted == 1): #This article has already been deleted. Redirect
return HttpResponseRedirect(reverse('wiki_view', args=(article.get_url(),))) return HttpResponseRedirect(wiki_article_reverse('wiki_view', article, course))
new_revision.contents = "" new_revision.contents = ""
new_revision.deleted = 1 new_revision.deleted = 1
elif not new_revision.get_diff(): elif not new_revision.get_diff():
return HttpResponseRedirect(reverse('wiki_view', args=(article.get_url(),))) return HttpResponseRedirect(wiki_article_reverse('wiki_view', article, course))
if not request.user.is_anonymous(): if not request.user.is_anonymous():
new_revision.revision_user = request.user new_revision.revision_user = request.user
...@@ -189,7 +196,7 @@ def edit(request, course_id, slug, namespace = None): ...@@ -189,7 +196,7 @@ def edit(request, course_id, slug, namespace = None):
if wiki_settings.WIKI_ALLOW_TITLE_EDIT: if wiki_settings.WIKI_ALLOW_TITLE_EDIT:
new_revision.article.title = f.cleaned_data['title'] new_revision.article.title = f.cleaned_data['title']
new_revision.article.save() new_revision.article.save()
return HttpResponseRedirect(reverse('wiki_view', args=(article.get_url(),))) return HttpResponseRedirect(wiki_article_reverse('wiki_view', article, course))
else: else:
startContents = article.current_revision.contents if (article.current_revision.deleted == 0) else 'Headline\n===\n\n' startContents = article.current_revision.contents if (article.current_revision.deleted == 0) else 'Headline\n===\n\n'
...@@ -200,6 +207,8 @@ def edit(request, course_id, slug, namespace = None): ...@@ -200,6 +207,8 @@ def edit(request, course_id, slug, namespace = None):
'wiki_title' : article.title, 'wiki_title' : article.title,
'wiki_attachments_write': article.can_attach(request.user), 'wiki_attachments_write': article.can_attach(request.user),
'create_article' : False, 'create_article' : False,
'course' : course,
'namespace' : article.namespace.name,
} }
d.update(csrf(request)) d.update(csrf(request))
...@@ -213,7 +222,6 @@ def history(request, course_id, article_path, page=1): ...@@ -213,7 +222,6 @@ def history(request, course_id, article_path, page=1):
perm_err = check_permissions(request, article, check_read=True, check_deleted=False) perm_err = check_permissions(request, article, check_read=True, check_deleted=False)
if perm_err: if perm_err:
print "returned error " , perm_err
return perm_err return perm_err
page_size = 10 page_size = 10
...@@ -254,9 +262,7 @@ def history(request, course_id, article_path, page=1): ...@@ -254,9 +262,7 @@ def history(request, course_id, article_path, page=1):
elif request.POST.__contains__('delete_all') and request.user.is_superuser: elif request.POST.__contains__('delete_all') and request.user.is_superuser:
Revision.objects.filter(article__exact = article, deleted = 0).update(deleted = 2) Revision.objects.filter(article__exact = article, deleted = 0).update(deleted = 2)
elif request.POST.__contains__('lock_article'): elif request.POST.__contains__('lock_article'):
print "changing locked article " , article.locked
article.locked = not article.locked article.locked = not article.locked
print "changed locked article " , article.locked
article.save() article.save()
except Exception as e: except Exception as e:
print str(e) print str(e)
...@@ -289,7 +295,8 @@ def history(request, course_id, article_path, page=1): ...@@ -289,7 +295,8 @@ def history(request, course_id, article_path, page=1):
'wiki_title': article.title, 'wiki_title': article.title,
'wiki_history': history[beginItem:beginItem+page_size], 'wiki_history': history[beginItem:beginItem+page_size],
'show_delete_revision' : request.user.is_superuser, 'show_delete_revision' : request.user.is_superuser,
'course' : course} 'course' : course,
'namespace' : article.namespace.name}
d.update(csrf(request)) d.update(csrf(request))
return render_to_response('simplewiki/simplewiki_history.html', d) return render_to_response('simplewiki/simplewiki_history.html', d)
...@@ -322,21 +329,24 @@ def revision_feed(request, page=1): ...@@ -322,21 +329,24 @@ def revision_feed(request, page=1):
return render_to_response('simplewiki/simplewiki_revision_feed.html', d) return render_to_response('simplewiki/simplewiki_revision_feed.html', d)
def search_articles(request, course_id): def search_articles(request, course_id, namespace=None):
# blampe: We should check for the presence of other popular django search # blampe: We should check for the presence of other popular django search
# apps and use those if possible. Only fall back on this as a last resort. # apps and use those if possible. Only fall back on this as a last resort.
# Adding some context to results (eg where matches were) would also be nice. # Adding some context to results (eg where matches were) would also be nice.
# todo: maybe do some perm checking here # todo: maybe do some perm checking here
if request.method == 'POST': if request.method == 'GET':
querystring = request.POST['value'].strip() querystring = request.GET.get('value', '').strip()
else: else:
querystring = "" querystring = ""
course = get_course(course_id)
results = Article.objects.filter(namespace__exact = course_id)
results = Article.objects.all()
if namespace:
results = results.filter(namespace__name__exact = namespace)
if request.user.is_superuser: if request.user.is_superuser:
results = results.order_by('current_revision__deleted') results = results.order_by('current_revision__deleted')
else: else:
...@@ -355,15 +365,17 @@ def search_articles(request, course_id): ...@@ -355,15 +365,17 @@ def search_articles(request, course_id):
results = results._search(Q(current_revision__contents__icontains = queryword) | \ results = results._search(Q(current_revision__contents__icontains = queryword) | \
Q(title__icontains = queryword)) Q(title__icontains = queryword))
results = results.select_related('current_revision__deleted') results = results.select_related('current_revision__deleted','namespace')
results = sorted(results, key=lambda article: (article.current_revision.deleted, article.get_url().lower()) ) results = sorted(results, key=lambda article: (article.current_revision.deleted, article.get_path().lower()) )
if len(results) == 1 and querystring: if len(results) == 1 and querystring:
return HttpResponseRedirect(reverse('wiki_view', args=(results[0].get_url(),))) return HttpResponseRedirect(wiki_article_reverse('wiki_view', article=results[0], course=course ))
else: else:
d = {'wiki_search_results': results, d = {'wiki_search_results': results,
'wiki_search_query': querystring,} 'wiki_search_query': querystring,
'course' : course,
'namespace' : namespace}
d.update(csrf(request)) d.update(csrf(request))
return render_to_response('simplewiki/simplewiki_searchresults.html', d) return render_to_response('simplewiki/simplewiki_searchresults.html', d)
...@@ -440,14 +452,16 @@ def remove_related(request, course_id, namespace, slug, related_id): ...@@ -440,14 +452,16 @@ def remove_related(request, course_id, namespace, slug, related_id):
return HttpResponseRedirect(reverse('wiki_view', args=(article.get_url(),))) return HttpResponseRedirect(reverse('wiki_view', args=(article.get_url(),)))
def random_article(request, course_id): def random_article(request, course_id):
course = get_course(course_id)
from random import randint from random import randint
num_arts = Article.objects.count() num_arts = Article.objects.count()
article = Article.objects.all()[randint(0, num_arts-1)] article = Article.objects.all()[randint(0, num_arts-1)]
return HttpResponseRedirect(reverse('wiki_view', args=(article.get_url(),))) return HttpResponseRedirect( wiki_article_reverse('wiki_view', article, course))
def encode_err(request, url, course): def encode_err(request, url, course):
d = {'wiki_err_encode': True, d = {'wiki_err_encode': True,
'course' : course} 'course' : course,
'namespace' : course.wiki_namespace}
d.update(csrf(request)) d.update(csrf(request))
return render_to_response('simplewiki/simplewiki_error.html', d) return render_to_response('simplewiki/simplewiki_error.html', d)
...@@ -455,7 +469,8 @@ def not_found(request, wiki_url, course): ...@@ -455,7 +469,8 @@ def not_found(request, wiki_url, course):
"""Generate a NOT FOUND message for some URL""" """Generate a NOT FOUND message for some URL"""
d = {'wiki_err_notfound': True, d = {'wiki_err_notfound': True,
'wiki_url': wiki_url, 'wiki_url': wiki_url,
'course' : course} 'course' : course,
'namespace' : course.wiki_namespace}
d.update(csrf(request)) d.update(csrf(request))
return render_to_response('simplewiki/simplewiki_error.html', d) return render_to_response('simplewiki/simplewiki_error.html', d)
......
...@@ -3,7 +3,7 @@ var schematic_width = 640; ...@@ -3,7 +3,7 @@ var schematic_width = 640;
$(function(){ $(function(){
$(document).ready(function() { $(document).ready(function() {
$("a[rel*=leanModal]").leanModal(); //$("a[rel*=leanModal]").leanModal(); //TODO: Make this work with the new modal library. Try and integrate this with the "slices"
$("body").append('<div id="circuit_editor" class="leanModal_box" style="z-index: 11000; left: 50%; margin-left: -250px; position: absolute; top: 100px; opacity: 1; "><div align="center">'+ $("body").append('<div id="circuit_editor" class="leanModal_box" style="z-index: 11000; left: 50%; margin-left: -250px; position: absolute; top: 100px; opacity: 1; "><div align="center">'+
'<input class="schematic" height="' + schematic_height + '" width="' + schematic_width + '" id="schematic_editor" name="schematic" type="hidden" value=""/>' + '<input class="schematic" height="' + schematic_height + '" width="' + schematic_width + '" id="schematic_editor" name="schematic" type="hidden" value=""/>' +
...@@ -88,15 +88,20 @@ CodeMirror.defineMode("mitx_markdown", function(cmCfg, modeCfg) { ...@@ -88,15 +88,20 @@ CodeMirror.defineMode("mitx_markdown", function(cmCfg, modeCfg) {
return {width: schematic_width, height:schematic_height}; return {width: schematic_width, height:schematic_height};
}, },
callback: function(node, line) { callback: function(node, line) {
update_schematics(); try {
var schmInput = node.firstChild.firstChild; update_schematics();
schmInput.codeMirrorLine = line; var schmInput = node.firstChild.firstChild;
if (schmInput.schematic) { //This is undefined if there was an error making the schematic schmInput.codeMirrorLine = line;
schmInput.schematic.canvas.style.display = "block"; //Otherwise, it gets line height and is a weird size if (schmInput.schematic) { //This is undefined if there was an error making the schematic
schmInput.schematic.always_draw_grid = true; schmInput.schematic.canvas.style.display = "block"; //Otherwise, it gets line height and is a weird size
schmInput.schematic.redraw_background(); schmInput.schematic.always_draw_grid = true;
schmInput.schematic.redraw_background();
}
$(node.firstChild).leanModal();
} catch (err) {
console.log("Error in mitx_markdown callback: " + err);
} }
$(node.firstChild).leanModal();
} }
}; };
......
...@@ -5,14 +5,11 @@ ...@@ -5,14 +5,11 @@
<%! <%!
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from simplewiki.views import wiki_article_reverse, wiki_namespace_reverse
%> %>
## A convenience function that calls reverse with the kwargs course_id, namespace, and slug
<%def name="wiki_reverse(wiki_page, args=[], kwargs={})">
${reverse(wiki_page, kwargs=dict({'course_id': course.id, 'article_path' : wiki_article.get_path()}, **kwargs), args=args) }
</%def>
<%block name="headextra"> <%block name="headextra">
<script type="text/javascript" src="${static.url('js/simplewiki/bsn.AutoSuggest_c_2.0.js')}"></script> <script type="text/javascript" src="${static.url('js/simplewiki-AutoSuggest_c_2.0.js')}"></script>
<script type="text/javascript"> <script type="text/javascript">
function set_related_article_id(s) { function set_related_article_id(s) {
...@@ -23,7 +20,7 @@ ...@@ -23,7 +20,7 @@
var x = window.onload; var x = window.onload;
window.onload = function(){ window.onload = function(){
var options = { var options = {
script: "${ wiki_reverse('search_related')}/?self=${wiki_article.pk}&", script: "${ wiki_article_reverse('search_related', wiki_article, course)}/?self=${wiki_article.pk}&",
json: true, json: true,
varname: "query", varname: "query",
maxresults: 35, maxresults: 35,
...@@ -83,7 +80,7 @@ ...@@ -83,7 +80,7 @@
<ul class="action"> <ul class="action">
<li> <li>
<h3> <h3>
<a href="${reverse("wiki_list_articles", args=[course.id])}">All Articles</a> <a href="${wiki_namespace_reverse("wiki_list_articles", namespace, course)}">All Articles</a>
</h3> </h3>
</li> </li>
...@@ -93,32 +90,26 @@ ...@@ -93,32 +90,26 @@
</h3> </h3>
<div id="wiki_create_form"> <div id="wiki_create_form">
<form method="GET" action="${reverse("wiki_create", args=[course.id])}"> <%
baseURL = reverse("wiki_create", kwargs={"course_id" : course.id, "article_path" : course.wiki_namespace + "/" })
%>
<form method="GET" onsubmit="this.action='${baseURL}' + this.wiki_article_name.value.replace(/([^a-zA-Z0-9\-])/g, '');">
<div> <div>
<label for="id_wiki_article_name">Title of article</label> <label for="id_wiki_article_name">Title of article</label>
<input type="text" name="wiki_article_name" id="id_wiki_article_name" /><br/> <input type="text" name="wiki_article_name" id="id_wiki_article_name" /><br/>
<!-- <label for="id_wiki_article_is_child">Create as a child of current article</label> -->
<!-- <input type="checkbox" name="wiki_article_is_child" id="id_wiki_artcile_is_child" disabled="true" ${ 'checked="checked"' if wiki_article is not UNDEFINED else ""}> -->
</div> </div>
<ul> <ul>
<li> <li>
<input type="submit" class="button" value="Create" style="display: inline-block; margin-right: 2px; font-weight: bold;" /> <input type="submit" class="button" value="Create" style="display: inline-block; margin-right: 2px; font-weight: bold;" />
</li> </li>
</ul> </ul>
</form> </form>
</div> </div>
</li> </li>
<li class="search"> <li class="search">
<form method="POST" action='${reverse("wiki_search_articles", args=[course.id])}'> <form method="GET" action='${wiki_namespace_reverse("wiki_search_articles", namespace, course)}'>
<label class="wiki_box_title">Search</label> <label class="wiki_box_title">Search</label>
<div style="display:none">
<input type="hidden" name="csrfmiddlewaretoken" value="${csrf_token}"/>
</div>
<input type="text" placeholder="Search" name="value" id="wiki_search_input" style="width: 71%" value="${wiki_search_query if wiki_search_query is not UNDEFINED else '' |h}"/> <input type="text" placeholder="Search" name="value" id="wiki_search_input" style="width: 71%" value="${wiki_search_query if wiki_search_query is not UNDEFINED else '' |h}"/>
<input type="submit" id="wiki_search_input_submit" value="Go!" style="width: 20%" /> <input type="submit" id="wiki_search_input_submit" value="Go!" style="width: 20%" />
</form> </form>
...@@ -141,15 +132,15 @@ ...@@ -141,15 +132,15 @@
<ul> <ul>
<li> <li>
<a href="${ wiki_reverse('wiki_view')}" class="view">View</a> <a href="${ wiki_article_reverse('wiki_view', wiki_article, course)}" class="view">View</a>
</li> </li>
<li> <li>
<a href="${ wiki_reverse('wiki_edit')}" class="edit">Edit</a> <a href="${ wiki_article_reverse('wiki_edit', wiki_article, course)}" class="edit">Edit</a>
</li> </li>
<li> <li>
<a href="${ wiki_reverse('wiki_history')}" class="history">History</a> <a href="${ wiki_article_reverse('wiki_history', wiki_article, course)}" class="history">History</a>
</li> </li>
</ul> </ul>
</header> </header>
......
...@@ -20,11 +20,11 @@ ${"Edit " + wiki_title + " - " if wiki_title is not UNDEFINED else ""}MITx 6.002 ...@@ -20,11 +20,11 @@ ${"Edit " + wiki_title + " - " if wiki_title is not UNDEFINED else ""}MITx 6.002
</%block> </%block>
<%block name="wiki_head"> <%block name="wiki_head">
<script type="text/javascript" src="${ settings.LIB_URL }CodeMirror/codemirror.js"></script> <script type="text/javascript" src="${ settings.LIB_URL }vendor/CodeMirror/codemirror.js"></script>
<link rel="stylesheet" href="${ settings.LIB_URL }CodeMirror/codemirror.css" /> <link rel="stylesheet" href="${ settings.LIB_URL }vendor/CodeMirror/codemirror.css" />
<script type="text/javascript" src="${ settings.LIB_URL }CodeMirror/xml.js"></script> <script type="text/javascript" src="${ settings.LIB_URL }vendor/CodeMirror/xml.js"></script>
<script type="text/javascript" src="${ settings.LIB_URL }CodeMirror/mitx_markdown.js"></script> <script type="text/javascript" src="${ settings.LIB_URL }vendor/CodeMirror/mitx_markdown.js"></script>
<script> <script>
$(function(){ $(function(){
......
...@@ -41,10 +41,13 @@ ${wiki_error} ...@@ -41,10 +41,13 @@ ${wiki_error}
does not exist. Click <a href="${reverse("wiki_create", args=[wiki_url_parent])}">here</a> does not exist. Click <a href="${reverse("wiki_create", args=[wiki_url_parent])}">here</a>
to create it. to create it.
</p> </p>
%else: %elif wiki_err_no_namespace is not UNDEFINED and wiki_err_no_namespace:
%if wiki_err_keyword is not UNDEFINED and wiki_err_keyword: <p>
You must specify a namespace to create an article in.
</p>
%elif wiki_err_bad_namespace is not UNDEFINED and wiki_err_bad_namespace:
<p> <p>
The page you're trying to create <b>${wiki_url}</b> starts with <b>_</b>, which is reserved for internal use. The namespace for this article does not exist. This article cannot be created.
</p> </p>
%elif wiki_err_locked is not UNDEFINED and wiki_err_locked: %elif wiki_err_locked is not UNDEFINED and wiki_err_locked:
<p> <p>
...@@ -87,7 +90,6 @@ ${wiki_error} ...@@ -87,7 +90,6 @@ ${wiki_error}
</p> </p>
%endif %endif
%endif %endif
%endif
</div> </div>
</%block> </%block>
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
<%! <%!
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from simplewiki.views import wiki_article_reverse
%> %>
<%block name="wiki_page_title"> <%block name="wiki_page_title">
...@@ -64,10 +65,10 @@ ${ wiki_article.title } ...@@ -64,10 +65,10 @@ ${ wiki_article.title }
<tr> <tr>
<td colspan="4"> <td colspan="4">
%if wiki_prev_page: %if wiki_prev_page:
<a href="${self.wiki_reverse('wiki_history', kwargs={'page' : wiki_prev_page})}">Previous page</a> <a href="${wiki_article_reverse('wiki_history', wiki_article, course, kwargs={'page' : wiki_prev_page})}">Previous page</a>
%endif %endif
%if wiki_next_page: %if wiki_next_page:
<a href="${self.wiki_reverse('wiki_history', kwargs={'page' : wiki_next_page})}">Next page</a> <a href="${wiki_article_reverse('wiki_history', wiki_article, course, kwargs={'page' : wiki_next_page})}">Next page</a>
%endif %endif
</td> </td>
</tr> </tr>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<%block name="title"><title>Wiki - Search Results - MITx 6.002x</title></%block> <%block name="title"><title>Wiki - Search Results - MITx 6.002x</title></%block>
<%! <%!
from django.core.urlresolvers import reverse from simplewiki.views import wiki_article_reverse
%> %>
<%block name="wiki_page_title"> <%block name="wiki_page_title">
...@@ -23,7 +23,7 @@ Displaying all articles ...@@ -23,7 +23,7 @@ Displaying all articles
<ul class="article-list"> <ul class="article-list">
%for article in wiki_search_results: %for article in wiki_search_results:
<% article_deleted = not article.current_revision.deleted == 0 %> <% article_deleted = not article.current_revision.deleted == 0 %>
<li><h3><a href="${reverse("wiki_view", args=[article.get_url()])}">${article.title} ${'(Deleted)' if article_deleted else ''}</a></h3></li> <li><h3><a href="${wiki_article_reverse("wiki_view", article, course)}">${article.title} ${'(Deleted)' if article_deleted else ''}</a></h3></li>
%endfor %endfor
%if not wiki_search_results: %if not wiki_search_results:
......
...@@ -85,19 +85,21 @@ if settings.COURSEWARE_ENABLED: ...@@ -85,19 +85,21 @@ if settings.COURSEWARE_ENABLED:
) )
# Multicourse wiki # Multicourse wiki
article_slug = r"/(?P<article_path>[a-zA-Z\d_-]+/[a-zA-Z\d_-]*)" namespace_regex = r"[a-zA-Z\d_-]+"
article_slug = r'/(?P<article_path>' + namespace_regex + r'/[a-zA-Z\d_-]*)'
namespace = r'/(?P<namespace>' + namespace_regex + r')'
urlpatterns += ( urlpatterns += (
url(r'^courses/(?P<course_id>[^/]*)/wiki/$', 'simplewiki.views.root_redirect', name='wiki_root'), url(r'^courses/(?P<course_id>[^/]*)/wiki/$', 'simplewiki.views.root_redirect', name='wiki_root'),
url(r'^courses/(?P<course_id>[^/]*)/wiki/view' + article_slug + r'/?$', 'simplewiki.views.view', name='wiki_view'), url(r'^courses/(?P<course_id>[^/]*)/wiki/view' + article_slug + r'/?$', 'simplewiki.views.view', name='wiki_view'),
url(r'^courses/(?P<course_id>[^/]*)/wiki/view_revision/(?P<revision_number>[0-9]+)' + article_slug + r'/?$', 'simplewiki.views.view_revision', name='wiki_view_revision'), url(r'^courses/(?P<course_id>[^/]*)/wiki/view_revision/(?P<revision_number>[0-9]+)' + article_slug + r'/?$', 'simplewiki.views.view_revision', name='wiki_view_revision'),
url(r'^courses/(?P<course_id>[^/]*)/wiki/edit' + article_slug + r'/?$', 'simplewiki.views.edit', name='wiki_edit'), url(r'^courses/(?P<course_id>[^/]*)/wiki/edit' + article_slug + r'/?$', 'simplewiki.views.edit', name='wiki_edit'),
url(r'^courses/(?P<course_id>[^/]*)/wiki/create/?$', 'simplewiki.views.create', name='wiki_create'), url(r'^courses/(?P<course_id>[^/]*)/wiki/create' + article_slug + r'/?$', 'simplewiki.views.create', name='wiki_create'),
url(r'^courses/(?P<course_id>[^/]*)/wiki/history' + article_slug + r'(?:/(?P<page>[0-9]+))?/?$', 'simplewiki.views.history', name='wiki_history'), url(r'^courses/(?P<course_id>[^/]*)/wiki/history' + article_slug + r'(?:/(?P<page>[0-9]+))?/?$', 'simplewiki.views.history', name='wiki_history'),
url(r'^courses/(?P<course_id>[^/]*)/wiki/search_related' + article_slug + r'/?$', 'simplewiki.views.search_add_related', name='search_related'), url(r'^courses/(?P<course_id>[^/]*)/wiki/search_related' + article_slug + r'/?$', 'simplewiki.views.search_add_related', name='search_related'),
url(r'^courses/(?P<course_id>[^/]*)/wiki/random/?$', 'simplewiki.views.random_article', name='wiki_random'), url(r'^courses/(?P<course_id>[^/]*)/wiki/random/?$', 'simplewiki.views.random_article', name='wiki_random'),
url(r'^courses/(?P<course_id>[^/]*)/wiki/revision_feed/([0-9]+)/?$', 'simplewiki.views.revision_feed', name='wiki_revision_feed'), url(r'^courses/(?P<course_id>[^/]*)/wiki/revision_feed/([0-9]+)/?$', 'simplewiki.views.revision_feed', name='wiki_revision_feed'),
url(r'^courses/(?P<course_id>[^/]*)/wiki/search/?$', 'simplewiki.views.search_articles', name='wiki_search_articles'), url(r'^courses/(?P<course_id>[^/]*)/wiki/search' + namespace + r'?/?$', 'simplewiki.views.search_articles', name='wiki_search_articles'),
url(r'^courses/(?P<course_id>[^/]*)/wiki/list/?$', 'simplewiki.views.search_articles', name='wiki_list_articles'), #Just an alias for the search, but you usually don't submit a search term url(r'^courses/(?P<course_id>[^/]*)/wiki/list' + namespace + r'?/?$', 'simplewiki.views.search_articles', name='wiki_list_articles'), #Just an alias for the search, but you usually don't submit a search term
) )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment