* Add 'editsection-brackets' message to allow localization (or removal) of the bracke...
authorAryeh Gregor <simetrical@users.mediawiki.org>
Mon, 2 Jul 2007 15:46:55 +0000 (15:46 +0000)
committerAryeh Gregor <simetrical@users.mediawiki.org>
Mon, 2 Jul 2007 15:46:55 +0000 (15:46 +0000)
* rebuildMessages.php no longer adds the ending ?>
* Rebuilt MessagesEn.php
* Added Linker::doEditSectionLink to remove shared code from editSectionLink and editSectionLinkForOther

includes/Linker.php
languages/messages/MessagesEn.php
maintenance/language/messageTypes.inc
maintenance/language/messages.inc
maintenance/language/writeMessagesArray.inc

index ea3e5d8..600f455 100644 (file)
@@ -1060,34 +1060,66 @@ class Linker {
                 . "</script>\n";
        }
 
-       /** @todo document */
+       /**
+        * Used to generate section edit links that point to "other" pages
+        * (sections that are really part of included pages).
+        *
+        * @param $title Title string.
+        * @param $section Integer: section number.
+        */
        public function editSectionLinkForOther( $title, $section ) {
-               global $wgContLang;
                $title = Title::newFromText( $title );
-               $editurl = '&section='.$section;
-               $url = $this->makeKnownLinkObj( $title, wfMsg('editsection'), 'action=edit'.$editurl );
-               $result = null;
-               wfRunHooks( 'EditSectionLinkForOther', array( &$this, $title, $section, $url, &$result ) );
-               return is_null( $result )
-                       ? "<span class=\"editsection\">[{$url}]</span>"
-                       : "<span class=\"editsection\">[{$result}]</span>";
+               return $this->doEditSectionLink( $title, $section, '', 'EditSectionLinkForOther' );
        }
 
        /**
-        * @param $title Title object.
+        * @param $nt Title object.
         * @param $section Integer: section number.
         * @param $hint Link String: title, or default if omitted or empty
         */
