Skip to content

Commit

Permalink
* Added __HIDDENCAT__ feature, to hide categories from the box at the…
Browse files Browse the repository at this point in the history
… bottom of the member pages depending on special text on the category page.

* Added page_props backend, generic parser-driven page properties which, when changed, invalidate the cache of backlinked pages on any links table. Could be used to add overlays to images depending on their deletion status, or to add icons to articles based on category membership. 
* Refactored double-underscore handling in the parser. 
* Moved CoreParserFunctions registration to CoreParserFunctions.
  • Loading branch information
Tim Starling committed Feb 20, 2008
1 parent 700992c commit 269a910
Show file tree
Hide file tree
Showing 12 changed files with 305 additions and 129 deletions.
46 changes: 46 additions & 0 deletions includes/CoreParserFunctions.php
Expand Up @@ -5,6 +5,52 @@
* @addtogroup Parser
*/
class CoreParserFunctions {
static function register( $parser ) {
global $wgAllowDisplayTitle, $wgAllowSlowParserFunctions;

# Syntax for arguments (see self::setFunctionHook):
# "name for lookup in localized magic words array",
# function callback,
# optional SFH_NO_HASH to omit the hash from calls (e.g. {{int:...}
# instead of {{#int:...}})

$parser->setFunctionHook( 'int', array( __CLASS__, 'intFunction' ), SFH_NO_HASH );
$parser->setFunctionHook( 'ns', array( __CLASS__, 'ns' ), SFH_NO_HASH );
$parser->setFunctionHook( 'urlencode', array( __CLASS__, 'urlencode' ), SFH_NO_HASH );
$parser->setFunctionHook( 'lcfirst', array( __CLASS__, 'lcfirst' ), SFH_NO_HASH );
$parser->setFunctionHook( 'ucfirst', array( __CLASS__, 'ucfirst' ), SFH_NO_HASH );
$parser->setFunctionHook( 'lc', array( __CLASS__, 'lc' ), SFH_NO_HASH );
$parser->setFunctionHook( 'uc', array( __CLASS__, 'uc' ), SFH_NO_HASH );
$parser->setFunctionHook( 'localurl', array( __CLASS__, 'localurl' ), SFH_NO_HASH );
$parser->setFunctionHook( 'localurle', array( __CLASS__, 'localurle' ), SFH_NO_HASH );
$parser->setFunctionHook( 'fullurl', array( __CLASS__, 'fullurl' ), SFH_NO_HASH );
$parser->setFunctionHook( 'fullurle', array( __CLASS__, 'fullurle' ), SFH_NO_HASH );
$parser->setFunctionHook( 'formatnum', array( __CLASS__, 'formatnum' ), SFH_NO_HASH );
$parser->setFunctionHook( 'grammar', array( __CLASS__, 'grammar' ), SFH_NO_HASH );
$parser->setFunctionHook( 'plural', array( __CLASS__, 'plural' ), SFH_NO_HASH );
$parser->setFunctionHook( 'numberofpages', array( __CLASS__, 'numberofpages' ), SFH_NO_HASH );
$parser->setFunctionHook( 'numberofusers', array( __CLASS__, 'numberofusers' ), SFH_NO_HASH );
$parser->setFunctionHook( 'numberofarticles', array( __CLASS__, 'numberofarticles' ), SFH_NO_HASH );
$parser->setFunctionHook( 'numberoffiles', array( __CLASS__, 'numberoffiles' ), SFH_NO_HASH );
$parser->setFunctionHook( 'numberofadmins', array( __CLASS__, 'numberofadmins' ), SFH_NO_HASH );
$parser->setFunctionHook( 'numberofedits', array( __CLASS__, 'numberofedits' ), SFH_NO_HASH );
$parser->setFunctionHook( 'language', array( __CLASS__, 'language' ), SFH_NO_HASH );
$parser->setFunctionHook( 'padleft', array( __CLASS__, 'padleft' ), SFH_NO_HASH );
$parser->setFunctionHook( 'padright', array( __CLASS__, 'padright' ), SFH_NO_HASH );
$parser->setFunctionHook( 'anchorencode', array( __CLASS__, 'anchorencode' ), SFH_NO_HASH );
$parser->setFunctionHook( 'special', array( __CLASS__, 'special' ) );
$parser->setFunctionHook( 'defaultsort', array( __CLASS__, 'defaultsort' ), SFH_NO_HASH );
$parser->setFunctionHook( 'filepath', array( __CLASS__, 'filepath' ), SFH_NO_HASH );
$parser->setFunctionHook( 'tag', array( __CLASS__, 'tagObj' ), SFH_OBJECT_ARGS );

if ( $wgAllowDisplayTitle ) {
$parser->setFunctionHook( 'displaytitle', array( __CLASS__, 'displaytitle' ), SFH_NO_HASH );
}
if ( $wgAllowSlowParserFunctions ) {
$parser->setFunctionHook( 'pagesinnamespace', array( __CLASS__, 'pagesinnamespace' ), SFH_NO_HASH );
}
}

static function intFunction( $parser, $part1 = '' /*, ... */ ) {
if ( strval( $part1 ) !== '' ) {
$args = array_slice( func_get_args(), 2 );
Expand Down
8 changes: 8 additions & 0 deletions includes/DefaultSettings.php
Expand Up @@ -2937,3 +2937,11 @@
* Hooks should return strings or false
*/
$wgExceptionHooks = array();

/**
* Page property link table invalidation lists.
* Should only be set by extensions.
*/
$wgPagePropLinkInvalidations = array(
'hiddencat' => 'categorylinks',
);
29 changes: 15 additions & 14 deletions includes/LinkBatch.php
Expand Up @@ -73,12 +73,18 @@ function execute() {
* Return an array mapping PDBK to ID
*/
function executeInto( &$cache ) {
$fname = 'LinkBatch::executeInto';
wfProfileIn( $fname );
// Do query
wfProfileIn( __METHOD__ );
$res = $this->doQuery();
$ids = $this->addResultToCache( $cache, $res );
wfProfileOut( __METHOD__ );
return $ids;
}

/**
* Add a ResultWrapper containing IDs and titles to a LinkCache object
*/
function addResultToCache( $cache, $res ) {
if ( !$res ) {
wfProfileOut( $fname );
return array();
}

Expand All @@ -92,7 +98,6 @@ function executeInto( &$cache ) {
$ids[$title->getPrefixedDBkey()] = $row->page_id;
unset( $remaining[$row->page_namespace][$row->page_title] );
}
$res->free();

// The remaining links in $data are bad links, register them as such
foreach ( $remaining as $ns => $dbkeys ) {
Expand All @@ -102,43 +107,39 @@ function executeInto( &$cache ) {
$ids[$title->getPrefixedDBkey()] = 0;
}
}
wfProfileOut( $fname );
return $ids;
}

/**
* Perform the existence test query, return a ResultWrapper with page_id fields
*/
function doQuery() {
$fname = 'LinkBatch::doQuery';

if ( $this->isEmpty() ) {
return false;
}
wfProfileIn( $fname );
wfProfileIn( __METHOD__ );

// Construct query
// This is very similar to Parser::replaceLinkHolders
$dbr = wfGetDB( DB_SLAVE );
$page = $dbr->tableName( 'page' );
$set = $this->constructSet( 'page', $dbr );
if ( $set === false ) {
wfProfileOut( $fname );
wfProfileOut( __METHOD__ );
return false;
}
$sql = "SELECT page_id, page_namespace, page_title FROM $page WHERE $set";

// Do query
$res = new ResultWrapper( $dbr, $dbr->query( $sql, $fname ) );
wfProfileOut( $fname );
$res = new ResultWrapper( $dbr, $dbr->query( $sql, __METHOD__ ) );
wfProfileOut( __METHOD__ );
return $res;
}

/**
* Construct a WHERE clause which will match all the given titles.
* Give the appropriate table's field name prefix ('page', 'pl', etc).
*
* @param $prefix String: ??
* @param string $prefix the appropriate table's field name prefix ('page', 'pl', etc)
* @return string
* @public
*/
Expand Down

0 comments on commit 269a910

Please sign in to comment.