Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Wikipedia: Mediawiki-CVS

SVN: [58550] trunk/WikiWord/WikiWord/src/main/php

 

 

Wikipedia mediawiki-cvs RSS feed   Index | Next | Previous | View Threaded


daniel at svn

Nov 4, 2009, 8:52 AM

Post #1 of 1 (18 views)
Permalink
SVN: [58550] trunk/WikiWord/WikiWord/src/main/php

http://www.mediawiki.org/wiki/Special:Code/MediaWiki/58550

Revision: 58550
Author: daniel
Date: 2009-11-04 16:52:54 +0000 (Wed, 04 Nov 2009)

Log Message:
-----------
improving image search using remote api

Modified Paths:
--------------
trunk/WikiWord/WikiWord/src/main/php/config.sample.php
trunk/WikiWord/WikiWord/src/main/php/wikiword.php
trunk/WikiWord/WikiWord/src/main/php/wwimages.php
trunk/WikiWord/WikiWord/src/main/php/wwthesaurus.php

Modified: trunk/WikiWord/WikiWord/src/main/php/config.sample.php
===================================================================
--- trunk/WikiWord/WikiWord/src/main/php/config.sample.php 2009-11-04 16:07:42 UTC (rev 58549)
+++ trunk/WikiWord/WikiWord/src/main/php/config.sample.php 2009-11-04 16:52:54 UTC (rev 58550)
@@ -17,6 +17,7 @@
#error_reporting(E_ALL);

$wwMaxPreviewImages = 8;
+$wwMaxGalleryImages = 200;
$wwThumbSize = 120;
$wwThumbnailURL = "http://toolserver.org/tsthumb/tsthumb?f={name}&domain=commons.wikimedia.org&w={width}&h={height}";
$wwImagePageURL = "http://commons.wikimedia.org/wiki/File:{name}";

Modified: trunk/WikiWord/WikiWord/src/main/php/wikiword.php
===================================================================
--- trunk/WikiWord/WikiWord/src/main/php/wikiword.php 2009-11-04 16:07:42 UTC (rev 58549)
+++ trunk/WikiWord/WikiWord/src/main/php/wikiword.php 2009-11-04 16:52:54 UTC (rev 58550)
@@ -47,6 +47,8 @@
function printLocalConceptLink($lang, $row) {
global $wwSelf, $images;

+ $row = normalizeConceptRow($lang, $row);
+
extract($row);

if (!isset($weight) && isset($freq)) $weight = $freq;
@@ -117,17 +119,17 @@

if (!$row) return $row;

- $row['lang'] = $lang;
-
+ if (!isset($row['lang'])) $row['lang'] = $lang;
if (!isset($row['weight']) && isset($row['freq'])) $row['weight'] = $row['freq'];
if (!isset($row['weight']) && isset($row['conf'])) $row['weight'] = $row['conf'];
- if (isset($row['local_concept_name'])) $row['concept_name'] = $row['local_concept_name'];
+ if (!empty($row['local_concept_name'])) $row['concept_name'] = $row['local_concept_name'];
if (!isset($row['concept_name']) && isset($row['name'])) $row['concept_name'] = $row['name'];
if (!isset($row['concept_name']) && isset($row['global_concept_name'])) $row['concept_name'] = $row['global_concept_name'];
if (!isset($row['reference_id']) && isset($row['global_id'])) $row['reference_id'] = $row['global_id'];
if (!isset($row['reference_id']) && isset($row['global_concept'])) $row['reference_id'] = $row['global_concept'];
if (!isset($row['reference_id']) && isset($row['concept'])) $row['reference_id'] = $row['concept'];
if (!isset($row['reference_id']) && isset($row['id'])) $row['reference_id'] = $row['id'];
+ if (!empty($row['definition']) && is_array($row['definition'])) $row['definition'] = $row['definition'][$lang];

#print "<pre>";
#print_r($row);
@@ -151,8 +153,9 @@
return $row;
}

