Wikia code/includes/Wiki.php

From mediawiki.org
--- D:\Programming\SVN\mediawiki\branches\REL1_16\phase3\includes\Wiki.php	2011-07-18 22:31:28.188476600 +0100
+++ D:\Programming\SVN\wikia\trunk\includes\Wiki.php	2011-08-17 15:28:46.547851600 +0100
@@ -75,6 +75,12 @@
 				throw new MWException( "Shouldn't happen: MediaWiki::initializeArticle() returned neither an object nor a URL" );
 			}
 		}
+
+		// Wikia change - begin
+		// BugId:7282
+		wfRunHooks( 'AfterInitialize', array( &$title, &$article, &$output, &$user, $request, $this ) );
+		// Wikia change - end
+
 		wfProfileOut( __METHOD__ );
 	}
 
@@ -115,6 +121,14 @@
 			$ret = Title::newFromID( $curid );
 		} elseif( $title == '' && $action != 'delete' ) {
 			$ret = Title::newMainPage();
+
+			/* Wikia change begin - @author: Macbre */
+			/* Wysiwyg: Add hook to allow modification of page user is redirected to when title is not specified in URL */
+			if(!$wgRequest->getInt( 'diff' ) && !$wgRequest->getInt( 'oldid' )) {
+				wfRunHooks( 'InitialQueriesMainPage', array( &$ret ) );
+			}
+			/* Wikia change end */
+
 		} else {
 			$ret = Title::newFromURL( $title );
 			// check variant links so that interwiki links don't have to worry
@@ -133,6 +147,12 @@
 				$ret = $rev ? $rev->getTitle() : $ret;
 			}
 		}
+
+		/* Wikia change begin - @author: nAndy */
+		/* Add hook to allow modification of page user is redirected to when title is not specified in URL */
+		wfRunHooks( 'AfterCheckInitialQueries', array( &$title, &$action, &$ret ) );
+		/* Wikia change end */
+
 		return $ret;
 	}
 
@@ -312,12 +332,15 @@
 		}
 		// Namespace might change when using redirects
 		// Check for redirects ...
-		$file = ($title->getNamespace() == NS_FILE) ? $article->getFile() : null;
+		// ... and check that we still have ImagePage instance here (might be replaced by 'ArticleFromTitle' hook above) - bugId:9286 (ADi)
+		$file = (($title->getNamespace() == NS_FILE) && ($article instanceof ImagePage)) ? $article->getFile() : null;
 		if( ( $action == 'view' || $action == 'render' ) 	// ... for actions that show content
 			&& !$request->getVal( 'oldid' ) &&    // ... and are not old revisions
-			$request->getVal( 'redirect' ) != 'no' &&	// ... unless explicitly told not to
+			$request->getVal( 'redirect' ) != 'no' 	// ... unless explicitly told not to
 			// ... and the article is not a non-redirect image page with associated file
-			!( is_object( $file ) && $file->exists() && !$file->getRedirected() ) )
+			#&& !( is_object( $file ) && $file->exists() && !$file->getRedirected() ) )
+			# The line above commented out to enable on-click image redirects (trac #2789) --TOR
+			)
 		{
 			# Give extensions a change to ignore/handle redirects as needed
 			$ignoreRedirect = $target = false;
@@ -340,6 +363,10 @@
 						return $target;
 					}
 				}
+
+				// Originally implemented by Nick for HardRedirectsWithJSText Extension (which is now deprecated and deleted)
+				wfRunHooks('BeforeRedirect', array( &$title, &$target ) );
+
 				if( is_object($target) ) {
 					// Rewrite environment to redirected article
 					$rarticle = self::articleFromTitle( $target );
@@ -477,6 +504,15 @@
 			$action = 'nosuchaction';
 		}
 
+		/* Wikia change begin - @author: macbre */
+		/* fallback selected actions to "view" (BugId:9964) */
+		global $wgDisabledActionsWithViewFallback;
+		if ( in_array( $action, $wgDisabledActionsWithViewFallback ) ) {
+			$action = 'view';
+			$request->setVal('action', $action);
+		}
+		/* Wikia change end */
+
 		# Workaround for bug #20966: inability of IE to provide an action dependent
 		# on which submit button is clicked.
 		if ( $action === 'historysubmit' ) {
@@ -550,6 +586,10 @@
 					if( !$this->getVal( 'UseExternalEditor' ) || $action=='submit' || $internal ||
 					   $section || $oldid || ( !$user->getOption( 'externaleditor' ) && !$external ) ) {
 						$editor = new EditPage( $article );
+						/* Wikia change begin - @author: macbre */
+						/* Allow extensions to change EditPage class used for rendering edit pages */
+						wfRunHooks('AlternateEditPageClass', array(&$editor));
+						/* Wikia change - end */
 						$editor->submit();
 					} elseif( $this->getVal( 'UseExternalEditor' ) && ( $external || $user->getOption( 'externaleditor' ) ) ) {
 						$mode = $request->getVal( 'mode' );