summaryrefslogtreecommitdiff
path: root/includes/specials/SpecialRedirect.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/specials/SpecialRedirect.php')
-rw-r--r--includes/specials/SpecialRedirect.php72
1 files changed, 53 insertions, 19 deletions
diff --git a/includes/specials/SpecialRedirect.php b/includes/specials/SpecialRedirect.php
index f05dacbc..2022d748 100644
--- a/includes/specials/SpecialRedirect.php
+++ b/includes/specials/SpecialRedirect.php
@@ -55,6 +55,7 @@ class SpecialRedirect extends FormSpecialPage {
/**
* Set $mType and $mValue based on parsed value of $subpage.
+ * @param string $subpage
*/
function setParameter( $subpage ) {
// parse $subpage to pull out the parts
@@ -66,7 +67,7 @@ class SpecialRedirect extends FormSpecialPage {
/**
* Handle Special:Redirect/user/xxxx (by redirecting to User:YYYY)
*
- * @return string|null url to redirect to, or null if $mValue is invalid.
+ * @return string|null Url to redirect to, or null if $mValue is invalid.
*/
function dispatchUser() {
if ( !ctype_digit( $this->mValue ) ) {
@@ -78,18 +79,19 @@ class SpecialRedirect extends FormSpecialPage {
return null;
}
$userpage = Title::makeTitle( NS_USER, $username );
+
return $userpage->getFullURL( '', false, PROTO_CURRENT );
}
/**
* Handle Special:Redirect/file/xxxx
*
- * @return string|null url to redirect to, or null if $mValue is not found.
+ * @return string|null Url to redirect to, or null if $mValue is not found.
*/
function dispatchFile() {
$title = Title::makeTitleSafe( NS_FILE, $this->mValue );
- if ( ! $title instanceof Title ) {
+ if ( !$title instanceof Title ) {
return null;
}
$file = wfFindFile( $title );
@@ -112,6 +114,7 @@ class SpecialRedirect extends FormSpecialPage {
$url = $mto->getURL();
}
}
+
return $url;
}
@@ -119,7 +122,7 @@ class SpecialRedirect extends FormSpecialPage {
* Handle Special:Redirect/revision/xxx
* (by redirecting to index.php?oldid=xxx)
*
- * @return string|null url to redirect to, or null if $mValue is invalid.
+ * @return string|null Url to redirect to, or null if $mValue is invalid.
*/
function dispatchRevision() {
$oldid = $this->mValue;
@@ -130,46 +133,73 @@ class SpecialRedirect extends FormSpecialPage {
if ( $oldid === 0 ) {
return null;
}
+
return wfAppendQuery( wfScript( 'index' ), array(
'oldid' => $oldid
) );
}
/**
+ * Handle Special:Redirect/page/xxx (by redirecting to index.php?curid=xxx)
+ *
+ * @return string|null Url to redirect to, or null if $mValue is invalid.
+ */
+ function dispatchPage() {
+ $curid = $this->mValue;
+ if ( !ctype_digit( $curid ) ) {
+ return null;
+ }
+ $curid = (int)$curid;
+ if ( $curid === 0 ) {
+ return null;
+ }
+
+ return wfAppendQuery( wfScript( 'index' ), array(
+ 'curid' => $curid
+ ) );
+ }
+
+ /**
* Use appropriate dispatch* method to obtain a redirection URL,
* and either: redirect, set a 404 error code and error message,
* or do nothing (if $mValue wasn't set) allowing the form to be
* displayed.
*
- * @return bool true if a redirect was successfully handled.
+ * @return bool True if a redirect was successfully handled.
*/
function dispatch() {
// the various namespaces supported by Special:Redirect
switch ( $this->mType ) {
- case 'user':
- $url = $this->dispatchUser();
- break;
- case 'file':
- $url = $this->dispatchFile();
- break;
- case 'revision':
- $url = $this->dispatchRevision();
- break;
- default:
- $this->getOutput()->setStatusCode( 404 );
- $url = null;
- break;
+ case 'user':
+ $url = $this->dispatchUser();
+ break;
+ case 'file':
+ $url = $this->dispatchFile();
+ break;
+ case 'revision':
+ $url = $this->dispatchRevision();
+ break;
+ case 'page':
+ $url = $this->dispatchPage();
+ break;
+ default:
+ $this->getOutput()->setStatusCode( 404 );
+ $url = null;
+ break;
}
if ( $url ) {
$this->getOutput()->redirect( $url );
+
return true;
}
if ( !is_null( $this->mValue ) ) {
$this->getOutput()->setStatusCode( 404 );
// Message: redirect-not-exists
$msg = $this->getMessagePrefix() . '-not-exists';
+
return Status::newFatal( $msg );
}
+
return false;
}
@@ -177,8 +207,10 @@ class SpecialRedirect extends FormSpecialPage {
$mp = $this->getMessagePrefix();
$ns = array(
// subpage => message
- // Messages: redirect-user, redirect-revision, redirect-file
+ // Messages: redirect-user, redirect-page, redirect-revision,
+ // redirect-file
'user' => $mp . '-user',
+ 'page' => $mp . '-page',
'revision' => $mp . '-revision',
'file' => $mp . '-file',
);
@@ -204,6 +236,7 @@ class SpecialRedirect extends FormSpecialPage {
if ( !empty( $this->mValue ) ) {
$a['value']['default'] = $this->mValue;
}
+
return $a;
}
@@ -211,6 +244,7 @@ class SpecialRedirect extends FormSpecialPage {
if ( !empty( $data['type'] ) && !empty( $data['value'] ) ) {
$this->setParameter( $data['type'] . '/' . $data['value'] );
}
+
/* if this returns false, will show the form */
return $this->dispatch();
}