Wikimedia function to get all my Templates - mediawiki

I need to get all the pages I have created like Templates in my wikimedia webpage. I have to do this with javascript.
Is this possible?

You can do this with a UserContribs API query, like this:
https://en.wikipedia.org/w/api.php?format=jsonfm&action=query&list=usercontribs&ucuser=Ilmari_Karonen&ucnamespace=10&ucshow=new&continue=
Basically, the parameters you need are:
format=json to get results in JSON format, which is probably what you want for JavaScript. (I've used jsonfm in the example link above to get pretty-printed human readable output.)
action=query to indicate that this is, indeed, a query rather than, say, an edit or a login attempt.
list=usercontribs to indicate that you want a list of a user's contributions (i.e. the stuff you see on the Special:Contributions page).
ucuser=your_username to select which user's contributions you want to see. (The example link above shows mine.)
ucnamespace=10 to select only contributions to templates. (10 is the namespace number for the built-in Template namespace).
ucshow=new to select only contributions that involve creating a new page. (Note that this also includes page moves; I don't see any simple way to filter those out.)
Of course, there are other parameters you may also want to include.
I've also included an empty continue= parameter to indicate that I want to use the new query continuation syntax, and to suppress the warning about it. Obviously, if you actually want to use query continuation, you'll need to implement the client-side part yourself (or use an MW API client that implements it for you). Here's one simplistic way to do that:
function getNewTemplatesForUser( username ) {
var queryURL = 'https://en.wikipedia.org/w/api.php?format=json&action=query&list=usercontribs&ucnamespace=10&ucshow=new';
queryURL += '&ucuser=' + encodeURIComponent( username );
var callback = function( json ) {
// TODO: actually process the results here
if ( json.continue ) {
var continueURL = queryURL;
for ( var attr in json.continue ) {
continueURL += '&' + attr + '=' + encodeURIComponent( json.continue[attr] );
}
doAjaxRequest( continueURL, callback );
}
};
doAjaxRequest( queryURL + '&continue=', callback );
}

Related

How to change language automatically using user browser language Yii2?

A user can change the language manually from the website. But for better user experience, I would like to change it automatically based on the users' browser language. I have a global Controller and can use init() and then redirect.
Please give me tips to do it right.
You should remember the chosen language for a user, if they had selected one previously, I store this in the database, in a user_preference table.
Then you need to intercept the request, it can be done in the application configuration file, using the on beforeRequest property.
If you don't have stored a preference for the current user, or the user is a guest, use the browser language to set the application language.
Configuration file
use app\models\User;
...
'on beforeRequest' => function ($event) {
$user_lang = '';
if (!Yii::$app->user->isGuest) {
// Check if you have stored a language preference for the user
$user_lang = User::findIdentity(Yii::$app->user->id)->getUserPreference('lang');
}
if (!empty($user_lang)) {
// If you have a stored preference for the user, use it
Yii::$app->language = $user_lang;
} else {
// If you don't have a preference, use the browser language
// Get the browser language from the headers
$browser_lang = Yii::$app->request->headers->get('accept-language');
// Alternatively get the headers from the event
// $event->sender->request->headers->get('accept-language')
// Calculate the language you want to provide based on the browser language
$language_code = LanguageHelper::calculatei18nCode($browser_lang);
Yii::$app->language = $language_code;
}
},
...
If you wanted to keep your configuration file clean, you could use filters instead to intercept the request.
Your LanguageHelper::calculatei18nCode($browser_lang) method would try to find a match for the browser language in the available languages, if it didn't find one it could return the closest match, or the default application language.
LanguageHelper
public static function calculatei18nCode ($browser_lang) {
// For example, if you are offering one translation file for french
if (stripos($browser_lang, 'fr')) {
return 'fr';
}
...
return 'en';
}

Phonegap GetJson Strange Output - REST

I am having this situation: ( public api a test website of mine )
$.getJSON("http://ee-tutz.com/entry_api/rest/read_entry/json?auth[username]=test&auth[password]=guest&data[entry_id]=80",function(data){
alert(data); // here i get [obj Obj]
var tweetlistHTML = "";
for(var i = 0; i< data.results.length;i++){
tweetlistHTML +='<li>'+data.results[i].title+ '</li>'
}
var tweetList = $("#tweetlist");
tweetList.html(tweetlistHTML);
});
Is anything worng with the code ?
I want to output some data of out the resulting from the URL ( for example Title )
But it Doesen't Output the titles
Can you try to output the object details using JSON.stringify() method.
This will let you know the returned object properties and values.
e.g: alert the first object details.
alert(JSON.stringify(data.results[0]));
OR the entire objects in the array.
alert(JSON.stringify(data.results));
Also did you try to check the results form the desktop browser whether the URL is returning JSON response.
EDIT1:
I just checked the response of the URL
You need to change the data variable syntax.
data.data[i].title
instead of
data.results[i].title
EDIT2:
Oops. I forgot to change my alert code.
The alert should be.
alert(JSON.stringify(data.data[0]));
or you could alert the whole data.
alert(JSON.stringify(data));
EDIT3:
Your JSON data returned by the URL
http://ee-tutz.com/entry_api/rest/read_entry/json?auth[username]=test&auth[password]=guest&data[entry_id]=80
JSON data:
{"message":"Successfully readed","code":200,"code_http":200,"data":[{"entry_id":"80","site_id":"1","channel_id":"1","author_id":"1","forum_topic_id":null,"ip_address":"86.120.164.135","title":"POP ON OP: an Interactive Real-Time Animation Object-Book","url_title":"pop-on-op-an-interactive-real-time-animation-object-book","status":"open","versioning_enabled":"y","view_count_one":"0","view_count_two":"0","view_count_three":"0","view_count_four":"0","allow_comments":"y","sticky":"n","entry_date":"1405812194","year":"2014","month":"07","day":"20","expiration_date":"0","comment_expiration_date":"0","edit_date":"20140719233024","recent_comment_date":"0","comment_total":"0","main_content":"POP ON OP is an interactive real-time animation object-book in which you can experience movement directly on paper with a special film.","propietati":"74%$23,959 Funded ","testfisier":false,"poza":"<img alt=\"Photo little\" class=\"fit\" height=\"150\" src=\"https:\/\/s3.amazonaws.com\/ksr\/projects\/1055334\/photo-little.jpg?1404412397\" width=\"200\" \/>","descriere":" POP ON OP is an interactive real-time animation object-book in which you can experience movement directly on paper with a special film. ","autor":" by PARRATORO ","categories":[]}],"id":"80"}

innerHTML call to receive a url

I am trying to make a call so that when a title of a video is clicked on in my playlist, it will call back a particular videos url to be shown in the metadata field box that I have created.
So far I am getting results but the function below that I am using is giving me rmtp url's like this:
(rtmp://brightcove.fcod.llnwd.net/a500/d16/&mp4:media/1978114949001/1978114949001_2073371902001_How-to-Fish-the-Ice-Worm.mp4&1358870400000&7b1c5b2e65a7c051419c7f50bd712b1b
)
Brightcove has said to use (FLVURL&media_delivery=http).
I have tried every way I know of to put a media delivery in my function but always come up with nothing but the rmtp or a blank.
Can you please help with the small amount of code I have shown. If I need to show more that is not a problem. Thanks
function showMetaData(idx) {
$("tr.select").removeClass("select");
$("#tbData>tr:eq("+idx+")").addClass("select");
var v = oCurrentVideoList[idx];
//URL Metadata
document.getElementById('divMeta.FLVURL').innerHTML = v.FLVURL;
Here is my Population call for my list.
//For PlayList by ID
function buildMAinVideoList() {
//Wipe out the old results
$("#tbData").empty();
console.log(oCurrentMainVideoList);
oCurrentVideoList = oCurrentMainVideoList;
// Display video count
document.getElementById('divVideoCount').innerHTML = oCurrentMainVideoList.length + " videos";
document.getElementById('nameCol').innerHTML = "Video Name";
//document.getElementById('headTitle').innerHTML = title;
document.getElementById('search').value = "Search Videos";
document.getElementById('tdMeta').style.display = "block";
document.getElementById('searchDiv').style.display = "inline";
document.getElementById('checkToggle').style.display = "inline";
$("span[name=buttonRow]").show();
$(":button[name=delFromPlstButton]").hide();
//For each retrieved video, add a row to the table
var modDate = new Date();
$.each(oCurrentMainVideoList, function(i,n){
modDate.setTime(n.lastModifiedDate);
$("#tbData").append(
"<tr style=\"cursor:pointer;\" id=\""+(i)+"\"> \
<td>\
<input type=\"checkbox\" value=\""+(i)+"\" id=\""+(i)+"\" onclick=\"checkCheck()\">\
</td><td>"
+n.name +
"</td><td>"
+(modDate.getMonth()+1)+"/"+modDate.getDate()+"/"+modDate.getFullYear()+"\
</td><td>"
+n.id+
"</td><td>"
+((n.referenceId)?n.referenceId:'')+
"</td></tr>"
).children("tr").bind('click', function(){
showMetaData(this.id);
})
});
//Zebra stripe the table
$("#tbData>tr:even").addClass("oddLine");
//And add a hover effect
$("#tbData>tr").hover(function(){
$(this).addClass("hover");
}, function(){
$(this).removeClass("hover");
});
//if there are videos, show the metadata window, else hide it
if(oCurrentMainVideoList.length > 1){showMetaData(0);}
else{closeBox("tdMeta");}
}
If looking for HTTP paths, when the API call to Brightcove is correct you won't see the rtmp:// urls.
Since you're getting the rtmp URLs, this verifies you're using an API token with URL access, which is good. A request like this should return the playlist and the http URLs (insert your token and playlist ID).
http://api.brightcove.com/services/library?command=find_playlist_by_id&token={yourToken}&playlist_id={yourPlaylist}&video_fields=FLVURL&media_delivery=http
This API test tool can help build the queries for you, and show the expected results:
http://opensource.brightcove.com/tool/api-test-tool
I'm not seeing what would be wrong in your code, but in case you haven't tried this already, debugging in the browser can help you confirm the API results being returned, without having to access it via code. This help you root out any issues with the code you're using to access the values, vs problems with the values themselves. This is an overview on step-debugging in Chrome if you haven't used this before:
https://developers.google.com/chrome-developer-tools/docs/scripts-breakpoints

how to trace in the name of its variable

var abc:int=123
trace(abc)
//actual output:
123
//my expected output:
abc:123
Although I can type trace("abc:"+abc) by hands,but I still want to have a more simple way to trace
I have tried something like
function tracee(word){
trace("word:"+word)
}
function traceee(word){
var wordd:Srting=word
trace(wordd+word)
}
but these functions are not working.
is it possible to have the expected output?
import flash.utils.describeType;
var num:Number = 47;
function customTrace(word:*){
trace(describeType(this).variable.#name + " : "+word)
}
customTrace(num);
SOURCE
No. Variables are passed to functions by link (memory offset) or by value, so you don't have any data about names.
The one thing I can propose - is to use automatic code generation in IDEs. For example, in IntelliJ Idea it is in Settings -> Live Templates, that you can use via ctrl+J in editor.

html search form, how do i reduce the URL

I am creating a search for using the GET method at the moment, the problem is even if values are not selected and left at there default value they are sent and visible in the url.
I want to only have values selected in the url rather than every current value of the form, including default of 0.
the url ends up long and nasty:
search.php?search_shop_name=mcdonalds&search_shop_address=&search_total_rating=0&search_shop_comfort=0&search_shop_service=2&search_shop_ambience=0&search_shop_friendliness=0&search_shop_spacious=0&search_shop_experience=0&submit=#legend_total_results
I basically want to tidy up the url, am not actually sure if removing unwanted data is a good process or not, any possible advice on this situation? not sure if am being OCD with the visuals
Thanks
I would do the following. Using JavaScript or jQuery, create a submit function, in that function do a validate search with all fields if they = null then don't include them.
For e.g
var search;
function search(){
if(input[name=search].val() != null)
{
search = "q="+input[name=search].val();
}
if(input[name=search_shop_experience].val() != null)
{
search += "search_shop_experience="+input[name=ssearch_shop_experience].val();
}
}
I think you do .= or its += .