X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FWiki.php;h=4fa421a69a81c14866dbc8bf31eca02191914a33;hb=b342a81da0454cc39a2e404f7208c8cbb2eed3c6;hp=133d511585cdee926205d5e1b11cdc5ea9b0478a;hpb=8aa182976cc275acd050999d99b59c847bd5c581;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Wiki.php b/includes/Wiki.php index 133d511585..4fa421a69a 100644 --- a/includes/Wiki.php +++ b/includes/Wiki.php @@ -25,7 +25,7 @@ class MediaWiki { } /** - * Retieves key/value pairs to circumvent global variables + * Retrieves key/value pairs to circumvent global variables * Note that keys are case-insensitive! */ function getVal( $key, $default = '' ) { @@ -51,7 +51,7 @@ class MediaWiki { } elseif( is_string( $article ) ) { $output->redirect( $article ); } else { - wfDebugDieBacktrace( "Shouldn't happen: MediaWiki::initializeArticle() returned neither an object nor a URL" ); + throw new MWException( "Shouldn't happen: MediaWiki::initializeArticle() returned neither an object nor a URL" ); } } wfProfileOut( 'MediaWiki::initialize' ); @@ -71,7 +71,7 @@ class MediaWiki { if ( '' == $title && 'delete' != $action ) { - $ret = Title::newFromText( wfMsgForContent( 'mainpage' ) ); + $ret = Title::newMainPage(); } elseif ( $curid = $request->getInt( 'curid' ) ) { # URLs like this are generated by RC, because rc_title isn't always accurate $ret = Title::newFromID( $curid ); @@ -99,7 +99,7 @@ class MediaWiki { if( !is_null( $search ) && $search !== '' ) { // Compatibility with old search URLs which didn't use Special:Search // Do this above the read whitelist check for security... - $title = Title::makeTitle( NS_SPECIAL, 'Search' ); + $title = SpecialPage::getTitleFor( 'Search' ); } $this->setVal( 'Search', $search ); @@ -125,11 +125,12 @@ class MediaWiki { $action = $this->getVal('Action'); if( !$this->getVal('DisableInternalSearch') && !is_null( $search ) && $search !== '' ) { require_once( 'includes/SpecialSearch.php' ); - $title = Title::makeTitle( NS_SPECIAL, 'Search' ); + $title = SpecialPage::getTitleFor( 'Search' ); wfSpecialSearch(); } else if( !$title or $title->getDBkey() == '' ) { - $title = Title::newFromText( wfMsgForContent( 'badtitle' ) ); - $output->errorpage( 'badtitle', 'badtitletext' ); + $title = SpecialPage::getTitleFor( 'Badtitle' ); + # Die now before we mess up $wgArticle and the skin stops working + throw new ErrorPageError( 'badtitle', 'badtitletext' ); } else if ( $title->getInterwiki() != '' ) { if( $rdfrom = $request->getVal( 'rdfrom' ) ) { $url = $title->getFullURL( 'rdfrom=' . urlencode( $rdfrom ) ); @@ -140,16 +141,43 @@ class MediaWiki { if ( !preg_match( '/^' . preg_quote( $this->getVal('Server'), '/' ) . '/', $url ) && $title->isLocal() ) { $output->redirect( $url ); } else { - $title = Title::newFromText( wfMsgForContent( 'badtitle' ) ); - $output->errorpage( 'badtitle', 'badtitletext' ); + $title = SpecialPage::getTitleFor( 'Badtitle' ); + throw new ErrorPageError( 'badtitle', 'badtitletext' ); } } else if ( ( $action == 'view' ) && (!isset( $this->GET['title'] ) || $title->getPrefixedDBKey() != $this->GET['title'] ) && !count( array_diff( array_keys( $this->GET ), array( 'action', 'title' ) ) ) ) { - /* Redirect to canonical url, make it a 301 to allow caching */ - $output->setSquidMaxage( 1200 ); - $output->redirect( $title->getFullURL(), '301'); + $targetUrl = $title->getFullURL(); + // Redirect to canonical url, make it a 301 to allow caching + global $wgServer, $wgUsePathInfo; + if( isset( $_SERVER['REQUEST_URI'] ) && + $targetUrl == $wgServer . $_SERVER['REQUEST_URI'] ) { + $message = "Redirect loop detected!\n\n" . + "This means the wiki got confused about what page was " . + "requested; this sometimes happens when moving a wiki " . + "to a new server or changing the server configuration.\n\n"; + + if( $wgUsePathInfo ) { + $message .= "The wiki is trying to interpret the page " . + "title from the URL path portion (PATH_INFO), which " . + "sometimes fails depending on the web server. Try " . + "setting \"\$wgUsePathInfo = false;\" in your " . + "LocalSettings.php, or check that \$wgArticlePath " . + "is correct."; + } else { + $message .= "Your web server was detected as possibly not " . + "supporting URL path components (PATH_INFO) correctly; " . + "check your LocalSettings.php for a customized " . + "\$wgArticlePath setting and/or toggle \$wgUsePathInfo " . + "to true."; + } + wfHttpError( 500, "Internal error", $message ); + return false; + } else { + $output->setSquidMaxage( 1200 ); + $output->redirect( $targetUrl, '301'); + } } else if ( NS_SPECIAL == $title->getNamespace() ) { /* actions that need to be made when we have a special pages */ SpecialPage::executePath( $title ); @@ -169,6 +197,12 @@ class MediaWiki { * @return Article */ function articleFromTitle( $title ) { + $article = null; + wfRunHooks('ArticleFromTitle', array( &$title, &$article ) ); + if ( $article ) { + return $article; + } + if( NS_MEDIA == $title->getNamespace() ) { // FIXME: where should this go? $title = Title::makeTitle( NS_IMAGE, $title->getDBkey() ); @@ -176,10 +210,8 @@ class MediaWiki { switch( $title->getNamespace() ) { case NS_IMAGE: - require_once( 'includes/ImagePage.php' ); return new ImagePage( $title ); case NS_CATEGORY: - require_once( 'includes/CategoryPage.php' ); return new CategoryPage( $title ); default: return new Article( $title ); @@ -202,17 +234,12 @@ class MediaWiki { $article = $this->articleFromTitle( $title ); // Namespace might change when using redirects - if( $action == 'view' && !$request->getVal( 'oldid' ) && + if( $action == 'view' && !$request->getVal( 'oldid' ) && $request->getVal( 'redirect' ) != 'no' ) { - $dbr=&wfGetDB(DB_SLAVE); - - // If we don't check for existance we'll get "Trying to get - // property of non-object" E_NOTICE in Article::loadPageData() when - // viewing a page that does not exist - if ( $article->exists() ) { - $article->loadPageData($article->pageDataFromTitle($dbr,$title)); - } - + + $dbr =& wfGetDB(DB_SLAVE); + $article->loadPageData($article->pageDataFromTitle($dbr, $title)); + /* Follow redirects only for... redirects */ if ($article->mIsRedirect) { $target = $article->followRedirect(); @@ -264,19 +291,25 @@ class MediaWiki { */ function doUpdates ( &$updates ) { wfProfileIn( 'MediaWiki::doUpdates' ); + $dbw =& wfGetDB( DB_MASTER ); foreach( $updates as $up ) { $up->doUpdate(); + + # Commit after every update to prevent lock contention + if ( $dbw->trxLevel() ) { + $dbw->commit(); + } } - wfProfileOut( 'MediaWiki::doUpdates' ); + wfProfileOut( 'MediaWiki::doUpdates' ); } /** * Do a job from the job queue */ function doJobs() { - global $wgJobLogFile, $wgJobRunRate; + global $wgJobRunRate; - if ( $wgJobRunRate <= 0 ) { + if ( $wgJobRunRate <= 0 || wfReadOnly() ) { return; } if ( $wgJobRunRate < 1 ) { @@ -289,16 +322,18 @@ class MediaWiki { $n = intval( $wgJobRunRate ); } - require_once( 'JobQueue.php' ); - while ( $n-- && false != ($job = Job::pop())) { $output = $job->toString() . "\n"; - if ( !$job->run() ) { - $output .= "Error: " . $job->getLastError() . "\n"; - } - if ( $wgJobLogFile ) { - error_log( $output, 3, $wgJobLogFile ); + $t = -wfTime(); + $success = $job->run(); + $t += wfTime(); + $t = round( $t*1000 ); + if ( !$success ) { + $output .= "Error: " . $job->getLastError() . ", Time: $t ms\n"; + } else { + $output .= "Success, Time: $t ms\n"; } + wfDebugLog( 'jobqueue', $output ); } } @@ -306,8 +341,7 @@ class MediaWiki { * Ends this task peacefully */ function restInPeace ( &$loadBalancer ) { - wfProfileClose(); - logProfilingData(); + wfLogProfilingData(); $loadBalancer->closeAll(); wfDebug( "Request ended normally\n" ); } @@ -339,7 +373,6 @@ class MediaWiki { case 'unprotect': case 'info': case 'markpatrolled': - case 'validate': case 'render': case 'deletetrackback': case 'purge': @@ -381,11 +414,9 @@ class MediaWiki { $oldid = $request->getVal( 'oldid' ); if( !$this->getVal( 'UseExternalEditor' ) || $action=='submit' || $internal || $section || $oldid || ( !$user->getOption( 'externaleditor' ) && !$external ) ) { - require_once( 'includes/EditPage.php' ); $editor = new EditPage( $article ); $editor->submit(); } elseif( $this->getVal( 'UseExternalEditor' ) && ( $external || $user->getOption( 'externaleditor' ) ) ) { - require_once( 'includes/ExternalEdit.php' ); $mode = $request->getVal( 'mode' ); $extedit = new ExternalEdit( $article, $mode ); $extedit->edit(); @@ -395,18 +426,16 @@ class MediaWiki { if( $_SERVER['REQUEST_URI'] == $title->getInternalURL( 'action=history' ) ) { $output->setSquidMaxage( $this->getVal( 'SquidMaxage' ) ); } - require_once( 'includes/PageHistory.php' ); $history = new PageHistory( $article ); $history->history(); break; case 'raw': - require_once( 'includes/RawPage.php' ); $raw = new RawPage( $article ); $raw->view(); break; default: if( wfRunHooks( 'UnknownAction', array( $action, $article ) ) ) { - $output->errorpage( 'nosuchaction', 'nosuchactiontext' ); + $output->showErrorPage( 'nosuchaction', 'nosuchactiontext' ); } } wfProfileOut( 'MediaWiki::performAction' );