This file is indexed.

/usr/share/xul-ext/ubiquity/standard-feeds/social.js is in xul-ext-ubiquity 0.6.4~pre20140729-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
Cu.import("resource://ubiquity/modules/oauth.js");

/* TODO
From Abi:
	I think the ones I most often use would be to check the current status
	of a specific friend (or maybe, the last 3 statuses). The ability to
	check your friends timeline as a whole would also be nice.
*/

// http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-statuses%C2%A0update
// "Statuses over 140 characters will cause a 403 error from the API"
const TWITTER_STATUS_MAXLEN = 140;

// TODO should there also be a "share" overlord verb with
// providers "using twitter", "using digg", etc.

CmdUtils.CreateCommand({
  names: ["twitter", "tweet", "share using twitter"],
  description: (
    "Sets your Twitter status to a message of at most " +
    TWITTER_STATUS_MAXLEN + " characters."),
  help: ("You'll need a <a href=\"http://twitter.com\">Twitter account</a>," +
         " obviously.  If the account isn't already authorized," +
         " you'll be asked for password."),
  icon: "chrome://ubiquity/skin/icons/twitter.ico",
  arguments: [
    {role: "object", label: _("status"), nountype: noun_arb_text},
    {role: "alias",  label: _("user"),   nountype: noun_type_twitter_user}],
  preview: function twitter_preview(previewBlock, args) {
    var statusText = args.object.text;
    if (!statusText) return void this.previewDefault(previewBlock);

    var username = args.alias.text || (Bin.twitterLastLogin() || 0).username;
    var remaining = TWITTER_STATUS_MAXLEN - statusText.length;
    var previewTemplate = (
      _("Updates Twitter status of ${username} to:") +
        "<p><strong class='status'>${status}</strong></p>" +
      _("Characters remaining: ${chars}") +
      (remaining >= 0 ? "" :
       "<br/><strong class='warning'>" +
       _("The last ${truncate} characters will be truncated!",
         {truncate: "<b class='truncate'>" + -remaining + "</b>"}) +
       "</strong>") +
      "<p><small>" +
      _("tip: tweet @mozillaubiquity for help") +
      "</small></p>");

    previewBlock.innerHTML = (
      "<div class='twitter'>" +
      CmdUtils.renderTemplate(previewTemplate, {
        status: Utils.escapeHtml(statusText),
        username: ("<b class='username'>" +
                   (username ? Utils.escapeHtml(username) : "??") + "</b>"),
        chars: "<b class='remaining'>" + remaining + "</b>",
      }) +
      "</div>");
  },
  execute: function twitter_execute({object: {text}, alias}) {
    var me = this;
    if (!text) return me._show(_("requires a status to be entered"));

    var login = alias.data || Bin.twitterLastLogin() || {};
    me._auth(login, function twitter_tweet(username, key, secret) {
      me._post({
        url: "https://api.twitter.com/1.1/statuses/update.json",
        data: {status: text = text.slice(0, TWITTER_STATUS_MAXLEN)},
        dataType: "json",
        success: function twitter_success(res) {
          me._show(
            text, username, text === res.text && function twitter_onclick() {
              Utils.openUrlInBrowser(
                "http://twitter.com/" + username + "/status/" + res.id_str);
            });
        },
        error: function twitter_error(xhr) {
          me._show(_("error - status not updated") + " / " +
                   xhr.status + " " + xhr.statusText,
                   username);
        },
      }, {token: key, tokenSecret: secret});
      Bin.twitterLastLogin({username: username, password: ""});
    });
  },
  _show: function twitter_show(text, user, cb) {
    var title = this.name;
    if (user) title += " \u2013 " + user;
    displayMessage({icon: this.icon, title: title, text: text, onclick: cb});
  },
  _post: function twitter_post(settings, accessor) {
    settings.type = "POST";
    accessor.consumerKey    = "C6h2HUUjmOcqXTtPRYqAVg";
    accessor.consumerSecret = "AYNHPfkpm5lL3uPKXRCuzGFYItA8EOWlrkajyEBOd6s";
    return $.ajax(OAuth.completeAjaxSettings(settings, accessor));
  },
  _auth: function twitter_auth({username, password}, cb) {
    username = username && username.toLowerCase();
    var keys = CmdUtils.loadPassword("TwitterOAuth", username);
    if (keys) return cb.apply(this, [username].concat(keys.split(" ")));

    const APIURL = "https://api.twitter.com/oauth/access_token";
    if (!username || !password) {
      let un = {value: username || ""};
      let pw = {value: password || ""};
      let ok = Utils.PromptService.promptUsernameAndPassword(
        context.chromeWindow, this.name, APIURL, un, pw, null, {});
      if (!ok || !un.value || !pw.value) return;
      username = un.value.toLowerCase();
      password = pw.value;
    }
    var me = this;
    this._post({
      url: APIURL,
      data: {
        x_auth_mode: "client_auth",
        x_auth_username: username,
        x_auth_password: password,
      },
      success: function twitter_xAuth_success(res) {
        var {oauth_token, oauth_token_secret} = Utils.urlToParams(res);
        CmdUtils.savePassword({
          name: "TwitterOAuth",
          username: username,
          password: oauth_token + " " + oauth_token_secret,
        });
        cb.call(me, username, oauth_token, oauth_token_secret);
      },
      error: function twitter_xAuth_error(xhr) {
        var status = xhr.status + " " + xhr.statusText;
        Cu.reportError("Twitter xAuth for " + username + ": " + status);
        me._show(status, username);
        Bin.twitterLastLogin(null);
      },
    }, {});
  },
});

