Implemented the PoolCounter feature and did some general refactoring in the areas that it touched.
* Renamed Article::outputFromWikitext() to Article::getOutputFromWikitext()
* Factored out cascade protection updates
* Removed recently-added Article::tryParserCache(): misnamed, can be done in one line of code in the caller. Deprecated OutputPage::tryParserCache().
* Made some functions public instead of protected when they could be useful from hooks.
* In ParserCache, removed PHP 4-style ampersands
In Article::view():
* Factored out robot policy logic, "redirected from" header, patrol footer, diff page, revdelete header, CSS/JS formatting, footer, namespace header, missing article error
* Removed some variables, renamed some others, fixed incorrect use of empty()
* Used the refactored footer section to do a couple of early returns and unindent a massive if(!$outputDone) block
* Removed fantasy interpretation of $this->getContent()===false in comment
* Don't try the parser cache when ArticleViewHeader specified $outputDone=true
* Move timing hack to getOutputFromWikitext()
* Stop using $wgOut->parserOptions() with save/restore nonsense every time you want to change something in it. This is meant to be OOP.
* Don't overwrite the article text with an error message and then pretend to write it to the cache, that's confusing
2009-07-08 08:12:35 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
abstract class PoolCounter {
|
2009-07-08 08:42:13 +00:00
|
|
|
public static function factory( $type, $key ) {
|
Implemented the PoolCounter feature and did some general refactoring in the areas that it touched.
* Renamed Article::outputFromWikitext() to Article::getOutputFromWikitext()
* Factored out cascade protection updates
* Removed recently-added Article::tryParserCache(): misnamed, can be done in one line of code in the caller. Deprecated OutputPage::tryParserCache().
* Made some functions public instead of protected when they could be useful from hooks.
* In ParserCache, removed PHP 4-style ampersands
In Article::view():
* Factored out robot policy logic, "redirected from" header, patrol footer, diff page, revdelete header, CSS/JS formatting, footer, namespace header, missing article error
* Removed some variables, renamed some others, fixed incorrect use of empty()
* Used the refactored footer section to do a couple of early returns and unindent a massive if(!$outputDone) block
* Removed fantasy interpretation of $this->getContent()===false in comment
* Don't try the parser cache when ArticleViewHeader specified $outputDone=true
* Move timing hack to getOutputFromWikitext()
* Stop using $wgOut->parserOptions() with save/restore nonsense every time you want to change something in it. This is meant to be OOP.
* Don't overwrite the article text with an error message and then pretend to write it to the cache, that's confusing
2009-07-08 08:12:35 +00:00
|
|
|
global $wgPoolCounterConf;
|
|
|
|
|
if ( !isset( $wgPoolCounterConf[$type] ) ) {
|
|
|
|
|
return new PoolCounter_Stub;
|
|
|
|
|
}
|
|
|
|
|
$conf = $wgPoolCounterConf[$type];
|
|
|
|
|
$class = $conf['class'];
|
|
|
|
|
return new $class( $conf, $type, $key );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
abstract public function acquire();
|
|
|
|
|
abstract public function release();
|
|
|
|
|
abstract public function wait();
|
|
|
|
|
|
|
|
|
|
public function executeProtected( $mainCallback, $dirtyCallback = false ) {
|
|
|
|
|
$status = $this->acquire();
|
|
|
|
|
if ( !$status->isOK() ) {
|
|
|
|
|
return $status;
|
|
|
|
|
}
|
|
|
|
|
if ( !empty( $status->value['overload'] ) ) {
|
|
|
|
|
# Overloaded. Try a dirty cache entry.
|
|
|
|
|
if ( $dirtyCallback ) {
|
|
|
|
|
if ( call_user_func( $dirtyCallback ) ) {
|
|
|
|
|
$this->release();
|
|
|
|
|
return Status::newGood();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Wait for a thread
|
|
|
|
|
$status = $this->wait();
|
|
|
|
|
if ( !$status->isOK() ) {
|
|
|
|
|
$this->release();
|
|
|
|
|
return $status;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
# Call the main callback
|
|
|
|
|
call_user_func( $mainCallback );
|
|
|
|
|
return $this->release();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class PoolCounter_Stub extends PoolCounter {
|
|
|
|
|
public function acquire() {
|
|
|
|
|
return Status::newGood();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function release() {
|
|
|
|
|
return Status::newGood();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function wait() {
|
|
|
|
|
return Status::newGood();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function executeProtected( $mainCallback, $dirtyCallback = false ) {
|
|
|
|
|
call_user_func( $mainCallback );
|
|
|
|
|
return Status::newGood();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|