r99808 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99807‎ | r99808 | r99809 >
Date:21:18, 14 October 2011
Author:reedy
Status:ok (Comments)
Tags:
Comment:
Update some deprecated code

Documentation

Fix "/*" comments to "/**"

Flesh out some missing returns, change some return types
Modified paths:
  • /trunk/phase3/api.php (modified) (history)
  • /trunk/phase3/includes/Block.php (modified) (history)
  • /trunk/phase3/includes/CategoryPage.php (modified) (history)
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/EditPage.php (modified) (history)
  • /trunk/phase3/includes/Exception.php (modified) (history)
  • /trunk/phase3/includes/RawPage.php (modified) (history)
  • /trunk/phase3/includes/WikiFilePage.php (modified) (history)
  • /trunk/phase3/includes/db/LoadBalancer.php (modified) (history)
  • /trunk/phase3/includes/extauth/vB.php (modified) (history)
  • /trunk/phase3/includes/libs/CSSMin.php (modified) (history)
  • /trunk/phase3/includes/parser/Preprocessor_DOM.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialImport.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialUploadStash.php (modified) (history)
  • /trunk/phase3/includes/upload/UploadFromStash.php (modified) (history)
  • /trunk/phase3/maintenance/cleanupImages.php (modified) (history)
  • /trunk/phase3/maintenance/reassignEdits.php (modified) (history)
  • /trunk/phase3/tests/phpunit/includes/TitlePermissionTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/cleanupImages.php
@@ -89,6 +89,9 @@
9090 $this->progress( 0 );
9191 }
9292
 93+ /**
 94+ * @param $name string
 95+ */
