+
+ /**
+ * Tell the page view functions that this view was redirected
+ * from another page on the wiki.
+ * @param Title $from
+ */
+ function setRedirectedFrom( $from ) {
+ $this->mRedirectedFrom = $from;
+ }
+
+ /**
+ * @return mixed false, Title of in-wiki target, or string with URL
+ */
+ function followRedirect() {
+ $text = $this->getContent();
+ $rt = Title::newFromRedirect( $text );
+
+ # process if title object is valid and not special:userlogout
+ if( $rt ) {
+ if( $rt->getInterwiki() != '' ) {
+ if( $rt->isLocal() ) {
+ // Offsite wikis need an HTTP redirect.
+ //
+ // This can be hard to reverse and may produce loops,
+ // so they may be disabled in the site configuration.
+
+ $source = $this->mTitle->getFullURL( 'redirect=no' );
+ return $rt->getFullURL( 'rdfrom=' . urlencode( $source ) );
+ }
+ } else {
+ if( $rt->getNamespace() == NS_SPECIAL ) {
+ // Gotta hand redirects to special pages differently:
+ // Fill the HTTP response "Location" header and ignore
+ // the rest of the page we're on.
+ //
+ // This can be hard to reverse, so they may be disabled.
+
+ if( $rt->getNamespace() == NS_SPECIAL && $rt->getText() == 'Userlogout' ) {
+ // rolleyes
+ } else {
+ return $rt->getFullURL();
+ }
+ } elseif( $rt->exists() ) {
+ // Internal redirects can be handled relatively gracefully.
+ // We may have to change to another Article subclass, though.
+ return $rt;
+ }
+ }
+ }
+
+ // No or invalid redirect
+ return false;
+ }