-
Notifications
You must be signed in to change notification settings - Fork 5
/
PrefilledDefaultQuestion.php
66 lines (55 loc) · 1.72 KB
/
PrefilledDefaultQuestion.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
<?php
/**
* Originally used only by NewWikiBuilder, nowadays used by WikiBuilder.
*
* @file
* @author Bartek Łapiński <[email protected]>
*/
class PrefilledDefaultQuestion extends DefaultQuestion {
function create( $text ) {
global $wgOut, $wgUser, $wgContLang;
if ( wfReadOnly() ) {
return false;
}
if ( $this->badWordsTest() ) {
return false;
}
if ( !wfRunHooks( 'CreateDefaultQuestionPageFilter', array( $this->title ) ) ) {
return false;
}
if ( !$this->title->userCan( 'edit' ) || !$this->title->userCan( 'create' ) ) {
return false;
}
if ( $this->searchTest() ) {
return false;
}
$defaultText = $text . Answer::getSpecialCategoryTag( 'unanswered' );
// add default category tags passed in
if ( $this->categories ) {
$categories_array = explode( '|', $this->categories );
foreach ( $categories_array as $category ) {
$defaultText .= "\n[[" .
$wgContLang->getNsText( NS_CATEGORY ) . ':' .
$wgContLang->ucfirst( $category ) . ']]';
}
}
$flags = EDIT_NEW;
$article = new Article( $this->title );
$article->doEdit(
$defaultText,
wfMessage( 'new_question_comment' )->inContentLanguage()->parse(),
$flags
);
if ( $wgUser->isLoggedIn() ) {
//$stats = new UserStatsTrack( $wgUser->getId(), $wgUser->getName() );
//$stats->incStatField( 'quiz_created' ); // we'll use this to track how many questions a user created
$wgUser->addWatch( $this->title );
}
// store question in session so we can give attribution if they create an account afterwards
$_SESSION['wsQuestionAsk'] = '';
if ( $wgUser->isAnon() ) {
$_SESSION['wsQuestionAsk'] = $this->question;
}
return true;
}
}