Esempio n. 1
0
 @Override
 public void Func_evaluate(Bry_bfr bfr, Xop_ctx ctx, Xot_invk caller, Xot_invk self, byte[] src) {
   byte[] user_name = Eval_argx(ctx, src, caller, self);
   byte[] when_m = Bry_.Empty, when_f = Bry_.Empty, when_u = Bry_.Empty;
   int self_args_len = self.Args_len();
   if (self_args_len == 0) return; // per MW: EX: {{gender:name}} -> ""
   else {
     if (self_args_len > 0) {
       when_m =
           when_u =
               Pf_func_.Eval_arg_or_empty(
                   ctx, src, caller, self, self_args_len, 0); // default when_u to when_m
       if (self_args_len > 1) {
         when_f = Pf_func_.Eval_arg_or_empty(ctx, src, caller, self, self_args_len, 1);
         if (self_args_len > 2) {
           when_u = Pf_func_.Eval_arg_or_empty(ctx, src, caller, self, self_args_len, 2);
         }
       }
     }
   }
   if (self_args_len == 1) {
     bfr.Add(when_m);
     return;
   } // per MW: EX: {{gender:name|a}} -> "a"
   int gender = Get_gender(ctx.App().User(), user_name);
   Xol_lang_itm lang = ctx.Page().Lang();
   bfr.Add(lang.Gender().Gender_eval(gender, when_m, when_f, when_u));
 }
