r85749 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85748‎ | r85749 | r85750 >
Date:07:17, 10 April 2011
Author:werdna
Status:deferred
Tags:
Comment:
LiquidThreads backend rewrite: Now fully tested and ready for integration with the front-end
Modified paths:
  • /branches/lqt-updates/extensions/LiquidThreads/LiquidThreads.php (modified) (history)
  • /branches/lqt-updates/extensions/LiquidThreads/classes/model/Channel.php (added) (history)
  • /branches/lqt-updates/extensions/LiquidThreads/classes/model/Object.php (modified) (history)
  • /branches/lqt-updates/extensions/LiquidThreads/classes/model/Post.php (modified) (history)
  • /branches/lqt-updates/extensions/LiquidThreads/classes/model/PostVersion.php (modified) (history)
  • /branches/lqt-updates/extensions/LiquidThreads/classes/model/Topic.php (modified) (history)
  • /branches/lqt-updates/extensions/LiquidThreads/classes/model/TopicVersion.php (modified) (history)
  • /branches/lqt-updates/extensions/LiquidThreads/new-schema.sql (modified) (history)

Diff [purge]

Index: branches/lqt-updates/extensions/LiquidThreads/new-schema.sql
@@ -10,7 +10,10 @@
1111
1212 -- NS/title pair of the talk page this channel is attached to.
1313 lqc_page_namespace int(2) not null,
14 - lqc_page_title varbinary(255) not null
 14+ lqc_page_title varbinary(255) not null,
 15+
 16+ PRIMARY KEY (lqc_id),
 17+ UNIQUE KEY (lqc_page_namespace,lqc_page_title)
1518 ) /*$wgDBTableOptions*/;
1619
1720 -- Topic table
@@ -23,11 +26,14 @@
2427 lqt_current_version bigint(10) unsigned not null,
2528
2629 -- Cache of the number of replies
27 - lqp_replies int unsigned not null,
 30+ lqt_replies int unsigned not null,
2831
2932 -- The Channel that this topic is contained in.
3033 -- Foreign key to lqt_channel.lqc_id
3134 lqt_channel bigint(10) unsigned not null,
 35+
 36+ PRIMARY KEY (lqt_id),
 37+ KEY (lqt_channel)
3238 ) /*$wgDBTableOptions*/;
3339
3440 -- Topic Version table
@@ -52,8 +58,16 @@
5359 -- Bitfield for single-version deletion
5460 ltv_deleted tinyint unsigned NOT NULL default 0,
5561
 62+ -- Pointer to the text table, stores the summary text.
 63+ -- Foreign key to text.old_id
 64+ ltv_summary_text_id bigint(10) unsigned not null,
 65+
5666 ltv_subject TINYBLOB NOT NULL,
57 - ltv_channel bigint(10) unsigned not null
 67+ ltv_channel bigint(10) unsigned not null,
 68+
 69+ PRIMARY KEY (ltv_id),
 70+ KEY (ltv_topic, ltv_timestamp),
 71+ KEY (ltv_user_id,ltv_user_ip)
5872 ) /*$wgDBTableOptions*/;
5973
6074 -- Post table
@@ -77,8 +91,11 @@
7892
7993 -- Parent post. Potentially blank, if it's at the top level in the topic.
8094 -- Foreign key to lqt_post.lqp_id
81 - lqp_parent_post bigint(10) unsigned null
 95+ lqp_parent_post bigint(10) unsigned null,
8296
 97+ PRIMARY KEY (lqp_id),
 98+ KEY (lqp_topic, lqp_parent_post)
 99+
83100 ) /*$wgDBTableOptions*/;
84101
85102 -- Post Version table
@@ -125,5 +142,8 @@
126143 lpv_parent_post bigint(10) unsigned null,
127144
128145 -- Signature
129 - lpv_signature TINYBLOB NOT NULL
 146+ lpv_signature TINYBLOB NOT NULL,
 147+
 148+ PRIMARY KEY (lpv_id),
 149+ KEY (lpv_post, lpv_timestamp)
130150 ) /*$wgDBTableOptions*/;
Index: branches/lqt-updates/extensions/LiquidThreads/LiquidThreads.php
@@ -13,10 +13,12 @@
1414
1515 require( 'LqtFunctions.php' );
1616
 17+// @deprecated
1718 define( 'NS_LQT_THREAD', efArrayDefault( 'egLqtNamespaceNumbers', 'Thread', 90 ) );
1819 define( 'NS_LQT_THREAD_TALK', efArrayDefault( 'egLqtNamespaceNumbers', 'Thread_talk', 91 ) );
1920 define( 'NS_LQT_SUMMARY', efArrayDefault( 'egLqtNamespaceNumbers', 'Summary', 92 ) );
2021 define( 'NS_LQT_SUMMARY_TALK', efArrayDefault( 'egLqtNamespaceNumbers', 'Summary_talk', 93 ) );
 22+
2123 define( 'LQT_NEWEST_CHANGES', 'nc' );
2224 define( 'LQT_NEWEST_THREADS', 'nt' );
2325 define( 'LQT_OLDEST_THREADS', 'ot' );
@@ -82,165 +84,176 @@
8385
8486 // Hooks
8587 // Parser Function Setup
86 -$wgHooks['ParserFirstCallInit'][] = 'LqtHooks::onParserFirstCallInit';
8788
88 -// Namespaces
89 -$wgHooks['CanonicalNamespaces'][] = 'LqtHooks::onCanonicalNamespaces';
 89+// Commented out for testing
 90+//
 91+// $wgHooks['ParserFirstCallInit'][] = 'LqtHooks::onParserFirstCallInit';
 92+//
 93+// // Namespaces
 94+// $wgHooks['CanonicalNamespaces'][] = 'LqtHooks::onCanonicalNamespaces';
 95+//
 96+// // Main dispatch hook
 97+// $wgHooks['MediaWikiPerformAction'][] = 'LqtDispatch::tryPage';
 98+// $wgHooks['SkinTemplateTabs'][] = 'LqtDispatch::onSkinTemplateTabs';
 99+// $wgHooks['SkinTemplateNavigation'][] = 'LqtDispatch::onSkinTemplateNavigation';
 100+//
 101+// // Customisation of recentchanges
 102+// $wgHooks['OldChangesListRecentChangesLine'][] = 'LqtHooks::customizeOldChangesList';
 103+//
 104+// // Notification (watchlist, newtalk)
 105+// $wgHooks['SkinTemplateOutputPageBeforeExec'][] = 'LqtHooks::setNewtalkHTML';
 106+// $wgHooks['SpecialWatchlistQuery'][] = 'LqtHooks::beforeWatchlist';
 107+// $wgHooks['ArticleEditUpdateNewTalk'][] = 'LqtHooks::updateNewtalkOnEdit';
 108+// $wgHooks['PersonalUrls'][] = 'LqtHooks::onPersonalUrls';
 109+//
 110+// // Preferences
 111+// $wgHooks['GetPreferences'][] = 'LqtHooks::getPreferences';
 112+//
 113+// // Export-related
 114+// $wgHooks['XmlDumpWriterOpenPage'][] = 'LqtHooks::dumpThreadData';
 115+// $wgHooks['ModifyExportQuery'][] = 'LqtHooks::modifyExportQuery';
 116+// $wgHooks['OAIFetchRowsQuery'][] = 'LqtHooks::modifyOAIQuery';
 117+// $wgHooks['OAIFetchRecordQuery'][] = 'LqtHooks::modifyOAIQuery';
 118+//
 119+// // Import-related
 120+// $wgHooks['ImportHandlePageXMLTag'][] = 'LqtHooks::handlePageXMLTag';
 121+// $wgHooks['AfterImportPage'][] = 'LqtHooks::afterImportPage';
 122+//
 123+// // Deletion
 124+// $wgHooks['ArticleDeleteComplete'][] = 'LqtDeletionController::onArticleDeleteComplete';
 125+// $wgHooks['ArticleRevisionUndeleted'][] = 'LqtDeletionController::onArticleRevisionUndeleted';
 126+// $wgHooks['ArticleUndelete'][] = 'LqtDeletionController::onArticleUndelete';
 127+// $wgHooks['ArticleConfirmDelete'][] = 'LqtDeletionController::onArticleConfirmDelete';
 128+// $wgHooks['ArticleDelete'][] = 'LqtDeletionController::onArticleDelete';
 129+//
 130+// // Moving
 131+// $wgHooks['SpecialMovepageAfterMove'][] = 'LqtHooks::onArticleMoveComplete';
 132+// $wgHooks['AbortMove'][] = 'LqtHooks::onArticleMove';
 133+//
 134+// // Search
 135+// $wgHooks['ShowSearchHitTitle'][] = 'LqtHooks::customiseSearchResultTitle';
 136+// $wgHooks['SpecialSearchProfiles'][] = 'LqtHooks::customiseSearchProfiles';
 137+//
 138+// // Updates
 139+// $wgHooks['LoadExtensionSchemaUpdates'][] = 'LqtHooks::onLoadExtensionSchemaUpdates';
 140+//
 141+// // Rename
 142+// $wgHooks['RenameUserSQL'][] = 'LqtHooks::onUserRename';
 143+//
 144+// // Edit-related
 145+// $wgHooks['EditPageBeforeEditChecks'][] = 'LqtHooks::editCheckBoxes';
 146+// $wgHooks['ArticleSaveComplete'][] = 'LqtHooks::onArticleSaveComplete';
 147+//
 148+// // Blocking
 149+// $wgHooks['UserIsBlockedFrom'][] = 'LqtHooks::userIsBlockedFrom';
 150+//
 151+// // Protection
 152+// $wgHooks['TitleGetRestrictionTypes'][] = 'LqtHooks::getProtectionTypes';
 153+//
 154+// // New User Messages
 155+// $wgHooks['SetupNewUserMessageSubject'][] = 'LqtHooks::setupNewUserMessageSubject';
 156+// $wgHooks['SetupNewUserMessageBody'][] = 'LqtHooks::setupNewUserMessageBody';
 157+// $wgHooks['FormatUserMessage'][] = 'LqtHooks::formatUserMessage';
 158+//
 159+// // User Message
 160+// $wgHooks['SetupUserMessageArticle'][] = 'LqtHooks::setupUserMessageArticle';
 161+// $wgHooks['AfterUserMessage'][] = 'LqtHooks::afterUserMessage';
 162+//
 163+// // JS variables
 164+// $wgHooks['MakeGlobalVariablesScript'][] = 'LqtHooks::onMakeGlobalVariablesScript';
