Advertisement
Guest User

CPWN Archives $news function update

a guest
Dec 26th, 2014
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $news.fn.create = function (a) {
  2.     var date = new Date(a.path.match(/(\d+)(\d\d)(\d\d)$/).splice(1).join("/"));
  3.         pageContent = encodeURIComponent('{{Newspaper2\n|issue= ' + a.issue + '\n|date= ' + (["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"][date.getMonth()] + " " + date.getDate() + ", " + date.getFullYear()) + '\n|ask= ' + "" + '\n}}');
  4.     $.ajax({
  5.         url: mw.util.wikiScript("api") + "?action=edit&titles=Club_Penguin_Times/" + a.issue + "&text=" + encodeURIComponent(pageContent) + "&summary=" + encodeURIComponent("test") + "&token=" + encodeURIComponent(mw.user.tokens.get("editToken")),
  6.         type: "POST",
  7.         success: function(data) {
  8.             console.log("Success!");
  9.         },
  10.         error: function(data) {
  11.             window.Q_publisherror = data;
  12.             if (data.status == 756) {
  13.                 console.error("The request was too long. Please copy the content in the textarea and use it for creating the page");
  14.             } else {
  15.                 console.error("An error occured while attempting to publish the page");
  16.             }
  17.         }
  18.     }).always(function() {
  19.         $("#newsupload-result").val(pageContent);
  20.         $("#newsupload dt").html('<a href="/wiki/Club_Penguin_Times/' + a.issue + '">' + a.issue + '</a>');
  21.     });
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement