r103117 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103116‎ | r103117 | r103118 >
Date:01:39, 15 November 2011
Author:brion
Status:deferred
Tags:
Comment:
stub loading content via API -- this gives regular view and has no frame security
Modified paths:
  • /trunk/mockups/athena/athena.js (modified) (history)

Diff [purge]

Index: trunk/mockups/athena/athena.js
@@ -1,2 +1,79 @@
22 // stub
 3+(function($) {
34
 5+var wiki = {
 6+ base: 'https://$1.wikipedia.org/w/api.php',
 7+ lang: 'en',
 8+
 9+ /**
 10+ * @return string
 11+ */
 12+ apiUrl: function() {
 13+ return wiki.base.replace('$1', wiki.lang);
 14+ },
 15+
 16+ /**
 17+ * @param object params: map of parameters to send to API
 18+ * @return promise
 19+ */
 20+ api: function(params) {
 21+ var ajaxParams = {
 22+ format: 'json'
 23+ };
 24+ $.extend(ajaxParams, params || {});
 25+ return $.ajax({
 26+ url: wiki.apiUrl(),
 27+ data: ajaxParams,
 28+ dataType: 'jsonp'
 29+ });
 30+ }
 31+};
 32+
 33+var ui = {
 34+ startSpinner: function() {
 35+ },
 36+
 37+ stopSpinner: function() {
 38+ },
 39+
 40+ showPage: function(title, content) {
 41+ // @fixme trust issues :)
 42+ console.log('Showing title', title);
 43+ console.log('Showing content', content);
 44+ $('#page-content').html(content);
 45+ }
 46+};
 47+
 48+var app = {
 49+ loadPage: function(title) {
 50+ ui.startSpinner();
 51+ wiki.api({
 52+ action: 'query',
 53+ prop: 'revisions',
 54+ titles: title,
 55+ rvprop: 'timestamp|content',
 56+ rvparse: 1
 57+ }).then(function(data) {
 58+ console.log('page!', data);
 59+ var pageId, page;
 60+ $.each(data.query.pages, function() {
 61+ pageId = this.id;
 62+ page = this;
 63+ });
 64+ var revId, rev;
 65+ $.each(page.revisions, function() {
 66+ revId = this.revid;
 67+ rev = this;
 68+ });
 69+ ui.showPage(page.title, rev['*']);
 70+ ui.stopSpinner();
 71+ });
 72+ },
 73+};
 74+
 75+$(function() {
 76+ app.loadPage('While My Guitar Gently Weeps');
 77+});
 78+
 79+})(jQuery);
 80+

Status & tagging log