Index: branches/liquidthreads/extensions/LqtExtension.php |
— | — | @@ -81,16 +81,17 @@ |
82 | 82 | @return true if the value of the give query variable name is equal to the given post's ID. |
83 | 83 | */ |
84 | 84 | function commandApplies( $command, $post ) { |
85 | | - |
86 | | - return $this->request->getInt($command) == $post->getID(); |
| 85 | + return $this->request->getVal($command) == $post->getTitle()->getPrefixedURL(); |
87 | 86 | } |
| 87 | + function commandAppliesToThread( $command, $thread ) { |
| 88 | + return $this->request->getVal($command) == $thread->id(); |
| 89 | + } |
88 | 90 | |
89 | 91 | /************************* |
90 | 92 | * Simple HTML methods * |
91 | 93 | *************************/ |
92 | 94 | |
93 | 95 | function openDiv( $class = null ) { |
94 | | - |
95 | 96 | if ( $class ) |
96 | 97 | $this->output->addHTML( wfOpenElement( 'div', array('class'=>$class) ) ); |
97 | 98 | else |
— | — | @@ -98,7 +99,6 @@ |
99 | 100 | } |
100 | 101 | |
101 | 102 | function closeDiv() { |
102 | | - |
103 | 103 | $this->output->addHTML( wfCloseElement( 'div' ) ); |
104 | 104 | } |
105 | 105 | |
— | — | @@ -112,25 +112,36 @@ |
113 | 113 | |
114 | 114 | function showPostEditingForm( $post ) { |
115 | 115 | $pp = new PostProxy( $post, $this->request ); |
116 | | - $this->showEditingFormInGeneral( $pp, 'editExisting', $post->getID() ); |
| 116 | + $this->showEditingFormInGeneral( $pp, 'editExisting', $post->getTitle() ); |
117 | 117 | } |
118 | 118 | |
119 | | - function showReplyForm( $post ) { |
| 119 | + function showReplyForm( $thread ) { |
120 | 120 | $pp = new PostProxy( null, $this->request ); |
121 | | - $this->showEditingFormInGeneral( $pp, 'reply', $post->getID() ); |
| 121 | + $this->showEditingFormInGeneral( $pp, 'reply', $thread ); |
122 | 122 | } |
123 | 123 | |
124 | 124 | function showEditingFormInGeneral( $post_proxy, $edit_type, $edit_applies_to ) { |
125 | 125 | |
126 | 126 | $pp = $post_proxy; |
127 | 127 | |
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 | + } |
129 | 137 | |
130 | 138 | // this only works for editing because we refer to the article directly. |
131 | 139 | |
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 | + } |
135 | 146 | |
136 | 147 | /* if ( $p->thread()->firstPost()->getID() == $p->getID() ) { |
137 | 148 | // This is the thread's root post; display topic field. |
— | — | @@ -145,15 +156,20 @@ |
146 | 157 | // $wgOut->setArticleRelated( false ); |
147 | 158 | $this->output->setArticleFlag( false ); |
148 | 159 | |
149 | | - // Override editpage's redirect. |
150 | | -// if ($e->didRedirect) { |
151 | 160 | // I have lost track of where the redirect happens, so I can't set a flag there until I find it. |
152 | 161 | // In the meantime, just check if somewhere somebody redirected. I'm afraid this might have |
153 | 162 | // unwanted side-effects. |
154 | 163 | if ( $this->output->getRedirect() != '' ) { |
155 | | - $t = $pp->article->getTitle()->getPartialURL(); |
156 | 164 | $this->output->redirect( $this->title->getFullURL() ); |
157 | 165 | } |
| 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 | + } |
158 | 174 | |
159 | 175 | /* // Save new topic line if there is one: |
160 | 176 | if ( $e->mDidSave && $wgRequest->getVal('lqt_topic') ) { |
— | — | @@ -161,6 +177,11 @@ |
162 | 178 | $p->setSubject($v); |
163 | 179 | }*/ |
164 | 180 | } |
| 181 | + |
| 182 | + function scratchTitle() { |
| 183 | + $token = md5(uniqid(rand(), true)); |
| 184 | + return Title::newFromText( "Post:$token" ); |
| 185 | + } |
165 | 186 | |
166 | 187 | |
167 | 188 | function showPostBody( $post ) { |
— | — | @@ -188,10 +209,10 @@ |
189 | 210 | } |
190 | 211 | } |
191 | 212 | |
192 | | - function showPostCommands( $post ) { |
| 213 | + function showThreadCommands( $thread ) { |
193 | 214 | |
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() ) )); |
196 | 217 | |
197 | 218 | $this->output->addHTML(wfOpenElement('ul', array('class'=>'lqt_footer'))); |
198 | 219 | |
— | — | @@ -204,21 +225,23 @@ |
205 | 226 | $this->output->addHTML(wfCloseELement('ul')); |
206 | 227 | } |
207 | 228 | |
208 | | - function showPost( $post ) { |
| 229 | + function showRootPost( $thread ) { |
| 230 | + $post = $thread->rootPost(); |
| 231 | + |
209 | 232 | $this->openDiv( 'lqt_post' ); |
210 | 233 | |
211 | 234 | if( $this->commandApplies( LQT_COMMAND_EDIT_POST, $post ) ) { |
212 | 235 | $this->showPostEditingForm( $post ); |
213 | 236 | } else{ |
214 | 237 | $this->showPostBody( $post ); |
215 | | - $this->showPostCommands( $post ); |
| 238 | + $this->showThreadCommands( $thread ); |
216 | 239 | } |
217 | 240 | |
218 | 241 | $this->closeDiv(); |
219 | 242 | |
220 | | - if( $this->commandApplies( LQT_COMMAND_REPLY_TO_POST, $post ) ) { |
| 243 | + if( $this->commandAppliesToThread( LQT_COMMAND_REPLY_TO_POST, $thread ) ) { |
221 | 244 | $this->indent(); |
222 | | - $this->showReplyForm( $post ); |
| 245 | + $this->showReplyForm( $thread ); |
223 | 246 | $this->unindent(); |
224 | 247 | } |
225 | 248 | } |
— | — | @@ -230,7 +253,7 @@ |
231 | 254 | |
232 | 255 | function showThread( $thread ) { |
233 | 256 | $this->showThreadHeading( $thread ); |
234 | | - $this->showPost( $thread->rootPost() ); |
| 257 | + $this->showRootPost( $thread ); |
235 | 258 | $this->indent(); |
236 | 259 | foreach( $thread->subthreads() as $st ) { |
237 | 260 | $this->showThread($st); |
Index: branches/liquidthreads/extensions/LqtModel.php |
— | — | @@ -115,10 +115,6 @@ |
116 | 116 | /* Identity */ |
117 | 117 | protected $id; |
118 | 118 | |
119 | | - /** |
120 | | - * Make the given Post a reply to this. |
121 | | - * |
122 | | - */ |
123 | 119 | function setSuperthread($thread) { |
124 | 120 | $this->superthreadId = $thread->id(); |
125 | 121 | $this->updateRecord(); |
— | — | @@ -182,7 +178,23 @@ |
183 | 179 | $t->subject = $line->thread_subject; |
184 | 180 | return $t; |
185 | 181 | } |
| 182 | + |
| 183 | + static function newFromId( $id ) { |
| 184 | + $foo = Thread::threadsWhere( array('thread_id' => $id) ); |
| 185 | + return count($foo) > 0 ? $foo[0] : null; |
| 186 | + } |
186 | 187 | |
| 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 | + |
187 | 199 | static function latestNThreadsOfArticle( $article, $n ) { |
188 | 200 | return Thread::threadsWhere( array('thread_article' => $article->getID(), |
189 | 201 | 'thread_subthread_of is null'), |
— | — | @@ -195,6 +207,10 @@ |
196 | 208 | 'thread_subthread_of is null'), |
197 | 209 | array('ORDER BY' => 'thread_touched DESC') ); |
198 | 210 | } |
| 211 | + |
| 212 | + static function threadsOfPost( $post ) { |
| 213 | + return Thread::threadsWhere( array('thread_root_post' => $post->getID()) ); |
| 214 | + } |
199 | 215 | |
200 | 216 | static function threadsWhere( $where_clause, $options = array() ) { |
201 | 217 | $dbr =& wfGetDB( DB_SLAVE ); |
Index: branches/liquidthreads/includes/EditPage.php |
— | — | @@ -45,6 +45,7 @@ |
46 | 46 | public $editFormTextAfterTools; |
47 | 47 | public $editFormTextBottom; |
48 | 48 | |
| 49 | + public $didSave = false; # LQT HACK. |
49 | 50 | |
50 | 51 | /** |
51 | 52 | * @todo document |
— | — | @@ -732,6 +733,7 @@ |
733 | 734 | $isComment=($this->section=='new'); |
734 | 735 | $this->mArticle->insertNewArticle( $this->textbox1, $this->summary, |
735 | 736 | $this->minoredit, $this->watchthis, false, $isComment); |
| 737 | + $this->didSave = true; # LQT HACK. |
736 | 738 | |
737 | 739 | wfProfileOut( $fname ); |
738 | 740 | return false; |
— | — | @@ -865,6 +867,7 @@ |
866 | 868 | # update the article here |
867 | 869 | if( $this->mArticle->updateArticle( $text, $this->summary, $this->minoredit, |
868 | 870 | $this->watchthis, '', $sectionanchor ) ) { |
| 871 | + $this->didSave = true; # LQT HACK. |
869 | 872 | wfProfileOut( $fname ); |
870 | 873 | return false; |
871 | 874 | } else { |