6e0e7a924bb0948be9229703cd45af8569789d4b
[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 $fname = "wfSpecialAllMessages";
15 wfProfileIn( $fname );
16
17 wfProfileIn( "$fname-setup");
18 $ot = $wgRequest->getText( 'ot' );
19 $mwMsg =& MagicWord::get( MAG_MSG );
20
21 $navText = wfMsg( 'allmessagestext', $mwMsg->getSynonym( 0 ) );
22
23 if($wgLanguageCode != $wgContLanguageCode &&
24 !in_array($wgLanguageCode, $wgContLang->getVariants())) {
25 $err = wfMsg('allmessagesnotsupported');
26 $wgOut->addHTML( $err );
27 return;
28 }
29
30 $first = true;
31 $sortedArray = $wgAllMessagesEn;
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."' => \"".str_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;
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
100 <table border='1' cellspacing='0' width='100%'>
101 <tr bgcolor='#b2b2ff'>
102 <th>Name</th>
103 <th>Default text</th>
104 <th>Current text</th>
105 </tr>";
106
107 wfProfileIn( "$fname-check" );
108 # This is a nasty hack to avoid doing independent existence checks
109 # without sending the links and table through the slow wiki parser.
110 $pageExists = array(
111 NS_MEDIAWIKI => array(),
112 NS_MEDIAWIKI_TALK => array()
113 );
114 $sql = "SELECT cur_namespace,cur_title FROM cur WHERE cur_namespace IN (" . NS_MEDIAWIKI . ", " . NS_MEDIAWIKI_TALK . ")";
115 $dbr =& wfGetDB( DB_SLAVE );
116 $res = $dbr->query( $sql );
117 while( $s = $dbr->fetchObject( $res ) ) {
118 $pageExists[$s->cur_namespace][$s->cur_title] = true;
119 }
120 $dbr->freeResult( $res );
121 wfProfileOut( "$fname-check" );
122
123 wfProfileIn( "$fname-output" );
124 foreach( $messages as $key => $m ) {
125
126 $title = $wgLang->ucfirst( $key )."/$wgLanguageCode";
127 $titleObj =& Title::makeTitle( NS_MEDIAWIKI, $title );
128 $talkPage =& Title::makeTitle( NS_MEDIAWIKI_TALK, $title );
129
130 $colorIt = ($m['statmsg'] == $m['msg']) ? " bgcolor=\"#f0f0ff\"" : " bgcolor=\"#ffe2e2\"";
131 $message = htmlspecialchars( $m['statmsg'] );
132 $mw = htmlspecialchars( $m['msg'] );
133
134 #$pageLink = $sk->makeLinkObj( $titleObj, htmlspecialchars( $key ) );
135 #$talkLink = $sk->makeLinkObj( $talkPage, htmlspecialchars( $talk ) );
136 if( isset( $pageExists[NS_MEDIAWIKI][$title] ) ) {
137 $pageLink = $sk->makeKnownLinkObj( $titleObj, htmlspecialchars( $key ) );
138 } else {
139 $pageLink = $sk->makeBrokenLinkObj( $titleObj, htmlspecialchars( $key ) );
140 }
141 if( isset( $pageExists[NS_MEDIAWIKI_TALK][$title] ) ) {
142 $talkLink = $sk->makeKnownLinkObj( $talkPage, htmlspecialchars( $talk ) );
143 } else {
144 $talkLink = $sk->makeBrokenLinkObj( $talkPage, htmlspecialchars( $talk ) );
145 }
146
147 $txt .=
148 "<tr$colorIt><td>
149 $pageLink<br />
150 $talkLink
151 </td><td>
152 $message
153 </td><td>
154 $mw
155 </td></tr>";
156 }
157 $txt .= "</table>";
158 wfProfileOut( "$fname-output" );
159
160 wfProfileOut( $fname );
161 return $txt;
162 }
163
164 ?>