90165
91 -// Main dispatch hook
92 -$wgHooks['MediaWikiPerformAction'][] = 'LqtDispatch::tryPage';
93 -$wgHooks['SkinTemplateTabs'][] = 'LqtDispatch::onSkinTemplateTabs';
94 -$wgHooks['SkinTemplateNavigation'][] = 'LqtDispatch::onSkinTemplateNavigation';
95 -
96 -// Customisation of recentchanges
97 -$wgHooks['OldChangesListRecentChangesLine'][] = 'LqtHooks::customizeOldChangesList';
98 -
99 -// Notification (watchlist, newtalk)
100 -$wgHooks['SkinTemplateOutputPageBeforeExec'][] = 'LqtHooks::setNewtalkHTML';
101 -$wgHooks['SpecialWatchlistQuery'][] = 'LqtHooks::beforeWatchlist';
102 -$wgHooks['ArticleEditUpdateNewTalk'][] = 'LqtHooks::updateNewtalkOnEdit';
103 -$wgHooks['PersonalUrls'][] = 'LqtHooks::onPersonalUrls';
104 -
105 -// Preferences
106 -$wgHooks['GetPreferences'][] = 'LqtHooks::getPreferences';
107 -
108 -// Export-related
109 -$wgHooks['XmlDumpWriterOpenPage'][] = 'LqtHooks::dumpThreadData';
110 -$wgHooks['ModifyExportQuery'][] = 'LqtHooks::modifyExportQuery';
111 -$wgHooks['OAIFetchRowsQuery'][] = 'LqtHooks::modifyOAIQuery';
112 -$wgHooks['OAIFetchRecordQuery'][] = 'LqtHooks::modifyOAIQuery';
113 -
114 -// Import-related
115 -$wgHooks['ImportHandlePageXMLTag'][] = 'LqtHooks::handlePageXMLTag';
116 -$wgHooks['AfterImportPage'][] = 'LqtHooks::afterImportPage';
117 -
118 -// Deletion
119 -$wgHooks['ArticleDeleteComplete'][] = 'LqtDeletionController::onArticleDeleteComplete';
120 -$wgHooks['ArticleRevisionUndeleted'][] = 'LqtDeletionController::onArticleRevisionUndeleted';
121 -$wgHooks['ArticleUndelete'][] = 'LqtDeletionController::onArticleUndelete';
122 -$wgHooks['ArticleConfirmDelete'][] = 'LqtDeletionController::onArticleConfirmDelete';
123 -$wgHooks['ArticleDelete'][] = 'LqtDeletionController::onArticleDelete';
124 -
125 -// Moving
126 -$wgHooks['SpecialMovepageAfterMove'][] = 'LqtHooks::onArticleMoveComplete';
127 -$wgHooks['AbortMove'][] = 'LqtHooks::onArticleMove';
128 -
129 -// Search
130 -$wgHooks['ShowSearchHitTitle'][] = 'LqtHooks::customiseSearchResultTitle';
131 -$wgHooks['SpecialSearchProfiles'][] = 'LqtHooks::customiseSearchProfiles';
132 -
133 -// Updates
134 -$wgHooks['LoadExtensionSchemaUpdates'][] = 'LqtHooks::onLoadExtensionSchemaUpdates';
135 -
136 -// Rename
137 -$wgHooks['RenameUserSQL'][] = 'LqtHooks::onUserRename';
138 -
139 -// Edit-related
140 -$wgHooks['EditPageBeforeEditChecks'][] = 'LqtHooks::editCheckBoxes';
141 -$wgHooks['ArticleSaveComplete'][] = 'LqtHooks::onArticleSaveComplete';
142 -
143 -// Blocking
144 -$wgHooks['UserIsBlockedFrom'][] = 'LqtHooks::userIsBlockedFrom';
145 -
146 -// Protection
147 -$wgHooks['TitleGetRestrictionTypes'][] = 'LqtHooks::getProtectionTypes';
148 -
149 -// New User Messages
150 -$wgHooks['SetupNewUserMessageSubject'][] = 'LqtHooks::setupNewUserMessageSubject';
151 -$wgHooks['SetupNewUserMessageBody'][] = 'LqtHooks::setupNewUserMessageBody';
152 -$wgHooks['FormatUserMessage'][] = 'LqtHooks::formatUserMessage';
153 -
154 -// User Message
155 -$wgHooks['SetupUserMessageArticle'][] = 'LqtHooks::setupUserMessageArticle';
156 -$wgHooks['AfterUserMessage'][] = 'LqtHooks::afterUserMessage';
157 -
158 -// JS variables
159 -$wgHooks['MakeGlobalVariablesScript'][] = 'LqtHooks::onMakeGlobalVariablesScript';
160 -
161 -// Special pages
162 -$wgSpecialPages['MoveThread'] = 'SpecialMoveThread';
163 -$wgSpecialPages['NewMessages'] = 'SpecialNewMessages';
164 -$wgSpecialPages['SplitThread'] = 'SpecialSplitThread';
165 -$wgSpecialPages['MergeThread'] = 'SpecialMergeThread';
 166+// // Special pages
 167+// $wgSpecialPages['MoveThread'] = 'SpecialMoveThread';
 168+// $wgSpecialPages['NewMessages'] = 'SpecialNewMessages';
 169+// $wgSpecialPages['SplitThread'] = 'SpecialSplitThread';
 170+// $wgSpecialPages['MergeThread'] = 'SpecialMergeThread';
