Fix syntax errors in r51305.
[lhc/web/wiklou.git] / includes / specials / SpecialCreatePage.php
1 <?php
2 /* This code was adapted from CreatePage.php from: Travis Derouin <travis@wikihow.com> for the Uniwiki extension CreatePage
3 * Originally licensed as: GNU GPL v2.0 or later
4 *
5 * This page has been copied and adapted from the Uniwiki extension CreatePage
6 * Originally licensed as: http://www.gnu.org/licenses/gpl-3.0.txt
7 *
8 * @license GNU GPL v3.0 http://www.gnu.org/licenses/gpl-3.0.txt
9 * @author Travis Derouin
10 * @author Merrick Schaefer
11 * @author Mark Johnston
12 * @author Evan Wheeler
13 * @author Adam Mckaig (at UNICEF)
14 * @author Siebrand Mazeland (integrated into MediaWiki core)
15 * @addtogroup SpecialPage
16 */
17
18 class SpecialCreatePage extends SpecialPage {
19
20 public function __construct() {
21 parent::__construct( 'CreatePage', 'createpage' );
22 }
23
24 public function execute( $params ) {
25 global $wgOut, $wgRequest, $wgUser;
26
27 $this->setHeaders();
28
29 if ( !$this->userCanExecute( $wgUser ) ) {
30 $this->displayRestrictionError();
31 return;
32 }
33
34 $wgOut->addWikiMsg( 'createpage-summary' );
35
36 // check to see if we are trying to create a page
37 $target = $wgRequest->getVal ( 'target' );
38 $title = Title::newFromText ( $target );
39
40 // check for no title
41 if ( $wgRequest->wasPosted() && $target === '' ) {
42 $this->error( wfMsg( 'createpage-entertitle' ) );
43 }
44 // check for invalid title
45 elseif ( $wgRequest->wasPosted() && is_null( $title ) ) {
46 $this->error( wfMsg( 'createpage-badtitle', $target ) );
47 }
48 elseif ( $target != null ) {
49 if ( $title->getArticleID() > 0 ) {
50 // if the title exists then let the user know and give other options
51 $wgOut->addWikiText ( wfMsg ( 'createpage-titleexists', $title->getFullText() ) . "<br />" );
52 $skin = $wgUser->getSkin();
53 $editlink = $skin->makeLinkObj( $title, wfMsg ( 'createpage-editexisting' ), 'action=edit' );
54 $thisPage = Title::newFromText ( 'CreatePage', NS_SPECIAL );
55 $wgOut->addHTML ( $editlink . '<br />'
56 . $skin->makeLinkObj ( $thisPage, wfMsg ( 'createpage-tryagain' ) )
57 );
58 return;
59 } else {
60 /* TODO - may want to search for closely named pages and give
61 * other options here... */
62
63 // otherwise, redirect them to the edit page for their title
64 $wgOut->redirect ( $title->getEditURL() );
65 }
66 }
67
68 // if this is just a normal GET, then output the form
69
70 // prefill the input with the title, if it was passed along
71 $newTitle = false;
72 $newTitleText = $wgRequest->getVal( 'newtitle', null );
73 if ( $newTitleText != null ) {
74 $newTitle = Title::newFromURL( $newTitleText );
75 if ( is_null( $newTitle ) )
76 $newTitle = $newTitleText;
77 else
78 $newTitle = $newTitle->getText();
79 }
80
81 // output the form
82 $form = Xml::openElement( 'fieldset' ) .
83 Xml::element( 'legend', null, wfMsg( 'createpage' ) ) . # This should really use a different message
84 wfMsgWikiHtml( 'createpage-instructions' ) .
85 Xml::openElement( 'form', array( 'method' => 'post', 'name' => 'createpageform', 'action' => '' ) ) .
86 Xml::element( 'input', array( 'type' => 'text', 'name' => 'target', 'size' => 50, 'value' => $newTitle ) ) .
87 '<br />' .
88 Xml::element( 'input', array( 'type' => 'submit', 'value' => wfMsgHtml( 'createpage-submitbutton' ) ) ) .
89 Xml::closeElement( 'form' ) .
90 Xml::closeElement( 'fieldset' );
91 $wgOut->addHTML( $form );
92 }
93 /*
94 * Function to output an error message
95 * @param $msg String: message text or HTML
96 */
97 function error( $msg ) {
98 global $wgOut;
99 $wgOut->addHTML( Xml::element( 'p', array( 'class' => 'error' ), $msg ) );
100 }
101 }