Beispiel #1
0
 @GET
 @Path("res/{spec:.*}")
 public Response res(@PathParam("spec") String spec, @Context HttpServletRequest req)
     throws Exception {
   Matcher matcher = RES_REGEXP.matcher(spec);
   if (!matcher.matches()) {
     // todo fallback for old site format
     throw new BadRequestException("");
   }
   Integer width = null;
   String widthStr = matcher.group(2);
   Long id = Long.parseLong(matcher.group(3));
   if (widthStr != null) {
     width = Integer.parseInt(widthStr);
   } else {
     int maxWidth = env.xcfg().getInt("mediawiki.max-inline-image-width-px", 0);
     if (maxWidth > 0) {
       MediaResource mres = repository.findMediaResource(id, messages.getLocale(req));
       if (mres == null) {
         throw new NotFoundException("");
       }
       if (CTypeUtils.isImageContentType(mres.getContentType())) {
         if (mres.getImageWidth() > maxWidth) { // restrict maximal image width
           repository.ensureResizedImage(id, maxWidth, null, MediaRepository.RESIZE_SKIP_SMALL);
           width = maxWidth;
         }
       }
     }
   }
   return repository.get(id, req, width, null, true);
 }
Beispiel #2
0
 @GET
 @Path("link/{spec:Page:.*}")
 public Redirect pageLink(@PathParam("spec") String spec, @Context HttpServletRequest req)
     throws Exception {
   String title = spec.substring("Page:".length());
   String link = env.getAppRoot() + "/" + title;
   return new Redirect(link);
 }