166171 // $wgSpecialPages['HotTopics'] = 'SpecialHotTopics';
167 -$wgSpecialPageGroups['NewMessages'] = 'wiki';
 172+// $wgSpecialPageGroups['NewMessages'] = 'wiki';
 173+//
 174+// // Embedding
 175+// $wgHooks['OutputPageParserOutput'][] = 'LqtParserFunctions::onAddParserOutput';
 176+// $wgHooks['OutputPageBeforeHTML'][] = 'LqtParserFunctions::onAddHTML';
 177+//
 178+// // Permissions
 179+// $wgHooks['userCan'][] = 'LqtHooks::onGetUserPermissionsErrors';
 180+//
 181+// // Classes
 182+// $wgAutoloadClasses['LqtDispatch'] = $dir . 'classes/Dispatch.php';
 183+// $wgAutoloadClasses['LqtView'] = $dir . 'classes/View.php';
 184+// $wgAutoloadClasses['HistoricalThread'] = $dir . 'classes/HistoricalThread.php';
 185+// $wgAutoloadClasses['Thread'] = $dir . 'classes/Thread.php';
 186+// $wgAutoloadClasses['Threads'] = $dir . 'classes/Threads.php';
 187+// $wgAutoloadClasses['NewMessages'] = $dir . 'classes/NewMessagesController.php';
 188+// $wgAutoloadClasses['LqtParserFunctions'] = $dir . 'classes/ParserFunctions.php';
 189+// $wgAutoloadClasses['LqtDeletionController'] = $dir . 'classes/DeletionController.php';
 190+// $wgAutoloadClasses['LqtHooks'] = $dir . 'classes/Hooks.php';
 191+// $wgAutoloadClasses['ThreadRevision'] = $dir . "classes/ThreadRevision.php";
 192+// $wgAutoloadClasses['SynchroniseThreadArticleDataJob'] = $dir . 'classes/SynchroniseThreadArticleDataJob.php';
 193+// $wgAutoloadClasses['ThreadHistoryPager'] = $dir . 'classes/ThreadHistoryPager.php';
 194+// $wgAutoloadClasses['TalkpageHistoryView'] = $dir . 'pages/TalkpageHistoryView.php';
 195+// $wgAutoloadClasses['LqtHotTopicsController'] = $dir . 'classes/HotTopics.php';
 196+// $wgAutoloadClasses['LqtLogFormatter'] = $dir . 'classes/LogFormatter.php';
 197+//
 198+// // View classes
 199+// $wgAutoloadClasses['TalkpageView'] = $dir . 'pages/TalkpageView.php';
 200+// $wgAutoloadClasses['ThreadPermalinkView'] = $dir . 'pages/ThreadPermalinkView.php';
 201+// $wgAutoloadClasses['TalkpageHeaderView'] = $dir . 'pages/TalkpageHeaderView.php';
 202+// $wgAutoloadClasses['IndividualThreadHistoryView'] = $dir . 'pages/IndividualThreadHistoryView.php';
 203+// $wgAutoloadClasses['ThreadDiffView'] = $dir . 'pages/ThreadDiffView.php';
 204+// $wgAutoloadClasses['ThreadWatchView'] = $dir . 'pages/ThreadWatchView.php';
 205+// $wgAutoloadClasses['ThreadProtectionFormView'] = $dir . 'pages/ThreadProtectionFormView.php';
 206+// $wgAutoloadClasses['ThreadHistoryListingView'] = $dir . 'pages/ThreadHistoryListingView.php';
 207+// $wgAutoloadClasses['ThreadHistoricalRevisionView'] = $dir . 'pages/ThreadHistoricalRevisionView.php';
 208+// $wgAutoloadClasses['SummaryPageView'] = $dir . 'pages/SummaryPageView.php';
 209+// $wgAutoloadClasses['NewUserMessagesView'] = $dir . 'pages/NewUserMessagesView.php';
 210+//
 211+// // Pagers
 212+// $wgAutoloadClasses['LqtDiscussionPager'] = $dir . "pages/TalkpageView.php";
 213+//
 214+// // Special pages
 215+// $wgAutoloadClasses['ThreadActionPage'] = $dir . 'pages/ThreadActionPage.php';
 216+// $wgAutoloadClasses['SpecialMoveThread'] = $dir . 'pages/SpecialMoveThread.php';
 217+// $wgAutoloadClasses['SpecialNewMessages'] = $dir . 'pages/SpecialNewMessages.php';
 218+// $wgAutoloadClasses['SpecialSplitThread'] = $dir . 'pages/SpecialSplitThread.php';
 219+// $wgAutoloadClasses['SpecialMergeThread'] = $dir . 'pages/SpecialMergeThread.php';
 220+//
 221+// // Job queue
 222+// $wgJobClasses['synchroniseThreadArticleData'] = 'SynchroniseThreadArticleDataJob';
 223+//
 224+// // Logging
 225+// $wgLogTypes[] = 'liquidthreads';
 226+// $wgLogNames['liquidthreads'] = 'lqt-log-name';
 227+// $wgLogHeaders['liquidthreads'] = 'lqt-log-header';
 228+//
 229+// foreach ( array( 'move', 'split', 'merge', 'subjectedit', 'resort' ) as $action ) {
 230+// $wgLogActionsHandlers["liquidthreads/$action"] = 'LqtLogFormatter::formatLogEntry';
 231+// }
 232+//
 233+// // Preferences
 234+// $wgDefaultUserOptions['lqtnotifytalk'] = false;
 235+// $wgDefaultUserOptions['lqtdisplaydepth'] = 5;
 236+// $wgDefaultUserOptions['lqtdisplaycount'] = 25;
 237+// $wgDefaultUserOptions['lqtcustomsignatures'] = true;
 238+//
 239+// // API
 240+// $wgAutoloadClasses['ApiQueryLQTThreads'] = $dir . 'api/ApiQueryLQTThreads.php';
 241+// $wgAPIListModules['threads'] = 'ApiQueryLQTThreads';
 242+// $wgAutoloadClasses['ApiFeedLQTThreads'] = $dir . 'api/ApiFeedLQTThreads.php';
 243+// $wgAPIModules['feedthreads'] = 'ApiFeedLQTThreads';
 244+// $wgAutoloadClasses['ApiThreadAction'] = $dir . '/api/ApiThreadAction.php';
 245+// $wgAPIModules['threadaction'] = 'ApiThreadAction';
 246+//
 247+// // Path to the LQT directory
 248+// $wgLiquidThreadsExtensionPath = "{$wgScriptPath}/extensions/LiquidThreads";
168249
169 -// Embedding
170 -$wgHooks['OutputPageParserOutput'][] = 'LqtParserFunctions::onAddParserOutput';
171 -$wgHooks['OutputPageBeforeHTML'][] = 'LqtParserFunctions::onAddHTML';
 250+$wgAutoloadClasses['LiquidThreadsObject'] = "$dir/classes/model/Object.php";
 251+$wgAutoloadClasses['LiquidThreadsVersionedObject'] = "$dir/classes/model/VersionedObject.php";
 252+$wgAutoloadClasses['LiquidThreadsPost'] = "$dir/classes/model/Post.php";
 253+$wgAutoloadClasses['LiquidThreadsPostVersion'] = "$dir/classes/model/PostVersion.php";
 254+$wgAutoloadClasses['LiquidThreadsTopic'] = "$dir/classes/model/Topic.php";
 255+$wgAutoloadClasses['LiquidThreadsTopicVersion'] = "$dir/classes/model/TopicVersion.php";
 256+$wgAutoloadClasses['LiquidThreadsChannel'] = "$dir/classes/model/Channel.php";
