# Don't change the following default, NS_MAIN is hardcoded in several
# places. See bug 696.
var $mDefaultNamespace = NS_MAIN; // /< Namespace index when there is no namespace
- # Zero except in {{transclusion}} tags
+ # Zero except in {{transclusion}} tags
var $mWatched = null; // /< Is $wgUser watching this page? null if unfilled, accessed through userIsWatching()
var $mLength = -1; // /< The page length, 0 for special pages
var $mRedirect = null; // /< Is the article at this title a redirect?
return array();
}
$dbr = wfGetDB( DB_SLAVE );
-
+
$res = $dbr->select(
'page',
array(
*/
public static function newFromRedirectArray( $text ) {
global $wgMaxRedirects;
- // are redirects disabled?
- if ( $wgMaxRedirects < 1 ) {
- return null;
- }
$title = self::newFromRedirectInternal( $text );
if ( is_null( $title ) ) {
return null;
* @return Title
*/
protected static function newFromRedirectInternal( $text ) {
+ global $wgMaxRedirects;
+ if ( $wgMaxRedirects < 1 ) {
+ //redirects are disabled, so quit early
+ return null;
+ }
$redir = MagicWord::get( 'redirect' );
$text = trim( $text );
if ( $redir->matchStartAndRemove( $text ) ) {
return MWNamespace::getCanonicalName( $this->mNamespace );
}
}
+
+ if ( $wgContLang->needsGenderDistinction() &&
+ MWNamespace::hasGenderDistinction( $this->mNamespace ) ) {
+ $gender = GenderCache::singleton()->getGenderOf( $this->getText(), __METHOD__ );
+ return $wgContLang->getGenderNsText( $this->mNamespace, $gender );
+ }
+
return $wgContLang->getNsText( $this->mNamespace );
}
* @return String the URL
*/
public function getInternalURL( $query = '', $variant = false ) {
- global $wgInternalServer;
- $url = $wgInternalServer . $this->getLocalURL( $query, $variant );
+ global $wgInternalServer, $wgServer;
+ $server = $wgInternalServer !== false ? $wgInternalServer : $wgServer;
+ $url = $server . $this->getLocalURL( $query, $variant );
wfRunHooks( 'GetInternalURL', array( &$this, &$url, $query ) );
return $url;
}
/**
* Check restrictions on cascading pages.
- *
+ *
* @param $action String the action to check
* @param $user User to check
* @param $errors Array list of current errors
* cache that we don't need to over-optimize by doing direct comparisons and
* acidentally creating new bugs where $title->equals( Title::newFromText() )
* ends up reporting something differently than $title->isMainPage();
- *
+ *
* @return Bool
*/
public function isMainPage() {
* Is this a *valid* .css or .js subpage of a user page?
*
* @return Bool
- * @deprecated @since 1.17
+ * @deprecated since 1.17
*/
public function isValidCssJsSubpage() {
return $this->isCssJsSubpage();
public function userCanEditJsSubpage() {
global $wgUser;
return ( ( $wgUser->isAllowed( 'editusercssjs' ) && $wgUser->isAllowed( 'edituserjs' ) )
- || preg_match( '/^' . preg_quote( $wgUser->getName(), '/' ) . '\//', $this->mTextform ) );
+ || preg_match( '/^' . preg_quote( $wgUser->getName(), '/' ) . '\//', $this->mTextform ) );
}
/**
if ( $this->mInterwiki != '' ) {
$p = $this->mInterwiki . ':';
}
+
if ( 0 != $this->mNamespace ) {
$p .= $this->getNsText() . ':';
}
# Redundant interwiki prefix to the local wiki
if ( $wgLocalInterwiki !== false
- && 0 == strcasecmp( $this->mInterwiki, $wgLocalInterwiki ) )
+ && 0 == strcasecmp( $this->mInterwiki, $wgLocalInterwiki ) )
{
if ( $dbkey == '' ) {
# Can't have an empty self-link
# reachable due to the way web browsers deal with 'relative' URLs.
# Also, they conflict with subpage syntax. Forbid them explicitly.
if ( strpos( $dbkey, '.' ) !== false &&
- ( $dbkey === '.' || $dbkey === '..' ||
- strpos( $dbkey, './' ) === 0 ||
- strpos( $dbkey, '../' ) === 0 ||
- strpos( $dbkey, '/./' ) !== false ||
- strpos( $dbkey, '/../' ) !== false ||
- substr( $dbkey, -2 ) == '/.' ||
- substr( $dbkey, -3 ) == '/..' ) )
+ ( $dbkey === '.' || $dbkey === '..' ||
+ strpos( $dbkey, './' ) === 0 ||
+ strpos( $dbkey, '../' ) === 0 ||
+ strpos( $dbkey, '/./' ) !== false ||
+ strpos( $dbkey, '/../' ) !== false ||
+ substr( $dbkey, -2 ) == '/.' ||
+ substr( $dbkey, -3 ) == '/..' ) )
{
return false;
}
}
if ( ( $this->getDBkey() == '' ) ||
( !$oldid ) ||
- ( $nt->getDBkey() == '' ) ) {
+ ( $nt->getDBkey() == '' ) ) {
$errors[] = array( 'badarticleerror' );
}
// Image-specific checks
if ( $this->getNamespace() == NS_FILE ) {
- if ( $nt->getNamespace() != NS_FILE ) {
- $errors[] = array( 'imagenocrossnamespace' );
- }
- $file = wfLocalFile( $this );
- if ( $file->exists() ) {
- if ( $nt->getText() != wfStripIllegalFilenameChars( $nt->getText() ) ) {
- $errors[] = array( 'imageinvalidfilename' );
- }
- if ( !File::checkExtensionCompatibility( $file, $nt->getDBkey() ) ) {
- $errors[] = array( 'imagetypemismatch' );
- }
- }
- $destfile = wfLocalFile( $nt );
- if ( !$wgUser->isAllowed( 'reupload-shared' ) && !$destfile->exists() && wfFindFile( $nt ) ) {
- $errors[] = array( 'file-exists-sharedrepo' );
- }
+ $errors = array_merge( $errors, $this->validateFileMoveOperation( $nt ) );
}
-
+
if ( $nt->getNamespace() == NS_FILE && $this->getNamespace() != NS_FILE ) {
$errors[] = array( 'nonfile-cannot-move-to-file' );
}
}
return $errors;
}
+
+ /**
+ * Check if the requested move target is a valid file move target
+ * @param Title $nt Target title
+ * @return array List of errors
+ */
+ protected function validateFileMoveOperation( $nt ) {
+ global $wgUser;
+
+ $errors = array();
+
+ if ( $nt->getNamespace() != NS_FILE ) {
+ $errors[] = array( 'imagenocrossnamespace' );
+ }
+
+ $file = wfLocalFile( $this );
+ if ( $file->exists() ) {
+ if ( $nt->getText() != wfStripIllegalFilenameChars( $nt->getText() ) ) {
+ $errors[] = array( 'imageinvalidfilename' );
+ }
+ if ( !File::checkExtensionCompatibility( $file, $nt->getDBkey() ) ) {
+ $errors[] = array( 'imagetypemismatch' );
+ }
+ }
+
+ $destFile = wfLocalFile( $nt );
+ if ( !$wgUser->isAllowed( 'reupload-shared' ) && !$destfile->exists() && wfFindFile( $nt ) ) {
+ $errors[] = array( 'file-exists-sharedrepo' );
+ }
+
+ return $errors;
+ }
/**
* Move a title to a new location
);
$dbw->update( 'categorylinks',
array(
- 'cl_sortkey' => Collation::singleton()->getSortKey(
+ 'cl_sortkey' => Collation::singleton()->getSortKey(
$nt->getCategorySortkey( $prefix ) ),
'cl_timestamp=cl_timestamp' ),
array( 'cl_from' => $pageid ),
/**
* Callback for usort() to do title sorts by (namespace, title)
- *
+ *
+ * @param $a Title
+ * @param $b Title
+ *
* @return Integer: result of string comparison, or namespace comparison
*/
public static function compare( $a, $b ) {
// Spec: http://www.sixapart.com/pronet/docs/trackback_spec
return "<!--
<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"
- xmlns:dc=\"http://purl.org/dc/elements/1.1/\"
- xmlns:trackback=\"http://madskills.com/public/xml/rss/module/trackback/\">
+ xmlns:dc=\"http://purl.org/dc/elements/1.1/\"
+ xmlns:trackback=\"http://madskills.com/public/xml/rss/module/trackback/\">
<rdf:Description
rdf:about=\"$url\"
dc:identifier=\"$url\"
* @return array applicable restriction types
*/
public function getRestrictionTypes() {
- global $wgRestrictionTypes;
-
- $types = $this->exists() ? $wgRestrictionTypes : array( 'create' );
+ if ( $this->getNamespace() == NS_SPECIAL ) {
+ return array();
+ }
+
+ $types = self::getFilteredRestrictionTypes( $this->exists() );
if ( $this->getNamespace() != NS_FILE ) {
+ # Remove the upload restriction for non-file titles
$types = array_diff( $types, array( 'upload' ) );
}
-
+
wfRunHooks( 'TitleGetRestrictionTypes', array( $this, &$types ) );
+ wfDebug( __METHOD__ . ': applicable restriction types for ' .
+ $this->getPrefixedText() . ' are ' . implode( ',', $types ) . "\n" );
+
+ return $types;
+ }
+ /**
+ * Get a filtered list of all restriction types supported by this wiki.
+ * @param bool $exists True to get all restriction types that apply to
+ * titles that do exist, False for all restriction types that apply to
+ * titles that do not exist
+ * @return array
+ */
+ public static function getFilteredRestrictionTypes( $exists = true ) {
+ global $wgRestrictionTypes;
+ $types = $wgRestrictionTypes;
+ if ( $exists ) {
+ # Remove the create restriction for existing titles
+ $types = array_diff( $types, array( 'create' ) );
+ } else {
+ # Only the create and upload restrictions apply to non-existing titles
+ $types = array_intersect( $types, array( 'create', 'upload' ) );
+ }
return $types;
}