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