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