Follow-up r49880, tweaks to Special:CreatePage:
authorAlexandre Emsenhuber <ialex@users.mediawiki.org>
Sat, 25 Apr 2009 19:40:41 +0000 (19:40 +0000)
committerAlexandre Emsenhuber <ialex@users.mediawiki.org>
Sat, 25 Apr 2009 19:40:41 +0000 (19:40 +0000)
* Fix doc, use @ingroup, NOT @addtogroup
* Allow to use the subpage paramter if the "target" URL parameter is not passed
* Fixed a fatal error when calling Special:CreatePage?target=> (GET request with invalid target)
* Escaping messages used for Skin::makeLinkObj() since they won't be escaped by that function
* Fixed double escaping for 'createpage-submitbutton'
* Whitespaces tweaks

includes/specials/SpecialCreatePage.php

index 63dcf3e..ba0ce41 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+
 /* This code was adapted from CreatePage.php from: Travis Derouin <travis@wikihow.com> for the Uniwiki extension CreatePage
  * Originally licensed as: GNU GPL v2.0 or later
  *
  * @author Evan Wheeler
  * @author Adam Mckaig (at UNICEF)
  * @author Siebrand Mazeland (integrated into MediaWiki core)
- * @addtogroup SpecialPage
+ * @ingroup SpecialPage
  */
-
 class SpecialCreatePage extends SpecialPage {
 
        function __construct() {
                SpecialPage::SpecialPage( 'CreatePage', 'createpage' );
        }
 
-       public function execute( $params ) {
+       public function execute( $par ) {
                global $wgOut, $wgRequest, $wgUser;
 
                $this->setHeaders();
@@ -31,37 +31,34 @@ class SpecialCreatePage extends SpecialPage {
                        return;
                }
 
-               $wgOut->addWikiMsg( 'createpage-summary' );
+               $this->outputHeader();
 
                // check to see if we are trying to create a page
-               $target = $wgRequest->getVal ( 'target' );
-               $title = Title::newFromText ( $target );
+               $target = $wgRequest->getVal( 'target', $par );
+               $title = Title::newFromText( $target );
 
                // check for no title
                if ( $wgRequest->wasPosted() && $target === '' ) {
                        $this->error( wfMsg( 'createpage-entertitle' ) );
-               }
-               // check for invalid title
-               elseif ( $wgRequest->wasPosted() && is_null( $title ) ) {
-                       $this->error( wfMsg( 'createpage-badtitle', $target ) );
-               }
-               elseif ( $target != null ) {
-                       if ( $title->getArticleID() > 0 ) {
+               } elseif ( $target !== '' ) {
+                       if ( !$title instanceof Title ) {
+                               // check for invalid title
+                               $this->error( wfMsg( 'createpage-badtitle', $target ) );
+                       } else if ( $title->getArticleID() > 0 ) {
                                // if the title exists then let the user know and give other options
-                               $wgOut->addWikiText ( wfMsg ( 'createpage-titleexists', $title->getFullText() ) . "<br />" );
+                               $wgOut->addWikiMsg( 'createpage-titleexists', $title->getFullText() );
+                               $wgOut->addHTML( '<br />' );
                                $skin = $wgUser->getSkin();
-                               $editlink = $skin->makeLinkObj( $title, wfMsg ( 'createpage-editexisting' ), 'action=edit' );
-                               $thisPage = Title::newFromText ( 'CreatePage', NS_SPECIAL );
-                               $wgOut->addHTML ( $editlink . '<br />'
-                                       . $skin->makeLinkObj ( $thisPage, wfMsg ( 'createpage-tryagain' ) )
-                               );
+                               $editlink = $skin->makeLinkObj( $title, wfMsgHTML( 'createpage-editexisting' ), 'action=edit' );
+                               $thislink = $skin->makeLinkObj( $this->getTitle(), wfMsgHTML( 'createpage-tryagain' ) );
+                               $wgOut->addHTML( $editlink . '<br />' . $editlink );
                                return;
                        } else {
                                /* TODO - may want to search for closely named pages and give
                                 * other options here... */
 
                                // otherwise, redirect them to the edit page for their title
-                               $wgOut->redirect ( $title->getEditURL() );
+                               $wgOut->redirect( $title->getEditURL() );
                        }
                }
 
@@ -79,16 +76,17 @@ class SpecialCreatePage extends SpecialPage {
                }
 
                // output the form
-               $form = Xml::openElement( 'fieldset' ) .
+               $wgOut->addHTML(
+                       Xml::openElement( 'fieldset' ) .
                        Xml::element( 'legend', null, wfMsg( 'createpage' ) ) . # This should really use a different message
                        wfMsgWikiHtml( 'createpage-instructions' ) .
-                       Xml::openElement( 'form', array( 'method' => 'post', 'name' => 'createpageform', 'action' => '' ) ) .
+                       Xml::openElement( 'form', array( 'method' => 'post', 'name' => 'createpageform', 'action' => $this->getTitle()->getLocalUrl() ) ) .
                        Xml::element( 'input', array( 'type' => 'text', 'name' => 'target', 'size' => 50, 'value' => $newTitle ) ) .
                        '<br />' .
-                       Xml::element( 'input', array( 'type' => 'submit', 'value' => wfMsgHtml( 'createpage-submitbutton' ) ) ) .
+                       Xml::element( 'input', array( 'type' => 'submit', 'value' => wfMsg( 'createpage-submitbutton' ) ) ) .
                        Xml::closeElement( 'form' ) .
-                       Xml::closeElement( 'fieldset' );
-               $wgOut->addHTML( $form );
+                       Xml::closeElement( 'fieldset' )
+               );
        }
        /*
         * Function to output an error message