// TODO this should take arguments -- url (defaulting to current page)
// optional commentary, and alias?
CmdUtils.CreateCommand({
  names: ["digg","share using digg"],
  icon: "chrome://ubiquity/skin/icons/digg.ico",
  homepage: "http://www.gialloporpora.netsons.org",
  description: "If not yet submitted, submits the page to Digg. Otherwise, it takes you to the story's Digg page.",
  author: { name: "Sandro Della Giustina", email: "sandrodll@yahoo.it"},
  license: "MPL,GPL",
  execute: function() {
    var win = CmdUtils.getWindow();
    var sel = win.getSelection().toString().slice(0, 375);
    Utils.openUrlInBrowser("http://digg.com/submit" +
                           Utils.paramsToString({
                             phase: "2",
                             url: win.location.href,
                             title: win.document.title,
                             bodytext: sel,
                           }));
  },
  preview: function(pblock) {
    var win = CmdUtils.getWindow();
    var selected_text = win.getSelection() + "";
    var api_url='http://services.digg.com/stories';

    var params = Utils.paramsToString({
      appkey: "http://www.gialloporpora.netsons.org",
      link: win.location.href,
    });

    var html= _('Submit or digg this page. Checking if this page has already been submitted...');
    pblock.innerHTML = html;

    CmdUtils.previewAjax(pblock, {
      type: "GET",
      url: api_url+params,
      error: function(){
        //pblock.innerHTML= 'Digg API seems to be unavailable or the URI is incorrect.<br/>';
      },
      success: function(xml){
        var el = jQuery(xml).find("story");
        var diggs = el.attr("diggs");

        if (diggs == null){
          html = _('Submit this page to Digg');
          if (selected_text.length > 0) {
            html = _("Submit this page to Digg with the description:")+"<br/> <i style='padding:10px;color: #CCC;display:block;'>" + selected_text + "</i>";
            if (selected_text.length > 375){
              html +='<br/> '+_('Description can only be 375 characters. The last <b>${chars}</b> characters will be truncated.',{chars:(selected_text.length - 375)});
            }
          }
        } else {
          html = _('Digg this page. This page already has <b>${diggs}</b> diggs.',{diggs:diggs});
        }
        pblock.innerHTML = html;
      }
    });
  }
});

