<?php
/**
* See title.txt
- *
+ * @file
*/
/** */
*/
static private $titleCache=array();
static private $interwikiCache=array();
-
-
+
+
/**
* All member variables should be considered private
* Please use the accessor functions
* but not used for anything else
*
* @param int $id the page_id corresponding to the Title to create
+ * @param int $flags, use GAID_FOR_UPDATE to use master
* @return Title the new object, or NULL on an error
*/
- public static function newFromID( $id ) {
+ public static function newFromID( $id, $flags = 0 ) {
$fname = 'Title::newFromID';
- $dbr = wfGetDB( DB_SLAVE );
- $row = $dbr->selectRow( 'page', array( 'page_namespace', 'page_title' ),
+ $db = ($flags & GAID_FOR_UPDATE) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE );
+ $row = $db->selectRow( 'page', array( 'page_namespace', 'page_title' ),
array( 'page_id' => $id ), $fname );
if ( $row !== false ) {
$title = Title::makeTitle( $row->page_namespace, $row->page_title );
}
/**
- * Make an array of titles from an array of IDs
+ * Make an array of titles from an array of IDs
*/
public static function newFromIDs( $ids ) {
if ( !count( $ids ) ) {
}
return $titles;
}
-
+
/**
* Make a Title object from a DB row
* @param Row $row (needs at least page_title,page_namespace)
return $s->iw_url;
}
-
+
/**
* Fetch interwiki prefix data from local cache in constant database
*
* @return string Base name
*/
public function getBaseText() {
- global $wgNamespacesWithSubpages;
- if( !empty( $wgNamespacesWithSubpages[$this->mNamespace] ) ) {
- $parts = explode( '/', $this->getText() );
- # Don't discard the real title if there's no subpage involved
- if( count( $parts ) > 1 )
- unset( $parts[ count( $parts ) - 1 ] );
- return implode( '/', $parts );
- } else {
+ if( !MWNamespace::hasSubpages( $this->mNamespace ) ) {
return $this->getText();
}
+
+ $parts = explode( '/', $this->getText() );
+ # Don't discard the real title if there's no subpage involved
+ if( count( $parts ) > 1 )
+ unset( $parts[ count( $parts ) - 1 ] );
+ return implode( '/', $parts );
}
/**
* @return string Subpage name
*/
public function getSubpageText() {
- global $wgNamespacesWithSubpages;
- if( isset( $wgNamespacesWithSubpages[ $this->mNamespace ] ) && $wgNamespacesWithSubpages[ $this->mNamespace ] ) {
- $parts = explode( '/', $this->mTextform );
- return( $parts[ count( $parts ) - 1 ] );
- } else {
+ if( !MWNamespace::hasSubpages( $this->mNamespace ) ) {
return( $this->mTextform );
}
+ $parts = explode( '/', $this->mTextform );
+ return( $parts[ count( $parts ) - 1 ] );
}
/**
$url = "{$wgScript}?title={$dbkey}&{$query}";
}
}
-
+
// FIXME: this causes breakage in various places when we
// actually expected a local URL and end up with dupe prefixes.
if ($wgRequest->getVal('action') == 'render') {
return true;
# Check regular protection levels
- foreach( $wgRestrictionTypes as $type ){
+ foreach( $wgRestrictionTypes as $type ){
if( $action == $type || $action == '' ) {
$r = $this->getRestrictions( $type );
foreach( $wgRestrictionLevels as $level ) {
* @return array Array of arrays of the arguments to wfMsg to explain permissions problems.
*/
public function getUserPermissionsErrors( $action, $user, $doExpensiveQueries = true ) {
+ if( !StubObject::isRealObject( $user ) ) {
+ //Since StubObject is always used on globals, we can unstub $wgUser here and set $user = $wgUser
+ global $wgUser;
+ $wgUser->_unstub( '', 5 );
+ $user = $wgUser;
+ }
$errors = $this->getUserPermissionsErrorsInternal( $action, $user, $doExpensiveQueries );
global $wgContLang;
global $wgLang;
global $wgEmailConfirmToEdit;
- if ( $wgEmailConfirmToEdit && !$user->isEmailConfirmed() ) {
+ if ( $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount' ) {
$errors[] = array( 'confirmedittext' );
}
$intended = $user->mBlock->mAddress;
- $errors[] = array ( ($block->mAuto ? 'autoblockedtext' : 'blockedtext'), $link, $reason, $ip, $name, $blockid, $blockExpiry, $intended, $blockTimestamp );
+ $errors[] = array( ($block->mAuto ? 'autoblockedtext' : 'blockedtext'), $link, $reason, $ip, $name,
+ $blockid, $blockExpiry, $intended, $blockTimestamp );
}
return $errors;
// Use getUserPermissionsErrors instead
if ( !wfRunHooks( 'userCan', array( &$this, &$user, $action, &$result ) ) ) {
+ wfProfileOut( __METHOD__ );
return $result ? array() : array( array( 'badaccess-group0' ) );
}
else if ($result === false )
$errors[] = array('badaccess-group0'); # a generic "We don't want them to do that"
}
-
- if( NS_SPECIAL == $this->mNamespace ) {
+
+ $specialOKActions = array( 'createaccount', 'execute' );
+ if( NS_SPECIAL == $this->mNamespace && !in_array( $action, $specialOKActions) ) {
$errors[] = array('ns-specialprotected');
}
-
+
if ( $this->isNamespaceProtected() ) {
$ns = $this->getNamespace() == NS_MAIN
? wfMsg( 'nstab-main' )
: $this->getNsText();
- $errors[] = (NS_MEDIAWIKI == $this->mNamespace
- ? array('protectedinterface')
+ $errors[] = (NS_MEDIAWIKI == $this->mNamespace
+ ? array('protectedinterface')
: array( 'namespaceprotected', $ns ) );
}
&& !preg_match('/^'.preg_quote($user->getName(), '/').'\//', $this->mTextform) ) {
$errors[] = array('customcssjsprotected');
}
-
+
if ( $doExpensiveQueries && !$this->isCssJsSubpage() ) {
# We /could/ use the protection level on the source page, but it's fairly ugly
# as we have to establish a precedence hierarchy for pages included by multiple
}
}
}
-
+
foreach( $this->getRestrictions($action) as $right ) {
// Backwards compatibility, rewrite sysop -> protect
if ( $right == 'sysop' ) {
$right = 'protect';
}
if( '' != $right && !$user->isAllowed( $right ) ) {
- //Users with 'editprotected' permission can edit protected pages
- if( $action=='edit' && $user->isAllowed( 'editprotected' ) ) {
- //Users with 'editprotected' permission cannot edit protected pages
- //with cascading option turned on.
- if($this->mCascadeRestriction) {
- $errors[] = array( 'protectedpagetext', $right );
- } else {
- //Nothing, user can edit!
- }
+ // Users with 'editprotected' permission can edit protected
+ // pages if protection is not with cascading option turned on.
+ if( $action=='edit' && $user->isAllowed( 'editprotected' ) && !$this->areRestrictionsCascading() ) {
+ // Nothing, user can edit!
} else {
$errors[] = array( 'protectedpagetext', $right );
}
}
}
- if ($action == 'create') {
+ if ($action == 'create') {
$title_protection = $this->getTitleProtection();
if (is_array($title_protection)) {
}
$dbr = wfGetDB( DB_SLAVE );
- $res = $dbr->select( 'protected_titles', '*',
+ $res = $dbr->select( 'protected_titles', '*',
array ('pt_namespace' => $this->getNamespace(), 'pt_title' => $this->getDBkey()) );
if ($row = $dbr->fetchRow( $res )) {
public function deleteTitleProtection() {
$dbw = wfGetDB( DB_MASTER );
- $dbw->delete( 'protected_titles',
+ $dbw->delete( 'protected_titles',
array ('pt_namespace' => $this->getNamespace(), 'pt_title' => $this->getDBkey()), __METHOD__ );
}
} else {
global $wgWhitelistRead;
- /**
+ /**
* Always grant access to the login page.
* Even anons need to be able to log in.
*/
* Check for explicit whitelisting
*/
$name = $this->getPrefixedText();
- if( in_array( $name, $wgWhitelistRead, true ) )
+ $dbName = $this->getPrefixedDBKey();
+ // Check with and without underscores
+ if( in_array($name,$wgWhitelistRead,true) || in_array($dbName,$wgWhitelistRead,true) )
return true;
/**
* @return bool
*/
public function isSubpage() {
- global $wgNamespacesWithSubpages;
-
- if( isset( $wgNamespacesWithSubpages[ $this->mNamespace ] ) ) {
- return ( strpos( $this->getText(), '/' ) !== false && $wgNamespacesWithSubpages[ $this->mNamespace ] == true );
- } else {
+ return MWNamespace::hasSubpages( $this->mNamespace )
+ ? strpos( $this->getText(), '/' ) !== false
+ : false;
+ }
+
+ /**
+ * Does this have subpages? (Warning, usually requires an extra DB query.)
+ * @return bool
+ */
+ public function hasSubpages() {
+ if( !MWNamespace::hasSubpages( $this->mNamespace ) ) {
+ # Duh
return false;
}
+
+ # We dynamically add a member variable for the purpose of this method
+ # alone to cache the result. There's no point in having it hanging
+ # around uninitialized in every Title object; therefore we only add it
+ # if needed and don't declare it statically.
+ if( isset( $this->mHasSubpages ) ) {
+ return $this->mHasSubpages;
+ }
+
+ $db = wfGetDB( DB_SLAVE );
+ return $this->mHasSubpages = (bool)$db->selectField( 'page', '1',
+ "page_namespace = {$this->mNamespace} AND page_title LIKE '"
+ . $db->escapeLike( $this->mDbkeyform ) . "/%'",
+ __METHOD__
+ );
}
-
+
/**
* Could this page contain custom CSS or JavaScript, based
* on the title?
* The restriction array is an array of each type, each of which contains an array of unique groups
*/
public function getCascadeProtectionSources( $get_pages = true ) {
- global $wgEnableCascadingProtection, $wgRestrictionTypes;
+ global $wgRestrictionTypes;
# Define our dimension of restrictions types
$pagerestrictions = array();
foreach( $wgRestrictionTypes as $action )
$pagerestrictions[$action] = array();
- if (!$wgEnableCascadingProtection)
- return array( false, $pagerestrictions );
-
if ( isset( $this->mCascadeSources ) && $get_pages ) {
return array( $this->mCascadeSources, $this->mCascadingRestrictions );
} else if ( isset( $this->mHasCascadingRestrictions ) && !$get_pages ) {
wfProfileIn( __METHOD__ );
- $dbr = wfGetDb( DB_SLAVE );
+ $dbr = wfGetDB( DB_SLAVE );
if ( $this->getNamespace() == NS_IMAGE ) {
$tables = array ('imagelinks', 'page_restrictions');
$sources = $get_pages ? array() : false;
$now = wfTimestampNow();
$purgeExpired = false;
-
+
while( $row = $dbr->fetchObject( $res ) ) {
$expiry = Block::decodeExpiry( $row->pr_expiry );
if( $expiry > $now ) {
# Backwards-compatibility: also load the restrictions from the page record (old format).
- if ( $oldFashionedRestrictions == NULL ) {
- $oldFashionedRestrictions = $dbr->selectField( 'page', 'page_restrictions', array( 'page_id' => $this->getArticleId() ), __METHOD__ );
+ if ( $oldFashionedRestrictions === NULL ) {
+ $oldFashionedRestrictions = $dbr->selectField( 'page', 'page_restrictions',
+ array( 'page_id' => $this->getArticleId() ), __METHOD__ );
}
if ($oldFashionedRestrictions != '') {
while ($row = $dbr->fetchObject( $res ) ) {
# Cycle through all the restrictions.
-
+
// Don't take care of restrictions types that aren't in $wgRestrictionTypes
if( !in_array( $row->pr_type, $wgRestrictionTypes ) )
continue;
}
return $this->mArticleID;
}
-
+
/**
* Is this an article that is a redirect page?
* Uses link cache, adding it if necessary
public function isRedirect( $flags = 0 ) {
if( !is_null($this->mRedirect) )
return $this->mRedirect;
- # Zero for special pages.
+ # Zero for special pages.
# Also, calling getArticleID() loads the field from cache!
if( !$this->getArticleID($flags) || $this->getNamespace() == NS_SPECIAL ) {
return false;
return $this->mRedirect;
}
-
+
/**
* What is the length of this page?
* Uses link cache, adding it if necessary
public function getLength( $flags = 0 ) {
if( $this->mLength != -1 )
return $this->mLength;
- # Zero for special pages.
+ # Zero for special pages.
# Also, calling getArticleID() loads the field from cache!
if( !$this->getArticleID($flags) || $this->getNamespace() == NS_SPECIAL ) {
return 0;
return $this->mLength;
}
- public function getLatestRevID() {
+ /**
+ * What is the page_latest field for this page?
+ * @param int $flags a bit field; may be GAID_FOR_UPDATE to select for update
+ * @return int
+ */
+ public function getLatestRevID( $flags = 0 ) {
if ($this->mLatestID !== false)
return $this->mLatestID;
- $db = wfGetDB(DB_SLAVE);
+ $db = ($flags & GAID_FOR_UPDATE) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE );
return $this->mLatestID = $db->selectField( 'revision',
"max(rev_id)",
- array('rev_page' => $this->getArticleID()),
+ array('rev_page' => $this->getArticleID($flags)),
'Title::getLatestRevID' );
}
$this->mInterwiki = $this->mFragment = '';
$this->mNamespace = $this->mDefaultNamespace; # Usually NS_MAIN
-
+
$dbkey = $this->mDbkeyform;
# Strip Unicode bidi override characters.
# override chars get included in list displays.
$dbkey = str_replace( "\xE2\x80\x8E", '', $dbkey ); // 200E LEFT-TO-RIGHT MARK
$dbkey = str_replace( "\xE2\x80\x8F", '', $dbkey ); // 200F RIGHT-TO-LEFT MARK
-
+
# Clean up whitespace
#
$dbkey = preg_replace( '/[ _]+/', '_', $dbkey );
{
return false;
}
-
+
/**
* Magic tilde sequences? Nu-uh!
*/
* Limit the size of titles to 255 bytes.
* This is typically the size of the underlying database field.
* We make an exception for special pages, which don't need to be stored
- * in the database, and may edge over 255 bytes due to subpage syntax
+ * in the database, and may edge over 255 bytes due to subpage syntax
* for long titles, e.g. [[Special:Block/Long name]]
*/
if ( ( $this->mNamespace != NS_SPECIAL && strlen( $dbkey ) > 255 ) ||
- strlen( $dbkey ) > 512 )
+ strlen( $dbkey ) > 512 )
{
return false;
}
return false;
}
// Allow IPv6 usernames to start with '::' by canonicalizing IPv6 titles.
- // IP names are not allowed for accounts, and can only be referring to
- // edits from the IP. Given '::' abbreviations and caps/lowercaps,
- // there are numerous ways to present the same IP. Having sp:contribs scan
- // them all is silly and having some show the edits and others not is
+ // IP names are not allowed for accounts, and can only be referring to
+ // edits from the IP. Given '::' abbreviations and caps/lowercaps,
+ // there are numerous ways to present the same IP. Having sp:contribs scan
+ // them all is silly and having some show the edits and others not is
// inconsistent. Same for talk/userpages. Keep them normalized instead.
- $dbkey = ($this->mNamespace == NS_USER || $this->mNamespace == NS_USER_TALK) ?
+ $dbkey = ($this->mNamespace == NS_USER || $this->mNamespace == NS_USER_TALK) ?
IP::sanitizeIP( $dbkey ) : $dbkey;
// Any remaining initial :s are illegal.
if ( $dbkey !== '' && ':' == $dbkey{0} ) {
return false;
}
-
+
# Fill fields
$this->mDbkeyform = $dbkey;
$this->mUrlform = wfUrlencode( $dbkey );
/**
* Set the fragment for this title
* This is kind of bad, since except for this rarely-used function, Title objects
- * are immutable. The reason this is here is because it's better than setting the
+ * are immutable. The reason this is here is because it's better than setting the
* members directly, which is what Linker::formatComment was doing previously.
*
* @param string $fragment text
/**
* Check whether a given move operation would be valid.
- * Returns true if ok, or a message key string for an error message
- * if invalid. (Scarrrrry ugly interface this.)
+ * Returns true if ok, or a getUserPermissionsErrors()-like array otherwise
* @param Title &$nt the new title
* @param bool $auth indicates whether $wgUser's permissions
* should be checked
- * @return mixed true on success, message name on failure
+ * @return mixed True on success, getUserPermissionsErrors()-like array on failure
*/
public function isValidMoveOperation( &$nt, $auth = true ) {
- if( !$this or !$nt ) {
- return 'badtitletext';
+ $errors = array();
+ if( !$nt ) {
+ // Normally we'd add this to $errors, but we'll get
+ // lots of syntax errors if $nt is not an object
+ return array(array('badtitletext'));
}
if( $this->equals( $nt ) ) {
- return 'selfmove';
+ $errors[] = array('selfmove');
}
if( !$this->isMovable() || !$nt->isMovable() ) {
- return 'immobile_namespace';
+ $errors[] = array('immobile_namespace');
}
$oldid = $this->getArticleID();
$newid = $nt->getArticleID();
if ( strlen( $nt->getDBkey() ) < 1 ) {
- return 'articleexists';
+ $errors[] = array('articleexists');
}
if ( ( '' == $this->getDBkey() ) ||
( !$oldid ) ||
( '' == $nt->getDBkey() ) ) {
- return 'badarticleerror';
+ $errors[] = array('badarticleerror');
+ }
+
+ // Image-specific checks
+ if( $this->getNamespace() == NS_IMAGE ) {
+ $file = wfLocalFile( $this );
+ if( $file->exists() ) {
+ if( $nt->getNamespace() != NS_IMAGE ) {
+ $errors[] = array('imagenocrossnamespace');
+ }
+ if( !File::checkExtensionCompatibility( $file, $nt->getDbKey() ) ) {
+ $errors[] = array('imagetypemismatch');
+ }
+ }
}
if ( $auth ) {
global $wgUser;
- $errors = array_merge($this->getUserPermissionsErrors('move', $wgUser),
+ $errors = array_merge($errors,
+ $this->getUserPermissionsErrors('move', $wgUser),
$this->getUserPermissionsErrors('edit', $wgUser),
$nt->getUserPermissionsErrors('move', $wgUser),
$nt->getUserPermissionsErrors('edit', $wgUser));
- if($errors !== array())
- return $errors[0][0];
}
global $wgUser;
$err = null;
if( !wfRunHooks( 'AbortMove', array( $this, $nt, $wgUser, &$err ) ) ) {
- return 'hookaborted';
+ $errors[] = array('hookaborted', $err);
}
# The move is allowed only if (1) the target doesn't exist, or
if ( 0 != $newid ) { # Target exists; check for validity
if ( ! $this->isValidMoveTarget( $nt ) ) {
- return 'articleexists';
+ $errors[] = array('articleexists');
}
} else {
$tp = $nt->getTitleProtection();
- if ( $tp and !$wgUser->isAllowed( $tp['pt_create_perm'] ) ) {
- return 'cantmove-titleprotected';
+ $right = ( $tp['pt_create_perm'] == 'sysop' ) ? 'protect' : $tp['pt_create_perm'];
+ if ( $tp and !$wgUser->isAllowed( $right ) ) {
+ $errors[] = array('cantmove-titleprotected');
}
}
- return true;
+ if(empty($errors))
+ return true;
+ return $errors;
}
/**
* @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.
- * @return mixed true on success, message name on failure
+ * @return mixed true on success, getUserPermissionsErrors()-like array on failure
*/
public function moveTo( &$nt, $auth = true, $reason = '', $createRedirect = true ) {
$err = $this->isValidMoveOperation( $nt, $auth );
- if( is_string( $err ) ) {
+ if( is_array( $err ) ) {
return $err;
}
$pageid = $this->getArticleID();
if( $nt->exists() ) {
- $this->moveOverExistingRedirect( $nt, $reason, $createRedirect );
+ $err = $this->moveOverExistingRedirect( $nt, $reason, $createRedirect );
$pageCountChange = ($createRedirect ? 0 : -1);
} else { # Target didn't exist, do normal move.
- $this->moveToNewTitle( $nt, $reason, $createRedirect );
+ $err = $this->moveToNewTitle( $nt, $reason, $createRedirect );
$pageCountChange = ($createRedirect ? 1 : 0);
}
+
+ if( is_array( $err ) ) {
+ return $err;
+ }
$redirid = $this->getArticleID();
// Category memberships include a sort key which may be customized.
$newarticle = new Article( $nt );
$wgMessageCache->replace( $nt->getDBkey(), $newarticle->getContent() );
}
-
+
global $wgUser;
wfRunHooks( 'TitleMoveComplete', array( &$this, &$nt, &$wgUser, $pageid, $redirid ) );
return true;
$now = wfTimestampNow();
$newid = $nt->getArticleID();
$oldid = $this->getArticleID();
+
$dbw = wfGetDB( DB_MASTER );
+ $dbw->begin();
# Delete the old redirect. We don't save it to history since
# by definition if we've got here it's rather uninteresting.
# Save a null revision in the page's history notifying of the move
$nullRevision = Revision::newNullRevision( $dbw, $oldid, $comment, true );
$nullRevId = $nullRevision->insertOn( $dbw );
+
+ $article = new Article( $this );
+ wfRunHooks( 'NewRevisionFromEditComplete', array($article, $nullRevision, false) );
# Change the name of the target page:
$dbw->update( 'page',
$nt->resetArticleID( $oldid );
# Recreate the redirect, this time in the other direction.
- if($createRedirect || !$wgUser->isAllowed('suppressredirect'))
- {
+ if( $createRedirect || !$wgUser->isAllowed('suppressredirect') ) {
$mwRedir = MagicWord::get( 'redirect' );
$redirectText = $mwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n";
$redirectArticle = new Article( $this );
'text' => $redirectText ) );
$redirectRevision->insertOn( $dbw );
$redirectArticle->updateRevisionOn( $dbw, $redirectRevision, 0 );
+
+ wfRunHooks( 'NewRevisionFromEditComplete', array($redirectArticle, $redirectRevision, false) );
# Now, we record the link from the redirect to the new title.
# It should have no other outgoing links...
$this->resetArticleID( 0 );
}
+ # Move an image if this is a file
+ if( $this->getNamespace() == NS_IMAGE ) {
+ $file = wfLocalFile( $this );
+ if( $file->exists() ) {
+ $status = $file->move( $nt );
+ if( !$status->isOk() ) {
+ $dbw->rollback();
+ return $status->getErrorsArray();
+ }
+ }
+ }
+ $dbw->commit();
+
# Log the move
$log = new LogPage( 'move' );
$log->addEntry( 'move_redir', $this, $reason, array( 1 => $nt->getPrefixedText() ) );
$u = new SquidUpdate( $urls );
$u->doUpdate();
}
+
}
/**
$newid = $nt->getArticleID();
$oldid = $this->getArticleID();
+
$dbw = wfGetDB( DB_MASTER );
+ $dbw->begin();
$now = $dbw->timestamp();
# Save a null revision in the page's history notifying of the move
$nullRevision = Revision::newNullRevision( $dbw, $oldid, $comment, true );
$nullRevId = $nullRevision->insertOn( $dbw );
+
+ $article = new Article( $this );
+ wfRunHooks( 'NewRevisionFromEditComplete', array($article, $nullRevision, false) );
# Rename page entry
$dbw->update( 'page',
);
$nt->resetArticleID( $oldid );
- if($createRedirect || !$wgUser->isAllowed('suppressredirect'))
- {
+ if( $createRedirect || !$wgUser->isAllowed('suppressredirect') ) {
# Insert redirect
$mwRedir = MagicWord::get( 'redirect' );
$redirectText = $mwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n";
'text' => $redirectText ) );
$redirectRevision->insertOn( $dbw );
$redirectArticle->updateRevisionOn( $dbw, $redirectRevision, 0 );
+
+ wfRunHooks( 'NewRevisionFromEditComplete', array($redirectArticle, $redirectRevision, false) );
# Record the just-created redirect's linking to the page
$dbw->insert( 'pagelinks',
} else {
$this->resetArticleID( 0 );
}
+
+ # Move an image if this is a file
+ if( $this->getNamespace() == NS_IMAGE ) {
+ $file = wfLocalFile( $this );
+ if( $file->exists() ) {
+ $status = $file->move( $nt );
+ if( !$status->isOk() ) {
+ $dbw->rollback();
+ return $status->getErrorsArray();
+ }
+ }
+ }
+ $dbw->commit();
# Log the move
$log = new LogPage( 'move' );
# Purge old title from squid
# The new title, and links to the new title, are purged in Article::onArticleCreate()
$this->purgeSquid();
+
}
/**
$fname = 'Title::isValidMoveTarget';
$dbw = wfGetDB( DB_MASTER );
+ # Is it an existsing file?
+ if( $nt->getNamespace() == NS_IMAGE ) {
+ $file = wfLocalFile( $nt );
+ if( $file->exists() ) {
+ wfDebug( __METHOD__ . ": file exists\n" );
+ return false;
+ }
+ }
+
# Is it a redirect?
$id = $nt->getArticleID();
$obj = $dbw->selectRow( array( 'page', 'revision', 'text'),
# Return true if there was no history
return $row === false;
}
-
+
/**
* Can this title be added to a user's watchlist?
*
$stack = array();
$parents = $this->getParentCategories();
- if($parents != '') {
+ if( $parents ) {
foreach($parents as $parent => $current) {
if ( array_key_exists( $parent, $children ) ) {
# Circular reference
* Get the revision ID of the previous revision
*
* @param integer $revision Revision ID. Get the revision that was before this one.
+ * @param integer $flags, GAID_FOR_UPDATE
* @return integer $oldrevision|false
*/
- public function getPreviousRevisionID( $revision ) {
- $dbr = wfGetDB( DB_SLAVE );
- return $dbr->selectField( 'revision', 'rev_id',
- 'rev_page=' . intval( $this->getArticleId() ) .
- ' AND rev_id<' . intval( $revision ) . ' ORDER BY rev_id DESC' );
+ public function getPreviousRevisionID( $revision, $flags=0 ) {
+ $db = ($flags & GAID_FOR_UPDATE) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE );
+ return $db->selectField( 'revision', 'rev_id',
+ array(
+ 'rev_page' => $this->getArticleId($flags),
+ 'rev_id < ' . intval( $revision )
+ ),
+ __METHOD__,
+ array( 'ORDER BY' => 'rev_id DESC' )
+ );
}
/**
* Get the revision ID of the next revision
*
* @param integer $revision Revision ID. Get the revision that was after this one.
+ * @param integer $flags, GAID_FOR_UPDATE
* @return integer $oldrevision|false
*/
- public function getNextRevisionID( $revision ) {
- $dbr = wfGetDB( DB_SLAVE );
- return $dbr->selectField( 'revision', 'rev_id',
- 'rev_page=' . intval( $this->getArticleId() ) .
- ' AND rev_id>' . intval( $revision ) . ' ORDER BY rev_id' );
+ public function getNextRevisionID( $revision, $flags=0 ) {
+ $db = ($flags & GAID_FOR_UPDATE) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE );
+ return $db->selectField( 'revision', 'rev_id',
+ array(
+ 'rev_page' => $this->getArticleId($flags),
+ 'rev_id > ' . intval( $revision )
+ ),
+ __METHOD__,
+ array( 'ORDER BY' => 'rev_id' )
+ );
}
/**
* Get the number of revisions between the given revision IDs.
+ * Used for diffs and other things that really need it.
*
* @param integer $old Revision ID.
* @param integer $new Revision ID.
return $dbr->selectField( 'revision', 'count(*)',
'rev_page = ' . intval( $this->getArticleId() ) .
' AND rev_id > ' . intval( $old ) .
- ' AND rev_id < ' . intval( $new ) );
+ ' AND rev_id < ' . intval( $new ),
+ __METHOD__,
+ array( 'USE INDEX' => 'PRIMARY' ) );
}
/**
&& $this->getNamespace() == $title->getNamespace()
&& $this->getDBkey() === $title->getDBkey();
}
-
+
+ /**
+ * Callback for usort() to do title sorts by (namespace, title)
+ */
+ static function compare( $a, $b ) {
+ if( $a->getNamespace() == $b->getNamespace() ) {
+ return strcmp( $a->getText(), $b->getText() );
+ } else {
+ return $a->getNamespace() - $b->getNamespace();
+ }
+ }
+
/**
* Return a string representation of this title
*
/**
* Update page_touched timestamps and send squid purge messages for
- * pages linking to this title. May be sent to the job queue depending
+ * pages linking to this title. May be sent to the job queue depending
* on the number of links. Typically called on create and delete.
*/
public function touchLinks() {
public function getTouched() {
$dbr = wfGetDB( DB_SLAVE );
$touched = $dbr->selectField( 'page', 'page_touched',
- array(
+ array(
'page_namespace' => $this->getNamespace(),
'page_title' => $this->getDBkey()
), __METHOD__
}
/**
- * If the Title refers to a special page alias which is not the local default,
+ * If the Title refers to a special page alias which is not the local default,
* returns a new Title which points to the local default. Otherwise, returns $this.
*/
public function fixSpecialName() {
public function isContentPage() {
return MWNamespace::isContent( $this->getNamespace() );
}
-
+
+ public function getRedirectsHere( $ns = null ) {
+ $redirs = array();
+
+ $dbr = wfGetDB( DB_SLAVE );
+ $where = array(
+ 'rd_namespace' => $this->getNamespace(),
+ 'rd_title' => $this->getDBkey(),
+ 'rd_from = page_id'
+ );
+ if ( !is_null($ns) ) $where['page_namespace'] = $ns;
+
+ $result = $dbr->select(
+ array( 'redirect', 'page' ),
+ array( 'page_namespace', 'page_title' ),
+ $where,
+ __METHOD__
+ );
+
+
+ while( $row = $dbr->fetchObject( $result ) ) {
+ $redirs[] = self::newFromRow( $row );
+ }
+ return $redirs;
+ }
}