}
/**
+ * THIS IS NOT THE FUNCTION YOU WANT. Use Title::newFromText().
+ *
+ * Example of wrong and broken code:
+ * $title = Title::newFromURL( $wgRequest->getVal( 'title' ) );
+ *
+ * Example of right code:
+ * $title = Title::newFromText( $wgRequest->getVal( 'title' ) );
+ *
* Create a new Title from URL-encoded text. Ensures that
* the given title's length does not exceed the maximum.
* @param $url \type{\string} the title, as might be taken from a URL
/**
* Create a new Title from an article ID
*
- * @todo This is inefficiently implemented, the page row is requested
- * but not used for anything else
- *
* @param $id \type{\int} the page_id corresponding to the Title to create
* @param $flags \type{\int} use GAID_FOR_UPDATE to use master
* @return \type{Title} the new object, or NULL on an error
*/
public static function newFromID( $id, $flags = 0 ) {
- $fname = 'Title::newFromID';
$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 );
+ $row = $db->selectRow( 'page', '*', array( 'page_id' => $id ), __METHOD__ );
+ if( $row !== false ) {
+ $title = Title::newFromRow( $row );
} else {
$title = NULL;
}
return trim( $t );
}
- /*
+ /**
* Make a prefixed DB key from a DB key and a namespace index
* @param $ns \type{\int} numerical representation of the namespace
* @param $title \type{\string} the DB key form the title
return $name;
}
- /**
- * Returns the URL associated with an interwiki prefix
- * @param $key \type{\string} the interwiki prefix (e.g. "MeatBall")
- * @return \type{\string} the associated URL, containing "$1",
- * which should be replaced by an article title
- * @static (arguably)
- * @deprecated See Interwiki class
- */
- public function getInterwikiLink( $key ) {
- return Interwiki::fetch( $key )->getURL( );
- }
-
/**
* Determine whether the object refers to a page within
* this project.
* there's a fragment but the prefixed text is empty, we just return a link
* to the fragment.
*
+ * The result obviously should not be URL-escaped, but does need to be
+ * HTML-escaped if it's being output in HTML.
+ *
* @param $query \type{\arrayof{\string}} An associative array of key => value pairs for the
* query string. Keys and values will be escaped.
* @param $variant \type{\string} Language variant of URL (for sr, zh..). Ignored
if( !$user->isAllowed( 'move' ) ) {
// User can't move anything
- $errors[] = $user->isAnon() ? array ( 'movenologintext' ) : array ('movenotallowed');
+ global $wgGroupPermissions;
+ if( $user->isAnon() && ( $wgGroupPermissions['user']['move']
+ || $wgGroupPermissions['autoconfirmed']['move'] ) ) {
+ // custom message if logged-in users without any special rights can move
+ $errors[] = array ( 'movenologintext' );
+ } else {
+ $errors[] = array ('movenotallowed');
+ }
}
} elseif ( $action == 'create' ) {
if( ( $this->isTalkPage() && !$user->isAllowed( 'createtalk' ) ) ||
} elseif( $action == 'move-target' ) {
if( !$user->isAllowed( 'move' ) ) {
// User can't move anything
- $errors[] = $user->isAnon() ? array ( 'movenologintext' ) : array ('movenotallowed');
+ $errors[] = array ('movenotallowed');
} elseif( !$user->isAllowed( 'move-rootuserpages' )
&& $this->getNamespace() == NS_USER && !$this->isSubpage() )
{
if( $create_perm ) {
$params = array("[create=$create_perm] $expiry_description",'');
- $log->addEntry( $this->mRestrictions['create'] ? 'modify' : 'protect', $this, trim( $reason ), $params );
+ $log->addEntry( ( isset( $this->mRestrictions['create'] ) && $this->mRestrictions['create'] ) ? 'modify' : 'protect', $this, trim( $reason ), $params );
} else {
$log->addEntry( 'unprotect', $this, $reason );
}
__METHOD__ );
}
- /**
- * Can $wgUser edit this page?
- * @return \type{\bool} TRUE or FALSE
- * @deprecated use userCan('edit')
- */
- public function userCanEdit( $doExpensiveQueries = true ) {
- return $this->userCan( 'edit', $doExpensiveQueries );
- }
-
- /**
- * Can $wgUser create this page?
- * @return \type{\bool} TRUE or FALSE
- * @deprecated use userCan('create')
- */
- public function userCanCreate( $doExpensiveQueries = true ) {
- return $this->userCan( 'create', $doExpensiveQueries );
- }
-
- /**
- * Can $wgUser move this page?
- * @return \type{\bool} TRUE or FALSE
- * @deprecated use userCan('move')
- */
- public function userCanMove( $doExpensiveQueries = true ) {
- return $this->userCan( 'move', $doExpensiveQueries );
- }
-
/**
* Would anybody with sufficient privileges be able to move this page?
* Some pages just aren't movable.
return $result;
}
- # Shortcut for public wikis, allows skipping quite a bit of code
- if ( !empty( $wgGroupPermissions['*']['read'] ) )
- return true;
-
if( $wgUser->isAllowed( 'read' ) ) {
return true;
} else {
$options['LIMIT'] = $limit;
return $this->mSubpages = TitleArray::newFromResult(
$dbr->select( 'page',
- array( 'page_id', 'page_namespace', 'page_title' ),
+ array( 'page_id', 'page_namespace', 'page_title', 'page_is_redirect' ),
$conds,
__METHOD__,
$options
#
$dbkey = preg_replace( '/[ _]+/', '_', $dbkey );
$dbkey = trim( $dbkey, '_' );
-
- # Clean up Arabic harakats (bug 16899)
- $dbkey = preg_replace( '/[\x{064B}-\x{0652}]/Su', '', $dbkey );
if ( '' == $dbkey ) {
return false;
if( $nt->getText() != wfStripIllegalFilenameChars( $nt->getText() ) ) {
$errors[] = array('imageinvalidfilename');
}
- if( !File::checkExtensionCompatibility( $file, $nt->getDBKey() ) ) {
+ if( !File::checkExtensionCompatibility( $file, $nt->getDBkey() ) ) {
$errors[] = array('imagetypemismatch');
}
}
$nt->getUserPermissionsErrors('edit', $wgUser) );
}
- $match = EditPage::matchSpamRegex( $reason );
+ $match = EditPage::matchSummarySpamRegex( $reason );
if( $match !== false ) {
// This is kind of lame, won't display nice
$errors[] = array('spamprotectiontext');
return $err;
}
+ // If it is a file, more it first. It is done before all other moving stuff is done because it's hard to revert
+ $dbw = wfGetDB( DB_MASTER );
+ if( $this->getNamespace() == NS_FILE ) {
+ $file = wfLocalFile( $this );
+ if( $file->exists() ) {
+ $status = $file->move( $nt );
+ if( !$status->isOk() ) {
+ return $status->getErrorsArray();
+ }
+ }
+ }
+
$pageid = $this->getArticleID();
$protected = $this->isProtected();
if( $nt->exists() ) {
// we can't actually distinguish it from a default here, and it'll
// be set to the new title even though it really shouldn't.
// It'll get corrected on the next edit, but resetting cl_timestamp.
- $dbw = wfGetDB( DB_MASTER );
$dbw->update( 'categorylinks',
array(
'cl_sortkey' => $nt->getPrefixedText(),
# Update message cache for interface messages
if( $nt->getNamespace() == NS_MEDIAWIKI ) {
global $wgMessageCache;
- $oldarticle = new Article( $this );
- $wgMessageCache->replace( $this->getDBkey(), $oldarticle->getContent() );
+
+ # @bug 17860: old article can be deleted, if this the case,
+ # delete it from message cache
+ if ( $this->getArticleID() === 0 ) {
+ $wgMessageCache->replace( $this->getDBkey(), false );
+ } else {
+ $oldarticle = new Article( $this );
+ $wgMessageCache->replace( $this->getDBkey(), $oldarticle->getContent() );
+ }
+
$newarticle = new Article( $nt );
$wgMessageCache->replace( $nt->getDBkey(), $newarticle->getContent() );
}
$redirectSuppressed = true;
}
- # Move an image if this is a file
- if( $this->getNamespace() == NS_FILE ) {
- $file = wfLocalFile( $this );
- if( $file->exists() ) {
- $status = $file->move( $nt );
- if( !$status->isOk() ) {
- $dbw->rollback();
- return $status->getErrorsArray();
- }
- }
- }
-
# Log the move
$log = new LogPage( 'move' );
$log->addEntry( 'move_redir', $this, $reason, array( 1 => $nt->getPrefixedText(), 2 => $redirectSuppressed ) );
$redirectSuppressed = true;
}
- # Move an image if this is a file
- if( $this->getNamespace() == NS_FILE ) {
- $file = wfLocalFile( $this );
- if( $file->exists() ) {
- $status = $file->move( $nt );
- if( !$status->isOk() ) {
- $dbw->rollback();
- return $status->getErrorsArray();
- }
- }
- }
-
# Log the move
$log = new LogPage( 'move' );
$log->addEntry( 'move', $this, $reason, array( 1 => $nt->getPrefixedText(), 2 => $redirectSuppressed ) );
* arrays (errors) as values, or an error array with numeric indices if no pages were moved
*/
public function moveSubpages( $nt, $auth = true, $reason = '', $createRedirect = true ) {
- global $wgUser, $wgMaximumMovedPages;
+ global $wgMaximumMovedPages;
// Check permissions
if( !$this->userCan( 'move-subpages' ) )
return array( 'cant-move-subpages' );
// don't move it twice
continue;
$newPageName = preg_replace(
- '#^'.preg_quote( $this->getDBKey(), '#' ).'#',
- $nt->getDBKey(), $oldSubpage->getDBKey() );
+ '#^'.preg_quote( $this->getDBkey(), '#' ).'#',
+ $nt->getDBkey(), $oldSubpage->getDBkey() );
if( $oldSubpage->isTalkPage() ) {
$newNs = $nt->getTalkPage()->getNamespace();
} else {
case NS_FILE:
return wfFindFile( $this ); // file exists, possibly in a foreign repo
case NS_SPECIAL:
- return SpecialPage::exists( $this->getDBKey() ); // valid special page
+ return SpecialPage::exists( $this->getDBkey() ); // valid special page
case NS_MAIN:
return $this->mDbkeyform == ''; // selflink, possibly with fragment
case NS_MEDIAWIKI:
* @return \type{\string} Trackback URL
*/
public function trackbackURL() {
- global $wgScriptPath, $wgServer;
+ global $wgScriptPath, $wgServer, $wgScriptExtension;
- return "$wgServer$wgScriptPath/trackback.php?article="
+ return "$wgServer$wgScriptPath/trackback$wgScriptExtension?article="
. htmlspecialchars(urlencode($this->getPrefixedDBkey()));
}