3

I'm relatively new to mediawiki and has just started last week.

Anyone can point me to the correct direction of getting the top article (based on number of likes) in mediawiki? I've already implemented the fblikebutton extension on every article and managed to retrieve the number of likes for each article.

Code that I used to check the number of likes in each article on different URLS

    $query_for_fql  = "SELECT like_count FROM link_stat WHERE url = '".$full_url."'";
    $fqlURL = "https://api.facebook.com/method/fql.query?format=json&query=" . urlencode($query_for_fql);
    $response = file_get_contents($fqlURL);
    $json_data = json_decode($response);
    $fb_like_count = $json_data[0]->like_count;
    echo 'Facebook Like:'.$fb_like_count .'<br/>';

eg: example.com/wiki/index.php?title=ABC (1 like) example.com/wiki/index.php?title=XYZ (2 likes)

I tried this but this is not working

        $highest = 0;
        while($highest < $fb_like_count)
        {
            if($fb_like_count > $highest) //if loop at first
            {
                $highest = $fb_like_count;
                echo "highest value is " . $highest . '<br/>';
            }
        }

I want to retrieve the content in example.com/wiki/index.php?title=XYZ and display in the "Top Article Page". What should I do next after retrieving the number of likes for each article on each url. The extensions I found for top articles are based on the number of views. But I want to classify the top article based on number of likes.

Thanks a million for helping!

Cœur
  • 37,241
  • 25
  • 195
  • 267
user1730935
  • 311
  • 3
  • 15
  • Where does the table link_stat comes from? What fblike extension did you used (link)? – Florian May 28 '15 at 05:38
  • @Florian Hi. The fblike extension which I've implemented is from this link https://www.mediawiki.org/wiki/Extension:FacebookLikeButton link_stat table is the table from Facebook. I used fql to query the likes. Thanks for your response! – user1730935 May 28 '15 at 05:47
  • FQL is deprecated, and the `https://api.facebook.com/method/fql.query` is as well. – Tobi May 28 '15 at 07:10
  • @user1730935: Please delete your own much more feeble duplicate at http://stackoverflow.com/questions/30497923/mediawiki-get-top-article-based-on-like ? – PJTraill May 28 '15 at 23:30

1 Answers1

1

As I said in my comment to you question, FQL is deprecated, and the https://api.facebook.com/method/fql.query endpoint as well.

If you want something future-proof, then you should switch to the /?ids={url1},{url2},... endpoint. You can use this one to generate the comma-separated list of URLs inn the forehand, and then retrieve all the shares in one request, for example

GET /?ids=http://www.techcrunch.com,http://www.google.com

returns

{
  "http://www.techcrunch.com": {
    "og_object": {
      "id": "433841427570", 
      "title": "TechCrunch", 
      "type": "website", 
      "updated_time": "2015-05-27T21:31:39+0000", 
      "url": "http://techcrunch.com/"
    }, 
    "share": {
      "comment_count": 0, 
      "share_count": 20914
    }, 
    "id": "http://www.techcrunch.com"
  }, 
  "http://www.google.com": {
    "og_object": {
      "id": "381702034999", 
      "description": "Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for.", 
      "title": "Google", 
      "type": "website", 
      "updated_time": "2015-05-28T07:10:18+0000", 
      "url": "http://www.google.com/"
    }, 
    "share": {
      "comment_count": 2, 
      "share_count": 12340803
    }, 
    "id": "http://www.google.com"
  }
}

The sorting issue you have is not related to the Facebook API, but PHP.

See

Community
  • 1
  • 1
Tobi
  • 31,405
  • 8
  • 58
  • 90
  • thanks for your great suggestions! But I am trying to get likes instead of share. Does the suggestion you provided include likes as well? Sorry for asking such a question, I am still learning. :) – user1730935 May 29 '15 at 02:39