| | 2 | |
| | 3 | function wfSajaxGetImageUrl( $term ) |
| | 4 | { |
| | 5 | global $wgContLang, $wgOut; |
| | 6 | |
| | 7 | $term = $wgContLang->checkTitleEncoding( $wgContLang->recodeInput( js_unescape( $term ) ) ); |
| | 8 | $term1 = str_replace( ' ', '_', $wgContLang->ucfirst( $term ) ); |
| | 9 | $term2 = str_replace( ' ', '_', $wgContLang->lc( $term ) ); |
| | 10 | $term3 = str_replace( ' ', '_', $wgContLang->uc( $term ) ); |
| | 11 | $term = $term1; |
| | 12 | |
| | 13 | if ( strlen( str_replace( '_', '', $term ) )<3 ) |
| | 14 | return ""; |
| | 15 | |
| | 16 | $db =& wfGetDB( DB_SLAVE ); |
| | 17 | $res = $db->select( 'page', 'page_title', |
| | 18 | array( 'page_namespace' => NS_IMAGE, |
| | 19 | "LCASE(page_title) = '". $db->strencode( $term2 ) ."'" ), |
| | 20 | "wfSajaxSearch", |
| | 21 | array( 'LIMIT' => 1 ) |
| | 22 | ); |
| | 23 | |
| | 24 | $row = $db->fetchObject( $res ); |
| | 25 | if (!$row) { |
| | 26 | return ""; |
| | 27 | } |
| | 28 | |
| | 29 | $ret = $row->page_title; |
| | 30 | |
| | 31 | if (!is_null($ret)) { |
| | 32 | $title = new Title(); |
| | 33 | $nt = Title::newFromText( $term , NS_IMAGE); |
| | 34 | $img = new Image( $nt ); |
| | 35 | return $img->getURL(); |
| | 36 | } else { |
| | 37 | return ""; |
| | 38 | } |
| | 39 | |
| | 40 | return $ret; |
| | 41 | } |