~ubuntu-branches/ubuntu/saucy/mediawiki-extensions/saucy

« back to all changes in this revision

Viewing changes to dist/mediawiki-extensions-fckeditor/usr/share/mediawiki-extensions/fckeditor/FCKeditorSajax.body.php

  • Committer: Bazaar Package Importer
  • Author(s): Romain Beauxis
  • Date: 2010-05-04 15:13:35 UTC
  • mfrom: (0.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20100504151335-54qeucg3ec108q28
Tags: 2.2
* Added Replaces:/Conflicts: to allow a proper upgrade.
Closes: #580066
* Fixed package descriptions.
Closes: #579667
* Patched mediawiki-extensions-fckeditor to make it work with
  php 5.3. The fix may not be perfect but at least it work.
  Not closing the bug (#579822) for now..

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
function wfSajaxGetMathUrl( $term ) {
 
4
        $originalLink = MathRenderer::renderMath( $term );
 
5
 
 
6
        if (false == strpos($originalLink, "src=\"")) {
 
7
                return "";
 
8
        }
 
9
 
 
10
        $srcPart = substr($originalLink, strpos($originalLink, "src=")+ 5);
 
11
        $url = strtok($srcPart, '"');
 
12
 
 
13
        return $url;
 
14
}
 
15
 
 
16
function wfSajaxGetImageUrl( $term ) {
 
17
        global $wgExtensionFunctions, $wgTitle;
 
18
 
 
19
        $options = new FCKeditorParserOptions();
 
20
        $options->setTidy(true);
 
21
        $parser = new FCKeditorParser();
 
22
 
 
23
        if (in_array("wfCite", $wgExtensionFunctions)) {
 
24
                $parser->setHook('ref', array($parser, 'ref'));
 
25
                $parser->setHook('references', array($parser, 'references'));
 
26
        }
 
27
        $parser->setOutputType(OT_HTML);
 
28
        $originalLink = $parser->parse("[[Image:".$term."]]", $wgTitle, $options)->getText();
 
29
        if (false == strpos($originalLink, "src=\"")) {
 
30
                return "";
 
31
        }
 
32
 
 
33
        $srcPart = substr($originalLink, strpos($originalLink, "src=")+ 5);
 
34
        $url = strtok($srcPart, '"');
 
35
 
 
36
        return $url;
 
37
}
 
38
 
 
39
function wfSajaxSearchSpecialTagFCKeditor($empty) {
 
40
        global $wgParser, $wgRawHtml;
 
41
 
 
42
        $ret = "nowiki\nincludeonly\nonlyinclude\nnoinclude\ngallery\n";
 
43
        if( $wgRawHtml )
 
44
        {
 
45
                $ret.="html\n";
 
46
        }
 
47
        $wgParser->firstCallInit();
 
48
        foreach ($wgParser->getTags() as $h) {
 
49
                if (!in_array($h, array("pre", "math", "ref", "references"))) {
 
50
                        $ret .= $h ."\n";
 
51
                }
 
52
        }
 
53
        $arr = explode("\n", $ret);
 
54
        sort($arr);
 
55
        $ret = implode("\n", $arr);
 
56
 
 
57
        return $ret;
 
58
}
 
59
 
 
60
function wfSajaxSearchImageFCKeditor( $term ) {
 
61
        global $wgContLang, $wgOut;
 
62
        $limit = 10;
 
63
 
 
64
        $term = $wgContLang->checkTitleEncoding( $wgContLang->recodeInput( js_unescape( $term ) ) );
 
65
        $term1 = str_replace( ' ', '_', $wgContLang->ucfirst( $term ) );
 
66
        $term2 = str_replace( ' ', '_', $wgContLang->lc( $term ) );
 
67
        $term3 = str_replace( ' ', '_', $wgContLang->uc( $term ) );
 
68
        $term4 = str_replace( ' ', '_', $wgContLang->ucfirst( $term2 ) );
 
69
        $term = $term1;
 
70
 
 
71
        if ( strlen( str_replace( '_', '', $term ) )<3 )
 
72
        return "";
 
73
 
 
74
        $db = wfGetDB( DB_SLAVE );
 
75
        $res = $db->select( 'page', 'page_title',
 
76
        array(  'page_namespace' => NS_IMAGE,
 
77
        "page_title LIKE '%". $db->strencode( $term1 ) ."%'".
 
78
        "OR (page_title LIKE '%". $db->strencode( $term2 ) ."%') ".
 
79
        "OR (page_title LIKE '%". $db->strencode( $term3 ) ."%') ".
 
80
        "OR (page_title LIKE '%". $db->strencode( $term4 ) ."%') " ),
 
81
        "wfSajaxSearch",
 
82
        array( 'LIMIT' => $limit+1 )
 
83
        );
 
84
 
 
85
        $ret = "";
 
86
        $i = 0;
 
87
        while ( ( $row = $db->fetchObject( $res ) ) && ( ++$i <= $limit ) ) {
 
88
                $ret .= $row->page_title ."\n";
 
89
        }
 
90
 
 
91
        $term = htmlspecialchars( $term );
 
92
 
 
93
        return $ret;
 
94
}
 
95
 
 
96
function wfSajaxSearchArticleFCKeditor( $term ) {
 
97
        global $wgContLang, $wgOut, $wgExtraNamespaces;
 
98
        $limit = 10;
 
99
        $ns = NS_MAIN;
 
100
 
 
101
        $term = $wgContLang->checkTitleEncoding( $wgContLang->recodeInput( js_unescape( $term ) ) );
 
102
 
 
103
        if (strpos(strtolower($term), "category:") === 0) {
 
104
                $ns = NS_CATEGORY;
 
105
                $term = substr($term, 9);
 
106
                $prefix = "Category:";
 
107
        }
 
108
        else if (strpos(strtolower($term), ":category:") === 0) {
 
109
                $ns = NS_CATEGORY;
 
110
                $term = substr($term, 10);
 
111
                $prefix = ":Category:";
 
112
        }
 
113
        else if (strpos(strtolower($term), "media:") === 0) {
 
114
                $ns = NS_IMAGE;
 
115
                $term = substr($term, 6);
 
116
                $prefix = "Media:";
 
117
        }
 
118
        else if (strpos(strtolower($term), ":image:") === 0) {
 
119
                $ns = NS_IMAGE;
 
120
                $term = substr(strtolower($term), 7);
 
121
                $prefix = ":Image:";
 
122
        }
 
123
        else if ( strpos($term,":") && is_array($wgExtraNamespaces )) {
 
124
                $pos = strpos($term,":");
 
125
                $find_ns = array_search(substr($term,0,$pos),$wgExtraNamespaces);
 
126
                if ($find_ns) {
 
127
                        $ns = $find_ns;
 
128
                        $prefix = substr($term,0,$pos+1);
 
129
                        $term = substr($term,$pos+1);
 
130
                }
 
131
        }
 
132
 
 
133
        $term1 = str_replace( ' ', '_', $wgContLang->ucfirst( $term ) );
 
134
        $term2 = str_replace( ' ', '_', $wgContLang->lc( $term ) );
 
135
        $term3 = str_replace( ' ', '_', $wgContLang->uc( $term ) );
 
136
        $term4 = str_replace( ' ', '_', $wgContLang->ucfirst( $term2 ) );
 
137
        $term = $term1;
 
138
 
 
139
        if ( strlen( str_replace( '_', '', $term ) )<3 ) {
 
140
                return "";
 
141
        }
 
142
 
 
143
        $db = wfGetDB( DB_SLAVE );
 
144
        $res = $db->select( 'page', 'page_title',
 
145
        array(  'page_namespace' => $ns,
 
146
        "page_title LIKE '%". $db->strencode( $term1 ) ."%' ".
 
147
        "OR (page_title LIKE '%". $db->strencode( $term2 ) ."%') ".
 
148
        "OR (page_title LIKE '%". $db->strencode( $term3 ) ."%') ".
 
149
        "OR (page_title LIKE '%". $db->strencode( $term4 ) ."%') " ),
 
150
        "wfSajaxSearch",
 
151
        array( 'LIMIT' => $limit+1 )
 
152
        );
 
153
 
 
154
        $ret = "";
 
155
        $i = 0;
 
156
        while ( ( $row = $db->fetchObject( $res ) ) && ( ++$i <= $limit ) ) {
 
157
                if (isset($prefix) && !is_null($prefix)) {
 
158
                        $ret .= $prefix;
 
159
                }
 
160
                $ret .= $row->page_title ."\n";
 
161
        }
 
162
 
 
163
        $term = htmlspecialchars( $term );
 
164
 
 
165
        return $ret;
 
166
}
 
167
 
 
168
function wfSajaxSearchCategoryFCKeditor()
 
169
{
 
170
        global $wgContLang, $wgOut;
 
171
        $ns = NS_CATEGORY;
 
172
        $db =& wfGetDB( DB_SLAVE );
 
173
        $m_sql="SELECT tmpSelectCat1.cl_to AS title FROM ".$db->tableName('categorylinks')." AS tmpSelectCat1 ".
 
174
                "LEFT JOIN ".$db->tableName('page')." AS tmpSelectCatPage ON ( tmpSelectCat1.cl_to = tmpSelectCatPage.page_title ".
 
175
                "AND tmpSelectCatPage.page_namespace =$ns ) ".
 
176
                "LEFT JOIN ".$db->tableName('categorylinks')." AS tmpSelectCat2 ON tmpSelectCatPage.page_id = tmpSelectCat2.cl_from ".
 
177
                "WHERE tmpSelectCat2.cl_from IS NULL GROUP BY tmpSelectCat1.cl_to";
 
178
 
 
179
        $res = $db->query($m_sql,__METHOD__ );
 
180
 
 
181
        $ret = "";
 
182
        $i=0;
 
183
        while ( ( $row = $db->fetchObject( $res ) ) ) {
 
184
                $ret .= $row->title ."\n";
 
185
                $sub = explode("\n",wfSajaxSearchCategoryChildrenFCKeditor($row->title));
 
186
                foreach($sub as $subrow)if(strlen($subrow)>0)$ret.=" ".$subrow."\n";
 
187
        }
 
188
 
 
189
        return $ret;
 
190
}
 
191
 
 
192
function wfSajaxSearchCategoryChildrenFCKeditor($m_root)
 
193
{
 
194
        global $wgContLang, $wgOut;
 
195
        $limit = 50;
 
196
        $ns = NS_CATEGORY;
 
197
        $m_root = str_replace("'","\'",$m_root);
 
198
        $db =& wfGetDB( DB_SLAVE );
 
199
        $m_sql ="SELECT tmpSelectCatPage.page_title AS title FROM ".$db->tableName('categorylinks')." AS tmpSelectCat ".
 
200
                        "LEFT JOIN ".$db->tableName('page')." AS tmpSelectCatPage ON tmpSelectCat.cl_from = tmpSelectCatPage.page_id ".
 
201
                        "WHERE tmpSelectCat.cl_to LIKE '$m_root' AND tmpSelectCatPage.page_namespace = $ns";
 
202
 
 
203
 
 
204
        $res = $db->query($m_sql,__METHOD__ );
 
205
 
 
206
        $ret = "";
 
207
        $i=0;
 
208
        while ( ( $row = $db->fetchObject( $res ) ) ) {
 
209
                $ret .= $row->title ."\n";
 
210
                $sub = explode("\n",wfSajaxSearchCategoryChildrenFCKeditor($row->title));
 
211
                foreach($sub as $subrow)if(strlen($subrow)>0)$ret.=" ".$subrow."\n";
 
212
 
 
213
        }
 
214
 
 
215
        return $ret;
 
216
}
 
217
 
 
218
function wfSajaxSearchTemplateFCKeditor($empty) {
 
219
        global $wgContLang, $wgOut;
 
220
        $ns = NS_TEMPLATE;
 
221
 
 
222
        $db = wfGetDB( DB_SLAVE );
 
223
        $options['ORDER BY'] = 'page_title';
 
224
        $res = $db->select( 'page', 'page_title',
 
225
        array( 'page_namespace' => $ns),
 
226
        "wfSajaxSearch",
 
227
        $options
 
228
        );
 
229
 
 
230
        $ret = "";
 
231
        while ( $row = $db->fetchObject( $res ) ) {
 
232
                $ret .= $row->page_title ."\n";
 
233
        }
 
234
 
 
235
        return $ret;
 
236
}
 
237
 
 
238
function wfSajaxWikiToHTML( $wiki ) {
 
239
        global $wgTitle;
 
240
 
 
241
        $options = new FCKeditorParserOptions();
 
242
        $options->setTidy(true);
 
243
        $parser = new FCKeditorParser();
 
244
        $parser->setOutputType(OT_HTML);
 
245
 
 
246
        wfSajaxToggleFCKeditor('show');         //FCKeditor was switched to visible
 
247
        return str_replace("<!-- Tidy found serious XHTML errors -->", "", $parser->parse($wiki, $wgTitle, $options)->getText());
 
248
}
 
249
 
 
250
function wfSajaxToggleFCKeditor($data) {
 
251
        global $wgFCKEditorSaveUserSetting;
 
252
 
 
253
        if($data == 'show'){
 
254
                $_SESSION['showMyFCKeditor'] = RTE_VISIBLE;     //visible last time
 
255
        }
 
256
        else {
 
257
                $_SESSION['showMyFCKeditor'] = 0;       //invisible
 
258
        }
 
259
        return "SUCCESS";
 
260
}