-
Notifications
You must be signed in to change notification settings - Fork 5
/
SpecialCreateDefaultQuestionPage.php
66 lines (50 loc) · 1.51 KB
/
SpecialCreateDefaultQuestionPage.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
class CreateQuestionPage extends UnlistedSpecialPage {
public function __construct() {
parent::__construct( 'CreateQuestionPage' );
}
public function execute( $question ) {
$out = $this->getOutput();
$request = $this->getRequest();
$user = $this->getUser();
// don't allow users who don't have edit permission to ask questions
if ( !$user->isAllowed( 'edit' ) ) {
return false;
}
// don't allow questions if the wiki is in read-only mode
if ( wfReadOnly() ) {
return false;
}
// don't allow blocked users to ask questions, duh
if ( $user->isBlocked() ) {
$out->blockedPage( false );
return false;
}
if ( empty( $question ) ) {
$question = $request->getVal( 'questiontitle' );
}
if ( empty( $question ) ) {
return true;
}
$q = new DefaultQuestion( $question );
if ( !is_object( $q ) ) {
return false;
}
if ( is_object( $q->title ) && $q->title->exists() ) {
$out->redirect( $q->title->getFullURL() );
return false;
}
if ( $q->searchTest() ) {
$srch = SpecialPage::getTitleFor( 'Search' );
$out->redirect( $srch->getFullURL( 'search=' . $q->question . '&fulltext=Search' ) );
return false;
}
$res = $q->create();
if ( $res ) {
$out->redirect( $q->title->getFullURL( 'state=asked' ) );
} else {
$out->redirect( Title::makeTitle( NS_MAIN, wfMessage( 'question_redirected_help_page' )->inContentLanguage()->text() )->getFullURL() );
}
return false;
}
}