Index: trunk/WikiWord/WikiWord/src/main/php/wwutils.php |
— | — | @@ -424,6 +424,44 @@ |
425 | 425 | return $list; |
426 | 426 | } |
427 | 427 | |
| 428 | + function queryTemplatesOnImagePage($lang, $image) { |
| 429 | + global $wwTablePrefix, $wwThesaurusDataset, $wwCommonsTablePrefix; |
| 430 | + $page_table = $this->getWikiTableName($lang, "page"); |
| 431 | + $templatelinks_table = $this->getWikiTableName($lang, "templatelinks"); |
| 432 | + |
| 433 | + $sql = "/* queryTemplatesOnImagePage(" . $this->quote($lang) . ", " . $this->quote($image) . ") */ "; |
| 434 | + |
| 435 | + $sql .= " SELECT tl_title as template FROM $templatelinks_table as T "; |
| 436 | + $sql .= " JOIN $page_table as P on P.page_id = T.tl_from AND T.tl_namespace = " . NS_TEMPLATE . " "; |
| 437 | + |
| 438 | + $sql .= " WHERE P.page_title = " . $this->quote($image); |
| 439 | + $sql .= " AND P.page_namespace = " . NS_IMAGE; |
| 440 | + |
| 441 | + return $this->queryWiki($lang, $sql); |
| 442 | + } |
| 443 | + |
| 444 | + function getTemplatesOnImagePage($lang, $image) { |
| 445 | + $rs = $this->queryTemplatesOnImagePage($lang, $image); |
| 446 | + $list = WWUtils::slurpList($rs, "template"); |
| 447 | + mysql_free_result($rs); |
| 448 | + return $list; |
| 449 | + } |
| 450 | + |
| 451 | + function getTemplateScores($templates, $values = NULL) { |
| 452 | + global $wwWikiServerName; |
| 453 | + if ($values === NULL) $values = $wwTemplateScores; |
| 454 | + |
| 455 | + if (!$values) return 0; |
| 456 | + |
| 457 | + $score = 0; |
| 458 | + foreach ($templates as $t) { |
| 459 | + $v = @$values[$t]; |
| 460 | + if ($v) $score += $v; |
| 461 | + } |
| 462 | + |
| 463 | + return $score; |
| 464 | + } |
| 465 | + |
428 | 466 | function getRelevantImagesOnPage($lang, $ns, $title, $commonsOnly = false) { |
429 | 467 | $img = $this->getImagesOnPage($lang, 0, $title, true); |
430 | 468 | $timg = $this->getImagesOnPageTemplates($lang, 0, $title, true); |