CmdUtils.CreateCommand({
  names: ["tinyurl"],
  arguments: noun_type_url,
  icon: "chrome://ubiquity/skin/icons/tinyurl.ico",
  description: ("Replaces the selected URL with a " +
                "<a href=\"http://www.tinyurl.com\">TinyURL</a>."),
  preview: function(pblock, {object: {text}}){
    if (!text) {
      pblock.innerHTML = this.description;
      return;
    }
    var me = this;
    pblock.innerHTML = _("Replaces the selected URL with...");
    CmdUtils.previewGet(pblock, this._api(text), function(tinyUrl) {
      if(tinyUrl !== "Error")
        pblock.innerHTML = _("Replaces the selected URL with <b>${tinyurl}</b>.",
                             {tinyurl:me._link(tinyUrl)});
    });
  },
  execute: function(args) {
    var me = this;
    jQuery.get(this._api(args.object.text), function(tinyUrl) {
      CmdUtils.setSelection(me._link(tinyUrl), {text: tinyUrl});
      Utils.clipboard.text = tinyUrl;
    });
  },
  _api: function(url)("http://tinyurl.com/api-create.php?url=" +
                      encodeURIComponent(url)),
  _link: function(url) {
    var eu = Utils.escapeHtml(url);
    return eu.link(eu);
  },
});

/**
 * share-on-delicious - an Ubiquity command for sharing bookmarks on
 * delicious.com
 *
 * l.m.orchard@pobox.com
 * http://decafbad.com/
 * Share and Enjoy!
 *
 * TODO: convert to use xhtml templates
 * TODO: work out how to use suggested tags in the UI
 * TODO: enforce the 1000 character notes limit with a counter
 * TODO: wrap selected text in quotes, typed notes without
 * TODO: implement modifier to support private posting
 * TODO: handle error codes from delicious, not just HTTP itself
 */
var cookie_mgr = (
  Cc["@mozilla.org/cookiemanager;1"].getService(Ci.nsICookieManager));

