forked from Brickimedia/Answers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnswers.php
353 lines (288 loc) · 11.7 KB
/
Answers.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
<?php
/**
* Answers tools
*
* @file
* @ingroup Extensions
* @version 1.0 (r57364)
* @date 31 July 2012
* @author Maciej Brencz <[email protected]>
* @author Maciej Błaszkowski <[email protected]>
* @author Adrian Wieczorek <[email protected]>
* @author Nick Sullivan <[email protected]>
* @author Sean Colombo <[email protected]>
* @author David Pean <[email protected]>
* @author Jack Phoenix <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 3.0 or later
* @link http://www.mediawiki.org/wiki/Extension:Answers Documentation
*/
if ( !defined( 'MEDIAWIKI' ) ) {
die();
}
// Extension credits that will show up on Special:Version
$wgExtensionCredits['other'][] = array(
'path' => __FILE__,
'name' => 'Answers',
'version' => '1.0',
'author' => array(
'Maciej Brencz', 'Maciej Błaszkowski', 'Adrian Wieczorek',
'Nick Sullivan', 'Sean Colombo', 'David Pean', 'Jack Phoenix'
),
'descriptionmsg' => 'answers-desc',
'url' => 'https://www.mediawiki.org/wiki/Extension:Answers',
);
// Set up i18n, autoload classes and include the various sub-extensions
$dir = dirname( __FILE__ ) . '/';
$wgExtensionMessagesFiles['Answers'] = $dir . 'Answers.i18n.php';
// Didn't do anything when called in GetQuestionWidget.php
$wgExtensionMessagesFiles['GetQuestionWidget'] = dirname( __FILE__ ) . '/GetQuestionWidget/GetQuestionWidget.i18n.php';
$wgAutoloadClasses['Answer'] = $dir . 'AnswersClass.php';
$wgAutoloadClasses['AttributionCache'] = $dir . 'AttributionCache.class.php';
$wgAutoloadClasses['CustomMovePageForm'] = $dir . 'CustomMoveForm.php';
//$wgAutoloadClasses['CategoryWithAds'] = $dir . 'CategoryWithAds.php';
$wgAutoloadClasses['AnswersHooks'] = $dir . 'AnswersHooks.php';
$wgAutoloadClasses['DefaultQuestion'] = $dir . 'DefaultQuestion.php';
$wgAutoloadClasses['PrefilledDefaultQuestion'] = $dir . 'PrefilledDefaultQuestion.php';
$wgAutoloadClasses['CreateQuestionPage'] = $dir . 'SpecialCreateDefaultQuestionPage.php';
$wgSpecialPages['CreateQuestionPage'] = 'CreateQuestionPage';
$wgAutoloadClasses['GetQuestionWidget'] = $dir . 'GetQuestionWidget/SpecialGetQuestionWidget.php';
$wgSpecialPages['GetQuestionWidget'] = 'GetQuestionWidget';
$wgAutoloadClasses['EditResearch'] = $dir . 'EditResearch/EditResearch.php';
/**
TESTING
*/
$wgResourceModules['answers_css'] = array(
'styles' => array( 'extensions/Answers/Skins/vector.css' => array( 'media' => 'screen' ) )
);
//include( $dir . 'customUserCreateForm.php' );
//include( $dir . 'TrackCategories.php' );
//include( $dir . 'TrackMainPage.php' );
include( $dir . 'HomePageList.php' );
include( $dir . 'EditSimilarAnswers.php' );
include( $dir . 'FakeAnswersMessaging.php' );
//include( $dir . 'SuperDeduper/SuperDeduper.php' );
$wgAnswerHelperIDs = array(
0, /* anonymous */
1172427 /* Wikia User */ //How the hell did they get that number?
);
// Over 9000 hooked functions
$wgHooks['AddNewAccount'][] = 'AnswersHooks::questionAttributionRegister';
$wgHooks['UserLoginComplete'][] = 'AnswersHooks::questionAttributionLogin';
$wgHooks['ArticleSaveComplete'][] = 'AttributionCache::purgeArticleContribs';
$wgHooks['TitleMoveComplete'][] = 'AttributionCache::purgeArticleContribsAfterMove';
$wgHooks['MovePageForm'][] = 'AnswersHooks::customMoveForm';
$wgHooks['TitleMoveComplete'][] = 'AnswersHooks::redirectOnMove';
/* Extension to change the display of the category page for answers
* - Hide the title if there is no subcategory
* - Display "unanswered" questions differently
*/
$wgHooks['CategoryViewer::getOtherSection'][] = 'AnswersHooks::categoryOtherSection';
$wgHooks['CategoryViewer::addPage'][] = 'AnswersHooks::addCategoryPage';
// For Magic Answer, override the text in the edit box if it is passed in the request
$wgHooks['EditPage::showEditForm:initial2'][] = 'AnswersHooks::displayMagicAnswer';
// injects ads into Category pages
//$wgHooks['CategoryPageView'][] = 'AnswersHooks::injectAdsToCategoryPages';
$wgHooks['GetPreferences'][] = 'AnswersHooks::addHideAttributtionToggle';
$wgHooks['CustomArticleFooter'][] = 'AnswersHooks::hideFooter';
$wgHooks['EditPage::attemptSave'][] = 'AnswersHooks::markAsAnswered';
$wgHooks['MakeGlobalVariablesScript'][] = 'AnswersHooks::addJSGlobalVariables';
// Integration with SocialProfile's UserProfile
$wgHooks['UserProfileBeginLeft'][] = 'AnswersHooks::showAskedQuestionsOnUserProfile';
$wgHooks['UserProfileBeginRight'][] = 'AnswersHooks::showAnsweredQuestionsOnUserProfile';
// Adds a question mark to the question page
$wgHooks['OutputPageParserOutput'][] = 'AnswersHooks::addQuestionMarkTitle';
// API modules
$wgAutoloadClasses['ApiQueryPagesByCategory'] = $dir . 'api/ApiQueryPagesByCategory.php';
// 1.13 version
//$wgApiQueryListModules['wkpagesincat'] = 'ApiQueryPagesByCategory';
// 1.14 version
$wgAPIListModules['wkpagesincat'] = 'ApiQueryPagesByCategory';
$wgAutoloadClasses['ApiQueryMostCategories'] = $dir . 'api/ApiQueryMostCategories.php';
// 1.13 version
//$wgApiQueryListModules['wkmostcat'] = 'ApiQueryMostCategories';
// 1.14 version
$wgAPIListModules['wkmostcat'] = 'ApiQueryMostCategories';
// register answers themes
/*
$wgSkinTheme['answers'] = array(
'bluebell', 'leaf', 'carnation', 'sky', 'spring', 'forest', 'moonlight',
'carbon', 'obsession', 'custom'
);
*/
include( 'NewSkin/NewSkin.php' );
// make SkinChooser work for Answers
/*
$wgSkinTheme['monobook'] = array();
$wgSkipSkins[] = 'monaco';
$wgSkipSkins[] = 'monobook';
// remove answers from $wgSkipSkins
unset( $wgSkipSkins[array_search( 'answers', $wgSkipSkins )] );
*/
// FIXME: this SHOULD NOT be here. Move to Skin.
#$wgExtensionFunctions[] = 'answersStyle';
function answersStyle() {
global $wgOut, $wgStylePath, $wgUseNewAnswersSkin;
if ( !empty( $wgUseNewAnswersSkin ) ) {
$wgOut->addExtensionStyle( "{$wgStylePath}/answers/css/monaco_answers.css" );
}
return true;
}
//require_once( "$IP/extensions/solr2rss/solr2rss.php" );
function fnWatchHeldPage( $user ) {
global $wgOut, $wgCookiePrefix, $wgCookieDomain, $wgCookieSecure;
$watch_page = '';
if ( isset( $_COOKIE["{$wgCookiePrefix}wsWatchHold"] ) ) {
$watch_page = $_COOKIE["{$wgCookiePrefix}wsWatchHold"];
}
// user had clicked to watch page
if ( isset( $watch_page ) && $watch_page != '' ) {
$watchedTitle = Title::newFromDBkey( $watch_page );
$user->addWatch( $watchedTitle );
setcookie(
"{$wgCookiePrefix}wsWatchHold",
'',
time() - 86400,
'/',
$wgCookieDomain,
$wgCookieSecure
);
$wgOut->redirect( $watchedTitle->getFullURL() );
}
}
function fnQuestionAttribution( $user ) {
global $wgMemc;
$dbw = wfGetDB( DB_MASTER );
$title = Title::newFromText( $_SESSION['wsQuestionAsk'] );
$pageTitleId = $title->getArticleID();
// watchlist page for them
$user->addWatch( $title );
// get first revision ID
$s = $dbw->selectRow(
'revision',
array( 'rev_id' ),
array( 'rev_page' => $pageTitleId ),
__METHOD__,
array( 'ORDER BY' => 'rev_id ASC', 'LIMIT' => 1 )
);
$revisionId = $s->rev_id;
// change necessary tables
$dbw->update(
'revision',
/* SET */array(
'rev_user' => $user->getId(),
'rev_user_text' => $user->getName()
),
/* WHERE */array( 'rev_id' => $revisionId ),
__METHOD__
);
$dbw->commit();
$dbw->update(
'recentchanges',
/* SET */array(
'rc_user' => $user->getId(),
'rc_user_text' => $user->getName()
),
/* WHERE */array(
'rc_cur_id' => $pageTitleId,
'rc_new' => 1
),
__METHOD__
);
$dbw->commit();
// if the page happens to get deleted in between the anon asking a question
// and registration, we have to also update the archive
$dbw->update(
'archive',
/* SET */array(
'ar_user' => $user->getId(),
'ar_user_text' => $user->getName()
),
/* WHERE */array( 'ar_title' => $title->getDBkey() ),
__METHOD__
);
$dbw->commit();
// clear cache
$title->invalidateCache();
$title->purgeSquid();
$key = wfMemcKey( 'answer_author', $pageTitleId );
$wgMemc->delete( $key );
return true;
}
$wgAjaxExportList[] = 'wfGetCategoriesSuggest';
function wfGetCategoriesSuggest( $query, $limit = 5 ) {
$dbr = wfGetDB( DB_SLAVE );
$res = $dbr->select(
'categorylinks',
array( 'cl_to', 'COUNT(*) AS cnt' ),
array( 'UPPER(cl_to) ' . $dbr->buildLike( strtoupper( $query ), $dbr->anyString() ) ),
__METHOD__,
array( 'ORDER BY' => 'cl_to', 'GROUP BY' => 'cl_to' )
);
foreach ( $res as $row ) {
$title = Title::makeTitle( NS_CATEGORY, $row->cl_to );
$out['ResultSet']['Result'][] = array(
'category' => $title->getText(),
'count' => $row->cnt
);
}
return json_encode( $out );
}
$wgAjaxExportList[] = 'wfGetQuestionsWidget';
function wfGetQuestionsWidget( $title, $category, $limit = 5, $order = '' ) {
global $wgServer, $wgScriptPath, $wgStylePath;
$category = urldecode( $category );
$category = str_replace( ' ', '%20', $category );
$url = $wgServer . $wgScriptPath .
"/api.php?action=query&smaxage=60&list=wkpagesincat&wkcategory=$category&wklimit=$limit&wkorder=$order&format=php";
$questions = Http::get( $url );
$questions = unserialize( $questions );
// @todo FIXME: incorrect path to NewSkin
$html = "document.write('<link rel=\"stylesheet\" type=\"text/css\" href=\"{$wgServer}{$wgStylePath}/answers/css/widget.css\" />')\n";
$html .= "document.write('<div class=\"question_widget\" style=\"' + ( ( answers_width ) ? 'width:' + answers_width + ';' : '' ) + ( ( answers_border ) ? 'border:' + answers_border + ';' : '' ) + ( ( answers_background_color ) ? 'background-color:' + answers_background_color + ';' : '' ) + '\">')\n";
$html .= "document.write('<div class=\"question_widget_title\"><h3>$title</h3></div>')\n";
if ( is_array( $questions ) ) {
$html .= "document.write('<ul style=\"\">')\n";
foreach ( $questions['query']['wkpagesincat'] as $page ) {
$title = Title::newFromDBkey( $page['title'] );
$html .= "document.write('<li><a style=\"' + ( ( answers_link_color ) ? 'color:' + answers_link_color + ';' : '' ) + '\" href=\"" .
$page['url'] . '" target="_top">' . str_replace( "'", "\'", $title->getText() ) . "?</a></li>')\n";
}
$html .= "document.write('</ul>')\n";
} else {
$html .= "document.write('<div>" . wfMsg( 'no_questions_found' ) . "</div>')";
}
$html .= "document.write('<div id=\"question_widget_logo\"><a href=\"$wgServer\"><img src=\"$wgServer/skins/answers/images/wikianswers_logo.png\" border=\"0\"></a></div>')\n
document.write('</div>')";
return $html;
}
$wgAjaxExportList[] = 'wfHoldWatchForAnon';
function wfHoldWatchForAnon( $title ) {
global $wgCookiePrefix, $wgCookieDomain, $wgCookieSecure, $wgCookieExpiration;
setcookie(
$wgCookiePrefix . 'wsWatchHold',
$title,
time() + $wgCookieExpiration,
'/',
$wgCookieDomain,
$wgCookieSecure
);
return SpecialPage::getTitleFor( 'Userlogin', 'signup' )->getFullURL();
}
$wgAjaxExportList[] = 'wfAnswersGetEditPointsAjax';
function wfAnswersGetEditPointsAjax() {
global $wgRequest, $wgSquidMaxage;
$userId = $wgRequest->getInt( 'userId' );
$points = AttributionCache::getInstance()->getUserEditPoints( $userId );
$timestamp = AttributionCache::getInstance()->getUserLastModifiedFromCache( $userId );
$timestamp = !empty( $timestamp ) ? $timestamp : wfTimestampNow();
$data = array(
'points' => $points,
'timestamp' => wfTimestampNow()
);
$json = json_encode( $data );
$response = new AjaxResponse( $json );
$response->setContentType( 'application/json; charset=utf-8' );
$response->checkLastModified( strtotime( $timestamp ) );
$response->setCacheDuration( $wgSquidMaxage );
return $response;
}