Ejemplo n.º 1
0
        /// <summary>
        /// "Whats link here" list of item. Only ns0 and without redirect
        /// </summary>
        /// <param name="Item">Q number to use with "Whats link here"</param>
        /// <param name="WD">Object</param>
        /// <param name="Continue">Default="" Used to change page</param>
        /// <param name="Max">Default=5000. Max items to return</param>
        /// <returns>Array. index 0 is continue parameter, index 1 is the list of item separated by "|"</returns>
        public string[] WhatsLinskHereWDQ(string Item, WikimediaAPI WD, string Continue = "", int Max = 5000)
        {
            string PostData = WD.URL() + WD.API() + "?action=query&prop=linkshere&format=xml&lhprop=title&lhnamespace=0&lhlimit=" + Max.ToString() + "&lhcontinue=" + Continue + "&lhshow=!redirect&titles=" + Item;
            string respStr  = WD.PostRequest(PostData, "");

            // Extract of continue number
            int da = -1; int a = -1;

            da = respStr.IndexOf("<linkshere lhcontinue") + 23;
            if (da != 22)
            {
                a        = respStr.IndexOf("\"", da);
                Continue = respStr.Substring(da, a - da);
            }

            //Extract of Qnumber
            string ret = "";

            da      = respStr.IndexOf("<linkshere>") + 11;
            a       = respStr.IndexOf("</linkshere>", da);
            respStr = respStr.Substring(da, a - da);
            string[] list = respStr.Split(new char[] { '>' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (string item in list)
            {
                ret += item.Replace("<lh ns=\"0\" title=\"", "").Replace("\" /", "") + "|";
            }
            ret = ret.Remove(ret.LastIndexOf("|"));

            return(new string[] { Continue, ret });
        }