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
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
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
18 class SpecialCreatePage
extends SpecialPage
{
20 public function __construct() {
21 parent
::__construct( 'CreatePage', 'createpage' );
24 public function execute( $params ) {
25 global $wgOut, $wgRequest, $wgUser;
29 if ( !$this->userCanExecute( $wgUser ) ) {
30 $this->displayRestrictionError();
34 $wgOut->addWikiMsg( 'createpage-summary' );
36 // check to see if we are trying to create a page
37 $target = $wgRequest->getVal ( 'target' );
38 $title = Title
::newFromText ( $target );
41 if ( $wgRequest->wasPosted() && $target === '' ) {
42 $this->error( wfMsg( 'createpage-entertitle' ) );
44 // check for invalid title
45 elseif ( $wgRequest->wasPosted() && is_null( $title ) ) {
46 $this->error( wfMsg( 'createpage-badtitle', $target ) );
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' ) )
60 /* TODO - may want to search for closely named pages and give
61 * other options here... */
63 // otherwise, redirect them to the edit page for their title
64 $wgOut->redirect ( $title->getEditURL() );
68 // if this is just a normal GET, then output the form
70 // prefill the input with the title, if it was passed along
72 $newTitleText = $wgRequest->getVal( 'newtitle', null );
73 if ( $newTitleText != null ) {
74 $newTitle = Title
::newFromURL( $newTitleText );
75 if ( is_null( $newTitle ) )
76 $newTitle = $newTitleText;
78 $newTitle = $newTitle->getText();
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 ) ) .
88 Xml
::element( 'input', array( 'type' => 'submit', 'value' => wfMsgHtml( 'createpage-submitbutton' ) ) ) .
89 Xml
::closeElement( 'form' ) .
90 Xml
::closeElement( 'fieldset' );
91 $wgOut->addHTML( $form );
94 * Function to output an error message
95 * @param $msg String: message text or HTML
97 function error( $msg ) {
99 $wgOut->addHTML( Xml
::element( 'p', array( 'class' => 'error' ), $msg ) );