-function printLocalConcept($a_lang, $a_row, $b_lang, $b_row, $pos = 0, $images) {
- global $wwSelf;
+function printLocalConcept($a_lang, $a_row, $b_lang, $b_row, $pos = 0, $terse = true) {
+ global $wwSelf, $images, $utils;
+ global $wwMaxPreviewImages, $wwMaxGalleryImages;

$a_row = normalizeConceptRow($a_lang, $a_row);
$b_row = normalizeConceptRow($b_lang, $b_row);
@@ -164,13 +167,17 @@
<tr class="row_item">
<td class="cell_weight <?php print "weight_$a_wclass"; ?>"><?php print htmlspecialchars($a_weight); ?></td>
<td colspan="3" class="cell_name <?php print "weight_$a_wclass"; ?>">
+ <h3>
<a href="<?php print htmlspecialchars($a_cu); ?>"><?php print htmlspecialchars($a_concept_name); ?></a>
<span class="conceptref">(<a href="<?php print htmlspecialchars($a_wu); ?>" title="<?php print htmlspecialchars($a_concept_name); ?>">wiki page</a>)</span>
+ </h3>
</td>
<?php if ($b_row) { ?>
<td colspan="3" class="cell_name <?php print "weight_$b_wclass"; ?>">
+ <h3>
<a href="<?php print htmlspecialchars($b_cu); ?>"><?php print htmlspecialchars($b_concept_name); ?></a>
<span class="conceptref">(<a href="<?php print htmlspecialchars($b_wu); ?>" title="<?php print htmlspecialchars($b_concept_name); ?>">wiki page</a>)</span>
+ </h3>
</td>
<?php } ?>
</tr>
@@ -199,6 +206,19 @@
</tr>
<?php } ?>

+ <?php if ($images) { ?>
+ <tr class="row_details row_images">
+ <td></td>
+ <td class="cell_label">Images:</td>
+ <td class="cell_broader" colspan="<?php $b_row ? 5 : 2 ?>">
+ <?php
+ $gallery = $utils->getImagesAbout($a_reference_id, $terse ? $wwMaxPreviewImages : $wwMaxGalleryImages );
+ $c = printConceptImageList( $gallery, $terse ? "terselist" : "gallery" );
+ ?>
+ </td>
+ </tr>
+ <?php } ?>
+
<?php if (isset($a_similar) && !empty($a_similar)) { ?>
<tr class="row_details row_similar">
<td></td>
@@ -247,15 +267,6 @@
</tr>
<?php } ?>

- <?php if ($images) { ?>
- <tr class="row_details row_images">
- <td></td>
- <td class="cell_label">Images:</td>
- <td class="cell_broader" colspan="<?php $b_row ? 5 : 2 ?>">
- <?php printConceptImageList($a_reference_id); ?>
- </td>
- </tr>
- <?php } ?>
<?php
if (isset($a_weight) && $a_weight && $a_weight<2 && $pos>=3) return false;
else return true;
@@ -401,36 +412,9 @@
else if (@$row['concept']) $id = $row['concept'];
else $id = "concept";

- if (@$row['local_concept_name']) $title = $row['local_concept_name'];
- else if (@$row['concept_name']) $title = $row['concept_name'];
- else if (@$row['name']) $title = $row['name'];
- else if ($id) $title = "Concept #$id";
- else if ($concept) $title = "Concept #$concept";
-
?>
<div id="<?php print htmlspecialchars("concept-$id")?>">
- <h2><?php print htmlspecialchars($title); ?></h2>

- <?php
- if ($images) $gallery = $utils->getImagesAbout($id);
- else $images = NULL;
-
- if ($gallery) {
- $title = "Gallery #$concept";
- ?>
- <h2><?php print htmlspecialchars($title); ?></h2>
- <div border="0" class="gallery">
- <?php
- printConceptImageList($gallery, "gallery");
- ?>
- </div>
-
- <p>Found <?php print count($gallery); ?> images.</p>
-
- <?php
- }
- ?>
-
<table border="0" class="results">
<?php
if ($lang) {
@@ -462,14 +446,14 @@
if ($tolang && isset($row['global_concept'])) {
$toresult = $utils->queryConceptInfo($row['global_concept'], $tolang);
while ($torow = mysql_fetch_assoc($toresult)) {
- $continue= printLocalConcept($lang, $row, $tolang, $torow, $count, $images);
+ $continue= printLocalConcept($lang, $row, $tolang, $torow, $count, true);
$show_single = false;
}
mysql_free_result($toresult);
}

if ($show_single) {
- $continue= printLocalConcept($lang, $row, NULL, NULL, $count, $images);
+ $continue= printLocalConcept($lang, $row, NULL, NULL, $count, true);
}
}
//else $continue= printGlobalConcept($lang, $row, $count);

Modified: trunk/WikiWord/WikiWord/src/main/php/wwimages.php
===================================================================
--- trunk/WikiWord/WikiWord/src/main/php/wwimages.php 2009-11-04 16:07:42 UTC (rev 58549)
+++ trunk/WikiWord/WikiWord/src/main/php/wwimages.php 2009-11-04 16:52:54 UTC (rev 58550)
@@ -252,6 +252,7 @@
if (!isset($wwLanguages[$lang])) continue;

foreach ($pages as $page) {
+ //FIXME: detect namespace prefix?!
$img = $this->getRelevantImagesOnPage($lang, 0, $page, true);
$images->addImages($img, $lang . ":" . $page, "article", 1);
}
@@ -266,21 +267,27 @@
$pages = $concepts['commons'];

foreach ($pages as $page) {
- $img = $this->getRelevantImagesOnPage("commons", 0, $page, false);
- $images->addImages($img, "commons:" . $page, "gallery", 0.8);
+ if ( $wwFakeCommonsConcepts || !preg_match('/^Category:(.*)$/', $page) ) {
+ $img = $this->getRelevantImagesOnPage("commons", 0, $page, false);
+ $images->addImages($img, "commons:" . $page, "gallery", 0.8);
+ }

if ($max && $images->size()>$max) {
$this->addImageTags($images);
return $images->listImages($max);
}

- $img = $this->getImagesInCategory("commons", $page); //FIXME: resource mapping
- if ($img) $images->addImages($img, "commons:category:" . $page, "category", 0.5);
- else if ($wwFakeCommonsConcepts && $wwFakeCommonsPlural && !preg_match('/s$/', $page)) {
- $cname = $page."s";
+ if ( $wwFakeCommonsConcepts || preg_match('/^Category:(.*)$/', $page, $m) ) {
+ if ( @$m[1] ) $page = $m[1]; //hack
+ $img = $this->getImagesInCategory("commons", $page);

- $img = $this->getImagesInCategory("commons", $cname); //FIXME: resource mapping
- $images->addImages($img, "commons:category:" . $cname, "category(pl)", 0.5);
+ if ($img) $images->addImages($img, "commons:category:" . $page, "category", 0.5);
+ else if ($wwFakeCommonsConcepts && $wwFakeCommonsPlural && !preg_match('/s$/', $page)) {
+ $cname = $page."s";
+
+ $img = $this->getImagesInCategory("commons", $cname);
+ $images->addImages($img, "commons:category:" . $cname, "category(pl)", 0.5);
+ }
}
}
}

Modified: trunk/WikiWord/WikiWord/src/main/php/wwthesaurus.php
===================================================================
--- trunk/WikiWord/WikiWord/src/main/php/wwthesaurus.php 2009-11-04 16:07:42 UTC (rev 58549)
+++ trunk/WikiWord/WikiWord/src/main/php/wwthesaurus.php 2009-11-04 16:52:54 UTC (rev 58550)
@@ -180,10 +180,14 @@
function getRelatedForConcept( $id, $lang = null, $limit = 100 ) {
global $wwTablePrefix, $wwThesaurusDataset;

- $sql = "SELECT C.* FROM {$wwTablePrefix}_{$wwThesaurusDataset}_concept as C "
- . " JOIN {$wwTablePrefix}_{$wwThesaurusDataset}_relation as R ON R.concept2 = C.id "
- . " WHERE R.concept1 = ".(int)$id
+ $sql = "SELECT " . ($lang ? " C.*, O.* " : " C.* " ) . " FROM {$wwTablePrefix}_{$wwThesaurusDataset}_concept as C "
+ . " JOIN {$wwTablePrefix}_{$wwThesaurusDataset}_relation as R ON R.concept2 = C.id ";
+
+ if ( $lang ) $sql .= " LEFT JOIN {$wwTablePrefix}_{$wwThesaurusDataset}_origin as O ON O.lang = \"" . mysql_real_escape_string($lang) . "\" AND C.id = O.global_concept ";
+
+ $sql .= " WHERE R.concept1 = ".(int)$id
. " AND ( R.bilink > 0 OR R.langref > 0 OR R.langmatch > 0 )"
+ . " GROUP BY C.id "
. " LIMIT " . (int)$limit;

return $this->getRows($sql);
@@ -192,9 +196,13 @@
function getBroaderForConcept( $id, $lang = null, $limit = 100 ) {
global $wwTablePrefix, $wwThesaurusDataset;

- $sql = "SELECT C.* FROM {$wwTablePrefix}_{$wwThesaurusDataset}_concept as C "
- . " JOIN {$wwTablePrefix}_{$wwThesaurusDataset}_broader as R ON R.broad = C.id "
- . " WHERE R.narrow = ".(int)$id
+ $sql = "SELECT " . ($lang ? " C.*, O.* " : " C.* " ) . " FROM {$wwTablePrefix}_{$wwThesaurusDataset}_concept as C "
+ . " JOIN {$wwTablePrefix}_{$wwThesaurusDataset}_broader as R ON R.broad = C.id ";
+
+ if ( $lang ) $sql .= " LEFT JOIN {$wwTablePrefix}_{$wwThesaurusDataset}_origin as O ON O.lang = \"" . mysql_real_escape_string($lang) . "\" AND C.id = O.global_concept ";
+
+ $sql .= " WHERE R.narrow = ".(int)$id
+ . " GROUP BY C.id "
. " LIMIT " . (int)$limit;

return $this->getRows($sql);
@@ -203,15 +211,19 @@
function getNarrowerForConcept( $id, $lang = null, $limit = 100 ) {
global $wwTablePrefix, $wwThesaurusDataset;

- $sql = "SELECT C.* FROM {$wwTablePrefix}_{$wwThesaurusDataset}_concept as C "
- . " JOIN {$wwTablePrefix}_{$wwThesaurusDataset}_broader as R ON R.narrow = C.id "
- . " WHERE R.broad = ".(int)$id
+ $sql = "SELECT " . ($lang ? " C.*, O.* " : " C.* " ) . " FROM {$wwTablePrefix}_{$wwThesaurusDataset}_concept as C "
+ . " JOIN {$wwTablePrefix}_{$wwThesaurusDataset}_broader as R ON R.narrow = C.id ";
+
+ if ( $lang ) $sql .= " LEFT JOIN {$wwTablePrefix}_{$wwThesaurusDataset}_origin as O ON O.lang = \"" . mysql_real_escape_string($lang) . "\" AND C.id = O.global_concept ";
+
+ $sql .= " WHERE R.broad = ".(int)$id
+ . " GROUP BY C.id "
. " LIMIT " . (int)$limit;

return $this->getRows($sql);
}

- function getPagesForConcept( $id, $lang, $limit = 100 ) {
+ function getPagesForConcept( $id, $lang = null, $limit = 100 ) {
global $wwTablePrefix, $wwThesaurusDataset, $wwLanguages;

if ( !$lang ) $lang = array_keys( $wwLanguages );



_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS[at]lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Wikipedia mediawiki-cvs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.