* 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() );
}
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 \type{\bool}
*/
public function isKnown() {
- return $this->exists() || $this->isAlwaysKnown();
+ return $this->isAlwaysKnown() || $this->exists();
}
/**
return $types;
}
+
+ /**
+ * 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( $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;
+ }
}