1 | <?php |
---|
2 | |
---|
3 | function wfSajaxGetMathUrl( $term ) |
---|
4 | { |
---|
5 | $originalLink = MathRenderer::renderMath( $term ); |
---|
6 | |
---|
7 | if (false == strpos($originalLink, "src=\"")) { |
---|
8 | return ""; |
---|
9 | } |
---|
10 | |
---|
11 | $srcPart = substr($originalLink, strpos($originalLink, "src=")+ 5); |
---|
12 | $url = strtok($srcPart, '"'); |
---|
13 | |
---|
14 | return $url; |
---|
15 | } |
---|
16 | |
---|
17 | function wfSajaxGetImageUrl( $term ) |
---|
18 | { |
---|
19 | global $wgExtensionFunctions, $wgTitle; |
---|
20 | |
---|
21 | $options = new FCKeditorParserOptions(); |
---|
22 | $options->setTidy(true); |
---|
23 | $parser = new FCKeditorParser(); |
---|
24 | |
---|
25 | if (in_array("wfCite", $wgExtensionFunctions)) { |
---|
26 | $parser->setHook('ref', array($parser, 'ref')); |
---|
27 | $parser->setHook('references', array($parser, 'references')); |
---|
28 | } |
---|
29 | $parser->setOutputType(OT_HTML); |
---|
30 | $originalLink = $parser->parse("[[Image:".$term."]]", $wgTitle, $options)->getText(); |
---|
31 | if (false == strpos($originalLink, "src=\"")) { |
---|
32 | return ""; |
---|
33 | } |
---|
34 | |
---|
35 | $srcPart = substr($originalLink, strpos($originalLink, "src=")+ 5); |
---|
36 | $url = strtok($srcPart, '"'); |
---|
37 | |
---|
38 | return $url; |
---|
39 | } |
---|
40 | |
---|
41 | function wfSajaxSearchImageFCKeditor( $term ) |
---|
42 | { |
---|
43 | global $wgContLang, $wgOut; |
---|
44 | $limit = 10; |
---|
45 | |
---|
46 | $term = $wgContLang->checkTitleEncoding( $wgContLang->recodeInput( js_unescape( $term ) ) ); |
---|
47 | $term1 = str_replace( ' ', '_', $wgContLang->ucfirst( $term ) ); |
---|
48 | $term2 = str_replace( ' ', '_', $wgContLang->lc( $term ) ); |
---|
49 | $term3 = str_replace( ' ', '_', $wgContLang->uc( $term ) ); |
---|
50 | $term = $term1; |
---|
51 | |
---|
52 | if ( strlen( str_replace( '_', '', $term ) )<3 ) |
---|
53 | return ""; |
---|
54 | |
---|
55 | $db =& wfGetDB( DB_SLAVE ); |
---|
56 | $res = $db->select( 'page', 'page_title', |
---|
57 | array( 'page_namespace' => NS_IMAGE, |
---|
58 | "LOWER(page_title) LIKE '%". $db->strencode( $term2 ) ."%'" ), |
---|
59 | "wfSajaxSearch", |
---|
60 | array( 'LIMIT' => $limit+1 ) |
---|
61 | ); |
---|
62 | |
---|
63 | $ret = ""; |
---|
64 | $i=0; |
---|
65 | while ( ( $row = $db->fetchObject( $res ) ) && ( ++$i <= $limit ) ) { |
---|
66 | $ret .= $row->page_title ."\n"; |
---|
67 | } |
---|
68 | |
---|
69 | $term = htmlspecialchars( $term ); |
---|
70 | |
---|
71 | return $ret; |
---|
72 | } |
---|
73 | |
---|
74 | function wfSajaxSearchArticleFCKeditor( $term ) |
---|
75 | { |
---|
76 | global $wgContLang, $wgOut; |
---|
77 | $limit = 10; |
---|
78 | $ns = NS_MAIN; |
---|
79 | |
---|
80 | $term = $wgContLang->checkTitleEncoding( $wgContLang->recodeInput( js_unescape( $term ) ) ); |
---|
81 | |
---|
82 | if (strpos($term, "Category:") === 0) { |
---|
83 | $ns = NS_CATEGORY; |
---|
84 | $term = substr($term, 9); |
---|
85 | $prefix = "Category:"; |
---|
86 | } |
---|
87 | else if (strpos($term, ":Category:") === 0) { |
---|
88 | $ns = NS_CATEGORY; |
---|
89 | $term = substr($term, 10); |
---|
90 | $prefix = ":Category:"; |
---|
91 | } |
---|
92 | |
---|
93 | $term1 = str_replace( ' ', '_', $wgContLang->ucfirst( $term ) ); |
---|
94 | $term2 = str_replace( ' ', '_', $wgContLang->lc( $term ) ); |
---|
95 | $term3 = str_replace( ' ', '_', $wgContLang->uc( $term ) ); |
---|
96 | $term = $term1; |
---|
97 | |
---|
98 | if ( strlen( str_replace( '_', '', $term ) )<3 ) { |
---|
99 | return ""; |
---|
100 | } |
---|
101 | |
---|
102 | $db =& wfGetDB( DB_SLAVE ); |
---|
103 | $res = $db->select( 'page', 'page_title', |
---|
104 | array( 'page_namespace' => $ns, |
---|
105 | "LOWER(page_title) LIKE '%". $db->strencode( $term2 ) ."%'" ), |
---|
106 | "wfSajaxSearch", |
---|
107 | array( 'LIMIT' => $limit+1 ) |
---|
108 | ); |
---|
109 | |
---|
110 | $ret = ""; |
---|
111 | $i=0; |
---|
112 | while ( ( $row = $db->fetchObject( $res ) ) && ( ++$i <= $limit ) ) { |
---|
113 | if (!is_null($prefix)) { |
---|
114 | $ret .= $prefix; |
---|
115 | } |
---|
116 | $ret .= $row->page_title ."\n"; |
---|
117 | } |
---|
118 | |
---|
119 | $term = htmlspecialchars( $term ); |
---|
120 | |
---|
121 | return $ret; |
---|
122 | } |
---|
123 | |
---|
124 | function wfSajaxWikiToHTML( $wiki ) |
---|
125 | { |
---|
126 | global $wgTitle; |
---|
127 | |
---|
128 | $options = new FCKeditorParserOptions(); |
---|
129 | $options->setTidy(true); |
---|
130 | $parser = new FCKeditorParser(); |
---|
131 | $parser->setOutputType(OT_HTML); |
---|
132 | |
---|
133 | return $parser->parse($wiki, $wgTitle, $options)->getText(); |
---|
134 | } |
---|