profiling correction
[mediawiki.git] / includes / SpecialMovepage.php
blob329c0d28cfbb4cebc233111813c2665819b95dea
1 <?php
2 require_once( "LinksUpdate.php" );
4 function wfSpecialMovepage()
6 global $wgUser, $wgOut, $wgRequest, $action;
8 if ( 0 == $wgUser->getID() or $wgUser->isBlocked() ) {
9 $wgOut->errorpage( "movenologin", "movenologintext" );
10 return;
12 if ( wfReadOnly() ) {
13 $wgOut->readOnlyPage();
14 return;
17 $f = new MovePageForm();
19 if ( "success" == $action ) { $f->showSuccess(); }
20 else if ( "submit" == $action && $wgRequest->wasPosted() ) { $f->doSubmit(); }
21 else { $f->showForm( "" ); }
24 class MovePageForm {
25 var $oldTitle, $newTitle; # Text input
27 function MovePageForm() {
28 global $wgRequest;
29 $this->oldTitle = $wgRequest->getText( 'wpOldTitle', $wgRequest->getVal( 'target' ) );
30 $this->newTitle = $wgRequest->getText( 'wpNewTitle' );
33 function showForm( $err )
35 global $wgOut, $wgUser, $wgLang;
37 $wgOut->setPagetitle( wfMsg( "movepage" ) );
39 if ( empty( $this->oldTitle ) ) {
40 $wgOut->errorpage( "notargettitle", "notargettext" );
41 return;
44 $encOldTitle = htmlspecialchars( $this->oldTitle );
45 $encNewTitle = htmlspecialchars( $this->newTitle );
46 $ot = Title::newFromURL( $this->oldTitle );
47 $ott = $ot->getPrefixedText();
49 $wgOut->addWikiText( wfMsg( "movepagetext" ) );
50 if ( ! Namespace::isTalk( $ot->getNamespace() ) ) {
51 $wgOut->addWikiText( wfMsg( "movepagetalktext" ) );
54 $ma = wfMsg( "movearticle" );
55 $newt = wfMsg( "newtitle" );
56 $mpb = wfMsg( "movepagebtn" );
57 $movetalk = wfMsg( "movetalk" );
59 $titleObj = Title::makeTitle( NS_SPECIAL, "Movepage" );
60 $action = $titleObj->escapeLocalURL( "action=submit" );
62 if ( "" != $err ) {
63 $wgOut->setSubtitle( wfMsg( "formerror" ) );
64 $wgOut->addHTML( "<p class='error'>{$err}</p>\n" );
66 $wgOut->addHTML( "
67 <form id=\"movepage\" method=\"post\" action=\"{$action}\">
68 <table border='0'>
69 <tr>
70 <td align='right'>{$ma}:</td>
71 <td align='left'><strong>{$ott}</strong></td>
72 </tr>
73 <tr>
74 <td align='right'>{$newt}:</td>
75 <td align='left'>
76 <input type='text' size='40' name=\"wpNewTitle\" value=\"{$encNewTitle}\" />
77 <input type='hidden' name=\"wpOldTitle\" value=\"{$encOldTitle}\" />
78 </td>
79 </tr>" );
81 if ( ! Namespace::isTalk( $ot->getNamespace() ) ) {
82 $wgOut->addHTML( "
83 <tr>
84 <td align='right'>
85 <input type='checkbox' name=\"wpMovetalk\" checked='checked' value=\"1\" />
86 </td>
87 <td>{$movetalk}</td>
88 </tr>" );
90 $wgOut->addHTML( "
91 <tr>
92 <td>&nbsp;</td>
93 <td align='left'>
94 <input type='submit' name=\"wpMove\" value=\"{$mpb}\" />
95 </td>
96 </tr>
97 </table>
98 </form>\n" );
102 function doSubmit()
104 global $wgOut, $wgUser, $wgLang;
105 global $wgDeferredUpdateList, $wgMessageCache;
106 global $wgUseSquid;
107 $fname = "MovePageForm::doSubmit";
109 $ot = Title::newFromText( $this->oldTitle );
110 $nt = Title::newFromText( $this->newTitle );
112 $error = $ot->moveTo( $nt );
113 if ( $error !== true ) {
114 $this->showForm( wfMsg( $error ) );
115 return;
118 # Move talk page if
119 # (1) the checkbox says to,
120 # (2) the namespaces are not themselves talk namespaces, and of course
121 # (3) it exists.
123 $ons = $ot->getNamespace();
124 $nns = $nt->getNamespace();
126 if ( ( 1 == $_REQUEST['wpMovetalk'] ) &&
127 ( ! Namespace::isTalk( $ons ) ) &&
128 ( ! Namespace::isTalk( $nns ) ) ) {
130 # get old talk page namespace
131 $ons = Namespace::getTalk( $ons );
132 # get new talk page namespace
133 $nns = Namespace::getTalk( $nns );
135 # make talk page title objects
136 $ott = Title::makeTitle( $ons, $ot->getDBkey() );
137 $ntt = Title::makeTitle( $nns, $nt->getDBkey() );
139 # Attempt the move
140 $error = $ott->moveTo( $ntt );
141 if ( $error === true ) {
142 $talkmoved = 1;
143 } else {
144 $talkmoved = $error;
148 $titleObj = Title::makeTitle( NS_SPECIAL, "Movepage" );
149 $success = $titleObj->getFullURL(
150 "action=success&oldtitle=" . wfUrlencode( $ot->getPrefixedText() ) .
151 "&newtitle=" . wfUrlencode( $nt->getPrefixedText() ) .
152 "&talkmoved={$talkmoved}" );
154 $wgOut->redirect( $success );
157 function showSuccess()
159 global $wgOut, $wgUser;
161 $wgOut->setPagetitle( wfMsg( "movepage" ) );
162 $wgOut->setSubtitle( wfMsg( "pagemovedsub" ) );
164 $text = wfMsg( "pagemovedtext", $_REQUEST['oldtitle'], $_REQUEST['newtitle'] );
165 $wgOut->addWikiText( $text );
167 $talkmoved = $_REQUEST['talkmoved'];
168 if ( 1 == $talkmoved ) {
169 $wgOut->addHTML( "\n<p>" . wfMsg( "talkpagemoved" ) . "</p>\n" );
170 } elseif( 'articleexists' == $talkmoved ) {
171 $wgOut->addHTML( "\n<p><strong>" . wfMsg( "talkexists" ) . "</strong></p>\n" );
172 } else {
173 $ot = Title::newFromURL( $_REQUEST['oldtitle'] );
174 if ( ! Namespace::isTalk( $ot->getNamespace() ) ) {
175 $wgOut->addHTML( "\n<p>" . wfMsg( "talkpagenotmoved", wfMsg( $talkmoved ) ) . "</p>\n" );