Thread:Extension talk:DynamicPageList (Wikimedia)/Redirect to another page on the wiki

I've included the diff of the changes I made to DynamicPageList.php for our wiki, where we wanted to have canonical links that would always point to the newest page in a category (for example.)

This adds a mode, 'redirect', to DynamicPageList.php which will cause PHP to do a header redirect to the first result it gets back. It's a little ghetto, but it works very well and doesn't add any kind of weird overhead.

Index: docroot/extensions/intersection/DynamicPageList.php

=
====================================================== --- docroot/extensions/intersection/DynamicPageList.php	(revision 31) +++ docroot/extensions/intersection/DynamicPageList.php	(revision 32) @@ -197,6 +197,7 @@ 						$endList = ''; $startItem = ''; $endItem = ''; +						$redirectMode = false; break; case 'none': $startList = ''; @@ -204,6 +205,7 @@ 						$startItem = ''; $endItem = ' '; 						$inlineMode = false; +						$redirectMode = false; break; case 'ordered': $startList = ''; @@ -211,6 +213,7 @@ 						$startItem = ''; $endItem = ''; $inlineMode = false; +						$redirectMode = false; break; case 'inline': // aka comma seperated list @@ -219,7 +222,16 @@ 						$startItem = ''; $endItem = ''; $inlineMode = true; +						$redirectMode = false; break; +					case 'redirect': +						$startList = ''; +						$endList = ''; +						$startItem = ''; +						$endItem = ''; +						$inlineMode = false; +						$redirectMode = true; +						break; case 'unordered': default: $startList = ''; @@ -227,6 +239,7 @@ 						$startItem = ''; $endItem = ''; $inlineMode = false; +						$redirectMode = false; break; } 				break; @@ -627,7 +640,14 @@ 	} 	// end unordered list -	if ( $useGallery ) { +	if ( $redirectMode ) { +		if (count($articleList) > 0) { +			$uri = preg_replace('/^[^"]*"([^"]*)".*$/', '\1', $articleList[0]); +			header("Location: $uri"); +		} else { +			$output = 'No matches!'; +		} +	} elseif ( $useGallery ) { $gallery->setHideBadImages; $gallery->setShowFilename( $galleryFileName ); $gallery->setShowBytes( $galleryFileSize );