Extension:CreateArticle/sourcecode

Note: to get this code working under PHP 5.3.3 & MediaWiki 1.16.0, I had to change the definition of the function renderCreatebox from

to

With MediaWiki 1.16.0, a fatal error occurs when you try to create an article that already exists ("Fatal error: Call to a member function getNamespace on a non-object in /www/wiki/includes/Skin.php on line 376") This can be fixed by changing line 216 from

to

ENDFORM; return $createform; }       /**         * If br=no, create button is placed on rh side of textbox * defaults to yes */       function lineBreak { # Should we be inserting a tag? $cond = ( strtolower( $this->br ) == "no" ); $this->br = $cond ? '' : ' ';       }        /**         * If the width is not supplied, set it to 50 */       function checkWidth { if( !$this->width || trim( $this->width ) == '' ) $this->width = 50; } } /* creates the requested article using the supplied parameters */ function actionCreatearticle($action, $article) { global $wgRequest, $wgTitle, $wgOut, $prefix;

if($action != 'createarticle') return true;

$prefix = $wgRequest->getVal('prefix'); $subpage = $wgRequest->getVal('subpage'); $title = $wgRequest->getVal('title');

if($prefix && strpos($title, $prefix)!==0) { $title = $prefix. $title; }   if($subpage && substr($title,-strlen($subpage))!=$subpage) { $title.= $subpage; }   $title = Title::newFromText( $title ); if (trim($wgRequest->getVal('title'))=='') { $wgTitle = Title::newFromText( wfMsgForContent( 'badtitle' ) ); $wgOut->errorpage( 'badtitle', 'badtitletext');   } if(isset($title) && $title->getArticleID == 0) { accRedirect($title, 'createarticle'); } elseif (!isset($title)) { $wgTitle = Title::newFromText( wfMsgForContent( 'badtitle' ) ); $wgOut->errorpage( 'badtitle', 'badtitletext'); } else { ##need to make this create error messages to disallow editing existing articles from here $wgTitle = Title::newFromText( wfMsgForContent( 'createarticle' ) ); $wgOut->errorpage( 'error', 'articleexists' ); }   return false; } /* builds and sends the URL to the browser */ function accRedirect($title, $action) { global $wgRequest, $wgOut; $query = "action=edit&section=". $wgRequest->getVal('section'). "&createintro=". $wgRequest->getVal('createintro'). "&preload=". $wgRequest->getVal('preload'). "&editintro=". $wgRequest->getVal('editintro');

$wgOut->setSquidMaxage( 1200 ); $wgOut->redirect($title->getFullURL( $query ), '301'); }