From: Sam Reed Date: Fri, 14 Oct 2011 21:18:38 +0000 (+0000) Subject: Update some deprecated code X-Git-Tag: 1.31.0-rc.0~27109 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/bilan.php?a=commitdiff_plain;h=27665d27ae0e545b341cc76940a9c78d8e0d21eb;p=lhc%2Fweb%2Fwiklou.git Update some deprecated code Documentation Fix "/*" comments to "/**" Flesh out some missing returns, change some return types --- diff --git a/api.php b/api.php index 5318aeaed9..a5a257992d 100644 --- a/api.php +++ b/api.php @@ -117,7 +117,7 @@ $processor = new ApiMain( $wgRequest, $wgEnableWriteAPI ); $processor->execute(); // Execute any deferred updates -wfDoUpdates(); +DeferredUpdates::doUpdates(); // Log what the user did, for book-keeping purposes. $endtime = microtime( true ); diff --git a/includes/Block.php b/includes/Block.php index 71e128d626..368ab81208 100644 --- a/includes/Block.php +++ b/includes/Block.php @@ -77,7 +77,7 @@ class Block { $this->mAuto = $auto; $this->isHardblock( !$anonOnly ); $this->prevents( 'createaccount', $createAccount ); - if ( $expiry == 'infinity' || $expiry == Block::infinity() ) { + if ( $expiry == 'infinity' || $expiry == wfGetDB( DB_SLAVE )->getInfinity() ) { $this->mExpiry = 'infinity'; } else { $this->mExpiry = wfTimestamp( TS_MW, $expiry ); diff --git a/includes/CategoryPage.php b/includes/CategoryPage.php index 95abd5e5dd..38cf01df7a 100644 --- a/includes/CategoryPage.php +++ b/includes/CategoryPage.php @@ -17,6 +17,15 @@ class CategoryPage extends Article { # Subclasses can change this to override the viewer class. protected $mCategoryViewerClass = 'CategoryViewer'; + /** + * @var Title + */ + protected $mTitle; + + /** + * @param $title Title + * @return WikiCategoryPage + */ protected function newPage( Title $title ) { // Overload mPage with a category-specific page return new WikiCategoryPage( $title ); @@ -69,7 +78,7 @@ class CategoryPage extends Article { $oldUntil = $request->getVal( 'until' ); $reqArray = $request->getValues(); - + $from = $until = array(); foreach ( array( 'page', 'subcat', 'file' ) as $type ) { $from[$type] = $request->getVal( "{$type}from", $oldFrom ); @@ -101,7 +110,7 @@ class CategoryViewer extends ContextSource { $imgsNoGallery; /** - * @var + * @var */ var $nextPage; @@ -236,7 +245,7 @@ class CategoryViewer extends ContextSource { } $this->children[] = $link; - $this->children_start_char[] = + $this->children_start_char[] = $this->getSubcategorySortChar( $cat->getTitle(), $sortkey ); } diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index daeb88b568..331742822c 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -3702,6 +3702,7 @@ $wgSummarySpamRegex = array(); * - false : let it through * * @deprecated since 1.17 Use hooks. See SpamBlacklist extension. + * @var callback */ $wgFilterCallback = false; diff --git a/includes/EditPage.php b/includes/EditPage.php index f2cdc00ef2..b34184f20d 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -923,7 +923,7 @@ class EditPage { wfProfileOut( __METHOD__ ); return $status; } - if ( $wgFilterCallback && $wgFilterCallback( $this->mTitle, $this->textbox1, $this->section, $this->hookError, $this->summary ) ) { + if ( $wgFilterCallback && is_callable( $wgFilterCallback ) && $wgFilterCallback( $this->mTitle, $this->textbox1, $this->section, $this->hookError, $this->summary ) ) { # Error messages or other handling should be performed by the filter function $status->setResult( false, self::AS_FILTERING ); wfProfileOut( __METHOD__ . '-checks' ); diff --git a/includes/Exception.php b/includes/Exception.php index f771af0680..c5abad0bee 100644 --- a/includes/Exception.php +++ b/includes/Exception.php @@ -53,7 +53,7 @@ class MWException extends Exception { global $wgExceptionHooks; if ( !isset( $wgExceptionHooks ) || !is_array( $wgExceptionHooks ) ) { - return; // Just silently ignore + return; // Just silently ignore } if ( !array_key_exists( $name, $wgExceptionHooks ) || !is_array( $wgExceptionHooks[ $name ] ) ) { diff --git a/includes/RawPage.php b/includes/RawPage.php index 9ef4045fad..35b6fb3ffe 100644 --- a/includes/RawPage.php +++ b/includes/RawPage.php @@ -154,6 +154,7 @@ class RawPage { } else { return $this->getArticleText(); } + return ''; } function getArticleText() { diff --git a/includes/WikiFilePage.php b/includes/WikiFilePage.php index 2d8108fb0d..4997145638 100644 --- a/includes/WikiFilePage.php +++ b/includes/WikiFilePage.php @@ -5,6 +5,9 @@ * @ingroup Media */ class WikiFilePage extends WikiPage { + /** + * @var File + */ protected $mFile = false; // !< File object protected $mRepo = null; // !< protected $mFileLoaded = false; // !< @@ -43,6 +46,7 @@ class WikiFilePage extends WikiPage { } } $this->mRepo = $this->mFile->getRepo(); + return true; } public function getRedirectTarget() { @@ -77,7 +81,7 @@ class WikiFilePage extends WikiPage { if ( $this->mFile->isLocal() ) { return parent::isRedirect( $text ); } - + return (bool)$this->mFile->getRedirected(); } diff --git a/includes/db/LoadBalancer.php b/includes/db/LoadBalancer.php index cabda93e74..ef4408ace1 100644 --- a/includes/db/LoadBalancer.php +++ b/includes/db/LoadBalancer.php @@ -723,6 +723,9 @@ class LoadBalancer { wfProfileOut( __METHOD__ ); } + /** + * @return int + */ function getWriterIndex() { return 0; } diff --git a/includes/extauth/vB.php b/includes/extauth/vB.php index f516c4234f..0565a2e3a5 100644 --- a/includes/extauth/vB.php +++ b/includes/extauth/vB.php @@ -103,13 +103,14 @@ class ExternalUser_vB extends ExternalUser { private function getDb() { global $wgExternalAuthConf; - return new Database( - $wgExternalAuthConf['server'], - $wgExternalAuthConf['username'], - $wgExternalAuthConf['password'], - $wgExternalAuthConf['dbname'], - 0, - $wgExternalAuthConf['tablePrefix'] + return DatabaseBase::factory( 'mysql', + array( + 'host' => $wgExternalAuthConf['server'], + 'user' => $wgExternalAuthConf['username'], + 'password' => $wgExternalAuthConf['password'], + 'dbname' => $wgExternalAuthConf['dbname'], + 'tablePrefix' => $wgExternalAuthConf['tablePrefix'], + ) ); } diff --git a/includes/libs/CSSMin.php b/includes/libs/CSSMin.php index 4012b69552..225a8ab928 100644 --- a/includes/libs/CSSMin.php +++ b/includes/libs/CSSMin.php @@ -1,5 +1,5 @@ memoryLimit === false ) { - return; + return true; } $usage = memory_get_usage(); if ( $usage > $this->memoryLimit * 0.9 ) { diff --git a/includes/specials/SpecialImport.php b/includes/specials/SpecialImport.php index 165e337b39..d346c0ed92 100644 --- a/includes/specials/SpecialImport.php +++ b/includes/specials/SpecialImport.php @@ -112,11 +112,11 @@ class SpecialImport extends SpecialPage { if( $user->isAllowed( 'importupload' ) ) { $source = ImportStreamSource::newFromUpload( "xmlimport" ); } else { - return $this->getOutput()->permissionRequired( 'importupload' ); + throw new PermissionsError( 'importupload' ); } } elseif ( $sourceName == "interwiki" ) { if( !$user->isAllowed( 'import' ) ){ - return $this->getOutput()->permissionRequired( 'import' ); + throw new PermissionsError( 'import' ); } $this->interwiki = $request->getVal( 'interwiki' ); if ( !in_array( $this->interwiki, $wgImportSources ) ) { diff --git a/includes/specials/SpecialUploadStash.php b/includes/specials/SpecialUploadStash.php index 9dd78efa3d..8901fa5a73 100644 --- a/includes/specials/SpecialUploadStash.php +++ b/includes/specials/SpecialUploadStash.php @@ -35,7 +35,6 @@ class SpecialUploadStash extends UnlistedSpecialPage { try { $this->stash = RepoGroup::singleton()->getLocalRepo()->getUploadStash(); } catch ( UploadStashNotAvailableException $e ) { - return null; } } @@ -48,17 +47,15 @@ class SpecialUploadStash extends UnlistedSpecialPage { public function execute( $subPage ) { if ( !$this->userCanExecute( $this->getUser() ) ) { $this->displayRestrictionError(); - return; + return false; } if ( $subPage === null || $subPage === '' ) { return $this->showUploads(); - } else { - return $this->showUpload( $subPage ); } + return $this->showUpload( $subPage ); } - /** * If file available in stash, cats it out to the client as a simple HTTP response. * n.b. Most sanity checking done in UploadStashLocalFile, so this is straightforward. @@ -206,7 +203,7 @@ class SpecialUploadStash extends UnlistedSpecialPage { // do not use trailing slash global $wgUploadStashScalerBaseUrl; $scalerBaseUrl = $wgUploadStashScalerBaseUrl; - + if( preg_match( '/^\/\//', $scalerBaseUrl ) ) { // this is apparently a protocol-relative URL, which makes no sense in this context, // since this is used for communication that's internal to the application. diff --git a/includes/upload/UploadFromStash.php b/includes/upload/UploadFromStash.php index 62c672387a..8392270f3c 100644 --- a/includes/upload/UploadFromStash.php +++ b/includes/upload/UploadFromStash.php @@ -9,13 +9,18 @@ class UploadFromStash extends UploadBase { protected $mFileKey, $mVirtualTempPath, $mFileProps, $mSourceType; - + // an instance of UploadStash private $stash; - + //LocalFile repo private $repo; - + + /** + * @param $user User + * @param $stash UploadStash + * @param $repo FileRepo + */ public function __construct( $user = false, $stash = false, $repo = false ) { // user object. sometimes this won't exist, as when running from cron. $this->user = $user; @@ -40,7 +45,11 @@ class UploadFromStash extends UploadBase { return true; } - + + /** + * @param $key string + * @return bool + */ public static function isValidKey( $key ) { // this is checked in more detail in UploadStash return (bool)preg_match( UploadStash::KEY_FORMAT_REGEX, $key ); @@ -58,13 +67,17 @@ class UploadFromStash extends UploadBase { return self::isValidKey( $request->getText( 'wpFileKey', $request->getText( 'wpSessionKey' ) ) ); } + /** + * @param $key string + * @param $name string + */ public function initialize( $key, $name = 'upload_file' ) { /** * Confirming a temporarily stashed upload. * We don't want path names to be forged, so we keep * them in the session on the server and just give * an opaque key to the user agent. - */ + */ $metadata = $this->stash->getMetadata( $key ); $this->initializePathInfo( $name, $this->getRealPath ( $metadata['us_path'] ), @@ -91,8 +104,11 @@ class UploadFromStash extends UploadBase { return $this->initialize( $fileKey, $desiredDestName ); } - public function getSourceType() { - return $this->mSourceType; + /** + * @return string + */ + public function getSourceType() { + return $this->mSourceType; } /** @@ -106,6 +122,8 @@ class UploadFromStash extends UploadBase { /** * Stash the file. + * + * @return UploadStashFile */ public function stashFile() { // replace mLocalFile with an instance of UploadStashFile, which adds some methods @@ -131,6 +149,11 @@ class UploadFromStash extends UploadBase { /** * Perform the upload, then remove the database record afterward. + * @param $comment string + * @param $pageText string + * @param $watch bool + * @param $user User + * @return Status */ public function performUpload( $comment, $pageText, $watch, $user ) { $rv = parent::performUpload( $comment, $pageText, $watch, $user ); @@ -141,7 +164,7 @@ class UploadFromStash extends UploadBase { /** * Append a chunk to the temporary file. * - * @return void + * @return Status */ public function appendChunk($chunk, $chunkSize, $offset) { //to use $this->getFileSize() here, db needs to be updated @@ -153,7 +176,7 @@ class UploadFromStash extends UploadBase { //append chunk if ( $fileSize == $offset ) { $status = $this->appendToUploadFile( $chunk, - $this->mVirtualTempPath ); + $this->mVirtualTempPath ); } else { $status = Status::newFatal( 'invalid-chunk-offset' ); } diff --git a/maintenance/cleanupImages.php b/maintenance/cleanupImages.php index 378161684f..267061009a 100644 --- a/maintenance/cleanupImages.php +++ b/maintenance/cleanupImages.php @@ -89,6 +89,9 @@ class ImageCleanup extends TableCleanup { $this->progress( 0 ); } + /** + * @param $name string + */ private function killRow( $name ) { if ( $this->dryrun ) { $this->output( "DRY RUN: would delete bogus row '$name'\n" ); diff --git a/maintenance/reassignEdits.php b/maintenance/reassignEdits.php index bb34e51c7b..20de17e6e5 100644 --- a/maintenance/reassignEdits.php +++ b/maintenance/reassignEdits.php @@ -139,8 +139,8 @@ class ReassignEdits extends Maintenance { * i.e. user => id, user_text => text * * @param $user User for the spec - * @param $idfield Field name containing the identifier - * @param $utfield Field name containing the user text + * @param $idfield string Field name containing the identifier + * @param $utfield string Field name containing the user text * @return array */ private function userSpecification( &$user, $idfield, $utfield ) { diff --git a/tests/phpunit/includes/TitlePermissionTest.php b/tests/phpunit/includes/TitlePermissionTest.php index 7016164d4a..a91c1613a2 100644 --- a/tests/phpunit/includes/TitlePermissionTest.php +++ b/tests/phpunit/includes/TitlePermissionTest.php @@ -5,12 +5,16 @@ */ class TitlePermissionTest extends MediaWikiLangTestCase { protected $title; - protected $user; - protected $anonUser; - protected $userUser; - protected $altUser; - protected $userName; - protected $altUserName; + + /** + * @var User + */ + protected $user, $anonUser, $userUser, $altUser; + + /** + * @var string + */ + protected $userName, $altUserName; function setUp() { global $wgLocaltimezone, $wgLocalTZoffset, $wgMemc, $wgContLang, $wgLang; @@ -64,7 +68,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase { for ($i = 0; $i < 100; $i++) { $this->user->mRights[$i] = $perm; } - + // Hack, hack hack ... $this->user->mRights['*'] = $perm; } @@ -543,7 +547,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase { $this->setTitle( NS_MAIN, "test page" ); $this->title->mTitleProtection['pt_create_perm'] = ''; $this->title->mTitleProtection['pt_user'] = $this->user->getID(); - $this->title->mTitleProtection['pt_expiry'] = Block::infinity(); + $this->title->mTitleProtection['pt_expiry'] = wfGetDB( DB_SLAVE )->getInfinity(); $this->title->mTitleProtection['pt_reason'] = 'test'; $this->title->mCascadeRestriction = false;