CmdUtils.CreateCommand({
  names: ["share on delicious", "delicious"],
  icon: "chrome://ubiquity/skin/icons/delicious.ico",
  description: 'Share the current page as a bookmark on delicious.com',
  help: (
    'Select text on the page to use as notes, or enter your own ' +
    'text after the command word.  You can also assign tags to the '+
    'bookmark with the "tagged" modifier, and alter the bookmark ' +
    'default page title with the "entitled" modifier.  Note that ' +
    'you must also already be logged in at delicious.com to use ' +
    'this command.'),
  homepage: 'http://decafbad.com',
  author: {
    name: 'Leslie Michael Orchard',
    email: 'l.m.orchard@pobox.com',
  },
  license: 'MPL/GPL/LGPL',
  arguments: {
    object_notes: noun_arb_text,
    alias_title: noun_arb_text,
    instrument_tags: noun_arb_text,
  },

  /**
   * Command configuration settings.
   */
  _config: {
    // Base URL for the delicious v1 API
    api_base:      'https://api.del.icio.us',
    // Domain and name of the delicious login session cookie.
    cookie_domain: '.delicious.com',
    cookie_name:   '_user',
  },

  /**
   * Present a preview of the bookmark under construction during the course
   * of composing the command.
   */
  preview: function(pblock, args) {
    var bm          = this._extractBookmarkData(args);
    var user_cookie = this._getUserCookie();
    var user_name   = (user_cookie) ? user_cookie.split(' ')[0] : '';

    var ns = { user_name: user_name, bm: bm };

    var tmpl;

    var delicious = ''
      +'<b><a style="color: #3774D0" href="http://delicious.com">delicious.com</a></b>';

    if (!bm.bookmarkable) {
      tmpl = '<p class="error">'
        + _('This URL cannot be shared on ${delicious}.',{delicious:delicious})
          + '</p>';
    } else if (!user_name) {

      // If there's no user name, there's no login, so this command won't work.
      tmpl = '<p class="error">' +
        _("No active user found - log in at ${delicious} to use this command.",
          {delicious:delicious})
          + '</p>';

    } else if (!bm.description) {

      // If there's no title, somehow, then this is an error too.
      tmpl = '<p style="color: #d44">'
        + _("A title is required for bookmarks on ${delicious}",
            {delicious:'<b><a style="color: #3774D0" href="http://delicious.com">delicious.com</a></b>'})
          + '</p>';

    } else {

      delicious = ''
        +'<b><a href="http://delicious.com/${user_name}">delicious.com/${user_name}</a></b>';

      // Attempt to construct a vaguely delicious-esque preview of a bookmark.
      tmpl = [
        '<style type="text/css">',
        '.preview a { color: #3774D0 }',
        '.del-bookmark { font: 12px arial; color: #ddd; background: #eee; line-height: 1.25em }',
        '.del-bookmark a.title { color: #1259C7 }',
        '.del-bookmark .full-url { color: #396C9B; font-size: 12px; display: block; padding: 0.25em 0 }',
        '.del-bookmark .notes { color: #4D4D4D }',
        '.del-bookmark .tags { color: #787878; padding-top: 0.25em; text-align: right }',
        '</style>',
        '<div class="preview">',
        '<p>'+_('Share a bookmark at ${delicious}:', {delicious:delicious})+'</p>',
        '<div class="del-bookmark">',
        '<div style="padding: 1em;">',
        '<a class="title" href="${bm.url}">${bm.description}</a>',
        '<a class="full-url" href="${bm.url}">${bm.url}</a>',
        bm.extended ?
        '<div class="notes">${bm.extended}</div>' : '',
        bm.tags ?
        '<div class="tags"><span>tags:</span> ${bm.tags}</div>' : '',
        '</div>',
        '</div>'
        ].join("\n");

    }

    pblock.innerHTML = CmdUtils.renderTemplate(tmpl, ns);
  },

  /**
   * Attempt to use the delicious v1 API to post a bookmark using the
   * command input
   */
  execute: function(args) {
    var bm          = this._extractBookmarkData(args);
    var user_cookie = this._getUserCookie();
    var user_name   = (user_cookie) ? user_cookie.split(' ')[0] : '';

    if (!bm.bookmarkable) {
      displayMessage(_('This URL cannot be shared on delicious.'));
      return false;
    }

    if (!user_name) {
      // If there's no user name, there's no login, so this command won't work.
      displayMessage(_('No active user found - log in at delicious.com to use this command.'));
      return false;
    }

    if (!bm.description) {
      // If there's no title, somehow, then this is an error too.
      displayMessage(_("A title is required for bookmarks at delicious.com"));
      return false;
    }

    var path = '/v1/posts/add';
    var url  = this._config.api_base + path;
    var req = XMLHttpRequest();

    req.open('POST', url, true);

    var _this = this;
    var onload, onerror;

    req.onload = onload = function(ev) {
      displayMessage(
        _('Bookmark "${description}" shared at delicious.com/${user_name}',
          {description: bm.description, user_name: user_name}));
    }

    req.onerror = onerror = function(ev) {
      // TODO: more informative reporting on errors
      displayMessage(_('ERROR: Bookmark "${description}" NOT shared on delicious.com/${user_name}',{description:bm.description,user_name:user_name}));
    }

    // TODO: implement timeout here, in case requests take too long.

    req.setRequestHeader('Authorization', 'Basic Y29va2llOmNvb2tpZQ=='); // btoa('cookie:cookie')
    req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

    var mediator = Components.classes["@mozilla.org/appshell/window-mediator;1"].
      getService(Components.interfaces.nsIWindowMediator);
    var win = mediator.getMostRecentWindow(null);
    var user_agent = win.navigator.userAgent + ";Ubiquity-share-on-delicious";

    req.setRequestHeader("User-Agent", user_agent);
    req.send($.param(bm));
  },

  /**
   * Given input data and modifiers, attempt to assemble data necessary to
   * post a bookmark.
   */
  _checkBookmarkable: new RegExp('^https?://'),
  _extractBookmarkData: function(args) {
    return {
      _user:
      this._getUserCookie(),
      url:
      context.focusedWindow.location,
      bookmarkable:
      this._checkBookmarkable.test(context.focusedWindow.location),
      description:
      args.alias.text || context.focusedWindow.document.title,
      extended:
      args.object.text ? '"' + args.object.text + '"' : '',
      tags:
      args.instrument.text
      };
  },

  /**
   * Dig up the Delicious login session cookie.
   */
  _getUserCookie: function() {
    var iter = cookie_mgr.enumerator;
    while (iter.hasMoreElements()) {
      var cookie = iter.getNext();
      if (cookie instanceof Ci.nsICookie &&
          cookie.host.indexOf(this._config.cookie_domain) !== -1 &&
          cookie.name === this._config.cookie_name) {
        return decodeURIComponent(cookie.value);
      }
    }
  },
});