r22447 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r22446‎ | r22447 | r22448 >
Date:02:56, 26 May 2007
Author:david
Status:old
Tags:
Comment:
Replies now work.
Modified paths:
  • /branches/liquidthreads/extensions/LqtExtension.php (modified) (history)
  • /branches/liquidthreads/extensions/LqtModel.php (modified) (history)
  • /branches/liquidthreads/includes/EditPage.php (modified) (history)

Diff [purge]

Index: branches/liquidthreads/extensions/LqtExtension.php
@@ -81,16 +81,17 @@
8282 @return true if the value of the give query variable name is equal to the given post's ID.
8383 */
8484 function commandApplies( $command, $post ) {
85 -
86 - return $this->request->getInt($command) == $post->getID();
 85+ return $this->request->getVal($command) == $post->getTitle()->getPrefixedURL();
8786 }
 87+ function commandAppliesToThread( $command, $thread ) {
 88+ return $this->request->getVal($command) == $thread->id();
 89+ }
8890
8991 /*************************
9092 * Simple HTML methods *
9193 *************************/
9294
9395 function openDiv( $class = null ) {
94 -
9596 if ( $class )
9697 $this->output->addHTML( wfOpenElement( 'div', array('class'=>$class) ) );
9798 else
@@ -98,7 +99,6 @@
99100 }
100101
101102 function closeDiv() {
102 -
103103 $this->output->addHTML( wfCloseElement( 'div' ) );
104104 }
105105
@@ -112,25 +112,36 @@
113113
114114 function showPostEditingForm( $post ) {
115115 $pp = new PostProxy( $post, $this->request );
116 - $this->showEditingFormInGeneral( $pp, 'editExisting', $post->getID() );
 116+ $this->showEditingFormInGeneral( $pp, 'editExisting', $post->getTitle() );
117117 }
118118
119 - function showReplyForm( $post ) {
 119+ function showReplyForm( $thread ) {
120120 $pp = new PostProxy( null, $this->request );
121 - $this->showEditingFormInGeneral( $pp, 'reply', $post->getID() );
 121+ $this->showEditingFormInGeneral( $pp, 'reply', $thread );
122122 }
123123
124124 function showEditingFormInGeneral( $post_proxy, $edit_type, $edit_applies_to ) {
125125
126126 $pp = $post_proxy;
127127
128 - $this->output->addHTML("<p>Doing an $edit_type to $edit_applies_to.");
 128+ // If there is no article, we need a randomly-generated title. On the first pass,
 129+ // we generate one. After that, we find it in the request.
 130+ if ( $pp->article == null ) {
 131+ $rt = Title::newFromURL( $pp->request->getVal('lqt_edit_post') );
 132+ $t = $rt ? $rt : $this->scratchTitle();
 133+ $article = new Article( $t );
 134+ } else {
 135+ $article = $pp->article;
 136+ }
129137
130138 // this only works for editing because we refer to the article directly.
131139
132 - $e = new EditPage($pp->article);
133 - $e->editFormTextBottom .= "<input type=\"hidden\" name=\"lqt_edit_post\" value=\"{$pp->article->getID()}\">";
134 -// $e->setAction( $this->title->getFullURL( "lqt_edit_post={$pp->article->getID()}" ) );
 140+ $e = new EditPage($article);
 141+ $e->editFormTextBottom .= "<input type=\"hidden\" name=\"lqt_edit_post\" value=\"{$article->getTitle()->getPrefixedURL()}\">";
 142+
 143+ if ( $edit_type == 'reply' ) {
 144+ $e->editFormTextBottom .= "<input type=\"hidden\" name=\"lqt_reply_to\" value=\"{$edit_applies_to->id()}\">";
 145+ }
135146
136147 /* if ( $p->thread()->firstPost()->getID() == $p->getID() ) {
137148 // This is the thread's root post; display topic field.
@@ -145,15 +156,20 @@
146157 // $wgOut->setArticleRelated( false );
147158 $this->output->setArticleFlag( false );
148159
149 - // Override editpage's redirect.
150 -// if ($e->didRedirect) {
151160 // I have lost track of where the redirect happens, so I can't set a flag there until I find it.
152161 // In the meantime, just check if somewhere somebody redirected. I'm afraid this might have
153162 // unwanted side-effects.
154163 if ( $this->output->getRedirect() != '' ) {
155 - $t = $pp->article->getTitle()->getPartialURL();
156164 $this->output->redirect( $this->title->getFullURL() );
157165 }
 166+
 167+ // If this is a reply and the page was saved, we need to create a new thread
 168+ // pointing to the new page and with the appropriate superthread.
 169+ if ($edit_type == 'reply' && $e->didSave) {
 170+ // TODO this is two database writes instead of one.
 171+ $t = Thread::newThread( $article, $this->article );
 172+ $t->setSuperthread( $edit_applies_to );
 173+ }
158174
159175 /* // Save new topic line if there is one:
160176 if ( $e->mDidSave && $wgRequest->getVal('lqt_topic') ) {
@@ -161,6 +177,11 @@
162178 $p->setSubject($v);
163179 }*/
164180 }
 181+
 182+ function scratchTitle() {
 183+ $token = md5(uniqid(rand(), true));
 184+ return Title::newFromText( "Post:$token" );
 185+ }
165186
166187
167188 function showPostBody( $post ) {
@@ -188,10 +209,10 @@
189210 }
190211 }
191212
192 - function showPostCommands( $post ) {
 213+ function showThreadCommands( $thread ) {
193214
194 - $commands = array( 'Edit' => $this->selflink( array( LQT_COMMAND_EDIT_POST => $post->getID() ) ),
195 - 'Reply' => $this->selflink( array( LQT_COMMAND_REPLY_TO_POST => $post->getID() ) ));
 215+ $commands = array( 'Edit' => $this->selflink( array( LQT_COMMAND_EDIT_POST => $thread->rootPost()->getTitle()->getPrefixedURL() ) ),
 216+ 'Reply' => $this->selflink( array( LQT_COMMAND_REPLY_TO_POST => $thread->id() ) ));
196217
197218 $this->output->addHTML(wfOpenElement('ul', array('class'=>'lqt_footer')));
198219
@@ -204,21 +225,23 @@
205226 $this->output->addHTML(wfCloseELement('ul'));
206227 }
207228
208 - function showPost( $post ) {
 229+ function showRootPost( $thread ) {
 230+ $post = $thread->rootPost();
 231+
209232 $this->openDiv( 'lqt_post' );
210233
211234 if( $this->commandApplies( LQT_COMMAND_EDIT_POST, $post ) ) {
212235 $this->showPostEditingForm( $post );
213236 } else{
214237 $this->showPostBody( $post );
215 - $this->showPostCommands( $post );
 238+ $this->showThreadCommands( $thread );
216239 }
217240
218241 $this->closeDiv();
219242
220 - if( $this->commandApplies( LQT_COMMAND_REPLY_TO_POST, $post ) ) {
 243+ if( $this->commandAppliesToThread( LQT_COMMAND_REPLY_TO_POST, $thread ) ) {
221244 $this->indent();
222 - $this->showReplyForm( $post );
 245+ $this->showReplyForm( $thread );
223246 $this->unindent();
224247 }
225248 }
@@ -230,7 +253,7 @@
231254
232255 function showThread( $thread ) {
233256 $this->showThreadHeading( $thread );
234 - $this->showPost( $thread->rootPost() );
 257+ $this->showRootPost( $thread );
235258 $this->indent();
236259 foreach( $thread->subthreads() as $st ) {
237260 $this->showThread($st);
Index: branches/liquidthreads/extensions/LqtModel.php
@@ -115,10 +115,6 @@
116116 /* Identity */
117117 protected $id;
118118
119 - /**
120 - * Make the given Post a reply to this.
121 - *
122 - */
123119 function setSuperthread($thread) {
124120 $this->superthreadId = $thread->id();
125121 $this->updateRecord();
@@ -182,7 +178,23 @@
183179 $t->subject = $line->thread_subject;
184180 return $t;
185181 }
 182+
 183+ static function newFromId( $id ) {
 184+ $foo = Thread::threadsWhere( array('thread_id' => $id) );
 185+ return count($foo) > 0 ? $foo[0] : null;
 186+ }
186187
 188+ static function newThread( $root_post, $article ) {
 189+ $dbr =& wfGetDB( DB_MASTER );
 190+ $res = $dbr->insert('lqt_thread',
 191+ array('thread_article' => $article->getID(),
 192+ 'thread_root_post' => $root_post->getID(),
 193+ 'thread_touched' => wfTimestampNow()),
 194+ __METHOD__);
 195+ // TODO we could avoid a query here.
 196+ return Thread::newFromId( $dbr->insertId() );
 197+ }
 198+
187199 static function latestNThreadsOfArticle( $article, $n ) {
188200 return Thread::threadsWhere( array('thread_article' => $article->getID(),
189201 'thread_subthread_of is null'),
@@ -195,6 +207,10 @@
196208 'thread_subthread_of is null'),
197209 array('ORDER BY' => 'thread_touched DESC') );
198210 }
 211+
 212+ static function threadsOfPost( $post ) {
 213+ return Thread::threadsWhere( array('thread_root_post' => $post->getID()) );
 214+ }
199215
200216 static function threadsWhere( $where_clause, $options = array() ) {
201217 $dbr =& wfGetDB( DB_SLAVE );
Index: branches/liquidthreads/includes/EditPage.php
@@ -45,6 +45,7 @@
4646 public $editFormTextAfterTools;
4747 public $editFormTextBottom;
4848
 49+ public $didSave = false; # LQT HACK.
4950
5051 /**
5152 * @todo document
@@ -732,6 +733,7 @@
733734 $isComment=($this->section=='new');
734735 $this->mArticle->insertNewArticle( $this->textbox1, $this->summary,
735736 $this->minoredit, $this->watchthis, false, $isComment);
 737+ $this->didSave = true; # LQT HACK.
736738
737739 wfProfileOut( $fname );
738740 return false;
@@ -865,6 +867,7 @@
866868 # update the article here
867869 if( $this->mArticle->updateArticle( $text, $this->summary, $this->minoredit,
868870 $this->watchthis, '', $sectionanchor ) ) {
 871+ $this->didSave = true; # LQT HACK.
869872 wfProfileOut( $fname );
870873 return false;
871874 } else {