Ejemplo n.º 1
0
  /**
   * Constructs a HttpURLConnection to upload a block. Sign with page length for update, or 0 for
   * clear.
   *
   * @param uri The absolute URI to the blob
   * @param timeout The server timeout interval
   * @param properties the page properties
   * @param accessCondition An {@link AccessCondition} object that represents the access conditions
   *     for the blob.
   * @param blobOptions the options to use for the request.
   * @param opContext a tracking object for the request
   * @return a HttpURLConnection to use to perform the operation.
   * @throws IOException if there is an error opening the connection
   * @throws URISyntaxException if the resource URI is invalid
   * @throws StorageException an exception representing any error which occurred during the
   *     operation.
   * @throws IllegalArgumentException
   */
  public static HttpURLConnection putPage(
      final URI uri,
      final int timeout,
      final PageProperties properties,
      final AccessCondition accessCondition,
      final BlobRequestOptions blobOptions,
      final OperationContext opContext)
      throws IOException, URISyntaxException, StorageException {
    final UriQueryBuilder builder = new UriQueryBuilder();
    builder.add("comp", "page");

    final HttpURLConnection request =
        BlobRequest.createURLConnection(uri, timeout, builder, blobOptions, opContext);

    request.setDoOutput(true);
    request.setRequestMethod("PUT");

    if (properties.getPageOperation() == PageOperationType.CLEAR) {
      request.setFixedLengthStreamingMode(0);
    }

    // Page write is either update or clean; required
    request.setRequestProperty(BlobConstants.PAGE_WRITE, properties.getPageOperation().toString());
    request.setRequestProperty(
        Constants.HeaderConstants.STORAGE_RANGE_HEADER, properties.getRange().toString());

    if (accessCondition != null) {
      accessCondition.applyConditionToRequest(request);
    }

    return request;
  }
  private void displayLeadSection() {
    try {
      final Page page = model.getPage();
      final PageProperties pageProperties = page.getPageProperties();

      JSONObject marginPayload = new JSONObject();
      int margin =
          DimenUtil.roundedPxToDp(activity.getResources().getDimension(R.dimen.content_margin));
      marginPayload.put("marginLeft", margin);
      marginPayload.put("marginRight", margin);
      bridge.sendMessage("setMargins", marginPayload);

      JSONObject leadSectionPayload = new JSONObject();
      leadSectionPayload.put("sequence", pageSequenceNum);
      leadSectionPayload.put("title", page.getDisplayTitle());
      leadSectionPayload.put("section", page.getSections().get(0).toJSON());
      leadSectionPayload.put(
          "string_page_similar_titles", activity.getString(R.string.page_similar_titles));
      leadSectionPayload.put("string_page_issues", activity.getString(R.string.button_page_issues));
      leadSectionPayload.put("string_table_infobox", activity.getString(R.string.table_infobox));
      leadSectionPayload.put("string_table_other", activity.getString(R.string.table_other));
      leadSectionPayload.put("string_table_close", activity.getString(R.string.table_close));
      leadSectionPayload.put("string_expand_refs", activity.getString(R.string.expand_refs));
      leadSectionPayload.put("isBeta", app.getReleaseType() != WikipediaApp.RELEASE_PROD);
      leadSectionPayload.put("siteLanguage", model.getTitle().getSite().getLanguageCode());
      leadSectionPayload.put("isMainPage", page.isMainPage());
      leadSectionPayload.put("apiLevel", Build.VERSION.SDK_INT);
      bridge.sendMessage("displayLeadSection", leadSectionPayload);
      Log.d(TAG, "Sent message 'displayLeadSection' for page: " + page.getDisplayTitle());

      Utils.setupDirectionality(
          model.getTitle().getSite().getLanguageCode(), Locale.getDefault().getLanguage(), bridge);

      // Hide edit pencils if anon editing is disabled by remote killswitch or if this is a file
      // page
      JSONObject miscPayload = new JSONObject();
      boolean isAnonEditingDisabled =
          app.getRemoteConfig().getConfig().optBoolean("disableAnonEditing", false)
              && !app.getUserInfoStorage().isLoggedIn();
      miscPayload.put("noedit", (isAnonEditingDisabled || page.isFilePage() || page.isMainPage()));
      miscPayload.put("protect", !pageProperties.canEdit());
      bridge.sendMessage("setPageProtected", miscPayload);
    } catch (JSONException e) {
      // This should never happen
      throw new RuntimeException(e);
    }

    if (webView.getVisibility() != View.VISIBLE) {
      webView.setVisibility(View.VISIBLE);
    }

    refreshView.setRefreshing(false);
    activity.updateProgressBar(true, true, 0);
  }