71 parent::__construct(
'Redirect' );
75 $this->repoGroup = $repoGroup;
76 $this->userFactory = $userFactory;
85 $parts = $subpage !==
null ? explode(
'/', $subpage, 2 ) : [];
86 $this->mType = $parts[0] ??
null;
87 $this->mValue = $parts[1] ??
null;
96 if ( !ctype_digit( $this->mValue ) ) {
97 return Status::newFatal(
'redirect-not-numeric' );
99 $user = $this->userFactory->newFromId( (
int)$this->mValue );
101 if ( $user->isAnon() ) {
102 return Status::newFatal(
'redirect-not-exists' );
104 if ( $user->isHidden() && !$this->getAuthority()->isAllowed(
'hideuser' ) ) {
108 return Status::newGood( [
109 $user->getUserPage()->getFullURL(
'',
false,
PROTO_CURRENT ), 302
120 $title = Title::newFromTextThrow( $this->mValue,
NS_FILE );
121 if ( $title && !$title->inNamespace(
NS_FILE ) ) {
123 $title = Title::newFromTextThrow( Title::makeName(
NS_FILE, $this->mValue ) );
129 $file = $this->repoGroup->findFile( $title );
131 if ( !$file || !$file->exists() ) {
132 return Status::newFatal(
'redirect-not-exists' );
135 $url = $file->getUrl();
137 $width = $request->getInt(
'width', -1 );
138 $height = $request->getInt(
'height', -1 );
141 if ( $width != -1 ) {
142 $mto = $file->transform( [
'width' => $width,
'height' => $height ] );
144 if ( $mto && !$mto->isError() ) {
148 $url = [ $mto->getUrl(), $height === -1 ? 301 : 302 ];
152 return Status::newGood(
$url );
163 if ( !ctype_digit( $oldid ) ) {
164 return Status::newFatal(
'redirect-not-numeric' );
166 $oldid = (int)$oldid;
167 if ( $oldid === 0 ) {
168 return Status::newFatal(
'redirect-not-exists' );
183 if ( !ctype_digit( $curid ) ) {
184 return Status::newFatal(
'redirect-not-numeric' );
186 $curid = (int)$curid;
187 if ( $curid === 0 ) {
188 return Status::newFatal(
'redirect-not-exists' );
205 if ( !ctype_digit( $logid ) ) {
206 return Status::newFatal(
'redirect-not-numeric' );
208 $logid = (int)$logid;
209 if ( $logid === 0 ) {
210 return Status::newFatal(
'redirect-not-exists' );
212 $query = [
'title' =>
'Special:Log',
'logid' => $logid ];
224 private function dispatch() {
226 switch ( $this->mType ) {
246 if ( $status && $status->isGood() ) {
249 $value = $status->getValue();
250 if ( is_array( $value ) ) {
251 [
$url, $code ] = $value;
256 if ( $code === 301 ) {
257 $this->
getOutput()->setCdnMaxage( 60 * 60 );
265 if ( $this->mValue !==
null ) {
266 $this->
getOutput()->setStatusCode( 404 );
279 'label-message' =>
'redirect-lookup',
280 'options-messages' => [
281 'redirect-user' =>
'user',
282 'redirect-page' =>
'page',
283 'redirect-revision' =>
'revision',
284 'redirect-file' =>
'file',
285 'redirect-logid' =>
'logid',
291 'label-message' =>
'redirect-value',
299 if ( !empty( $data[
'type'] ) && !empty( $data[
'value'] ) ) {
300 $this->
setParameter( $data[
'type'] .
'/' . $data[
'value'] );
304 return $this->dispatch();
351class_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.