*/
private function checkPermissionHooks( $action, $user, $errors, $doExpensiveQueries, $short ) {
// Use getUserPermissionsErrors instead
+ $result = '';
if ( !wfRunHooks( 'userCan', array( &$this, &$user, $action, &$result ) ) ) {
return $result ? array() : array( array( 'badaccess-group0' ) );
}
* This clears some fields in this object, and clears any associated
* keys in the "bad links" section of the link cache.
*
+ * - This is called from Article::insertNewArticle() to allow
+ * loading of the new page_id. It's also called from
+ * Article::doDeleteArticle()
+ *
* @param $newid \type{\int} the new Article ID
*/
public function resetArticleID( $newid ) {
}
}
}
- $db->freeResult( $res );
return $retVal;
}
* @return \type{\mixed} true on success, getUserPermissionsErrors()-like array on failure
*/
public function moveTo( &$nt, $auth = true, $reason = '', $createRedirect = true ) {
+ global $wgContLang;
+
$err = $this->isValidMoveOperation( $nt, $auth, $reason );
if ( is_array( $err ) ) {
return $err;
}
$redirid = $this->getArticleID();
- // Category memberships include a sort key which may be customized.
- // If it's left as the default (the page title), we need to update
- // the sort key to match the new title.
- //
- // Be careful to avoid resetting cl_timestamp, which may disturb
- // time-based lists on some sites.
- //
- // Warning -- if the sort key is *explicitly* set to the old title,
- // 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.
+ // Refresh the sortkey for this row. Be careful to avoid resetting
+ // cl_timestamp, which may disturb time-based lists on some sites.
+ $prefix = $dbw->selectField(
+ 'categorylinks',
+ 'cl_sortkey_prefix',
+ array( 'cl_from' => $pageid ),
+ __METHOD__
+ );
$dbw->update( 'categorylinks',
array(
- 'cl_sortkey' => $nt->getPrefixedText(),
+ 'cl_sortkey' => $wgContLang->convertToSortkey( $nt->getCategorySortkey( $prefix ) ),
'cl_timestamp=cl_timestamp' ),
- array(
- 'cl_from' => $pageid,
- 'cl_sortkey' => $this->getPrefixedText() ),
+ array( 'cl_from' => $pageid ),
__METHOD__ );
if ( $protected ) {
$u->doUpdate();
}
# Update message cache for interface messages
- if ( $nt->getNamespace() == NS_MEDIAWIKI ) {
- global $wgMessageCache;
-
+ global $wgMessageCache;
+ if ( $this->getNamespace() == NS_MEDIAWIKI ) {
# @bug 17860: old article can be deleted, if this the case,
# delete it from message cache
if ( $this->getArticleID() === 0 ) {
$oldarticle = new Article( $this );
$wgMessageCache->replace( $this->getDBkey(), $oldarticle->getContent() );
}
-
+ }
+ if ( $nt->getNamespace() == NS_MEDIAWIKI ) {
$newarticle = new Article( $nt );
$wgMessageCache->replace( $nt->getDBkey(), $newarticle->getContent() );
}
. " ORDER BY cl_sortkey";
$res = $dbr->query( $sql );
+ $data = array();
if ( $dbr->numRows( $res ) > 0 ) {
- foreach ( $res as $row )
+ foreach ( $res as $row ) {
// $data[] = Title::newFromText($wgContLang->getNSText ( NS_CATEGORY ).':'.$row->cl_to);
$data[$wgContLang->getNSText( NS_CATEGORY ) . ':' . $row->cl_to] = $this->getFullText();
- $dbr->freeResult( $res );
- } else {
- $data = array();
+ }
}
return $data;
}
}
}
}
- return $stack;
- } else {
- return array();
}
+
+ return $stack;
}
return true; // any interwiki link might be viewable, for all we know
}
switch( $this->mNamespace ) {
- case NS_MEDIA:
- case NS_FILE:
- return (bool)wfFindFile( $this ); // file exists, possibly in a foreign repo
- case NS_SPECIAL:
- return SpecialPage::exists( $this->getDBkey() ); // valid special page
- case NS_MAIN:
- return $this->mDbkeyform == ''; // selflink, possibly with fragment
- case NS_MEDIAWIKI:
- // If the page is form Mediawiki:message/lang, calling wfMsgWeirdKey causes
- // the full l10n of that language to be loaded. That takes much memory and
- // isn't needed. So we strip the language part away.
- list( $basename, /* rest */ ) = explode( '/', $this->mDbkeyform, 2 );
- return (bool)wfMsgWeirdKey( $basename ); // known system message
- default:
- return false;
+ case NS_MEDIA:
+ case NS_FILE:
+ return (bool)wfFindFile( $this ); // file exists, possibly in a foreign repo
+ case NS_SPECIAL:
+ return SpecialPage::exists( $this->getDBkey() ); // valid special page
+ case NS_MAIN:
+ return $this->mDbkeyform == ''; // selflink, possibly with fragment
+ case NS_MEDIAWIKI:
+ // If the page is form Mediawiki:message/lang, calling wfMsgWeirdKey causes
+ // the full l10n of that language to be loaded. That takes much memory and
+ // isn't needed. So we strip the language part away.
+ list( $basename, /* rest */ ) = explode( '/', $this->mDbkeyform, 2 );
+ return (bool)wfMsgWeirdKey( $basename ); // known system message
+ default:
+ return false;
}
}
* @return \type{\bool}
*/
public function isKnown() {
- return $this->exists() || $this->isAlwaysKnown();
+ return $this->isAlwaysKnown() || $this->exists();
}
/**
__METHOD__
);
-
foreach ( $res as $row ) {
$redirs[] = self::newFromRow( $row );
}
}
/**
- * Returns what the default sort key for categories would be, if
- * {{defaultsort:}} isn't used. This is the same as getText() for
- * categories, and for everything if $wgCategoryPrefixedDefaultSortkey is
- * false; otherwise it's the same as getPrefixedText().
+ * Returns the raw sort key to be used for categories, with the specified
+ * prefix. This will be fed to Language::convertToSortkey() to get a
+ * binary sortkey that can be used for actual sorting.
*
+ * @param $prefix string The prefix to be used, specified using
+ * {{defaultsort:}} or like [[Category:Foo|prefix]]. Empty for no
+ * prefix.
* @return string
*/
- public function getCategorySortkey() {
- global $wgCategoryPrefixedDefaultSortkey;
- if ( $this->getNamespace() == NS_CATEGORY
- || !$wgCategoryPrefixedDefaultSortkey ) {
- return $this->getText();
- } else {
- return $this->getPrefixedText();
+ public function getCategorySortkey( $prefix = '' ) {
+ $unprefixed = $this->getText();
+ if ( $prefix !== '' ) {
+ # Separate with a null byte, so the unprefixed part is only used as
+ # a tiebreaker when two pages have the exact same prefix -- null
+ # sorts before everything else (hopefully).
+ return "$prefix\0$unprefixed";
}
+ return $unprefixed;
}
}