From bda0b8e104f5463d19806c5a2b7fe98edfe7a15f Mon Sep 17 00:00:00 2001 From: Domas Mituzas Date: Thu, 1 Jun 2006 07:22:49 +0000 Subject: [PATCH] Use AutoLoader to load classes: * remove require_once() throughout whole code, yet left in few places * move global functions in HttpUtils, ProxyTools, Credits to class methods * php5 only: __autoload() now used, combined with class->file map and require() * move initialization of $wgValidSkinNames to Skin::getSkinNames() * few more changes that will surely break stuff. --- includes/AjaxDispatcher.php | 13 - includes/AjaxFunctions.php | 2 - includes/Article.php | 11 - includes/AutoLoader.php | 219 +++++++++++++++++ includes/Block.php | 8 +- includes/CacheManager.php | 5 - includes/CategoryPage.php | 3 - includes/ChangesList.php | 1 - includes/Credits.php | 229 +++++++++--------- includes/Database.php | 5 - includes/DatabaseOracle.php | 5 - includes/DatabasePostgreSQL.php | 5 - includes/DifferenceEngine.php | 3 - includes/EditPage.php | 4 +- includes/Export.php | 3 - includes/ExternalStoreDB.php | 2 - includes/GlobalFunctions.php | 30 ++- includes/HistoryBlob.php | 21 +- includes/HttpFunctions.php | 143 +++++------ includes/Image.php | 3 - includes/ImagePage.php | 6 +- includes/LinksUpdate.php | 2 - includes/LoadBalancer.php | 11 +- includes/LogPage.php | 1 - includes/Math.php | 16 +- includes/MessageCache.php | 3 - includes/ObjectCache.php | 140 ++++++----- includes/OutputPage.php | 5 +- includes/PageHistory.php | 3 - includes/Parser.php | 9 +- includes/ParserXML.php | 3 - includes/Profiling.php | 2 - includes/ProxyTools.php | 384 +++++++++++++++--------------- includes/QueryPage.php | 5 - includes/RawPage.php | 3 - includes/RecentChange.php | 8 +- includes/Revision.php | 6 - includes/SearchEngine.php | 2 - includes/SearchMySQL.php | 3 - includes/SearchMySQL4.php | 2 - includes/SearchTsearch2.php | 3 - includes/SearchUpdate.php | 1 - includes/Setup.php | 34 +-- includes/Skin.php | 49 ++-- includes/SkinTemplate.php | 3 +- includes/SpecialBlockme.php | 2 +- includes/SpecialPage.php | 4 + includes/SpecialPreferences.php | 4 +- includes/SpecialRecentchanges.php | 7 - includes/SpecialUpload.php | 2 - includes/SpecialUserlogin.php | 4 +- includes/SpecialVersion.php | 2 +- includes/Title.php | 7 +- includes/UpdateClasses.php | 9 - includes/User.php | 21 +- includes/WebRequest.php | 1 - includes/Wiki.php | 11 +- 57 files changed, 779 insertions(+), 714 deletions(-) create mode 100644 includes/AutoLoader.php diff --git a/includes/AjaxDispatcher.php b/includes/AjaxDispatcher.php index ae0d3e3470..f5af30b37e 100644 --- a/includes/AjaxDispatcher.php +++ b/includes/AjaxDispatcher.php @@ -1,18 +1,5 @@ setPageTitle( $this->mTitle->getPrefixedText() ); $de = new DifferenceEngine( $this->mTitle, $oldid, $diff, $rcid ); @@ -1233,7 +1226,6 @@ class Article { Article::onArticleCreate( $this->mTitle ); if(!$suppressRC) { - require_once( 'RecentChange.php' ); $rcid = RecentChange::notifyNew( $now, $this->mTitle, $isminor, $wgUser, $summary, 'default', '', strlen( $text ), $revisionId ); # Mark as patrolled if the user can and has the option set @@ -1440,7 +1432,6 @@ class Article { $dbw->rollback(); } else { # Update recentchanges and purge cache and whatnot - require_once( 'RecentChange.php' ); $bot = (int)($wgUser->isBot() || $forceBot); $rcid = RecentChange::notifyEdit( $now, $this->mTitle, $isminor, $wgUser, $summary, $lastRevision, $this->getTimestamp(), $bot, '', $oldsize, $newsize, @@ -1564,7 +1555,6 @@ class Article { $rcid = $wgRequest->getVal( 'rcid' ); if ( !is_null ( $rcid ) ) { if( wfRunHooks( 'MarkPatrolled', array( &$rcid, &$wgUser, false ) ) ) { - require_once( 'RecentChange.php' ); RecentChange::markPatrolled( $rcid ); wfRunHooks( 'MarkPatrolledComplete', array( &$rcid, &$wgUser, false ) ); $wgOut->setPagetitle( wfMsg( 'markedaspatrolled' ) ); @@ -1679,7 +1669,6 @@ class Article { * action=protect handler */ function protect() { - require_once 'ProtectionForm.php'; $form = new ProtectionForm( $this ); $form->show(); } diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php new file mode 100644 index 0000000000..8c372f72fb --- /dev/null +++ b/includes/AutoLoader.php @@ -0,0 +1,219 @@ + 'AjaxDispatcher.php', + 'AjaxCachePolicy' => 'AjaxFunctions.php', + 'Article' => 'Article.php', + 'AuthPlugin' => 'AuthPlugin.php', + 'BagOStuff' => 'BagOStuff.php', + 'HashBagOStuff' => 'BagOStuff.php', + 'SqlBagOStuff' => 'BagOStuff.php', + 'MediaWikiBagOStuff' => 'BagOStuff.php', + 'TurckBagOStuff' => 'BagOStuff.php', + 'APCBagOStuff' => 'BagOStuff.php', + 'eAccelBagOStuff' => 'BagOStuff.php', + 'Block' => 'Block.php', + 'CacheManager' => 'CacheManager.php', + 'CategoryPage' => 'CategoryPage.php', + 'Categoryfinder' => 'Categoryfinder.php', + 'RCCacheEntry' => 'ChangesList.php', + 'ChangesList' => 'ChangesList.php', + 'OldChangesList' => 'ChangesList.php', + 'EnhancedChangesList' => 'ChangesList.php', + 'DBObject' => 'Database.php', + 'Database' => 'Database.php', + 'DatabaseMysql' => 'Database.php', + 'ResultWrapper' => 'Database.php', + 'OracleBlob' => 'DatabaseOracle.php', + 'DatabaseOracle' => 'DatabaseOracle.php', + 'DatabasePgsql' => 'DatabasePostgreSQL.php', + 'DatabasePostgreSQL' => 'DatabasePostgreSQL.php', + 'DateFormatter' => 'DateFormatter.php', + 'DifferenceEngine' => 'DifferenceEngine.php', + '_DiffOp' => 'DifferenceEngine.php', + '_DiffOp_Copy' => 'DifferenceEngine.php', + '_DiffOp_Delete' => 'DifferenceEngine.php', + '_DiffOp_Add' => 'DifferenceEngine.php', + '_DiffOp_Change' => 'DifferenceEngine.php', + '_DiffEngine' => 'DifferenceEngine.php', + 'Diff' => 'DifferenceEngine.php', + 'MappedDiff' => 'DifferenceEngine.php', + 'DiffFormatter' => 'DifferenceEngine.php', + '_HWLDF_WordAccumulator' => 'DifferenceEngine.php', + 'WordLevelDiff' => 'DifferenceEngine.php', + 'TableDiffFormatter' => 'DifferenceEngine.php', + 'EditPage' => 'EditPage.php', + 'Exif' => 'Exif.php', + 'FormatExif' => 'Exif.php', + 'WikiExporter' => 'Export.php', + 'XmlDumpWriter' => 'Export.php', + 'DumpOutput' => 'Export.php', + 'DumpFileOutput' => 'Export.php', + 'DumpPipeOutput' => 'Export.php', + 'DumpGZipOutput' => 'Export.php', + 'DumpBZip2Output' => 'Export.php', + 'Dump7ZipOutput' => 'Export.php', + 'DumpFilter' => 'Export.php', + 'DumpNotalkFilter' => 'Export.php', + 'DumpNamespaceFilter' => 'Export.php', + 'DumpLatestFilter' => 'Export.php', + 'DumpMultiWriter' => 'Export.php', + 'ExternalEdit' => 'ExternalEdit.php', + 'ExternalStore' => 'ExternalStore.php', + 'ExternalStoreDB' => 'ExternalStoreDB.php', + 'ExternalStoreHttp' => 'ExternalStoreHttp.php', + 'FakeTitle' => 'FakeTitle.php', + 'FeedItem' => 'Feed.php', + 'ChannelFeed' => 'Feed.php', + 'RSSFeed' => 'Feed.php', + 'AtomFeed' => 'Feed.php', + 'ReplacerCallback' => 'GlobalFunctions.php', + 'Group' => 'Group.php', + 'HTMLForm' => 'HTMLForm.php', + 'HistoryBlob' => 'HistoryBlob.php', + 'ConcatenatedGzipHistoryBlob' => 'HistoryBlob.php', + 'HistoryBlobStub' => 'HistoryBlob.php', + 'HistoryBlobCurStub' => 'HistoryBlob.php', + 'Image' => 'Image.php', + 'ThumbnailImage' => 'Image.php', + 'ImageGallery' => 'ImageGallery.php', + 'ImagePage' => 'ImagePage.php', + 'ImageHistoryList' => 'ImagePage.php', + 'ImageRemote' => 'ImageRemote.php', + 'Job' => 'JobQueue.php', + 'Licenses' => 'Licenses.php', + 'License' => 'Licenses.php', + 'LinkBatch' => 'LinkBatch.php', + 'LinkCache' => 'LinkCache.php', + 'LinkFilter' => 'LinkFilter.php', + 'Linker' => 'Linker.php', + 'LinksUpdate' => 'LinksUpdate.php', + 'LoadBalancer' => 'LoadBalancer.php', + 'LogPage' => 'LogPage.php', + 'MacBinary' => 'MacBinary.php', + 'MagicWord' => 'MagicWord.php', + 'MathRenderer' => 'Math.php', + 'MessageCache' => 'MessageCache.php', + 'MimeMagic' => 'MimeMagic.php', + 'Namespace' => 'Namespace.php', + 'FakeMemCachedClient' => 'ObjectCache.php', + 'ObjectCacheManager' => 'ObjectCache.php', + 'MemCachedClientforWiki' => 'ObjectCache.php', + 'OutputPage' => 'OutputPage.php', + 'PageHistory' => 'PageHistory.php', + 'Parser' => 'Parser.php', + 'ParserOutput' => 'Parser.php', + 'ParserOptions' => 'Parser.php', + 'ParserCache' => 'ParserCache.php', + 'element' => 'ParserXML.php', + 'xml2php' => 'ParserXML.php', + 'ParserXML' => 'ParserXML.php', + 'ProfilerSimple' => 'ProfilerSimple.php', + 'ProfilerSimpleUDP' => 'ProfilerSimpleUDP.php', + 'Profiler' => 'Profiling.php', + 'ProxyTools' => 'ProxyTools.php', + 'ProtectionForm' => 'ProtectionForm.php', + 'QueryPage' => 'QueryPage.php', + 'PageQueryPage' => 'QueryPage.php', + 'RawPage' => 'RawPage.php', + 'RecentChange' => 'RecentChange.php', + 'Revision' => 'Revision.php', + 'Sanitizer' => 'Sanitizer.php', + 'SearchEngine' => 'SearchEngine.php', + 'SearchResultSet' => 'SearchEngine.php', + 'SearchResult' => 'SearchEngine.php', + 'SearchEngineDummy' => 'SearchEngine.php', + 'SearchMySQL' => 'SearchMySQL.php', + 'MySQLSearchResultSet' => 'SearchMySQL.php', + 'SearchMySQL4' => 'SearchMySQL4.php', + 'SearchTsearch2' => 'SearchTsearch2.php', + 'SearchUpdate' => 'SearchUpdate.php', + 'SearchUpdateMyISAM' => 'SearchUpdate.php', + 'SiteConfiguration' => 'SiteConfiguration.php', + 'SiteStatsUpdate' => 'SiteStatsUpdate.php', + 'Skin' => 'Skin.php', + 'MediaWiki_I18N' => 'SkinTemplate.php', + 'SkinTemplate' => 'SkinTemplate.php', + 'QuickTemplate' => 'SkinTemplate.php', + 'SpecialAllpages' => 'SpecialAllpages.php', + 'AncientPagesPage' => 'SpecialAncientpages.php', + 'IPBlockForm' => 'SpecialBlockip.php', + 'BookSourceList' => 'SpecialBooksources.php', + 'BrokenRedirectsPage' => 'SpecialBrokenRedirects.php', + 'CategoriesPage' => 'SpecialCategories.php', + 'EmailConfirmation' => 'SpecialConfirmemail.php', + 'contribs_finder' => 'SpecialContributions.php', + 'DeadendPagesPage' => 'SpecialDeadendpages.php', + 'DisambiguationsPage' => 'SpecialDisambiguations.php', + 'DoubleRedirectsPage' => 'SpecialDoubleRedirects.php', + 'EmailUserForm' => 'SpecialEmailuser.php', + 'GroupsForm' => 'SpecialGroups.php', + 'WikiRevision' => 'SpecialImport.php', + 'WikiImporter' => 'SpecialImport.php', + 'ImportStringSource' => 'SpecialImport.php', + 'ImportStreamSource' => 'SpecialImport.php', + 'IPUnblockForm' => 'SpecialIpblocklist.php', + 'ListredirectsPage' => 'SpecialListredirects.php', + 'ListUsersPage' => 'SpecialListusers.php', + 'DBLockForm' => 'SpecialLockdb.php', + 'LogReader' => 'SpecialLog.php', + 'LogViewer' => 'SpecialLog.php', + 'LonelyPagesPage' => 'SpecialLonelypages.php', + 'LongPagesPage' => 'SpecialLongpages.php', + 'MIMEsearchPage' => 'SpecialMIMEsearch.php', + 'MostcategoriesPage' => 'SpecialMostcategories.php', + 'MostimagesPage' => 'SpecialMostimages.php', + 'MostlinkedPage' => 'SpecialMostlinked.php', + 'MostlinkedCategoriesPage' => 'SpecialMostlinkedcategories.php', + 'MostrevisionsPage' => 'SpecialMostrevisions.php', + 'MovePageForm' => 'SpecialMovepage.php', + 'NewPagesPage' => 'SpecialNewpages.php', + 'SpecialPage' => 'SpecialPage.php', + 'UnlistedSpecialPage' => 'SpecialPage.php', + 'IncludableSpecialPage' => 'SpecialPage.php', + 'PopularPagesPage' => 'SpecialPopularpages.php', + 'PreferencesForm' => 'SpecialPreferences.php', + 'SpecialPrefixindex' => 'SpecialPrefixindex.php', + 'RevisionDeleteForm' => 'SpecialRevisiondelete.php', + 'RevisionDeleter' => 'SpecialRevisiondelete.php', + 'SpecialSearch' => 'SpecialSearch.php', + 'ShortPagesPage' => 'SpecialShortpages.php', + 'UncategorizedCategoriesPage' => 'SpecialUncategorizedcategories.php', + 'UncategorizedPagesPage' => 'SpecialUncategorizedpages.php', + 'PageArchive' => 'SpecialUndelete.php', + 'UndeleteForm' => 'SpecialUndelete.php', + 'DBUnlockForm' => 'SpecialUnlockdb.php', + 'UnusedCategoriesPage' => 'SpecialUnusedcategories.php', + 'UnusedimagesPage' => 'SpecialUnusedimages.php', + 'UnusedtemplatesPage' => 'SpecialUnusedtemplates.php', + 'UnwatchedpagesPage' => 'SpecialUnwatchedpages.php', + 'UploadForm' => 'SpecialUpload.php', + 'UploadFormMogile' => 'SpecialUploadMogile.php', + 'LoginForm' => 'SpecialUserlogin.php', + 'UserrightsForm' => 'SpecialUserrights.php', + 'SpecialVersion' => 'SpecialVersion.php', + 'WantedCategoriesPage' => 'SpecialWantedcategories.php', + 'WantedPagesPage' => 'SpecialWantedpages.php', + 'WhatLinksHerePage' => 'SpecialWhatlinkshere.php', + 'SquidUpdate' => 'SquidUpdate.php', + 'Title' => 'Title.php', + 'User' => 'User.php', + 'MailAddress' => 'UserMailer.php', + 'EmailNotification' => 'UserMailer.php', + 'WatchedItem' => 'WatchedItem.php', + 'WebRequest' => 'WebRequest.php', + 'FauxRequest' => 'WebRequest.php', + 'MediaWiki' => 'Wiki.php', + 'WikiError' => 'WikiError.php', + 'WikiErrorMsg' => 'WikiError.php', + 'WikiXmlError' => 'WikiError.php', + 'ZhClient' => 'ZhClient.php', + 'memcached' => 'memcached-client.php', + 'UtfNormal' => 'normal/UtfNormal.php' + ); + require($classes[$class_name]); +} + +?> \ No newline at end of file diff --git a/includes/Block.php b/includes/Block.php index 42969b606c..c2f8ea3d83 100644 --- a/includes/Block.php +++ b/includes/Block.php @@ -169,7 +169,7 @@ class Block { $fname = 'Block::loadRange'; - $iaddr = wfIP2Hex( $address ); + $iaddr = ProxyTools::IP2Hex( $address ); if ( $iaddr === false ) { # Invalid address return false; @@ -207,7 +207,7 @@ class Block * Determine if a given integer IPv4 address is in a given CIDR network */ function isAddressInRange( $addr, $range ) { - list( $network, $bits ) = wfParseCIDR( $range ); + list( $network, $bits ) = ProxyTools::parseCIDR( $range ); if ( $network !== false && $addr >> ( 32 - $bits ) == $network >> ( 32 - $bits ) ) { return true; } else { @@ -241,7 +241,7 @@ class Block $this->mRangeStart = ''; $this->mRangeEnd = ''; if ( $this->mUser == 0 ) { - list( $network, $bits ) = wfParseCIDR( $this->mAddress ); + list( $network, $bits ) = ProxyTools::parseCIDR( $this->mAddress ); if ( $network !== false ) { $this->mRangeStart = sprintf( '%08X', $network ); $this->mRangeEnd = sprintf( '%08X', $network + (1 << (32 - $bits)) - 1 ); @@ -431,7 +431,7 @@ class Block $parts = explode( '/', $range ); if ( count( $parts ) == 2 ) { $shift = 32 - $parts[1]; - $ipint = wfIP2Unsigned( $parts[0] ); + $ipint = ProxyTools::IP2Unsigned( $parts[0] ); $ipint = $ipint >> $shift << $shift; $newip = long2ip( $ipint ); $range = "$newip/{$parts[1]}"; diff --git a/includes/CacheManager.php b/includes/CacheManager.php index 0d116f72ad..b9e307f44f 100644 --- a/includes/CacheManager.php +++ b/includes/CacheManager.php @@ -5,11 +5,6 @@ * @subpackage Cache */ -/** - * We need the title class - */ -require_once( 'Title.php' ); - /** * Handles talking to the file cache, putting stuff in and taking it back out. * Mostly called from Article.php, also from DatabaseFunctions.php for the diff --git a/includes/CategoryPage.php b/includes/CategoryPage.php index d574ddade2..6d85e3761f 100644 --- a/includes/CategoryPage.php +++ b/includes/CategoryPage.php @@ -10,9 +10,6 @@ if( !defined( 'MEDIAWIKI' ) ) die( -1 ); global $wgCategoryMagicGallery; -if( $wgCategoryMagicGallery ) - /** */ - require_once('ImageGallery.php'); /** * @package MediaWiki diff --git a/includes/ChangesList.php b/includes/ChangesList.php index 59c410fe98..a34b496683 100644 --- a/includes/ChangesList.php +++ b/includes/ChangesList.php @@ -7,7 +7,6 @@ * - recent changes */ -require_once("RecentChange.php"); /** * @todo document * @package MediaWiki diff --git a/includes/Credits.php b/includes/Credits.php index ff33de74ce..672168736d 100644 --- a/includes/Credits.php +++ b/includes/Credits.php @@ -24,164 +24,165 @@ /** * This is largely cadged from PageHistory::history */ -function showCreditsPage($article) { - global $wgOut; +class Credits { + function showCreditsPage($article) { + global $wgOut; - $fname = 'showCreditsPage'; + $fname = 'Credits::showCreditsPage'; - wfProfileIn( $fname ); + wfProfileIn( $fname ); - $wgOut->setPageTitle( $article->mTitle->getPrefixedText() ); - $wgOut->setSubtitle( wfMsg( 'creditspage' ) ); - $wgOut->setArticleFlag( false ); - $wgOut->setArticleRelated( true ); - $wgOut->setRobotpolicy( 'noindex,nofollow' ); - - if( $article->mTitle->getArticleID() == 0 ) { - $s = wfMsg( 'nocredits' ); - } else { - $s = getCredits($article, -1); - } + $wgOut->setPageTitle( $article->mTitle->getPrefixedText() ); + $wgOut->setSubtitle( wfMsg( 'creditspage' ) ); + $wgOut->setArticleFlag( false ); + $wgOut->setArticleRelated( true ); + $wgOut->setRobotpolicy( 'noindex,nofollow' ); + + if( $article->mTitle->getArticleID() == 0 ) { + $s = wfMsg( 'nocredits' ); + } else { + $s = Credits::getCredits($article, -1); + } - $wgOut->addHTML( $s ); + $wgOut->addHTML( $s ); - wfProfileOut( $fname ); -} + wfProfileOut( $fname ); + } -function getCredits($article, $cnt, $showIfMax=true) { - $fname = 'getCredits'; - wfProfileIn( $fname ); - $s = ''; + function getCredits($article, $cnt, $showIfMax=true) { + $fname = 'Credits::getCredits'; + wfProfileIn( $fname ); + $s = ''; - if (isset($cnt) && $cnt != 0) { - $s = getAuthorCredits($article); - if ($cnt > 1 || $cnt < 0) { - $s .= ' ' . getContributorCredits($article, $cnt - 1, $showIfMax); + if (isset($cnt) && $cnt != 0) { + $s = Credits::getAuthorCredits($article); + if ($cnt > 1 || $cnt < 0) { + $s .= ' ' . Credits::getContributorCredits($article, $cnt - 1, $showIfMax); + } } + + wfProfileOut( $fname ); + return $s; } - wfProfileOut( $fname ); - return $s; -} + /** + * + */ + function getAuthorCredits($article) { + global $wgLang, $wgAllowRealName; -/** - * - */ -function getAuthorCredits($article) { - global $wgLang, $wgAllowRealName; + $last_author = $article->getUser(); - $last_author = $article->getUser(); + if ($last_author == 0) { + $author_credit = wfMsg('anonymous'); + } else { + if($wgAllowRealName) { $real_name = User::whoIsReal($last_author); } + $user_name = User::whoIs($last_author); - if ($last_author == 0) { - $author_credit = wfMsg('anonymous'); - } else { - if($wgAllowRealName) { $real_name = User::whoIsReal($last_author); } - $user_name = User::whoIs($last_author); + if (!empty($real_name)) { + $author_credit = Credits::creditLink($user_name, $real_name); + } else { + $author_credit = wfMsg('siteuser', Credits::creditLink($user_name)); + } + } - if (!empty($real_name)) { - $author_credit = creditLink($user_name, $real_name); + $timestamp = $article->getTimestamp(); + if ($timestamp) { + $d = $wgLang->timeanddate($article->getTimestamp(), true); } else { - $author_credit = wfMsg('siteuser', creditLink($user_name)); + $d = ''; } + return wfMsg('lastmodifiedby', $d, $author_credit); } - $timestamp = $article->getTimestamp(); - if ($timestamp) { - $d = $wgLang->timeanddate($article->getTimestamp(), true); - } else { - $d = ''; - } - return wfMsg('lastmodifiedby', $d, $author_credit); -} + /** + * + */ + function getContributorCredits($article, $cnt, $showIfMax) { -/** - * - */ -function getContributorCredits($article, $cnt, $showIfMax) { + global $wgLang, $wgAllowRealName; - global $wgLang, $wgAllowRealName; + $contributors = $article->getContributors(); - $contributors = $article->getContributors(); + $others_link = ''; - $others_link = ''; + # Hmm... too many to fit! - # Hmm... too many to fit! - - if ($cnt > 0 && count($contributors) > $cnt) { - $others_link = creditOthersLink($article); - if (!$showIfMax) { - return wfMsg('othercontribs', $others_link); - } else { - $contributors = array_slice($contributors, 0, $cnt); + if ($cnt > 0 && count($contributors) > $cnt) { + $others_link = Credits::creditOthersLink($article); + if (!$showIfMax) { + return wfMsg('othercontribs', $others_link); + } else { + $contributors = array_slice($contributors, 0, $cnt); + } } - } - $real_names = array(); - $user_names = array(); + $real_names = array(); + $user_names = array(); - $anon = ''; + $anon = ''; - # Sift for real versus user names + # Sift for real versus user names - foreach ($contributors as $user_parts) { - if ($user_parts[0] != 0) { - if ($wgAllowRealName && !empty($user_parts[2])) { - $real_names[] = creditLink($user_parts[1], $user_parts[2]); + foreach ($contributors as $user_parts) { + if ($user_parts[0] != 0) { + if ($wgAllowRealName && !empty($user_parts[2])) { + $real_names[] = Credits::creditLink($user_parts[1], $user_parts[2]); + } else { + $user_names[] = Credits::creditLink($user_parts[1]); + } } else { - $user_names[] = creditLink($user_parts[1]); + $anon = wfMsg('anonymous'); } - } else { - $anon = wfMsg('anonymous'); } - } - # Two strings: real names, and user names + # Two strings: real names, and user names - $real = $wgLang->listToText($real_names); - $user = $wgLang->listToText($user_names); + $real = $wgLang->listToText($real_names); + $user = $wgLang->listToText($user_names); - # "ThisSite user(s) A, B and C" + # "ThisSite user(s) A, B and C" - if (!empty($user)) { - $user = wfMsg('siteusers', $user); - } + if (!empty($user)) { + $user = wfMsg('siteusers', $user); + } - # This is the big list, all mooshed together. We sift for blank strings + # This is the big list, all mooshed together. We sift for blank strings - $fulllist = array(); + $fulllist = array(); - foreach (array($real, $user, $anon, $others_link) as $s) { - if (!empty($s)) { - array_push($fulllist, $s); + foreach (array($real, $user, $anon, $others_link) as $s) { + if (!empty($s)) { + array_push($fulllist, $s); + } } - } - # Make the list into text... + # Make the list into text... - $creds = $wgLang->listToText($fulllist); + $creds = $wgLang->listToText($fulllist); - # "Based on work by ..." + # "Based on work by ..." - return (empty($creds)) ? '' : wfMsg('othercontribs', $creds); -} + return (empty($creds)) ? '' : wfMsg('othercontribs', $creds); + } -/** - * - */ -function creditLink($user_name, $link_text = '') { - global $wgUser, $wgContLang; - $skin = $wgUser->getSkin(); - return $skin->makeLink($wgContLang->getNsText(NS_USER) . ':' . $user_name, - htmlspecialchars( (empty($link_text)) ? $user_name : $link_text )); -} + /** + * + */ + function creditLink($user_name, $link_text = '') { + global $wgUser, $wgContLang; + $skin = $wgUser->getSkin(); + return $skin->makeLink($wgContLang->getNsText(NS_USER) . ':' . $user_name, + htmlspecialchars( (empty($link_text)) ? $user_name : $link_text )); + } -/** - * - */ -function creditOthersLink($article) { - global $wgUser; - $skin = $wgUser->getSkin(); - return $skin->makeKnownLink($article->mTitle->getPrefixedText(), wfMsg('others'), 'action=credits'); + /** + * + */ + function creditOthersLink($article) { + global $wgUser; + $skin = $wgUser->getSkin(); + return $skin->makeKnownLink($article->mTitle->getPrefixedText(), wfMsg('others'), 'action=credits'); + } } - ?> diff --git a/includes/Database.php b/includes/Database.php index 2bdf610baa..904e2bd3b1 100644 --- a/includes/Database.php +++ b/includes/Database.php @@ -5,11 +5,6 @@ * @package MediaWiki */ -/** - * Depends on the CacheManager - */ -require_once( 'CacheManager.php' ); - /** See Database::makeList() */ define( 'LIST_COMMA', 0 ); define( 'LIST_AND', 1 ); diff --git a/includes/DatabaseOracle.php b/includes/DatabaseOracle.php index 226bb4d6bd..396b1c14e6 100644 --- a/includes/DatabaseOracle.php +++ b/includes/DatabaseOracle.php @@ -6,11 +6,6 @@ * @package MediaWiki */ -/** - * Depends on database - */ -require_once( 'Database.php' ); - class OracleBlob extends DBObject { function isLOB() { return true; diff --git a/includes/DatabasePostgreSQL.php b/includes/DatabasePostgreSQL.php index 130a247a85..442ec35e79 100644 --- a/includes/DatabasePostgreSQL.php +++ b/includes/DatabasePostgreSQL.php @@ -13,11 +13,6 @@ * @package MediaWiki */ -/** - * Depends on database - */ -require_once( 'Database.php' ); - /** * * @package MediaWiki diff --git a/includes/DifferenceEngine.php b/includes/DifferenceEngine.php index 58fdc76627..900d5031b2 100644 --- a/includes/DifferenceEngine.php +++ b/includes/DifferenceEngine.php @@ -5,9 +5,6 @@ * @subpackage DifferenceEngine */ -/** */ -require_once( 'Revision.php' ); - define( 'MAX_DIFF_LINE', 10000 ); define( 'MAX_DIFF_XREF_LENGTH', 10000 ); diff --git a/includes/EditPage.php b/includes/EditPage.php index 341427b63a..28b4084aba 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -725,7 +725,7 @@ class EditPage { $this->summary = ''; if ( !$this->mArticle->exists() && $this->mArticle->mTitle->getNamespace() == NS_MEDIAWIKI ) $this->textbox1 = wfMsgWeirdKey ( $this->mArticle->mTitle->getText() ) ; - wfProxyCheck(); + ProxyTools::proxyCheck(); } /** @@ -1118,7 +1118,6 @@ END $wgOut->addHTML( "\n" ); if ( $this->isConflict ) { - require_once( "DifferenceEngine.php" ); $wgOut->addWikiText( '==' . wfMsg( "yourdiff" ) . '==' ); $de = new DifferenceEngine( $this->mTitle ); @@ -1618,7 +1617,6 @@ END * @return string HTML */ function getDiff() { - require_once( 'DifferenceEngine.php' ); $oldtext = $this->mArticle->fetchContent(); $newtext = $this->mArticle->replaceSection( $this->section, $this->textbox1, $this->summary, $this->edittime ); diff --git a/includes/Export.php b/includes/Export.php index d0253eb7ae..244bbd3b84 100644 --- a/includes/Export.php +++ b/includes/Export.php @@ -22,9 +22,6 @@ * @subpackage SpecialPage */ -/** */ -require_once( 'Revision.php' ); - define( 'MW_EXPORT_FULL', 0 ); define( 'MW_EXPORT_CURRENT', 1 ); diff --git a/includes/ExternalStoreDB.php b/includes/ExternalStoreDB.php index f610df8053..70713d0107 100644 --- a/includes/ExternalStoreDB.php +++ b/includes/ExternalStoreDB.php @@ -6,8 +6,6 @@ * DB accessable external objects * */ -require_once( 'LoadBalancer.php' ); - /** @package MediaWiki */ diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index f8ef126ace..ee48231420 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -27,8 +27,6 @@ $wgTotalEdits = -1; require_once( 'DatabaseFunctions.php' ); -require_once( 'UpdateClasses.php' ); -require_once( 'LogPage.php' ); require_once( 'normal/UtfNormalUtil.php' ); require_once( 'XmlFunctions.php' ); @@ -1508,11 +1506,6 @@ function &wfGetMimeMagic() { return $wgMimeMagic; } - if (!class_exists("MimeMagic")) { - #include on demand - require_once("MimeMagic.php"); - } - $wgMimeMagic= new MimeMagic(); return $wgMimeMagic; @@ -1861,4 +1854,27 @@ class ReplacerCallback { } } +/***** DEPRECATED INTERFACES *******/ +function wfGetForwardedFor() { return ProxyTools::getForwardedFor(); } +function wfGetIP() { return ProxyTools::getIP(); } +function wfIP2Unsigned($ip) { return ProxyTools::IP2Unsigned($ip); } +function wfIP2Hex($ip) { return ProxyTools::IP2Hex($ip); } +function wfIsIPPublic($ip) { return ProxyTools::isIPPublic($ip); } +function wfProxyCheck() { return ProxyTools::proxyCheck(); } +function wfParseCIDR($range) { return ProxyTools::parseCIDR($range); } +function wfIsLocallyBlockedProxy($ip) { return ProxyTools::isLocallyBlockedProxy($ip); } + +function wfGetCache($type) { return ObjectCacheManager::getCache($type); } +function wfGetMainCache() { return ObjectCacheManager::getMainCache(); } +function wfGetMessageCacheStorage() { return ObjectCacheManager::getMessageCache(); } +function wfGetParserCacheStorage() { return ObjectCacheManager::getParserCache(); } + +function renderMath($tex) { return MathRenderer::renderMath($tex); } + +function showCreditsPage($article) { return Credits::showCreditsPage($article); } +function getCredits($article, $cnt, $showIfMax=true) { return Credits::getCredits($article,$cnt,$showIfMax); } + +function wfGetHTTP( $url, $timeout = 'default' ) { return HttpFunctions::getHTTP($url,$timeout); } +function wfIsLocalURL( $url ) { return HttpFunctions::isLocalURL($url); } + ?> diff --git a/includes/HistoryBlob.php b/includes/HistoryBlob.php index 4dee4da5d1..8679660183 100644 --- a/includes/HistoryBlob.php +++ b/includes/HistoryBlob.php @@ -167,17 +167,6 @@ class ConcatenatedGzipHistoryBlob extends HistoryBlob } } - -/** - * One-step cache variable to hold base blobs; operations that - * pull multiple revisions may often pull multiple times from - * the same blob. By keeping the last-used one open, we avoid - * redundant unserialization and decompression overhead. - */ -global $wgBlobCache; -$wgBlobCache = array(); - - /** * @package MediaWiki */ @@ -215,6 +204,15 @@ class HistoryBlobStub { function getText() { $fname = 'HistoryBlob::getText'; global $wgBlobCache; + /** + * One-step cache variable to hold base blobs; operations that + * pull multiple revisions may often pull multiple times from + * the same blob. By keeping the last-used one open, we avoid + * redundant unserialization and decompression overhead. + */ + if (!is_array($wgBlobCache)) { + $wgBlobCache = array(); + } if( isset( $wgBlobCache[$this->mOldId] ) ) { $obj = $wgBlobCache[$this->mOldId]; } else { @@ -231,7 +229,6 @@ class HistoryBlobStub { wfProfileOut( $fname ); return false; } - require_once('ExternalStore.php'); $row->old_text=ExternalStore::fetchFromUrl($url); } diff --git a/includes/HttpFunctions.php b/includes/HttpFunctions.php index fd2e87eebd..f748640412 100644 --- a/includes/HttpFunctions.php +++ b/includes/HttpFunctions.php @@ -3,88 +3,89 @@ * Various HTTP related functions */ -/** - * Get the contents of a file by HTTP - * - * if $timeout is 'default', $wgHTTPTimeout is used - */ -function wfGetHTTP( $url, $timeout = 'default' ) { - global $wgHTTPTimeout, $wgHTTPProxy, $wgVersion, $wgTitle; +class HttpFunctions { + /** + * Get the contents of a file by HTTP + * + * if $timeout is 'default', $wgHTTPTimeout is used + */ + function getHTTP( $url, $timeout = 'default' ) { + global $wgHTTPTimeout, $wgHTTPProxy, $wgVersion, $wgTitle; - # Use curl if available - if ( function_exists( 'curl_init' ) ) { - $c = curl_init( $url ); - if ( wfIsLocalURL( $url ) ) { - curl_setopt( $c, CURLOPT_PROXY, 'localhost:80' ); - } else if ($wgHTTPProxy) { - curl_setopt($c, CURLOPT_PROXY, $wgHTTPProxy); - } + # Use curl if available + if ( function_exists( 'curl_init' ) ) { + $c = curl_init( $url ); + if ( HttpFunctions::isLocalURL( $url ) ) { + curl_setopt( $c, CURLOPT_PROXY, 'localhost:80' ); + } else if ($wgHTTPProxy) { + curl_setopt($c, CURLOPT_PROXY, $wgHTTPProxy); + } - if ( $timeout == 'default' ) { - $timeout = $wgHTTPTimeout; - } - curl_setopt( $c, CURLOPT_TIMEOUT, $timeout ); - curl_setopt( $c, CURLOPT_USERAGENT, "MediaWiki/$wgVersion" ); + if ( $timeout == 'default' ) { + $timeout = $wgHTTPTimeout; + } + curl_setopt( $c, CURLOPT_TIMEOUT, $timeout ); + curl_setopt( $c, CURLOPT_USERAGENT, "MediaWiki/$wgVersion" ); - # Set the referer to $wgTitle, even in command-line mode - # This is useful for interwiki transclusion, where the foreign - # server wants to know what the referring page is. - # $_SERVER['REQUEST_URI'] gives a less reliable indication of the - # referring page. - if ( is_object( $wgTitle ) ) { - curl_setopt( $c, CURLOPT_REFERER, $wgTitle->getFullURL() ); - } + # Set the referer to $wgTitle, even in command-line mode + # This is useful for interwiki transclusion, where the foreign + # server wants to know what the referring page is. + # $_SERVER['REQUEST_URI'] gives a less reliable indication of the + # referring page. + if ( is_object( $wgTitle ) ) { + curl_setopt( $c, CURLOPT_REFERER, $wgTitle->getFullURL() ); + } - ob_start(); - curl_exec( $c ); - $text = ob_get_contents(); - ob_end_clean(); + ob_start(); + curl_exec( $c ); + $text = ob_get_contents(); + ob_end_clean(); - # Don't return the text of error messages, return false on error - if ( curl_getinfo( $c, CURLINFO_HTTP_CODE ) != 200 ) { - $text = false; + # Don't return the text of error messages, return false on error + if ( curl_getinfo( $c, CURLINFO_HTTP_CODE ) != 200 ) { + $text = false; + } + curl_close( $c ); + } else { + # Otherwise use file_get_contents, or its compatibility function from GlobalFunctions.php + # This may take 3 minutes to time out, and doesn't have local fetch capabilities + $url_fopen = ini_set( 'allow_url_fopen', 1 ); + $text = file_get_contents( $url ); + ini_set( 'allow_url_fopen', $url_fopen ); } - curl_close( $c ); - } else { - # Otherwise use file_get_contents, or its compatibility function from GlobalFunctions.php - # This may take 3 minutes to time out, and doesn't have local fetch capabilities - $url_fopen = ini_set( 'allow_url_fopen', 1 ); - $text = file_get_contents( $url ); - ini_set( 'allow_url_fopen', $url_fopen ); + return $text; } - return $text; -} -/** - * Check if the URL can be served by localhost - */ -function wfIsLocalURL( $url ) { - global $wgCommandLineMode, $wgConf; - if ( $wgCommandLineMode ) { - return false; - } + /** + * Check if the URL can be served by localhost + */ + function isLocalURL( $url ) { + global $wgCommandLineMode, $wgConf; + if ( $wgCommandLineMode ) { + return false; + } - // Extract host part - $matches = array(); - if ( preg_match( '!^http://([\w.-]+)[/:].*$!', $url, $matches ) ) { - $host = $matches[1]; - // Split up dotwise - $domainParts = explode( '.', $host ); - // Check if this domain or any superdomain is listed in $wgConf as a local virtual host - $domainParts = array_reverse( $domainParts ); - for ( $i = 0; $i < count( $domainParts ); $i++ ) { - $domainPart = $domainParts[$i]; - if ( $i == 0 ) { - $domain = $domainPart; - } else { - $domain = $domainPart . '.' . $domain; - } - if ( $wgConf->isLocalVHost( $domain ) ) { - return true; + // Extract host part + $matches = array(); + if ( preg_match( '!^http://([\w.-]+)[/:].*$!', $url, $matches ) ) { + $host = $matches[1]; + // Split up dotwise + $domainParts = explode( '.', $host ); + // Check if this domain or any superdomain is listed in $wgConf as a local virtual host + $domainParts = array_reverse( $domainParts ); + for ( $i = 0; $i < count( $domainParts ); $i++ ) { + $domainPart = $domainParts[$i]; + if ( $i == 0 ) { + $domain = $domainPart; + } else { + $domain = $domainPart . '.' . $domain; + } + if ( $wgConf->isLocalVHost( $domain ) ) { + return true; + } } } + return false; } - return false; } - ?> diff --git a/includes/Image.php b/includes/Image.php index b21964224d..8e6cf43273 100644 --- a/includes/Image.php +++ b/includes/Image.php @@ -12,9 +12,6 @@ * extension=extensions/php_exif.dll */ -if ($wgShowEXIF) - require_once('Exif.php'); - /** * Bump this number when serialized cache records may be incompatible. */ diff --git a/includes/ImagePage.php b/includes/ImagePage.php index 9b91c8785e..e9ed19153e 100644 --- a/includes/ImagePage.php +++ b/includes/ImagePage.php @@ -9,8 +9,6 @@ if( !defined( 'MEDIAWIKI' ) ) die( -1 ); -require_once( 'Image.php' ); - /** * Special handling for image description pages * @package MediaWiki @@ -309,9 +307,8 @@ END $wgOut->addHTML($sharedtext); if ($wgRepositoryBaseUrl && $wgFetchCommonsDescriptions) { - require_once("HttpFunctions.php"); $ur = ini_set('allow_url_fopen', true); - $text = wfGetHTTP($url . '?action=render'); + $text = HttpFunctions::getHTTP($url . '?action=render'); ini_set('allow_url_fopen', $ur); if ($text) $this->mExtraDescription = $text; @@ -674,7 +671,6 @@ END } function blockedIPpage() { - require_once( 'EditPage.php' ); $edit = new EditPage( $this ); return $edit->blockedIPpage(); } diff --git a/includes/LinksUpdate.php b/includes/LinksUpdate.php index bd09502e79..54728582dd 100644 --- a/includes/LinksUpdate.php +++ b/includes/LinksUpdate.php @@ -119,7 +119,6 @@ class LinksUpdate { if ( $this->mRecursive ) { $tlto = $this->mTitle->getTemplateLinksTo(); if ( count( $tlto ) ) { - require_once( 'JobQueue.php' ); Job::queueLinksJobs( $tlto ); } } @@ -155,7 +154,6 @@ class LinksUpdate { if ( $this->mRecursive ) { $tlto = $this->mTitle->getTemplateLinksTo(); if ( count( $tlto ) ) { - require_once( 'JobQueue.php' ); Job::queueLinksJobs( $tlto ); } } diff --git a/includes/LoadBalancer.php b/includes/LoadBalancer.php index 6cf743b9e3..3e6cd7ec15 100644 --- a/includes/LoadBalancer.php +++ b/includes/LoadBalancer.php @@ -7,7 +7,6 @@ /** * Depends on the database object */ -require_once( 'Database.php' ); # Valid database indexes # Operation-based indexes @@ -440,12 +439,14 @@ class LoadBalancer { } extract( $server ); + # Get class for this database type - $class = 'Database' . ucfirst( $type ); - if ( !class_exists( $class ) ) { - require_once( "$class.php" ); + if ($type != 'mysql' ) { + $class = 'Database' . ucfirst( $type ); + } else { + $class = 'Database'; } - + # Create object $db = new $class( $host, $user, $password, $dbname, 1, $flags ); $db->setLBInfo( $server ); diff --git a/includes/LogPage.php b/includes/LogPage.php index c3b236762a..753c1dc47b 100644 --- a/includes/LogPage.php +++ b/includes/LogPage.php @@ -83,7 +83,6 @@ class LogPage { $rcComment .= ': ' . $this->comment; } - require_once( 'RecentChange.php' ); RecentChange::notifyLog( $now, $titleObj, $wgUser, $rcComment, '', $this->type, $this->action, $this->target, $this->comment, $this->params ); } diff --git a/includes/Math.php b/includes/Math.php index e40abdf1af..d47a4299fe 100644 --- a/includes/Math.php +++ b/includes/Math.php @@ -248,15 +248,13 @@ class MathRenderer { wfDebug( "TeX: getHashPath, hash is: $this->hash, path is: $path\n" ); return $path; } - - -} - -function renderMath( $tex ) { - global $wgUser; - $math = new MathRenderer( $tex ); - $math->setOutputMode( $wgUser->getOption('math')); - return $math->render(); + + static function renderMath ( $tex ) { + global $wgUser; + $math = new MathRenderer( $tex ); + $math->setOutputMode( $wgUser->getOption('math')); + return $math->render(); + } } ?> diff --git a/includes/MessageCache.php b/includes/MessageCache.php index 8e54af91c4..083e220570 100644 --- a/includes/MessageCache.php +++ b/includes/MessageCache.php @@ -5,9 +5,6 @@ * @subpackage Cache */ -/** */ -require_once( 'Revision.php' ); - /** * */ diff --git a/includes/ObjectCache.php b/includes/ObjectCache.php index fe7417d2c1..d851f3ab2a 100644 --- a/includes/ObjectCache.php +++ b/includes/ObjectCache.php @@ -33,93 +33,91 @@ class FakeMemCachedClient { global $wgCaches; $wgCaches = array(); -/** @todo document */ -function &wfGetCache( $inputType ) { - global $wgCaches, $wgMemCachedServers, $wgMemCachedDebug, $wgMemCachedPersistent; - $cache = false; +class ObjectCacheManager { + /* @static */ + function getCache( $inputType ) { + global $wgCaches, $wgMemCachedServers, $wgMemCachedDebug, $wgMemCachedPersistent; + $cache = false; - if ( $inputType == CACHE_ANYTHING ) { - reset( $wgCaches ); - $type = key( $wgCaches ); - if ( $type === false || $type === CACHE_NONE ) { - $type = CACHE_DB; + if ( $inputType == CACHE_ANYTHING ) { + reset( $wgCaches ); + $type = key( $wgCaches ); + if ( $type === false || $type === CACHE_NONE ) { + $type = CACHE_DB; + } + } else { + $type = $inputType; } - } else { - $type = $inputType; - } - - if ( $type == CACHE_MEMCACHED ) { - if ( !array_key_exists( CACHE_MEMCACHED, $wgCaches ) ){ - require_once( 'memcached-client.php' ); - if (!class_exists("MemcachedClientforWiki")) { - class MemCachedClientforWiki extends memcached { - function _debugprint( $text ) { - wfDebug( "memcached: $text\n" ); - } + if ( $type == CACHE_MEMCACHED ) { + if ( !array_key_exists( CACHE_MEMCACHED, $wgCaches ) ){ + $wgCaches[CACHE_DB] = new MemCachedClientforWiki( + array('persistant' => $wgMemCachedPersistent, 'compress_threshold' => 1500 ) ); + $cache =& $wgCaches[CACHE_DB]; + $cache->set_servers( $wgMemCachedServers ); + $cache->set_debug( $wgMemCachedDebug ); + } + } elseif ( $type == CACHE_ACCEL ) { + if ( !array_key_exists( CACHE_ACCEL, $wgCaches ) ) { + if ( function_exists( 'eaccelerator_get' ) ) { + $wgCaches[CACHE_ACCEL] = new eAccelBagOStuff; + } elseif ( function_exists( 'apc_fetch') ) { + $wgCaches[CACHE_ACCEL] = new APCBagOStuff; + } elseif ( function_exists( 'mmcache_get' ) ) { + $wgCaches[CACHE_ACCEL] = new TurckBagOStuff; + } else { + $wgCaches[CACHE_ACCEL] = false; } } + if ( $wgCaches[CACHE_ACCEL] !== false ) { + $cache =& $wgCaches[CACHE_ACCEL]; + } + } - $wgCaches[CACHE_DB] = new MemCachedClientforWiki( - array('persistant' => $wgMemCachedPersistent, 'compress_threshold' => 1500 ) ); + if ( $type == CACHE_DB || ( $inputType == CACHE_ANYTHING && $cache === false ) ) { + if ( !array_key_exists( CACHE_DB, $wgCaches ) ) { + $wgCaches[CACHE_DB] = new MediaWikiBagOStuff('objectcache'); + } $cache =& $wgCaches[CACHE_DB]; - $cache->set_servers( $wgMemCachedServers ); - $cache->set_debug( $wgMemCachedDebug ); } - } elseif ( $type == CACHE_ACCEL ) { - if ( !array_key_exists( CACHE_ACCEL, $wgCaches ) ) { - if ( function_exists( 'eaccelerator_get' ) ) { - require_once( 'BagOStuff.php' ); - $wgCaches[CACHE_ACCEL] = new eAccelBagOStuff; - } elseif ( function_exists( 'apc_fetch') ) { - require_once( 'BagOStuff.php' ); - $wgCaches[CACHE_ACCEL] = new APCBagOStuff; - } elseif ( function_exists( 'mmcache_get' ) ) { - require_once( 'BagOStuff.php' ); - $wgCaches[CACHE_ACCEL] = new TurckBagOStuff; - } else { - $wgCaches[CACHE_ACCEL] = false; + + if ( $cache === false ) { + if ( !array_key_exists( CACHE_NONE, $wgCaches ) ) { + $wgCaches[CACHE_NONE] = new FakeMemCachedClient; } + $cache =& $wgCaches[CACHE_NONE]; } - if ( $wgCaches[CACHE_ACCEL] !== false ) { - $cache =& $wgCaches[CACHE_ACCEL]; - } - } - if ( $type == CACHE_DB || ( $inputType == CACHE_ANYTHING && $cache === false ) ) { - if ( !array_key_exists( CACHE_DB, $wgCaches ) ) { - require_once( 'BagOStuff.php' ); - $wgCaches[CACHE_DB] = new MediaWikiBagOStuff('objectcache'); - } - $cache =& $wgCaches[CACHE_DB]; + return $cache; } - - if ( $cache === false ) { - if ( !array_key_exists( CACHE_NONE, $wgCaches ) ) { - $wgCaches[CACHE_NONE] = new FakeMemCachedClient; - } - $cache =& $wgCaches[CACHE_NONE]; + + /** @static */ + function &getMainCache() { + global $wgMainCacheType; + $ret =& ObjectCacheManager::getCache( $wgMainCacheType ); + return $ret; } - return $cache; -} - -function &wfGetMainCache() { - global $wgMainCacheType; - $ret =& wfGetCache( $wgMainCacheType ); - return $ret; -} - -function &wfGetMessageCacheStorage() { - global $wgMessageCacheType; - $ret =& wfGetCache( $wgMessageCacheType ); - return $ret; + /** @static */ + function &getMessageCache() { + global $wgMessageCacheType; + $ret =& ObjectCacheManager::getCache( $wgMessageCacheType ); + return $ret; + } + + /** @static */ + function &getParserCache() { + global $wgParserCacheType; + $ret =& ObjectCacheManager::getCache( $wgParserCacheType ); + return $ret; + } + } -function &wfGetParserCacheStorage() { - global $wgParserCacheType; - $ret =& wfGetCache( $wgParserCacheType ); - return $ret; +class MemCachedClientforWiki extends memcached { + function _debugprint( $text ) { + wfDebug( "memcached: $text\n" ); + } } ?> diff --git a/includes/OutputPage.php b/includes/OutputPage.php index c155d380c4..451acb2438 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -5,9 +5,6 @@ if ( ! defined( 'MEDIAWIKI' ) ) * @package MediaWiki */ -if ( $wgUseTeX ) - require_once 'Math.php'; - /** * @todo document * @package MediaWiki @@ -650,7 +647,7 @@ class OutputPage { $id = $wgUser->blockedBy(); $reason = $wgUser->blockedFor(); - $ip = wfGetIP(); + $ip = ProxyTools::getIP(); if ( is_numeric( $id ) ) { $name = User::whoIs( $id ); diff --git a/includes/PageHistory.php b/includes/PageHistory.php index 2e70e4d902..2c69a3e4e6 100644 --- a/includes/PageHistory.php +++ b/includes/PageHistory.php @@ -576,9 +576,6 @@ class PageHistory { * @param string $type */ function feed( $type ) { - require_once 'Feed.php'; - require_once 'SpecialRecentchanges.php'; - global $wgFeedClasses; if( !isset( $wgFeedClasses[$type] ) ) { global $wgOut; diff --git a/includes/Parser.php b/includes/Parser.php index 2bfa48273c..8e6fd965e1 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -6,11 +6,6 @@ * @subpackage Parser */ -/** */ -require_once( 'Sanitizer.php' ); -require_once( 'HttpFunctions.php' ); -require_once( 'ImageGallery.php' ); - /** * Update this version number when the ParserOutput format * changes in an incompatible way, so the parser cache @@ -452,7 +447,7 @@ class Parser $output = wfEscapeHTMLTagsOnly( $content ); break; case 'math': - $output = renderMath( $content ); + $output = MathRenderer::renderMath( $content ); break; case 'pre': // Backwards-compatibility hack @@ -2972,7 +2967,7 @@ class Parser } } - $text = wfGetHTTP($url); + $text = HttpFunctions::getHTTP($url); if (!$text) return wfMsg('scarytranscludefailed', $url); diff --git a/includes/ParserXML.php b/includes/ParserXML.php index e7b64f6e92..b5dae85fb3 100644 --- a/includes/ParserXML.php +++ b/includes/ParserXML.php @@ -5,9 +5,6 @@ * @subpackage Experimental */ -/** */ -require_once ('Parser.php'); - /** * This should one day become the XML->(X)HTML parser * Based on work by Jan Hidders and Magnus Manske diff --git a/includes/Profiling.php b/includes/Profiling.php index edecc4f32f..531e336d37 100644 --- a/includes/Profiling.php +++ b/includes/Profiling.php @@ -278,7 +278,6 @@ class Profiler { } } $prof .= "\nTotal: $total\n\n"; - return $prof; } @@ -322,7 +321,6 @@ class Profiler { } else { $pfhost = ''; } - $sql = "UPDATE $profiling "."SET pf_count=pf_count+{$eventCount}, "."pf_time=pf_time + {$timeSum} ". "WHERE pf_name='{$encname}' AND pf_server='{$pfhost}'"; $dbw->query($sql); diff --git a/includes/ProxyTools.php b/includes/ProxyTools.php index bed79c1003..350078d2fe 100644 --- a/includes/ProxyTools.php +++ b/includes/ProxyTools.php @@ -4,230 +4,228 @@ * @package MediaWiki */ -function wfGetForwardedFor() { - if( function_exists( 'apache_request_headers' ) ) { - // More reliable than $_SERVER due to case and -/_ folding - $set = apache_request_headers(); - $index = 'X-Forwarded-For'; - } else { - // Subject to spoofing with headers like X_Forwarded_For - $set = $_SERVER; - $index = 'HTTP_X_FORWARDED_FOR'; - } - if( isset( $set[$index] ) ) { - return $set[$index]; - } else { - return null; +class ProxyTools { + function getForwardedFor() { + if( function_exists( 'apache_request_headers' ) ) { + // More reliable than $_SERVER due to case and -/_ folding + $set = apache_request_headers(); + $index = 'X-Forwarded-For'; + } else { + // Subject to spoofing with headers like X_Forwarded_For + $set = $_SERVER; + $index = 'HTTP_X_FORWARDED_FOR'; + } + if( isset( $set[$index] ) ) { + return $set[$index]; + } else { + return null; + } } -} -/** Work out the IP address based on various globals */ -function wfGetIP() { - global $wgSquidServers, $wgSquidServersNoPurge, $wgIP; + /** Work out the IP address based on various globals */ + function getIP() { + global $wgSquidServers, $wgSquidServersNoPurge, $wgIP; - # Return cached result - if ( !empty( $wgIP ) ) { - return $wgIP; - } + # Return cached result + if ( !empty( $wgIP ) ) { + return $wgIP; + } - /* collect the originating ips */ - # Client connecting to this webserver - if ( isset( $_SERVER['REMOTE_ADDR'] ) ) { - $ipchain = array( $_SERVER['REMOTE_ADDR'] ); - } else { - # Running on CLI? - $ipchain = array( '127.0.0.1' ); - } - $ip = $ipchain[0]; - - # Get list of trusted proxies - # Flipped for quicker access - $trustedProxies = array_flip( array_merge( $wgSquidServers, $wgSquidServersNoPurge ) ); - if ( count( $trustedProxies ) ) { - # Append XFF on to $ipchain - $forwardedFor = wfGetForwardedFor(); - if ( isset( $forwardedFor ) ) { - $xff = array_map( 'trim', explode( ',', $forwardedFor ) ); - $xff = array_reverse( $xff ); - $ipchain = array_merge( $ipchain, $xff ); - } - # Step through XFF list and find the last address in the list which is a trusted server - # Set $ip to the IP address given by that trusted server, unless the address is not sensible (e.g. private) - foreach ( $ipchain as $i => $curIP ) { - if ( array_key_exists( $curIP, $trustedProxies ) ) { - if ( isset( $ipchain[$i + 1] ) && wfIsIPPublic( $ipchain[$i + 1] ) ) { - $ip = $ipchain[$i + 1]; + /* collect the originating ips */ + # Client connecting to this webserver + if ( isset( $_SERVER['REMOTE_ADDR'] ) ) { + $ipchain = array( $_SERVER['REMOTE_ADDR'] ); + } else { + # Running on CLI? + $ipchain = array( '127.0.0.1' ); + } + $ip = $ipchain[0]; + + # Get list of trusted proxies + # Flipped for quicker access + $trustedProxies = array_flip( array_merge( $wgSquidServers, $wgSquidServersNoPurge ) ); + if ( count( $trustedProxies ) ) { + # Append XFF on to $ipchain + $forwardedFor = ProxyTools::getForwardedFor(); + if ( isset( $forwardedFor ) ) { + $xff = array_map( 'trim', explode( ',', $forwardedFor ) ); + $xff = array_reverse( $xff ); + $ipchain = array_merge( $ipchain, $xff ); + } + # Step through XFF list and find the last address in the list which is a trusted server + # Set $ip to the IP address given by that trusted server, unless the address is not sensible (e.g. private) + foreach ( $ipchain as $i => $curIP ) { + if ( array_key_exists( $curIP, $trustedProxies ) ) { + if ( isset( $ipchain[$i + 1] ) && ProxyTools::isIPPublic( $ipchain[$i + 1] ) ) { + $ip = $ipchain[$i + 1]; + } + } else { + break; } - } else { - break; } } - } - - wfDebug( "IP: $ip\n" ); - $wgIP = $ip; - return $ip; -} -/** - * Given an IP address in dotted-quad notation, returns an unsigned integer. - * Like ip2long() except that it actually works and has a consistent error return value. - */ -function wfIP2Unsigned( $ip ) { - $n = ip2long( $ip ); - if ( $n == -1 || $n === false ) { # Return value on error depends on PHP version - $n = false; - } elseif ( $n < 0 ) { - $n += pow( 2, 32 ); + wfDebug( "IP: $ip\n" ); + $wgIP = $ip; + return $ip; + } + + /** + * Given an IP address in dotted-quad notation, returns an unsigned integer. + * Like ip2long() except that it actually works and has a consistent error return value. + */ + function IP2Unsigned( $ip ) { + $n = ip2long( $ip ); + if ( $n == -1 || $n === false ) { # Return value on error depends on PHP version + $n = false; + } elseif ( $n < 0 ) { + $n += pow( 2, 32 ); + } + return $n; } - return $n; -} -/** - * Return a zero-padded hexadecimal representation of an IP address - */ -function wfIP2Hex( $ip ) { - $n = wfIP2Unsigned( $ip ); - if ( $n !== false ) { - $n = sprintf( '%08X', $n ); + /** + * Return a zero-padded hexadecimal representation of an IP address + */ + function IP2Hex( $ip ) { + $n = ProxyTools::IP2Unsigned( $ip ); + if ( $n !== false ) { + $n = sprintf( '%08X', $n ); + } + return $n; } - return $n; -} -/** - * Determine if an IP address really is an IP address, and if it is public, - * i.e. not RFC 1918 or similar - */ -function wfIsIPPublic( $ip ) { - $n = wfIP2Unsigned( $ip ); - if ( !$n ) { - return false; - } + /** + * Determine if an IP address really is an IP address, and if it is public, + * i.e. not RFC 1918 or similar + */ + function isIPPublic( $ip ) { + $n = ProxyTools::IP2Unsigned( $ip ); + if ( !$n ) { + return false; + } - // ip2long accepts incomplete addresses, as well as some addresses - // followed by garbage characters. Check that it's really valid. - if( $ip != long2ip( $n ) ) { - return false; - } - - static $privateRanges = false; - if ( !$privateRanges ) { - $privateRanges = array( - array( '10.0.0.0', '10.255.255.255' ), # RFC 1918 (private) - array( '172.16.0.0', '172.31.255.255' ), # " - array( '192.168.0.0', '192.168.255.255' ), # " - array( '0.0.0.0', '0.255.255.255' ), # this network - array( '127.0.0.0', '127.255.255.255' ), # loopback - ); - } - - foreach ( $privateRanges as $r ) { - $start = wfIP2Unsigned( $r[0] ); - $end = wfIP2Unsigned( $r[1] ); - if ( $n >= $start && $n <= $end ) { + // ip2long accepts incomplete addresses, as well as some addresses + // followed by garbage characters. Check that it's really valid. + if( $ip != long2ip( $n ) ) { return false; } - } - return true; -} -/** - * Forks processes to scan the originating IP for an open proxy server - * MemCached can be used to skip IPs that have already been scanned - */ -function wfProxyCheck() { - global $wgBlockOpenProxies, $wgProxyPorts, $wgProxyScriptPath; - global $wgUseMemCached, $wgMemc, $wgDBname, $wgProxyMemcExpiry; - global $wgProxyKey; + static $privateRanges = false; + if ( !$privateRanges ) { + $privateRanges = array( + array( '10.0.0.0', '10.255.255.255' ), # RFC 1918 (private) + array( '172.16.0.0', '172.31.255.255' ), # " + array( '192.168.0.0', '192.168.255.255' ), # " + array( '0.0.0.0', '0.255.255.255' ), # this network + array( '127.0.0.0', '127.255.255.255' ), # loopback + ); + } - if ( !$wgBlockOpenProxies ) { - return; + foreach ( $privateRanges as $r ) { + $start = ProxyTools::IP2Unsigned( $r[0] ); + $end = ProxyTools::IP2Unsigned( $r[1] ); + if ( $n >= $start && $n <= $end ) { + return false; + } + } + return true; } - $ip = wfGetIP(); + /** + * Forks processes to scan the originating IP for an open proxy server + * MemCached can be used to skip IPs that have already been scanned + */ + function proxyCheck() { + global $wgBlockOpenProxies, $wgProxyPorts, $wgProxyScriptPath; + global $wgUseMemCached, $wgMemc, $wgDBname, $wgProxyMemcExpiry; + global $wgProxyKey; - # Get MemCached key - $skip = false; - if ( $wgUseMemCached ) { - $mcKey = "$wgDBname:proxy:ip:$ip"; - $mcValue = $wgMemc->get( $mcKey ); - if ( $mcValue ) { - $skip = true; + if ( !$wgBlockOpenProxies ) { + return; } - } - # Fork the processes - if ( !$skip ) { - $title = Title::makeTitle( NS_SPECIAL, 'Blockme' ); - $iphash = md5( $ip . $wgProxyKey ); - $url = $title->getFullURL( 'ip='.$iphash ); - - foreach ( $wgProxyPorts as $port ) { - $params = implode( ' ', array( - escapeshellarg( $wgProxyScriptPath ), - escapeshellarg( $ip ), - escapeshellarg( $port ), - escapeshellarg( $url ) - )); - exec( "php $params &>/dev/null &" ); - } - # Set MemCached key + $ip = ProxyTools::getIP(); + + # Get MemCached key + $skip = false; if ( $wgUseMemCached ) { - $wgMemc->set( $mcKey, 1, $wgProxyMemcExpiry ); + $mcKey = "$wgDBname:proxy:ip:$ip"; + $mcValue = $wgMemc->get( $mcKey ); + if ( $mcValue ) { + $skip = true; + } } - } -} -/** - * Convert a network specification in CIDR notation to an integer network and a number of bits - */ -function wfParseCIDR( $range ) { - $parts = explode( '/', $range, 2 ); - if ( count( $parts ) != 2 ) { - return array( false, false ); + # Fork the processes + if ( !$skip ) { + $title = Title::makeTitle( NS_SPECIAL, 'Blockme' ); + $iphash = md5( $ip . $wgProxyKey ); + $url = $title->getFullURL( 'ip='.$iphash ); + + foreach ( $wgProxyPorts as $port ) { + $params = implode( ' ', array( + escapeshellarg( $wgProxyScriptPath ), + escapeshellarg( $ip ), + escapeshellarg( $port ), + escapeshellarg( $url ) + )); + exec( "php $params &>/dev/null &" ); + } + # Set MemCached key + if ( $wgUseMemCached ) { + $wgMemc->set( $mcKey, 1, $wgProxyMemcExpiry ); + } + } } - $network = wfIP2Unsigned( $parts[0] ); - if ( $network !== false && is_numeric( $parts[1] ) && $parts[1] >= 0 && $parts[1] <= 32 ) { - $bits = $parts[1]; - } else { - $network = false; - $bits = false; + + /** + * Convert a network specification in CIDR notation to an integer network and a number of bits + */ + function parseCIDR( $range ) { + $parts = explode( '/', $range, 2 ); + if ( count( $parts ) != 2 ) { + return array( false, false ); + } + $network = ProxyTools::IP2Unsigned( $parts[0] ); + if ( $network !== false && is_numeric( $parts[1] ) && $parts[1] >= 0 && $parts[1] <= 32 ) { + $bits = $parts[1]; + } else { + $network = false; + $bits = false; + } + return array( $network, $bits ); } - return array( $network, $bits ); -} -/** - * Check if an IP address is in the local proxy list - */ -function wfIsLocallyBlockedProxy( $ip ) { - global $wgProxyList; - $fname = 'wfIsLocallyBlockedProxy'; + /** + * Check if an IP address is in the local proxy list + */ + function isLocallyBlockedProxy( $ip ) { + global $wgProxyList; + $fname = 'ProxyTools::isLocallyBlockedProxy'; - if ( !$wgProxyList ) { - return false; - } - wfProfileIn( $fname ); + if ( !$wgProxyList ) { + return false; + } + wfProfileIn( $fname ); - if ( !is_array( $wgProxyList ) ) { - # Load from the specified file - $wgProxyList = array_map( 'trim', file( $wgProxyList ) ); - } + if ( !is_array( $wgProxyList ) ) { + # Load from the specified file + $wgProxyList = array_map( 'trim', file( $wgProxyList ) ); + } - if ( !is_array( $wgProxyList ) ) { - $ret = false; - } elseif ( array_search( $ip, $wgProxyList ) !== false ) { - $ret = true; - } elseif ( array_key_exists( $ip, $wgProxyList ) ) { - # Old-style flipped proxy list - $ret = true; - } else { - $ret = false; + if ( !is_array( $wgProxyList ) ) { + $ret = false; + } elseif ( array_search( $ip, $wgProxyList ) !== false ) { + $ret = true; + } elseif ( array_key_exists( $ip, $wgProxyList ) ) { + # Old-style flipped proxy list + $ret = true; + } else { + $ret = false; + } + wfProfileOut( $fname ); + return $ret; } - wfProfileOut( $fname ); - return $ret; } - - - - ?> diff --git a/includes/QueryPage.php b/includes/QueryPage.php index 7848c53cbc..515e458a3b 100644 --- a/includes/QueryPage.php +++ b/includes/QueryPage.php @@ -4,11 +4,6 @@ * @package MediaWiki */ -/** - * - */ -require_once 'Feed.php'; - /** * List of query page classes and their associated special pages, for periodic update purposes */ diff --git a/includes/RawPage.php b/includes/RawPage.php index 5685385cc6..252ab3206f 100644 --- a/includes/RawPage.php +++ b/includes/RawPage.php @@ -10,9 +10,6 @@ * @package MediaWiki */ -/** */ -require_once( 'Revision.php' ); - /** * @todo document * @package MediaWiki diff --git a/includes/RecentChange.php b/includes/RecentChange.php index cae6d76978..d550513d0b 100644 --- a/includes/RecentChange.php +++ b/includes/RecentChange.php @@ -205,7 +205,7 @@ class RecentChange } if ( !$ip ) { - $ip = wfGetIP(); + $ip = ProxyTools::getIP(); if ( !$ip ) { $ip = ''; } @@ -249,7 +249,7 @@ class RecentChange $ip='', $size = 0, $newId = 0 ) { if ( !$ip ) { - $ip = wfGetIP(); + $ip = ProxyTools::getIP(); if ( !$ip ) { $ip = ''; } @@ -294,7 +294,7 @@ class RecentChange /*static*/ function notifyMove( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='', $overRedir = false ) { if ( !$ip ) { - $ip = wfGetIP(); + $ip = ProxyTools::getIP(); if ( !$ip ) { $ip = ''; } @@ -344,7 +344,7 @@ class RecentChange $type, $action, $target, $logComment, $params ) { if ( !$ip ) { - $ip = wfGetIP(); + $ip = ProxyTools::getIP(); if ( !$ip ) { $ip = ''; } diff --git a/includes/Revision.php b/includes/Revision.php index e9083a7742..9aaa93c15c 100644 --- a/includes/Revision.php +++ b/includes/Revision.php @@ -4,10 +4,6 @@ * @todo document */ -/** */ -require_once( 'Database.php' ); -require_once( 'Article.php' ); - /** @+ */ define( 'MW_REV_DELETED_TEXT', 1 ); define( 'MW_REV_DELETED_COMMENT', 2 ); @@ -514,7 +510,6 @@ class Revision { wfProfileOut( $fname ); return false; } - require_once('ExternalStore.php'); $text=ExternalStore::fetchFromURL($url); } @@ -604,7 +599,6 @@ class Revision { } else { $store = $wgDefaultExternalStore; } - require_once('ExternalStore.php'); // Store and get the URL $data = ExternalStore::insert( $store, $data ); if ( !$data ) { diff --git a/includes/SearchEngine.php b/includes/SearchEngine.php index 2ef70451ec..0175210782 100644 --- a/includes/SearchEngine.php +++ b/includes/SearchEngine.php @@ -195,10 +195,8 @@ class SearchEngine { $class = $wgSearchType; } elseif( $wgDBtype == 'mysql' ) { $class = 'SearchMySQL4'; - require_once( 'SearchMySQL4.php' ); } else if ( $wgDBtype == 'PostgreSQL' ) { $class = 'SearchTsearch2'; - require_once( 'SearchTsearch2.php' ); } else { $class = 'SearchEngineDummy'; } diff --git a/includes/SearchMySQL.php b/includes/SearchMySQL.php index 6683cbe04c..80bddbddeb 100644 --- a/includes/SearchMySQL.php +++ b/includes/SearchMySQL.php @@ -24,9 +24,6 @@ * @subpackage Search */ -/** */ -require_once( 'SearchEngine.php' ); - /** @package MediaWiki */ class SearchMySQL extends SearchEngine { /** diff --git a/includes/SearchMySQL4.php b/includes/SearchMySQL4.php index 59f1bbee6c..dcc1f685c1 100644 --- a/includes/SearchMySQL4.php +++ b/includes/SearchMySQL4.php @@ -23,8 +23,6 @@ * @subpackage Search */ -require_once( 'SearchMySQL.php' ); - /** * @package MediaWiki * @subpackage Search diff --git a/includes/SearchTsearch2.php b/includes/SearchTsearch2.php index 3c0f13281a..767979cd40 100644 --- a/includes/SearchTsearch2.php +++ b/includes/SearchTsearch2.php @@ -23,9 +23,6 @@ * @subpackage Search */ -/** */ -require_once( 'SearchEngine.php' ); - /** * @todo document * @package MediaWiki diff --git a/includes/SearchUpdate.php b/includes/SearchUpdate.php index 1f222b3952..37981a67d7 100644 --- a/includes/SearchUpdate.php +++ b/includes/SearchUpdate.php @@ -37,7 +37,6 @@ class SearchUpdate { $fname = 'SearchUpdate::doUpdate'; wfProfileIn( $fname ); - require_once( 'SearchEngine.php' ); $search = SearchEngine::create(); $lc = $search->legalSearchChars() . '&#;'; diff --git a/includes/Setup.php b/includes/Setup.php index 4c4328dd40..dedf6a44a2 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -22,13 +22,14 @@ if ( !isset( $wgVersion ) ) { die( -1 ); } +require('AutoLoader.php'); + if( !isset( $wgProfiling ) ) $wgProfiling = false; if ( function_exists( 'wfProfileIn' ) ) { /* nada, everything should be done already */ } elseif ( $wgProfiling and (0 == rand() % $wgProfileSampleRate ) ) { - require_once( 'Profiling.php' ); $wgProfiling = true; if ($wgProfilerType == "") { $wgProfiler = new Profiler(); @@ -48,29 +49,8 @@ wfProfileIn( $fname.'-includes' ); require_once( 'GlobalFunctions.php' ); require_once( 'Hooks.php' ); require_once( 'Namespace.php' ); -require_once( 'User.php' ); -require_once( 'Skin.php' ); -require_once( 'OutputPage.php' ); -require_once( 'LinkCache.php' ); -require_once( 'LinkBatch.php' ); -require_once( 'Title.php' ); -require_once( 'Article.php' ); require_once( 'MagicWord.php' ); -require_once( 'Block.php' ); -require_once( 'MessageCache.php' ); -require_once( 'Parser.php' ); -require_once( 'ParserCache.php' ); -require_once( 'WebRequest.php' ); -require_once( 'LoadBalancer.php' ); -require_once( 'HistoryBlob.php' ); -require_once( 'ProxyTools.php' ); -require_once( 'ObjectCache.php' ); -require_once( 'WikiError.php' ); -require_once( 'SpecialPage.php' ); - -if ( $wgUseDynamicDates ) { - require_once( 'DateFormatter.php' ); -} + wfProfileOut( $fname.'-includes' ); wfProfileIn( $fname.'-misc1' ); @@ -108,9 +88,9 @@ $wgUseEnotif = $wgEnotifUserTalk || $wgEnotifWatchlist; wfProfileOut( $fname.'-misc1' ); wfProfileIn( $fname.'-memcached' ); -$wgMemc =& wfGetMainCache(); -$messageMemc =& wfGetMessageCacheStorage(); -$parserMemc =& wfGetParserCacheStorage(); +$wgMemc =& ObjectCacheManager::getMainCache(); +$messageMemc =& ObjectCacheManager::getMessageCache(); +$parserMemc =& ObjectCacheManager::getParserCache(); wfDebug( 'Main cache: ' . get_class( $wgMemc ) . "\nMessage cache: " . get_class( $messageMemc ) . @@ -208,7 +188,6 @@ foreach ( $wgSkinExtensionFunctions as $func ) { } if( !is_object( $wgAuth ) ) { - require_once( 'AuthPlugin.php' ); $wgAuth = new AuthPlugin(); } @@ -296,7 +275,6 @@ $wgMagicWords = array(); $wgMwRedir =& MagicWord::get( MAG_REDIRECT ); if ( $wgUseXMLparser ) { - require_once( 'ParserXML.php' ); $wgParser = new ParserXML(); } else { $wgParser = new Parser(); diff --git a/includes/Skin.php b/includes/Skin.php index 5bf36abec4..dc0a998416 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -8,28 +8,11 @@ if ( ! defined( 'MEDIAWIKI' ) ) * @subpackage Skins */ -# See skin.txt -require_once( 'Linker.php' ); -require_once( 'Image.php' ); - # Get a list of available skins # Build using the regular expression '^(.*).php$' # Array keys are all lower case, array value keep the case used by filename # -$skinDir = dir( $wgStyleDirectory ); - -# while code from www.php.net -while (false !== ($file = $skinDir->read())) { - // Skip non-PHP files, hidden files, and '.dep' includes - if(preg_match('/^([^.]*)\.php$/',$file, $matches)) { - $aSkin = $matches[1]; - $wgValidSkinNames[strtolower($aSkin)] = $aSkin; - } -} -$skinDir->close(); -unset($matches); - /** * The main skin class that provide methods and properties for all other skins. * This base class is also the "Standard" skin. @@ -55,9 +38,35 @@ class Skin extends Linker { */ function getSkinNames() { global $wgValidSkinNames; + if (!is_array($wgValidSkinNames)) { + Skin::initializeSkinNames(); + } return $wgValidSkinNames; } + /** + * Initializes set of available skins. + * @return array of strings - skin names + * @static + */ + + function initializeSkinNames() { + global $wgStyleDirectory, $wgValidSkinNames; + $skinDir = dir( $wgStyleDirectory ); + + # while code from www.php.net + while (false !== ($file = $skinDir->read())) { + // Skip non-PHP files, hidden files, and '.dep' includes + if(preg_match('/^([^.]*)\.php$/',$file, $matches)) { + $aSkin = $matches[1]; + $wgValidSkinNames[strtolower($aSkin)] = $aSkin; + } + } + $skinDir->close(); + unset($matches); + + } + /** * Normalize a skin preference value to a form that can be loaded. * If a skin can't be found, it will fall back to the configured @@ -745,7 +754,7 @@ END; $s = ''; if ( $wgUser->isAnon() ) { if( $wgShowIPinHeader && isset( $_COOKIE[ini_get('session.name')] ) ) { - $n = wfGetIP(); + $n = ProxyTools::getIP(); $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), $wgLang->getNsText( NS_TALK ) ); @@ -896,8 +905,7 @@ END; } if (isset($wgMaxCredits) && $wgMaxCredits != 0) { - require_once('Credits.php'); - $s .= ' ' . getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax); + $s .= ' ' . Credits::getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax); } else { $s .= $this->lastModified(); } @@ -1015,7 +1023,6 @@ END; */ function specialPagesList() { global $wgUser, $wgContLang, $wgServer, $wgRedirectScript, $wgAvailableRights; - require_once('SpecialPage.php'); $a = array(); $pages = SpecialPage::getPages(); diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php index f054153ada..c86b67ec2f 100644 --- a/includes/SkinTemplate.php +++ b/includes/SkinTemplate.php @@ -343,8 +343,7 @@ class SkinTemplate extends Skin { $this->credits = false; if (isset($wgMaxCredits) && $wgMaxCredits != 0) { - require_once("Credits.php"); - $this->credits = getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax); + $this->credits = Credits::getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax); } else { $tpl->set('lastmod', $this->lastModified()); } diff --git a/includes/SpecialBlockme.php b/includes/SpecialBlockme.php index b452b14738..c3524e4b50 100644 --- a/includes/SpecialBlockme.php +++ b/includes/SpecialBlockme.php @@ -12,7 +12,7 @@ function wfSpecialBlockme() { global $wgBlockOpenProxies, $wgOut, $wgProxyKey; - $ip = wfGetIP(); + $ip = ProxyTools::getIP(); if ( !$wgBlockOpenProxies || $_REQUEST['ip'] != md5( $ip . $wgProxyKey ) ) { $wgOut->addWikiText( wfMsg( "disabled" ) ); diff --git a/includes/SpecialPage.php b/includes/SpecialPage.php index 7c5465459f..bd2829dc1a 100644 --- a/includes/SpecialPage.php +++ b/includes/SpecialPage.php @@ -15,6 +15,10 @@ * @subpackage SpecialPage */ +/** + * @todo put all global specialpages stuff into class + */ +global $wgSpecialPages, $wgDisableCounters, $wgDisableInternalSearch, $wgEmailAuthentication; /** * @access private diff --git a/includes/SpecialPreferences.php b/includes/SpecialPreferences.php index bccbc6e4b5..69a68132c8 100644 --- a/includes/SpecialPreferences.php +++ b/includes/SpecialPreferences.php @@ -444,7 +444,7 @@ class PreferencesForm { * @access private */ function mainPrefsForm( $status , $message = '' ) { - global $wgUser, $wgOut, $wgLang, $wgContLang, $wgValidSkinNames; + global $wgUser, $wgOut, $wgLang, $wgContLang; global $wgAllowRealName, $wgImageLimits, $wgThumbLimits; global $wgDisableLangConversion; global $wgEnotifWatchlist, $wgEnotifUserTalk,$wgEnotifMinorEdits; @@ -723,7 +723,7 @@ class PreferencesForm { $previewtext = wfMsg('skinpreview'); # Only show members of $wgValidSkinNames rather than # $skinNames (skins is all skin names from Language.php) - foreach ($wgValidSkinNames as $skinkey => $skinname ) { + foreach (Skin::getSkinNames() as $skinkey => $skinname ) { if ( in_array( $skinkey, $wgSkipSkins ) ) { continue; } diff --git a/includes/SpecialRecentchanges.php b/includes/SpecialRecentchanges.php index 74c6ebf4e6..48470a7232 100644 --- a/includes/SpecialRecentchanges.php +++ b/includes/SpecialRecentchanges.php @@ -5,13 +5,6 @@ * @subpackage SpecialPage */ -/** - * - */ -require_once( 'Feed.php' ); -require_once( 'ChangesList.php' ); -require_once( 'Revision.php' ); - /** * Constructor */ diff --git a/includes/SpecialUpload.php b/includes/SpecialUpload.php index 84b732f7b9..e61f485394 100644 --- a/includes/SpecialUpload.php +++ b/includes/SpecialUpload.php @@ -9,8 +9,6 @@ * */ require_once 'Image.php'; -require_once 'MacBinary.php'; -require_once 'Licenses.php'; /** * Entry point */ diff --git a/includes/SpecialUserlogin.php b/includes/SpecialUserlogin.php index 03a4185385..2d3838812e 100644 --- a/includes/SpecialUserlogin.php +++ b/includes/SpecialUserlogin.php @@ -210,7 +210,7 @@ class LoginForm { return false; } - $ip = wfGetIP(); + $ip = ProxyTools::getIP(); if ( $wgEnableSorbs && !in_array( $ip, $wgProxyWhitelist ) && $wgUser->inSorbsBlacklist( $ip ) ) { @@ -416,7 +416,7 @@ class LoginForm { $u->saveSettings(); - $ip = wfGetIP(); + $ip = ProxyTools::getIP(); if ( '' == $ip ) { $ip = '(Unknown)'; } $m = wfMsg( 'passwordremindertext', $ip, $u->getName(), $np, $wgServer . $wgScript ); diff --git a/includes/SpecialVersion.php b/includes/SpecialVersion.php index 5f7e857f3f..c941e2badd 100644 --- a/includes/SpecialVersion.php +++ b/includes/SpecialVersion.php @@ -190,7 +190,7 @@ class SpecialVersion { * @return string */ function IPInfo() { - $ip = str_replace( '--', ' - ', htmlspecialchars( wfGetIP() ) ); + $ip = str_replace( '--', ' - ', htmlspecialchars( ProxyTools::getIP() ) ); return "\n" . "visited from $ip"; } diff --git a/includes/Title.php b/includes/Title.php index 1e87fd8a8d..f86bf3eb5b 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -5,9 +5,6 @@ * @package MediaWiki */ -/** */ -require_once( 'normal/UtfNormal.php' ); - $wgTitleInterwikiCache = array(); $wgTitleCache = array(); @@ -334,7 +331,6 @@ class Title { */ /* static */ function indexTitle( $ns, $title ) { global $wgContLang; - require_once( 'SearchEngine.php' ); $lc = SearchEngine::legalSearchChars() . '&#;'; $t = $wgContLang->stripForSearch( $title ); @@ -1162,8 +1158,7 @@ class Title { * Check that the corresponding skin exists */ function isValidCssJsSubpage() { - global $wgValidSkinNames; - return( $this->isCssJsSubpage() && array_key_exists( $this->getSkinFromCssJsSubpage(), $wgValidSkinNames ) ); + return( $this->isCssJsSubpage() && array_key_exists( $this->getSkinFromCssJsSubpage(), Skin::getSkinNames() ) ); } /** * Trim down a .css or .js subpage title to get the corresponding skin name diff --git a/includes/UpdateClasses.php b/includes/UpdateClasses.php index e6da731db3..d3c2b032ba 100644 --- a/includes/UpdateClasses.php +++ b/includes/UpdateClasses.php @@ -5,13 +5,4 @@ * @package MediaWiki */ -/** - * - */ - -require_once( 'SiteStatsUpdate.php' ); -require_once( 'LinksUpdate.php' ); -require_once( 'SearchUpdate.php' ); -require_once( 'SquidUpdate.php' ); - ?> \ No newline at end of file diff --git a/includes/User.php b/includes/User.php index 15d469a5a8..a9ab11830b 100644 --- a/includes/User.php +++ b/includes/User.php @@ -5,11 +5,6 @@ * @package MediaWiki */ -/** - * - */ -require_once( 'WatchedItem.php' ); - # Number of characters in user_token field define( 'USER_TOKEN_LENGTH', 32 ); @@ -433,7 +428,7 @@ class User { wfDebug( "$fname: checking...\n" ); $this->mBlockedby = 0; - $ip = wfGetIP(); + $ip = ProxyTools::getIP(); # User/IP blocking $block = new Block(); @@ -454,7 +449,7 @@ class User { if ( !$this->isAllowed('proxyunbannable') && !in_array( $ip, $wgProxyWhitelist ) ) { # Local list - if ( wfIsLocallyBlockedProxy( $ip ) ) { + if ( ProxyTools::isLocallyBlockedProxy( $ip ) ) { $this->mBlockedby = wfMsg( 'proxyblocker' ); $this->mBlockreason = wfMsg( 'proxyblockreason' ); } @@ -538,7 +533,7 @@ class User { $limits = $wgRateLimits[$action]; $keys = array(); $id = $this->getId(); - $ip = wfGetIP(); + $ip = ProxyTools::getIP(); if( isset( $limits['anon'] ) && $id == 0 ) { $keys["$wgDBname:limiter:$action:anon"] = $limits['anon']; @@ -790,7 +785,7 @@ class User { function getName() { $this->loadFromDatabase(); if ( $this->mName === false ) { - $this->mName = wfGetIP(); + $this->mName = ProxyTools::getIP(); } return $this->mName; } @@ -1526,7 +1521,7 @@ class User { } # Check if this IP address is already blocked - $ipblock = Block::newFromDB( wfGetIP() ); + $ipblock = Block::newFromDB( ProxyTools::getIP() ); if ( $ipblock->isValid() ) { # If the user is already blocked. Then check if the autoblock would # excede the user block. If it would excede, then do nothing, else @@ -1541,8 +1536,8 @@ class User { } # Make a new block object with the desired properties - wfDebug( "Autoblocking {$this->mName}@" . wfGetIP() . "\n" ); - $ipblock->mAddress = wfGetIP(); + wfDebug( "Autoblocking {$this->mName}@" . ProxyTools::getIP() . "\n" ); + $ipblock->mAddress = ProxyTools::getIP(); $ipblock->mUser = 0; $ipblock->mBy = $userblock->mBy; $ipblock->mReason = wfMsg( 'autoblocker', $this->getName(), $userblock->mReason ); @@ -1762,7 +1757,7 @@ class User { $url = $this->confirmationTokenUrl( $expiration ); return $this->sendMail( wfMsg( 'confirmemail_subject' ), wfMsg( 'confirmemail_body', - wfGetIP(), + ProxyTools::getIP(), $this->getName(), $url, $wgContLang->timeanddate( $expiration, false ) ) ); diff --git a/includes/WebRequest.php b/includes/WebRequest.php index 736e215fdd..efae012faa 100644 --- a/includes/WebRequest.php +++ b/includes/WebRequest.php @@ -117,7 +117,6 @@ class WebRequest { $data = $wgContLang->checkTitleEncoding( $data ); } } - require_once( 'normal/UtfNormal.php' ); $data = $this->normalizeUnicode( $data ); return $data; } else { diff --git a/includes/Wiki.php b/includes/Wiki.php index 187dc06f92..a134552e3f 100644 --- a/includes/Wiki.php +++ b/includes/Wiki.php @@ -176,10 +176,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 ); @@ -284,8 +282,6 @@ class MediaWiki { $n = intval( $wgJobRunRate ); } - require_once( 'JobQueue.php' ); - while ( $n-- && false != ($job = Job::pop())) { $output = $job->toString() . "\n"; if ( !$job->run() ) { @@ -359,8 +355,7 @@ class MediaWiki { } break; case 'credits': - require_once( 'includes/Credits.php' ); - showCreditsPage( $article ); + Credits::showCreditsPage( $article ); break; case 'submit': if( !$this->getVal( 'CommandLineMode' ) && !$request->checkSessionCookie() ) { @@ -375,11 +370,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(); @@ -389,12 +382,10 @@ 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; -- 2.20.1