include_once -> require_once
[lhc/web/wiklou.git] / includes / SpecialMovepage.php
1 <?php
2 require_once( "LinksUpdate.php" );
3
4 function wfSpecialMovepage()
5 {
6 global $wgUser, $wgOut, $wgRequest, $action;
7
8 if ( 0 == $wgUser->getID() or $wgUser->isBlocked() ) {
9 $wgOut->errorpage( "movenologin", "movenologintext" );
10 return;
11 }
12 if ( wfReadOnly() ) {
13 $wgOut->readOnlyPage();
14 return;
15 }
16
17 $f = new MovePageForm();
18
19 if ( "success" == $action ) { $f->showSuccess(); }
20 else if ( "submit" == $action && $wgRequest->wasPosted() ) { $f->doSubmit(); }
21 else { $f->showForm( "" ); }
22 }
23
24 class MovePageForm {
25 var $oldTitle, $newTitle; # Text input
26
27 function MovePageForm() {
28 global $wgRequest;
29 $this->oldTitle = $wgRequest->getText( 'wpOldTitle', $wgRequest->getVal( 'target' ) );
30 $this->newTitle = $wgRequest->getText( 'wpNewTitle' );
31 }
32
33 function showForm( $err )
34 {
35 global $wgOut, $wgUser, $wgLang;
36
37 $wgOut->setPagetitle( wfMsg( "movepage" ) );
38
39 if ( empty( $this->oldTitle ) ) {
40 $wgOut->errorpage( "notargettitle", "notargettext" );
41 return;
42 }
43
44 $encOldTitle = htmlspecialchars( $this->oldTitle );
45 $encNewTitle = htmlspecialchars( $this->newTitle );
46 $ot = Title::newFromURL( $this->oldTitle );
47 $ott = $ot->getPrefixedText();
48
49 $wgOut->addWikiText( wfMsg( "movepagetext" ) );
50 if ( ! Namespace::isTalk( $ot->getNamespace() ) ) {
51 $wgOut->addWikiText( wfMsg( "movepagetalktext" ) );
52 }
53
54 $ma = wfMsg( "movearticle" );
55 $newt = wfMsg( "newtitle" );
56 $mpb = wfMsg( "movepagebtn" );
57 $movetalk = wfMsg( "movetalk" );
58
59 $titleObj = Title::makeTitle( NS_SPECIAL, "Movepage" );
60 $action = $titleObj->escapeLocalURL( "action=submit" );
61
62 if ( "" != $err ) {
63 $wgOut->setSubtitle( wfMsg( "formerror" ) );
64 $wgOut->addHTML( "<p class='error'>{$err}</p>\n" );
65 }
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>" );
80
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>" );
89 }
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" );
99
100 }
101
102 function doSubmit()
103 {
104 global $wgOut, $wgUser, $wgLang;
105 global $wgDeferredUpdateList, $wgMessageCache;
106 global $wgUseSquid;
107 $fname = "MovePageForm::doSubmit";
108
109 $ot = Title::newFromText( $this->oldTitle );
110 $nt = Title::newFromText( $this->newTitle );
111
112 $error = $ot->moveTo( $nt );
113 if ( $error !== true ) {
114 $this->showForm( wfMsg( $error ) );
115 return;
116 }
117
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.
122
123 $ons = $ot->getNamespace();
124 $nns = $nt->getNamespace();
125
126 if ( ( 1 == $_REQUEST['wpMovetalk'] ) &&
127 ( ! Namespace::isTalk( $ons ) ) &&
128 ( ! Namespace::isTalk( $nns ) ) ) {
129
130 # get old talk page namespace
131 $ons = Namespace::getTalk( $ons );
132 # get new talk page namespace
133 $nns = Namespace::getTalk( $nns );
134
135 # make talk page title objects
136 $ott = Title::makeTitle( $ons, $ot->getDBkey() );
137 $ntt = Title::makeTitle( $nns, $nt->getDBkey() );
138
139 # Attempt the move
140 $error = $ott->moveTo( $ntt );
141 if ( $error === true ) {
142 $talkmoved = 1;
143 } else {
144 $talkmoved = $error;
145 }
146 }
147
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}" );
153
154 $wgOut->redirect( $success );
155 }
156
157 function showSuccess()
158 {
159 global $wgOut, $wgUser;
160
161 $wgOut->setPagetitle( wfMsg( "movepage" ) );
162 $wgOut->setSubtitle( wfMsg( "pagemovedsub" ) );
163
164 $text = wfMsg( "pagemovedtext", $_REQUEST['oldtitle'], $_REQUEST['newtitle'] );
165 $wgOut->addWikiText( $text );
166
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" );
176 }
177 }
178 }
179 }
180 ?>