42dd1a10eefe94dbcb83a52f62d622c854bed17e
[lhc/web/wiklou.git] / includes / GlobalFunctions.php
1 <?
2 # Global functions used everywhere
3
4 $wgNumberOfArticles = -1; # Unset
5 $wgTotalViews = -1;
6 $wgTotalEdits = -1;
7
8 global $IP;
9 include_once( "$IP/DatabaseFunctions.php" );
10 include_once( "$IP/UpdateClasses.php" );
11 include_once( "$IP/LogPage.php" );
12
13 # PHP 4.1+ has array_key_exists, PHP 4.0.6 has key_exists instead, and earlier
14 # versions of PHP have neither. So we roll our own. Note that this
15 # function will return false even for keys that exist but whose associated
16 # value is NULL.
17 #
18 if ( phpversion() == "4.0.6" ) {
19 function array_key_exists( $k, $a ) {
20 return key_exists( $k, $a );
21 }
22 } else if (phpversion() < "4.1") {
23 function array_key_exists( $k, $a ) {
24 return isset($a[$k]);
25 }
26 }
27
28 $wgRandomSeeded = false;
29
30 function wfSeedRandom()
31 {
32 global $wgRandomSeeded;
33
34 if ( ! $wgRandomSeeded ) {
35 $seed = hexdec(substr(md5(microtime()),-8)) & 0x7fffffff;
36 mt_srand( $seed );
37 $wgRandomSeeded = true;
38 }
39 }
40
41 function wfLocalUrl( $a, $q = "" )
42 {
43 global $wgServer, $wgScript, $wgArticlePath;
44
45 $a = str_replace( " ", "_", $a );
46 #$a = wfUrlencode( $a ); # This stuff is _already_ URL-encoded.
47
48 if ( "" == $a ) {
49 if( "" == $q ) {
50 $a = $wgScript;
51 } else {
52 $a = "{$wgScript}?{$q}";
53 }
54 } else if ( "" == $q ) {
55 $a = str_replace( "$1", $a, $wgArticlePath );
56 } else {
57 $a = "{$wgScript}?title={$a}&{$q}";
58 }
59 return $a;
60 }
61
62 function wfLocalUrlE( $a, $q = "" )
63 {
64 return wfEscapeHTML( wfLocalUrl( $a, $q ) );
65 }
66
67 function wfFullUrl( $a, $q = "" ) {
68 global $wgServer;
69 return $wgServer . wfLocalUrl( $a, $q );
70 }
71
72 function wfFullUrlE( $a, $q = "" ) {
73 return wfEscapeHTML( wfFullUrl( $a, $q ) );
74 }
75
76 function wfImageUrl( $img )
77 {
78 global $wgUploadPath;
79
80 $nt = Title::newFromText( $img );
81 $name = $nt->getDBkey();
82 $hash = md5( $name );
83
84 $url = "{$wgUploadPath}/" . $hash{0} . "/" .
85 substr( $hash, 0, 2 ) . "/{$name}";
86 return wfUrlencode( $url );
87 }
88
89 function wfImageArchiveUrl( $name )
90 {
91 global $wgUploadPath;
92
93 $hash = md5( substr( $name, 15) );
94 $url = "{$wgUploadPath}/archive/" . $hash{0} . "/" .
95 substr( $hash, 0, 2 ) . "/{$name}";
96 return $url;
97 }
98
99 function wfUrlencode ( $s )
100 {
101 $ulink = urlencode( $s );
102 $ulink = preg_replace( "/%3[Aa]/", ":", $ulink );
103 $ulink = preg_replace( "/%2[Ff]/", "/", $ulink );
104 return $ulink;
105 }
106
107 function wfUtf8Sequence($codepoint) {
108 if($codepoint < 0x80) return chr($codepoint);
109 if($codepoint < 0x800) return chr($codepoint >> 6 & 0x3f | 0xc0) .
110 chr($codepoint & 0x3f | 0x80);
111 if($codepoint < 0x10000) return chr($codepoint >> 12 & 0x0f | 0xe0) .
112 chr($codepoint >> 6 & 0x3f | 0x80) .
113 chr($codepoint & 0x3f | 0x80);
114 if($codepoint < 0x100000) return chr($codepoint >> 18 & 0x07 | 0xf0) . # Double-check this
115 chr($codepoint >> 12 & 0x3f | 0x80) .
116 chr($codepoint >> 6 & 0x3f | 0x80) .
117 chr($codepoint & 0x3f | 0x80);
118 # Doesn't yet handle outside the BMP
119 return "&#$codepoint;";
120 }
121
122 function wfMungeToUtf8($string) {
123 global $wgInputEncoding; # This is debatable
124 #$string = iconv($wgInputEncoding, "UTF-8", $string);
125 $string = preg_replace ( '/&#([0-9]+);/e', 'wfUtf8Sequence($1)', $string );
126 $string = preg_replace ( '/&#x([0-9a-f]+);/ie', 'wfUtf8Sequence(0x$1)', $string );
127 # Should also do named entities here
128 return $string;
129 }
130
131 function wfDebug( $text, $logonly = false )
132 {
133 global $wgOut, $wgDebugLogFile, $wgDebugComments;
134
135 if ( $wgDebugComments && !$logonly ) {
136 $wgOut->debug( $text );
137 }
138 if ( "" != $wgDebugLogFile ) {
139 error_log( $text, 3, $wgDebugLogFile );
140 }
141 }
142
143 function wfReadOnly()
144 {
145 global $wgReadOnlyFile;
146
147 if ( "" == $wgReadOnlyFile ) { return false; }
148 return is_file( $wgReadOnlyFile );
149 }
150
151 $wgReplacementKeys = array( "$1", "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9" );
152
153 # Get a message from anywhere
154 function wfMsg( $key ) {
155 $args = func_get_args();
156 if ( count( $args ) ) {
157 array_shift( $args );
158 }
159 return wfMsgReal( $key, $args, true );
160 }
161
162 # Get a message from the language file
163 function wfMsgNoDB( $key ) {
164 $args = func_get_args();
165 if ( count( $args ) ) {
166 array_shift( $args );
167 }
168 return wfMsgReal( $key, $args, false );
169 }
170
171 # Really get a message
172 function wfMsgReal( $key, $args, $useDB ) {
173 global $wgLang, $wgReplacementKeys, $wgMemc, $wgDBname;
174 global $wgUseDatabaseMessages, $wgUseMemCached, $wgOut;
175 global $wgAllMessagesEn, $wgLanguageCode;
176
177 $fname = "wfMsg";
178 wfProfileIn( $fname );
179
180 static $messageCache = false;
181 $memcKey = "$wgDBname:messages";
182 $fname = "wfMsg";
183 $message = false;
184
185 # newFromText is too slow!
186 $title = ucfirst( $key );
187 if ( $messageCache ) {
188 $message = $messageCache[$title];
189 } elseif ( !$wgUseDatabaseMessages || !$useDB ) {
190 $message = $wgLang->getMessage( $key );
191 }
192
193 if ( !$message && $wgUseMemCached ) {
194 # Try memcached
195 if ( !$messageCache ) {
196 $messageCache = $wgMemc->get( $memcKey );
197 }
198
199 # If there's nothing in memcached, load all the messages from the database
200 # This should only happen on server reset -- ordinary changes should update
201 # memcached in editUpdates()
202 if ( !$messageCache ) {
203 # Other threads don't need to load the messages if another thread is doing it.
204 $wgMemc->set( $memcKey, "loading", time() + 60 );
205 $messageCache = wfLoadAllMessages();
206 # Save in memcached
207 $wgMemc->set( $memcKey, $messageCache, time() + 3600 );
208
209
210 }
211 if ( is_array( $messageCache ) && array_key_exists( $title, $messageCache ) ) {
212 $message = $messageCache[$title];
213 }
214 }
215
216 # If there was no MemCached, load each message from the DB individually
217 if ( !$message ) {
218 if ( $useDB ) {
219 $sql = "SELECT cur_text FROM cur WHERE cur_namespace=" . NS_MEDIAWIKI .
220 " AND cur_title='$title'";
221 $res = wfQuery( $sql, DB_READ, $fname );
222
223 if ( wfNumRows( $res ) ) {
224 $obj = wfFetchObject( $res );
225 $message = $obj->cur_text;
226 wfFreeResult( $res );
227 }
228 }
229 }
230
231 # Try the array in $wgLang
232 if ( !$message ) {
233 $message = $wgLang->getMessage( $key );
234 }
235
236 # Try the English array
237 if ( !$message && $wgLanguageCode != "en" ) {
238 $message = Language::getMessage( $key );
239 }
240
241 # Replace arguments
242 if( count( $args ) ) {
243 $message = str_replace( $wgReplacementKeys, $args, $message );
244 }
245 wfProfileOut( $fname );
246 if ( !$message ) {
247 # Failed, message does not exist
248 return "&lt;$key&gt;";
249 }
250 return $message;
251 }
252
253 function wfCleanFormFields( $fields )
254 {
255 global $HTTP_POST_VARS;
256 global $wgInputEncoding, $wgOutputEncoding, $wgEditEncoding, $wgLang;
257
258 if ( get_magic_quotes_gpc() ) {
259 foreach ( $fields as $fname ) {
260 if ( isset( $HTTP_POST_VARS[$fname] ) ) {
261 $HTTP_POST_VARS[$fname] = stripslashes(
262 $HTTP_POST_VARS[$fname] );
263 }
264 global ${$fname};
265 if ( isset( ${$fname} ) ) {
266 ${$fname} = stripslashes( ${$fname} );
267 }
268 }
269 }
270 $enc = $wgOutputEncoding;
271 if( $wgEditEncoding != "") $enc = $wgEditEncoding;
272 if ( $enc != $wgInputEncoding ) {
273 foreach ( $fields as $fname ) {
274 if ( isset( $HTTP_POST_VARS[$fname] ) ) {
275 $HTTP_POST_VARS[$fname] = $wgLang->iconv(
276 $wgOutputEncoding, $wgInputEncoding,
277 $HTTP_POST_VARS[$fname] );
278 }
279 global ${$fname};
280 if ( isset( ${$fname} ) ) {
281 ${$fname} = $wgLang->iconv(
282 $enc, $wgInputEncoding, ${$fname} );
283 }
284 }
285 }
286 }
287
288 function wfMungeQuotes( $in )
289 {
290 $out = str_replace( "%", "%25", $in );
291 $out = str_replace( "'", "%27", $out );
292 $out = str_replace( "\"", "%22", $out );
293 return $out;
294 }
295
296 function wfDemungeQuotes( $in )
297 {
298 $out = str_replace( "%22", "\"", $in );
299 $out = str_replace( "%27", "'", $out );
300 $out = str_replace( "%25", "%", $out );
301 return $out;
302 }
303
304 function wfCleanQueryVar( $var )
305 {
306 global $wgLang;
307 if ( get_magic_quotes_gpc() ) {
308 $var = stripslashes( $var );
309 }
310 return $wgLang->recodeInput( $var );
311 }
312
313 function wfSpecialPage()
314 {
315 global $wgUser, $wgOut, $wgTitle, $wgLang;
316
317 /* FIXME: this list probably shouldn't be language-specific, per se */
318 $validSP = $wgLang->getValidSpecialPages();
319 $sysopSP = $wgLang->getSysopSpecialPages();
320 $devSP = $wgLang->getDeveloperSpecialPages();
321
322 $wgOut->setArticleFlag( false );
323 $wgOut->setRobotpolicy( "noindex,follow" );
324
325 $par = NULL;
326 list($t, $par) = split( "/", $wgTitle->getDBkey(), 2 );
327
328 if ( array_key_exists( $t, $validSP ) ||
329 ( $wgUser->isSysop() && array_key_exists( $t, $sysopSP ) ) ||
330 ( $wgUser->isDeveloper() && array_key_exists( $t, $devSP ) ) ) {
331 if($par !== NULL)
332 $wgTitle = Title::makeTitle( Namespace::getSpecial(), $t );
333
334 $wgOut->setPageTitle( wfMsg( strtolower( $wgTitle->getText() ) ) );
335
336 $inc = "Special" . $t . ".php";
337 include_once( $inc );
338 $call = "wfSpecial" . $t;
339 $call( $par );
340 } else if ( array_key_exists( $t, $sysopSP ) ) {
341 $wgOut->sysopRequired();
342 } else if ( array_key_exists( $t, $devSP ) ) {
343 $wgOut->developerRequired();
344 } else {
345 $wgOut->errorpage( "nosuchspecialpage", "nospecialpagetext" );
346 }
347 }
348
349 function wfSearch( $s )
350 {
351 $se = new SearchEngine( wfCleanQueryVar( $s ) );
352 $se->showResults();
353 }
354
355 function wfGo( $s )
356 { # pick the nearest match
357 $se = new SearchEngine( wfCleanQueryVar( $s ) );
358 $se->goResult();
359 }
360
361 function wfNumberOfArticles()
362 {
363 global $wgNumberOfArticles;
364
365 wfLoadSiteStats();
366 return $wgNumberOfArticles;
367 }
368
369 /* private */ function wfLoadSiteStats()
370 {
371 global $wgNumberOfArticles, $wgTotalViews, $wgTotalEdits;
372 if ( -1 != $wgNumberOfArticles ) return;
373
374 $sql = "SELECT ss_total_views, ss_total_edits, ss_good_articles " .
375 "FROM site_stats WHERE ss_row_id=1";
376 $res = wfQuery( $sql, DB_READ, "wfLoadSiteStats" );
377
378 if ( 0 == wfNumRows( $res ) ) { return; }
379 else {
380 $s = wfFetchObject( $res );
381 $wgTotalViews = $s->ss_total_views;
382 $wgTotalEdits = $s->ss_total_edits;
383 $wgNumberOfArticles = $s->ss_good_articles;
384 }
385 }
386
387 function wfEscapeHTML( $in )
388 {
389 return str_replace(
390 array( "&", "\"", ">", "<" ),
391 array( "&amp;", "&quot;", "&gt;", "&lt;" ),
392 $in );
393 }
394
395 function wfEscapeHTMLTagsOnly( $in ) {
396 return str_replace(
397 array( "\"", ">", "<" ),
398 array( "&quot;", "&gt;", "&lt;" ),
399 $in );
400 }
401
402 function wfUnescapeHTML( $in )
403 {
404 $in = str_replace( "&lt;", "<", $in );
405 $in = str_replace( "&gt;", ">", $in );
406 $in = str_replace( "&quot;", "\"", $in );
407 $in = str_replace( "&amp;", "&", $in );
408 return $in;
409 }
410
411 function wfImageDir( $fname )
412 {
413 global $wgUploadDirectory;
414
415 $hash = md5( $fname );
416 $oldumask = umask(0);
417 $dest = $wgUploadDirectory . "/" . $hash{0};
418 if ( ! is_dir( $dest ) ) { mkdir( $dest, 0777 ); }
419 $dest .= "/" . substr( $hash, 0, 2 );
420 if ( ! is_dir( $dest ) ) { mkdir( $dest, 0777 ); }
421
422 umask( $oldumask );
423 return $dest;
424 }
425
426 function wfImageArchiveDir( $fname )
427 {
428 global $wgUploadDirectory;
429
430 $hash = md5( $fname );
431 $oldumask = umask(0);
432 $archive = "{$wgUploadDirectory}/archive";
433 if ( ! is_dir( $archive ) ) { mkdir( $archive, 0777 ); }
434 $archive .= "/" . $hash{0};
435 if ( ! is_dir( $archive ) ) { mkdir( $archive, 0777 ); }
436 $archive .= "/" . substr( $hash, 0, 2 );
437 if ( ! is_dir( $archive ) ) { mkdir( $archive, 0777 ); }
438
439 umask( $oldumask );
440 return $archive;
441 }
442
443 function wfRecordUpload( $name, $oldver, $size, $desc )
444 {
445 global $wgUser, $wgLang, $wgTitle, $wgOut, $wgDeferredUpdateList;
446 global $wgUseCopyrightUpload , $wpUploadCopyStatus , $wpUploadSource ;
447
448 $fname = "wfRecordUpload";
449
450 $sql = "SELECT img_name,img_size,img_timestamp,img_description,img_user," .
451 "img_user_text FROM image WHERE img_name='" . wfStrencode( $name ) . "'";
452 $res = wfQuery( $sql, DB_READ, $fname );
453
454 $now = wfTimestampNow();
455 $won = wfInvertTimestamp( $now );
456
457 if ( $wgUseCopyrightUpload )
458 {
459 $textdesc = "== " . wfMsg ( "filedesc" ) . " ==\n" . $desc . "\n" .
460 "== " . wfMsg ( "filestatus" ) . " ==\n" . $wpUploadCopyStatus . "\n" .
461 "== " . wfMsg ( "filesource" ) . " ==\n" . $wpUploadSource ;
462 }
463 else $textdesc = $desc ;
464
465 if ( 0 == wfNumRows( $res ) ) {
466 $sql = "INSERT INTO image (img_name,img_size,img_timestamp," .
467 "img_description,img_user,img_user_text) VALUES ('" .
468 wfStrencode( $name ) . "',{$size},'{$now}','" .
469 wfStrencode( $desc ) . "', '" . $wgUser->getID() .
470 "', '" . wfStrencode( $wgUser->getName() ) . "')";
471 wfQuery( $sql, DB_WRITE, $fname );
472
473 $sql = "SELECT cur_id,cur_text FROM cur WHERE cur_namespace=" .
474 Namespace::getImage() . " AND cur_title='" .
475 wfStrencode( $name ) . "'";
476 $res = wfQuery( $sql, DB_READ, $fname );
477 if ( 0 == wfNumRows( $res ) ) {
478 $common =
479 Namespace::getImage() . ",'" .
480 wfStrencode( $name ) . "','" .
481 wfStrencode( $desc ) . "','" . $wgUser->getID() . "','" .
482 wfStrencode( $wgUser->getName() ) . "','" . $now .
483 "',1";
484 $sql = "INSERT INTO cur (cur_namespace,cur_title," .
485 "cur_comment,cur_user,cur_user_text,cur_timestamp,cur_is_new," .
486 "cur_text,inverse_timestamp,cur_touched) VALUES (" .
487 $common .
488 ",'" . wfStrencode( $textdesc ) . "','{$won}','{$now}')";
489 wfQuery( $sql, DB_WRITE, $fname );
490 $id = wfInsertId() or 0; # We should throw an error instead
491 $sql = "INSERT INTO recentchanges (rc_namespace,rc_title,
492 rc_comment,rc_user,rc_user_text,rc_timestamp,rc_new,
493 rc_cur_id,rc_cur_time) VALUES ({$common},{$id},'{$now}')";
494 wfQuery( $sql, DB_WRITE, $fname );
495 $u = new SearchUpdate( $id, $name, $desc );
496 $u->doUpdate();
497 }
498 } else {
499 $s = wfFetchObject( $res );
500
501 $sql = "INSERT INTO oldimage (oi_name,oi_archive_name,oi_size," .
502 "oi_timestamp,oi_description,oi_user,oi_user_text) VALUES ('" .
503 wfStrencode( $s->img_name ) . "','" .
504 wfStrencode( $oldver ) .
505 "',{$s->img_size},'{$s->img_timestamp}','" .
506 wfStrencode( $s->img_description ) . "','" .
507 wfStrencode( $s->img_user ) . "','" .
508 wfStrencode( $s->img_user_text) . "')";
509 wfQuery( $sql, DB_WRITE, $fname );
510
511 $sql = "UPDATE image SET img_size={$size}," .
512 "img_timestamp='" . wfTimestampNow() . "',img_user='" .
513 $wgUser->getID() . "',img_user_text='" .
514 wfStrencode( $wgUser->getName() ) . "', img_description='" .
515 wfStrencode( $desc ) . "' WHERE img_name='" .
516 wfStrencode( $name ) . "'";
517 wfQuery( $sql, DB_WRITE, $fname );
518
519 $sql = "UPDATE cur SET cur_touched='{$now}' WHERE cur_namespace=" .
520 Namespace::getImage() . " AND cur_title='" .
521 wfStrencode( $name ) . "'";
522 wfQuery( $sql, DB_WRITE, $fname );
523 }
524
525 $log = new LogPage( wfMsg( "uploadlogpage" ), wfMsg( "uploadlogpagetext" ) );
526 $da = str_replace( "$1", "[[:" . $wgLang->getNsText(
527 Namespace::getImage() ) . ":{$name}|{$name}]]",
528 wfMsg( "uploadedimage" ) );
529 $ta = str_replace( "$1", $name, wfMsg( "uploadedimage" ) );
530 $log->addEntry( $da, $desc, $ta );
531 }
532
533
534 /* Some generic result counters, pulled out of SearchEngine */
535
536 function wfShowingResults( $offset, $limit )
537 {
538 $top = str_replace( "$1", $limit, wfMsg( "showingresults" ) );
539 $top = str_replace( "$2", $offset+1, $top );
540 return $top;
541 }
542
543 function wfShowingResultsNum( $offset, $limit, $num )
544 {
545 $top = str_replace( "$1", $limit, wfMsg( "showingresultsnum" ) );
546 $top = str_replace( "$2", $offset+1, $top );
547 $top = str_replace( "$3", $num, $top );
548 return $top;
549 }
550
551 function wfViewPrevNext( $offset, $limit, $link, $query = "" )
552 {
553 global $wgUser;
554 $prev = str_replace( "$1", $limit, wfMsg( "prevn" ) );
555 $next = str_replace( "$1", $limit, wfMsg( "nextn" ) );
556
557 $sk = $wgUser->getSkin();
558 if ( 0 != $offset ) {
559 $po = $offset - $limit;
560 if ( $po < 0 ) { $po = 0; }
561 $q = "limit={$limit}&offset={$po}";
562 if ( "" != $query ) { $q .= "&{$query}"; }
563 $plink = "<a href=\"" . wfLocalUrlE( $link, $q ) . "\">{$prev}</a>";
564 } else { $plink = $prev; }
565
566 $no = $offset + $limit;
567 $q = "limit={$limit}&offset={$no}";
568 if ( "" != $query ) { $q .= "&{$query}"; }
569
570 $nlink = "<a href=\"" . wfLocalUrlE( $link, $q ) . "\">{$next}</a>";
571 $nums = wfNumLink( $offset, 20, $link , $query ) . " | " .
572 wfNumLink( $offset, 50, $link, $query ) . " | " .
573 wfNumLink( $offset, 100, $link, $query ) . " | " .
574 wfNumLink( $offset, 250, $link, $query ) . " | " .
575 wfNumLink( $offset, 500, $link, $query );
576
577 $sl = str_replace( "$1", $plink, wfMsg( "viewprevnext" ) );
578 $sl = str_replace( "$2", $nlink, $sl );
579 $sl = str_replace( "$3", $nums, $sl );
580 return $sl;
581 }
582
583 function wfNumLink( $offset, $limit, $link, $query = "" )
584 {
585 global $wgUser;
586 if ( "" == $query ) { $q = ""; }
587 else { $q = "{$query}&"; }
588 $q .= "limit={$limit}&offset={$offset}";
589
590 $s = "<a href=\"" . wfLocalUrlE( $link, $q ) . "\">{$limit}</a>";
591 return $s;
592 }
593
594 function wfClientAcceptsGzip() {
595 global $wgUseGzip;
596 if( $wgUseGzip ) {
597 # FIXME: we may want to blacklist some broken browsers
598 if( preg_match(
599 '/\bgzip(?:;(q)=([0-9]+(?:\.[0-9]+)))?\b/',
600 $_SERVER["HTTP_ACCEPT_ENCODING"],
601 $m ) ) {
602 if( ( $m[1] == "q" ) && ( $m[2] == 0 ) ) return false;
603 wfDebug( " accepts gzip\n" );
604 return true;
605 }
606 }
607 return false;
608 }
609
610 # Yay, more global functions!
611 function wfCheckLimits( $deflimit = 50, $optionname = "rclimit" ) {
612 global $wgUser;
613
614 $limit = (int)$_REQUEST['limit'];
615 if( $limit < 0 ) $limit = 0;
616 if( ( $limit == 0 ) && ( $optionname != "" ) ) {
617 $limit = (int)$wgUser->getOption( $optionname );
618 }
619 if( $limit <= 0 ) $limit = $deflimit;
620 if( $limit > 5000 ) $limit = 5000; # We have *some* limits...
621
622 $offset = (int)$_REQUEST['offset'];
623 $offset = (int)$offset;
624 if( $offset < 0 ) $offset = 0;
625 if( $offset > 65000 ) $offset = 65000; # do we need a max? what?
626
627 return array( $limit, $offset );
628 }
629
630 # Escapes the given text so that it may be output using addWikiText()
631 # without any linking, formatting, etc. making its way through. This
632 # is achieved by substituting certain characters with HTML entities.
633 # As required by the callers, <nowiki> is not used. It currently does
634 # not filter out characters which have special meaning only at the
635 # start of a line, such as "*".
636 function wfEscapeWikiText( $text )
637 {
638 $text = str_replace(
639 array( '[', "'", 'ISBN ' , '://'),
640 array( '&#91;', '&#39;', 'ISBN&#32;', '&#58;//'),
641 htmlspecialchars($text) );
642 return $text;
643 }
644
645 # Loads the entire MediaWiki namespace, retuns the array
646 function wfLoadAllMessages()
647 {
648 $sql = "SELECT cur_title,cur_text FROM cur WHERE cur_namespace=" . NS_MEDIAWIKI;
649 $res = wfQuery( $sql, DB_READ, $fname );
650
651 $messages = array();
652 for ( $row = wfFetchObject( $res ); $row; $row = wfFetchObject( $res ) ) {
653 $messages[$row->cur_title] = $row->cur_text;
654 }
655 wfFreeResult( $res );
656 return $messages;
657 }
658 ?>