172257
173 -// Permissions
174 -$wgHooks['userCan'][] = 'LqtHooks::onGetUserPermissionsErrors';
175 -
176 -// Classes
177 -$wgAutoloadClasses['LqtDispatch'] = $dir . 'classes/Dispatch.php';
178 -$wgAutoloadClasses['LqtView'] = $dir . 'classes/View.php';
179 -$wgAutoloadClasses['HistoricalThread'] = $dir . 'classes/HistoricalThread.php';
180 -$wgAutoloadClasses['Thread'] = $dir . 'classes/Thread.php';
181 -$wgAutoloadClasses['Threads'] = $dir . 'classes/Threads.php';
182 -$wgAutoloadClasses['NewMessages'] = $dir . 'classes/NewMessagesController.php';
183 -$wgAutoloadClasses['LqtParserFunctions'] = $dir . 'classes/ParserFunctions.php';
184 -$wgAutoloadClasses['LqtDeletionController'] = $dir . 'classes/DeletionController.php';
185 -$wgAutoloadClasses['LqtHooks'] = $dir . 'classes/Hooks.php';
186 -$wgAutoloadClasses['ThreadRevision'] = $dir . "classes/ThreadRevision.php";
187 -$wgAutoloadClasses['SynchroniseThreadArticleDataJob'] = $dir . 'classes/SynchroniseThreadArticleDataJob.php';
188 -$wgAutoloadClasses['ThreadHistoryPager'] = $dir . 'classes/ThreadHistoryPager.php';
189 -$wgAutoloadClasses['TalkpageHistoryView'] = $dir . 'pages/TalkpageHistoryView.php';
190 -$wgAutoloadClasses['LqtHotTopicsController'] = $dir . 'classes/HotTopics.php';
191 -$wgAutoloadClasses['LqtLogFormatter'] = $dir . 'classes/LogFormatter.php';
192 -
193 -// View classes
194 -$wgAutoloadClasses['TalkpageView'] = $dir . 'pages/TalkpageView.php';
195 -$wgAutoloadClasses['ThreadPermalinkView'] = $dir . 'pages/ThreadPermalinkView.php';
196 -$wgAutoloadClasses['TalkpageHeaderView'] = $dir . 'pages/TalkpageHeaderView.php';
197 -$wgAutoloadClasses['IndividualThreadHistoryView'] = $dir . 'pages/IndividualThreadHistoryView.php';
198 -$wgAutoloadClasses['ThreadDiffView'] = $dir . 'pages/ThreadDiffView.php';
199 -$wgAutoloadClasses['ThreadWatchView'] = $dir . 'pages/ThreadWatchView.php';
200 -$wgAutoloadClasses['ThreadProtectionFormView'] = $dir . 'pages/ThreadProtectionFormView.php';
201 -$wgAutoloadClasses['ThreadHistoryListingView'] = $dir . 'pages/ThreadHistoryListingView.php';
202 -$wgAutoloadClasses['ThreadHistoricalRevisionView'] = $dir . 'pages/ThreadHistoricalRevisionView.php';
203 -$wgAutoloadClasses['SummaryPageView'] = $dir . 'pages/SummaryPageView.php';
204 -$wgAutoloadClasses['NewUserMessagesView'] = $dir . 'pages/NewUserMessagesView.php';
205 -
206 -// Pagers
207 -$wgAutoloadClasses['LqtDiscussionPager'] = $dir . "pages/TalkpageView.php";
208 -
209 -// Special pages
210 -$wgAutoloadClasses['ThreadActionPage'] = $dir . 'pages/ThreadActionPage.php';
211 -$wgAutoloadClasses['SpecialMoveThread'] = $dir . 'pages/SpecialMoveThread.php';
212 -$wgAutoloadClasses['SpecialNewMessages'] = $dir . 'pages/SpecialNewMessages.php';
213 -$wgAutoloadClasses['SpecialSplitThread'] = $dir . 'pages/SpecialSplitThread.php';
214 -$wgAutoloadClasses['SpecialMergeThread'] = $dir . 'pages/SpecialMergeThread.php';
215 -
216 -// Job queue
217 -$wgJobClasses['synchroniseThreadArticleData'] = 'SynchroniseThreadArticleDataJob';
218 -
219 -// Logging
220 -$wgLogTypes[] = 'liquidthreads';
221 -$wgLogNames['liquidthreads'] = 'lqt-log-name';
222 -$wgLogHeaders['liquidthreads'] = 'lqt-log-header';
223 -
224 -foreach ( array( 'move', 'split', 'merge', 'subjectedit', 'resort' ) as $action ) {
225 - $wgLogActionsHandlers["liquidthreads/$action"] = 'LqtLogFormatter::formatLogEntry';
226 -}
227 -
228 -// Preferences
229 -$wgDefaultUserOptions['lqtnotifytalk'] = false;
230 -$wgDefaultUserOptions['lqtdisplaydepth'] = 5;
231 -$wgDefaultUserOptions['lqtdisplaycount'] = 25;
232 -$wgDefaultUserOptions['lqtcustomsignatures'] = true;
233 -
234 -// API
235 -$wgAutoloadClasses['ApiQueryLQTThreads'] = $dir . 'api/ApiQueryLQTThreads.php';
236 -$wgAPIListModules['threads'] = 'ApiQueryLQTThreads';
237 -$wgAutoloadClasses['ApiFeedLQTThreads'] = $dir . 'api/ApiFeedLQTThreads.php';
238 -$wgAPIModules['feedthreads'] = 'ApiFeedLQTThreads';
239 -$wgAutoloadClasses['ApiThreadAction'] = $dir . '/api/ApiThreadAction.php';
240 -$wgAPIModules['threadaction'] = 'ApiThreadAction';
241 -
242 -// Path to the LQT directory
243 -$wgLiquidThreadsExtensionPath = "{$wgScriptPath}/extensions/LiquidThreads";
244 -
245258 /** CONFIGURATION SECTION */
246259
247260 $wgDefaultUserOptions['lqt-watch-threads'] = true;
Index: branches/lqt-updates/extensions/LiquidThreads/classes/model/PostVersion.php
@@ -71,19 +71,20 @@
7272 protected function __construct() {
7373 $this->source = wfGetAllCallers();
7474 }
 75+
 76+// Commented out due to misfires
 77+// /**
 78+// * Default destructor
 79+// * If this Version has yet to be saved, throws an exception.
 80+// * To prevent this behaviour, call destroy()
 81+// */
 82+// public function __destruct() {
 83+// if ( $this->id == 0 && !$this->destroyed ) {
 84+// throw new MWException( "Version object has not been saved nor destroyed. From: " . $this->source );
 85+// }
 86+// }
7587
7688 /**
77 - * Default destructor
78 - * If this Version has yet to be saved, throws an exception.
79 - * To prevent this behaviour, call destroy()
80 - */
81 - public function __destruct() {
82 - if ( $this->id == 0 && !$this->destroyed ) {
83 - throw new MWException( "Version object has not been saved nor destroyed. From: " . $this->source );
84 - }
85 - }
86 -
87 - /**
8889 * Disables the "not saved" error message.
8990 * This MUST be called if you do not plan to save this version.
9091 */
@@ -200,8 +201,7 @@
201202 * Factory method to create a Version for a new Post.
202203 * @return LiquidThreadsPostVersion: A Version object for a new post.
203204 */
204 - public static function createNewPost( LiquidThreadsTopic $topic,
205 - LiquidThreadsPost $parent = null )
 205+ public static function createNewPost( LiquidThreadsTopic $topic, $parent = null )
206206 {
207207 $post = new LiquidThreadsPostVersion;
208208
@@ -235,7 +235,7 @@
236236 $user = User::newFromRow( $row );
237237 }
238238 } elseif ( User::isIP( $row->lpv_user_ip ) ) {
239 - $user = User::newFromName( $row->lpv_user_ip );
 239+ $user = User::newFromName( $row->lpv_user_ip, false );
240240 }
241241
242242 if ( is_null($user) ) {
@@ -244,7 +244,7 @@
245245 $this->versionUser = $user;
246246
247247 // Other metadata
248 - $this->comment = $row->lpv_comment
 248+ $this->comment = $row->lpv_comment;
249249 $this->timestamp = wfTimestamp( TS_MW, $row->lpv_timestamp );
250250 $this->postID = $row->lpv_post;
251251
@@ -257,7 +257,7 @@
258258 $user = User::newFromRow( $row );
259259 }
260260 } elseif ( User::isIP( $row->lpv_poster_ip ) ) {
261 - $user = User::newFromName( $row->lpv_poster_ip );
 261+ $user = User::newFromName( $row->lpv_poster_ip, false );
262262 }
263263
264264 if ( is_null($user) ) {
@@ -301,7 +301,7 @@
302302 $this->signature = $baseVersion->getSignature();
303303
304304 global $wgUser;
305 - $this->editor = $wgUser;
 305+ $this->versionUser = $wgUser;
306306
307307 $this->id = 0;
308308 $this->postID = $post->getID();
@@ -313,19 +313,22 @@
314314 * @param $parent LiquidThreadsPost: (Optional) A parent Post for this one.
315315 */
316316 protected function initialiseNewPost( LiquidThreadsTopic $topic,
317 - LiquidThreadsPost $parent )
 317+ $parent = null )
