/**
* Returns the DB name of the distant wiki which owns the object.
*
- * @return string The DB name
+ * @return string|false The DB name
*/
public function getTransWikiID() {
if ( !$this->isExternal() ) {
/**
* Get the namespace text
*
- * @return string Namespace text
+ * @return string|false Namespace text
*/
public function getNsText() {
if ( $this->isExternal() ) {
&& ( $this->hasContentModel( CONTENT_MODEL_CSS )
|| $this->hasContentModel( CONTENT_MODEL_JAVASCRIPT ) );
- # @note This hook is also called in ContentHandler::getDefaultModel.
- # It's called here again to make sure hook functions can force this
- # method to return true even outside the MediaWiki namespace.
-
- Hooks::run( 'TitleIsCssOrJsPage', [ $this, &$isCssOrJsPage ], '1.25' );
-
return $isCssOrJsPage;
}
*
* @since 1.19 (r105919)
* @param array|string $query
- * @param bool $query2
+ * @param string|string[]|bool $query2
* @return string
*/
private static function fixUrlQueryArgs( $query, $query2 = false ) {
*
* @see self::getLocalURL for the arguments.
* @see wfExpandUrl
- * @param array|string $query
- * @param bool $query2
+ * @param string|string[] $query
+ * @param string|string[]|bool $query2
* @param string $proto Protocol type to use in URL
* @return string The URL
*/
# Finally, add the fragment.
$url .= $this->getFragmentForURL();
-
- Hooks::run( 'GetFullURL', [ &$this, &$url, $query ] );
+ // Avoid PHP 7.1 warning from passing $this by reference
+ $titleRef = $this;
+ Hooks::run( 'GetFullURL', [ &$titleRef, &$url, $query ] );
return $url;
}
* valid to link, locally, to the current Title.
* @see self::newFromText to produce a Title object.
*
- * @param string|array $query An optional query string,
+ * @param string|string[] $query An optional query string,
* not used for interwiki links. Can be specified as an associative array as well,
* e.g., array( 'action' => 'edit' ) (keys and values will be URL-escaped).
* Some query patterns will trigger various shorturl path replacements.
- * @param array $query2 An optional secondary query array. This one MUST
+ * @param string|string[]|bool $query2 An optional secondary query array. This one MUST
* be an array. If a string is passed it will be interpreted as a deprecated
* variant argument and urlencoded into a variant= argument.
* This second query argument will be added to the $query
$dbkey = wfUrlencode( $this->getPrefixedDBkey() );
if ( $query == '' ) {
$url = str_replace( '$1', $dbkey, $wgArticlePath );
- Hooks::run( 'GetLocalURL::Article', [ &$this, &$url ] );
+ // Avoid PHP 7.1 warning from passing $this by reference
+ $titleRef = $this;
+ Hooks::run( 'GetLocalURL::Article', [ &$titleRef, &$url ] );
} else {
global $wgVariantArticlePath, $wgActionPaths, $wgContLang;
$url = false;
$url = "{$wgScript}?title={$dbkey}&{$query}";
}
}
-
- Hooks::run( 'GetLocalURL::Internal', [ &$this, &$url, $query ] );
+ // Avoid PHP 7.1 warning from passing $this by reference
+ $titleRef = $this;
+ Hooks::run( 'GetLocalURL::Internal', [ &$titleRef, &$url, $query ] );
// @todo FIXME: This causes breakage in various places when we
// actually expected a local URL and end up with dupe prefixes.
$url = $wgServer . $url;
}
}
- Hooks::run( 'GetLocalURL', [ &$this, &$url, $query ] );
+ // Avoid PHP 7.1 warning from passing $this by reference
+ $titleRef = $this;
+ Hooks::run( 'GetLocalURL', [ &$titleRef, &$url, $query ] );
return $url;
}
* The result obviously should not be URL-escaped, but does need to be
* HTML-escaped if it's being output in HTML.
*
- * @param array $query
+ * @param string|string[] $query
* @param bool $query2
* @param string|int|bool $proto A PROTO_* constant on how the URL should be expanded,
* or false (default) for no expansion
$query = self::fixUrlQueryArgs( $query, $query2 );
$server = $wgInternalServer !== false ? $wgInternalServer : $wgServer;
$url = wfExpandUrl( $server . $this->getLocalURL( $query ), PROTO_HTTP );
- Hooks::run( 'GetInternalURL', [ &$this, &$url, $query ] );
+ // Avoid PHP 7.1 warning from passing $this by reference
+ $titleRef = $this;
+ Hooks::run( 'GetInternalURL', [ &$titleRef, &$url, $query ] );
return $url;
}
public function getCanonicalURL( $query = '', $query2 = false ) {
$query = self::fixUrlQueryArgs( $query, $query2 );
$url = wfExpandUrl( $this->getLocalURL( $query ) . $this->getFragmentForURL(), PROTO_CANONICAL );
- Hooks::run( 'GetCanonicalURL', [ &$this, &$url, $query ] );
+ // Avoid PHP 7.1 warning from passing $this by reference
+ $titleRef = $this;
+ Hooks::run( 'GetCanonicalURL', [ &$titleRef, &$url, $query ] );
return $url;
}
private function checkPermissionHooks( $action, $user, $errors, $rigor, $short ) {
// Use getUserPermissionsErrors instead
$result = '';
- if ( !Hooks::run( 'userCan', [ &$this, &$user, $action, &$result ] ) ) {
+ // Avoid PHP 7.1 warning from passing $this by reference
+ $titleRef = $this;
+ if ( !Hooks::run( 'userCan', [ &$titleRef, &$user, $action, &$result ] ) ) {
return $result ? [] : [ [ 'badaccess-group0' ] ];
}
// Check getUserPermissionsErrors hook
- if ( !Hooks::run( 'getUserPermissionsErrors', [ &$this, &$user, $action, &$result ] ) ) {
+ // Avoid PHP 7.1 warning from passing $this by reference
+ $titleRef = $this;
+ if ( !Hooks::run( 'getUserPermissionsErrors', [ &$titleRef, &$user, $action, &$result ] ) ) {
$errors = $this->resultToError( $errors, $result );
}
// Check getUserPermissionsErrorsExpensive hook
if (
$rigor !== 'quick'
&& !( $short && count( $errors ) > 0 )
- && !Hooks::run( 'getUserPermissionsErrorsExpensive', [ &$this, &$user, $action, &$result ] )
+ && !Hooks::run( 'getUserPermissionsErrorsExpensive', [ &$titleRef, &$user, $action, &$result ] )
) {
$errors = $this->resultToError( $errors, $result );
}
*
* @param string $action The action to check
* @param bool $short Short circuit on first error
- * @return array List of errors
+ * @return array Array containing an error message key and any parameters
*/
private function missingPermissionError( $action, $short ) {
// We avoid expensive display logic for quickUserCan's and such
return [ 'badaccess-group0' ];
}
- $groups = array_map( [ 'User', 'makeGroupLinkWiki' ],
- User::getGroupsWithPermission( $action ) );
-
- if ( count( $groups ) ) {
- global $wgLang;
- return [
- 'badaccess-groups',
- $wgLang->commaList( $groups ),
- count( $groups )
- ];
- } else {
- return [ 'badaccess-group0' ];
- }
+ return User::newFatalPermissionDeniedStatus( $action )->getErrorsArray()[0];
}
/**
);
}
- /**
- * Move this page without authentication
- *
- * @deprecated since 1.25 use MovePage class instead
- * @param Title $nt The new page Title
- * @return array|bool True on success, getUserPermissionsErrors()-like array on failure
- */
- public function moveNoAuth( &$nt ) {
- wfDeprecated( __METHOD__, '1.25' );
- return $this->moveTo( $nt, false );
- }
-
/**
* Check whether a given move operation would be valid.
* Returns true if ok, or a getUserPermissionsErrors()-like array otherwise
* @param string $reason The reason for the move
* @param bool $createRedirect Whether to create a redirect from the old title to the new title.
* Ignored if the user doesn't have the suppressredirect right.
+ * @param array $changeTags Applied to the entry in the move log and redirect page revision
* @return array|bool True on success, getUserPermissionsErrors()-like array on failure
*/
- public function moveTo( &$nt, $auth = true, $reason = '', $createRedirect = true ) {
+ public function moveTo( &$nt, $auth = true, $reason = '', $createRedirect = true,
+ array $changeTags = [] ) {
+
global $wgUser;
$err = $this->isValidMoveOperation( $nt, $auth, $reason );
if ( is_array( $err ) ) {
}
$mp = new MovePage( $this, $nt );
- $status = $mp->move( $wgUser, $reason, $createRedirect );
+ $status = $mp->move( $wgUser, $reason, $createRedirect, $changeTags );
if ( $status->isOK() ) {
return true;
} else {
* @param string $reason The reason for the move
* @param bool $createRedirect Whether to create redirects from the old subpages to
* the new ones Ignored if the user doesn't have the 'suppressredirect' right
+ * @param array $changeTags Applied to the entry in the move log and redirect page revision
* @return array Array with old page titles as keys, and strings (new page titles) or
- * arrays (errors) as values, or an error array with numeric indices if no pages
- * were moved
+ * getUserPermissionsErrors()-like arrays (errors) as values, or a
+ * getUserPermissionsErrors()-like error array with numeric indices if
+ * no pages were moved
*/
- public function moveSubpages( $nt, $auth = true, $reason = '', $createRedirect = true ) {
+ public function moveSubpages( $nt, $auth = true, $reason = '', $createRedirect = true,
+ array $changeTags = [] ) {
+
global $wgMaximumMovedPages;
// Check permissions
if ( !$this->userCan( 'move-subpages' ) ) {
- return [ 'cant-move-subpages' ];
+ return [
+ [ 'cant-move-subpages' ],
+ ];
}
// Do the source and target namespaces support subpages?
if ( !MWNamespace::hasSubpages( $this->getNamespace() ) ) {
- return [ 'namespace-nosubpages',
- MWNamespace::getCanonicalName( $this->getNamespace() ) ];
+ return [
+ [ 'namespace-nosubpages', MWNamespace::getCanonicalName( $this->getNamespace() ) ],
+ ];
}
if ( !MWNamespace::hasSubpages( $nt->getNamespace() ) ) {
- return [ 'namespace-nosubpages',
- MWNamespace::getCanonicalName( $nt->getNamespace() ) ];
+ return [
+ [ 'namespace-nosubpages', MWNamespace::getCanonicalName( $nt->getNamespace() ) ],
+ ];
}
$subpages = $this->getSubpages( $wgMaximumMovedPages + 1 );
foreach ( $subpages as $oldSubpage ) {
$count++;
if ( $count > $wgMaximumMovedPages ) {
- $retval[$oldSubpage->getPrefixedText()] =
- [ 'movepage-max-pages',
- $wgMaximumMovedPages ];
+ $retval[$oldSubpage->getPrefixedText()] = [
+ [ 'movepage-max-pages', $wgMaximumMovedPages ],
+ ];
break;
}
# be longer than 255 characters.
$newSubpage = Title::makeTitleSafe( $newNs, $newPageName );
- $success = $oldSubpage->moveTo( $newSubpage, $auth, $reason, $createRedirect );
+ $success = $oldSubpage->moveTo( $newSubpage, $auth, $reason, $createRedirect, $changeTags );
if ( $success === true ) {
$retval[$oldSubpage->getPrefixedText()] = $newSubpage->getPrefixedText();
} else {
* Get the last touched timestamp
*
* @param IDatabase $db Optional db
- * @return string Last-touched timestamp
+ * @return string|false Last-touched timestamp
*/
public function getTouched( $db = null ) {
if ( $db === null ) {