From b8b833b753274d11011b802052d307f8de78b5e9 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Tue, 28 Jun 2016 10:15:52 +0100 Subject: [PATCH] moved wiki into module --- .../Features/Wiki/WikiController.coffee | 88 ------------------- services/web/app/coffee/router.coffee | 8 -- services/web/app/views/wiki/page.jade | 68 -------------- 3 files changed, 164 deletions(-) delete mode 100644 services/web/app/coffee/Features/Wiki/WikiController.coffee delete mode 100644 services/web/app/views/wiki/page.jade diff --git a/services/web/app/coffee/Features/Wiki/WikiController.coffee b/services/web/app/coffee/Features/Wiki/WikiController.coffee deleted file mode 100644 index e4f85a6c9f..0000000000 --- a/services/web/app/coffee/Features/Wiki/WikiController.coffee +++ /dev/null @@ -1,88 +0,0 @@ -request = require("request") -settings = require("settings-sharelatex") -logger = require("logger-sharelatex") -ErrorController = require "../Errors/ErrorController" -_ = require("underscore") -AuthenticationController = require("../Authentication/AuthenticationController") -async = require("async") -other_lngs = ["es"] - -module.exports = WikiController = - - - _checkIfLoginIsNeeded: (req, res, next)-> - if settings.apis.wiki.requireLogin - AuthenticationController.requireLogin()(req, res, next) - else - next() - - getPage: (req, res, next) -> - WikiController._checkIfLoginIsNeeded req, res, -> - - page = req.url.replace(/^\/learn/, "").replace(/^\//, "") - if page == "" - page = "Main_Page" - - logger.log page: page, "getting page from wiki" - if _.include(other_lngs, req.lng) - lngPage = "#{page}_#{req.lng}" - else - lngPage = page - jobs = - contents: (cb)-> - WikiController._getPageContent "Contents", cb - pageData: (cb)-> - WikiController._getPageContent lngPage, cb - async.parallel jobs, (error, results)-> - return next(error) if error? - {pageData, contents} = results - if pageData.content?.length > 280 - if _.include(other_lngs, req.lng) - pageData.title = pageData.title.slice(0, pageData.title.length - (req.lng.length+1) ) - - if pageData.title?.toLowerCase()?.indexOf("kb") == 0 - pageData.title = pageData.title.slice(3) - - if pageData.title?.toLowerCase()?.indexOf("errors") == 0 - pageData.title = pageData.title.slice(7) - - WikiController._renderPage(pageData, contents, res) - else - WikiController._getPageContent page, (error, pageData) -> - return next(error) if error? - WikiController._renderPage(pageData, contents, res) - - - - - _getPageContent: (page, callback = (error, data = { content: "", title: "" }) ->) -> - request { - url: "#{settings.apis.wiki.url}/learn-scripts/api.php" - qs: { - page: decodeURI(page) - action: "parse" - format: "json" - } - }, (err, response, data)-> - return callback(err) if err? - try - data = JSON.parse(data) - catch err - logger.err err:err, data:data, "error parsing data from wiki" - result = - content: data?.parse?.text?['*'] - title: data?.parse?.title - callback null, result - - - _renderPage: (page, contents, res)-> - if page.title == "Main Page" - title = "Documentation" - else - title = page.title - - res.render "wiki/page", { - page: page - contents: contents - title: title - } \ No newline at end of file diff --git a/services/web/app/coffee/router.coffee b/services/web/app/coffee/router.coffee index 7fc890ebd7..40792ed540 100644 --- a/services/web/app/coffee/router.coffee +++ b/services/web/app/coffee/router.coffee @@ -30,7 +30,6 @@ PasswordResetRouter = require("./Features/PasswordReset/PasswordResetRouter") StaticPagesRouter = require("./Features/StaticPages/StaticPagesRouter") ChatController = require("./Features/Chat/ChatController") BlogController = require("./Features/Blog/BlogController") -WikiController = require("./Features/Wiki/WikiController") Modules = require "./infrastructure/Modules" RateLimiterMiddlewear = require('./Features/Security/RateLimiterMiddlewear') RealTimeProxyRouter = require('./Features/RealTimeProxy/RealTimeProxyRouter') @@ -204,13 +203,6 @@ module.exports = class Router webRouter.get "/project/:Project_id/messages", AuthorizationMiddlewear.ensureUserCanReadProject, ChatController.getMessages webRouter.post "/project/:Project_id/messages", AuthorizationMiddlewear.ensureUserCanReadProject, ChatController.sendMessage - webRouter.get /learn(\/.*)?/, RateLimiterMiddlewear.rateLimit({ - endpointName: "wiki" - params: [] - maxRequests: 60 - timeInterval: 60 - }), WikiController.getPage - webRouter.post "/project/:Project_id/references/index", AuthorizationMiddlewear.ensureUserCanReadProject, ReferencesController.index webRouter.post "/project/:Project_id/references/indexAll", AuthorizationMiddlewear.ensureUserCanReadProject, ReferencesController.indexAll diff --git a/services/web/app/views/wiki/page.jade b/services/web/app/views/wiki/page.jade deleted file mode 100644 index 6a6bea2202..0000000000 --- a/services/web/app/views/wiki/page.jade +++ /dev/null @@ -1,68 +0,0 @@ -extends ../layout - -block content - .content.content-alt(ng-cloak) - .container.wiki - .row.template-page-header - .col-md-8(ng-cloak) - - .row - .col-xs-3.contents(ng-non-bindable) - | !{contents.content} - - .col-xs-9.page - - if(typeof(settings.algolia) != "undefined" && typeof(settings.algolia.indexes) != "undefined" && typeof(settings.algolia.indexes.wiki) != "undefined") - span(ng-controller="SearchWikiController") - .row - form.project-search.form-horizontal.col-md-9(role="form") - .form-group.has-feedback.has-feedback-left.col-md-12 - input.form-control.col-md-12(type='text', ng-model='searchQueryText', ng-keyup='search()', placeholder="Search help library....") - i.fa.fa-search.form-control-feedback-left - i.fa.fa-times.form-control-feedback( - ng-click="clearSearchText()", - style="cursor: pointer;", - ng-show="searchQueryText.length > 0" - ) - .col-md-3.text-right - a.btn.btn-primary(ng-click="showMissingTemplateModal()") #{translate("suggest_new_doc")} - - .row - .col-md-12(ng-cloak) - a(ng-href='{{hit.url}}',ng-repeat='hit in hits').search-result.card.card-thin - span(ng-bind-html='hit.name') - div.search-result-content(ng-show="hit.content != ''", ng-bind-html='hit.content') - - .card.row-spaced(ng-non-bindable) - .page-header - h1 #{title} - - | !{page.content} - - - - - script(type="text/ng-template", id="missingWikiPageModal") - .modal-header - button.close( - type="button" - data-dismiss="modal" - ng-click="close()" - ) × - h3 #{translate("suggest_new_doc")} - .modal-body.contact-us-modal - span(ng-show="sent == false") - label.desc - | #{translate("email")} (#{translate("optional")}) - .form-group - input.field.text.medium.span8.form-control(ng-model="form.email", ng-init="form.email = '#{getUserEmail()}'", type='email', spellcheck='false', value='', maxlength='255', tabindex='2') - label.desc - | #{translate("suggestion")} - .form-group - textarea.field.text.medium.span8.form-control(ng-model="form.message",type='text', value='', maxlength='255', tabindex='4', onkeyup='') - span(ng-show="sent") - p #{translate("request_sent_thank_you")} - .modal-footer - button.btn.btn-default(ng-click="close()") - span #{translate("dismiss")} - button.btn-success.btn(type='submit', ng-disabled="sending", ng-click="contactUs()") #{translate("contact_us")} -