* (bug 153) Adjust thumbnail size calculations to match consistently;
[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 continue;
75 } elseif ($m['msg'] == '&lt;'.$key.'&gt;'){
76 $m['msg'] = '';
77 $comment = ' #empty';
78 } else {
79 $comment = '';
80 }
81 $txt .= "'$key' => '" . preg_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 <table border='1' cellspacing='0' width='100%' id='allmessagestable'>
101 <tr>
102 <th rowspan='2'>" . wfMsgHtml('allmessagesname') . "</th>
103 <th>" . wfMsgHtml('allmessagesdefault') . "</th>
104 </tr>
105 <tr>
106 <th>" . wfMsgHtml('allmessagescurrent') . "</th>
107 </tr>";
108
109 wfProfileIn( "$fname-check" );
110 # This is a nasty hack to avoid doing independent existence checks
111 # without sending the links and table through the slow wiki parser.
112 $pageExists = array(
113 NS_MEDIAWIKI => array(),
114 NS_MEDIAWIKI_TALK => array()
115 );
116 $dbr =& wfGetDB( DB_SLAVE );
117 $page = $dbr->tableName( 'page' );
118 $sql = "SELECT page_namespace,page_title FROM $page WHERE page_namespace IN (" . NS_MEDIAWIKI . ", " . NS_MEDIAWIKI_TALK . ")";
119 $res = $dbr->query( $sql );
120 while( $s = $dbr->fetchObject( $res ) ) {
121 $pageExists[$s->page_namespace][$s->page_title] = true;
122 }
123 $dbr->freeResult( $res );
124 wfProfileOut( "$fname-check" );
125
126 wfProfileIn( "$fname-output" );
127
128 foreach( $messages as $key => $m ) {
129
130 $title = $wgLang->ucfirst( $key );
131 if($wgLanguageCode != $wgContLanguageCode)
132 $title.="/$wgLanguageCode";
133
134 $titleObj =& Title::makeTitle( NS_MEDIAWIKI, $title );
135 $talkPage =& Title::makeTitle( NS_MEDIAWIKI_TALK, $title );
136
137 $changed = ($m['statmsg'] != $m['msg']);
138 $message = htmlspecialchars( $m['statmsg'] );
139 $mw = htmlspecialchars( $m['msg'] );
140
141 #$pageLink = $sk->makeLinkObj( $titleObj, htmlspecialchars( $key ) );
142 #$talkLink = $sk->makeLinkObj( $talkPage, htmlspecialchars( $talk ) );
143 if( isset( $pageExists[NS_MEDIAWIKI][$title] ) ) {
144 $pageLink = $sk->makeKnownLinkObj( $titleObj, htmlspecialchars( $key ) );
145 } else {
146 $pageLink = $sk->makeBrokenLinkObj( $titleObj, htmlspecialchars( $key ) );
147 }
148 if( isset( $pageExists[NS_MEDIAWIKI_TALK][$title] ) ) {
149 $talkLink = $sk->makeKnownLinkObj( $talkPage, htmlspecialchars( $talk ) );
150 } else {
151 $talkLink = $sk->makeBrokenLinkObj( $talkPage, htmlspecialchars( $talk ) );
152 }
153
154 if($changed) {
155
156 $txt .=
157 "<tr class='orig'>
158 <td rowspan='2'>
159 $pageLink<br />$talkLink
160 </td><td>
161 $message
162 </td>
163 </tr><tr class='new'>
164 <td>
165 $mw
166 </td>
167 </tr>";
168 } else {
169
170 $txt .=
171 "<tr class='def'>
172 <td>
173 $pageLink<br />$talkLink
174 </td><td>
175 $mw
176 </td>
177 </tr>";
178
179 }
180 }
181 $txt .= "</table>";
182 wfProfileOut( "$fname-output" );
183
184 wfProfileOut( $fname );
185 return $txt;
186 }
187
188 ?>