fix a problem by not inserting __MWTEMPLATESECTION for section titles that don't...
[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
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 $first = true;
23 $sortedArray = $wgAllMessagesEn;
24 ksort( $sortedArray );
25 $messages = array();
26 $wgMessageCache->disableTransform();
27
28 foreach ( $sortedArray as $key => $enMsg ) {
29 $messages[$key]['enmsg'] = $enMsg;
30 $messages[$key]['statmsg'] = wfMsgNoDbNoConvert( $key );
31 $messages[$key]['msg'] = wfMsgNoConvert ( $key );
32 }
33
34 $wgMessageCache->enableTransform();
35 wfProfileOut( "$fname-setup" );
36
37 wfProfileIn( "$fname-output" );
38 if ($ot == 'php') {
39 $navText .= makePhp($messages);
40 $wgOut->addHTML('PHP | <a href="'.$wgTitle->escapeLocalUrl('ot=html').'">HTML</a><pre>'.htmlspecialchars($navText).'</pre>');
41 } else {
42 $wgOut->addHTML( '<a href="'.$wgTitle->escapeLocalUrl('ot=php').'">PHP</a> | HTML' );
43 $wgOut->addWikiText( $navText );
44 $wgOut->addHTML( makeHTMLText( $messages ) );
45 }
46 wfProfileOut( "$fname-output" );
47
48 wfProfileOut( $fname );
49 }
50
51 /**
52 *
53 */
54 function makePhp($messages) {
55 global $wgLanguageCode;
56 $txt = "\n\n".'$wgAllMessages'.ucfirst($wgLanguageCode).' = array('."\n";
57 foreach( $messages as $key => $m ) {
58 if(strtolower($wgLanguageCode) != 'en' and $m['msg'] == $m['enmsg'] ) {
59 if (strstr($m['msg'],"\n")) {
60 $txt.='/* ';
61 $comment=' */';
62 } else {
63 $txt .= '#';
64 $comment = '';
65 }
66 } elseif ($m['msg'] == '&lt;'.$key.'&gt;'){
67 $m['msg'] = '';
68 $comment = ' #empty';
69 } else {
70 $comment = '';
71 }
72 $txt .= "'".$key."' => \"".str_replace('"','\"',$m['msg'])."\",$comment\n";
73 }
74 $txt .= ');';
75 return $txt;
76 }
77
78 /**
79 *
80 */
81 function makeHTMLText( $messages ) {
82 global $wgLang, $wgUser;
83 $fname = "makeHTMLText";
84 wfProfileIn( $fname );
85
86 $sk =& $wgUser->getSkin();
87 $talk = $wgLang->getNsText( NS_TALK );
88 $mwnspace = $wgLang->getNsText( NS_MEDIAWIKI );
89 $mwtalk = $wgLang->getNsText( NS_MEDIAWIKI_TALK );
90 $txt = "
91
92 <table border='1' cellspacing='0' width='100%'>
93 <tr bgcolor='#b2b2ff'>
94 <th>Name</th>
95 <th>Default text</th>
96 <th>Current text</th>
97 </tr>";
98
99 wfProfileIn( "$fname-check" );
100 # This is a nasty hack to avoid doing independent existence checks
101 # without sending the links and table through the slow wiki parser.
102 $pageExists = array(
103 NS_MEDIAWIKI => array(),
104 NS_MEDIAWIKI_TALK => array()
105 );
106 $sql = "SELECT cur_namespace,cur_title FROM cur WHERE cur_namespace IN (" . NS_MEDIAWIKI . ", " . NS_MEDIAWIKI_TALK . ")";
107 $dbr =& wfGetDB( DB_SLAVE );
108 $res = $dbr->query( $sql );
109 while( $s = $dbr->fetchObject( $res ) ) {
110 $pageExists[$s->cur_namespace][$s->cur_title] = true;
111 }
112 $dbr->freeResult( $res );
113 wfProfileOut( "$fname-check" );
114
115 wfProfileIn( "$fname-output" );
116 foreach( $messages as $key => $m ) {
117 $title = $wgLang->ucfirst( $key );
118 $titleObj =& Title::makeTitle( NS_MEDIAWIKI, $title );
119 $talkPage =& Title::makeTitle( NS_MEDIAWIKI_TALK, $title );
120
121 $colorIt = ($m['statmsg'] == $m['msg']) ? " bgcolor=\"#f0f0ff\"" : " bgcolor=\"#ffe2e2\"";
122 $message = htmlspecialchars( $m['statmsg'] );
123 $mw = htmlspecialchars( $m['msg'] );
124
125 #$pageLink = $sk->makeLinkObj( $titleObj, htmlspecialchars( $key ) );
126 #$talkLink = $sk->makeLinkObj( $talkPage, htmlspecialchars( $talk ) );
127 if( isset( $pageExists[NS_MEDIAWIKI][$title] ) ) {
128 $pageLink = $sk->makeKnownLinkObj( $titleObj, htmlspecialchars( $key ) );
129 } else {
130 $pageLink = $sk->makeBrokenLinkObj( $titleObj, htmlspecialchars( $key ) );
131 }
132 if( isset( $pageExists[NS_MEDIAWIKI_TALK][$title] ) ) {
133 $talkLink = $sk->makeKnownLinkObj( $talkPage, htmlspecialchars( $talk ) );
134 } else {
135 $talkLink = $sk->makeBrokenLinkObj( $talkPage, htmlspecialchars( $talk ) );
136 }
137
138 $txt .=
139 "<tr$colorIt><td>
140 $pageLink<br />
141 $talkLink
142 </td><td>
143 $message
144 </td><td>
145 $mw
146 </td></tr>";
147 }
148 $txt .= "</table>";
149 wfProfileOut( "$fname-output" );
150
151 wfProfileOut( $fname );
152 return $txt;
153 }
154
155 ?>