r80309 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80308‎ | r80309 | r80310 >
Date:20:02, 14 January 2011
Author:krinkle
Status:deferred
Tags:
Comment:
combined loose requests into one combined for API thumbs
Modified paths:
  • /trunk/tools/wp-photocommons/search.js (modified) (history)
  • /trunk/tools/wp-photocommons/search.php (modified) (history)

Diff [purge]

Index: trunk/tools/wp-photocommons/search.js
@@ -1,5 +1,6 @@
2 -// Debug
3 -window.log = (console && console.log) ? console.log : function(){};
 2+window.log = function(a){
 3+ console.log(a);
 4+}
45
56 if ( !window.Photocommons ) {
67 window.Photocommons = {};
@@ -21,7 +22,8 @@
2223 'action' : 'query',
2324 'prop' : 'images',
2425 'indexpageids' : '1',
25 - 'titles' : q.title
 26+ 'titles' : q.title,
 27+ 'redirects' : '1'
2628 };
2729 },
2830
@@ -32,13 +34,13 @@
3335 'iiprop' : 'url',
3436 'iiurlwidth' : q.width,
3537 'indexpageids' : '1',
36 - 'titles' : q.image
 38+ 'titles' : q.images//.join( '|' )
3739 };
3840 }
3941 };
4042
4143 if (!queries[type]) {
42 - throw new Error('Unknown query type');
 44+ throw new Error( 'Unknown query type' );
4345 }
4446
4547 return Photocommons.makeUrl(queries[type](args));
@@ -57,7 +59,7 @@
5860 url += (first) ? '?' : '&';
5961 first = false;
6062
61 - if (value.indexOf('!noencode!') === 0 && typeof value === 'string') {
 63+ if (value.indexOf( '!noencode!' ) === 0 && typeof value === 'string' ) {
6264 value = value.slice(10);
6365 } else {
6466 value = encodeURIComponent(value);
@@ -69,10 +71,10 @@
7072 },
7173 init: function() {
7274
73 - $('#wp-photocommons-search').autocomplete({
 75+ $( '#wp-photocommons-search' ).autocomplete({
7476 source : function(request, response) {
75 - var url = Photocommons.getQueryUrl('pagesearch', {
76 - 'search' : $('#wp-photocommons-search').val()
 77+ var url = Photocommons.getQueryUrl( 'pagesearch', {
 78+ 'search' : $( '#wp-photocommons-search' ).val()
7779 });
7880
7981 $.getJSON(url, function(data) {
@@ -81,35 +83,45 @@
8284 },
8385
8486 select : function(event, ui) {
85 - $('#wp-photocommons-images').empty();
86 - $('#wp-photocommons-loading').show();
 87+ $( '#wp-photocommons-images' ).empty();
 88+ $( '#wp-photocommons-loading' ).show();
8789
88 - var url = Photocommons.getQueryUrl('pageimages', {
 90+ var url = Photocommons.getQueryUrl( 'pageimages', {
8991 'title' : ui.item.value
9092 });
9193
9294 $.getJSON(url, function(data) {
93 - var pageid = data.query.pageids[0],
94 - query = data.query.pages[pageid].images;
 95+ var pageid = data.query.pageids[0],
 96+ pageimages = data.query.pages[pageid].images,
 97+ titles = '';
9598
96 - if (!query) {
97 - $('#wp-photocommons-images').html('No images found :(');
 99+ if ( !pageimages.length ) {
 100+ $( '#wp-photocommons-images' ).html( 'No images found :(' );
98101 }
99102
100 - $.each(query, function() {
101 - var url = Photocommons.getQueryUrl('thumbs', {
102 - width : '200',
103 - image : this.title
104 - });
105 -
106 - $.getJSON(url, function(data) {
107 - var pageid = data.query.pageids[0],
108 - src = data.query.pages[pageid].imageinfo[0].thumburl;
109 - $('#wp-photocommons-images').append('<img src="' + src + '" style="display:none;"/>').find('img').fadeIn();
110 - });
 103+ $.each( pageimages, function() {
 104+ titles += '|' + this.title;
 105+ } );
 106+
 107+ var url = Photocommons.getQueryUrl( 'thumbs', {
 108+ width : '200',
 109+ images : titles
111110 });
112111
113 - $('#wp-photocommons-loading').hide();
 112+
 113+ $.getJSON(url, function(data){
 114+
 115+ $.each(data.query.pageids, function(key,pageid){
 116+ var img = data.query.pages[pageid];
 117+ if ( img.imageinfo && img.imageinfo[0] ) {
 118+ $( '#wp-photocommons-images' ).append( '<img src="' + img.imageinfo[0].thumburl + '" style="display:none;"/>' ).find( 'img' ).fadeIn();
 119+
 120+ }
 121+ })
 122+
 123+ });
 124+
 125+ $( '#wp-photocommons-loading' ).hide();
114126 });
115127 }
116128 });
Index: trunk/tools/wp-photocommons/search.php
@@ -1,3 +1,5 @@
 2+<?php
 3+ if ( basename( $_SERVER['SCRIPT_FILENAME'] ) == 'search.php' ) : ?>
24 <!doctype html>
35 <html>
46 <head>
@@ -8,7 +10,9 @@
911 <link rel="stylesheet" href="css/ui-lightness/jquery-ui-1.8.5.custom.css" />
1012 </head>
1113 <body>
 14+<?php endif; ?>
1215
 16+
1317 <input type="search" id="wp-photocommons-search" />
1418
1519 <ul id="wp-photocommons-results"></ul>
@@ -17,5 +21,10 @@
1822
1923 <div id="wp-photocommons-images"></div>
2024
 25+
 26+
 27+
 28+<?php if ( basename( $_SERVER['SCRIPT_FILENAME'] ) == 'search.php' ) : ?>
2129 </body>
22 -</html>
\ No newline at end of file
 30+</html>
 31+<?php endif; ?>
\ No newline at end of file

Status & tagging log