r23042 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23041‎ | r23042 | r23043 >
Date:03:58, 17 June 2007
Author:david
Status:old
Tags:
Comment:
Rearrange request variable scheme from lqt_whatever=idnumber to lqt_method=whatever & lqt_operand=idnumber; this makes things way nice. First of a wee bit of refactoring before we dive into thread histories.
Modified paths:
  • /branches/liquidthreads/extensions/LqtExtension.php (modified) (history)

Diff [purge]

Index: branches/liquidthreads/extensions/LqtExtension.php
@@ -22,7 +22,7 @@
2323 $title->getDBkey());
2424 $article = new Article($article_title);
2525
26 - if ( $request->getBool('lqt_show_archive') ) {
 26+ if ( $request->getVal('lqt_method') == 'talkpage_archive' ) {
2727 $view = new TalkpageArchiveView( $output, $article, $title, $user, $request );
2828 } else {
2929 $view = new TalkpageView( $output, $article, $title, $user, $request );
@@ -119,30 +119,26 @@
120120 return $q;
121121 }
122122
123 - /**
124 - * @return href for a link to the same page as is being currently viewed,
125 - * but with additional query variables.
126 - * @param $vars array( 'query_variable_name' => 'value', ... ).
127 - */
128 - function selflink( $vars = null ) {
129 - return $this->title->getFullURL( $this->queryStringFromArray($vars) );
 123+ function methodAppliesToThread( $method, $thread ) {
 124+ return $this->request->getVal('lqt_method') == $method &&
 125+ $this->request->getVal('lqt_operand') == $thread->id();
130126 }
131 -
132 - /**
133 - * @return true if the value of the give query variable name is equal to the given post's ID.
134 - */
135 - function commandApplies( $command, $post ) {
136 - return $this->request->getVal($command) == $post->getTitle()->getPrefixedURL();
 127+ function methodApplies( $method ) {
 128+ return $this->request->getVal('lqt_method') == $method;
137129 }
138 - function commandAppliesToThread( $command, $thread ) {
139 - return $this->request->getVal($command) == $thread->id();
 130+
 131+ function permalinkUrl( $thread, $method = null, $operand = null ) {
 132+ $query = $method ? "lqt_method=$method" : "";
 133+ $query = $operand ? "$query&lqt_operand={$operand->id()}" : $query;
 134+ return $thread->rootPost()->getTitle()->getFullUrl($query);
140135 }
141136
142 - function permalinkUrl( $thread, $query ='' ) {
143 - return $thread->rootPost()->getTitle()->getFullURL($query);
144 - return SpecialPage::getTitleFor('Thread', $thread->id())->getFullURL($query);
 137+ function talkpageUrl( $title, $method = null, $operand = null ) {
 138+ $query = $method ? "lqt_method=$method" : "";
 139+ $query = $operand ? "$query&lqt_operand={$operand->id()}" : $query;
 140+ return $title->getFullURL( $query );
145141 }
146 -
 142+
147143 /*************************
148144 * Simple HTML methods *
149145 *************************/
@@ -217,10 +213,8 @@
218214 $e->suppressIntro = true;
219215
220216 $e->editFormTextBeforeContent .=
221 - $this->perpetuate('lqt_edit_post', 'hidden') .
222 - $this->perpetuate('lqt_reply_to', 'hidden') .
223 - $this->perpetuate('lqt_new_thread_form', 'hidden') .
224 - $this->perpetuate('lqt_summarize', 'hidden');
 217+ $this->perpetuate('lqt_method', 'hidden') .
 218+ $this->perpetuate('lqt_operand', 'hidden');
225219
226220 if ( /*$thread == null*/ $edit_type=='new' || ($thread && $thread->superthread() == null) ) {
227221 // This is a top-level post; show the subject line.
@@ -368,21 +362,6 @@
369363 }
370364 }
371365
372 - function talkpageUrl( $title, $operator = null, $operand = null ) {
373 - if ( $operator == 'lqt_reply_to' ) {
374 - $query = array( 'lqt_reply_to' => $operand ? $operand->id() : null );
375 - } else if ($operator == 'lqt_edit_post') {
376 - $query = array( 'lqt_edit_post' => $operand ? $operand->id() : null );
377 - } else if ($operator == 'lqt_new_thread_form' ) {
378 - $query = array( 'lqt_new_thread_form' => '1' );
379 - } else if ($operator == 'lqt_show_archive') {
380 - $query = array( 'lqt_show_archive' => '1' );
381 - } else {
382 - $query = array();
383 - }
384 - return $title->getFullURL( $this->queryStringFromArray($query) );
385 - }
386 -
387366 function showThreadFooter( $thread ) {
388367 $color_number = $this->selectNewUserColor( $thread->rootPost()->originalAuthor() );
389368 $this->output->addHTML(wfOpenElement('ul', array('class'=>"lqt_footer" )));
@@ -397,8 +376,8 @@
398377 $this->output->addHTML( $d->lastMonth()->text() );
399378 $this->output->addHTML( wfCloseElement( 'li' ) );
400379
401 - $commands = array( 'Edit' => $this->talkpageUrl( $this->title, 'lqt_edit_post', $thread ),
402 - 'Reply' => $this->talkpageUrl( $this->title, 'lqt_reply_to', $thread ),
 380+ $commands = array( 'Edit' => $this->talkpageUrl( $this->title, 'edit', $thread ),
 381+ 'Reply' => $this->talkpageUrl( $this->title, 'reply', $thread ),
403382 'Permalink' => $this->permalinkUrl( $thread ) );
404383
405384 foreach( $commands as $label => $href ) {
@@ -430,7 +409,7 @@
431410 $this->openDiv( "lqt_post lqt_post_color_$color_number" );*/
432411 $this->openDiv( 'lqt_post' );
433412
434 - if( $this->commandAppliesToThread( 'lqt_edit_post', $thread ) ) {
 413+ if( $this->methodAppliesToThread( 'edit', $thread ) ) {
435414 $this->showPostEditingForm( $thread );
436415 } else{
437416 $this->showPostBody( $post );
@@ -439,7 +418,7 @@
440419
441420 $this->closeDiv();
442421
443 - if( $this->commandAppliesToThread( 'lqt_reply_to', $thread ) ) {
 422+ if( $this->methodAppliesToThread( 'reply', $thread ) ) {
444423 $this->indent();
445424 $this->showReplyForm( $thread );
446425 $this->unindent();
@@ -464,7 +443,7 @@
465444 $this->showSummary($thread);
466445 } else if ( $touched->isBefore(Date::now()->nDaysAgo($this->archive_start_days))
467446 && !$thread->summary() && !$thread->superthread() ) {
468 - $this->output->addHTML("<p class=\"lqt_summary_notice\">If this discussion seems to be concluded, you are encouraged to <a href=\"{$this->permalinkUrl($thread, 'lqt_summarize=1')}\">write a summary</a>. There have been no changes here for at least $this->archive_start_days days.</p>");
 447+ $this->output->addHTML("<p class=\"lqt_summary_notice\">If this discussion seems to be concluded, you are encouraged to <a href=\"{$this->permalinkUrl($thread, 'summarize')}\">write a summary</a>. There have been no changes here for at least $this->archive_start_days days.</p>");
469448 }
470449
471450 $this->openDiv('lqt_thread', "lqt_thread_id_{$thread->id()}");
@@ -496,7 +475,7 @@
497476 <span class="lqt_thread_permalink_summary_title">
498477 This thread has been summarized as follows:
499478 </span><span class="lqt_thread_permalink_summary_edit">
500 - [<a href="{$this->permalinkUrl($t,'lqt_summarize=1')}">edit</a>]
 479+ [<a href="{$this->permalinkUrl($t,'summarize')}">edit</a>]
501480 </span>
502481 HTML
503482 );
@@ -525,10 +504,10 @@
526505 */
527506 }
528507
529 - function permalinksForThreads($ts, $query = '') {
 508+ function permalinksForThreads($ts, $method = null, $operand = null) {
530509 $ps = array();
531510 foreach ($ts as $t) {
532 - $u = $this->permalinkUrl($t, $query);
 511+ $u = $this->permalinkUrl($t, $method, $operand);
533512 $l = $t->subjectWithoutIncrement();
534513 $ps[] = "<a href=\"$u\">$l</a>";
535514 }
@@ -546,7 +525,7 @@
547526 } else {
548527 $this->openDiv();
549528 }
550 - $url = $this->talkpageUrl($this->title, 'lqt_show_archive');
 529+ $url = $this->talkpageUrl($this->title, 'talkpage_archive');
551530 $this->output->addHTML(<<<HTML
552531 <a href="$url" class="lqt_browse_archive">Browse the Archive</a>
553532 HTML
@@ -622,10 +601,10 @@
623602
624603 $this->showArchiveWidget();
625604
626 - if( $this->request->getBool('lqt_new_thread_form') ) {
 605+ if( $this->methodApplies('talkpage_new_thread') ) {
627606 $this->showNewThreadForm();
628607 } else {
629 - $url = $this->talkpageUrl( $this->title, 'lqt_new_thread_form' );
 608+ $url = $this->talkpageUrl( $this->title, 'talkpage_new_thread' );
630609 $this->output->addHTML("<strong><a class=\"lqt_start_discussion\" href=\"$url\">Start&nbsp;a&nbsp;Discussion</a></strong>");
631610 }
632611
@@ -797,7 +776,7 @@
798777
799778 $this->output->addHTML(<<<HTML
800779 <form id="lqt_archive_search_form" action="{$this->title->getLocalURL()}">
801 - <input type="hidden" name="lqt_show_archive" value="1">
 780+ <input type="hidden" name="lqt_method" value="talkpage_archive">
802781 <input type="hidden" name="title" value="{$this->title->getPrefixedURL()}"
803782
804783 <input type="radio" id="lqt_archive_filter_by_date_no"
@@ -881,7 +860,7 @@
882861 $this->output->setSubtitle( "from " . $talkpage_link );
883862 }
884863
885 - if( $this->request->getBool('lqt_summarize') ) {
 864+ if( $this->methodApplies('summarize') ) {
886865 $this->showSummarizeForm($t);
887866 }
888867

Status & tagging log