318318 {
319319 global $wgUser;
320320
321321 $this->id = 0;
322322 $this->poster = $wgUser;
323323 $this->versionUser = $wgUser;
324 - $this->postID = 0;
 324+ $this->postID = 0; // Filled later
325325 $this->textID = 0;
326326 $this->textRow = null;
327327 $this->textDirty = true;
328328 $this->topicID = $topic->getID();
329 - $this->parentID = $parent->getID();
 329+
 330+ if ( $parent ) {
 331+ $this->parentID = $parent->getID();
 332+ }
330333 }
331334
332335 /* SETTING AND SAVING */
@@ -432,11 +435,13 @@
433436 'lpv_post' => $this->postID,
434437 'lpv_timestamp' => $dbw->timestamp( wfTimestampNow() ),
435438 'lpv_comment' => $this->comment,
436 - 'lpv_topic' => $this->
 439+ 'lpv_topic' => $this->topicID,
437440 );
438441
 442+ $this->timestamp = $row['lpv_timestamp'];
 443+
439444 if ( $this->textDirty ) {
440 - $this->textID = self::saveText($this->text);
 445+ $this->textID = LiquidThreadsObject::saveText($this->text);
441446 $this->textDirty = false;
442447 }
443448
@@ -465,55 +470,8 @@
466471 $dbw->insert( 'lqt_post_version', $row, __METHOD__ );
467472
468473 $this->id = $dbw->insertId();
469 -
470 - // Update pointer
471 - if ( $this->postID ) {
472 - $dbw->update( 'lqt_post', array( 'lqp_current_version', $this->id ),
473 - array( 'lqp_id' => $this->postID ), __METHOD__ );
474 - }
475474 }
476 -
477 - /**
478 - * Saves the text to the text table (or external storage).
479 - * @param $data String: The text to save to the text table.
480 - * @return Integer: an ID for the text table.
481 - */
482 - protected static function saveText( $data ) {
483 - global $wgDefaultExternalStore;
484 -
485 - $dbw = wfGetDB( DB_MASTER );
486 -
487 - $flags = Revision::compressRevisionText( $data );
488475
489 - # Write to external storage if required
490 - if( $wgDefaultExternalStore ) {
491 - // Store and get the URL
492 - $data = ExternalStore::insertToDefault( $data );
493 -
494 - if( !$data ) {
495 - throw new MWException( "Unable to store text to external storage" );
496 - }
497 -
498 - if( $flags ) {
499 - $flags .= ',';
500 - }
501 - $flags .= 'external';
502 - }
503 -
504 - # Record the text (or external storage URL) to the text table
505 - $old_id = $dbw->nextSequenceValue( 'text_old_id_seq' );
506 -
507 - $dbw->insert( 'text',
508 - array(
509 - 'old_id' => $old_id,
510 - 'old_text' => $data,
511 - 'old_flags' => $flags,
512 - ), __METHOD__
513 - );
514 -
515 - return $dbw->insertId();
516 - }
517 -
518476 /* PROPERTY ACCESSORS */
519477
520478 /**
@@ -617,4 +575,22 @@
618576 public function getSignature() {
619577 return $this->signature;
620578 }
 579+
 580+ /**
 581+ * Lets you set the post ID, once.
 582+ * Only valid use is from LiquidThreadsPost::save(), for a new LiquidThreadsPost
 583+ * @param $id Integer: The post ID that this version applies to.
 584+ */
 585+ public function setPostID( $id ) {
 586+ if ( $this->postID ) {
 587+ throw new MWException( "Post ID is already set" );
 588+ }
 589+
 590+ $this->postID = $id;
 591+
 592+ $dbw = wfGetDB( DB_MASTER );
 593+ $dbw->update( 'lqt_post_version', array( 'lpv_post' => $id ),
 594+ array( 'lpv_id' => $this->getID() ),
 595+ __METHOD__ );
 596+ }
