Monday, October 19, 2009

g-osc-user-cont (Ubiquity command)

function open_usercontributionspage(arguments) {

if(arguments.object.text!="")
Utils.focusUrlInBrowser("http://se.bigbuddysociety.net/wiki/index.php?title=Special:Contributions/"
+ arguments.object.text);
else
Utils.focusUrlInBrowser("http://se.bigbuddysociety.net/wiki/index.php?title=Main_Page");
}

CmdUtils.CreateCommand({

names: ["g-osc-user-cont"],
author: { name: "Mostafa ELkhouly", email: "mostafa-khouly@hotmail.com"},
description: "Go to the G-OSC User contributions page.",
arguments: [{role: "object", nountype: noun_arb_text,label: "Username"}],
execute: open_usercontributionspage,
icon: "http://se.bigbuddysociety.net/wiki/images/c/c4/GOSC-Logo-135.png",
preview: function (pblock){
pblock.innerHTML = "Go to the G-OSC User contributions page\t"
+'<http://se.bigbuddysociety.net/wiki/images/c/c4/GOSC-Logo-135.png/>';}
})


This is the code of my first Ubiquity command, it is called "g-osc-user-cont", it is a very simple command it takes a username as an argument, and opens the contribution page of this username (if it is a valid username), but if the command is used without an argument it just opens the g-osc home page in a new tab. The command also uses the g-osc logo as an icon and it also appears in the preview window along with some text.

Now I am going to talk about the implementation of the command, I think that the action of "names", "author", "description" and "icon" are quite obvious, so I am going to start with the "preview" which contains a function that adds some text and g-osc logo to the preview page of the command. The second part is the "execute" which calls the "open_usercontributionspage" with the arguments if any, this function checks the argument and extracts the text from it, if the text is empty it just goes to the g-osc home page, in any other case it uses the text of the argument to open the contributions page for the given text (even if it isn't a valid username), and that's it.

One more thing I would like to thank Abdallah Elgindy for his blog post about using Utils.focusUrlInBrowser() instead of Utils.openUrlInBrowser().

1 comment:

  1. Good work Khouly,
    I test it and it works well

    ReplyDelete