From 43b05c00cb4e75882781f6883835004ae911d9a1 Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Mon, 2 Jul 2007 15:46:55 +0000 Subject: [PATCH] * Add 'editsection-brackets' message to allow localization (or removal) of the brackets in the "[edit]" link for sections. * rebuildMessages.php no longer adds the ending ?> * Rebuilt MessagesEn.php * Added Linker::doEditSectionLink to remove shared code from editSectionLink and editSectionLinkForOther --- includes/Linker.php | 66 +++++++++++++++----- languages/messages/MessagesEn.php | 69 +++++++++++---------- maintenance/language/messageTypes.inc | 1 + maintenance/language/messages.inc | 1 + maintenance/language/writeMessagesArray.inc | 5 +- 5 files changed, 88 insertions(+), 54 deletions(-) diff --git a/includes/Linker.php b/includes/Linker.php index ea3e5d83b3..600f455244 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -1060,34 +1060,66 @@ class Linker { . "\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 = '§ion='.$section; - $url = $this->makeKnownLinkObj( $title, wfMsg('editsection'), 'action=edit'.$editurl ); - $result = null; - wfRunHooks( 'EditSectionLinkForOther', array( &$this, $title, $section, $url, &$result ) ); - return is_null( $result ) - ? "[{$url}]" - : "[{$result}]"; + 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 = '§ion='.$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 ) - ? "[{$url}]" - : "[{$result}]"; + + // 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 "$result"; } /** diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index d48cdb7e59..d4065af35d 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -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 diff --git a/maintenance/language/messageTypes.inc b/maintenance/language/messageTypes.inc index 28a0fa1805..235aeb2fda 100644 --- a/maintenance/language/messageTypes.inc +++ b/maintenance/language/messageTypes.inc @@ -106,6 +106,7 @@ $wgIgnoredMessages = array( $wgOptionalMessages = array( 'imgmultigotopost', 'linkprefix', + 'editsection-brackets', 'feed-atom', 'feed-rss', 'sectionlink', diff --git a/maintenance/language/messages.inc b/maintenance/language/messages.inc index 3ec4beda6e..c252b92133 100644 --- a/maintenance/language/messages.inc +++ b/maintenance/language/messages.inc @@ -248,6 +248,7 @@ $wgMessageStructure = array( 'newmessageslink', 'newmessagesdifflink', 'editsection', + 'editsection-brackets', 'editold', 'editsectionhint', 'toc', diff --git a/maintenance/language/writeMessagesArray.inc b/maintenance/language/writeMessagesArray.inc index 4606ad917f..f9340bef7d 100644 --- a/maintenance/language/writeMessagesArray.inc +++ b/maintenance/language/writeMessagesArray.inc @@ -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 { -- 2.20.1