r22618 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r22617‎ | r22618 | r22619 >
Date:03:55, 1 June 2007
Author:david
Status:old
Tags:
Comment:
Preliminary support for summaries. Everything works except the hide/show code, now done in javascript without ajax, is incompatible with doing any other operations. So we'll probably have to move that server side. It'll be faster that way anyways.
Modified paths:
  • /branches/liquidthreads/extensions/LqtExtension.php (modified) (history)
  • /branches/liquidthreads/extensions/LqtModel.php (modified) (history)
  • /branches/liquidthreads/skins/common/lqt.js (modified) (history)
  • /branches/liquidthreads/skins/monobook/main.css (modified) (history)

Diff [purge]

Index: branches/liquidthreads/skins/monobook/main.css
@@ -33,6 +33,42 @@
3434 margin-bottom: .1em;
3535 }*/
3636
 37+.lqt_thread_showhide {
 38+ margin-left: 1em;
 39+ margin-bottom: 0.5em;
 40+}
 41+
 42+.lqt_thread_permalink_summary {
 43+ clear: both;
 44+ border: solid 1px #ddd;
 45+ padding-left: 1em; padding-right: 1em;
 46+ margin: 2em 2em 0.7em 1em;
 47+}
 48+.lqt_thread_permalink_summary_title {
 49+ float: left;
 50+ margin-left: 1em;
 51+ font-weight: bold;
 52+}
 53+.lqt_thread_permalink_summary_edit {
 54+ float: right;
 55+ margin-right: 2em;
 56+ font-weight: bold;
 57+ font-size: smaller;
 58+}
 59+
 60+.lqt_summarize_command {
 61+ display: block;
 62+ float: right;
 63+ position: relative;
 64+ top: -3em;
 65+ font-size: smaller;
 66+ font-weight: bold;
 67+}
 68+
 69+h1.lqt_header {
 70+ padding-right: 4.2em;
 71+}
 72+
3773 .lqt_archive_widget {
3874 /* floats to the right of the main h1 page title. */
3975 float:right;
@@ -48,14 +84,7 @@
4985 padding-right: 4.5em;
5086 }
5187
52 -#lqt_archive_hide_show {
53 - display: block;
54 -}
5588
56 -#lqt_archive_toc {
57 - display: none;
58 -}
59 -
6089 h1.lqt_header {
6190
6291 font-size: 150%; /* same as h2 normally is */
@@ -69,11 +98,6 @@
7099 margin-right: 4pt;
71100 }
72101
73 -.lqt_archive_browser {
74 - margin-top: 1em;
75 - margin-bottom: 1em;
76 -}
77 -
78102 .lqt_deleted_notice {
79103 color: #999;
80104 font-style: italic;
Index: branches/liquidthreads/skins/common/lqt.js
@@ -11,6 +11,28 @@
1212 }
1313 }
1414
 15+function lqt_handle_hide_show() {
 16+ var threadid = this.id.replace(/lqt_thread_showhide_/g, "lqt_thread_id_");
 17+ var thread = document.getElementById(threadid);
 18+ if ( thread.style.display == 'none' ) thread.style.display = 'block';
 19+ else thread.style.display = 'none';
 20+}
 21+
 22+function lqt_hide_all_hidden_threads() {
 23+ var els = getElementsByClassName(document, 'div', ['lqt_thread_hidden']);
 24+ for (var i in els) {
 25+ e = els[i];
 26+ e.style.display = 'none';
 27+ var link = document.createElement('a');
 28+ link.className = 'lqt_thread_showhide';
 29+ link.id = e.id.replace(/lqt_thread_id_/g, "lqt_thread_showhide_");
 30+ link.innerHTML = 'Show this thread';
 31+ lqt_add_event(link, 'click', lqt_handle_hide_show);
 32+ e.parentNode.insertBefore(link, e);
 33+ }
 34+}
 35+
 36+