9396 private function killRow( $name ) {
9497 if ( $this->dryrun ) {
9598 $this->output( "DRY RUN: would delete bogus row '$name'\n" );
Index: trunk/phase3/maintenance/reassignEdits.php
@@ -139,8 +139,8 @@
140140 * i.e. user => id, user_text => text
141141 *
142142 * @param $user User for the spec
143 - * @param $idfield Field name containing the identifier
144 - * @param $utfield Field name containing the user text
 143+ * @param $idfield string Field name containing the identifier
 144+ * @param $utfield string Field name containing the user text
145145 * @return array
146146 */
147147 private function userSpecification( &$user, $idfield, $utfield ) {
Index: trunk/phase3/tests/phpunit/includes/TitlePermissionTest.php
@@ -5,13 +5,17 @@
66 */
77 class TitlePermissionTest extends MediaWikiLangTestCase {
88 protected $title;
9 - protected $user;
10 - protected $anonUser;
11 - protected $userUser;
12 - protected $altUser;
13 - protected $userName;
14 - protected $altUserName;
159
 10+ /**
 11+ * @var User
 12+ */
 13+ protected $user, $anonUser, $userUser, $altUser;
 14+
 15+ /**
 16+ * @var string
 17+ */
 18+ protected $userName, $altUserName;
 19+
1620 function setUp() {
1721 global $wgLocaltimezone, $wgLocalTZoffset, $wgMemc, $wgContLang, $wgLang;
1822 parent::setUp();
@@ -64,7 +68,7 @@
6569 for ($i = 0; $i < 100; $i++) {
6670 $this->user->mRights[$i] = $perm;
6771 }
68 -
 72+
6973 // Hack, hack hack ...
7074 $this->user->mRights['*'] = $perm;
7175 }
@@ -543,7 +547,7 @@
544548 $this->setTitle( NS_MAIN, "test page" );
545549 $this->title->mTitleProtection['pt_create_perm'] = '';
546550 $this->title->mTitleProtection['pt_user'] = $this->user->getID();
547 - $this->title->mTitleProtection['pt_expiry'] = Block::infinity();
 551+ $this->title->mTitleProtection['pt_expiry'] = wfGetDB( DB_SLAVE )->getInfinity();
548552 $this->title->mTitleProtection['pt_reason'] = 'test';
549553 $this->title->mCascadeRestriction = false;
550554
Index: trunk/phase3/includes/upload/UploadFromStash.php
@@ -9,13 +9,18 @@
1010
1111 class UploadFromStash extends UploadBase {
1212 protected $mFileKey, $mVirtualTempPath, $mFileProps, $mSourceType;
13 -
 13+
1414 // an instance of UploadStash
1515 private $stash;
16 -
 16+
1717 //LocalFile repo
1818 private $repo;
19 -
 19+
 20+ /**
 21+ * @param $user User
 22+ * @param $stash UploadStash
 23+ * @param $repo FileRepo
 24+ */
2025 public function __construct( $user = false, $stash = false, $repo = false ) {
2126 // user object. sometimes this won't exist, as when running from cron.
2227 $this->user = $user;
@@ -40,7 +45,11 @@
4146
4247 return true;
4348 }
44 -
 49+
 50+ /**
 51+ * @param $key string
 52+ * @return bool
 53+ */
4554 public static function isValidKey( $key ) {
4655 // this is checked in more detail in UploadStash
4756 return (bool)preg_match( UploadStash::KEY_FORMAT_REGEX, $key );
@@ -58,13 +67,17 @@
5968 return self::isValidKey( $request->getText( 'wpFileKey', $request->getText( 'wpSessionKey' ) ) );
6069 }
6170
 71+ /**
 72+ * @param $key string
 73+ * @param $name string
 74+ */
6275 public function initialize( $key, $name = 'upload_file' ) {
6376 /**
6477 * Confirming a temporarily stashed upload.
6578 * We don't want path names to be forged, so we keep
6679 * them in the session on the server and just give
6780 * an opaque key to the user agent.
68 - */
 81+ */
6982 $metadata = $this->stash->getMetadata( $key );
7083 $this->initializePathInfo( $name,
7184 $this->getRealPath ( $metadata['us_path'] ),
@@ -91,8 +104,11 @@
92105 return $this->initialize( $fileKey, $desiredDestName );
93106 }
94107
95 - public function getSourceType() {
96 - return $this->mSourceType;
 108+ /**
 109+ * @return string
 110+ */
 111+ public function getSourceType() {
 112+ return $this->mSourceType;
97113 }
98114
99115 /**
@@ -106,6 +122,8 @@
107123
108124 /**
109125 * Stash the file.
 126+ *
 127+ * @return UploadStashFile
110128 */
111129 public function stashFile() {
112130 // replace mLocalFile with an instance of UploadStashFile, which adds some methods
@@ -131,6 +149,11 @@
132150
133151 /**
134152 * Perform the upload, then remove the database record afterward.
 153+ * @param $comment string
 154+ * @param $pageText string
 155+ * @param $watch bool
 156+ * @param $user User
 157+ * @return Status
135158 */
136159 public function performUpload( $comment, $pageText, $watch, $user ) {
137160 $rv = parent::performUpload( $comment, $pageText, $watch, $user );
@@ -141,7 +164,7 @@
142165 /**
143166 * Append a chunk to the temporary file.
144167 *
145 - * @return void
 168+ * @return Status
146169 */
147170 public function appendChunk($chunk, $chunkSize, $offset) {
148171 //to use $this->getFileSize() here, db needs to be updated
@@ -153,7 +176,7 @@
154177 //append chunk
155178 if ( $fileSize == $offset ) {
156179 $status = $this->appendToUploadFile( $chunk,
157 - $this->mVirtualTempPath );
 180+ $this->mVirtualTempPath );
158181 } else {
159182 $status = Status::newFatal( 'invalid-chunk-offset' );
160183 }
Index: trunk/phase3/includes/CategoryPage.php
@@ -17,6 +17,15 @@
1818 # Subclasses can change this to override the viewer class.
1919 protected $mCategoryViewerClass = 'CategoryViewer';
2020
 21+ /**
 22+ * @var Title
 23+ */
 24+ protected $mTitle;
 25+
 26+ /**
 27+ * @param $title Title
 28+ * @return WikiCategoryPage
 29+ */
2130 protected function newPage( Title $title ) {
2231 // Overload mPage with a category-specific page
2332 return new WikiCategoryPage( $title );
@@ -69,7 +78,7 @@
7079 $oldUntil = $request->getVal( 'until' );
7180
7281 $reqArray = $request->getValues();
73 -
 82+
7483 $from = $until = array();
7584 foreach ( array( 'page', 'subcat', 'file' ) as $type ) {
7685 $from[$type] = $request->getVal( "{$type}from", $oldFrom );
@@ -101,7 +110,7 @@
102111 $imgsNoGallery;
103112
104113 /**
105 - * @var
 114+ * @var
106115 */
107116 var $nextPage;
108117
@@ -236,7 +245,7 @@
237246 }
238247 $this->children[] = $link;
239248
240 - $this->children_start_char[] =
 249+ $this->children_start_char[] =
241250 $this->getSubcategorySortChar( $cat->getTitle(), $sortkey );
242251 }
243252
Index: trunk/phase3/includes/WikiFilePage.php
@@ -5,6 +5,9 @@
66 * @ingroup Media
77 */
88 class WikiFilePage extends WikiPage {
 9+ /**
 10+ * @var File
 11+ */
912 protected $mFile = false; // !< File object
1013 protected $mRepo = null; // !<
1114 protected $mFileLoaded = false; // !<
@@ -43,6 +46,7 @@
4447 }
4548 }
4649 $this->mRepo = $this->mFile->getRepo();
 50+ return true;
4751 }
4852
4953 public function getRedirectTarget() {
@@ -77,7 +81,7 @@
7882 if ( $this->mFile->isLocal() ) {
7983 return parent::isRedirect( $text );
8084 }
81 -
 85+
8286 return (bool)$this->mFile->getRedirected();
8387 }
8488
Index: trunk/phase3/includes/parser/Preprocessor_DOM.php
@@ -81,7 +81,7 @@
8282 */
8383 function memCheck() {
8484 if ( $this->memoryLimit === false ) {
85 - return;
 85+ return true;
8686 }
8787 $usage = memory_get_usage();
8888 if ( $usage > $this->memoryLimit * 0.9 ) {
Index: trunk/phase3/includes/db/LoadBalancer.php
@@ -723,6 +723,9 @@
724724 wfProfileOut( __METHOD__ );
725725 }
726726
 727+ /**
 728+ * @return int
 729+ */
727730 function getWriterIndex() {
728731 return 0;
729732 }
Index: trunk/phase3/includes/EditPage.php
@@ -923,7 +923,7 @@
924924 wfProfileOut( __METHOD__ );
925925 return $status;
926926 }
927 - if ( $wgFilterCallback && $wgFilterCallback( $this->mTitle, $this->textbox1, $this->section, $this->hookError, $this->summary ) ) {
 927+ if ( $wgFilterCallback && is_callable( $wgFilterCallback ) && $wgFilterCallback( $this->mTitle, $this->textbox1, $this->section, $this->hookError, $this->summary ) ) {
928928 # Error messages or other handling should be performed by the filter function
929929 $status->setResult( false, self::AS_FILTERING );
930930 wfProfileOut( __METHOD__ . '-checks' );
Index: trunk/phase3/includes/RawPage.php
@@ -154,6 +154,7 @@
155155 } else {
156156 return $this->getArticleText();
157157 }
 158+ return '';
158159 }
159160
160161 function getArticleText() {
Index: trunk/phase3/includes/libs/CSSMin.php
@@ -1,5 +1,5 @@
22 <?php
3 -/*
 3+/**
44 * Copyright 2010 Wikimedia Foundation
55 *
66 * Licensed under the Apache License, Version 2.0 (the "License"); you may
Index: trunk/phase3/includes/DefaultSettings.php
@@ -3702,6 +3702,7 @@
37033703 * - false : let it through
37043704 *
37053705 * @deprecated since 1.17 Use hooks. See SpamBlacklist extension.
 3706+ * @var callback
37063707 */
37073708 $wgFilterCallback = false;
37083709
Index: trunk/phase3/includes/specials/SpecialImport.php
@@ -112,11 +112,11 @@
113113 if( $user->isAllowed( 'importupload' ) ) {
114114 $source = ImportStreamSource::newFromUpload( "xmlimport" );
115115 } else {
116 - return $this->getOutput()->permissionRequired( 'importupload' );
 116+ throw new PermissionsError( 'importupload' );
117117 }
118118 } elseif ( $sourceName == "interwiki" ) {
119119 if( !$user->isAllowed( 'import' ) ){
120 - return $this->getOutput()->permissionRequired( 'import' );
 120+ throw new PermissionsError( 'import' );
121121 }
122122 $this->interwiki = $request->getVal( 'interwiki' );
123123 if ( !in_array( $this->interwiki, $wgImportSources ) ) {
Index: trunk/phase3/includes/specials/SpecialUploadStash.php
@@ -35,7 +35,6 @@
3636 try {
3737 $this->stash = RepoGroup::singleton()->getLocalRepo()->getUploadStash();
3838 } catch ( UploadStashNotAvailableException $e ) {
39 - return null;
4039 }
4140 }
4241
@@ -48,17 +47,15 @@
4948 public function execute( $subPage ) {
5049 if ( !$this->userCanExecute( $this->getUser() ) ) {
5150 $this->displayRestrictionError();
52 - return;
 51+ return false;
5352 }
5453
5554 if ( $subPage === null || $subPage === '' ) {
5655 return $this->showUploads();
57 - } else {
58 - return $this->showUpload( $subPage );
5956 }
 57+ return $this->showUpload( $subPage );
6058 }
6159
62 -
6360 /**
6461 * If file available in stash, cats it out to the client as a simple HTTP response.
6562 * n.b. Most sanity checking done in UploadStashLocalFile, so this is straightforward.
@@ -206,7 +203,7 @@
207204 // do not use trailing slash
208205 global $wgUploadStashScalerBaseUrl;
209206 $scalerBaseUrl = $wgUploadStashScalerBaseUrl;
210 -
 207+
211208 if( preg_match( '/^\/\//', $scalerBaseUrl ) ) {
212209 // this is apparently a protocol-relative URL, which makes no sense in this context,
213210 // since this is used for communication that's internal to the application.
Index: trunk/phase3/includes/Block.php
@@ -77,7 +77,7 @@
7878 $this->mAuto = $auto;
7979 $this->isHardblock( !$anonOnly );
8080 $this->prevents( 'createaccount', $createAccount );
81 - if ( $expiry == 'infinity' || $expiry == Block::infinity() ) {
 81+ if ( $expiry == 'infinity' || $expiry == wfGetDB( DB_SLAVE )->getInfinity() ) {
8282 $this->mExpiry = 'infinity';
8383 } else {
8484 $this->mExpiry = wfTimestamp( TS_MW, $expiry );
Index: trunk/phase3/includes/extauth/vB.php
@@ -103,13 +103,14 @@
104104
105105 private function getDb() {
106106 global $wgExternalAuthConf;
107 - return new Database(
108 - $wgExternalAuthConf['server'],
109 - $wgExternalAuthConf['username'],
110 - $wgExternalAuthConf['password'],
111 - $wgExternalAuthConf['dbname'],
112 - 0,
113 - $wgExternalAuthConf['tablePrefix']
 107+ return DatabaseBase::factory( 'mysql',
 108+ array(
 109+ 'host' => $wgExternalAuthConf['server'],
 110+ 'user' => $wgExternalAuthConf['username'],
 111+ 'password' => $wgExternalAuthConf['password'],
 112+ 'dbname' => $wgExternalAuthConf['dbname'],
 113+ 'tablePrefix' => $wgExternalAuthConf['tablePrefix'],
 114+ )
114115 );
115116 }
116117
Index: trunk/phase3/includes/Exception.php
@@ -53,7 +53,7 @@
5454 global $wgExceptionHooks;
5555
5656 if ( !isset( $wgExceptionHooks ) || !is_array( $wgExceptionHooks ) ) {
57 - return; // Just silently ignore
 57+ return; // Just silently ignore
5858 }
5959
6060 if ( !array_key_exists( $name, $wgExceptionHooks ) || !is_array( $wgExceptionHooks[ $name ] ) ) {
Index: trunk/phase3/api.php
@@ -117,7 +117,7 @@
118118 $processor->execute();
119119
120120 // Execute any deferred updates
121 -wfDoUpdates();
 121+DeferredUpdates::doUpdates();
122122
123123 // Log what the user did, for book-keeping purposes.
124124 $endtime = microtime( true );

Comments

#Comment by Raymond (talk | contribs)   17:26, 15 October 2011

PHP Fatal error: Call to a member function getNamespace() on a non-object in /www/w/includes/CategoryPage.php on line 59

#Comment by Reedy (talk | contribs)   17:35, 16 October 2011

I didn't touch that code in this revision

#Comment by Aaron Schulz (talk | contribs)   22:16, 8 December 2011

This made mTitle of CategoryPage now protected. Is no one accessing this?

#Comment by Reedy (talk | contribs)   22:35, 8 December 2011

Looking at the code in trunk...

	# Subclasses can change this to override the viewer class.
	protected $mCategoryViewerClass = 'CategoryViewer';

	/**
	 * @param $title Title
	 * @return WikiCategoryPage
	 */
	protected function newPage( Title $title ) {
		// Overload mPage with a category-specific page
		return new WikiCategoryPage( $title );
	}

It's either been replaced, or removed already

Status & tagging log