The war on redundant ampersand usage!
[lhc/web/wiklou.git] / includes / SpecialAllmessages.php
index 6e3f658..9f68d14 100644 (file)
@@ -1,12 +1,11 @@
 <?php
 /**
- * Provide functions to generate a special page
- * @package MediaWiki
- * @subpackage SpecialPage
+ * Use this special page to get a list of the MediaWiki system messages.
+ * @addtogroup SpecialPage
  */
 
 /**
- *
+ * Constructor.
  */
 function wfSpecialAllmessages() {
        global $wgOut, $wgRequest, $wgMessageCache, $wgTitle;
@@ -18,10 +17,9 @@ function wfSpecialAllmessages() {
                return;
        }
 
-       $fname = "wfSpecialAllMessages";
-       wfProfileIn( $fname );
+       wfProfileIn( __METHOD__ );
 
-       wfProfileIn( "$fname-setup");
+       wfProfileIn( __METHOD__ . '-setup' );
        $ot = $wgRequest->getText( 'ot' );
 
        $navText = wfMsg( 'allmessagestext' );
@@ -29,7 +27,6 @@ function wfSpecialAllmessages() {
        # Make sure all extension messages are available
        MessageCache::loadAllMessages();
 
-       $first = true;
        $sortedArray = array_merge( Language::getMessagesFor( 'en' ), $wgMessageCache->getExtensionMessagesFor( 'en' ) );
        ksort( $sortedArray );
        $messages = array();
@@ -42,96 +39,91 @@ function wfSpecialAllmessages() {
        }
 
        $wgMessageCache->enableTransform();
-       wfProfileOut( "$fname-setup" );
+       wfProfileOut( __METHOD__ . '-setup' );
 
-       wfProfileIn( "$fname-output" );
-       if ($ot == 'php') {
-               $navText .= makePhp($messages);
-               $wgOut->addHTML('PHP | <a href="'.$wgTitle->escapeLocalUrl('ot=html').'">HTML</a><pre>'.htmlspecialchars($navText).'</pre>');
+       wfProfileIn( __METHOD__ . '-output' );
+       if ( $ot == 'php' ) {
+               $navText .= makePhp( $messages );
+               $wgOut->addHTML( 'PHP | <a href="' . $wgTitle->escapeLocalUrl( 'ot=html' ) . '">HTML</a><pre>' . htmlspecialchars( $navText ) . '</pre>' );
        } else {
-               $wgOut->addHTML( '<a href="'.$wgTitle->escapeLocalUrl('ot=php').'">PHP</a> | HTML' );
+               $wgOut->addHTML( '<a href="' . $wgTitle->escapeLocalUrl( 'ot=php' ) . '">PHP</a> | HTML' );
                $wgOut->addWikiText( $navText );
                $wgOut->addHTML( makeHTMLText( $messages ) );
        }
-       wfProfileOut( "$fname-output" );
+       wfProfileOut( __METHOD__ . '-output' );
 
-       wfProfileOut( $fname );
+       wfProfileOut( __METHOD__ );
 }
 
 /**
- *
+ * Create the messages array, formatted in PHP to copy to language files.
+ * @param $messages Messages array.
+ * @return The PHP messages array.
+ * @todo Make suitable for language files.
  */
-function makePhp($messages) {
+function makePhp( $messages ) {
        global $wgLang;
        $txt = "\n\n\$messages = array(\n";
        foreach( $messages as $key => $m ) {
-               if($wgLang->getCode() != 'en' and $m['msg'] == $m['enmsg'] ) {
-                       //if (strstr($m['msg'],"\n")) {
-                       //      $txt.='/* ';
-                       //      $comment=' */';
-                       //} else {
-                       //      $txt .= '#';
-                       //      $comment = '';
-                       //}
+               if( $wgLang->getCode() != 'en' && $m['msg'] == $m['enmsg'] ) {
                        continue;
-               } elseif ( wfEmptyMsg( $key, $m['msg'] ) ) {
+               } else if ( wfEmptyMsg( $key, $m['msg'] ) ) {
                        $m['msg'] = '';
                        $comment = ' #empty';
                } else {
                        $comment = '';
                }
-               $txt .= "'$key' => '" . preg_replace( "/(?<!\\\\)'/", "\'", $m['msg']) . "',$comment\n";
+               $txt .= "'$key' => '" . preg_replace( '/(?<!\\\\)\'/', "\'", $m['msg']) . "',$comment\n";
        }
        $txt .= ');';
        return $txt;
 }
 
 /**
- *
+ * Create a list of messages, formatted in HTML as a list of messages and values and showing differences between the default language file message and the message in MediaWiki: namespace.
+ * @param $messages Messages array.
+ * @return The HTML list of messages.
  */
 function makeHTMLText( $messages ) {
        global $wgLang, $wgContLang, $wgUser;
-       $fname = "makeHTMLText";
-       wfProfileIn( $fname );
+       wfProfileIn( __METHOD__ );
 
-       $sk =& $wgUser->getSkin();
+       $sk = $wgUser->getSkin();
        $talk = $wgLang->getNsText( NS_TALK );
-       $mwnspace = $wgLang->getNsText( NS_MEDIAWIKI );
-       $mwtalk = $wgLang->getNsText( NS_MEDIAWIKI_TALK );
 
        $input = wfElement( 'input', array(
                'type'    => 'text',
                'id'      => 'allmessagesinput',
-               'onkeyup' => 'allmessagesfilter()',),
-               '');
+               'onkeyup' => 'allmessagesfilter()'
+       ), '' );
        $checkbox = wfElement( 'input', array(
                'type'    => 'button',
                'value'   => wfMsgHtml( 'allmessagesmodified' ),
                'id'      => 'allmessagescheckbox',
-               'onclick' => 'allmessagesmodified()',),
-               '');
+               'onclick' => 'allmessagesmodified()'
+       ), '' );
 
-       $txt = '<span id="allmessagesfilter" style="display:none;">' .
-               wfMsgHtml('allmessagesfilter') . " {$input}{$checkbox} " . '</span>';
+       $txt = '<span id="allmessagesfilter" style="display: none;">' . wfMsgHtml( 'allmessagesfilter' ) . " {$input}{$checkbox} " . '</span>';
 
-       $txt .= "
-<table border='1' cellspacing='0' width='100%' id='allmessagestable'>
+       $txt .= '
+<table border="1" cellspacing="0" width="100%" id="allmessagestable">
        <tr>
-               <th rowspan='2'>" . wfMsgHtml('allmessagesname') . "</th>
-               <th>" . wfMsgHtml('allmessagesdefault') . "</th>
+               <th rowspan="2">' . wfMsgHtml( 'allmessagesname' ) . '</th>
+               <th>' . wfMsgHtml( 'allmessagesdefault' ) . '</th>
        </tr>
        <tr>
-               <th>" . wfMsgHtml('allmessagescurrent') . "</th>
-       </tr>";
+               <th>' . wfMsgHtml( 'allmessagescurrent' ) . '</th>
+       </tr>';
+
+       wfProfileIn( __METHOD__ . "-check" );
 
-       wfProfileIn( "$fname-check" );
        # This is a nasty hack to avoid doing independent existence checks
        # without sending the links and table through the slow wiki parser.
        $pageExists = array(
                NS_MEDIAWIKI => array(),
                NS_MEDIAWIKI_TALK => array()
        );
-       $dbr =& wfGetDB( DB_SLAVE );
+       $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 );
@@ -139,31 +131,29 @@ function makeHTMLText( $messages ) {
                $pageExists[$s->page_namespace][$s->page_title] = true;
        }
        $dbr->freeResult( $res );