621597 }
Index: branches/lqt-updates/extensions/LiquidThreads/classes/model/Topic.php
@@ -53,7 +53,8 @@
5454 $fields = '*';
5555 $joins = array(
5656 'lqt_topic_version' => array(
57 - 'left join' => array(
 57+ 'left join',
 58+ array(
5859 'lqt_current_version=ltv_id',
5960 ),
6061 ),
@@ -137,6 +138,7 @@
138139 $this->id = $row->lqt_id;
139140 $this->channelID = $row->lqt_channel;
140141 $this->currentVersionID = $row->lqt_current_version;
 142+ $this->replyCount = $row->lqt_replies;
141143
142144 if ( isset($row->ltv_id) ) {
143145 $version = LiquidThreadsTopicVersion::newFromRow( $row );
@@ -152,8 +154,9 @@
153155 $this->id = 0;
154156
155157 $this->currentVersionID = 0;
156 - $this->currentVersion = LiquidThreadsTopicVersion::createNewTopic();
 158+ $this->currentVersion = LiquidThreadsTopicVersion::createNewTopic( $channel );
157159 $this->pendingVersion = $this->currentVersion;
 160+ $this->replyCount = 0;
158161
159162 $this->channel = $channel;
160163 }
@@ -188,7 +191,7 @@
189192 * Should only really be called from LiquidThreadsPost::save
190193 * @param $version The LiquidThreadsTopicVersion object that was just saved.
191194 */
192 - protected function update( $version ) {
 195+ protected function update( ) {
193196 if ( ! $this->getID() ) {
194197 throw new MWException( "Attempt to call update() on a topic not yet in the database." );
195198 }
@@ -213,14 +216,12 @@
214217 $dbw = wfGetDB( DB_MASTER );
215218
216219 $row = $this->getRow();
217 - $dbw->insert( 'lqt_post', $row, __METHOD__ );
 220+ $dbw->insert( 'lqt_topic', $row, __METHOD__ );
218221
219 - $postId = $dbw->insertId();
220 - $this->id = $postId;
 222+ $topicID = $dbw->insertId();
 223+ $this->id = $topicID;
221224
222 - $dbw->update( 'lqt_topic_version', array( 'ltv_topic' => $postId ),
223 - array( 'ltv_id' => $this->currentVersion->getID() ),
224 - __METHOD__ );
 225+ $this->currentVersion->setTopicID( $topicID );
225226 }
226227
227228 /**
@@ -228,13 +229,14 @@
229230 * Used internally by update() and insert()
230231 */
231232 protected function getRow() {
 233+ $dbw = wfGetDB( DB_MASTER );
232234 $row = array(
233235 'lqt_current_version' => $this->currentVersion->getID(),
234236 'lqt_channel' => $this->getChannelID(),
235237 'lqt_replies' => $this->replyCount,
236238 );
237239
238 - if ( $this->id ) {
 240+ if ( !$this->id ) {
239241 $row['lqt_id'] = $dbw->nextSequenceValue( 'lqt_topic_lqt_id' );
240242 }
241243
@@ -297,6 +299,13 @@
298300 }
299301
300302 /**
 303+ * @return String: The current summary text for this Topic.
 304+ */
 305+ public function getSummary() {
 306+ return $this->getCurrentVersion()->getSummaryText();
 307+ }
 308+
 309+ /**
301310 * Returns the ID of the channel that this topic belongs to.
302311 */
303312 public function getChannelID() {
@@ -343,6 +352,14 @@
344353 }
345354
346355 /**
 356+ * Sets the summary text of this topic.
 357+ * @param $text String: new summary text.
 358+ */
 359+ public function setSummary( $text ) {
 360+ $this->getPendingVersion()->setSummaryText( $text );
 361+ }
 362+
 363+ /**
347364 * Sets the channel ID for this topic (i.e. moves the topic to a new channel)
348365 * @param $id Integer: The ID of the channel to move the topic to.
349366 */
@@ -361,5 +378,22 @@
362379
363380 $this->setChannelID( $channel->getID() );
364381 }
 382+
 383+ /**
 384+ * Adds a post to the instance cache.
 385+ * Used when a post is saved to the database,
 386+ * only to be called by LiquidThreadsPost::insert
 387+ * @param $post The LiquidThreadsPost object
 388+ */
 389+ public function addPost( $post ) {
 390+ // Initialise initial array.
 391+ $this->getPosts();
 392+
 393+ if ( ! $post->getId() ) {
 394+ throw new MWException( "You need to save the post first!" );
 395+ }
 396+
 397+ $this->posts[$post->getId()] = $post;
 398+ }
365399 }
366400
Index: branches/lqt-updates/extensions/LiquidThreads/classes/model/TopicVersion.php
@@ -11,8 +11,8 @@
1212 /** ID of this version **/
1313 protected $id;
1414
15 - /** ID of the post that this version applies to **/
16 - protected $postID;
 15+ /** ID of the topic that this version applies to **/
 16+ protected $topicID;
1717
1818 /** User object for the person who created this *VERSION* **/
1919 protected $versionUser;
@@ -31,6 +31,23 @@
3232 /** This topic's subject **/
3333 protected $subject = null;
3434
 35+ /** Summary text ID -- get the row from the text table **/
 36+ protected $summaryTextID = null;
 37+
 38+ /** Summary text row -- use Revision::getRevisionText to convert to text **/
 39+ protected $summaryTextRow = null;
 40+
 41+ /** Summary text ES URL -- convert to text by retrieving from ES,
 42+ * substituting into $summaryTextRow and calling Revision::getRevisionText **/
 43+ protected $summaryTextURL = null;
 44+
 45+ /** Actual summary text **/
 46+ protected $summaryText = null;
 47+
 48+ /** Whether or not the text has been modified directly in $text
 49+ * (and therefore needs to be saved to ES). **/
 50+ protected $summaryTextDirty = false;
 51+
3552 /* Ancestry information, for not-saved errors */
3653
3754 /** Where this object was instantiated. Used for not-saved errors **/
@@ -49,16 +66,17 @@
5067 $this->source = wfGetAllCallers();
5168 }
5269
53 - /**
54 - * Default destructor
55 - * If this Version has yet to be saved, throws an exception.
56 - * To prevent this behaviour, call destroy()
57 - */
58 - public function __destruct() {
59 - if ( $this->id == 0 && !$this->destroyed ) {
60 - throw new MWException( "Version object has not been saved nor destroyed. From: " . $this->source );
61 - }
62 - }
 70+ // Commented out due to misfires
 71+// /**
 72+// * Default destructor
 73+// * If this Version has yet to be saved, throws an exception.
 74+// * To prevent this behaviour, call destroy()
 75+// */
 76+// public function __destruct() {
 77+// if ( $this->id == 0 && !$this->destroyed ) {
 78+// throw new MWException( "Version object has not been saved nor destroyed. From: " . $this->source );
 79+// }
 80+// }
6381
6482 /**
6583 * Disables the "not saved" error message.
@@ -74,7 +92,7 @@
7593 * @param $conditions Array: Conditions to pass to Database::select
7694 * @return Array: LiquidThreadsTopicVersion objects with those conditions.
7795 */
78 - public static function loadFromConditions( $conditions, $fetchText = false, $options = array() ) {
 96+ public static function loadFromConditions( $conditions, $options = array() ) {
7997 $dbr = wfGetDB( DB_SLAVE );
8098
8199 $tables = array( 'lqt_topic_version' );
@@ -183,14 +201,13 @@
184202
185203 $version->initialiseNewTopic( $channel );
186204
187 - return $post;
 205+ return $version;
188206 }
189207
190208 /* Initialisation functions. One of these has to be called on a new object */
191209
192210 /**
193211 * Initialise this object from a database row.
194 - * This "row" may be joined to the text row.
195212 * @param $row Object: A row object containing the
196213 * appropriate lqt_topic_version row.
197214 */
@@ -211,7 +228,7 @@
212229 $user = User::newFromRow( $row );
213230 }
214231 } elseif ( User::isIP( $row->ltv_user_ip ) ) {
215 - $user = User::newFromName( $row->ltv_user_ip );
 232+ $user = User::newFromName( $row->ltv_user_ip, false );
216233 }
217234
218235 if ( is_null($user) ) {
@@ -220,34 +237,39 @@
221238 $this->versionUser = $user;
222239
223240 // Other metadata
224 - $this->comment = $row->ltv_comment
 241+ $this->comment = $row->ltv_comment;
225242 $this->timestamp = wfTimestamp( TS_MW, $row->ltv_timestamp );
226243 $this->topicID = $row->ltv_topic;
227244
228245 // Real version data loading
229246 $this->channelID = $row->ltv_channel;
230247 $this->subject = $row->ltv_subject;
 248+
 249+ $this->summaryTextID = $row->ltv_summary_text_id;
231250 }
232251
233252 /**
234 - * Initialise a new version object for a post.
235 - * If the base revision is not specified, it is based on the current version of the Post.
236 - * @param $post LiquidThreadsPost: The post that this version is for.
237 - * @param $baseVersion LiquidThreadsPostVersion: The base version for this version. \em{(optional)}
 253+ * Initialise a new version object for a LiquidThreadsTopic.
 254+ * If the base revision is not specified, it is based on the current version of the topic.
 255+ * @param $topic LiquidThreadsTopic: The topic that this version is for.
 256+ * @param $baseVersion LiquidThreadsTopicVersion: The base version for this version. \em{(optional)}
238257 */
239 - protected function initialiseNew( LiquidThreadsPost $post,
240 - LiquidThreadsPostVersion $baseVersion = null )
 258+ protected function initialiseNew( LiquidThreadsTopic $topic, $baseVersion = null )
241259 {
242260 if ( ! $baseVersion ) {
243 - $baseVersion = $post->getCurrentVersion();
 261+ $baseVersion = $topic->getCurrentVersion();
244262 }
245263
246264 // Copy all data members across.
247265 $this->channelID = $baseVersion->getChannelID();
248266 $this->subject = $baseVersion->getSubject();
249267
 268+ $this->summaryText = $baseVersion->getSummaryText();
 269+ $this->summaryTextDirty = false;
 270+ $this->summaryTextID = $baseVersion->summaryTextID;
 271+
250272 global $wgUser;
251 - $this->editor = $wgUser;
 273+ $this->versionUser = $wgUser;
252274
253275 $this->id = 0;
254276 $this->topicID = $topic->getID();
@@ -265,6 +287,10 @@
266288 $this->versionUser = $wgUser;
267289 $this->channelID = $channel->getID();
268290 $this->subject = '';
 291+ $this->topicID = 0; // Filled later
 292+ $this->summaryTextID = 0;
 293+ $this->summaryTextRow = null;
 294+ $this->summaryTextDirty = true;
269295 }
270296
271297 /* SETTING AND SAVING */
@@ -313,11 +339,25 @@
314340 * Sets the subject associated with this version.
315341 * @param $subject String: The new subject
316342 */
317 - public function setSignature( $subject ) {
 343+ public function setSubject( $subject ) {
318344 $this->subject = $subject;
319345 }
320346
321347 /**
 348+ * Set the summary text of this version.
 349+ * @param $newtext String: The new summary text for this version.
 350+ */
 351+ public function setSummaryText( $newtext ) {
 352+ if ( !$this->isMutable() ) {
 353+ throw new MWException( "This Version object is not mutable." );
 354+ }
 355+
 356+ $this->summaryText = $newtext;
 357+ $this->summaryTextDirty = true;
 358+ $this->summaryTextID = $this->summaryTextRow = null;
 359+ }
 360+
 361+ /**
322362 * Saves this Version to the database.
323363 * @param $comment String: (optional) The edit comment for this version.
324364 */
@@ -341,6 +381,19 @@
342382 'ltv_subject' => $this->subject,
343383 );
344384
 385+ $this->timestamp = $row['ltv_timestamp'];
 386+
 387+ if ( $this->summaryTextDirty ) {
 388+ $this->summaryTextID = LiquidThreadsObject::saveText($this->summaryText);
 389+ $this->summaryTextDirty = false;
 390+ }
 391+
 392+ if ( $this->summaryTextID == 0 ) {
 393+ throw new MWException( "Unable to store revision text" );
 394+ }
 395+
 396+ $row['ltv_summary_text_id'] = $this->summaryTextID;
 397+
345398 // Poster and user data
346399 $editor = $this->getEditor();
347400
@@ -353,12 +406,6 @@
354407 $dbw->insert( 'lqt_topic_version', $row, __METHOD__ );
355408
356409 $this->id = $dbw->insertId();
357 -
358 - // Update pointer
359 - if ( $this->topicID ) {
360 - $dbw->update( 'lqt_topic', array( 'lqt_current_version', $this->id ),
361 - array( 'lqt_id' => $this->topicID ), __METHOD__ );
362 - }
363410 }
364411
365412 /* PROPERTY ACCESSORS */
@@ -419,4 +466,52 @@
420467 public function getSubject() {
421468 return $this->subject;
422469 }
 470+
 471+ /**
 472+ * Lets you set the topic ID, once.
 473+ * Only valid use is from LiquidThreadsTopic::save(), for a new LiquidThreadsTopic
 474+ * @param $id Integer: The topic ID that this version applies to.
 475+ */
 476+ public function setTopicID( $id ) {
 477+ if ( $this->topicID ) {
 478+ throw new MWException( "Topic ID is already set" );
 479+ }
 480+
 481+ $this->topicID = $id;
 482+
 483+ $dbw = wfGetDB( DB_MASTER );
 484+ $dbw->update( 'lqt_topic_version', array( 'ltv_topic' => $id ),
 485+ array( 'ltv_id' => $this->getID() ),
 486+ __METHOD__ );
 487+ }
 488+
 489+ /**
 490+ * Retrieves the summary text associated with this Post Version.
 491+ * @return The summary text if available, or false if none exists.
 492+ */
 493+ public function getSummaryText() {
 494+ if ( !is_null( $this->summaryText ) ) {
 495+ // Already cached
 496+ return $this->summaryText;
 497+ } elseif ( 0 && !is_null( $this->summaryTextURL ) ) {
 498+ // Not implemented
 499+ } elseif ( !is_null( $this->summaryTextRow ) ) {
 500+ $this->summaryText = Revision::getRevisionText( $this->summaryTextRow );
 501+ return $this->summaryText;
 502+ } elseif ( !is_null( $this->summaryTextID ) ) {
 503+ $dbr = wfGetDB( DB_MASTER );
 504+
 505+ $row = $dbr->selectRow( 'text', '*',
 506+ array( 'old_id' => $this->summaryTextID ), __METHOD__ );
 507+
 508+ if ( $row ) {
 509+ $this->summaryText = Revision::getRevisionText( $row );
 510+ return $this->summaryText;
 511+ } else {
 512+ return false;
 513+ }
 514+ } else {
 515+ return false;
 516+ }
 517+ }
423518 }
Index: branches/lqt-updates/extensions/LiquidThreads/classes/model/Post.php
@@ -17,6 +17,9 @@
1818 /** The LiquidThreadsTopic object that this post is in. **/
1919 protected $topic;
2020
 21+ /** The version that is being worked on by set methods **/
 22+ protected $pendingVersion;
 23+
