00001 <?php
00011 function wfSpecialAllmessages() {
00012 global $wgOut, $wgRequest, $wgMessageCache, $wgTitle;
00013 global $wgUseDatabaseMessages, $wgLang;
00014
00015 # The page isn't much use if the MediaWiki namespace is not being used
00016 if( !$wgUseDatabaseMessages ) {
00017 $wgOut->addWikiMsg( 'allmessagesnotsupportedDB' );
00018 return;
00019 }
00020
00021 wfProfileIn( __METHOD__ );
00022
00023 wfProfileIn( __METHOD__ . '-setup' );
00024 $ot = $wgRequest->getText( 'ot' );
00025
00026 $navText = wfMsg( 'allmessagestext' );
00027
00028 # Make sure all extension messages are available
00029
00030 $wgMessageCache->loadAllMessages();
00031
00032 $sortedArray = array_merge( Language::getMessagesFor( 'en' ),
00033 $wgMessageCache->getExtensionMessagesFor( 'en' ) );
00034 ksort( $sortedArray );
00035
00036 $messages = array();
00037 foreach( $sortedArray as $key => $value ) {
00038 $messages[$key]['enmsg'] = $value;
00039 $messages[$key]['statmsg'] = wfMsgReal( $key, array(), false, false, false );
00040 $messages[$key]['msg'] = wfMsgNoTrans( $key );
00041 $sortedArray[$key] = NULL;
00042
00043 }
00044 unset($sortedArray);
00045
00046 wfProfileOut( __METHOD__ . '-setup' );
00047
00048 wfProfileIn( __METHOD__ . '-output' );
00049 $wgOut->addScriptFile( 'allmessages.js' );
00050 if ( $ot == 'php' ) {
00051 $navText .= wfAllMessagesMakePhp( $messages );
00052 $wgOut->addHTML( $wgLang->pipeList( array(
00053 'PHP',
00054 '<a href="' . $wgTitle->escapeLocalUrl( 'ot=html' ) . '">HTML</a>',
00055 '<a href="' . $wgTitle->escapeLocalUrl( 'ot=xml' ) . '">XML</a>' .
00056 '<pre>' . htmlspecialchars( $navText ) . '</pre>'
00057 ) ) );
00058 } else if ( $ot == 'xml' ) {
00059 $wgOut->disable();
00060 header( 'Content-type: text/xml' );
00061 echo wfAllMessagesMakeXml( $messages );
00062 } else {
00063 $wgOut->addHTML( $wgLang->pipeList( array(
00064 '<a href="' . $wgTitle->escapeLocalUrl( 'ot=php' ) . '">PHP</a>',
00065 'HTML',
00066 '<a href="' . $wgTitle->escapeLocalUrl( 'ot=xml' ) . '">XML</a>'
00067 ) ) );
00068 $wgOut->addWikiText( $navText );
00069 $wgOut->addHTML( wfAllMessagesMakeHTMLText( $messages ) );
00070 }
00071 wfProfileOut( __METHOD__ . '-output' );
00072
00073 wfProfileOut( __METHOD__ );
00074 }
00075
00076 function wfAllMessagesMakeXml( &$messages ) {
00077 global $wgLang;
00078 $lang = $wgLang->getCode();
00079 $txt = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";
00080 $txt .= "<messages lang=\"$lang\">\n";
00081 foreach( $messages as $key => $m ) {
00082 $txt .= "\t" . Xml::element( 'message', array( 'name' => $key ), $m['msg'] ) . "\n";
00083 $messages[$key] = NULL;
00084 }
00085 $txt .= "</messages>";
00086 return $txt;
00087 }
00088
00095 function wfAllMessagesMakePhp( &$messages ) {
00096 global $wgLang;
00097 $txt = "\n\n\$messages = array(\n";
00098 foreach( $messages as $key => $m ) {
00099 if( $wgLang->getCode() != 'en' && $m['msg'] == $m['enmsg'] ) {
00100 continue;
00101 } else if ( wfEmptyMsg( $key, $m['msg'] ) ) {
00102 $m['msg'] = '';
00103 $comment = ' #empty';
00104 } else {
00105 $comment = '';
00106 }
00107 $txt .= "'$key' => '" . preg_replace( '/(?<!\\\\)\'/', "\'", $m['msg']) . "',$comment\n";
00108 $messages[$key] = NULL;
00109 }
00110 $txt .= ');';
00111 return $txt;
00112 }
00113
00119 function wfAllMessagesMakeHTMLText( &$messages ) {
00120 global $wgLang, $wgContLang, $wgUser;
00121 wfProfileIn( __METHOD__ );
00122
00123 $sk = $wgUser->getSkin();
00124 $talk = wfMsg( 'talkpagelinktext' );
00125
00126 $input = Xml::element( 'input', array(
00127 'type' => 'text',
00128 'id' => 'allmessagesinput',
00129 'onkeyup' => 'allmessagesfilter()'
00130 ), '' );
00131 $checkbox = Xml::element( 'input', array(
00132 'type' => 'button',
00133 'value' => wfMsgHtml( 'allmessagesmodified' ),
00134 'id' => 'allmessagescheckbox',
00135 'onclick' => 'allmessagesmodified()'
00136 ), '' );
00137
00138 $txt = '<span id="allmessagesfilter" style="display: none;">' . wfMsgHtml( 'allmessagesfilter' ) .
00139 " {$input}{$checkbox} " . '</span>';
00140
00141 $txt .= '
00142 <table border="1" cellspacing="0" width="100%" id="allmessagestable">
00143 <tr>
00144 <th rowspan="2">' . wfMsgHtml( 'allmessagesname' ) . '</th>
00145 <th>' . wfMsgHtml( 'allmessagesdefault' ) . '</th>
00146 </tr>
00147 <tr>
00148 <th>' . wfMsgHtml( 'allmessagescurrent' ) . '</th>
00149 </tr>';
00150
00151 wfProfileIn( __METHOD__ . "-check" );
00152
00153 # This is a nasty hack to avoid doing independent existence checks
00154 # without sending the links and table through the slow wiki parser.
00155 $pageExists = array(
00156 NS_MEDIAWIKI => array(),
00157 NS_MEDIAWIKI_TALK => array()
00158 );
00159 $dbr = wfGetDB( DB_SLAVE );
00160 $res = $dbr->select( 'page',
00161 array( 'page_namespace', 'page_title' ),
00162 array( 'page_namespace' => array(NS_MEDIAWIKI,NS_MEDIAWIKI_TALK) ),
00163 __METHOD__,
00164 array( 'USE INDEX' => 'name_title' )
00165 );
00166 while( $s = $dbr->fetchObject( $res ) ) {
00167 $pageExists[$s->page_namespace][$s->page_title] = 1;
00168 }
00169 $dbr->freeResult( $res );
00170 wfProfileOut( __METHOD__ . "-check" );
00171
00172 wfProfileIn( __METHOD__ . "-output" );
00173
00174 $i = 0;
00175
00176 foreach( $messages as $key => $m ) {
00177 $title = $wgLang->ucfirst( $key );
00178 if( $wgLang->getCode() != $wgContLang->getCode() ) {
00179 $title .= '/' . $wgLang->getCode();
00180 }
00181
00182 $titleObj = Title::makeTitle( NS_MEDIAWIKI, $title );
00183 $talkPage = Title::makeTitle( NS_MEDIAWIKI_TALK, $title );
00184
00185 $changed = ( $m['statmsg'] != $m['msg'] );
00186 $message = htmlspecialchars( $m['statmsg'] );
00187 $mw = htmlspecialchars( $m['msg'] );
00188
00189 if( array_key_exists( $title, $pageExists[NS_MEDIAWIKI] ) ) {
00190 $pageLink = $sk->makeKnownLinkObj( $titleObj, "<span id=\"sp-allmessages-i-$i\">" .
00191 htmlspecialchars( $key ) . '</span>' );
00192 } else {
00193 $pageLink = $sk->makeBrokenLinkObj( $titleObj, "<span id=\"sp-allmessages-i-$i\">" .
00194 htmlspecialchars( $key ) . '</span>' );
00195 }
00196 if( array_key_exists( $title, $pageExists[NS_MEDIAWIKI_TALK] ) ) {
00197 $talkLink = $sk->makeKnownLinkObj( $talkPage, htmlspecialchars( $talk ) );
00198 } else {
00199 $talkLink = $sk->makeBrokenLinkObj( $talkPage, htmlspecialchars( $talk ) );
00200 }
00201
00202 $anchor = 'msg_' . htmlspecialchars( strtolower( $title ) );
00203 $anchor = "<a id=\"$anchor\" name=\"$anchor\"></a>";
00204
00205 if( $changed ) {
00206 $txt .= "
00207 <tr class=\"orig\" id=\"sp-allmessages-r1-$i\">
00208 <td rowspan=\"2\">
00209 $anchor$pageLink<br />$talkLink
00210 </td><td>
00211 $message
00212 </td>
00213 </tr><tr class=\"new\" id=\"sp-allmessages-r2-$i\">
00214 <td>
00215 $mw
00216 </td>
00217 </tr>";
00218 } else {
00219 $txt .= "
00220 <tr class=\"def\" id=\"sp-allmessages-r1-$i\">
00221 <td>
00222 $anchor$pageLink<br />$talkLink
00223 </td><td>
00224 $mw
00225 </td>
00226 </tr>";
00227 }
00228 $messages[$key] = NULL;
00229 $i++;
00230 }
00231 $txt .= '</table>';
00232 wfProfileOut( __METHOD__ . '-output' );
00233
00234 wfProfileOut( __METHOD__ );
00235 return $txt;
00236 }