Index: branches/lqt-updates/extensions/LiquidThreads/new-schema.sql |
— | — | @@ -10,7 +10,10 @@ |
11 | 11 | |
12 | 12 | -- NS/title pair of the talk page this channel is attached to. |
13 | 13 | 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) |
15 | 18 | ) /*$wgDBTableOptions*/; |
16 | 19 | |
17 | 20 | -- Topic table |
— | — | @@ -23,11 +26,14 @@ |
24 | 27 | lqt_current_version bigint(10) unsigned not null, |
25 | 28 | |
26 | 29 | -- Cache of the number of replies |
27 | | - lqp_replies int unsigned not null, |
| 30 | + lqt_replies int unsigned not null, |
28 | 31 | |
29 | 32 | -- The Channel that this topic is contained in. |
30 | 33 | -- Foreign key to lqt_channel.lqc_id |
31 | 34 | lqt_channel bigint(10) unsigned not null, |
| 35 | + |
| 36 | + PRIMARY KEY (lqt_id), |
| 37 | + KEY (lqt_channel) |
32 | 38 | ) /*$wgDBTableOptions*/; |
33 | 39 | |
34 | 40 | -- Topic Version table |
— | — | @@ -52,8 +58,16 @@ |
53 | 59 | -- Bitfield for single-version deletion |
54 | 60 | ltv_deleted tinyint unsigned NOT NULL default 0, |
55 | 61 | |
| 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 | + |
56 | 66 | 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) |
58 | 72 | ) /*$wgDBTableOptions*/; |
59 | 73 | |
60 | 74 | -- Post table |
— | — | @@ -77,8 +91,11 @@ |
78 | 92 | |
79 | 93 | -- Parent post. Potentially blank, if it's at the top level in the topic. |
80 | 94 | -- Foreign key to lqt_post.lqp_id |
81 | | - lqp_parent_post bigint(10) unsigned null |
| 95 | + lqp_parent_post bigint(10) unsigned null, |
82 | 96 | |
| 97 | + PRIMARY KEY (lqp_id), |
| 98 | + KEY (lqp_topic, lqp_parent_post) |
| 99 | + |
83 | 100 | ) /*$wgDBTableOptions*/; |
84 | 101 | |
85 | 102 | -- Post Version table |
— | — | @@ -125,5 +142,8 @@ |
126 | 143 | lpv_parent_post bigint(10) unsigned null, |
127 | 144 | |
128 | 145 | -- 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) |
130 | 150 | ) /*$wgDBTableOptions*/; |
Index: branches/lqt-updates/extensions/LiquidThreads/LiquidThreads.php |
— | — | @@ -13,10 +13,12 @@ |
14 | 14 | |
15 | 15 | require( 'LqtFunctions.php' ); |
16 | 16 | |
| 17 | +// @deprecated |
17 | 18 | define( 'NS_LQT_THREAD', efArrayDefault( 'egLqtNamespaceNumbers', 'Thread', 90 ) ); |
18 | 19 | define( 'NS_LQT_THREAD_TALK', efArrayDefault( 'egLqtNamespaceNumbers', 'Thread_talk', 91 ) ); |
19 | 20 | define( 'NS_LQT_SUMMARY', efArrayDefault( 'egLqtNamespaceNumbers', 'Summary', 92 ) ); |
20 | 21 | define( 'NS_LQT_SUMMARY_TALK', efArrayDefault( 'egLqtNamespaceNumbers', 'Summary_talk', 93 ) ); |
| 22 | + |
21 | 23 | define( 'LQT_NEWEST_CHANGES', 'nc' ); |
22 | 24 | define( 'LQT_NEWEST_THREADS', 'nt' ); |
23 | 25 | define( 'LQT_OLDEST_THREADS', 'ot' ); |
— | — | @@ -82,165 +84,176 @@ |
83 | 85 | |
84 | 86 | // Hooks |
85 | 87 | // Parser Function Setup |
86 | | -$wgHooks['ParserFirstCallInit'][] = 'LqtHooks::onParserFirstCallInit'; |
87 | 88 | |
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'; |
90 | 165 | |
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'; |
166 | 171 | // $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"; |
168 | 249 | |
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"; |
172 | 257 | |
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 | | - |
245 | 258 | /** CONFIGURATION SECTION */ |
246 | 259 | |
247 | 260 | $wgDefaultUserOptions['lqt-watch-threads'] = true; |
Index: branches/lqt-updates/extensions/LiquidThreads/classes/model/PostVersion.php |
— | — | @@ -71,19 +71,20 @@ |
72 | 72 | protected function __construct() { |
73 | 73 | $this->source = wfGetAllCallers(); |
74 | 74 | } |
| 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 | +// } |
75 | 87 | |
76 | 88 | /** |
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 | | - /** |
88 | 89 | * Disables the "not saved" error message. |
89 | 90 | * This MUST be called if you do not plan to save this version. |
90 | 91 | */ |
— | — | @@ -200,8 +201,7 @@ |
201 | 202 | * Factory method to create a Version for a new Post. |
202 | 203 | * @return LiquidThreadsPostVersion: A Version object for a new post. |
203 | 204 | */ |
204 | | - public static function createNewPost( LiquidThreadsTopic $topic, |
205 | | - LiquidThreadsPost $parent = null ) |
| 205 | + public static function createNewPost( LiquidThreadsTopic $topic, $parent = null ) |
206 | 206 | { |
207 | 207 | $post = new LiquidThreadsPostVersion; |
208 | 208 | |
— | — | @@ -235,7 +235,7 @@ |
236 | 236 | $user = User::newFromRow( $row ); |
237 | 237 | } |
238 | 238 | } elseif ( User::isIP( $row->lpv_user_ip ) ) { |
239 | | - $user = User::newFromName( $row->lpv_user_ip ); |
| 239 | + $user = User::newFromName( $row->lpv_user_ip, false ); |
240 | 240 | } |
241 | 241 | |
242 | 242 | if ( is_null($user) ) { |
— | — | @@ -244,7 +244,7 @@ |
245 | 245 | $this->versionUser = $user; |
246 | 246 | |
247 | 247 | // Other metadata |
248 | | - $this->comment = $row->lpv_comment |
| 248 | + $this->comment = $row->lpv_comment; |
249 | 249 | $this->timestamp = wfTimestamp( TS_MW, $row->lpv_timestamp ); |
250 | 250 | $this->postID = $row->lpv_post; |
251 | 251 | |
— | — | @@ -257,7 +257,7 @@ |
258 | 258 | $user = User::newFromRow( $row ); |
259 | 259 | } |
260 | 260 | } elseif ( User::isIP( $row->lpv_poster_ip ) ) { |
261 | | - $user = User::newFromName( $row->lpv_poster_ip ); |
| 261 | + $user = User::newFromName( $row->lpv_poster_ip, false ); |
262 | 262 | } |
263 | 263 | |
264 | 264 | if ( is_null($user) ) { |
— | — | @@ -301,7 +301,7 @@ |
302 | 302 | $this->signature = $baseVersion->getSignature(); |
303 | 303 | |
304 | 304 | global $wgUser; |
305 | | - $this->editor = $wgUser; |
| 305 | + $this->versionUser = $wgUser; |
306 | 306 | |
307 | 307 | $this->id = 0; |
308 | 308 | $this->postID = $post->getID(); |
— | — | @@ -313,19 +313,22 @@ |
314 | 314 | * @param $parent LiquidThreadsPost: (Optional) A parent Post for this one. |
315 | 315 | */ |
316 | 316 | protected function initialiseNewPost( LiquidThreadsTopic $topic, |
317 | | - LiquidThreadsPost $parent ) |
| 317 | + $parent = null ) |
318 | 318 | { |
319 | 319 | global $wgUser; |
320 | 320 | |
321 | 321 | $this->id = 0; |
322 | 322 | $this->poster = $wgUser; |
323 | 323 | $this->versionUser = $wgUser; |
324 | | - $this->postID = 0; |
| 324 | + $this->postID = 0; // Filled later |
325 | 325 | $this->textID = 0; |
326 | 326 | $this->textRow = null; |
327 | 327 | $this->textDirty = true; |
328 | 328 | $this->topicID = $topic->getID(); |
329 | | - $this->parentID = $parent->getID(); |
| 329 | + |
| 330 | + if ( $parent ) { |
| 331 | + $this->parentID = $parent->getID(); |
| 332 | + } |
330 | 333 | } |
331 | 334 | |
332 | 335 | /* SETTING AND SAVING */ |
— | — | @@ -432,11 +435,13 @@ |
433 | 436 | 'lpv_post' => $this->postID, |
434 | 437 | 'lpv_timestamp' => $dbw->timestamp( wfTimestampNow() ), |
435 | 438 | 'lpv_comment' => $this->comment, |
436 | | - 'lpv_topic' => $this-> |
| 439 | + 'lpv_topic' => $this->topicID, |
437 | 440 | ); |
438 | 441 | |
| 442 | + $this->timestamp = $row['lpv_timestamp']; |
| 443 | + |
439 | 444 | if ( $this->textDirty ) { |
440 | | - $this->textID = self::saveText($this->text); |
| 445 | + $this->textID = LiquidThreadsObject::saveText($this->text); |
441 | 446 | $this->textDirty = false; |
442 | 447 | } |
443 | 448 | |
— | — | @@ -465,55 +470,8 @@ |
466 | 471 | $dbw->insert( 'lqt_post_version', $row, __METHOD__ ); |
467 | 472 | |
468 | 473 | $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 | | - } |
475 | 474 | } |
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 ); |
488 | 475 | |
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 | | - |
518 | 476 | /* PROPERTY ACCESSORS */ |
519 | 477 | |
520 | 478 | /** |
— | — | @@ -617,4 +575,22 @@ |
618 | 576 | public function getSignature() { |
619 | 577 | return $this->signature; |
620 | 578 | } |
| 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 | + } |
621 | 597 | } |
Index: branches/lqt-updates/extensions/LiquidThreads/classes/model/Topic.php |
— | — | @@ -53,7 +53,8 @@ |
54 | 54 | $fields = '*'; |
55 | 55 | $joins = array( |
56 | 56 | 'lqt_topic_version' => array( |
57 | | - 'left join' => array( |
| 57 | + 'left join', |
| 58 | + array( |
58 | 59 | 'lqt_current_version=ltv_id', |
59 | 60 | ), |
60 | 61 | ), |
— | — | @@ -137,6 +138,7 @@ |
138 | 139 | $this->id = $row->lqt_id; |
139 | 140 | $this->channelID = $row->lqt_channel; |
140 | 141 | $this->currentVersionID = $row->lqt_current_version; |
| 142 | + $this->replyCount = $row->lqt_replies; |
141 | 143 | |
142 | 144 | if ( isset($row->ltv_id) ) { |
143 | 145 | $version = LiquidThreadsTopicVersion::newFromRow( $row ); |
— | — | @@ -152,8 +154,9 @@ |
153 | 155 | $this->id = 0; |
154 | 156 | |
155 | 157 | $this->currentVersionID = 0; |
156 | | - $this->currentVersion = LiquidThreadsTopicVersion::createNewTopic(); |
| 158 | + $this->currentVersion = LiquidThreadsTopicVersion::createNewTopic( $channel ); |
157 | 159 | $this->pendingVersion = $this->currentVersion; |
| 160 | + $this->replyCount = 0; |
158 | 161 | |
159 | 162 | $this->channel = $channel; |
160 | 163 | } |
— | — | @@ -188,7 +191,7 @@ |
189 | 192 | * Should only really be called from LiquidThreadsPost::save |
190 | 193 | * @param $version The LiquidThreadsTopicVersion object that was just saved. |
191 | 194 | */ |
192 | | - protected function update( $version ) { |
| 195 | + protected function update( ) { |
193 | 196 | if ( ! $this->getID() ) { |
194 | 197 | throw new MWException( "Attempt to call update() on a topic not yet in the database." ); |
195 | 198 | } |
— | — | @@ -213,14 +216,12 @@ |
214 | 217 | $dbw = wfGetDB( DB_MASTER ); |
215 | 218 | |
216 | 219 | $row = $this->getRow(); |
217 | | - $dbw->insert( 'lqt_post', $row, __METHOD__ ); |
| 220 | + $dbw->insert( 'lqt_topic', $row, __METHOD__ ); |
218 | 221 | |
219 | | - $postId = $dbw->insertId(); |
220 | | - $this->id = $postId; |
| 222 | + $topicID = $dbw->insertId(); |
| 223 | + $this->id = $topicID; |
221 | 224 | |
222 | | - $dbw->update( 'lqt_topic_version', array( 'ltv_topic' => $postId ), |
223 | | - array( 'ltv_id' => $this->currentVersion->getID() ), |
224 | | - __METHOD__ ); |
| 225 | + $this->currentVersion->setTopicID( $topicID ); |
225 | 226 | } |
226 | 227 | |
227 | 228 | /** |
— | — | @@ -228,13 +229,14 @@ |
229 | 230 | * Used internally by update() and insert() |
230 | 231 | */ |
231 | 232 | protected function getRow() { |
| 233 | + $dbw = wfGetDB( DB_MASTER ); |
232 | 234 | $row = array( |
233 | 235 | 'lqt_current_version' => $this->currentVersion->getID(), |
234 | 236 | 'lqt_channel' => $this->getChannelID(), |
235 | 237 | 'lqt_replies' => $this->replyCount, |
236 | 238 | ); |
237 | 239 | |
238 | | - if ( $this->id ) { |
| 240 | + if ( !$this->id ) { |
239 | 241 | $row['lqt_id'] = $dbw->nextSequenceValue( 'lqt_topic_lqt_id' ); |
240 | 242 | } |
241 | 243 | |
— | — | @@ -297,6 +299,13 @@ |
298 | 300 | } |
299 | 301 | |
300 | 302 | /** |
| 303 | + * @return String: The current summary text for this Topic. |
| 304 | + */ |
| 305 | + public function getSummary() { |
| 306 | + return $this->getCurrentVersion()->getSummaryText(); |
| 307 | + } |
| 308 | + |
| 309 | + /** |
301 | 310 | * Returns the ID of the channel that this topic belongs to. |
302 | 311 | */ |
303 | 312 | public function getChannelID() { |
— | — | @@ -343,6 +352,14 @@ |
344 | 353 | } |
345 | 354 | |
346 | 355 | /** |
| 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 | + /** |
347 | 364 | * Sets the channel ID for this topic (i.e. moves the topic to a new channel) |
348 | 365 | * @param $id Integer: The ID of the channel to move the topic to. |
349 | 366 | */ |
— | — | @@ -361,5 +378,22 @@ |
362 | 379 | |
363 | 380 | $this->setChannelID( $channel->getID() ); |
364 | 381 | } |
| 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 | + } |
365 | 399 | } |
366 | 400 | |
Index: branches/lqt-updates/extensions/LiquidThreads/classes/model/TopicVersion.php |
— | — | @@ -11,8 +11,8 @@ |
12 | 12 | /** ID of this version **/ |
13 | 13 | protected $id; |
14 | 14 | |
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; |
17 | 17 | |
18 | 18 | /** User object for the person who created this *VERSION* **/ |
19 | 19 | protected $versionUser; |
— | — | @@ -31,6 +31,23 @@ |
32 | 32 | /** This topic's subject **/ |
33 | 33 | protected $subject = null; |
34 | 34 | |
| 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 | + |
35 | 52 | /* Ancestry information, for not-saved errors */ |
36 | 53 | |
37 | 54 | /** Where this object was instantiated. Used for not-saved errors **/ |
— | — | @@ -49,16 +66,17 @@ |
50 | 67 | $this->source = wfGetAllCallers(); |
51 | 68 | } |
52 | 69 | |
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 | +// } |
63 | 81 | |
64 | 82 | /** |
65 | 83 | * Disables the "not saved" error message. |
— | — | @@ -74,7 +92,7 @@ |
75 | 93 | * @param $conditions Array: Conditions to pass to Database::select |
76 | 94 | * @return Array: LiquidThreadsTopicVersion objects with those conditions. |
77 | 95 | */ |
78 | | - public static function loadFromConditions( $conditions, $fetchText = false, $options = array() ) { |
| 96 | + public static function loadFromConditions( $conditions, $options = array() ) { |
79 | 97 | $dbr = wfGetDB( DB_SLAVE ); |
80 | 98 | |
81 | 99 | $tables = array( 'lqt_topic_version' ); |
— | — | @@ -183,14 +201,13 @@ |
184 | 202 | |
185 | 203 | $version->initialiseNewTopic( $channel ); |
186 | 204 | |
187 | | - return $post; |
| 205 | + return $version; |
188 | 206 | } |
189 | 207 | |
190 | 208 | /* Initialisation functions. One of these has to be called on a new object */ |
191 | 209 | |
192 | 210 | /** |
193 | 211 | * Initialise this object from a database row. |
194 | | - * This "row" may be joined to the text row. |
195 | 212 | * @param $row Object: A row object containing the |
196 | 213 | * appropriate lqt_topic_version row. |
197 | 214 | */ |
— | — | @@ -211,7 +228,7 @@ |
212 | 229 | $user = User::newFromRow( $row ); |
213 | 230 | } |
214 | 231 | } elseif ( User::isIP( $row->ltv_user_ip ) ) { |
215 | | - $user = User::newFromName( $row->ltv_user_ip ); |
| 232 | + $user = User::newFromName( $row->ltv_user_ip, false ); |
216 | 233 | } |
217 | 234 | |
218 | 235 | if ( is_null($user) ) { |
— | — | @@ -220,34 +237,39 @@ |
221 | 238 | $this->versionUser = $user; |
222 | 239 | |
223 | 240 | // Other metadata |
224 | | - $this->comment = $row->ltv_comment |
| 241 | + $this->comment = $row->ltv_comment; |
225 | 242 | $this->timestamp = wfTimestamp( TS_MW, $row->ltv_timestamp ); |
226 | 243 | $this->topicID = $row->ltv_topic; |
227 | 244 | |
228 | 245 | // Real version data loading |
229 | 246 | $this->channelID = $row->ltv_channel; |
230 | 247 | $this->subject = $row->ltv_subject; |
| 248 | + |
| 249 | + $this->summaryTextID = $row->ltv_summary_text_id; |
231 | 250 | } |
232 | 251 | |
233 | 252 | /** |
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)} |
238 | 257 | */ |
239 | | - protected function initialiseNew( LiquidThreadsPost $post, |
240 | | - LiquidThreadsPostVersion $baseVersion = null ) |
| 258 | + protected function initialiseNew( LiquidThreadsTopic $topic, $baseVersion = null ) |
241 | 259 | { |
242 | 260 | if ( ! $baseVersion ) { |
243 | | - $baseVersion = $post->getCurrentVersion(); |
| 261 | + $baseVersion = $topic->getCurrentVersion(); |
244 | 262 | } |
245 | 263 | |
246 | 264 | // Copy all data members across. |
247 | 265 | $this->channelID = $baseVersion->getChannelID(); |
248 | 266 | $this->subject = $baseVersion->getSubject(); |
249 | 267 | |
| 268 | + $this->summaryText = $baseVersion->getSummaryText(); |
| 269 | + $this->summaryTextDirty = false; |
| 270 | + $this->summaryTextID = $baseVersion->summaryTextID; |
| 271 | + |
250 | 272 | global $wgUser; |
251 | | - $this->editor = $wgUser; |
| 273 | + $this->versionUser = $wgUser; |
252 | 274 | |
253 | 275 | $this->id = 0; |
254 | 276 | $this->topicID = $topic->getID(); |
— | — | @@ -265,6 +287,10 @@ |
266 | 288 | $this->versionUser = $wgUser; |
267 | 289 | $this->channelID = $channel->getID(); |
268 | 290 | $this->subject = ''; |
| 291 | + $this->topicID = 0; // Filled later |
| 292 | + $this->summaryTextID = 0; |
| 293 | + $this->summaryTextRow = null; |
| 294 | + $this->summaryTextDirty = true; |
269 | 295 | } |
270 | 296 | |
271 | 297 | /* SETTING AND SAVING */ |
— | — | @@ -313,11 +339,25 @@ |
314 | 340 | * Sets the subject associated with this version. |
315 | 341 | * @param $subject String: The new subject |
316 | 342 | */ |
317 | | - public function setSignature( $subject ) { |
| 343 | + public function setSubject( $subject ) { |
318 | 344 | $this->subject = $subject; |
319 | 345 | } |
320 | 346 | |
321 | 347 | /** |
| 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 | + /** |
322 | 362 | * Saves this Version to the database. |
323 | 363 | * @param $comment String: (optional) The edit comment for this version. |
324 | 364 | */ |
— | — | @@ -341,6 +381,19 @@ |
342 | 382 | 'ltv_subject' => $this->subject, |
343 | 383 | ); |
344 | 384 | |
| 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 | + |
345 | 398 | // Poster and user data |
346 | 399 | $editor = $this->getEditor(); |
347 | 400 | |
— | — | @@ -353,12 +406,6 @@ |
354 | 407 | $dbw->insert( 'lqt_topic_version', $row, __METHOD__ ); |
355 | 408 | |
356 | 409 | $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 | | - } |
363 | 410 | } |
364 | 411 | |
365 | 412 | /* PROPERTY ACCESSORS */ |
— | — | @@ -419,4 +466,52 @@ |
420 | 467 | public function getSubject() { |
421 | 468 | return $this->subject; |
422 | 469 | } |
| 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 | + } |
423 | 518 | } |
Index: branches/lqt-updates/extensions/LiquidThreads/classes/model/Post.php |
— | — | @@ -17,6 +17,9 @@ |
18 | 18 | /** The LiquidThreadsTopic object that this post is in. **/ |
19 | 19 | protected $topic; |
20 | 20 | |
| 21 | + /** The version that is being worked on by set methods **/ |
| 22 | + protected $pendingVersion; |
| 23 | + |
21 | 24 | /** The ID of this post's parent post **/ |
22 | 25 | protected $parentID; |
23 | 26 | /** The LiquidThreadsPost that this is found underneath. **/ |
— | — | @@ -45,12 +48,14 @@ |
46 | 49 | $fields = '*'; |
47 | 50 | $joins = array( |
48 | 51 | 'lqt_post_version' => array( |
49 | | - 'left join' => array( |
| 52 | + 'left join', |
| 53 | + array( |
50 | 54 | 'lqp_current_version=lpv_id', |
51 | 55 | ), |
52 | 56 | ), |
53 | 57 | 'text' => array( |
54 | | - 'left join' => array( |
| 58 | + 'left join', |
| 59 | + array( |
55 | 60 | 'old_id=lpv_text_id', |
56 | 61 | ), |
57 | 62 | ), |
— | — | @@ -155,7 +160,7 @@ |
156 | 161 | protected function initialiseNew( $topic, $parent = null ) { |
157 | 162 | $this->id = 0; |
158 | 163 | |
159 | | - $this->currentVersion = LiquidThreadsPostVersion::createNewPost(); |
| 164 | + $this->currentVersion = LiquidThreadsPostVersion::createNewPost( $topic, $parent ); |
160 | 165 | $this->pendingVersion = $this->currentVersion; |
161 | 166 | |
162 | 167 | $this->topic = $topic; |
— | — | @@ -209,10 +214,13 @@ |
210 | 215 | public function save( $comment = null ) { |
211 | 216 | if ( $this->pendingVersion ) { |
212 | 217 | $this->pendingVersion->commit( $comment ); |
| 218 | + $this->currentVersion = $this->pendingVersion; |
213 | 219 | $this->pendingVersion = null; |
214 | 220 | |
215 | 221 | if ( !$this->id ) { |
216 | 222 | $this->insert(); |
| 223 | + } else { |
| 224 | + $this->update(); |
217 | 225 | } |
218 | 226 | } else { |
219 | 227 | throw new MWException( "There are no pending changes." ); |
— | — | @@ -220,6 +228,34 @@ |
221 | 229 | } |
222 | 230 | |
223 | 231 | /** |
| 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 | + /** |
224 | 260 | * Inserts this Post into the database. |
225 | 261 | * ONLY to be called *after* the first PostVersion is saved to the database. |
226 | 262 | * This should only really be called from LiquidThreadsPost::save |
— | — | @@ -227,20 +263,39 @@ |
228 | 264 | protected function insert() { |
229 | 265 | $dbw = wfGetDB( DB_MASTER ); |
230 | 266 | |
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 | + } |
237 | 270 | |
238 | | - $dbw->insert( 'lqt_post', $row, __METHOD__ ); |
| 271 | + $row = $this->getRow(); |
239 | 272 | |
| 273 | + $result = $dbw->insert( 'lqt_post', $row, __METHOD__ ); |
| 274 | + |
240 | 275 | $postId = $dbw->insertId(); |
241 | 276 | $this->id = $postId; |
242 | 277 | |
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() ), |
245 | 300 | __METHOD__ ); |
246 | 301 | } |
247 | 302 | |
Index: branches/lqt-updates/extensions/LiquidThreads/classes/model/Object.php |
— | — | @@ -1,6 +1,6 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -class LiquidThreadsObject { |
| 4 | +abstract class LiquidThreadsObject { |
5 | 5 | /** |
6 | 6 | * Returns a unique identifier for this object instance. |
7 | 7 | * It should be unique for this class. |
— | — | @@ -8,4 +8,45 @@ |
9 | 9 | * unique identifier. |
10 | 10 | */ |
11 | 11 | 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 | + } |
12 | 53 | } |
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 | +} |