2124 /** The ID of this post's parent post **/
2225 protected $parentID;
2326 /** The LiquidThreadsPost that this is found underneath. **/
@@ -45,12 +48,14 @@
4649 $fields = '*';
4750 $joins = array(
4851 'lqt_post_version' => array(
49 - 'left join' => array(
 52+ 'left join',
 53+ array(
5054 'lqp_current_version=lpv_id',
5155 ),
5256 ),
5357 'text' => array(
54 - 'left join' => array(
 58+ 'left join',
 59+ array(
5560 'old_id=lpv_text_id',
5661 ),
5762 ),
@@ -155,7 +160,7 @@
156161 protected function initialiseNew( $topic, $parent = null ) {
157162 $this->id = 0;
158163
159 - $this->currentVersion = LiquidThreadsPostVersion::createNewPost();
 164+ $this->currentVersion = LiquidThreadsPostVersion::createNewPost( $topic, $parent );
160165 $this->pendingVersion = $this->currentVersion;
161166
162167 $this->topic = $topic;
@@ -209,10 +214,13 @@
210215 public function save( $comment = null ) {
211216 if ( $this->pendingVersion ) {
212217 $this->pendingVersion->commit( $comment );
 218+ $this->currentVersion = $this->pendingVersion;
213219 $this->pendingVersion = null;
214220
215221 if ( !$this->id ) {
216222 $this->insert();
 223+ } else {
 224+ $this->update();
217225 }
218226 } else {
219227 throw new MWException( "There are no pending changes." );
@@ -220,6 +228,34 @@
221229 }
222230
223231 /**
 232+ * Get a row array to insert into the database
 233+ * @return Row in Array form to insert into the database.
 234+ */
 235+ protected function getRow() {
 236+ $dbw = wfGetDB( DB_MASTER );
 237+
 238+ if ( $this->getTopicID() == 0 ) {
 239+ throw new MWException( "Topic must be saved first!" );
 240+ }
 241+
 242+ if ( $this->currentVersion == null ) {
 243+ throw new MWException( "No current version available!" );
 244+ }
 245+
 246+ $row = array(
 247+ 'lqp_current_version' => $this->currentVersion->getID(),
 248+ 'lqp_topic' => $this->getTopicID(),
 249+ 'lqp_parent_post' => $this->parent ? $this->parent->getID() : null,
 250+ );
 251+
 252+ if ( !$this->id ) {
 253+ $row['lqp_id'] = $dbw->nextSequenceValue( 'lqt_post_lqp_id' );
 254+ }
 255+
 256+ return $row;
 257+ }
 258+
 259+ /**
224260 * Inserts this Post into the database.
225261 * ONLY to be called *after* the first PostVersion is saved to the database.
226262 * This should only really be called from LiquidThreadsPost::save
@@ -227,20 +263,39 @@
228264 protected function insert() {
229265 $dbw = wfGetDB( DB_MASTER );
230266
231 - $row = array(
232 - 'lqp_id' => $dbw->nextSequenceValue( 'lqt_post_lqp_id' ),
233 - 'lqp_current_version' => 0, // Filled later
234 - 'lqp_topic' => $this->topic->getID(),
235 - 'lqp_parent_post' => $this->parent ? $this->parent->getID() : null,
236 - );
 267+ if ( $this->getID() ) {
 268+ throw new MWException( "Post has already been inserted.!" );
 269+ }
237270
238 - $dbw->insert( 'lqt_post', $row, __METHOD__ );
 271+ $row = $this->getRow();
239272
 273+ $result = $dbw->insert( 'lqt_post', $row, __METHOD__ );
 274+
240275 $postId = $dbw->insertId();
241276 $this->id = $postId;
242277
243 - $dbw->update( 'lqt_post_version', array( 'lpv_post' => $postId ),
244 - array( 'lpv_id' => $this->currentVersion->getID() ),
 278+ $this->currentVersion->setPostID( $postId );
 279+
 280+ if ( $this->topic ) {
 281+ $this->topic->addPost( $this );
 282+ }
 283+ }
 284+
 285+ /**
 286+ * Updates this post in the database.
 287+ * ONLY to be called *after* a PostVersion has been moved into currentVersion.
 288+ * Only to be called from LiquidThreadsPost::update()
 289+ */
 290+ protected function update() {
 291+ $dbw = wfGetDB( DB_MASTER );
 292+
 293+ if ( ! $this->getID() ) {
 294+ throw new MWException( "Post has not been saved!" );
 295+ }
 296+
 297+ $row = $this->getRow();
 298+
 299+ $dbw->update( 'lqt_post', $row, array( 'lqp_id' => $this->getID() ),
245300 __METHOD__ );
246301 }
247302
Index: branches/lqt-updates/extensions/LiquidThreads/classes/model/Object.php
@@ -1,6 +1,6 @@
22 <?php
33
4 -class LiquidThreadsObject {
 4+abstract class LiquidThreadsObject {
55 /**
66 * Returns a unique identifier for this object instance.
77 * It should be unique for this class.
@@ -8,4 +8,45 @@
99 * unique identifier.
1010 */
1111 public abstract function getID();
 12+
 13+ /**
 14+ * Saves the text to the text table (or external storage).
 15+ * @param $data String: The text to save to the text table.
 16+ * @return Integer: an ID for the text table.
 17+ */
 18+ public static function saveText( $data ) {
 19+ global $wgDefaultExternalStore;
 20+
 21+ $dbw = wfGetDB( DB_MASTER );
 22+
 23+ $flags = Revision::compressRevisionText( $data );
 24+
 25+ # Write to external storage if required
 26+ if( $wgDefaultExternalStore ) {
 27+ // Store and get the URL
 28+ $data = ExternalStore::insertToDefault( $data );
 29+
 30+ if( !$data ) {
 31+ throw new MWException( "Unable to store text to external storage" );
 32+ }
 33+
 34+ if( $flags ) {
 35+ $flags .= ',';
 36+ }
 37+ $flags .= 'external';
 38+ }
 39+
 40+ # Record the text (or external storage URL) to the text table
 41+ $old_id = $dbw->nextSequenceValue( 'text_old_id_seq' );
 42+
 43+ $dbw->insert( 'text',
 44+ array(
 45+ 'old_id' => $old_id,
 46+ 'old_text' => $data,
 47+ 'old_flags' => $flags,
 48+ ), __METHOD__
 49+ );
 50+
 51+ return $dbw->insertId();
 52+ }
1253 }
Index: branches/lqt-updates/extensions/LiquidThreads/classes/model/Channel.php
@@ -0,0 +1,193 @@
 2+<?php
 3+
 4+class LiquidThreadsChannel extends LiquidThreadsObject {
 5+
 6+ /** The ID of this channel **/
 7+ protected $id;
 8+
 9+ /** The Title that this Channel points to **/
 10+ protected $title;
 11+
 12+ /**
 13+ * Do not call directly, used internally
 14+ */
 15+ protected function __construct() {
 16+
 17+ }
 18+
 19+ /**
 20+ * Create a new LiquidThreadsChannel object.
 21+ * Will throw an exception if there is already a Channel at this location.
 22+ * @param $title The Title to point this channel at.
 23+ * @return A new LiquidThreadsChannel object.
 24+ */
 25+ public static function create( $title ) {
 26+ $obj = new LiquidThreadsChannel;
 27+
 28+ $obj->initialiseNew( $title );
 29+
 30+ return $obj;
 31+ }
 32+
 33+ /**
 34+ * Initialise this object as a new LiquidThreadsChannel.
 35+ * @param $title Title to point to.
 36+ */
 37+ protected function initialiseNew( $title ) {
 38+ $this->title = $title;
 39+
 40+ $this->insert();
 41+ }
 42+
 43+ /**
 44+ * Add this new object to the database.
 45+ */
 46+ protected function insert() {
 47+ $row = $this->getRow();
 48+ $dbw = wfGetDB( DB_MASTER );
 49+
 50+ $dbw->insert( 'lqt_channel', $row, __METHOD__ );
 51+
 52+ $this->id = $dbw->insertId();
 53+ }
 54+
 55+ /**
 56+ * Retrieve a LiquidThreadsChannel object from its unique ID.
 57+ * Throws an exception if no object is found.
 58+ * @param $id Integer: The ID to retrieve
 59+ * @return The LiquidThreadsChannel object.
 60+ */
 61+ public static function newFromID( $id ) {
 62+ $dbr = wfGetDB( DB_SLAVE );
 63+
 64+ $row = $dbr->selectRow( 'lqt_channel', '*', array( 'lqc_id' => intval($id) ),
 65+ __METHOD__ );
 66+
 67+ $channel = self::loadFromRow( $row );
 68+
 69+ if ( $channel == null ) {
 70+ throw new MWException( "Request for channel by ID returned no results" );
 71+ }
 72+
 73+ return $channel;
 74+ }
 75+
 76+ /**
 77+ * Retrieve a LiquidThreadsChannel object from the title it points to.
 78+ * Throws an exception if no object is found.
 79+ * @param $title The Title of the Channel to retrieve
 80+ * @return The LiquidThreadsChannel object.
 81+ */
 82+ public static function newFromTitle( $title ) {
 83+ $dbr = wfGetDB( DB_SLAVE );
 84+
 85+ $row = $dbr->selectRow( 'lqt_channel', '*',
 86+ array( 'lqc_page_namespace' => $title->getNamespace(),
 87+ 'lqc_page_title' => $title->getDBkey() ),
 88+ __METHOD__ );
 89+
 90+ $channel = self::loadFromRow( $row );
 91+
 92+ if ( $channel == null ) {
 93+ throw new MWException( "Request for channel by title returned no results" );
 94+ }
 95+
 96+ return $channel;
 97+ }
 98+
 99+ /**
 100+ * Load a set of LiquidThreadsChannel objects from a result wrapper
 101+ * @param $res ResultWrapper: A database result wrapper containing the rows to load.
 102+ * @return Array of LiquidThreadsChannel objects.
 103+ */
 104+ public static function loadFromResult( $res ) {
 105+ $output = array();
 106+
 107+ foreach( $res as $input ) {
 108+ $output[$input->lqc_id] = self::loadFromRow( $input );
 109+ }
 110+
 111+ return $output;
 112+ }
 113+
 114+ /**
 115+ * Load a LiquidThreadsChannel object from a database row object.
 116+ * @param $row Object: Output from Database::selectRow or ResultWrapper::fetchObject
 117+ * @return The new LiquidThreadsChannel object
 118+ */
 119+ public static function loadFromRow( $row ) {
 120+ $obj = new LiquidThreadsChannel;
 121+ $obj->initialiseFromRow( $row );
 122+
 123+ return $obj;
 124+ }
 125+
 126+ /**
 127+ * Initialise a LiquidThreadsChannel object from a database row object.
 128+ * @param $row Object: Output from Database::selectRow or ResultWrapper::fetchObject
 129+ */
 130+ protected function initialiseFromRow( $row ) {
 131+ $this->id = $row->lqc_id;
 132+ $this->title = Title::makeTitleSafe( $row->lqc_page_namespace, $row->lqc_page_title );
 133+ }
 134+
 135+ /**
 136+ * Returns an ID unique among LiquidThreadsChannel objects
 137+ * @return Integer: An ID.
 138+ */
 139+ public function getID() {
 140+ return $this->id;
 141+ }
 142+
 143+ /**
 144+ * Returns the Title that this channel points to.
 145+ * @return Title object.
 146+ */
 147+ public function getTitle() {
 148+ if ( is_null($this->title) ) {
 149+ throw new MWException( "Missing Title" );
 150+ }
 151+ return $this->title;
 152+ }
 153+
 154+ /**
 155+ * Changes the Title that this channel points to.
 156+ * @param $title The new Title to point this Channel to.
 157+ */
 158+ public function setTitle( $title ) {
 159+ $this->title = $title;
 160+
 161+ $this->save();
 162+ }
 163+
 164+ /**
 165+ * Saves changes to the database.
 166+ */
 167+ protected function save() {
 168+ $row = $this->getRow();
 169+
 170+ $dbw = wfGetDB( DB_MASTER );
 171+
 172+ $dbw->update( 'lqt_channel', $row, array( 'lqc_id' => $this->getID() ), __METHOD__ );
 173+ }
 174+
 175+ /**
 176+ * Retrieves a row to be saved to the database
 177+ * @return Row in Array for to be saved to the database.
 178+ */
 179+ protected function getRow() {
 180+ $dbw = wfGetDB( DB_MASTER );
 181+
 182+ $row = array(
 183+ 'lqc_id' => $this->getID(),
 184+ 'lqc_page_namespace' => $this->getTitle()->getNamespace(),
 185+ 'lqc_page_title' => $this->getTitle()->getDBkey(),
 186+ );
 187+
 188+ if ( !$row['lqc_id'] ) {
 189+ $row['lqc_id'] = $dbw->nextSequenceValue( 'lqt_channel_lqc_id' );
 190+ }
 191+
 192+ return $row;
 193+ }
 194+}

Status & tagging log