10

The Mathematica.SE have some change recently,The image link is forcible to be Https://,but my figure bed give a Http://.This maybe happen on 2017/3/8.When I upload it by

![](http://o8aucf9ny.bkt.clouddn.com/2017-03-13-08-46-08.png)

It give a error information like

enter image description here

And this result a disaster to all my post(whether question or answer) where I have used my figure bed.Such as in my this question,the image just show a link there,like enter image description here

I don't sure the administrator of Mathematica.SE can help me to give a batch adjustment.If cannot,I have to fixed it one by one in future...

8

This is an intentional change. All servers will need to support HTTPS to work with Stack Exchange sites.

See this Q&A on the main Meta site: Network-wide HTTPS: It's time

I am not sure if a batch re-upload to imgur is possible; I shall look for an existing question about this, and if I find nothing I'll inquire.


Apparently to have these images embedded in the post as before each one will need to be manually re-uploaded. Clicking Upload to imgur in the dialog shown is designed to streamline the process.

Another related Meta Q&A: Help us fix broken images! (just showing we're not suffering alone)


I just went through about a dozen of your posts and re-uploaded the images, to confirm that this works. It only takes two clicks per image, Upload to imgur and then in the dialog that appears Add picture and you're done. Not ideal but pretty fast.

This search appears to find the posts that need attention:

  • 1
    Thanks in advance,little sad to have a such experience. – yode Mar 13 '17 at 1:07
  • @yode Sorry I could not have a better answer for you. Is there any chance of clouddn.com supporting HTTPS? – Mr.Wizard Mar 13 '17 at 1:10
  • I have a many many times try to use Imgur API,but I fail to call it.I'm not very good at English to read that offical specification. – yode Mar 13 '17 at 1:14
  • Thanks for your method.I will edit that all post after several days. – yode Mar 13 '17 at 3:42
4

While it is an intentional change, the implementation by Stackexchange has been absolutely appalling, and it is remarkable that such a change has been implemented so poorly, and with so little thought to ensuring backward compatibility.

In particular:

  • All pre-existing posts that used previously perfectly valid external sites to host images no longer display correctly, if that hosting site does not support https for the image page. There are tens of thousands of postings on SE that now display effectively garbage (or make no sense) ... mine included ... because they now show http://blahblah.com/mypic.png ... instead of a picture or an equation.

  • Any reasonably competent programmer implementing a change to host images locally (which is a desirable feature for longevity) could easily script that valid images hosted on sites that do not support https get copied to imgur, and that the page/ question / answer display correctly, as it did before.

  • The implementation by stackexchange shows scant regard for the time and effort devoted by its own users in both asking and answering questions ... as if the past does not matter, and that only the future matters. That attitude frankly beggars belief for a question and answer site on maths and statistics etc ...

I would strongly urge SE to re-examine their implementation of the imgur hosting ... and make it backward compatible so that pre-existing valid posts display correctly.

Just to illustrate the scale of the mess, I have approximately 400 Q and Answers on various SE sites ... and most of them are illegible following this change by SE head office. I don't have the time to work through 400 posts (each with multiple pictures), nor is it my responsibility to fix something I didn't break. It just reflects very poorly on Stack exchange, and I would urge them to fix the mess they have created.

0

I have automated the process, but the code is long.

Register to use the API

To have write permissions at SE one needs to register an APP with SE API to authenticate. Assume you have the keys stored as

apireg = <|"client_id" -> "1224", "key" -> "keystring", 
 "access_token" -> "accesstokenstring"|>

Search for questions

page = 1;
searchoutput = Monitor[
   Module[{more = True, url, partial, full = <|"items" -> {}|>},
    url[p_] := URLBuild[
      {"https://api.stackexchange.com", "2.2", "search", "advanced"}
      , {
       "page" -> p
       , "order" -> "desc"
       , "sort" -> "activity"
       , "user" -> "21532"
       , "url" -> "*.bkt.clouddn.com/*"
       , "site" -> "mathematica"
       , "filter" -> "!-MOiNm40Dv9qWI4dBqjO4HV_ySVbpgQHr"
       , "key" -> Query["key"][apireg]
       }];
    While[more,
     partial = Import[url[page], "RawJSON"];
     more = partial[["has_more"]];
     page += 1;
     full = <|partial, 
       "items" -> Join[full["items"], partial["items"]]|>;
     Pause[1];
     ];
    full
    ], page];

questionsToEdit = Query["items", All, "question_id"]@searchoutput

Get questions, parse URL and upload image

Needs["SETools`SEUploader`"]

ClearAll[GetSEQuestion,GetURLFromSEMarkdown,moveToImgur];

GetSEQuestion[MSEQuestionId_Integer, site_String: "mathematica"] := 
 Import[URLBuild[{"https://api.stackexchange.com", "2.2", "questions",
     ToString[MSEQuestionId]}, {"site" -> site, 
    "filter" -> "!gB5*Xef0PUpwu*lEaRiDqomj.*3J9zCGB5u"}], "RawJSON"]

GetURLFromSEMarkdown[question_String] := 
 StringCases[question, 
  Shortest["![" ~~ ___ ~~ "](http://" ~~ url___ ~~ ")"] :> 
   StringJoin["http://", url]]

moveToImgur[url_String] := 
 moveToImgur[url] = SETools`SEUploader`Private`stackImage[Import[url]]

Edit the question

ClearAll[FixSEQuestion];
FixSEQuestion[id_] := 
 Module[{question, oldbody, questionmarkup, urlList, replaceRule, 
   fixedQuestion, response},
  question = GetSEQuestion[id];
  oldbody = 
   StringReplace[Query["items", 1, "body_markdown"][question], 
    Shortest[StringExpression["&", c__, ";"]] :>  
     ImportString[StringJoin["&", c, ";"], "HTML"]];
  urlList = GetURLFromSEMarkdown[oldbody];
  If[Length[urlList] >= 1,
   replaceRule = 
    Echo@Map[
      Rule[#, StringReplace[moveToImgur[#], 
         "http://" -> "https://"]] &, urlList];
   fixedQuestion = StringReplace[oldbody, replaceRule];
   response = URLRead@HTTPRequest[
      URLBuild[{"https://api.stackexchange.com", "2.2", "questions", 
        ToString[id], "edit"}]
      , <|"Body" ->  {
         "site" -> "mathematica"
         , "filter" -> "!b0OfN_Di4E09vY"
         , "key" -> apireg["key"]
         , "access_token" -> apireg["access_token"]
         , 
         "title" -> 

          StringReplace[Query["items", 1, "title"][question], 
           Shortest[StringExpression["&", c__, ";"]] :>  
            ImportString[StringJoin["&", c, ";"], "HTML"]]
         , 
         "tags" -> 
          StringReplace[
           ToString[Query["items", 1, "tags"][question]], {"{" -> "", 
            "}" -> "", ", " -> ";"}]
         , "body" -> fixedQuestion
         }
       , "Scheme" -> "https"
       , Method -> "POST"
       |>];
   Echo[response[{"StatusCode", "StatusCodeDescription"}]];
   Import[response, {"gzip", "RawJSON"}]
   ]
  ]
  • This still have issues, mainly error detection and it breaks with on some symbols. Any help with that? – rhermans May 12 '17 at 16:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .