75 parent::__construct(
'Redirect' );
79 $this->repoGroup = $repoGroup;
80 $this->userFactory = $userFactory;
89 $parts = $subpage !==
null ? explode(
'/', $subpage, 2 ) : [];
90 $this->mType = $parts[0] ??
null;
91 $this->mValue = $parts[1] ??
null;
100 if ( !ctype_digit( $this->mValue ) ) {
101 return Status::newFatal(
'redirect-not-numeric' );
103 $user = $this->userFactory->newFromId( (
int)$this->mValue );
105 if ( $user->isAnon() ) {
106 return Status::newFatal(
'redirect-not-exists' );
108 if ( $user->isHidden() && !$this->getAuthority()->isAllowed(
'hideuser' ) ) {
112 return Status::newGood( [
113 $user->getUserPage()->getFullURL(
'',
false,
PROTO_CURRENT ), 302
124 $title = Title::newFromTextThrow( $this->mValue,
NS_FILE );
125 if ( $title && !$title->inNamespace(
NS_FILE ) ) {
127 $title = Title::newFromTextThrow( Title::makeName(
NS_FILE, $this->mValue ) );
133 $file = $this->repoGroup->findFile( $title );
135 if ( !$file || !$file->exists() ) {
136 return Status::newFatal(
'redirect-not-exists' );
139 $url = $file->getUrl();
141 $width = $request->getInt(
'width', -1 );
142 $height = $request->getInt(
'height', -1 );
145 if ( $width != -1 ) {
146 $mto = $file->transform( [
'width' => $width,
'height' => $height ] );
148 if ( $mto && !$mto->isError() ) {
152 $url = [ $mto->getUrl(), $height === -1 ? 301 : 302 ];
156 return Status::newGood(
$url );
167 if ( !ctype_digit( $oldid ) ) {
168 return Status::newFatal(
'redirect-not-numeric' );
170 $oldid = (int)$oldid;
171 if ( $oldid === 0 ) {
172 return Status::newFatal(
'redirect-not-exists' );
187 if ( !ctype_digit( $curid ) ) {
188 return Status::newFatal(
'redirect-not-numeric' );
190 $curid = (int)$curid;
191 if ( $curid === 0 ) {
192 return Status::newFatal(
'redirect-not-exists' );
209 if ( !ctype_digit( $logid ) ) {
210 return Status::newFatal(
'redirect-not-numeric' );
212 $logid = (int)$logid;
213 if ( $logid === 0 ) {
214 return Status::newFatal(
'redirect-not-exists' );
216 $query = [
'title' =>
'Special:Log',
'logid' => $logid ];
228 private function dispatch() {
230 switch ( $this->mType ) {
250 if ( $status && $status->isGood() ) {
253 $value = $status->getValue();
254 if ( is_array( $value ) ) {
255 [
$url, $code ] = $value;
260 if ( $code === 301 ) {
261 $this->
getOutput()->setCdnMaxage( 60 * 60 );
269 if ( $this->mValue !==
null ) {
270 $this->
getOutput()->setStatusCode( 404 );
283 'label-message' =>
'redirect-lookup',
284 'options-messages' => [
285 'redirect-user' =>
'user',
286 'redirect-page' =>
'page',
287 'redirect-revision' =>
'revision',
288 'redirect-file' =>
'file',
289 'redirect-logid' =>
'logid',
295 'label-message' =>
'redirect-value',
303 if ( !empty( $data[
'type'] ) && !empty( $data[
'value'] ) ) {
304 $this->
setParameter( $data[
'type'] .
'/' . $data[
'value'] );
308 return $this->dispatch();
355class_alias( SpecialRedirect::class,
'SpecialRedirect' );
wfAppendQuery( $url, $query)
Append a query string to an existing URL, which may or may not already have query string parameters a...
wfScript( $script='index')
Get the URL path to a MediaWiki entry point.
Special page which uses an HTMLForm to handle processing.
getRequest()
Get the WebRequest being used for this instance.
getOutput()
Get the OutputPage being used for this instance.
Show an error when a user tries to do something they do not have the necessary permissions for.
Prioritized list of file repositories.