fetch commons descriptions for display on local wikis
[lhc/web/wiklou.git] / includes / SpecialAllmessages.php
index 6e0e7a9..e20d174 100644 (file)
 function wfSpecialAllmessages() {
        global $wgOut, $wgAllMessagesEn, $wgRequest, $wgMessageCache, $wgTitle;
        global $wgLanguageCode, $wgContLanguageCode, $wgContLang;
+       global $wgUseDatabaseMessages;
+
+       if(!$wgUseDatabaseMessages) {
+               $wgOut->addHTML(wfMsg('allmessagesnotsupportedDB'));
+               return;
+       }
+
        $fname = "wfSpecialAllMessages";
        wfProfileIn( $fname );
        
        wfProfileIn( "$fname-setup");
        $ot = $wgRequest->getText( 'ot' );
-       $mwMsg =& MagicWord::get( MAG_MSG );
        
-       $navText = wfMsg( 'allmessagestext', $mwMsg->getSynonym( 0 ) );
+       $navText = wfMsg( 'allmessagestext' );
 
-       if($wgLanguageCode != $wgContLanguageCode &&
-       !in_array($wgLanguageCode, $wgContLang->getVariants())) {
-               $err = wfMsg('allmessagesnotsupported');
-               $wgOut->addHTML( $err );
-               return;
-       }
 
        $first = true;
        $sortedArray = $wgAllMessagesEn;
@@ -77,7 +77,7 @@ function makePhp($messages) {
                } else {
                        $comment = '';
                }
-               $txt .= "'".$key."' => \"".str_replace('"','\"',$m['msg'])."\",$comment\n";
+               $txt .= "'$key' => '" . preg_replace( "/(?<!\\\\)'/", "\'", $m['msg']) . "',$comment\n";
        }
        $txt .= ');';
        return $txt;
@@ -87,7 +87,7 @@ function makePhp($messages) {
  *
  */
 function makeHTMLText( $messages ) {
-       global $wgLang, $wgUser, $wgLanguageCode;
+       global $wgLang, $wgUser, $wgLanguageCode, $wgContLanguageCode, $wgContLang;
        $fname = "makeHTMLText";
        wfProfileIn( $fname );
        
@@ -99,9 +99,9 @@ function makeHTMLText( $messages ) {
 
        <table border='1' cellspacing='0' width='100%'>
        <tr bgcolor='#b2b2ff'>
-               <th>Name</th>
-               <th>Default text</th>
-               <th>Current text</th>
+               <th>" . wfMsg('allmessagesname') . "</th>
+               <th>" . wfMsg('allmessagesdefault') . "</th>
+               <th>" . wfMsg('allmessagescurrent')  . "</th>
        </tr>";
        
        wfProfileIn( "$fname-check" );
@@ -111,19 +111,24 @@ function makeHTMLText( $messages ) {
                NS_MEDIAWIKI => array(),
                NS_MEDIAWIKI_TALK => array()
        );
-       $sql = "SELECT cur_namespace,cur_title FROM cur WHERE cur_namespace IN (" . NS_MEDIAWIKI . ", " . NS_MEDIAWIKI_TALK . ")";
        $dbr =& wfGetDB( DB_SLAVE );
+       $page = $dbr->tableName( 'page' );
+       $sql = "SELECT page_namespace,page_title FROM $page WHERE page_namespace IN (" . NS_MEDIAWIKI . ", " . NS_MEDIAWIKI_TALK . ")";
        $res = $dbr->query( $sql );
        while( $s = $dbr->fetchObject( $res ) ) {
-               $pageExists[$s->cur_namespace][$s->cur_title] = true;
+               $pageExists[$s->page_namespace][$s->page_title] = true;
        }
        $dbr->freeResult( $res );
        wfProfileOut( "$fname-check" );
 
        wfProfileIn( "$fname-output" );
+
        foreach( $messages as $key => $m ) {
 
-               $title = $wgLang->ucfirst( $key )."/$wgLanguageCode";
+               $title = $wgLang->ucfirst( $key );
+               if($wgLanguageCode != $wgContLanguageCode)
+                       $title.="/$wgLanguageCode";
+
                $titleObj =& Title::makeTitle( NS_MEDIAWIKI, $title );
                $talkPage =& Title::makeTitle( NS_MEDIAWIKI_TALK, $title );