So the user_stats table has a field named stats_opinion_created, which is meant to hold info about how many opinions (=blog posts; "opinion" being an ArmchairGM-ism) the user has created. Too bad that it doesn't work, yet some code uses it (namely BlogPageHooks::getArticles()), which results in profile pages showing stuff like "0 of 2" (when $wgUserProfileDisplay['articles'] = true;) next to the "Blogs" header.
It goes without saying that "0 of 2" makes no logical sense, although when you look at the code it's painfully obvious why: the first count is from the user_stats.stats_opinion_created field and the second one is the result of a direct SQL query to get the blog posts created by the user.
The sucky piece of code is called BlogPageHooks::updateCreatedOpinionsCount(). For whatever reason(s) it's hooked to both PageContentSave and PageContentSaveComplete hooks. I think it only needs to be hooked into the latter, because we want to update social statistics once the edit has definitely gone through, yes?
But more than that, there's the crappy code which pulls (or tries to, anyway) the user name from the MediaWiki:Blog-by-user-category i18n msg. Like the associated code comment says:
// @todo CHECKME/FIXME: This probably no longer works as intended // due to the recent (as of 20 September 2014) i18n message change
If core had something like Title::isInCategory() we could probably just do something like this:
$userBlogCat = wfMessage( 'blog-by-user-category', $user->getName() )->inContentLanguage()->text();
if ( $ctg->isInCategory( $userBlogCat ) ) {
// do our stuff here
}But alas, core has no such method so we need to roll out our own logic here. One possible solution (with some tweaks, obviously) would be this snippet used by the Games skin:
/**
* Checks if the current page is in the given category.
*
* @param string $category Category name
* @return bool True if the page is in the category, otherwise false
*/
function inCategory( $category ) {
$categoryText = array();
// This originally used getCategoryLinks() which returned HTML instead
// of pure category names...how silly.
foreach ( $this->skin->getOutput()->getCategories() as $ctg ) {
$categoryText[] = strip_tags( $ctg );
}
if ( is_array( $categoryText ) && in_array( $category, $categoryText ) ) {
return true;
} else {
return false;
}
}But I have no idea about how well (or not-so-well) that'd perform, so we oughta look into that as well.
Related to BlogPage i18n suckage: T87213: Investigate and rework BlogPage byline code