include sql patch
[mediawiki.git] / includes / SpecialAllmessages.php
blob6e0e7a924bb0948be9229703cd45af8569789d4b
1 <?php
2 /**
3 * Provide functions to generate a special page
4 * @package MediaWiki
5 * @subpackage SpecialPage
6 */
8 /**
11 function wfSpecialAllmessages() {
12 global $wgOut, $wgAllMessagesEn, $wgRequest, $wgMessageCache, $wgTitle;
13 global $wgLanguageCode, $wgContLanguageCode, $wgContLang;
14 $fname = "wfSpecialAllMessages";
15 wfProfileIn( $fname );
17 wfProfileIn( "$fname-setup");
18 $ot = $wgRequest->getText( 'ot' );
19 $mwMsg =& MagicWord::get( MAG_MSG );
21 $navText = wfMsg( 'allmessagestext', $mwMsg->getSynonym( 0 ) );
23 if($wgLanguageCode != $wgContLanguageCode &&
24 !in_array($wgLanguageCode, $wgContLang->getVariants())) {
25 $err = wfMsg('allmessagesnotsupported');
26 $wgOut->addHTML( $err );
27 return;
30 $first = true;
31 $sortedArray = $wgAllMessagesEn;
32 ksort( $sortedArray );
33 $messages = array();
34 $wgMessageCache->disableTransform();
36 foreach ( $sortedArray as $key => $enMsg ) {
37 $messages[$key]['enmsg'] = $enMsg;
38 $messages[$key]['statmsg'] = wfMsgNoDb( $key );
39 $messages[$key]['msg'] = wfMsg ( $key );
42 $wgMessageCache->enableTransform();
43 wfProfileOut( "$fname-setup" );
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 ) );
54 wfProfileOut( "$fname-output" );
56 wfProfileOut( $fname );
59 /**
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 = '';
74 } elseif ($m['msg'] == '&lt;'.$key.'&gt;'){
75 $m['msg'] = '';
76 $comment = ' #empty';
77 } else {
78 $comment = '';
80 $txt .= "'".$key."' => \"".str_replace('"','\"',$m['msg'])."\",$comment\n";
82 $txt .= ');';
83 return $txt;
86 /**
89 function makeHTMLText( $messages ) {
90 global $wgLang, $wgUser, $wgLanguageCode;
91 $fname = "makeHTMLText";
92 wfProfileIn( $fname );
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 = "
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>";
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()
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;
120 $dbr->freeResult( $res );
121 wfProfileOut( "$fname-check" );
123 wfProfileIn( "$fname-output" );
124 foreach( $messages as $key => $m ) {
126 $title = $wgLang->ucfirst( $key )."/$wgLanguageCode";
127 $titleObj =& Title::makeTitle( NS_MEDIAWIKI, $title );
128 $talkPage =& Title::makeTitle( NS_MEDIAWIKI_TALK, $title );
130 $colorIt = ($m['statmsg'] == $m['msg']) ? " bgcolor=\"#f0f0ff\"" : " bgcolor=\"#ffe2e2\"";
131 $message = htmlspecialchars( $m['statmsg'] );
132 $mw = htmlspecialchars( $m['msg'] );
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 ) );
141 if( isset( $pageExists[NS_MEDIAWIKI_TALK][$title] ) ) {
142 $talkLink = $sk->makeKnownLinkObj( $talkPage, htmlspecialchars( $talk ) );
143 } else {
144 $talkLink = $sk->makeBrokenLinkObj( $talkPage, htmlspecialchars( $talk ) );
147 $txt .=
148 "<tr$colorIt><td>
149 $pageLink<br />
150 $talkLink
151 </td><td>
152 $message
153 </td><td>
155 </td></tr>";
157 $txt .= "</table>";
158 wfProfileOut( "$fname-output" );
160 wfProfileOut( $fname );
161 return $txt;