Completed
Branch master (939199)
by
unknown
39:35
created

includes/changetags/ChangeTagsList.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License as published by
5
 * the Free Software Foundation; either version 2 of the License, or
6
 * (at your option) any later version.
7
 *
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
 * GNU General Public License for more details.
12
 *
13
 * You should have received a copy of the GNU General Public License along
14
 * with this program; if not, write to the Free Software Foundation, Inc.,
15
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16
 * http://www.gnu.org/copyleft/gpl.html
17
 *
18
 * @file
19
 * @ingroup Change tagging
20
 */
21
22
/**
23
 * Generic list for change tagging.
24
 */
25
abstract class ChangeTagsList extends RevisionListBase {
26
	function __construct( IContextSource $context, Title $title, array $ids ) {
27
		parent::__construct( $context, $title );
28
		$this->ids = $ids;
29
	}
30
31
	/**
32
	 * Creates a ChangeTags*List of the requested type.
33
	 *
34
	 * @param string $typeName 'revision' or 'logentry'
35
	 * @param IContextSource $context
36
	 * @param Title $title
37
	 * @param array $ids
38
	 * @return ChangeTagsList An instance of the requested subclass
39
	 * @throws Exception If you give an unknown $typeName
40
	 */
41
	public static function factory( $typeName, IContextSource $context,
42
		Title $title, array $ids ) {
43
44
		switch ( $typeName ) {
45
			case 'revision':
46
				$className = 'ChangeTagsRevisionList';
47
				break;
48
			case 'logentry':
49
				$className = 'ChangeTagsLogList';
50
				break;
51
			default:
52
				throw new Exception( "Class $className requested, but does not exist" );
53
		}
54
		return new $className( $context, $title, $ids );
55
	}
56
57
	/**
58
	 * Reload the list data from the master DB.
59
	 */
60
	function reloadFromMaster() {
61
		$dbw = wfGetDB( DB_MASTER );
62
		$this->res = $this->doQuery( $dbw );
0 ignored issues
show
It seems like $dbw defined by wfGetDB(DB_MASTER) on line 61 can be null; however, RevisionListBase::doQuery() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
63
	}
64
65
	/**
66
	 * Add/remove change tags from all the items in the list.
67
	 *
68
	 * @param array $tagsToAdd
69
	 * @param array $tagsToRemove
70
	 * @param array $params
71
	 * @param string $reason
72
	 * @param User $user
73
	 * @return Status
74
	 */
75
	abstract function updateChangeTagsOnAll( $tagsToAdd, $tagsToRemove, $params,
76
		$reason, $user );
77
}
78