* Fix notice in PHP output mode
[lhc/web/wiklou.git] / includes / SpecialAllmessages.php
1 <?php
2
3 function wfSpecialAllmessages()
4 {
5 global $wgOut, $wgAllMessagesEn, $wgRequest, $wgMessageCache, $wgTitle;
6 $ot = $wgRequest->getText('ot');
7 $mwMsg =& MagicWord::get( MAG_MSG );
8 set_time_limit(0);
9 $navText = wfMsg( 'allmessagestext', $mwMsg->getSynonym( 0 ) );
10 $first = true;
11 $sortedArray = $wgAllMessagesEn;
12 ksort( $sortedArray );
13 $messages = array();
14 $wgMessageCache->disableTransform();
15 foreach ( $sortedArray as $key => $enMsg ) {
16 $messages[$key]['enmsg'] = $enMsg;
17 $messages[$key]['statmsg'] = wfMsgNoDb( $key );
18 $messages[$key]['msg'] = wfMsg ( $key );
19 }
20 if ($ot == 'html') {
21 $wgOut->addHTML( '<a href="'.$wgTitle->escapeLocalUrl('ot=php').'">PHP</a> | HTML' );
22 $wgOut->addWikiText( $navText );
23 $wgOut->addHTML( makeHTMLText( $messages ) );
24 } else {
25 $navText .= makePhp($messages);
26 $wgOut->addHTML('PHP | <a href="'.$wgTitle->escapeLocalUrl('ot=html').'">HTML</a><pre>'.htmlspecialchars($navText).'</pre>');
27 }
28 return;
29 }
30 function makePhp($messages) {
31 global $wgLanguageCode;
32 $txt = "\n\n".'$wgAllMessages'.ucfirst($wgLanguageCode).' = array('."\n";
33 foreach( $messages as $key => $m ) {
34 if(strtolower($wgLanguageCode) != 'en' and $m['msg'] == $m['enmsg'] ) {
35 if (strstr($m['msg'],"\n")) {
36 $txt.='/* ';
37 $comment=' */';
38 } else {
39 $txt .= '#';
40 $comment = '';
41 }
42 } elseif ($m['msg'] == '&lt;'.$key.'&gt;'){
43 $m['msg'] = '';
44 $comment = ' #empty';
45 } else {
46 $comment = '';
47 }
48 $txt .= "'".$key."' => \"".str_replace('"','\"',$m['msg'])."\",$comment\n";
49 }
50 $txt .= ');';
51 return $txt;
52 }
53
54 function makeHTMLText( $messages ) {
55 global $wgLang, $wgUser;
56 $sk =& $wgUser->getSkin();
57 $talk = $wgLang->getNsText( NS_TALK );
58 $mwnspace = $wgLang->getNsText( NS_MEDIAWIKI );
59 $mwtalk = $wgLang->getNsText( NS_MEDIAWIKI_TALK );
60 $txt = "
61
62 <table border='1' cellspacing='0' width='100%'>
63 <tr bgcolor='#b2b2ff'>
64 <th>Name</th>
65 <th>Default text</th>
66 <th>Current text</th>
67 </tr>";
68
69 # This is a nasty hack to avoid doing independent existence checks
70 # without sending the links and table through the slow wiki parser.
71 $pageExists = array(
72 NS_MEDIAWIKI => array(),
73 NS_MEDIAWIKI_TALK => array()
74 );
75 $sql = "SELECT cur_namespace,cur_title FROM cur WHERE cur_namespace IN (" . NS_MEDIAWIKI . ", " . NS_MEDIAWIKI_TALK . ")";
76 $dbr =& wfGetDB( DB_SLAVE );
77 $res = $dbr->query( $sql );
78 while( $s = $dbr->fetchObject( $res ) ) {
79 $pageExists[$s->cur_namespace][$s->cur_title] = true;
80 }
81 $dbr->freeResult( $res );
82
83 foreach( $messages as $key => $m ) {
84 $titleObj = Title::makeTitle( NS_MEDIAWIKI, $key );
85 $talkPage = Title::makeTitle( NS_MEDIAWIKI_TALK, $key );
86 $title = $titleObj->getDBkey();
87
88 $colorIt = ($m['statmsg'] == $m['msg']) ? " bgcolor=\"#f0f0ff\"" : " bgcolor=\"#ffe2e2\"";
89 $message = htmlspecialchars( $m['statmsg'] );
90 $mw = htmlspecialchars( $m['msg'] );
91
92 #$pageLink = $sk->makeLinkObj( $titleObj, htmlspecialchars( $key ) );
93 #$talkLink = $sk->makeLinkObj( $talkPage, htmlspecialchars( $talk ) );
94 if( isset( $pageExists[NS_MEDIAWIKI][$title] ) ) {
95 $pageLink = $sk->makeKnownLinkObj( $titleObj, htmlspecialchars( $key ) );
96 } else {
97 $pageLink = $sk->makeBrokenLinkObj( $titleObj, htmlspecialchars( $key ) );
98 }
99 if( isset( $pageExists[NS_MEDIAWIKI_TALK][$title] ) ) {
100 $talkLink = $sk->makeKnownLinkObj( $talkPage, htmlspecialchars( $talk ) );
101 } else {
102 $talkLink = $sk->makeBrokenLinkObj( $talkPage, htmlspecialchars( $talk ) );
103 }
104
105 $txt .=
106 "<tr$colorIt><td>
107 $pageLink<br />
108 $talkLink
109 </td><td>
110 $message
111 </td><td>
112 $mw
113 </td></tr>";
114 }
115 $txt .= "</table>";
116
117 return $txt;
118 }
119
120 ?>