didn't mean to commit that comment
[lhc/web/wiklou.git] / includes / SpecialAllmessages.php
1 <?php
2 /**
3 * Provide functions to generate a special page
4 * @package MediaWiki
5 * @subpackage SpecialPage
6 */
7
8 /**
9 *
10 */
11 function wfSpecialAllmessages() {
12 global $wgOut, $wgAllMessagesEn, $wgRequest, $wgMessageCache, $wgTitle;
13 global $wgLanguageCode, $wgContLanguageCode, $wgContLang;
14 global $wgUseDatabaseMessages;
15
16 if(!$wgUseDatabaseMessages) {
17 $wgOut->addHTML(wfMsg('allmessagesnotsupportedDB'));
18 return;
19 }
20
21 $fname = "wfSpecialAllMessages";
22 wfProfileIn( $fname );
23
24 wfProfileIn( "$fname-setup");
25 $ot = $wgRequest->getText( 'ot' );
26 $mwMsg =& MagicWord::get( MAG_MSG );
27
28 $navText = wfMsg( 'allmessagestext', $mwMsg->getSynonym( 0 ) );
29
30
31 $first = true;
32 $sortedArray = $wgAllMessagesEn;
33 ksort( $sortedArray );
34 $messages = array();
35 $wgMessageCache->disableTransform();
36
37 foreach ( $sortedArray as $key => $enMsg ) {
38 $messages[$key]['enmsg'] = $enMsg;
39 $messages[$key]['statmsg'] = wfMsgNoDb( $key );
40 $messages[$key]['msg'] = wfMsg ( $key );
41 }
42
43 $wgMessageCache->enableTransform();
44 wfProfileOut( "$fname-setup" );
45
46 wfProfileIn( "$fname-output" );
47 if ($ot == 'php') {
48 $navText .= makePhp($messages);
49 $wgOut->addHTML('PHP | <a href="'.$wgTitle->escapeLocalUrl('ot=html').'">HTML</a><pre>'.htmlspecialchars($navText).'</pre>');
50 } else {
51 $wgOut->addHTML( '<a href="'.$wgTitle->escapeLocalUrl('ot=php').'">PHP</a> | HTML' );
52 $wgOut->addWikiText( $navText );
53 $wgOut->addHTML( makeHTMLText( $messages ) );
54 }
55 wfProfileOut( "$fname-output" );
56
57 wfProfileOut( $fname );
58 }
59
60 /**
61 *
62 */
63 function makePhp($messages) {
64 global $wgLanguageCode;
65 $txt = "\n\n".'$wgAllMessages'.ucfirst($wgLanguageCode).' = array('."\n";
66 foreach( $messages as $key => $m ) {
67 if(strtolower($wgLanguageCode) != 'en' and $m['msg'] == $m['enmsg'] ) {
68 if (strstr($m['msg'],"\n")) {
69 $txt.='/* ';
70 $comment=' */';
71 } else {
72 $txt .= '#';
73 $comment = '';
74 }
75 } elseif ($m['msg'] == '&lt;'.$key.'&gt;'){
76 $m['msg'] = '';
77 $comment = ' #empty';
78 } else {
79 $comment = '';
80 }
81 $txt .= "'".$key."' => \"".str_replace('"','\"',$m['msg'])."\",$comment\n";
82 }
83 $txt .= ');';
84 return $txt;
85 }
86
87 /**
88 *
89 */
90 function makeHTMLText( $messages ) {
91 global $wgLang, $wgUser, $wgLanguageCode, $wgContLanguageCode, $wgContLang;
92 $fname = "makeHTMLText";
93 wfProfileIn( $fname );
94
95 $sk =& $wgUser->getSkin();
96 $talk = $wgLang->getNsText( NS_TALK );
97 $mwnspace = $wgLang->getNsText( NS_MEDIAWIKI );
98 $mwtalk = $wgLang->getNsText( NS_MEDIAWIKI_TALK );
99 $txt = "
100
101 <table border='1' cellspacing='0' width='100%'>
102 <tr bgcolor='#b2b2ff'>
103 <th>" . wfMsg('allmessagesname') . "</th>
104 <th>" . wfMsg('allmessagesdefault') . "</th>
105 <th>" . wfMsg('allmessagescurrent') . "</th>
106 </tr>";
107
108 wfProfileIn( "$fname-check" );
109 # This is a nasty hack to avoid doing independent existence checks
110 # without sending the links and table through the slow wiki parser.
111 $pageExists = array(
112 NS_MEDIAWIKI => array(),
113 NS_MEDIAWIKI_TALK => array()
114 );
115 $dbr =& wfGetDB( DB_SLAVE );
116 $page = $dbr->tableName( 'page' );
117 $sql = "SELECT page_namespace,page_title FROM $page WHERE page_namespace IN (" . NS_MEDIAWIKI . ", " . NS_MEDIAWIKI_TALK . ")";
118 $res = $dbr->query( $sql );
119 while( $s = $dbr->fetchObject( $res ) ) {
120 $pageExists[$s->page_namespace][$s->page_title] = true;
121 }
122 $dbr->freeResult( $res );
123 wfProfileOut( "$fname-check" );
124
125 wfProfileIn( "$fname-output" );
126
127 foreach( $messages as $key => $m ) {
128
129 $title = $wgLang->ucfirst( $key );
130 if($wgLanguageCode != $wgContLanguageCode)
131 $title.="/$wgLanguageCode";
132
133 $titleObj =& Title::makeTitle( NS_MEDIAWIKI, $title );
134 $talkPage =& Title::makeTitle( NS_MEDIAWIKI_TALK, $title );
135
136 $colorIt = ($m['statmsg'] == $m['msg']) ? " bgcolor=\"#f0f0ff\"" : " bgcolor=\"#ffe2e2\"";
137 $message = htmlspecialchars( $m['statmsg'] );
138 $mw = htmlspecialchars( $m['msg'] );
139
140 #$pageLink = $sk->makeLinkObj( $titleObj, htmlspecialchars( $key ) );
141 #$talkLink = $sk->makeLinkObj( $talkPage, htmlspecialchars( $talk ) );
142 if( isset( $pageExists[NS_MEDIAWIKI][$title] ) ) {
143 $pageLink = $sk->makeKnownLinkObj( $titleObj, htmlspecialchars( $key ) );
144 } else {
145 $pageLink = $sk->makeBrokenLinkObj( $titleObj, htmlspecialchars( $key ) );
146 }
147 if( isset( $pageExists[NS_MEDIAWIKI_TALK][$title] ) ) {
148 $talkLink = $sk->makeKnownLinkObj( $talkPage, htmlspecialchars( $talk ) );
149 } else {
150 $talkLink = $sk->makeBrokenLinkObj( $talkPage, htmlspecialchars( $talk ) );
151 }
152
153 $txt .=
154 "<tr$colorIt><td>
155 $pageLink<br />
156 $talkLink
157 </td><td>
158 $message
159 </td><td>
160 $mw
161 </td></tr>";
162 }
163 $txt .= "</table>";
164 wfProfileOut( "$fname-output" );
165
166 wfProfileOut( $fname );
167 return $txt;
168 }
169
170 ?>