r22517 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r22516‎ | r22517 | r22518 >
Date:22:15, 28 May 2007
Author:david
Status:old
Tags:
Comment:
a little bit of code cleanup; working towards a coherent way to keep track of actions. minor cosmetic changes.
Modified paths:
  • /branches/liquidthreads/extensions/LqtExtension.php (modified) (history)
  • /branches/liquidthreads/skins/monobook/main.css (modified) (history)

Diff [purge]

Index: branches/liquidthreads/skins/monobook/main.css
@@ -108,8 +108,9 @@
109109 }*/
110110
111111 #lqt_subject_field {
112 - margin-top: 0.7em;
113 - margin-bottom: 0.5em;
 112+ margin-top: 0.7em;
 113+ margin-bottom: 0.5em;
 114+ width: 80%;
114115 }
115116
116117 .lqt_post .lqt_footer a {
Index: branches/liquidthreads/extensions/LqtExtension.php
@@ -13,11 +13,6 @@
1414 }
1515 else {
1616
17 -/** database ID of post to edit. */
18 -define('LQT_COMMAND_EDIT_POST', 'lqt_edit_post');
19 -/** database ID of post to reply to */
20 -define('LQT_COMMAND_REPLY_TO_POST', 'lqt_reply_to');
21 -
2217 require_once('LqtModel.php');
2318
2419 class LqtDispatch {
@@ -106,6 +101,19 @@
107102 * Output methods with logic *
108103 *******************************/
109104
 105+ /**
 106+ * Return an HTML form element whose value is gotten from the request.
 107+ * TODO: figure out a clean way to expand this to other forms.
 108+ */
 109+ function perpetuate( $name, $as ) {
 110+ $value = $this->request->getVal($name, '');
 111+ if ( $as == 'hidden' ) {
 112+ return <<<HTML
 113+ <input type="hidden" name="$name" id="$name" value="$value">
 114+HTML;
 115+ }
 116+ }
 117+
110118 function showNewThreadForm() {
111119 $this->showEditingFormInGeneral( null, 'new', null );
112120 }
@@ -133,22 +141,17 @@
134142 $e = new EditPage($article);
135143 $e->suppressIntro = true;
136144
137 - $e->editFormTextBottom .= "<input type=\"hidden\" name=\"lqt_edit_post\" value=\"{$article->getTitle()->getPrefixedURL()}\">";
 145+ $e->editFormTextBeforeContent .=
 146+ $this->perpetuate('lqt_edit_post', 'hidden') .
 147+ $this->perpetuate('lqt_reply_to', 'hidden') .
 148+ $this->perpetuate('lqt_new_thread_form', 'hidden');
138149
139 - if ( $edit_type == 'reply' ) {
140 - $e->editFormTextBottom .= "<input type=\"hidden\" name=\"lqt_reply_to\" value=\"{$edit_applies_to->id()}\">";
141 - }
142 -
143 - if ( $edit_type == 'new' ) {
144 - $e->editFormTextBottom .= "<input type=\"hidden\" name=\"lqt_new_thread_form\" value=\"1\">";
145 - }
146 -
147150 if ( $thread == null || $thread->superthread() == null ) {
148151 // This is a top-level post; show the subject line.
149152 $subject = $this->request->getVal('lqt_subject_field', $thread ? $thread->subject() : '');
150153 $e->editFormTextBeforeContent .= <<<HTML
151154 <label for="lqt_subject_field">Subject: </label>
152 - <input type="text" size="50" name="lqt_subject_field" id="lqt_subject_field" value="$subject"><br>
 155+ <input type="text" size="60" name="lqt_subject_field" id="lqt_subject_field" value="$subject"><br>
153156 HTML;
154157 }
155158
@@ -210,6 +213,19 @@
211214 }
212215 }
213216
 217+ function lqtTalkpageUrl( $title, $operator = null, $operand = null ) {
 218+ if ( $operator == 'lqt_reply_to' ) {
 219+ $query = array( 'lqt_reply_to' => $operand ? $operand->id() : null );
 220+ } else if ($operator == 'lqt_edit_post') {
 221+ $query = array( 'lqt_edit_post' => $operand ? $operand->rootPost()->getTitle()->getPrefixedURL() : null );
 222+ } else if ($operator == 'lqt_new_thread_form' ) {
 223+ $query = array( 'lqt_new_thread_form' => '1' );
 224+ } else {
 225+ $query = array();
 226+ }
 227+ return $title->getFullURL( $this->queryStringFromArray($query) );
 228+ }
 229+
214230 function showThreadFooter( $thread ) {
215231
216232 $this->output->addHTML(wfOpenElement('ul', array('class'=>'lqt_footer')));
@@ -218,16 +234,16 @@
219235 $p = new Parser(); $sig = $p->getUserSig( $thread->rootPost()->originalAuthor() );
220236 $this->output->addWikitext( $sig, false );
221237 $this->output->addHTML( wfCloseElement( 'li' ) );
222 -
223 - $commands = array( 'Edit' => $this->selflink( array( LQT_COMMAND_EDIT_POST => $thread->rootPost()->getTitle()->getPrefixedURL() ) ),
224 - 'Reply' => $this->selflink( array( LQT_COMMAND_REPLY_TO_POST => $thread->id() ) ));
225 -
 238+
 239+ $commands = array( 'Edit' => $this->lqtTalkpageUrl( $this->title, 'lqt_edit_post', $thread ),
 240+ 'Reply' => $this->lqtTalkpageUrl( $this->title, 'lqt_reply_to', $thread ) );
 241+
226242 foreach( $commands as $label => $href ) {
227243 $this->output->addHTML( wfOpenElement( 'li' ) );
228244 $this->output->addHTML( wfElement('a', array('href'=>$href), $label) );
229245 $this->output->addHTML( wfCloseElement( 'li' ) );
230246 }
231 -
 247+
232248 $this->output->addHTML(wfCloseELement('ul'));
233249 }
234250
@@ -236,7 +252,7 @@
237253
238254 $this->openDiv( 'lqt_post' );
239255
240 - if( $this->commandApplies( LQT_COMMAND_EDIT_POST, $post ) ) {
 256+ if( $this->commandApplies( 'lqt_edit_post', $post ) ) {
241257 $this->showPostEditingForm( $thread );
242258 } else{
243259 $this->showPostBody( $post );
@@ -245,7 +261,7 @@
246262
247263 $this->closeDiv();
248264
249 - if( $this->commandAppliesToThread( LQT_COMMAND_REPLY_TO_POST, $thread ) ) {
 265+ if( $this->commandAppliesToThread( 'lqt_reply_to', $thread ) ) {
250266 $this->indent();
251267 $this->showReplyForm( $thread );
252268 $this->unindent();
@@ -296,7 +312,8 @@
297313 if( $this->request->getBool('lqt_new_thread_form') ) {
298314 $this->showNewThreadForm();
299315 } else {
300 - $this->output->addHTML("<strong><a href=\"{$this->title->getFullURL('lqt_new_thread_form=1')}\">Start a Discussion</a></strong>");
 316+ $url = $this->lqtTalkpageUrl( $this->title, 'lqt_new_thread_form' );
 317+ $this->output->addHTML("<strong><a href=\"$url\">Start a Discussion</a></strong>");
301318 }
302319 $threads = Thread::allThreadsOfArticle($this->article);
303320 foreach($threads as $t) {