Esempio n. 2
0
 public void Xtn_parse(
     Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {
   Xox_xnde_.Xatr__set(wiki, this, xatrs_hash, src, xnde);
   this.html =
       Xop_parser_.Parse_text_to_html(
           wiki,
           ctx,
           ctx.Page(),
           ctx.Page().Ttl(),
           Bry_.Mid(src, xnde.Tag_open_end(), xnde.Tag_close_bgn()),
           false);
   Indicator_html_bldr html_bldr = ctx.Page().Html_data().Indicators();
   if (this.name != null)
     html_bldr.Add(this); // NOTE: must do null-check b/c Add will use Name as key for hashtable
 }
Esempio n. 3
0
 public static boolean Eq(
     Xop_ctx ctx,
     byte[] lhs,
     byte[]
         rhs) { // PATCH.PHP: php allows "003" == "3.0"; ASSUME: numbers are either int or int-like
   // decimal; long, float, decimal not supported
   int lhs_len = lhs.length, rhs_len = rhs.length;
   boolean rv = true;
   if (lhs_len == rhs_len) {
     for (int i = 0; i < lhs_len; i++) {
       if (lhs[i] != rhs[i]) {
         rv = false;
         break;
       }
     }
     if (rv) return true;
   } else if (lhs_len == 0
       || rhs_len == 0) // one side is empty String and the other side is String; return false;
   return false;
   Gfo_number_parser lhs_parser = ctx.Tmp_mgr().Pfunc_num_parser_0();
   Gfo_number_parser rhs_parser = ctx.Tmp_mgr().Pfunc_num_parser_1();
   lhs_parser.Parse(lhs, 0, lhs_len);
   if (lhs_parser.Has_err()) return false;
   rhs_parser.Parse(rhs, 0, rhs_len);
   if (rhs_parser.Has_err()) return false;
   return lhs_parser.Has_frac() || rhs_parser.Has_frac()
       ? lhs_parser.Rv_as_dec().Eq(rhs_parser.Rv_as_dec())
       : lhs_parser.Rv_as_int() == rhs_parser.Rv_as_int();
 }
Esempio n. 4
0
 private Xop_list_tkn PopTil(
     Xop_ctx ctx,
     Xop_tkn_mkr tkn_mkr,
     Xop_root_tkn root,
     byte[] src,
     int src_len,
     int bgn_pos,
     int cur_pos,
     byte subLast) {
   int acs_pos = ctx.Stack_idx_find_but_stop_at_tbl(Xop_tkn_itm_.Tid_list);
   if (acs_pos == -1) return null;
   Xop_list_tkn rv =
       (Xop_list_tkn)
           ctx.Stack_pop_til(root, src, acs_pos, false, bgn_pos, cur_pos, Xop_tkn_itm_.Tid_list);
   MakeTkn_end(ctx, tkn_mkr, root, src, src_len, bgn_pos, cur_pos, rv, subLast);
   return rv;
 }
Esempio n. 5
0
 public void Page_bgn(Xop_ctx ctx, Xop_root_tkn root) {
   this.Clear();
   para_enabled =
       enabled
           && ctx.Parse_tid()
               == Xop_parser_.Parse_tid_page_wiki; // only enable for wikitext (not for template)
   if (para_enabled) Prv_para_new(ctx, root, -1, 0); // create <para> at bos
 }
 public void Write_hdump(Bry_bfr bfr, Xop_ctx ctx, Xoh_wtr_ctx hctx, Xoae_page wpg) {
   if (wpg.Html_data().Xtn_pgbnr() != null) {
     ctx.Wiki()
         .Xtn_mgr()
         .Xtn_pgbnr()
         .Write_html(wpg, ctx, hctx)
         .Bfr_arg__add(bfr); // if pgbnr exists, write to top of html
   }
   this.Write_body(bfr, ctx, hctx, wpg);
 }
 public int Make_tkn(
     Xop_ctx ctx,
     Xop_tkn_mkr tkn_mkr,
     Xop_root_tkn root,
     byte[] src,
     int src_len,
     int bgn_pos,
     int cur_pos) {
   Xop_tkn_itm tkn = tkn_mkr.Brack_bgn(bgn_pos, cur_pos);
   ctx.Subs_add_and_stack(root, tkn);
   return cur_pos;
 }
Esempio n. 8
0
 public void Process_lnki_category(
     Xop_ctx ctx,
     Xop_root_tkn root,
     byte[] src,
     int pos,
     int src_len) { // REF.MW:Parser.php|replaceInternalLinks2|Strip the whitespace Category links
   // produce;
   if (!para_enabled) return;
   int subs_len = root.Subs_len();
   for (int i = subs_len - 2;
       i > -1;
       i--) { // -2: -1 b/c subs_len is invalid; -1 to skip current lnki
     Xop_tkn_itm sub_tkn = root.Subs_get(i);
     switch (sub_tkn.Tkn_tid()) {
       case Xop_tkn_itm_
           .Tid_para: // nl found; note this means that BOL -> [[Category:]] is all ws;
         if (prv_ws_bgn > 0) { // line begins with ws a
           if (sub_tkn.Src_bgn()
               != 0) // do not ignore BOS para; needed b/c it is often <p>; needed for test;
           sub_tkn.Ignore_y_(); // ignore nl (pretty-printing only)
           prv_ws_bgn = 0; // remove ws
           if (ctx.Stack_has(
               Xop_tkn_itm_
                   .Tid_list)) { // HACK: if in list, set prv_nl_pos to EOL; only here for one test
             // to pass
             int nl_at_eol = -1;
             for (int j = pos; j < src_len; j++) { // check if rest of line is ws
               byte b = src[j];
               switch (b) {
                 case Byte_ascii.Space:
                 case Byte_ascii.Tab:
                   break; // ignore space / tab
                 case Byte_ascii.Nl:
                   nl_at_eol = j;
                   j = src_len;
                   break;
                 default: // something else besides ws; stop
                   j = src_len;
                   break;
               }
               if (nl_at_eol != -1) prv_nl_pos = nl_at_eol + 1; // SEE:NOTE_2
             }
           }
         }
         return;
       default: // exit if anything except para / nl in front of [[Category:]]
         i = -1;
         break;
     }
   }
   //			if (para_found)	// BOS exit; just remove prv_ws_bgn
   prv_ws_bgn = 0;
 }
Esempio n. 9
0
 public void MakeTkn_end(
     Xop_ctx ctx,
     Xop_tkn_mkr tkn_mkr,
     Xop_root_tkn root,
     byte[] src,
     int src_len,
     int bgn_pos,
     int cur_pos,
     Xop_list_tkn bgn,
     byte sub_last) {
   // boolean empty_ignored = ctx.Empty_ignored(); // commented; see below; DATE:2014-06-24
   Xop_tkn_itm end_tkn =
       tkn_mkr.List_end(bgn_pos, bgn.List_itmTyp())
           .List_path_(bgn.List_path())
           .List_uid_(listId)
           .List_sub_last_(sub_last);
   ctx.Subs_add(root, end_tkn);
   // if (empty_ignored) ctx.Empty_ignore(root, bgn.Tkn_sub_idx());	// commented; code was
   // incorrectly deactivating "*a" when "<li>" encountered; PAGE:en.w:Bristol_Bullfinch
   // DATE:2014-06-24
   ctx.Para().Process_block__bgn_n__end_y(Xop_xnde_tag_.Tag__ul);
 }
Esempio n. 10
0
 public byte[] Format_durations(Xop_ctx ctx, long seconds, Xol_duration_itm[] ary) {
   if (interval_msgs == null) Format_durations_init();
   Xol_interval_itm[] intervals = Get_duration_intervals(seconds, ary);
   int intervals_len = intervals.length;
   byte[][] msgs_ary = new byte[intervals_len][];
   for (int i = 0; i < intervals_len; i++) {
     Xol_interval_itm interval = intervals[i];
     Xol_msg_itm msg_itm = interval_msgs[interval.Duration_itm().Tid()];
     byte[] msg_bry = msg_itm.Fmt(tmp_bfr, tmp_fmtr, interval.Val());
     msg_bry = ctx.Wiki().Parser_mgr().Main().Parse_text_to_html(ctx, msg_bry);
     msgs_ary[i] = msg_bry;
   }
   return List_to_str(msgs_ary);
 }
Esempio n. 11
0
 public void AutoClose(
     Xop_ctx ctx,
     Xop_tkn_mkr tkn_mkr,
     Xop_root_tkn root,
     byte[] src,
     int src_len,
     int bgn_pos,
     int cur_pos,
     Xop_tkn_itm tkn) {
   // NOTE: list_tkns can not be explicitly closed, so auto-close will happen for all items
   MakeTkn_end(
       ctx, tkn_mkr, root, src, src_len, bgn_pos, cur_pos, (Xop_list_tkn) tkn, Bool_.Y_byte);
   Reset(listId + 1);
   ctx.Para().Process_block__bgn_n__end_y(Xop_xnde_tag_.Tag__ul);
 }
Esempio n. 12
0
 public void Ident(Xop_ctx ctx, byte[] src, int apos_len, int cur_pos) {
   typ = cmd = lit_apos = dual_cmd = 0;
   switch (apos_len) {
     case Xop_apos_tkn_.Len_ital:
     case Xop_apos_tkn_.Len_bold:
     case Xop_apos_tkn_.Len_dual:
       Ident_props(apos_len);
       break;
     case Xop_apos_tkn_.Len_apos_bold:
       lit_apos = 1;
       Ident_props(Xop_apos_tkn_.Len_bold);
       break;
     default:
       lit_apos = apos_len - Xop_apos_tkn_.Len_dual;
       Ident_props(Xop_apos_tkn_.Len_dual);
       if (lit_apos > 1)
         ctx.Msg_log().Add_itm_none(Xop_apos_log.Multiple_apos, src, cur_pos - apos_len, cur_pos);
       break;
   }
 }
Esempio n. 13
0
  public int MakeTkn_bgn(
      Xop_ctx ctx,
      Xop_tkn_mkr tkn_mkr,
      Xop_root_tkn root,
      byte[] src,
      int src_len,
      int bgn_pos,
      int cur_pos) { // REF.MW: Parser|doBlockLevels
    if (bgn_pos == Xop_parser_.Doc_bgn_bos) bgn_pos = 0; // do not allow -1 pos

    // pop hdr if exists; EX: \n== a ==\n*b; \n* needs to close hdr
    int acsPos = ctx.Stack_idx_typ(Xop_tkn_itm_.Tid_hdr);
    if (acsPos != -1)
      ctx.Stack_pop_til(root, src, acsPos, true, bgn_pos, cur_pos, Xop_tkn_itm_.Tid_list);

    // close apos
    ctx.Apos().End_frame(ctx, root, src, bgn_pos, false);
    byte symByt =
        src[
            cur_pos
                - 1]; // -1 b/c symByt is byte before curByt; EX: \n*a; cur_pos is at a; want to get
    // *
    int prvSymLen = curSymLen;
    cur_pos = SymAry_fill(src, cur_pos, src_len, symByt);
    symByt =
        src[
            cur_pos
                - 1]; // NOTE: get symByt again b/c cur_pos may have changed; EX: "#*"; # may have
    // triggered list, but last symByt should be *
    if (SymAry_fill_overflow) return ctx.Lxr_make_txt_(cur_pos);
    PrvItm_compare();
    ctx.Para()
        .Process_block__bgn__nl_w_symbol(
            ctx,
            root,
            src,
            bgn_pos,
            cur_pos - 1,
            Xop_xnde_tag_
                .Tag__li); // -1 b/c cur_pos includes sym_byte; EX: \n*; pass li; should pass
    // correct tag, but for purposes of para_wkr, <li> doesn't matter
    if (prvSymMatch) {
      PopTil(ctx, tkn_mkr, root, src, src_len, bgn_pos, cur_pos, Bool_.N_byte);
      posBldr.MoveNext();
      prvSymAry = Xop_list_wkr_.MakeSymAry(curSymAry, curSymLen);
      Xop_list_tkn prvItm =
          tkn_mkr.List_bgn(bgn_pos, cur_pos, curSymAry[curSymLen - 1], curSymLen)
              .List_path_(posBldr.XtoIntAry())
              .List_uid_(listId);
      ctx.Subs_add_and_stack(root, prvItm);
      ctx.Empty_ignored_y_();
    } else {
      for (int i = prvSymLen; i > commonSymLen; i--) { // close all discontinued itms: EX: ##\n#\n
        PopTil(ctx, tkn_mkr, root, src, src_len, bgn_pos, cur_pos, Bool_.Y_byte);
        posBldr.MoveUp();
      }
      if (commonSymLen == 0 && prvSymLen != 0) { // nothing in common; reset list
        listId++;
        posBldr.Init();
      }
      if (curSymLen == commonSymLen) { // add another itm if continuing; EX: #\n#\n
        PopTil(ctx, tkn_mkr, root, src, src_len, bgn_pos, cur_pos, Bool_.N_byte);
        if ((prvSymLen - curSymLen)
                > 0 // moving up many levels; do not open new list; just MoveNext; EX: #1\n###3\n##2
            && curSymLen
                != 1) { // do not moveNext if at level 1; this has to do with strange incrementing
          // logic in posBldr at rootLvl
          posBldr.MoveNext();
        } else {
          posBldr.MoveUp();
          posBldr.MoveDown();
        }
        prvSymAry = Xop_list_wkr_.MakeSymAry(curSymAry, curSymLen);
        symByt = src[cur_pos - 1];
        Xop_list_tkn prvItm =
            tkn_mkr.List_bgn(bgn_pos, cur_pos, symByt, curSymLen)
                .List_path_(posBldr.XtoIntAry())
                .List_uid_(listId);
        ctx.Subs_add_and_stack(root, prvItm);
        ctx.Empty_ignored_y_();
      }
      for (int i = commonSymLen; i < curSymLen; i++) { // open new itms; EX: #\n##\n
        posBldr.MoveDown();
        symByt = curSymAry[i];
        prvSymAry = Xop_list_wkr_.MakeSymAry(curSymAry, curSymLen);
        Xop_list_tkn prvItm =
            tkn_mkr.List_bgn(bgn_pos, cur_pos, symByt, i + List_adp_.Base1)
                .List_path_(posBldr.XtoIntAry())
                .List_uid_(listId);
        ctx.Subs_add_and_stack(root, prvItm);
        ctx.Empty_ignored_y_();
      }
    }
    if (allDd
        && cur_pos < src_len - 2
        && src[cur_pos] == '{'
        && src[cur_pos + 1] == '|') // NOTE: if indent && next == {| then invoke table; EX: ":::{|"
    return ctx.Tblw()
          .Make_tkn_bgn(
              ctx,
              tkn_mkr,
              root,
              src,
              src_len,
              cur_pos,
              cur_pos + 2,
              false,
              Xop_tblw_wkr.Tblw_type_tb,
              Xop_tblw_wkr.Called_from_list,
              -1,
              -1); // NOTE: ws_enabled must be set to true; see test for Adinkras; Cato the Elder
    else {
      dd_chk = symByt == Xop_list_tkn_.List_itmTyp_dt;
      return cur_pos;
    }
  }
Esempio n. 14
0
 public void Process_nl(
     Xop_ctx ctx,
     Xop_root_tkn root,
     byte[] src,
     int bgn_pos,
     int cur_pos) { // REF.MW:Parser.php|doBlockLevels
   Dd_clear(ctx);
   if (block_is_bgn_xnde || block_is_end_xnde) {
     para_stack = Para_stack_none; // MW: $paragraphStack = false;
     Prv_para_end(); // MW: $output .= $this->closeParagraph()
     if (block_is_bgn_blockquote
         && !block_is_end_blockquote) // MW: if ( $preOpenMatch and !$preCloseMatch )
     in_blockquote = true; // MW: $this->mInPre = true;
     else in_blockquote = false; // XO: turn off blockquote else following para / nl won't work;
     // w:Snappy_(software); DATE:2014-04-25
     in_block = !block_is_end_xnde; // MW: $inBlockElem = !$closematch;
   } else if (!in_block && !in_blockquote) { // MW: elseif ( !$inBlockElem && !$this->mInPre ) {
     boolean line_is_ws = Line_is_ws(src, bgn_pos);
     if (prv_ws_bgn > 0
         && (cur_mode == Mode_pre
             || !line_is_ws)) { // MW: if ( ' ' == substr( $t, 0, 1 ) and ( $this->mLastSection ===
       // 'pre' || trim( $t ) != '' ) ) {
       if (cur_mode != Mode_pre) { // MW: if ( $this->mLastSection !== 'pre' ) {
         para_stack = Para_stack_none; // MW: $paragraphStack = false;
         prv_para.Space_bgn_(
             prv_ws_bgn
                 - 1); // -1 to ignore 1st "\s" in "\n\s"; note that prv_ws_bgn only includes
         // spaces, so BOS doesn't matter; DATE:2014-04-14
         Prv_para_end();
         Prv_para_bgn(Xop_para_tkn.Tid_pre); // MW: $output .= $this->closeParagraph() . '<pre>';
         cur_mode = Mode_pre; // MW: $this->mLastSection = 'pre';
       } else { // already in pre
         if (line_is_ws) { // line is entirely ws
           int next_char_pos = prv_nl_pos + 2; // "\n\s".length
           if (next_char_pos < src.length // bounds check
               && src[next_char_pos] == Byte_ascii.Nl // is "\n\s\n"; i.e.: "\n" only
           ) {
             ctx.Subs_add(
                 root,
                 ctx.Tkn_mkr()
                     .Bry_raw(
                         bgn_pos,
                         bgn_pos,
                         Byte_ascii
                             .Nl_bry)); // add a "\n" tkn; note that adding a NewLine tkn doesn't
             // work, b/c Xoh_html_wtr has code to remove consecutive
             // \n; PAGE:en.w:Preferred_numbers DATE:2014-06-24
             prv_nl_pos = bgn_pos;
           }
         }
       }
       prv_ws_bgn = 0; // MW: $t = substr( $t, 1 );
     } else {
       if (bgn_pos - prv_nl_pos == 1
           || line_is_ws) { // line is blank ("b" for blank)						MW: if ( trim( $t ) === '' ) {
         if (para_stack
             != Para_stack_none) { // "b1"; stack has "<p>" or "</p><p>"; output "<br/>";	MW: if (
           // $paragraphStack ) {
           Para_stack_end(cur_pos);
           Add_br(ctx, root, bgn_pos); // 														MW: $output .= $paragraphStack . '<br />';
           para_stack = Para_stack_none; // 														MW: $paragraphStack = false;
           cur_mode = Mode_para; // 														MW: $this->mLastSection = 'p';
         } else { // stack is empty
           if (cur_mode
               != Mode_para) { // "b2"; cur is '' or <pre>								MW: if ( $this->mLastSection !==
             // 'p' ) {
             Prv_para_end(); //														MW: $output .= $this->closeParagraph();
             cur_mode = Mode_none; // 														MW: $this->mLastSection = '';
             para_stack = Para_stack_bgn; // put <p> on stack										MW: $paragraphStack = '<p>';
           } else // "b3"; cur is p
           para_stack =
                 Para_stack_mid; // put </p><p> on stack									MW: $paragraphStack = '</p><p>';
         }
       } else { // line has text ("t" for text); NOTE: tkn already added before \n, so must change
         // prv_para; EX: "a\n" -> this code is called for "\n" but "a" already processed
         if (para_stack != Para_stack_none) { // "t1"													MW: if ( $paragraphStack ) {
           Para_stack_end(cur_pos); // 														MW: $output .= $paragraphStack;
           para_stack = Para_stack_none; // 														MW: $paragraphStack = false;
           cur_mode = Mode_para; // 														MW: $this->mLastSection = 'p';
         } else if (cur_mode
             != Mode_para) { // "t2"; cur is '' or <pre>								MW: elseif ( $this->mLastSection
           // !== 'p' ) {
           Prv_para_end();
           Prv_para_bgn(
               Xop_para_tkn
                   .Tid_para); //														MW: $output .= $this->closeParagraph() . '<p>';
           cur_mode = Mode_para; // 														MW: $this->mLastSection = 'p';
         } else {
         } // "t3"
       }
     }
   }
   if (in_blockquote
       && prv_ws_bgn
           > 0) // handle blockquote separate; EX: <blockquote>\n\sa\n</blockquote>; note that "\s"
     // needs to be added literally; MW doesn't have this logic specifically, since it
     // assumes all characters go into $output, whereas XO, sets aside the "\s" in
     // "\n\s" separately
     prv_para.Space_bgn_(prv_ws_bgn);
   prv_ws_bgn =
       0; // nl encountered and processed; always prv_ws_bgn set to 0, else ws from one line will
   // carry over to next
   // in_blockquote = false;
   block_is_bgn_xnde = block_is_end_xnde = false;
   // if ( $preCloseMatch && $this->mInPre )
   //		$this->mInPre = false;
   // prv_ws_bgn = false;
   Prv_para_new(ctx, root, bgn_pos, cur_pos); // add a prv_para placeholder
   if (para_stack == Para_stack_none) // "x1"													MW: if ( $paragraphStack === false ) {
   if (prv_para != null)
       prv_para
           .Nl_bgn_y_(); // add nl; note that "$t" has already been processed;	MW: $output .= $t .
   // "\n";
 }
Esempio n. 15
0
 public void Xtn_parse(
     Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {
   itm.Parse(wiki, ctx, ctx.Page().Ttl().Full_txt_w_ttl_case(), src, xnde);
   Dpl_page_finder.Find_pages(pages, wiki, itm);
   if (itm.Sort_ascending() != Bool_.__byte) pages.Sort_by(new Dpl_page_sorter(itm));
 }
Esempio n. 16
0
 private void Dd_clear(Xop_ctx ctx) {
   ctx.List().Dd_chk_(false);
 }
Esempio n. 17
0
 private void Add_br(Xop_ctx ctx, Xop_root_tkn root, int bgn_pos) {
   ctx.Subs_add(root, ctx.Tkn_mkr().Xnde(bgn_pos, bgn_pos).Tag_(Xop_xnde_tag_.Tag_br));
 }
Esempio n. 18
0
 private void Prv_para_new(Xop_ctx ctx, Xop_root_tkn root, int prv_nl_pos, int para_pos) {
   this.prv_nl_pos = prv_nl_pos;
   prv_para = ctx.Tkn_mkr().Para(para_pos);
   ctx.Subs_add(root, prv_para);
 }
Esempio n. 19
0
 public void Write_page(Bry_bfr rv, Xoae_page page, Xop_ctx ctx) {
   synchronized (thread_lock_1) {
     this.page = page;
     this.wiki = page.Wikie();
     this.app = wiki.Appe();
     ctx.Page_(page); // HACK: must update page for toc_mgr; WHEN: Xoae_page rewrite
     Bry_fmtr fmtr = null;
     if (mgr.Html_capable()) {
       wdata_lang_wtr.Page_(page);
       byte view_mode = page_mode;
       switch (page_mode) {
         case Xopg_page_.Tid_edit:
           fmtr = mgr.Page_edit_fmtr();
           break;
         case Xopg_page_.Tid_html:
           fmtr = mgr.Page_read_fmtr();
           view_mode = Xopg_page_.Tid_read;
           break; // set view_mode to read, so that "read" is highlighted in HTML
         case Xopg_page_.Tid_read:
           fmtr = mgr.Page_read_fmtr();
           // ctx.Page().Redlink_list().Clear();	// not sure if this is the best place to put it,
           // but redlinks (a) must only fire once; (b) must fire before html generation; (c)
           // cannot fire during edit (preview will handle separately); NOTE: probably put in to
           // handle reusable redlink lists; redlink lists are now instantiated per page, so clear
           // is not useful
           break;
       }
       Bry_bfr page_bfr =
           wiki.Utl__bfr_mkr()
               .Get_m001(); // NOTE: get separate page rv to output page; do not reuse tmp_bfr b/c
                            // it will be used inside Fmt_do
       Xoh_wtr_ctx hctx = null;
       if (page_mode == Xopg_page_.Tid_html
           && wiki.App().Api_root().Wiki().Hdump().Html_mode().Tid_is_hdump_save()) {
         hctx = Xoh_wtr_ctx.Hdump;
         Write_body(page_bfr, ctx, hctx, page);
         Write_page_by_tid(
             ctx,
             hctx,
             page_mode,
             rv,
             mgr.Page_html_fmtr(),
             Gfh_utl.Escape_html_as_bry(page_bfr.To_bry_and_clear()));
       } else {
         hctx = Xoh_wtr_ctx.Basic;
         Write_body(page_bfr, ctx, hctx, page);
         Write_page_by_tid(ctx, hctx, view_mode, rv, fmtr, page_bfr.To_bry_and_rls());
         new gplx.xowa.addons.apps.scripts.Xoscript_mgr().Write(rv, wiki, page);
         if (page_mode
             == Xopg_page_
                 .Tid_html) // if html, write page again, but wrap it in html skin this time
         Write_page_by_tid(
               ctx,
               hctx,
               page_mode,
               rv,
               mgr.Page_html_fmtr(),
               Gfh_utl.Escape_html_as_bry(rv.To_bry_and_clear()));
         wdata_lang_wtr.Page_(null);
       }
     } else Write_body(rv, ctx, Xoh_wtr_ctx.Basic, page);
     this.page = null;
   }
 }
Esempio n. 20
0
 public void Xtn_write(
     Bry_bfr bfr,
     Xoae_app app,
     Xop_ctx ctx,
     Xoh_html_wtr html_wtr,
     Xoh_wtr_ctx hctx,
     Xoae_page wpg,
     Xop_xnde_tkn xnde,
     byte[] src) {
   Xowe_wiki wiki = ctx.Wiki();
   Dpl_html_data html_mode = Dpl_html_data.new_(Dpl_itm_keys.Key_unordered);
   int itms_len = pages.Count();
   if (itms_len == 0) {
     if (!itm.Suppress_errors()) bfr.Add_str_a7("No pages meet these criteria.");
     return;
   }
   int itms_bgn = 0;
   if (itm.Offset() != Int_.Min_value) {
     itms_bgn = itm.Offset();
   }
   if (itm.Count() != Int_.Min_value && itms_bgn + itm.Count() < itms_len) {
     itms_len = itms_bgn + itm.Count();
   }
   boolean show_ns = itm.Show_ns();
   Bry_bfr tmp_bfr = Bry_bfr_.Get();
   Xop_amp_mgr amp_mgr = wiki.Appe().Parser_amp_mgr();
   try {
     bfr.Add(html_mode.Grp_bgn()).Add_byte_nl();
     for (int i = itms_bgn; i < itms_len; i++) {
       Xowd_page_itm page = (Xowd_page_itm) pages.Get_at(i);
       Xoa_ttl ttl = Xoa_ttl.Parse(wiki, page.Ns_id(), page.Ttl_page_db());
       byte[] ttl_page_txt = show_ns ? ttl.Full_txt_w_ttl_case() : ttl.Page_txt();
       if (ttl_page_txt == null)
         continue; // NOTE: apparently DynamicPageList allows null pages; DATE:2013-07-22
       switch (html_mode.Tid()) {
         case Dpl_html_data.Tid_list_ul:
         case Dpl_html_data.Tid_list_ol:
           bfr.Add(Xoh_consts.Space_2).Add(html_mode.Itm_bgn()).Add(Gfh_bldr_.Bry__a_lhs_w_href);
           bfr.Add_str_a7("/wiki/")
               .Add(Gfo_url_encoder_.Href.Encode(ttl.Full_db()))
               .Add_byte_quote(); // NOTE: Full_db to encode spaces as underscores;
                                  // PAGE:en.q:Wikiquote:Speedy_deletions DATE:2016-01-19
           Gfh_atr_.Add(
               bfr,
               Gfh_atr_.Bry__title,
               Xoh_html_wtr_escaper.Escape(
                   amp_mgr,
                   tmp_bfr,
                   ttl
                       .Full_txt_w_ttl_case())); // NOTE: Full_txt b/c title always includes ns,
                                                 // even if show_ns is off;
                                                 // PAGE:en.b:Wikibooks:WikiProject DATE:2016-01-20
           if (itm.No_follow()) bfr.Add(Bry_nofollow);
           bfr.Add_byte(Byte_ascii.Gt);
           Xoh_html_wtr_escaper.Escape(
               amp_mgr, bfr, ttl_page_txt, 0, ttl_page_txt.length, false, false);
           bfr.Add(Gfh_bldr_.Bry__a_rhs).Add(html_mode.Itm_end()).Add_byte_nl();
           // TODO_OLD:
           // lnki_wtr.Clear().Href_wiki_(ttl).Title_(ttl).Nofollow_().Write_head(bfr).Write_text(bfr).Write_tail(bfr)
           break;
         default:
           break;
       }
     }
     bfr.Add(html_mode.Grp_end()).Add_byte_nl();
   } finally {
     tmp_bfr.Mkr_rls();
   }
 }
Esempio n. 21
0
 public int Process_pre(
     Xop_ctx ctx,
     Xop_tkn_mkr tkn_mkr,
     Xop_root_tkn root,
     byte[] src,
     int src_len,
     int bgn_pos,
     int cur_pos,
     int txt_pos) {
   Dd_clear(ctx);
   Btrie_slim_mgr tblw_ws_trie = ctx.App().Utl_trie_tblw_ws();
   Object o = tblw_ws_trie.Match_bgn(src, txt_pos, src_len);
   if (o != null) { // tblw_ws found
     Xop_tblw_ws_itm ws_itm = (Xop_tblw_ws_itm) o;
     byte tblw_type = ws_itm.Tblw_type();
     switch (tblw_type) {
       case Xop_tblw_ws_itm.Type_nl: // \n\s
         if (cur_mode == Mode_pre) { // already in pre; just process "\n\s"
           ctx.Subs_add(root, tkn_mkr.NewLine(bgn_pos, bgn_pos, Xop_nl_tkn.Tid_char, 1));
           prv_nl_pos =
               bgn_pos; // NOTE: must update prv_nl_pos; PAGE:en.w:Preferred_number DATE:2014-06-24
           return txt_pos;
         }
         break;
       case Xop_tblw_ws_itm.Type_xnde:
         int nxt_pos = tblw_ws_trie.Match_pos();
         if (nxt_pos < src_len) { // bounds check
           switch (src[
               nxt_pos]) { // check that next char is "end" of xnde name; guard against false
               // matches like "<trk" PAGE:de.v:Via_Jutlandica/Gpx DATE:2014-11-29
             case Byte_ascii.Space:
             case Byte_ascii.Nl:
             case Byte_ascii.Tab: // whitespace
             case Byte_ascii.Slash:
             case Byte_ascii.Gt: // end node
             case Byte_ascii.Quote:
             case Byte_ascii.Apos: // quotes
               if (bgn_pos != Xop_parser_.Doc_bgn_bos)
                 ctx.Para().Process_nl(ctx, root, src, bgn_pos, cur_pos);
               return ctx.Xnde().Make_tkn(ctx, tkn_mkr, root, src, src_len, txt_pos, txt_pos + 1);
           }
         }
         break;
       default:
         {
           int tblw_rv =
               ctx.Tblw()
                   .Make_tkn_bgn(
                       ctx,
                       tkn_mkr,
                       root,
                       src,
                       src_len,
                       bgn_pos,
                       txt_pos + ws_itm.Hook_len(),
                       false,
                       tblw_type,
                       Xop_tblw_wkr.Called_from_pre,
                       -1,
                       -1);
           if (tblw_rv
               != -1) // \n\s| is valid tblw tkn and processed; otherwise process pre-code below;
             // EX:w:Wikipedia:WikiProject_History/CategoryExample; DATE:2014-04-14
             return tblw_rv;
           break;
         }
     }
   }
   // NOTE: pre lxr emulates MW for "\n\s" by (1) calling Process nl for "\n"; (2) anticipating
   // next line by setting prv_ws_bgn
   // EX: "\na\n b\n"; note that "\n " is cur
   if (bgn_pos != Xop_parser_.Doc_bgn_bos) // if bos, then don't close 1st para
   Process_nl(
         ctx,
         root,
         src,
         bgn_pos,
         bgn_pos + 1); // note that tkn is \n\s; so, bgn_pos -> bgn_pos + 1 is \n ...
   if (cur_mode == Mode_pre) // in pre_mode
   ctx.Subs_add(
         root,
         tkn_mkr.Space(
             root, cur_pos,
             txt_pos)); // cur_pos to start after \s; do not capture "\s" in "\n\s"; (not sure why
   // not before \s)
   prv_ws_bgn = txt_pos - cur_pos + 1;
   return txt_pos;
 }