-       public function editSectionLink( $nt, $section, $hint='' ) {
+       public function editSectionLink( Title $nt, $section, $hint='' ) {
+               if( $hint != '' ) {
+                       $hint = wfMsgHtml( 'editsectionhint', htmlspecialchars( $hint ) );
+                       $hint = " title=\"$hint\"";
+               }
+               return $this->doEditSectionLink( $nt, $section, $hint, 'EditSectionLink' );
+       }
+
+       /**
+        * Implement editSectionLink and editSectionLinkForOther.
+        *
+        * @param $nt      Title object
+        * @param $section Integer, section number
+        * @param $hint    String, for HTML title attribute
+        * @param $hook    String, name of hook to run
+        * @return         String, HTML to use for edit link
+        */
+       private function doEditSectionLink( Title $nt, $section, $hint, $hook ) {
                global $wgContLang;
                $editurl = '&section='.$section;
-               $hint = ( $hint=='' ) ? '' : ' title="' . wfMsgHtml( 'editsectionhint', htmlspecialchars( $hint ) ) . '"';
-               $url = $this->makeKnownLinkObj( $nt, wfMsg('editsection'), 'action=edit'.$editurl, '', '', '',  $hint );
+               $url = $this->makeKnownLinkObj(
+                       $nt,
+                       wfMsg('editsection'),
+                       'action=edit'.$editurl,
+                       '', '', '',  $hint
+               );
                $result = null;
-               wfRunHooks( 'EditSectionLink', array( &$this, $nt, $section, $hint, $url, &$result ) );
-               return is_null( $result )
-                       ? "<span class=\"editsection\">[{$url}]</span>"
-                       : "<span class=\"editsection\">[{$result}]</span>";
+
+               // The two hooks have slightly different interfaces . . .
+               if( $hook == 'EditSectionLink' ) {
+                       wfRunHooks( $hook, array( &$this, $nt, $section, $hint, $url, &$result ) );
+               } elseif( $hook == 'EditSectionLinkForOther' ) {
+                       wfRunHooks( $hook, array( &$this, $nt, $section, $url, &$result ) );
+               }
+               
+               // For reverse compatibility, add the brackets *after* the hook is run,
+               // and even add them to hook-provided text.
+               if( is_null( $result ) ) {
+                       $result = wfMsg( 'editsection-brackets', $url );
+               } else {
+                       $result = wfMsg( 'editsection-brackets', $result );
+               }
+               return "<span class=\"editsection\">$result</span>";
        }
 
        /**
index d48cdb7..d4065af 100644 (file)
@@ -682,29 +682,30 @@ XHTML id names.
 'versionrequired'     => 'Version $1 of MediaWiki required',
 'versionrequiredtext' => 'Version $1 of MediaWiki is required to use this page. See [[Special:Version|version page]].',
 
-'ok'                  => 'OK',
-'sitetitle'           => '{{SITENAME}}', # don't translate or duplicate this message to other languages
-'pagetitle'           => '$1 - {{SITENAME}}',
-'sitesubtitle'        => '', # don't translate or duplicate this message to other languages
-'retrievedfrom'       => 'Retrieved from "$1"',
-'youhavenewmessages'  => 'You have $1 ($2).',
-'newmessageslink'     => 'new messages',
-'newmessagesdifflink' => 'last change',
-'editsection'         => 'edit',
-'editold'             => 'edit',
-'editsectionhint'     => 'Edit section: $1',
-'toc'                 => 'Contents',
-'showtoc'             => 'show',
-'hidetoc'             => 'hide',
-'thisisdeleted'       => 'View or restore $1?',
-'viewdeleted'         => 'View $1?',
-'restorelink'         => '{{PLURAL:$1|one deleted edit|$1 deleted edits}}',
-'feedlinks'           => 'Feed:',
-'feed-invalid'        => 'Invalid subscription feed type.',
-'feed-atom'           => 'Atom', # only translate this message to other languages if you have to change it
-'feed-rss'            => 'RSS', # only translate this message to other languages if you have to change it
-'sitenotice'          => '-', # the equivalent to wgSiteNotice; don't translate or duplicate this message to other languages
-'anonnotice'          => '-', # don't translate or duplicate this message to other languages
+'ok'                   => 'OK',
+'sitetitle'            => '{{SITENAME}}', # don't translate or duplicate this message to other languages
+'pagetitle'            => '$1 - {{SITENAME}}',
+'sitesubtitle'         => '', # don't translate or duplicate this message to other languages
+'retrievedfrom'        => 'Retrieved from "$1"',
+'youhavenewmessages'   => 'You have $1 ($2).',
+'newmessageslink'      => 'new messages',
+'newmessagesdifflink'  => 'last change',
+'editsection'          => 'edit',
+'editsection-brackets' => '[$1]', # only translate this message to other languages if you have to change it
+'editold'              => 'edit',
+'editsectionhint'      => 'Edit section: $1',
+'toc'                  => 'Contents',
+'showtoc'              => 'show',
+'hidetoc'              => 'hide',
+'thisisdeleted'        => 'View or restore $1?',
+'viewdeleted'          => 'View $1?',
+'restorelink'          => '{{PLURAL:$1|one deleted edit|$1 deleted edits}}',
+'feedlinks'            => 'Feed:',
+'feed-invalid'         => 'Invalid subscription feed type.',
+'feed-atom'            => 'Atom', # only translate this message to other languages if you have to change it
+'feed-rss'             => 'RSS', # only translate this message to other languages if you have to change it
+'sitenotice'           => '-', # the equivalent to wgSiteNotice; don't translate or duplicate this message to other languages
+'anonnotice'           => '-', # don't translate or duplicate this message to other languages
 
 # Short words for each namespace, by default used in the 'article' tab in monobook
 'nstab-main'      => 'Article',
@@ -1266,18 +1267,18 @@ containing all of the search terms will appear in the result).",
 'files'                    => 'Files',
 
 # User rights
-'userrights-lookup-user'     => 'Manage user groups',
-'userrights-user-editname'   => 'Enter a username:',
-'editusergroup'              => 'Edit User Groups',
-'userrights-editusergroup'   => 'Edit user groups',
-'saveusergroups'             => 'Save User Groups',
-'userrights-groupsmember'    => 'Member of:',
-'userrights-groupsavailable' => 'Available groups:',
-'userrights-groupshelp'      => 'Select groups you want the user to be removed from or added to.
+'userrights-lookup-user'      => 'Manage user groups',
+'userrights-user-editname'    => 'Enter a username:',
+'editusergroup'               => 'Edit User Groups',
+'userrights-editusergroup'    => 'Edit user groups',
+'saveusergroups'              => 'Save User Groups',
+'userrights-groupsmember'     => 'Member of:',
+'userrights-groupsavailable'  => 'Available groups:',
+'userrights-groupshelp'       => 'Select groups you want the user to be removed from or added to.
 Unselected groups will not be changed. You can deselect a group with CTRL + Left Click',
-'userrights-reason'          => 'Reason for change:',
-'userrights-available-none' => 'You may not alter group membership.',
-'userrights-available-add' => 'You can add users to $1.',
+'userrights-reason'           => 'Reason for change:',
+'userrights-available-none'   => 'You may not alter group membership.',
+'userrights-available-add'    => 'You can add users to $1.',
 'userrights-available-remove' => 'You can remove users from $1.',
 
 # Groups
index 28a0fa1..235aeb2 100644 (file)
@@ -106,6 +106,7 @@ $wgIgnoredMessages = array(
 $wgOptionalMessages = array(
        'imgmultigotopost',
        'linkprefix',
+       'editsection-brackets',
        'feed-atom',
        'feed-rss',
        'sectionlink',
index 3ec4bed..c252b92 100644 (file)
@@ -248,6 +248,7 @@ $wgMessageStructure = array(
                'newmessageslink',
                'newmessagesdifflink',
                'editsection',
+               'editsection-brackets',
                'editold',
                'editsectionhint',
                'toc',
index 4606ad9..f9340be 100644 (file)
@@ -29,13 +29,12 @@ function writeMessagesToFile( $messages, $code, $write, $listUnknown ) {
        $contents = file_get_contents( $filename );
        if ( strpos( $contents, '$messages' ) !== false ) {
                $contents = explode( '$messages', $contents );
-               if ( $messagesText . "\n?>\n" == '$messages' . $contents[1] ) {
-                       echo "Generated messages for language $code. Same to the current file.\n";
+               if ( $messagesText == '$messages' . $contents[1] ) {
+                       echo "Generated messages for language $code. Same as the current file.\n";
                } else {
                        if ( $write ) {
                                $new = $contents[0];
                                $new .= $messagesText;
-                               $new .= "\n?>\n";
                                file_put_contents( $filename, $new );
                                echo "Generated and wrote messages for language $code.\n";
                        } else {