Index: trunk/phase3/docs/hooks.txt |
— | — | @@ -698,6 +698,12 @@ |
699 | 699 | &$file: File object |
700 | 700 | &$displayFile: displayed File object |
701 | 701 | |
| 702 | +'InitializeArticleMaybeRedirect': MediaWiki check to see if title is a redirect |
| 703 | +$title: Title object ($wgTitle) |
| 704 | +$request: WebRequest |
| 705 | +$ignoreRedirect: boolean to skip redirect check |
| 706 | +$target: Title/string of redirect target |
| 707 | + |
702 | 708 | 'InitPreferencesForm': called at the end of PreferencesForm's constructor |
703 | 709 | $form: the PreferencesForm |
704 | 710 | $request: the web request to initialized from |
Index: trunk/phase3/includes/Article.php |
— | — | @@ -111,10 +111,18 @@ |
112 | 112 | * |
113 | 113 | * @return mixed false, Title of in-wiki target, or string with URL |
114 | 114 | */ |
115 | | - function followRedirect() { |
| 115 | + public function followRedirect() { |
116 | 116 | $text = $this->getContent(); |
| 117 | + return self::followRedirectText( $text ); |
| 118 | + } |
| 119 | + |
| 120 | + /** |
| 121 | + * Get the Title object this text redirects to |
| 122 | + * |
| 123 | + * @return mixed false, Title of in-wiki target, or string with URL |
| 124 | + */ |
| 125 | + public static function followRedirectText( $text ) { |
117 | 126 | $rt = Title::newFromRedirect( $text ); |
118 | | - |
119 | 127 | # process if title object is valid and not special:userlogout |
120 | 128 | if( $rt ) { |
121 | 129 | if( $rt->getInterwiki() != '' ) { |
— | — | @@ -144,7 +152,6 @@ |
145 | 153 | return $rt; |
146 | 154 | } |
147 | 155 | } |
148 | | - |
149 | 156 | // No or invalid redirect |
150 | 157 | return false; |
151 | 158 | } |
Index: trunk/phase3/includes/Wiki.php |
— | — | @@ -43,7 +43,7 @@ |
44 | 44 | * Initialization of ... everything |
45 | 45 | * Performs the request too |
46 | 46 | * |
47 | | - * @param $title Title |
| 47 | + * @param $title Title ($wgTitle) |
48 | 48 | * @param $article Article |
49 | 49 | * @param $output OutputPage |
50 | 50 | * @param $user User |
— | — | @@ -264,7 +264,7 @@ |
265 | 265 | * Initialize the object to be known as $wgArticle for "standard" actions |
266 | 266 | * Create an Article object for the page, following redirects if needed. |
267 | 267 | * |
268 | | - * @param $title Title |
| 268 | + * @param $title Title ($wgTitle) |
269 | 269 | * @param $request WebRequest |
270 | 270 | * @return mixed an Article, or a string to redirect to another URL |
271 | 271 | */ |
— | — | @@ -280,18 +280,22 @@ |
281 | 281 | // Check for redirects ... |
282 | 282 | $file = $title->getNamespace() == NS_IMAGE ? $article->getFile() : null; |
283 | 283 | if( ( $action == 'view' || $action == 'render' ) // ... for actions that show content |
284 | | - && !$request->getVal( 'oldid' ) && // ... and are not old revisions |
| 284 | + && !$request->getVal( 'oldid' ) && // ... and are not old revisions |
285 | 285 | $request->getVal( 'redirect' ) != 'no' && // ... unless explicitly told not to |
286 | | - // ... and the article is not an image page with associated file |
287 | | - !( is_object( $file ) && $file->exists() && |
288 | | - !$file->getRedirected() ) ) { // ... unless it is really an image redirect |
| 286 | + // ... and the article is not a non-redirect image page with associated file |
| 287 | + !( is_object( $file ) && $file->exists() && !$file->getRedirected() ) ) { |
289 | 288 | |
| 289 | + # Give extensions a change to ignore/handle redirects as needed |
| 290 | + $ignoreRedirect = $target = false; |
| 291 | + wfRunHooks( 'InitializeArticleMaybeRedirect', array( &$title, &$request, &$ignoreRedirect, &$target ) ); |
| 292 | + |
290 | 293 | $dbr = wfGetDB( DB_SLAVE ); |
291 | 294 | $article->loadPageData( $article->pageDataFromTitle( $dbr, $title ) ); |
292 | 295 | |
293 | 296 | // Follow redirects only for... redirects |
294 | | - if( $article->isRedirect() ) { |
295 | | - $target = $article->followRedirect(); |
| 297 | + if( !$ignoreRedirect && $article->isRedirect() ) { |
| 298 | + # Is the target already set by an extension? |
| 299 | + $target = $target ? $target : $article->followRedirect(); |
296 | 300 | if( is_string( $target ) ) { |
297 | 301 | if( !$this->getVal( 'DisableHardRedirects' ) ) { |
298 | 302 | // we'll need to redirect |
— | — | @@ -303,9 +307,7 @@ |
304 | 308 | // Rewrite environment to redirected article |
305 | 309 | $rarticle = self::articleFromTitle( $target ); |
306 | 310 | $rarticle->loadPageData( $rarticle->pageDataFromTitle( $dbr, $target ) ); |
307 | | - if ( $rarticle->getTitle()->exists() || |
308 | | - ( is_object( $file ) && |
309 | | - !$file->isLocal() ) ) { |
| 311 | + if ( $rarticle->exists() || ( is_object( $file ) && !$file->isLocal() ) ) { |
310 | 312 | $rarticle->setRedirectedFrom( $title ); |
311 | 313 | $article = $rarticle; |
312 | 314 | $title = $target; |
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php |
— | — | @@ -316,12 +316,14 @@ |
317 | 317 | # Visibility - experimental |
318 | 318 | $wgHooks['userCan'][] = 'FlaggedRevs::userCanView'; |
319 | 319 | |
320 | | -# Main hooks, overrides pages content, adds tags, sets tabs and permalink |
| 320 | +# Override current revision, add patrol links, set cache... |
| 321 | +$wgHooks['ArticleViewHeader'][] = 'FlaggedRevs::onArticleViewHeader'; |
| 322 | +# Override redirect behavoir... |
| 323 | +$wgHooks['InitializeArticleMaybeRedirect'][] = 'FlaggedRevs::overrideRedirect'; |
| 324 | +# Sets tabs and permalink |
321 | 325 | $wgHooks['SkinTemplateTabs'][] = 'FlaggedRevs::setActionTabs'; |
322 | 326 | # Change last-modified footer |
323 | 327 | $wgHooks['SkinTemplateOutputPageBeforeExec'][] = 'FlaggedRevs::setLastModified'; |
324 | | -# Override current revision, add patrol links, set cache... |
325 | | -$wgHooks['ArticleViewHeader'][] = 'FlaggedRevs::onArticleViewHeader'; |
326 | 328 | # Add page notice |
327 | 329 | $wgHooks['SkinTemplateBuildNavUrlsNav_urlsAfterPermalink'][] = 'FlaggedRevs::setPermaLink'; |
328 | 330 | # Add tags do edit view |
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.class.php |
— | — | @@ -2010,6 +2010,26 @@ |
2011 | 2011 | return true; |
2012 | 2012 | } |
2013 | 2013 | |
| 2014 | + static function overrideRedirect( &$title, $request, &$ignoreRedirect, &$target ) { |
| 2015 | + if( $request->getVal( 'stableid' ) ) { |
| 2016 | + $ignoreRedirect = true; |
| 2017 | + } else { |
| 2018 | + # Get an instance on the title ($wgTitle) and save to process cache |
| 2019 | + $flaggedArticle = FlaggedArticle::getTitleInstance( $title ); |
| 2020 | + $srev = $flaggedArticle->getStableRev( true ); |
| 2021 | + if( $srev ) { |
| 2022 | + $text = $srev->getRevText(); |
| 2023 | + $redirect = Article::followRedirectText( $text ); |
| 2024 | + if( $redirect ) { |
| 2025 | + $target = $redirect; |
| 2026 | + } else { |
| 2027 | + $ignoreRedirect = true; |
| 2028 | + } |
| 2029 | + } |
| 2030 | + } |
| 2031 | + return true; |
| 2032 | + } |
| 2033 | + |
2014 | 2034 | static function setPermaLink( $skin, &$navUrls, &$revId, &$id ) { |
2015 | 2035 | $fa = FlaggedArticle::getGlobalInstance(); |
2016 | 2036 | if ( $fa ) { |