r40409 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r40408‎ | r40409 | r40410 >
Date:22:53, 3 September 2008
Author:siebrand
Status:old
Tags:
Comment:
* use $wgExtensionMessagesFiles for i18n
* add extension specific prefix to messages
* fixed order of languages in i18n file
* added descriptionmsg
* remove one indentation level by reversing check for MEDIAWIKI
* add/bump version
* removed trailing whitespace
* add support for DiscussionThreading in Translate

Remarks: message loading can probably be delayed further. Should probably use an autoloaded class.
Modified paths:
  • /trunk/extensions/DiscussionThreading/DiscussionThreading.i18n.php (modified) (history)
  • /trunk/extensions/DiscussionThreading/DiscussionThreading.php (modified) (history)
  • /trunk/extensions/DiscussionThreading/README (modified) (history)
  • /trunk/extensions/Translate/groups/mediawiki-defines.txt (modified) (history)

Diff [purge]

Index: trunk/extensions/DiscussionThreading/DiscussionThreading.php
@@ -1,177 +1,164 @@
22 <?php
3 -
43 /**
54 * Extension to provide discussion threading similar to a listserv archive
65 *
76 * @author Jack D. Pond <jack.pond@psitex.com>
87 * @addtogroup Extensions
9 - * @copyright � 2007 Jack D. pond
 8+ * @copyright 2007 Jack D. pond
109 * @licence GNU General Public Licence 2.0 or later
1110 */
1211
13 -if( defined( 'MEDIAWIKI' ) ) {
 12+if (!defined('MEDIAWIKI')) die('Not an entry point.');
1413
15 -
1614 # Internationalisation file
17 - require_once( "$IP/extensions/DiscussionThreading/DiscussionThreading.i18n.php" );
 15+$wgExtensionMessagesFiles['DiscussionThreading'] = dirname(__FILE__) . '/DiscussionThreading.i18n.php';
1816
19 - $wgExtensionFunctions[] = 'efDiscussionThreadSetup';
20 - $wgExtensionCredits['other'][] = array(
21 - 'name' => 'DiscussionThreading',
22 - 'author' => 'Jack D. Pond',
23 - 'url' => 'http://www.mediawiki.org/wiki/Extension:DiscussionThreading',
24 - 'description' => 'Add Threading to discussion (talk) pages' );
 17+$wgExtensionFunctions[] = 'efDiscussionThreadSetup';
 18+$wgExtensionCredits['other'][] = array(
 19+ 'name' => 'DiscussionThreading',
 20+ 'author' => 'Jack D. Pond',
 21+ 'version' => '1.2',
 22+ 'url' => 'http://www.mediawiki.org/wiki/Extension:DiscussionThreading',
 23+ 'description' => 'Add Threading to discussion (talk) pages',
 24+ 'descriptionmsg' => 'discussionthreading-desc',
 25+);
2526
26 - /**
27 - * Set up hooks for discussion threading
28 - *
29 - * @param $wgSectionThreadingOn global logical variable to activate threading
30 - */
 27+/**
 28+ * Set up hooks for discussion threading
 29+ *
 30+ * @param $wgSectionThreadingOn global logical variable to activate threading
 31+ */
 32+global $wgSectionThreadingOn;
 33+$wgSectionThreadingOn = True;
3134
 35+$wgHooks['EditPage::showEditForm:initial'][] = 'efDiscussionThread';
 36+$wgHooks['EditPage::attemptSave'][] = 'efStampReply';
 37+$wgHooks['EditPage::showEditForm:initial'][] = 'efDiscussionThreadEdit';
 38+$wgHooks['EditSectionLinkForOther'][] = 'efDiscussionLink4other';
 39+$wgHooks['EditSectionLink'][] = 'efDiscussionLink';
 40+$wgHooks['AlternateEdit'][] = 'efDiscussionThreadEdit';
3241
33 - global $wgSectionThreadingOn;
34 - $wgSectionThreadingOn = True;
 42+/**
 43+ * Initial setup, add .i18n. messages from $IP/extensions/DiscussionThreading.i18n.php
 44+*/
 45+function efDiscussionThreadSetup() {
 46+ wfLoadExtensionMessages( 'DiscussionThreading' );
 47+}
3548
36 - $wgHooks['EditPage::showEditForm:initial'][] = 'efDiscussionThread';
37 - $wgHooks['EditPage::attemptSave'][] = 'efStampReply';
38 - $wgHooks['EditPage::showEditForm:initial'][] = 'efDiscussionThreadEdit';
39 - $wgHooks['EditSectionLinkForOther'][] = 'efDiscussionLink4other';
40 - $wgHooks['EditSectionLink'][] = 'efDiscussionLink';
41 - $wgHooks['AlternateEdit'][] = 'efDiscussionThreadEdit';
42 -
43 -
44 -
45 -
46 - /**
47 - * Initial setup, add .i18n. messages from $IP/extensions/DiscussionThreading.i18n.php
48 - */
49 - function efDiscussionThreadSetup() {
50 - global $wgMessageCache, $wgDiscussionThreadMessages;
51 -
52 - foreach( $wgDiscussionThreadMessages as $lang => $messages )
53 - $wgMessageCache->addMessages( $messages, $lang );
 49+/**
 50+ * This function creates a linkobject for the editSectionLinkForOther function in linker
 51+ *
 52+ * @param $callobj Article object.
 53+ * @param $title Title object.
 54+ * @param $section Integer: section number.
 55+ * @param $hint Link String: title, or default if omitted or empty
 56+ * @param $url Link String: for edit url
 57+ * @param $result String: Returns the section [new][edit][reply] html if in a talk page - otherwise whatever came in with
 58+ * @return true
 59+ */
 60+function efDiscussionLink4other ($callobj, $title, $section , $url , &$result)
 61+{
 62+ global $wgSectionThreadingOn;
 63+ if($wgSectionThreadingOn && $title->isTalkPage() ) {
 64+ $commenturl = '&section='.$section.'&replyto=yes';
 65+ $curl = $callobj->makeKnownLinkObj( $title, wfMsg('discussionthreading-replysection'), 'action=edit'.$commenturl );
 66+ $newthreadurl = '&section=new';
 67+ $nurl = $callobj->makeKnownLinkObj( $nt, wfMsg('discussionthreading-threadnewsection'), 'action=edit'.$newthreadurl );
 68+ $result = $nurl."][".$url."][".$curl;
5469 }
55 - /**
56 - * This function creates a linkobject for the editSectionLinkForOther function in linker
57 - *
58 - * @param $callobj Article object.
59 - * @param $title Title object.
60 - * @param $section Integer: section number.
61 - * @param $hint Link String: title, or default if omitted or empty
62 - * @param $url Link String: for edit url
63 - * @param $result String: Returns the section [new][edit][reply] html if in a talk page - otherwise whatever came in with
64 - * @return true
65 - */
 70+ return (true);
 71+}
6672
67 - function efDiscussionLink4other ($callobj, $title, $section , $url , &$result)
68 - {
69 - global $wgSectionThreadingOn;
70 - if($wgSectionThreadingOn && $title->isTalkPage() ) {
71 - $commenturl = '&section='.$section.'&replyto=yes';
72 - $curl = $callobj->makeKnownLinkObj( $title, wfMsg('replysection'), 'action=edit'.$commenturl );
73 - $newthreadurl = '&section=new';
74 - $nurl = $callobj->makeKnownLinkObj( $nt, wfMsg('threadnewsection'), 'action=edit'.$newthreadurl );
75 - $result = $nurl."][".$url."][".$curl;
76 - }
77 - return (true);
 73+/**
 74+ * This function creates a linkobject for the editSectionLink function in linker
 75+ *
 76+ * @param $callobj Article object.
 77+ * @param $nt Title object.
 78+ * @param $section Integer: section number.
 79+ * @param $hint Link String: title, or default if omitted or empty
 80+ * @param $url Link String: for edit url
 81+ * @param $result String: Returns the section [new][edit][reply] html if in a talk page - otherwise whatever came in with
 82+ * @return true
 83+ */
 84+function efDiscussionLink ($callobj, $nt, $section, $hint='', $url , &$result)
 85+{
 86+ global $wgSectionThreadingOn;
 87+ if($wgSectionThreadingOn && $nt->isTalkPage() ) {
 88+ $commenturl = '&section='.$section.'&replyto=yes';
 89+ $hint = ( $hint=='' ) ? '' : ' title="' . wfMsgHtml( 'discussionthreading-replysectionhint', htmlspecialchars( $hint ) ) . '"';
 90+ $curl = $callobj->makeKnownLinkObj( $nt, wfMsg('discussionthreading-replysection'), 'action=edit'.$commenturl, '', '', '', $hint );
 91+ $newthreadurl = '&section=new';
 92+ $hint = ( $hint=='' ) ? '' : ' title="' . wfMsgHtml( 'discussionthreading-threadnewsectionhint', htmlspecialchars( $hint ) ) . '"';
 93+ $nurl = $callobj->makeKnownLinkObj( $nt, wfMsg('discussionthreading-threadnewsection'), 'action=edit'.$newthreadurl, '', '', '', $hint );
 94+ $result = $nurl."][".$url."][".$curl;
7895 }
 96+ return (true);
 97+}
7998
80 - /**
81 - * This function creates a linkobject for the editSectionLink function in linker
82 - *
83 - * @param $callobj Article object.
84 - * @param $nt Title object.
85 - * @param $section Integer: section number.
86 - * @param $hint Link String: title, or default if omitted or empty
87 - * @param $url Link String: for edit url
88 - * @param $result String: Returns the section [new][edit][reply] html if in a talk page - otherwise whatever came in with
89 - * @return true
90 - */
91 -
92 - function efDiscussionLink ($callobj, $nt, $section, $hint='', $url , &$result)
93 - {
94 - global $wgSectionThreadingOn;
95 - if($wgSectionThreadingOn && $nt->isTalkPage() ) {
96 - $commenturl = '&section='.$section.'&replyto=yes';
97 - $hint = ( $hint=='' ) ? '' : ' title="' . wfMsgHtml( 'replysectionhint', htmlspecialchars( $hint ) ) . '"';
98 - $curl = $callobj->makeKnownLinkObj( $nt, wfMsg('replysection'), 'action=edit'.$commenturl, '', '', '', $hint );
99 - $newthreadurl = '&section=new';
100 - $hint = ( $hint=='' ) ? '' : ' title="' . wfMsgHtml( 'threadnewsectionhint', htmlspecialchars( $hint ) ) . '"';
101 - $nurl = $callobj->makeKnownLinkObj( $nt, wfMsg('threadnewsection'), 'action=edit'.$newthreadurl, '', '', '', $hint );
102 - $result = $nurl."][".$url."][".$curl;
 99+/**
 100+ * This function is a hook used to test to see if empty, if so, start a comment
 101+ *
 102+ * @param $efform form object.
 103+ * @return true
 104+ */
 105+function efDiscussionThreadEdit ($efform) {
 106+ global $wgRequest,$wgSectionThreadingOn;
 107+ $efform->replytosection = '';
 108+ $efform->replyadded = false;
 109+ $efform->replytosection = $wgRequest->getVal( 'replyto' );
 110+ if( !$efform->mTitle->exists() ) {
 111+ if($wgSectionThreadingOn && $efform->mTitle->isTalkPage() ) {
 112+ $efform->section = 'new';
103113 }
104 - return (true);
105114 }
 115+ return (true);
 116+}
106117
107 - /**
108 - * This function is a hook used to test to see if empty, if so, start a comment
109 - *
110 - * @param $efform form object.
111 - * @return true
112 - */
113 -
114 -
115 - function efDiscussionThreadEdit ($efform) {
116 - global $wgRequest,$wgSectionThreadingOn;
117 - $efform->replytosection = '';
118 - $efform->replyadded = false;
119 - $efform->replytosection = $wgRequest->getVal( 'replyto' );
120 - if( !$efform->mTitle->exists() ) {
121 - if($wgSectionThreadingOn && $efform->mTitle->isTalkPage() ) {
122 - $efform->section = 'new';
123 - }
124 - }
125 - return (true);
126 - }
127 -
128 - /**
129 - * Create a new header, one level below the 'replyto' header, add re: to front and tag it with user information
130 - *
131 - * @param $efform Form Object before display
132 - * @return true
133 - */
134 -
135 - function efDiscussionThread($efform){
136 - global $wgSectionThreadingOn;
137 - $wgSectionThreadingOn = isset($wgSectionThreadingOn) ? $wgSectionThreadingOn : false;
138 - if ( $efform->replytosection != '' && $wgSectionThreadingOn && !$efform->replyadded) {
139 - if ($efform->replytosection != '') {
140 - $text = $efform->textbox1;
141 - $matches = array();
142 - preg_match( "/^(=+)(.+)\\1/mi",
143 - $efform->textbox1,
144 - $matches );
145 - if( !empty( $matches[2] ) ) {
146 - preg_match( "/.*(-+)\\1/mi",$matches[2],$matchsign);
147 - if (!empty($matchsign[0]) ){
148 - $text = $text."\n\n".$matches[1]."=Re: ".trim($matchsign[0])." ~~~~".$matches[1]."=";
149 - } else {
150 - $text = $text."\n\n".$matches[1]."=Re: ".trim($matches[2])." -- ~~~~".$matches[1]."=";
151 - }
 118+/**
 119+ * Create a new header, one level below the 'replyto' header, add re: to front and tag it with user information
 120+ *
 121+ * @param $efform Form Object before display
 122+ * @return true
 123+ */
 124+function efDiscussionThread($efform){
 125+ global $wgSectionThreadingOn;
 126+ $wgSectionThreadingOn = isset($wgSectionThreadingOn) ? $wgSectionThreadingOn : false;
 127+ if ( $efform->replytosection != '' && $wgSectionThreadingOn && !$efform->replyadded) {
 128+ if ($efform->replytosection != '') {
 129+ $text = $efform->textbox1;
 130+ $matches = array();
 131+ preg_match( "/^(=+)(.+)\\1/mi",
 132+ $efform->textbox1,
 133+ $matches );
 134+ if( !empty( $matches[2] ) ) {
 135+ preg_match( "/.*(-+)\\1/mi",$matches[2],$matchsign);
 136+ if (!empty($matchsign[0]) ){
 137+ $text = $text."\n\n".$matches[1]."=Re: ".trim($matchsign[0])." ~~~~".$matches[1]."=";
152138 } else {
153 - $text = $text." -- ~~~~<br>\n\n";
 139+ $text = $text."\n\n".$matches[1]."=Re: ".trim($matches[2])." -- ~~~~".$matches[1]."=";
154140 }
155 - $efform->replyadded = true;
156 - $efform->textbox1 = $text;
 141+ } else {
 142+ $text = $text." -- ~~~~<br>\n\n";
157143 }
158 - return (true);
 144+ $efform->replyadded = true;
 145+ $efform->textbox1 = $text;
159146 }
160147 return (true);
161148 }
162 - /**
163 - * When the new header is created from summary in new (+) add comment, just stamp the header as created
164 - *
165 - * @param $efform Form Object before display
166 - * @return true
167 - */
 149+ return (true);
 150+}
168151
169 - function efStampReply($efform){
170 - global $wgSectionThreadingOn;
171 - $wgSectionThreadingOn = isset($wgSectionThreadingOn) ? $wgSectionThreadingOn : false;
172 - if ( $efform->section == "new" && $wgSectionThreadingOn && !$efform->replyadded) {
173 - $efform->summary = $efform->summary." -- ~~~~";
174 - }
175 - return(true);
 152+/**
 153+ * When the new header is created from summary in new (+) add comment, just stamp the header as created
 154+ *
 155+ * @param $efform Form Object before display
 156+ * @return true
 157+ */
 158+function efStampReply($efform){
 159+ global $wgSectionThreadingOn;
 160+ $wgSectionThreadingOn = isset($wgSectionThreadingOn) ? $wgSectionThreadingOn : false;
 161+ if ( $efform->section == "new" && $wgSectionThreadingOn && !$efform->replyadded) {
 162+ $efform->summary = $efform->summary." -- ~~~~";
176163 }
 164+ return(true);
177165 }
178 -?>
\ No newline at end of file
Index: trunk/extensions/DiscussionThreading/DiscussionThreading.i18n.php
@@ -5,47 +5,43 @@
66 * @addtogroup Extensions
77 */
88
9 -$wgDiscussionThreadMessages = array();
 9+$messages = array();
1010
11 -$wgDiscussionThreadMessages['en'] = array(
12 - 'replysection' => 'reply',
13 - 'replysectionhint' => "Reply to this Posting",
14 - 'threadnewsection' => 'new',
15 - 'threadnewsectionhint' => "Start a new thread"
 11+/** English
 12+ * @author Jack D. Pond
 13+ */
 14+$messages['en'] = array(
 15+ 'discussionthreading-desc' => 'Add threading to talk pages',
 16+ 'discussionthreading-replysection' => 'reply',
 17+ 'discussionthreading-replysectionhint' => "Reply to this posting",
 18+ 'discussionthreading-threadnewsection' => 'new',
 19+ 'discussionthreading-threadnewsectionhint' => "Start a new thread"
1620 );
17 -$wgDiscussionThreadMessages['es'] = array(
18 - 'replysection' => 'respuesta',
19 - 'replysectionhint' => "Respuesta a este tema",
20 - 'threadnewsection' => 'nuevo',
21 - 'threadnewsectionhint' => "Empezar un nuevo tema"
 21+
 22+$messages['de'] = array(
 23+ 'discussionthreading-replysection' => 'antworten',
 24+ 'discussionthreading-replysectionhint' => "Auf diesen Eintrag antworten",
 25+ 'discussionthreading-threadnewsection' => 'neu',
 26+ 'discussionthreading-threadnewsectionhint' => "Neuen Eintrag erstellen"
2227 );
23 -$wgDiscussionThreadMessages['de'] = array(
24 - 'replysection' => 'antworten',
25 - 'replysectionhint' => "Auf diesen Eintrag antworten",
26 - 'threadnewsection' => 'neu',
27 - 'threadnewsectionhint' => "Neuen Eintrag erstellen"
 28+
 29+$messages['es'] = array(
 30+ 'discussionthreading-replysection' => 'respuesta',
 31+ 'discussionthreading-replysectionhint' => "Respuesta a este tema",
 32+ 'discussionthreading-threadnewsection' => 'nuevo',
 33+ 'discussionthreading-threadnewsectionhint' => "Empezar un nuevo tema"
2834 );
29 -$wgDiscussionThreadMessages['fr'] = array(
30 - 'replysection' => 'r&eacute;pondre',
31 - 'replysectionhint' => "R&eacute;pondre � ce commentaire",
32 - 'threadnewsection' => 'nouveau',
33 - 'threadnewsectionhint' => "Commencer une nouvelle discussion"
 35+
 36+$messages['fr'] = array(
 37+ 'discussionthreading-replysection' => 'répondre',
 38+ 'discussionthreading-replysectionhint' => "Répondre �e commentaire",
 39+ 'discussionthreading-threadnewsection' => 'nouveau',
 40+ 'discussionthreading-threadnewsectionhint' => "Commencer une nouvelle discussion"
3441 );
35 -$wgDiscussionThreadMessages['it'] = array(
36 - 'replysection' => 'rispondi',
37 - 'replysectionhint' => "Rispondi a questo messaggio",
38 - 'threadnewsection' => 'nuovo',
39 - 'threadnewsectionhint' => "Avvia una nuova discussione"
40 -);
41 -/* Need to add
42 - af,br,bs,ca,cs,cy,et,eu,fi,ga,gl,he,hr,hsb,id,is,ja,kk-kz,kk-tr,kk-cn,kk,lv,nl,
43 - no,nn,oc,pt,pt-br,ro,ru,sk,sl,sq,uk,wa,zh-cn,zh-tw,zh-yue,zh-hk,zh-sg
4442
45 - Would do this by adding a new $wgDiscussionThreadMessages array example:
46 -
47 -$wgDiscussionThreadMessages['lang1'] = array(
48 - 'replysection' => 'lang1tag',
49 - 'replysectionhint' => "lang1hint",
 43+$messages['it'] = array(
 44+ 'discussionthreading-replysection' => 'rispondi',
 45+ 'discussionthreading-replysectionhint' => "Rispondi a questo messaggio",
 46+ 'discussionthreading-threadnewsection' => 'nuovo',
 47+ 'discussionthreading-threadnewsectionhint' => "Avvia una nuova discussione"
5048 );
51 -*/
52 -?>
Index: trunk/extensions/DiscussionThreading/README
@@ -137,8 +137,8 @@
138138 require_once( "$IP/extensions/DiscussionThreading/DiscussionThreading.i18n.php" );
139139
140140 $wgExtensionFunctions[] = 'efDiscussionThreadSetup';
141 - $wgExtensionCredits['other'][] = array(
142 - 'name' => 'DiscussionThreading',
 141+ $wgExtensionCredits['other'][] = array(
 142+ 'name' => 'DiscussionThreading',
143143 'author' => 'Jack D. Pond',
144144 'url' => 'http://www.mediawiki.org/wiki/Extension:DiscussionThreading',
145145 'description' => 'Add Threading to discussion (talk) pages' );
@@ -159,13 +159,13 @@
160160 $wgHooks['editSectionLinkForOther'][] = 'efDiscussionLink4other';
161161 $wgHooks['editSectionLink'][] = 'efDiscussionLink';
162162 $wgHooks['AlternateEdit'][] = 'efDiscussionThreadEdit';
163 -
164163
165164
166165
 166+
167167 /**
168168 * Initial setup, add .i18n. messages from $IP/extensions/DiscussionThreading.i18n.php
169 - */
 169+ */
170170 function efDiscussionThreadSetup() {
171171 global $wgMessageCache, $wgDiscussionThreadMessages;
172172
@@ -323,12 +323,12 @@
324324 'threadnewsectionhint' => "Start a new thread"
325325 );
326326
327 -/* Need to add
 327+/* Need to add
328328 af,br,bs,ca,cs,cy,de,et,eu,fi,fr,ga,gl,he,hr,hsb,id,is,it,ja,kk-kz,kk-tr,kk-cn,kk,lv,nl,
329329 no,nn,oc,pt,pt-br,ro,ru,sk,sl,sq,uk,wa,zh-cn,zh-tw,zh-yue,zh-hk,zh-sg
330330
331331 Would do this by adding a new $wgDiscussionThreadMessages array example:
332 -
 332+
333333 $wgDiscussionThreadMessages['lang1'] = array(
334334 'replysection' => 'lang1 - tag',
335335 'replysectionhint' => "lang1 - hint",
Index: trunk/extensions/Translate/groups/mediawiki-defines.txt
@@ -195,6 +195,8 @@
196196
197197 Did You Mean
198198
 199+Discussion Threading
 200+
199201 Dismissable SiteNotice
200202 descmsg = sitenotice-desc
201203 ignored = sitenotice_id