00001 <?php 00002 require_once( "LinksUpdate.php" ); 00003 00004 function wfSpecialMovepage() 00005 { 00006 global $wgUser, $wgOut, $wgRequest, $action; 00007 00008 if ( 0 == $wgUser->getID() or $wgUser->isBlocked() ) { 00009 $wgOut->errorpage( "movenologin", "movenologintext" ); 00010 return; 00011 } 00012 if ( wfReadOnly() ) { 00013 $wgOut->readOnlyPage(); 00014 return; 00015 } 00016 00017 $f = new MovePageForm(); 00018 00019 if ( "success" == $action ) { $f->showSuccess(); } 00020 else if ( "submit" == $action && $wgRequest->wasPosted() ) { $f->doSubmit(); } 00021 else { $f->showForm( "" ); } 00022 } 00023 00024 class MovePageForm { 00025 var $oldTitle, $newTitle; # Text input 00026 00027 function MovePageForm() { 00028 global $wgRequest; 00029 $this->oldTitle = $wgRequest->getText( 'wpOldTitle', $wgRequest->getVal( 'target' ) ); 00030 $this->newTitle = $wgRequest->getText( 'wpNewTitle' ); 00031 } 00032 00033 function showForm( $err ) 00034 { 00035 global $wgOut, $wgUser, $wgLang; 00036 00037 $wgOut->setPagetitle( wfMsg( "movepage" ) ); 00038 00039 if ( empty( $this->oldTitle ) ) { 00040 $wgOut->errorpage( "notargettitle", "notargettext" ); 00041 return; 00042 } 00043 00044 $encOldTitle = htmlspecialchars( $this->oldTitle ); 00045 $encNewTitle = htmlspecialchars( $this->newTitle ); 00046 $ot = Title::newFromURL( $this->oldTitle ); 00047 $ott = $ot->getPrefixedText(); 00048 00049 $wgOut->addWikiText( wfMsg( "movepagetext" ) ); 00050 if ( ! Namespace::isTalk( $ot->getNamespace() ) ) { 00051 $wgOut->addWikiText( wfMsg( "movepagetalktext" ) ); 00052 } 00053 00054 $ma = wfMsg( "movearticle" ); 00055 $newt = wfMsg( "newtitle" ); 00056 $mpb = wfMsg( "movepagebtn" ); 00057 $movetalk = wfMsg( "movetalk" ); 00058 00059 $titleObj = Title::makeTitle( NS_SPECIAL, "Movepage" ); 00060 $action = $titleObj->escapeLocalURL( "action=submit" ); 00061 00062 if ( "" != $err ) { 00063 $wgOut->setSubtitle( wfMsg( "formerror" ) ); 00064 $wgOut->addHTML( "<p class='error'>{$err}</p>\n" ); 00065 } 00066 $wgOut->addHTML( " 00067 <form id=\"movepage\" method=\"post\" action=\"{$action}\"> 00068 <table border='0'> 00069 <tr> 00070 <td align='right'>{$ma}:</td> 00071 <td align='left'><strong>{$ott}</strong></td> 00072 </tr> 00073 <tr> 00074 <td align='right'>{$newt}:</td> 00075 <td align='left'> 00076 <input type='text' size='40' name=\"wpNewTitle\" value=\"{$encNewTitle}\" /> 00077 <input type='hidden' name=\"wpOldTitle\" value=\"{$encOldTitle}\" /> 00078 </td> 00079 </tr>" ); 00080 00081 if ( ! Namespace::isTalk( $ot->getNamespace() ) ) { 00082 $wgOut->addHTML( " 00083 <tr> 00084 <td align='right'> 00085 <input type='checkbox' name=\"wpMovetalk\" checked='checked' value=\"1\" /> 00086 </td> 00087 <td>{$movetalk}</td> 00088 </tr>" ); 00089 } 00090 $wgOut->addHTML( " 00091 <tr> 00092 <td> </td> 00093 <td align='left'> 00094 <input type='submit' name=\"wpMove\" value=\"{$mpb}\" /> 00095 </td> 00096 </tr> 00097 </table> 00098 </form>\n" ); 00099 00100 } 00101 00102 function doSubmit() 00103 { 00104 global $wgOut, $wgUser, $wgLang; 00105 global $wgDeferredUpdateList, $wgMessageCache; 00106 global $wgUseSquid; 00107 $fname = "MovePageForm::doSubmit"; 00108 00109 $ot = Title::newFromText( $this->oldTitle ); 00110 $nt = Title::newFromText( $this->newTitle ); 00111 00112 $error = $ot->moveTo( $nt ); 00113 if ( $error !== true ) { 00114 $this->showForm( wfMsg( $error ) ); 00115 return; 00116 } 00117 00118 # Move talk page if 00119 # (1) the checkbox says to, 00120 # (2) the namespaces are not themselves talk namespaces, and of course 00121 # (3) it exists. 00122 00123 $ons = $ot->getNamespace(); 00124 $nns = $nt->getNamespace(); 00125 00126 if ( ( 1 == $_REQUEST['wpMovetalk'] ) && 00127 ( ! Namespace::isTalk( $ons ) ) && 00128 ( ! Namespace::isTalk( $nns ) ) ) { 00129 00130 # get old talk page namespace 00131 $ons = Namespace::getTalk( $ons ); 00132 # get new talk page namespace 00133 $nns = Namespace::getTalk( $nns ); 00134 00135 # make talk page title objects 00136 $ott = Title::makeTitle( $ons, $ot->getDBkey() ); 00137 $ntt = Title::makeTitle( $nns, $nt->getDBkey() ); 00138 00139 # Attempt the move 00140 $error = $ott->moveTo( $ntt ); 00141 if ( $error === true ) { 00142 $talkmoved = 1; 00143 } else { 00144 $talkmoved = $error; 00145 } 00146 } 00147 00148 $titleObj = Title::makeTitle( NS_SPECIAL, "Movepage" ); 00149 $success = $titleObj->getFullURL( 00150 "action=success&oldtitle=" . wfUrlencode( $ot->getPrefixedText() ) . 00151 "&newtitle=" . wfUrlencode( $nt->getPrefixedText() ) . 00152 "&talkmoved={$talkmoved}" ); 00153 00154 $wgOut->redirect( $success ); 00155 } 00156 00157 function showSuccess() 00158 { 00159 global $wgOut, $wgUser; 00160 00161 $wgOut->setPagetitle( wfMsg( "movepage" ) ); 00162 $wgOut->setSubtitle( wfMsg( "pagemovedsub" ) ); 00163 00164 $text = wfMsg( "pagemovedtext", $_REQUEST['oldtitle'], $_REQUEST['newtitle'] ); 00165 $wgOut->addWikiText( $text ); 00166 00167 $talkmoved = $_REQUEST['talkmoved']; 00168 if ( 1 == $talkmoved ) { 00169 $wgOut->addHTML( "\n<p>" . wfMsg( "talkpagemoved" ) . "</p>\n" ); 00170 } elseif( 'articleexists' == $talkmoved ) { 00171 $wgOut->addHTML( "\n<p><strong>" . wfMsg( "talkexists" ) . "</strong></p>\n" ); 00172 } else { 00173 $ot = Title::newFromURL( $_REQUEST['oldtitle'] ); 00174 if ( ! Namespace::isTalk( $ot->getNamespace() ) ) { 00175 $wgOut->addHTML( "\n<p>" . wfMsg( "talkpagenotmoved", wfMsg( $talkmoved ) ) . "</p>\n" ); 00176 } 00177 } 00178 } 00179 } 00180 ?>