r37006 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r37005‎ | r37006 | r37007 >
Date:20:37, 3 July 2008
Author:aaron
Status:old
Tags:
Comment:
Make redirects work properly with flagging (bug 14714)
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.class.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.php (modified) (history)
  • /trunk/phase3/docs/hooks.txt (modified) (history)
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/Wiki.php (modified) (history)

Diff [purge]

Index: trunk/phase3/docs/hooks.txt
@@ -698,6 +698,12 @@
699699 &$file: File object
700700 &$displayFile: displayed File object
701701
 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+
702708 'InitPreferencesForm': called at the end of PreferencesForm's constructor
703709 $form: the PreferencesForm
704710 $request: the web request to initialized from
Index: trunk/phase3/includes/Article.php
@@ -111,10 +111,18 @@
112112 *
113113 * @return mixed false, Title of in-wiki target, or string with URL
114114 */
115 - function followRedirect() {
 115+ public function followRedirect() {
116116 $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 ) {
117126 $rt = Title::newFromRedirect( $text );
118 -
119127 # process if title object is valid and not special:userlogout
120128 if( $rt ) {
121129 if( $rt->getInterwiki() != '' ) {
@@ -144,7 +152,6 @@
145153 return $rt;
146154 }
147155 }
148 -
149156 // No or invalid redirect
150157 return false;
151158 }
Index: trunk/phase3/includes/Wiki.php
@@ -43,7 +43,7 @@
4444 * Initialization of ... everything
4545 * Performs the request too
4646 *
47 - * @param $title Title
 47+ * @param $title Title ($wgTitle)
4848 * @param $article Article
4949 * @param $output OutputPage
5050 * @param $user User
@@ -264,7 +264,7 @@
265265 * Initialize the object to be known as $wgArticle for "standard" actions
266266 * Create an Article object for the page, following redirects if needed.
267267 *
268 - * @param $title Title
 268+ * @param $title Title ($wgTitle)
269269 * @param $request WebRequest
270270 * @return mixed an Article, or a string to redirect to another URL
271271 */
@@ -280,18 +280,22 @@
281281 // Check for redirects ...
282282 $file = $title->getNamespace() == NS_IMAGE ? $article->getFile() : null;
283283 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
285285 $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() ) ) {
289288
 289+ # Give extensions a change to ignore/handle redirects as needed
 290+ $ignoreRedirect = $target = false;
 291+ wfRunHooks( 'InitializeArticleMaybeRedirect', array( &$title, &$request, &$ignoreRedirect, &$target ) );
 292+
290293 $dbr = wfGetDB( DB_SLAVE );
291294 $article->loadPageData( $article->pageDataFromTitle( $dbr, $title ) );
292295
293296 // 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();
296300 if( is_string( $target ) ) {
297301 if( !$this->getVal( 'DisableHardRedirects' ) ) {
298302 // we'll need to redirect
@@ -303,9 +307,7 @@
304308 // Rewrite environment to redirected article
305309 $rarticle = self::articleFromTitle( $target );
306310 $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() ) ) {
310312 $rarticle->setRedirectedFrom( $title );
311313 $article = $rarticle;
312314 $title = $target;
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php
@@ -316,12 +316,14 @@
317317 # Visibility - experimental
318318 $wgHooks['userCan'][] = 'FlaggedRevs::userCanView';
319319
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
321325 $wgHooks['SkinTemplateTabs'][] = 'FlaggedRevs::setActionTabs';
322326 # Change last-modified footer
323327 $wgHooks['SkinTemplateOutputPageBeforeExec'][] = 'FlaggedRevs::setLastModified';
324 -# Override current revision, add patrol links, set cache...
325 -$wgHooks['ArticleViewHeader'][] = 'FlaggedRevs::onArticleViewHeader';
326328 # Add page notice
327329 $wgHooks['SkinTemplateBuildNavUrlsNav_urlsAfterPermalink'][] = 'FlaggedRevs::setPermaLink';
328330 # Add tags do edit view
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.class.php
@@ -2010,6 +2010,26 @@
20112011 return true;
20122012 }
20132013
 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+
20142034 static function setPermaLink( $skin, &$navUrls, &$revId, &$id ) {
20152035 $fa = FlaggedArticle::getGlobalInstance();
20162036 if ( $fa ) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r37014Revert r37006 -- causes fatal errors:...brion00:04, 4 July 2008
r37035Re-commit fixed r37006aaron09:38, 4 July 2008

Status & tagging log