-       wfProfileOut( "$fname-check" );
+       wfProfileOut( __METHOD__ . "-check" );
 
-       wfProfileIn( "$fname-output" );
+       wfProfileIn( __METHOD__ . "-output" );
 
        $i = 0;
 
        foreach( $messages as $key => $m ) {
-
                $title = $wgLang->ucfirst( $key );
-               if($wgLang->getCode() != $wgContLang->getCode())
-                       $title.= '/' . $wgLang->getCode();
+               if( $wgLang->getCode() != $wgContLang->getCode() ) {
+                       $title .= '/' . $wgLang->getCode();
+               }
 
                $titleObj =& Title::makeTitle( NS_MEDIAWIKI, $title );
                $talkPage =& Title::makeTitle( NS_MEDIAWIKI_TALK, $title );
 
-               $changed = ($m['statmsg'] != $m['msg']);
+               $changed = ( $m['statmsg'] != $m['msg'] );
                $message = htmlspecialchars( $m['statmsg'] );
                $mw = htmlspecialchars( $m['msg'] );
 
-               #$pageLink = $sk->makeLinkObj( $titleObj, htmlspecialchars( $key ) );
-               #$talkLink = $sk->makeLinkObj( $talkPage, htmlspecialchars( $talk ) );
                if( isset( $pageExists[NS_MEDIAWIKI][$title] ) ) {
-                       $pageLink = $sk->makeKnownLinkObj( $titleObj, "<span id='sp-allmessages-i-$i'>" .  htmlspecialchars( $key ) . "</span>" );
+                       $pageLink = $sk->makeKnownLinkObj( $titleObj, "<span id=\"sp-allmessages-i-$i\">" .  htmlspecialchars( $key ) . '</span>' );
                } else {
-                       $pageLink = $sk->makeBrokenLinkObj( $titleObj, "<span id='sp-allmessages-i-$i'>" .  htmlspecialchars( $key ) . "</span>" );
+                       $pageLink = $sk->makeBrokenLinkObj( $titleObj, "<span id=\"sp-allmessages-i-$i\">" .  htmlspecialchars( $key ) . '</span>' );
                }
                if( isset( $pageExists[NS_MEDIAWIKI_TALK][$title] ) ) {
                        $talkLink = $sk->makeKnownLinkObj( $talkPage, htmlspecialchars( $talk ) );
@@ -174,38 +164,35 @@ function makeHTMLText( $messages ) {
                $anchor = 'msg_' . htmlspecialchars( strtolower( $title ) );
                $anchor = "<a id=\"$anchor\" name=\"$anchor\"></a>";
 
-               if($changed) {
-
+               if( $changed ) {
                        $txt .= "
-       <tr class='orig' id='sp-allmessages-r1-$i'>
-               <td rowspan='2'>
+       <tr class=\"orig\" id=\"sp-allmessages-r1-$i\">
+               <td rowspan=\"2\">
                        $anchor$pageLink<br />$talkLink
                </td><td>
 $message
                </td>
-       </tr><tr class='new' id='sp-allmessages-r2-$i'>
+       </tr><tr class=\"new\" id=\"sp-allmessages-r2-$i\">
                <td>
 $mw
                </td>
        </tr>";
                } else {
-
                        $txt .= "
-       <tr class='def' id='sp-allmessages-r1-$i'>
+       <tr class=\"def\" id=\"sp-allmessages-r1-$i\">
                <td>
                        $anchor$pageLink<br />$talkLink
                </td><td>
 $mw
                </td>
        </tr>";
-
                }
-       $i++;
+               $i++;
        }
-       $txt .= "</table>";
-       wfProfileOut( "$fname-output" );
+       $txt .= '</table>';
+       wfProfileOut( __METHOD__ . '-output' );
 
-       wfProfileOut( $fname );
+       wfProfileOut( __METHOD__ );
        return $txt;
 }