* "<tr >" => "<tr>"
[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
27 $navText = wfMsg( 'allmessagestext' );
28
29
30 $first = true;
31 $sortedArray = array_merge( $wgAllMessagesEn, $wgMessageCache->mExtensionMessages );
32 ksort( $sortedArray );
33 $messages = array();
34 $wgMessageCache->disableTransform();
35
36 foreach ( $sortedArray as $key => $enMsg ) {
37 $messages[$key]['enmsg'] = $enMsg;
38 $messages[$key]['statmsg'] = wfMsgNoDb( $key );
39 $messages[$key]['msg'] = wfMsg ( $key );
40 }
41
42 $wgMessageCache->enableTransform();
43 wfProfileOut( "$fname-setup" );
44
45 wfProfileIn( "$fname-output" );
46 if ($ot == 'php') {
47 $navText .= makePhp($messages);
48 $wgOut->addHTML('PHP | <a href="'.$wgTitle->escapeLocalUrl('ot=html').'">HTML</a><pre>'.htmlspecialchars($navText).'</pre>');
49 } else {
50 $wgOut->addHTML( '<a href="'.$wgTitle->escapeLocalUrl('ot=php').'">PHP</a> | HTML' );
51 $wgOut->addWikiText( $navText );
52 $wgOut->addHTML( makeHTMLText( $messages ) );
53 }
54 wfProfileOut( "$fname-output" );
55
56 wfProfileOut( $fname );
57 }
58
59 /**
60 *
61 */
62 function makePhp($messages) {
63 global $wgLanguageCode;
64 $txt = "\n\n".'$wgAllMessages'.ucfirst($wgLanguageCode).' = array('."\n";
65 foreach( $messages as $key => $m ) {
66 if(strtolower($wgLanguageCode) != 'en' and $m['msg'] == $m['enmsg'] ) {
67 if (strstr($m['msg'],"\n")) {
68 $txt.='/* ';
69 $comment=' */';
70 } else {
71 $txt .= '#';
72 $comment = '';
73 }
74 } elseif ($m['msg'] == '&lt;'.$key.'&gt;'){
75 $m['msg'] = '';
76 $comment = ' #empty';
77 } else {
78 $comment = '';
79 }
80 $txt .= "'$key' => '" . preg_replace( "/(?<!\\\\)'/", "\'", $m['msg']) . "',$comment\n";
81 }
82 $txt .= ');';
83 return $txt;
84 }
85
86 /**
87 *
88 */
89 function makeHTMLText( $messages ) {
90 global $wgLang, $wgUser, $wgLanguageCode, $wgContLanguageCode, $wgContLang;
91 $fname = "makeHTMLText";
92 wfProfileIn( $fname );
93
94 $sk =& $wgUser->getSkin();
95 $talk = $wgLang->getNsText( NS_TALK );
96 $mwnspace = $wgLang->getNsText( NS_MEDIAWIKI );
97 $mwtalk = $wgLang->getNsText( NS_MEDIAWIKI_TALK );
98 $txt = "
99 <table border='1' cellspacing='0' width='100%' id='allmessagestable'>
100 <tr>
101 <th rowspan='2'>" . wfMsgHtml('allmessagesname') . "</th>
102 <th>" . wfMsgHtml('allmessagesdefault') . "</th>
103 </tr>
104 <tr>
105 <th>" . wfMsgHtml('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 $changed = ($m['statmsg'] != $m['msg']);
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 if($changed) {
154
155 $txt .=
156 "<tr class='orig'>
157 <td rowspan='2'>
158 $pageLink<br />$talkLink
159 </td><td>
160 $message
161 </td>
162 </tr><tr class='new'>
163 <td>
164 $mw
165 </td>
166 </tr>";
167 } else {
168
169 $txt .=
170 "<tr class='def'>
171 <td>
172 $pageLink<br />$talkLink
173 </td><td>
174 $mw
175 </td>
176 </tr>";
177
178 }
179 }
180 $txt .= "</table>";
181 wfProfileOut( "$fname-output" );
182
183 wfProfileOut( $fname );
184 return $txt;
185 }
186
187 ?>