1537 function lqt_on_load() {
1638 if(!document.getElementById) return;
1739
@@ -23,6 +45,8 @@
2446 if (success) {
2547 document.getElementById('lqt_archive_go_button').className = "lqt_hidden";
2648 }
 49+
 50+ lqt_hide_all_hidden_threads();
2751 }
2852
2953 addOnloadHook(lqt_on_load);
\ No newline at end of file
Index: branches/liquidthreads/extensions/LqtExtension.php
@@ -88,19 +88,16 @@
8989 return $this->request->getVal($command) == $thread->id();
9090 }
9191
92 - function permalinkUrl( $thread ) {
93 - return SpecialPage::getTitleFor('Thread', $thread->id())->getFullURL();
 92+ function permalinkUrl( $thread, $query ='' ) {
 93+ return SpecialPage::getTitleFor('Thread', $thread->id())->getFullURL($query);
9494 }
9595
9696 /*************************
9797 * Simple HTML methods *
9898 *************************/
9999
100 - function openDiv( $class = null ) {
101 - if ( $class )
102 - $this->output->addHTML( wfOpenElement( 'div', array('class'=>$class) ) );
103 - else
104 - $this->output->addHTML( wfOpenElement( 'div') );
 100+ function openDiv( $class='', $id='' ) {
 101+ $this->output->addHTML( wfOpenElement( 'div', array('class'=>$class, 'id'=>$id) ) );
105102 }
106103
107104 function closeDiv() {
@@ -136,13 +133,21 @@
137134 $this->showEditingFormInGeneral( null, 'reply', $thread );
138135 }
139136
140 - function showEditingFormInGeneral( $thread, $edit_type, $edit_applies_to ) {
 137+ function showSummarizeForm( $thread ) {
 138+ $this->showEditingFormInGeneral( null, 'summarize', $thread );
 139+ }
 140+
 141+ private function showEditingFormInGeneral( $thread, $edit_type, $edit_applies_to ) {
141142 // If there is no article (reply or new), we need a randomly-generated title.
142143 // On the first pass, we generate one. After that, we find it in the request.
143 - if ( $thread == null ) {
 144+ if ($edit_type == 'summarize' && $edit_applies_to->summary() ) {
 145+ $article = $edit_applies_to->summary();
 146+ } else if ( $thread == null ) {
144147 $rt = Title::newFromURL( $this->request->getVal('lqt_edit_post') );
145148 $t = $rt ? $rt : $this->scratchTitle();
146149 $article = new Article( $t );
 150+ } else if ($edit_type == 'summarize') {
 151+ $article = $edit_applies_to->summary();
147152 } else {
148153 $article = $thread->rootPost();
149154 }
@@ -153,7 +158,8 @@
154159 $e->editFormTextBeforeContent .=
155160 $this->perpetuate('lqt_edit_post', 'hidden') .
156161 $this->perpetuate('lqt_reply_to', 'hidden') .
157 - $this->perpetuate('lqt_new_thread_form', 'hidden');
 162+ $this->perpetuate('lqt_new_thread_form', 'hidden') .
 163+ $this->perpetuate('lqt_summarize', 'hidden');
158164
159165 if ( /*$thread == null*/ $edit_type=='new' || ($thread && $thread->superthread() == null) ) {
160166 // This is a top-level post; show the subject line.
@@ -178,19 +184,23 @@
179185 }
180186
181187 // For replies and new posts, insert the associated thread object into the DB.
182 - if ($edit_type != 'editExisting' && $e->didSave) {
 188+ if ($edit_type != 'editExisting' && $edit_type != 'summarize' && $e->didSave) {
183189 $thread = Thread::newThread( $article, $this->article );
184190 if ( $edit_type == 'reply' ) {
185191 $thread->setSuperthread( $edit_applies_to );
 192+ } else {
 193+ $thread->touch();
186194 }
187195 }
 196+
 197+ if ($edit_type == 'summarize' && $e->didSave) {
 198+ $edit_applies_to->setSummary( $article );
 199+ }
188200
189201 $subject = $this->request->getVal('lqt_subject_field', '');
190202 if ( $e->didSave && $subject != '' ) {
191203 $thread->setSubject( Sanitizer::stripAllTags($subject) );
192204 }
193 -
194 - if ($e->didSave) $thread->touch(); // TODO reduntent if above $thread->setX called.
195205 }
196206
197207 function scratchTitle() {
@@ -306,17 +316,37 @@
307317
308318 function showThreadHeading( $thread ) {
309319 if ( $thread->hasSubject() )
310 - $this->output->addHTML( wfElement( "h{$this->headerLevel}", array('class'=>'lqt_header'), $thread->subject() ) );
 320+ $this->output->addHTML( wfElement( "h{$this->headerLevel}",
 321+ array('class'=>'lqt_header'),
 322+ $thread->subject() ) );
 323+ if ( !$thread->superthread() && !$thread->summary() ) {
 324+ $url = $this->permalinkUrl( $thread, 'lqt_summarize=1' );
 325+ $this->output->addHTML( <<<HTML
 326+ <span class="lqt_summarize_command">[<a href="{$url}">Summarize</a>]</span>
 327+HTML
 328+ );
 329+ }
311330 }
312331
313 - function showThread( $thread ) {
 332+ function showThread( $thread, $suppress_summaries = false ) {
314333 $this->showThreadHeading( $thread );
 334+
 335+ if( $thread->summary() && !$suppress_summaries ) {
 336+ $this->showSummary($thread);
 337+ $this->openDiv('lqt_thread lqt_thread_hidden', "lqt_thread_id_{$thread->id()}");
 338+ } else {
 339+ $this->openDiv('lqt_thread', "lqt_thread_id_{$thread->id()}");
 340+ }
 341+
 342+
315343 $this->showRootPost( $thread );
316344 $this->indent();
317345 foreach( $thread->subthreads() as $st ) {
318346 $this->showThread($st);
319347 }
320348 $this->unindent();
 349+
 350+ $this->closeDiv();
321351 }
322352
323353 function indent() {
@@ -329,6 +359,21 @@
330360 $this->output->addHTML( wfCloseElement( 'dl') );
331361 $this->headerLevel -= 1;
332362 }
 363+
 364+ function showSummary($t) {
 365+ if ( !$t->summary() ) return;
 366+ $this->output->addHTML(<<<HTML
 367+ <span class="lqt_thread_permalink_summary_title">
 368+ This thread has been summarized as follows:
 369+ </span><span class="lqt_thread_permalink_summary_edit">
 370+ [<a href="{$this->permalinkUrl($t,'lqt_summarize=1')}">edit</a>]
 371+ </span>
 372+HTML
 373+ );
 374+ $this->openDiv('lqt_thread_permalink_summary');
 375+ $this->showPostBody($t->summary());
 376+ $this->closeDiv();
 377+ }
333378 }
334379
335380 class TalkpageView extends LqtView {
@@ -436,7 +481,7 @@
437482 parent::showThreadHeading($thread);
438483 }
439484 }
440 -
 485+
441486 function show() {
442487 /* Extract the numeric ID after the slash in the URL. */
443488 $title_string = $this->request->getVal('title');
@@ -468,8 +513,15 @@
469514 $this->output->setSubtitle( "from " . $talkpage_link );
470515 }
471516
472 - $this->showThread($t);
 517+ if( $this->request->getBool('lqt_summarize') ) {
 518+ $this->showSummarizeForm($t);
 519+ } else if ( $t->summary() ) {
 520+ $this->showSummary($t);
 521+ }
 522+
 523+ $this->showThread($t, true);
473524 }
 525+
474526 }
475527
476528 /*
Index: branches/liquidthreads/extensions/LqtModel.php
@@ -138,6 +138,17 @@
139139 return $this->rootPost;
140140 }
141141
 142+ function summary() {
 143+ if ( !$this->summaryId ) return null;
 144+ if ( !$this->summary ) $this->summary = new Post( Title::newFromID( $this->summaryId ) );
 145+ return $this->summary;
 146+ }
 147+
 148+ function setSummary( $post ) {
 149+ $this->summaryId = $post->getID();
 150+ $this->updateRecord();
 151+ }
 152+
142153 function hasSubject() {
143154 return $this->subject != null;
144155 }