Random indentation and code formatting updates. No functional changes.
This commit is contained in:
parent
56af09782a
commit
f8b1c4cfb7
13 changed files with 762 additions and 696 deletions
|
|
@ -7,7 +7,7 @@
|
|||
* Handle ajax requests and send them to the proper handler.
|
||||
*/
|
||||
|
||||
if( !(defined( 'MEDIAWIKI' ) && $wgUseAjax ) ) {
|
||||
if ( !( defined( 'MEDIAWIKI' ) && $wgUseAjax ) ) {
|
||||
die( 1 );
|
||||
}
|
||||
|
||||
|
|
@ -33,11 +33,11 @@ class AjaxDispatcher {
|
|||
|
||||
$this->mode = "";
|
||||
|
||||
if (! empty($_GET["rs"])) {
|
||||
if ( ! empty( $_GET["rs"] ) ) {
|
||||
$this->mode = "get";
|
||||
}
|
||||
|
||||
if (!empty($_POST["rs"])) {
|
||||
if ( !empty( $_POST["rs"] ) ) {
|
||||
$this->mode = "post";
|
||||
}
|
||||
|
||||
|
|
@ -45,7 +45,7 @@ class AjaxDispatcher {
|
|||
|
||||
case 'get':
|
||||
$this->func_name = isset( $_GET["rs"] ) ? $_GET["rs"] : '';
|
||||
if (! empty($_GET["rsargs"])) {
|
||||
if ( ! empty( $_GET["rsargs"] ) ) {
|
||||
$this->args = $_GET["rsargs"];
|
||||
} else {
|
||||
$this->args = array();
|
||||
|
|
@ -54,7 +54,7 @@ class AjaxDispatcher {
|
|||
|
||||
case 'post':
|
||||
$this->func_name = isset( $_POST["rs"] ) ? $_POST["rs"] : '';
|
||||
if (! empty($_POST["rsargs"])) {
|
||||
if ( ! empty( $_POST["rsargs"] ) ) {
|
||||
$this->args = $_POST["rsargs"];
|
||||
} else {
|
||||
$this->args = array();
|
||||
|
|
@ -65,7 +65,7 @@ class AjaxDispatcher {
|
|||
wfProfileOut( __METHOD__ );
|
||||
return;
|
||||
# Or we could throw an exception:
|
||||
#throw new MWException( __METHOD__ . ' called without any data (mode empty).' );
|
||||
# throw new MWException( __METHOD__ . ' called without any data (mode empty).' );
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -83,9 +83,10 @@ class AjaxDispatcher {
|
|||
if ( empty( $this->mode ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
wfProfileIn( __METHOD__ );
|
||||
|
||||
if (! in_array( $this->func_name, $wgAjaxExportList ) ) {
|
||||
if ( ! in_array( $this->func_name, $wgAjaxExportList ) ) {
|
||||
wfDebug( __METHOD__ . ' Bad Request for unknown function ' . $this->func_name . "\n" );
|
||||
|
||||
wfHttpError( 400, 'Bad Request',
|
||||
|
|
@ -99,11 +100,11 @@ class AjaxDispatcher {
|
|||
$func = $this->func_name;
|
||||
}
|
||||
try {
|
||||
$result = call_user_func_array($func, $this->args);
|
||||
$result = call_user_func_array( $func, $this->args );
|
||||
|
||||
if ( $result === false || $result === null ) {
|
||||
wfDebug( __METHOD__ . ' ERROR while dispatching '
|
||||
. $this->func_name . "(" . var_export( $this->args, true ) . "): "
|
||||
wfDebug( __METHOD__ . ' ERROR while dispatching '
|
||||
. $this->func_name . "(" . var_export( $this->args, true ) . "): "
|
||||
. "no data returned\n" );
|
||||
|
||||
wfHttpError( 500, 'Internal Error',
|
||||
|
|
@ -111,7 +112,7 @@ class AjaxDispatcher {
|
|||
}
|
||||
else {
|
||||
if ( is_string( $result ) ) {
|
||||
$result= new AjaxResponse( $result );
|
||||
$result = new AjaxResponse( $result );
|
||||
}
|
||||
|
||||
$result->sendHeaders();
|
||||
|
|
@ -120,12 +121,12 @@ class AjaxDispatcher {
|
|||
wfDebug( __METHOD__ . ' dispatch complete for ' . $this->func_name . "\n" );
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
wfDebug( __METHOD__ . ' ERROR while dispatching '
|
||||
. $this->func_name . "(" . var_export( $this->args, true ) . "): "
|
||||
. get_class($e) . ": " . $e->getMessage() . "\n" );
|
||||
} catch ( Exception $e ) {
|
||||
wfDebug( __METHOD__ . ' ERROR while dispatching '
|
||||
. $this->func_name . "(" . var_export( $this->args, true ) . "): "
|
||||
. get_class( $e ) . ": " . $e->getMessage() . "\n" );
|
||||
|
||||
if (!headers_sent()) {
|
||||
if ( !headers_sent() ) {
|
||||
wfHttpError( 500, 'Internal Error',
|
||||
$e->getMessage() );
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
* @ingroup Ajax
|
||||
*/
|
||||
|
||||
if( !defined( 'MEDIAWIKI' ) ) {
|
||||
if ( !defined( 'MEDIAWIKI' ) ) {
|
||||
die( 1 );
|
||||
}
|
||||
|
||||
|
|
@ -14,31 +14,31 @@ if( !defined( 'MEDIAWIKI' ) ) {
|
|||
* Modified function from http://pure-essence.net/stuff/code/utf8RawUrlDecode.phps
|
||||
*
|
||||
* @param $source String escaped with Javascript's escape() function
|
||||
* @param $iconv_to String destination character set will be used as second parameter
|
||||
* @param $iconv_to String destination character set will be used as second parameter
|
||||
* in the iconv function. Default is UTF-8.
|
||||
* @return string
|
||||
*/
|
||||
function js_unescape($source, $iconv_to = 'UTF-8') {
|
||||
function js_unescape( $source, $iconv_to = 'UTF-8' ) {
|
||||
$decodedStr = '';
|
||||
$pos = 0;
|
||||
$len = strlen ($source);
|
||||
$len = strlen ( $source );
|
||||
|
||||
while ($pos < $len) {
|
||||
$charAt = substr ($source, $pos, 1);
|
||||
if ($charAt == '%') {
|
||||
while ( $pos < $len ) {
|
||||
$charAt = substr ( $source, $pos, 1 );
|
||||
if ( $charAt == '%' ) {
|
||||
$pos++;
|
||||
$charAt = substr ($source, $pos, 1);
|
||||
if ($charAt == 'u') {
|
||||
$charAt = substr ( $source, $pos, 1 );
|
||||
if ( $charAt == 'u' ) {
|
||||
// we got a unicode character
|
||||
$pos++;
|
||||
$unicodeHexVal = substr ($source, $pos, 4);
|
||||
$unicode = hexdec ($unicodeHexVal);
|
||||
$decodedStr .= code2utf($unicode);
|
||||
$unicodeHexVal = substr ( $source, $pos, 4 );
|
||||
$unicode = hexdec ( $unicodeHexVal );
|
||||
$decodedStr .= code2utf( $unicode );
|
||||
$pos += 4;
|
||||
} else {
|
||||
// we have an escaped ascii character
|
||||
$hexVal = substr ($source, $pos, 2);
|
||||
$decodedStr .= chr (hexdec ($hexVal));
|
||||
$hexVal = substr ( $source, $pos, 2 );
|
||||
$decodedStr .= chr ( hexdec ( $hexVal ) );
|
||||
$pos += 2;
|
||||
}
|
||||
} else {
|
||||
|
|
@ -47,8 +47,8 @@ function js_unescape($source, $iconv_to = 'UTF-8') {
|
|||
}
|
||||
}
|
||||
|
||||
if ($iconv_to != "UTF-8") {
|
||||
$decodedStr = iconv("UTF-8", $iconv_to, $decodedStr);
|
||||
if ( $iconv_to != "UTF-8" ) {
|
||||
$decodedStr = iconv( "UTF-8", $iconv_to, $decodedStr );
|
||||
}
|
||||
|
||||
return $decodedStr;
|
||||
|
|
@ -61,16 +61,16 @@ function js_unescape($source, $iconv_to = 'UTF-8') {
|
|||
* @param $num Integer
|
||||
* @return utf8char
|
||||
*/
|
||||
function code2utf($num){
|
||||
if ( $num<128 )
|
||||
return chr($num);
|
||||
if ( $num<2048 )
|
||||
return chr(($num>>6)+192).chr(($num&63)+128);
|
||||
if ( $num<65536 )
|
||||
return chr(($num>>12)+224).chr((($num>>6)&63)+128).chr(($num&63)+128);
|
||||
if ( $num<2097152 )
|
||||
return chr(($num>>18)+240).chr((($num>>12)&63)+128).chr((($num>>6)&63)+128) .chr(($num&63)+128);
|
||||
return '';
|
||||
function code2utf( $num ) {
|
||||
if ( $num < 128 )
|
||||
return chr( $num );
|
||||
if ( $num < 2048 )
|
||||
return chr( ( $num >> 6 ) + 192 ) . chr( ( $num&63 ) + 128 );
|
||||
if ( $num < 65536 )
|
||||
return chr( ( $num >> 12 ) + 224 ) . chr( ( ( $num >> 6 )&63 ) + 128 ) . chr( ( $num&63 ) + 128 );
|
||||
if ( $num < 2097152 )
|
||||
return chr( ( $num >> 18 ) + 240 ) . chr( ( ( $num >> 12 )&63 ) + 128 ) . chr( ( ( $num >> 6 )&63 ) + 128 ) . chr( ( $num&63 ) + 128 );
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -81,49 +81,49 @@ function code2utf($num){
|
|||
* respectively, followed by an HTML message to display in the alert box; or
|
||||
* '<err#>' on error
|
||||
*/
|
||||
function wfAjaxWatch($pagename = "", $watch = "") {
|
||||
if(wfReadOnly()) {
|
||||
function wfAjaxWatch( $pagename = "", $watch = "" ) {
|
||||
if ( wfReadOnly() ) {
|
||||
// redirect to action=(un)watch, which will display the database lock
|
||||
// message
|
||||
return '<err#>';
|
||||
}
|
||||
|
||||
if('w' !== $watch && 'u' !== $watch) {
|
||||
if ( 'w' !== $watch && 'u' !== $watch ) {
|
||||
return '<err#>';
|
||||
}
|
||||
$watch = 'w' === $watch;
|
||||
|
||||
$title = Title::newFromDBkey($pagename);
|
||||
if(!$title) {
|
||||
$title = Title::newFromDBkey( $pagename );
|
||||
if ( !$title ) {
|
||||
// Invalid title
|
||||
return '<err#>';
|
||||
}
|
||||
$article = new Article($title);
|
||||
$article = new Article( $title );
|
||||
$watching = $title->userIsWatching();
|
||||
|
||||
if($watch) {
|
||||
if(!$watching) {
|
||||
$dbw = wfGetDB(DB_MASTER);
|
||||
if ( $watch ) {
|
||||
if ( !$watching ) {
|
||||
$dbw = wfGetDB( DB_MASTER );
|
||||
$dbw->begin();
|
||||
$ok = $article->doWatch();
|
||||
$dbw->commit();
|
||||
}
|
||||
} else {
|
||||
if($watching) {
|
||||
$dbw = wfGetDB(DB_MASTER);
|
||||
if ( $watching ) {
|
||||
$dbw = wfGetDB( DB_MASTER );
|
||||
$dbw->begin();
|
||||
$ok = $article->doUnwatch();
|
||||
$dbw->commit();
|
||||
}
|
||||
}
|
||||
// Something stopped the change
|
||||
if( isset($ok) && !$ok ) {
|
||||
if ( isset( $ok ) && !$ok ) {
|
||||
return '<err#>';
|
||||
}
|
||||
if( $watch ) {
|
||||
return '<w#>'.wfMsgExt( 'addedwatchtext', array( 'parse' ), $title->getPrefixedText() );
|
||||
if ( $watch ) {
|
||||
return '<w#>' . wfMsgExt( 'addedwatchtext', array( 'parse' ), $title->getPrefixedText() );
|
||||
} else {
|
||||
return '<u#>'.wfMsgExt( 'removedwatchtext', array( 'parse' ), $title->getPrefixedText() );
|
||||
return '<u#>' . wfMsgExt( 'removedwatchtext', array( 'parse' ), $title->getPrefixedText() );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -133,12 +133,12 @@ function wfAjaxWatch($pagename = "", $watch = "") {
|
|||
*/
|
||||
function wfAjaxGetThumbnailUrl( $file, $width, $height ) {
|
||||
$file = wfFindFile( $file );
|
||||
|
||||
|
||||
if ( !$file || !$file->exists() )
|
||||
return null;
|
||||
|
||||
|
||||
$url = $file->getThumbnail( $width, $height )->url;
|
||||
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
|
|
@ -148,11 +148,11 @@ function wfAjaxGetThumbnailUrl( $file, $width, $height ) {
|
|||
*/
|
||||
function wfAjaxGetFileUrl( $file ) {
|
||||
$file = wfFindFile( $file );
|
||||
|
||||
|
||||
if ( !$file || !$file->exists() )
|
||||
return null;
|
||||
|
||||
|
||||
$url = $file->getUrl();
|
||||
|
||||
|
||||
return $url;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,14 +4,14 @@
|
|||
* @ingroup Ajax
|
||||
*/
|
||||
|
||||
if( !defined( 'MEDIAWIKI' ) ) {
|
||||
if ( !defined( 'MEDIAWIKI' ) ) {
|
||||
die( 1 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle responses for Ajax requests (send headers, print
|
||||
* content, that sort of thing)
|
||||
*
|
||||
*
|
||||
* @ingroup Ajax
|
||||
*/
|
||||
class AjaxResponse {
|
||||
|
|
@ -45,7 +45,7 @@ class AjaxResponse {
|
|||
$this->mText = '';
|
||||
$this->mResponseCode = '200 OK';
|
||||
$this->mLastModified = false;
|
||||
$this->mContentType= 'application/x-wiki';
|
||||
$this->mContentType = 'application/x-wiki';
|
||||
|
||||
if ( $text ) {
|
||||
$this->addText( $text );
|
||||
|
|
@ -95,13 +95,13 @@ class AjaxResponse {
|
|||
header( "Status: " . $this->mResponseCode, true, (int)$n );
|
||||
}
|
||||
|
||||
header ("Content-Type: " . $this->mContentType );
|
||||
header ( "Content-Type: " . $this->mContentType );
|
||||
|
||||
if ( $this->mLastModified ) {
|
||||
header ("Last-Modified: " . $this->mLastModified );
|
||||
header ( "Last-Modified: " . $this->mLastModified );
|
||||
}
|
||||
else {
|
||||
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
|
||||
header ( "Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . " GMT" );
|
||||
}
|
||||
|
||||
if ( $this->mCacheDuration ) {
|
||||
|
|
@ -110,31 +110,31 @@ class AjaxResponse {
|
|||
# and tell the client to always check with the squid. Otherwise,
|
||||
# tell the client to use a cached copy, without a way to purge it.
|
||||
|
||||
if( $wgUseSquid ) {
|
||||
if ( $wgUseSquid ) {
|
||||
|
||||
# Expect explicite purge of the proxy cache, but require end user agents
|
||||
# to revalidate against the proxy on each visit.
|
||||
# Surrogate-Control controls our Squid, Cache-Control downstream caches
|
||||
|
||||
if ( $wgUseESI ) {
|
||||
header( 'Surrogate-Control: max-age='.$this->mCacheDuration.', content="ESI/1.0"');
|
||||
header( 'Surrogate-Control: max-age=' . $this->mCacheDuration . ', content="ESI/1.0"' );
|
||||
header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
|
||||
} else {
|
||||
header( 'Cache-Control: s-maxage='.$this->mCacheDuration.', must-revalidate, max-age=0' );
|
||||
header( 'Cache-Control: s-maxage=' . $this->mCacheDuration . ', must-revalidate, max-age=0' );
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
# Let the client do the caching. Cache is not purged.
|
||||
header ("Expires: " . gmdate( "D, d M Y H:i:s", time() + $this->mCacheDuration ) . " GMT");
|
||||
header ("Cache-Control: s-max-age={$this->mCacheDuration},public,max-age={$this->mCacheDuration}");
|
||||
header ( "Expires: " . gmdate( "D, d M Y H:i:s", time() + $this->mCacheDuration ) . " GMT" );
|
||||
header ( "Cache-Control: s-max-age={$this->mCacheDuration},public,max-age={$this->mCacheDuration}" );
|
||||
}
|
||||
|
||||
} else {
|
||||
# always expired, always modified
|
||||
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
|
||||
header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
|
||||
header ("Pragma: no-cache"); // HTTP/1.0
|
||||
header ( "Expires: Mon, 26 Jul 1997 05:00:00 GMT" ); // Date in the past
|
||||
header ( "Cache-Control: no-cache, must-revalidate" ); // HTTP/1.1
|
||||
header ( "Pragma: no-cache" ); // HTTP/1.0
|
||||
}
|
||||
|
||||
if ( $this->mVary ) {
|
||||
|
|
@ -156,11 +156,11 @@ class AjaxResponse {
|
|||
wfDebug( "$fname: CACHE DISABLED, NO TIMESTAMP\n" );
|
||||
return;
|
||||
}
|
||||
if( !$wgCachePages ) {
|
||||
if ( !$wgCachePages ) {
|
||||
wfDebug( "$fname: CACHE DISABLED\n", false );
|
||||
return;
|
||||
}
|
||||
if( $wgUser->getOption( 'nocache' ) ) {
|
||||
if ( $wgUser->getOption( 'nocache' ) ) {
|
||||
wfDebug( "$fname: USER DISABLED CACHE\n", false );
|
||||
return;
|
||||
}
|
||||
|
|
@ -168,7 +168,7 @@ class AjaxResponse {
|
|||
$timestamp = wfTimestamp( TS_MW, $timestamp );
|
||||
$lastmod = wfTimestamp( TS_RFC2822, max( $timestamp, $wgUser->mTouched, $wgCacheEpoch ) );
|
||||
|
||||
if( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
|
||||
if ( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
|
||||
# IE sends sizes after the date like this:
|
||||
# Wed, 20 Aug 2003 06:51:19 GMT; length=5202
|
||||
# this breaks strtotime().
|
||||
|
|
@ -177,8 +177,8 @@ class AjaxResponse {
|
|||
$ismodsince = wfTimestamp( TS_MW, $modsinceTime ? $modsinceTime : 1 );
|
||||
wfDebug( "$fname: -- client send If-Modified-Since: " . $modsince . "\n", false );
|
||||
wfDebug( "$fname: -- we might send Last-Modified : $lastmod\n", false );
|
||||
if( ($ismodsince >= $timestamp ) && $wgUser->validateCache( $ismodsince ) && $ismodsince >= $wgCacheEpoch ) {
|
||||
ini_set('zlib.output_compression', 0);
|
||||
if ( ( $ismodsince >= $timestamp ) && $wgUser->validateCache( $ismodsince ) && $ismodsince >= $wgCacheEpoch ) {
|
||||
ini_set( 'zlib.output_compression', 0 );
|
||||
$this->setResponseCode( "304 Not Modified" );
|
||||
$this->disable();
|
||||
$this->mLastModified = $lastmod;
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
|
||||
/* This defines autoloading handler for whole MediaWiki framework */
|
||||
|
||||
# Locations of core classes
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* This class checks if user can get extra rights
|
||||
* because of conditions specified in $wgAutopromote
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Class for fetching backlink lists, approximate backlink counts and partitions.
|
||||
* Instances of this class should typically be fetched with $title->getBacklinkCache().
|
||||
*
|
||||
* Ideally you should only get your backlinks from here when you think there is some
|
||||
* Ideally you should only get your backlinks from here when you think there is some
|
||||
* advantage in caching them. Otherwise it's just a waste of memory.
|
||||
*/
|
||||
class BacklinkCache {
|
||||
|
|
@ -56,9 +55,10 @@ class BacklinkCache {
|
|||
wfProfileIn( __METHOD__ );
|
||||
|
||||
$fromField = $this->getPrefix( $table ) . '_from';
|
||||
|
||||
if ( $startId || $endId ) {
|
||||
// Partial range, not cached
|
||||
wfDebug( __METHOD__.": from DB (uncacheable range)\n" );
|
||||
wfDebug( __METHOD__ . ": from DB (uncacheable range)\n" );
|
||||
$conds = $this->getConditions( $table );
|
||||
// Use the from field in the condition rather than the joined page_id,
|
||||
// because databases are stupid and don't necessarily propagate indexes.
|
||||
|
|
@ -68,9 +68,9 @@ class BacklinkCache {
|
|||
if ( $endId ) {
|
||||
$conds[] = "$fromField <= " . intval( $endId );
|
||||
}
|
||||
$res = $this->getDB()->select(
|
||||
$res = $this->getDB()->select(
|
||||
array( $table, 'page' ),
|
||||
array( 'page_namespace', 'page_title', 'page_id'),
|
||||
array( 'page_namespace', 'page_title', 'page_id' ),
|
||||
$conds,
|
||||
__METHOD__,
|
||||
array(
|
||||
|
|
@ -83,8 +83,8 @@ class BacklinkCache {
|
|||
}
|
||||
|
||||
if ( !isset( $this->fullResultCache[$table] ) ) {
|
||||
wfDebug( __METHOD__.": from DB\n" );
|
||||
$res = $this->getDB()->select(
|
||||
wfDebug( __METHOD__ . ": from DB\n" );
|
||||
$res = $this->getDB()->select(
|
||||
array( $table, 'page' ),
|
||||
array( 'page_namespace', 'page_title', 'page_id' ),
|
||||
$this->getConditions( $table ),
|
||||
|
|
@ -111,6 +111,7 @@ class BacklinkCache {
|
|||
'templatelinks' => 'tl',
|
||||
'redirect' => 'rd',
|
||||
);
|
||||
|
||||
if ( isset( $prefixes[$table] ) ) {
|
||||
return $prefixes[$table];
|
||||
} else {
|
||||
|
|
@ -123,6 +124,7 @@ class BacklinkCache {
|
|||
*/
|
||||
protected function getConditions( $table ) {
|
||||
$prefix = $this->getPrefix( $table );
|
||||
|
||||
switch ( $table ) {
|
||||
case 'pagelinks':
|
||||
case 'templatelinks':
|
||||
|
|
@ -134,13 +136,13 @@ class BacklinkCache {
|
|||
);
|
||||
break;
|
||||
case 'imagelinks':
|
||||
$conds = array(
|
||||
$conds = array(
|
||||
'il_to' => $this->title->getDBkey(),
|
||||
'page_id=il_from'
|
||||
);
|
||||
break;
|
||||
case 'categorylinks':
|
||||
$conds = array(
|
||||
$conds = array(
|
||||
'cl_to' => $this->title->getDBkey(),
|
||||
'page_id=cl_from',
|
||||
);
|
||||
|
|
@ -158,10 +160,12 @@ class BacklinkCache {
|
|||
if ( isset( $this->fullResultCache[$table] ) ) {
|
||||
return $this->fullResultCache[$table]->numRows();
|
||||
}
|
||||
|
||||
if ( isset( $this->partitionCache[$table] ) ) {
|
||||
$entry = reset( $this->partitionCache[$table] );
|
||||
return $entry['numRows'];
|
||||
}
|
||||
|
||||
$titleArray = $this->getLinks( $table );
|
||||
return $titleArray->count();
|
||||
}
|
||||
|
|
@ -178,26 +182,33 @@ class BacklinkCache {
|
|||
public function partition( $table, $batchSize ) {
|
||||
// Try cache
|
||||
if ( isset( $this->partitionCache[$table][$batchSize] ) ) {
|
||||
wfDebug( __METHOD__.": got from partition cache\n" );
|
||||
wfDebug( __METHOD__ . ": got from partition cache\n" );
|
||||
return $this->partitionCache[$table][$batchSize]['batches'];
|
||||
}
|
||||
|
||||
$this->partitionCache[$table][$batchSize] = false;
|
||||
$cacheEntry =& $this->partitionCache[$table][$batchSize];
|
||||
|
||||
// Try full result cache
|
||||
if ( isset( $this->fullResultCache[$table] ) ) {
|
||||
$cacheEntry = $this->partitionResult( $this->fullResultCache[$table], $batchSize );
|
||||
wfDebug( __METHOD__.": got from full result cache\n" );
|
||||
wfDebug( __METHOD__ . ": got from full result cache\n" );
|
||||
return $cacheEntry['batches'];
|
||||
}
|
||||
|
||||
// Try memcached
|
||||
global $wgMemc;
|
||||
$memcKey = wfMemcKey( 'backlinks', md5( $this->title->getPrefixedDBkey() ),
|
||||
$table, $batchSize );
|
||||
$memcKey = wfMemcKey(
|
||||
'backlinks',
|
||||
md5( $this->title->getPrefixedDBkey() ),
|
||||
$table,
|
||||
$batchSize
|
||||
);
|
||||
$memcValue = $wgMemc->get( $memcKey );
|
||||
|
||||
if ( is_array( $memcValue ) ) {
|
||||
$cacheEntry = $memcValue;
|
||||
wfDebug( __METHOD__.": got from memcached $memcKey\n" );
|
||||
wfDebug( __METHOD__ . ": got from memcached $memcKey\n" );
|
||||
return $cacheEntry['batches'];
|
||||
}
|
||||
// Fetch from database
|
||||
|
|
@ -205,17 +216,18 @@ class BacklinkCache {
|
|||
$cacheEntry = $this->partitionResult( $this->fullResultCache[$table], $batchSize );
|
||||
// Save to memcached
|
||||
$wgMemc->set( $memcKey, $cacheEntry, self::CACHE_EXPIRY );
|
||||
wfDebug( __METHOD__.": got from database\n" );
|
||||
wfDebug( __METHOD__ . ": got from database\n" );
|
||||
return $cacheEntry['batches'];
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Partition a DB result with backlinks in it into batches
|
||||
*/
|
||||
protected function partitionResult( $res, $batchSize ) {
|
||||
$batches = array();
|
||||
$numRows = $res->numRows();
|
||||
$numBatches = ceil( $numRows / $batchSize );
|
||||
|
||||
for ( $i = 0; $i < $numBatches; $i++ ) {
|
||||
if ( $i == 0 ) {
|
||||
$start = false;
|
||||
|
|
@ -225,6 +237,7 @@ class BacklinkCache {
|
|||
$row = $res->fetchObject();
|
||||
$start = $row->page_id;
|
||||
}
|
||||
|
||||
if ( $i == $numBatches - 1 ) {
|
||||
$end = false;
|
||||
} else {
|
||||
|
|
@ -236,7 +249,7 @@ class BacklinkCache {
|
|||
|
||||
# Sanity check order
|
||||
if ( $start && $end && $start > $end ) {
|
||||
throw new MWException( __METHOD__.': Internal error: query result out of order' );
|
||||
throw new MWException( __METHOD__ . ': Internal error: query result out of order' );
|
||||
}
|
||||
|
||||
$batches[] = array( $start, $end );
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ abstract class BagOStuff {
|
|||
abstract public function get( $key );
|
||||
|
||||
/**
|
||||
* Set an item.
|
||||
* Set an item.
|
||||
* @param $key string
|
||||
* @param $value mixed
|
||||
* @param $exptime int Either an interval in seconds or a unix timestamp for expiry
|
||||
|
|
@ -87,9 +87,11 @@ abstract class BagOStuff {
|
|||
/* Better performance can likely be got with custom written versions */
|
||||
public function get_multi( $keys ) {
|
||||
$out = array();
|
||||
|
||||
foreach ( $keys as $key ) {
|
||||
$out[$key] = $this->get( $key );
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
|
|
@ -140,7 +142,7 @@ abstract class BagOStuff {
|
|||
}
|
||||
|
||||
public function decr( $key, $value = 1 ) {
|
||||
return $this->incr( $key, -$value );
|
||||
return $this->incr( $key, - $value );
|
||||
}
|
||||
|
||||
public function debug( $text ) {
|
||||
|
|
@ -160,7 +162,6 @@ abstract class BagOStuff {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Functional versions!
|
||||
* This is a test of the interface, mainly. It stores things in an associative
|
||||
|
|
@ -254,10 +255,10 @@ class SqlBagOStuff extends BagOStuff {
|
|||
$this->debug( "get: key has expired, deleting" );
|
||||
try {
|
||||
$db->begin();
|
||||
# Put the expiry time in the WHERE condition to avoid deleting a
|
||||
# Put the expiry time in the WHERE condition to avoid deleting a
|
||||
# newly-inserted value
|
||||
$db->delete( 'objectcache',
|
||||
array(
|
||||
$db->delete( 'objectcache',
|
||||
array(
|
||||
'keyname' => $key,
|
||||
'exptime' => $row->exptime
|
||||
), __METHOD__ );
|
||||
|
|
@ -284,8 +285,8 @@ class SqlBagOStuff extends BagOStuff {
|
|||
try {
|
||||
$db->begin();
|
||||
$db->delete( 'objectcache', array( 'keyname' => $key ), __METHOD__ );
|
||||
$db->insert( 'objectcache',
|
||||
array(
|
||||
$db->insert( 'objectcache',
|
||||
array(
|
||||
'keyname' => $key,
|
||||
'value' => $db->encodeBlob( $this->serialize( $value ) ),
|
||||
'exptime' => $encExpiry
|
||||
|
|
@ -458,7 +459,7 @@ class SqlBagOStuff extends BagOStuff {
|
|||
/**
|
||||
* Backwards compatibility alias
|
||||
*/
|
||||
class MediaWikiBagOStuff extends SqlBagOStuff {}
|
||||
class MediaWikiBagOStuff extends SqlBagOStuff { }
|
||||
|
||||
/**
|
||||
* This is a wrapper for Turck MMCache's shared memory functions.
|
||||
|
|
@ -533,14 +534,13 @@ class APCBagOStuff extends BagOStuff {
|
|||
$info = apc_cache_info( 'user' );
|
||||
$list = $info['cache_list'];
|
||||
$keys = array();
|
||||
foreach( $list as $entry ) {
|
||||
foreach ( $list as $entry ) {
|
||||
$keys[] = $entry['info'];
|
||||
}
|
||||
return $keys;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This is a wrapper for eAccelerator's shared memory functions.
|
||||
*
|
||||
|
|
@ -624,13 +624,12 @@ class XCacheBagOStuff extends BagOStuff {
|
|||
xcache_unset( $key );
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache that uses DBA as a backend.
|
||||
* Slow due to the need to constantly open and close the file to avoid holding
|
||||
* writer locks. Intended for development use only, as a memcached workalike
|
||||
* Cache that uses DBA as a backend.
|
||||
* Slow due to the need to constantly open and close the file to avoid holding
|
||||
* writer locks. Intended for development use only, as a memcached workalike
|
||||
* for systems that don't have it.
|
||||
*
|
||||
* @ingroup Cache
|
||||
|
|
@ -669,7 +668,7 @@ class DBABagOStuff extends BagOStuff {
|
|||
return array(
|
||||
unserialize( substr( $blob, 11 ) ),
|
||||
intval( substr( $blob, 0, 10 ) )
|
||||
);
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class Block {
|
|||
$this->mUser = $user;
|
||||
$this->mBy = $by;
|
||||
$this->mReason = $reason;
|
||||
$this->mTimestamp = wfTimestamp(TS_MW,$timestamp);
|
||||
$this->mTimestamp = wfTimestamp( TS_MW, $timestamp );
|
||||
$this->mAuto = $auto;
|
||||
$this->mAnonOnly = $anonOnly;
|
||||
$this->mCreateAccount = $createAccount;
|
||||
|
|
@ -54,7 +54,7 @@ class Block {
|
|||
* Load a block from the database, using either the IP address or
|
||||
* user ID. Tries the user ID first, and if that doesn't work, tries
|
||||
* the address.
|
||||
*
|
||||
*
|
||||
* @param $address String: IP address of user/anon
|
||||
* @param $user Integer: user id of user
|
||||
* @param $killExpired Boolean: delete expired blocks on load
|
||||
|
|
@ -130,6 +130,7 @@ class Block {
|
|||
*/
|
||||
protected function &getDBOptions( &$options ) {
|
||||
global $wgAntiLockFlags;
|
||||
|
||||
if ( $this->mForUpdate || $this->mFromMaster ) {
|
||||
$db = wfGetDB( DB_MASTER );
|
||||
if ( !$this->mForUpdate || ( $wgAntiLockFlags & ALF_NO_BLOCK_LOCK ) ) {
|
||||
|
|
@ -180,12 +181,13 @@ class Block {
|
|||
if ( $address ) {
|
||||
$conds = array( 'ipb_address' => $address, 'ipb_auto' => 0 );
|
||||
$res = $db->resultObject( $db->select( 'ipblocks', '*', $conds, __METHOD__, $options ) );
|
||||
|
||||
if ( $this->loadFromResult( $res, $killExpired ) ) {
|
||||
if ( $user && $this->mAnonOnly ) {
|
||||
# Block is marked anon-only
|
||||
# Whitelist this IP address against autoblocks and range blocks
|
||||
# (but not account creation blocks -- bug 13611)
|
||||
if( !$this->mCreateAccount ) {
|
||||
if ( !$this->mCreateAccount ) {
|
||||
$this->clear();
|
||||
}
|
||||
return false;
|
||||
|
|
@ -199,7 +201,7 @@ class Block {
|
|||
if ( $this->loadRange( $address, $killExpired, $user ) ) {
|
||||
if ( $user && $this->mAnonOnly ) {
|
||||
# Respect account creation blocks on logged-in users -- bug 13611
|
||||
if( !$this->mCreateAccount ) {
|
||||
if ( !$this->mCreateAccount ) {
|
||||
$this->clear();
|
||||
}
|
||||
return false;
|
||||
|
|
@ -211,10 +213,13 @@ class Block {
|
|||
# Try autoblock
|
||||
if ( $address ) {
|
||||
$conds = array( 'ipb_address' => $address, 'ipb_auto' => 1 );
|
||||
|
||||
if ( $user ) {
|
||||
$conds['ipb_anon_only'] = 0;
|
||||
}
|
||||
|
||||
$res = $db->resultObject( $db->select( 'ipblocks', '*', $conds, __METHOD__, $options ) );
|
||||
|
||||
if ( $this->loadFromResult( $res, $killExpired ) ) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -234,6 +239,7 @@ class Block {
|
|||
*/
|
||||
protected function loadFromResult( ResultWrapper $res, $killExpired = true ) {
|
||||
$ret = false;
|
||||
|
||||
if ( 0 != $res->numRows() ) {
|
||||
# Get first block
|
||||
$row = $res->fetchObject();
|
||||
|
|
@ -274,6 +280,7 @@ class Block {
|
|||
*/
|
||||
public function loadRange( $address, $killExpired = true, $user = 0 ) {
|
||||
$iaddr = IP::toHex( $address );
|
||||
|
||||
if ( $iaddr === false ) {
|
||||
# Invalid address
|
||||
return false;
|
||||
|
|
@ -309,7 +316,7 @@ class Block {
|
|||
public function initFromRow( $row ) {
|
||||
$this->mAddress = $row->ipb_address;
|
||||
$this->mReason = $row->ipb_reason;
|
||||
$this->mTimestamp = wfTimestamp(TS_MW,$row->ipb_timestamp);
|
||||
$this->mTimestamp = wfTimestamp( TS_MW, $row->ipb_timestamp );
|
||||
$this->mUser = $row->ipb_user;
|
||||
$this->mBy = $row->ipb_by;
|
||||
$this->mAuto = $row->ipb_auto;
|
||||
|
|
@ -321,17 +328,19 @@ class Block {
|
|||
$this->mHideName = $row->ipb_deleted;
|
||||
$this->mId = $row->ipb_id;
|
||||
$this->mExpiry = self::decodeExpiry( $row->ipb_expiry );
|
||||
|
||||
if ( isset( $row->user_name ) ) {
|
||||
$this->mByName = $row->user_name;
|
||||
} else {
|
||||
$this->mByName = $row->ipb_by_text;
|
||||
}
|
||||
|
||||
$this->mRangeStart = $row->ipb_range_start;
|
||||
$this->mRangeEnd = $row->ipb_range_end;
|
||||
}
|
||||
|
||||
/**
|
||||
* Once $mAddress has been set, get the range they came from.
|
||||
* Once $mAddress has been set, get the range they came from.
|
||||
* Wrapper for IP::parseRange
|
||||
*/
|
||||
protected function initialiseRange() {
|
||||
|
|
@ -352,6 +361,7 @@ class Block {
|
|||
if ( wfReadOnly() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( !$this->mId ) {
|
||||
throw new MWException( "Block::delete() now requires that the mId member be filled\n" );
|
||||
}
|
||||
|
|
@ -377,8 +387,9 @@ class Block {
|
|||
# Don't collide with expired blocks
|
||||
Block::purgeExpired();
|
||||
|
||||
$ipb_id = $dbw->nextSequenceValue('ipblocks_ipb_id_seq');
|
||||
$dbw->insert( 'ipblocks',
|
||||
$ipb_id = $dbw->nextSequenceValue( 'ipblocks_ipb_id_seq' );
|
||||
$dbw->insert(
|
||||
'ipblocks',
|
||||
array(
|
||||
'ipb_id' => $ipb_id,
|
||||
'ipb_address' => $this->mAddress,
|
||||
|
|
@ -386,7 +397,7 @@ class Block {
|
|||
'ipb_by' => $this->mBy,
|
||||
'ipb_by_text' => $this->mByName,
|
||||
'ipb_reason' => $this->mReason,
|
||||
'ipb_timestamp' => $dbw->timestamp($this->mTimestamp),
|
||||
'ipb_timestamp' => $dbw->timestamp( $this->mTimestamp ),
|
||||
'ipb_auto' => $this->mAuto,
|
||||
'ipb_anon_only' => $this->mAnonOnly,
|
||||
'ipb_create_account' => $this->mCreateAccount,
|
||||
|
|
@ -397,7 +408,9 @@ class Block {
|
|||
'ipb_deleted' => $this->mHideName,
|
||||
'ipb_block_email' => $this->mBlockEmail,
|
||||
'ipb_allow_usertalk' => $this->mAllowUsertalk
|
||||
), 'Block::insert', array( 'IGNORE' )
|
||||
),
|
||||
'Block::insert',
|
||||
array( 'IGNORE' )
|
||||
);
|
||||
$affected = $dbw->affectedRows();
|
||||
|
||||
|
|
@ -417,13 +430,14 @@ class Block {
|
|||
|
||||
$this->validateBlockParams();
|
||||
|
||||
$dbw->update( 'ipblocks',
|
||||
$dbw->update(
|
||||
'ipblocks',
|
||||
array(
|
||||
'ipb_user' => $this->mUser,
|
||||
'ipb_by' => $this->mBy,
|
||||
'ipb_by_text' => $this->mByName,
|
||||
'ipb_reason' => $this->mReason,
|
||||
'ipb_timestamp' => $dbw->timestamp($this->mTimestamp),
|
||||
'ipb_timestamp' => $dbw->timestamp( $this->mTimestamp ),
|
||||
'ipb_auto' => $this->mAuto,
|
||||
'ipb_anon_only' => $this->mAnonOnly,
|
||||
'ipb_create_account' => $this->mCreateAccount,
|
||||
|
|
@ -433,13 +447,15 @@ class Block {
|
|||
'ipb_range_end' => $this->mRangeEnd,
|
||||
'ipb_deleted' => $this->mHideName,
|
||||
'ipb_block_email' => $this->mBlockEmail,
|
||||
'ipb_allow_usertalk' => $this->mAllowUsertalk ),
|
||||
'ipb_allow_usertalk' => $this->mAllowUsertalk
|
||||
),
|
||||
array( 'ipb_id' => $this->mId ),
|
||||
'Block::update' );
|
||||
'Block::update'
|
||||
);
|
||||
|
||||
return $dbw->affectedRows();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Make sure all the proper members are set to sane values
|
||||
* before adding/updating a block
|
||||
|
|
@ -459,8 +475,8 @@ class Block {
|
|||
if ( !$this->mUser && $this->mAnonOnly ) {
|
||||
$this->mBlockEmail = 0;
|
||||
}
|
||||
if( !$this->mByName ) {
|
||||
if( $this->mBy ) {
|
||||
if ( !$this->mByName ) {
|
||||
if ( $this->mBy ) {
|
||||
$this->mByName = User::whoIs( $this->mBy );
|
||||
} else {
|
||||
global $wgUser;
|
||||
|
|
@ -481,7 +497,7 @@ class Block {
|
|||
# - stolen shamelessly from CheckUser_body.php
|
||||
|
||||
if ( $this->mEnableAutoblock && $this->mUser ) {
|
||||
wfDebug("Doing retroactive autoblocks for " . $this->mAddress . "\n");
|
||||
wfDebug( "Doing retroactive autoblocks for " . $this->mAddress . "\n" );
|
||||
|
||||
$options = array( 'ORDER BY' => 'rc_timestamp DESC' );
|
||||
$conds = array( 'rc_user_text' => $this->mAddress );
|
||||
|
|
@ -500,7 +516,7 @@ class Block {
|
|||
|
||||
if ( !$dbr->numRows( $res ) ) {
|
||||
# No results, don't autoblock anything
|
||||
wfDebug("No IP found to retroactively autoblock\n");
|
||||
wfDebug( "No IP found to retroactively autoblock\n" );
|
||||
} else {
|
||||
while ( $row = $dbr->fetchObject( $res ) ) {
|
||||
if ( $row->rc_ip )
|
||||
|
|
@ -528,9 +544,9 @@ class Block {
|
|||
$wgMemc->set( $key, $lines, 3600 * 24 );
|
||||
}
|
||||
|
||||
wfDebug("Checking the autoblock whitelist..\n");
|
||||
wfDebug( "Checking the autoblock whitelist..\n" );
|
||||
|
||||
foreach( $lines as $line ) {
|
||||
foreach ( $lines as $line ) {
|
||||
# List items only
|
||||
if ( substr( $line, 0, 1 ) !== '*' ) {
|
||||
continue;
|
||||
|
|
@ -539,11 +555,11 @@ class Block {
|
|||
$wlEntry = substr( $line, 1 );
|
||||
$wlEntry = trim( $wlEntry );
|
||||
|
||||
wfDebug("Checking $ip against $wlEntry...");
|
||||
wfDebug( "Checking $ip against $wlEntry..." );
|
||||
|
||||
# Is the IP in this range?
|
||||
if ( IP::isInRange( $ip, $wlEntry ) ) {
|
||||
wfDebug(" IP $ip matches $wlEntry, not autoblocking\n");
|
||||
wfDebug( " IP $ip matches $wlEntry, not autoblocking\n" );
|
||||
return true;
|
||||
} else {
|
||||
wfDebug( " No match\n" );
|
||||
|
|
@ -570,8 +586,8 @@ class Block {
|
|||
if ( Block::isWhitelistedFromAutoblocks( $autoblockIP ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
## Allow hooks to cancel the autoblock.
|
||||
|
||||
# # Allow hooks to cancel the autoblock.
|
||||
if ( !wfRunHooks( 'AbortAutoblock', array( $autoblockIP, &$this ) ) ) {
|
||||
wfDebug( "Autoblock aborted by hook.\n" );
|
||||
return false;
|
||||
|
|
@ -612,7 +628,7 @@ class Block {
|
|||
$ipblock->mAllowUsertalk = $this->mAllowUsertalk;
|
||||
# If the user is already blocked with an expiry date, we don't
|
||||
# want to pile on top of that!
|
||||
if( $this->mExpiry ) {
|
||||
if ( $this->mExpiry ) {
|
||||
$ipblock->mExpiry = min( $this->mExpiry, Block::getAutoblockExpiry( $this->mTimestamp ) );
|
||||
} else {
|
||||
$ipblock->mExpiry = Block::getAutoblockExpiry( $this->mTimestamp );
|
||||
|
|
@ -661,7 +677,7 @@ class Block {
|
|||
}
|
||||
|
||||
/**
|
||||
* Update the timestamp on autoblocks.
|
||||
* Update the timestamp on autoblocks.
|
||||
*/
|
||||
public function updateTimestamp() {
|
||||
if ( $this->mAuto ) {
|
||||
|
|
@ -727,7 +743,7 @@ class Block {
|
|||
/**
|
||||
* Encode expiry for DB
|
||||
*
|
||||
* @param $expiry String: timestamp for expiry, or
|
||||
* @param $expiry String: timestamp for expiry, or
|
||||
* @param $db Database object
|
||||
* @return String
|
||||
*/
|
||||
|
|
@ -809,7 +825,7 @@ class Block {
|
|||
|
||||
/**
|
||||
* Get a value to insert into expiry field of the database when infinite expiry
|
||||
* is desired. In principle this could be DBMS-dependant, but currently all
|
||||
* is desired. In principle this could be DBMS-dependant, but currently all
|
||||
* supported DBMS's support the string "infinity", so we just use that.
|
||||
*
|
||||
* @return String
|
||||
|
|
@ -829,10 +845,10 @@ class Block {
|
|||
public static function formatExpiry( $encoded_expiry ) {
|
||||
static $msg = null;
|
||||
|
||||
if( is_null( $msg ) ) {
|
||||
if ( is_null( $msg ) ) {
|
||||
$msg = array();
|
||||
$keys = array( 'infiniteblock', 'expiringblock' );
|
||||
foreach( $keys as $key ) {
|
||||
foreach ( $keys as $key ) {
|
||||
$msg[$key] = wfMsgHtml( $key );
|
||||
}
|
||||
}
|
||||
|
|
@ -859,6 +875,7 @@ class Block {
|
|||
$expiry = 'infinity';
|
||||
} else {
|
||||
$expiry = strtotime( $expiry_input );
|
||||
|
||||
if ( $expiry < 0 || $expiry === false ) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* This class stores an arbitrary value along with its dependencies.
|
||||
* Users should typically only use DependencyWrapper::getFromCache(), rather
|
||||
|
|
@ -108,7 +107,7 @@ abstract class CacheDependency {
|
|||
/**
|
||||
* Hook to perform any expensive pre-serialize loading of dependency values.
|
||||
*/
|
||||
function loadDependencyValues() {}
|
||||
function loadDependencyValues() { }
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -213,6 +212,7 @@ class TitleDependency extends CacheDependency {
|
|||
|
||||
function isExpired() {
|
||||
$touched = $this->getTitle()->getTouched();
|
||||
|
||||
if ( $this->touched === false ) {
|
||||
if ( $touched === false ) {
|
||||
# Still missing
|
||||
|
|
@ -251,6 +251,7 @@ class TitleListDependency extends CacheDependency {
|
|||
function calculateTimestamps() {
|
||||
# Initialise values to false
|
||||
$timestamps = array();
|
||||
|
||||
foreach ( $this->getLinkBatch()->data as $ns => $dbks ) {
|
||||
if ( count( $dbks ) > 0 ) {
|
||||
$timestamps[$ns] = array();
|
||||
|
|
@ -264,9 +265,13 @@ class TitleListDependency extends CacheDependency {
|
|||
if ( count( $timestamps ) ) {
|
||||
$dbr = wfGetDB( DB_SLAVE );
|
||||
$where = $this->getLinkBatch()->constructSet( 'page', $dbr );
|
||||
$res = $dbr->select( 'page',
|
||||
$res = $dbr->select(
|
||||
'page',
|
||||
array( 'page_namespace', 'page_title', 'page_touched' ),
|
||||
$where, __METHOD__ );
|
||||
$where,
|
||||
__METHOD__
|
||||
);
|
||||
|
||||
while ( $row = $dbr->fetchObject( $res ) ) {
|
||||
$timestamps[$row->page_namespace][$row->page_title] = $row->page_touched;
|
||||
}
|
||||
|
|
@ -283,7 +288,7 @@ class TitleListDependency extends CacheDependency {
|
|||
}
|
||||
|
||||
function getLinkBatch() {
|
||||
if ( !isset( $this->linkBatch ) ){
|
||||
if ( !isset( $this->linkBatch ) ) {
|
||||
$this->linkBatch = new LinkBatch;
|
||||
$this->linkBatch->setArray( $this->timestamps );
|
||||
}
|
||||
|
|
@ -295,6 +300,7 @@ class TitleListDependency extends CacheDependency {
|
|||
foreach ( $this->timestamps as $ns => $dbks ) {
|
||||
foreach ( $dbks as $dbk => $oldTimestamp ) {
|
||||
$newTimestamp = $newTimestamps[$ns][$dbk];
|
||||
|
||||
if ( $oldTimestamp === false ) {
|
||||
if ( $newTimestamp === false ) {
|
||||
# Still missing
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* Category objects are immutable, strictly speaking. If you call methods that change the database,
|
||||
* Category objects are immutable, strictly speaking. If you call methods that change the database,
|
||||
* like to refresh link counts, the objects will be appropriately reinitialized.
|
||||
* Member variables are lazy-initialized.
|
||||
*
|
||||
|
|
@ -18,21 +18,21 @@ class Category {
|
|||
/** Counts of membership (cat_pages, cat_subcats, cat_files) */
|
||||
private $mPages = null, $mSubcats = null, $mFiles = null;
|
||||
|
||||
private function __construct() {}
|
||||
private function __construct() { }
|
||||
|
||||
/**
|
||||
* Set up all member variables using a database query.
|
||||
* @return bool True on success, false on failure.
|
||||
*/
|
||||
protected function initialize() {
|
||||
if ( $this->mName === null && $this->mTitle )
|
||||
if ( $this->mName === null && $this->mTitle )
|
||||
$this->mName = $title->getDBkey();
|
||||
|
||||
if( $this->mName === null && $this->mID === null ) {
|
||||
throw new MWException( __METHOD__.' has both names and IDs null' );
|
||||
} elseif( $this->mID === null ) {
|
||||
if ( $this->mName === null && $this->mID === null ) {
|
||||
throw new MWException( __METHOD__ . ' has both names and IDs null' );
|
||||
} elseif ( $this->mID === null ) {
|
||||
$where = array( 'cat_title' => $this->mName );
|
||||
} elseif( $this->mName === null ) {
|
||||
} elseif ( $this->mName === null ) {
|
||||
$where = array( 'cat_id' => $this->mID );
|
||||
} else {
|
||||
# Already initialized
|
||||
|
|
@ -45,7 +45,8 @@ class Category {
|
|||
$where,
|
||||
__METHOD__
|
||||
);
|
||||
if( !$row ) {
|
||||
|
||||
if ( !$row ) {
|
||||
# Okay, there were no contents. Nothing to initialize.
|
||||
if ( $this->mTitle ) {
|
||||
# If there is a title object but no record in the category table, treat this as an empty category
|
||||
|
|
@ -60,6 +61,7 @@ class Category {
|
|||
return false; # Fail
|
||||
}
|
||||
}
|
||||
|
||||
$this->mID = $row->cat_id;
|
||||
$this->mName = $row->cat_title;
|
||||
$this->mPages = $row->cat_pages;
|
||||
|
|
@ -69,7 +71,7 @@ class Category {
|
|||
# (bug 13683) If the count is negative, then 1) it's obviously wrong
|
||||
# and should not be kept, and 2) we *probably* don't have to scan many
|
||||
# rows to obtain the correct figure, so let's risk a one-time recount.
|
||||
if( $this->mPages < 0 || $this->mSubcats < 0 || $this->mFiles < 0 ) {
|
||||
if ( $this->mPages < 0 || $this->mSubcats < 0 || $this->mFiles < 0 ) {
|
||||
$this->refreshCounts();
|
||||
}
|
||||
|
||||
|
|
@ -86,7 +88,8 @@ class Category {
|
|||
public static function newFromName( $name ) {
|
||||
$cat = new self();
|
||||
$title = Title::makeTitleSafe( NS_CATEGORY, $name );
|
||||
if( !is_object( $title ) ) {
|
||||
|
||||
if ( !is_object( $title ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -126,7 +129,7 @@ class Category {
|
|||
/**
|
||||
* Factory function, for constructing a Category object from a result set
|
||||
*
|
||||
* @param $row result set row, must contain the cat_xxx fields. If the fields are null,
|
||||
* @param $row result set row, must contain the cat_xxx fields. If the fields are null,
|
||||
* the resulting Category object will represent an empty category if a title object
|
||||
* was given. If the fields are null and no title was given, this method fails and returns false.
|
||||
* @param $title optional title object for the category represented by the given row.
|
||||
|
|
@ -137,8 +140,7 @@ class Category {
|
|||
$cat = new self();
|
||||
$cat->mTitle = $title;
|
||||
|
||||
|
||||
# NOTE: the row often results from a LEFT JOIN on categorylinks. This may result in
|
||||
# NOTE: the row often results from a LEFT JOIN on categorylinks. This may result in
|
||||
# all the cat_xxx fields being null, if the category page exists, but nothing
|
||||
# was ever added to the category. This case should be treated linke an empty
|
||||
# category, if possible.
|
||||
|
|
@ -169,12 +171,16 @@ class Category {
|
|||
|
||||
/** @return mixed DB key name, or false on failure */
|
||||
public function getName() { return $this->getX( 'mName' ); }
|
||||
|
||||
/** @return mixed Category ID, or false on failure */
|
||||
public function getID() { return $this->getX( 'mID' ); }
|
||||
|
||||
/** @return mixed Total number of member pages, or false on failure */
|
||||
public function getPageCount() { return $this->getX( 'mPages' ); }
|
||||
|
||||
/** @return mixed Number of subcategories, or false on failure */
|
||||
public function getSubcatCount() { return $this->getX( 'mSubcats' ); }
|
||||
|
||||
/** @return mixed Number of member files, or false on failure */
|
||||
public function getFileCount() { return $this->getX( 'mFiles' ); }
|
||||
|
||||
|
|
@ -182,9 +188,9 @@ class Category {
|
|||
* @return mixed The Title for this category, or false on failure.
|
||||
*/
|
||||
public function getTitle() {
|
||||
if( $this->mTitle ) return $this->mTitle;
|
||||
|
||||
if( !$this->initialize() ) {
|
||||
if ( $this->mTitle ) return $this->mTitle;
|
||||
|
||||
if ( !$this->initialize() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -204,13 +210,19 @@ class Category {
|
|||
|
||||
$conds = array( 'cl_to' => $this->getName(), 'cl_from = page_id' );
|
||||
$options = array( 'ORDER BY' => 'cl_sortkey' );
|
||||
if( $limit ) $options[ 'LIMIT' ] = $limit;
|
||||
if( $offset !== '' ) $conds[] = 'cl_sortkey > ' . $dbr->addQuotes( $offset );
|
||||
|
||||
if ( $limit ) {
|
||||
$options[ 'LIMIT' ] = $limit;
|
||||
}
|
||||
|
||||
if ( $offset !== '' ) {
|
||||
$conds[] = 'cl_sortkey > ' . $dbr->addQuotes( $offset );
|
||||
}
|
||||
|
||||
return TitleArray::newFromResult(
|
||||
$dbr->select(
|
||||
array( 'page', 'categorylinks' ),
|
||||
array( 'page_id', 'page_namespace','page_title', 'page_len',
|
||||
array( 'page_id', 'page_namespace', 'page_title', 'page_len',
|
||||
'page_is_redirect', 'page_latest' ),
|
||||
$conds,
|
||||
__METHOD__,
|
||||
|
|
@ -221,10 +233,10 @@ class Category {
|
|||
|
||||
/** Generic accessor */
|
||||
private function getX( $key ) {
|
||||
if( !$this->initialize() ) {
|
||||
if ( !$this->initialize() ) {
|
||||
return false;
|
||||
}
|
||||
return $this->{$key};
|
||||
return $this-> { $key } ;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -233,14 +245,14 @@ class Category {
|
|||
* @return bool True on success, false on failure
|
||||
*/
|
||||
public function refreshCounts() {
|
||||
if( wfReadOnly() ) {
|
||||
if ( wfReadOnly() ) {
|
||||
return false;
|
||||
}
|
||||
$dbw = wfGetDB( DB_MASTER );
|
||||
$dbw->begin();
|
||||
# Note, we must use names for this, since categorylinks does.
|
||||
if( $this->mName === null ) {
|
||||
if( !$this->initialize() ) {
|
||||
if ( $this->mName === null ) {
|
||||
if ( !$this->initialize() ) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
|
|
@ -249,15 +261,17 @@ class Category {
|
|||
$seqVal = $dbw->nextSequenceValue( 'category_cat_id_seq' );
|
||||
$dbw->insert(
|
||||
'category',
|
||||
array( 'cat_id' => $seqVal,
|
||||
'cat_title' => $this->mName ),
|
||||
array(
|
||||
'cat_id' => $seqVal,
|
||||
'cat_title' => $this->mName
|
||||
),
|
||||
__METHOD__,
|
||||
'IGNORE'
|
||||
);
|
||||
}
|
||||
|
||||
$cond1 = $dbw->conditional( 'page_namespace='.NS_CATEGORY, 1, 'NULL' );
|
||||
$cond2 = $dbw->conditional( 'page_namespace='.NS_FILE, 1, 'NULL' );
|
||||
$cond1 = $dbw->conditional( 'page_namespace=' . NS_CATEGORY, 1, 'NULL' );
|
||||
$cond2 = $dbw->conditional( 'page_namespace=' . NS_FILE, 1, 'NULL' );
|
||||
$result = $dbw->selectRow(
|
||||
array( 'categorylinks', 'page' ),
|
||||
array( 'COUNT(*) AS pages',
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
if( !defined( 'MEDIAWIKI' ) )
|
||||
if ( !defined( 'MEDIAWIKI' ) )
|
||||
die( 1 );
|
||||
|
||||
/**
|
||||
|
|
@ -20,7 +20,7 @@ class CategoryPage extends Article {
|
|||
if ( isset( $diff ) && $diffOnly )
|
||||
return Article::view();
|
||||
|
||||
if( !wfRunHooks( 'CategoryPageView', array( &$this ) ) )
|
||||
if ( !wfRunHooks( 'CategoryPageView', array( &$this ) ) )
|
||||
return;
|
||||
|
||||
if ( NS_CATEGORY == $this->mTitle->getNamespace() ) {
|
||||
|
|
@ -33,18 +33,17 @@ class CategoryPage extends Article {
|
|||
$this->closeShowCategory();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Don't return a 404 for categories in use.
|
||||
*/
|
||||
function hasViewableContent() {
|
||||
if( parent::hasViewableContent() ) {
|
||||
if ( parent::hasViewableContent() ) {
|
||||
return true;
|
||||
} else {
|
||||
$cat = Category::newFromTitle( $this->mTitle );
|
||||
return $cat->getId() != 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function openShowCategory() {
|
||||
|
|
@ -99,7 +98,7 @@ class CategoryViewer {
|
|||
$this->getPagesSection() .
|
||||
$this->getImageSection();
|
||||
|
||||
if( $r == '' ) {
|
||||
if ( $r == '' ) {
|
||||
// If there is no category content to display, only
|
||||
// show the top part of the navigation links.
|
||||
// FIXME: cannot be completely suppressed because it
|
||||
|
|
@ -118,7 +117,7 @@ class CategoryViewer {
|
|||
}
|
||||
|
||||
wfProfileOut( __METHOD__ );
|
||||
return $wgContLang->convert($r);
|
||||
return $wgContLang->convert( $r );
|
||||
}
|
||||
|
||||
function clearCategoryState() {
|
||||
|
|
@ -126,7 +125,7 @@ class CategoryViewer {
|
|||
$this->articles_start_char = array();
|
||||
$this->children = array();
|
||||
$this->children_start_char = array();
|
||||
if( $this->showGallery ) {
|
||||
if ( $this->showGallery ) {
|
||||
$this->gallery = new ImageGallery();
|
||||
$this->gallery->setHideBadImages();
|
||||
}
|
||||
|
|
@ -149,7 +148,7 @@ class CategoryViewer {
|
|||
}
|
||||
|
||||
/**
|
||||
* Add a subcategory to the internal lists, using a title object
|
||||
* Add a subcategory to the internal lists, using a title object
|
||||
* @deprecated kept for compatibility, please use addSubcategoryObject instead
|
||||
*/
|
||||
function addSubcategory( $title, $sortkey, $pageLength ) {
|
||||
|
|
@ -175,7 +174,7 @@ class CategoryViewer {
|
|||
function getSubcategorySortChar( $title, $sortkey ) {
|
||||
global $wgContLang;
|
||||
|
||||
if( $title->getPrefixedText() == $sortkey ) {
|
||||
if ( $title->getPrefixedText() == $sortkey ) {
|
||||
$firstChar = $wgContLang->firstChar( $title->getDBkey() );
|
||||
} else {
|
||||
$firstChar = $wgContLang->firstChar( $sortkey );
|
||||
|
|
@ -189,7 +188,7 @@ class CategoryViewer {
|
|||
*/
|
||||
function addImage( Title $title, $sortkey, $pageLength, $isRedirect = false ) {
|
||||
if ( $this->showGallery ) {
|
||||
if( $this->flip ) {
|
||||
if ( $this->flip ) {
|
||||
$this->gallery->insert( $title );
|
||||
} else {
|
||||
$this->gallery->add( $title );
|
||||
|
|
@ -218,7 +217,7 @@ class CategoryViewer {
|
|||
}
|
||||
|
||||
function finaliseCategoryState() {
|
||||
if( $this->flip ) {
|
||||
if ( $this->flip ) {
|
||||
$this->children = array_reverse( $this->children );
|
||||
$this->children_start_char = array_reverse( $this->children_start_char );
|
||||
$this->articles = array_reverse( $this->articles );
|
||||
|
|
@ -228,16 +227,17 @@ class CategoryViewer {
|
|||
|
||||
function doCategoryQuery() {
|
||||
$dbr = wfGetDB( DB_SLAVE, 'category' );
|
||||
if( $this->from != '' ) {
|
||||
if ( $this->from != '' ) {
|
||||
$pageCondition = 'cl_sortkey >= ' . $dbr->addQuotes( $this->from );
|
||||
$this->flip = false;
|
||||
} elseif( $this->until != '' ) {
|
||||
} elseif ( $this->until != '' ) {
|
||||
$pageCondition = 'cl_sortkey < ' . $dbr->addQuotes( $this->until );
|
||||
$this->flip = true;
|
||||
} else {
|
||||
$pageCondition = '1 = 1';
|
||||
$this->flip = false;
|
||||
}
|
||||
|
||||
$res = $dbr->select(
|
||||
array( 'page', 'categorylinks', 'category' ),
|
||||
array( 'page_title', 'page_namespace', 'page_len', 'page_is_redirect', 'cl_sortkey',
|
||||
|
|
@ -253,8 +253,9 @@ class CategoryViewer {
|
|||
|
||||
$count = 0;
|
||||
$this->nextPage = null;
|
||||
while( $x = $dbr->fetchObject ( $res ) ) {
|
||||
if( ++$count > $this->limit ) {
|
||||
|
||||
while ( $x = $dbr->fetchObject ( $res ) ) {
|
||||
if ( ++$count > $this->limit ) {
|
||||
// We've reached the one extra which shows that there are
|
||||
// additional pages to be had. Stop here...
|
||||
$this->nextPage = $x->cl_sortkey;
|
||||
|
|
@ -263,10 +264,10 @@ class CategoryViewer {
|
|||
|
||||
$title = Title::makeTitle( $x->page_namespace, $x->page_title );
|
||||
|
||||
if( $title->getNamespace() == NS_CATEGORY ) {
|
||||
if ( $title->getNamespace() == NS_CATEGORY ) {
|
||||
$cat = Category::newFromRow( $x, $title );
|
||||
$this->addSubcategoryObject( $cat, $x->cl_sortkey, $x->page_len );
|
||||
} elseif( $this->showGallery && $title->getNamespace() == NS_FILE ) {
|
||||
} elseif ( $this->showGallery && $title->getNamespace() == NS_FILE ) {
|
||||
$this->addImage( $title, $x->cl_sortkey, $x->page_len, $x->page_is_redirect );
|
||||
} else {
|
||||
$this->addPage( $title, $x->cl_sortkey, $x->page_len, $x->page_is_redirect );
|
||||
|
|
@ -287,7 +288,8 @@ class CategoryViewer {
|
|||
$rescnt = count( $this->children );
|
||||
$dbcnt = $this->cat->getSubcatCount();
|
||||
$countmsg = $this->getCountMessage( $rescnt, $dbcnt, 'subcat' );
|
||||
if( $rescnt > 0 ) {
|
||||
|
||||
if ( $rescnt > 0 ) {
|
||||
# Showing subcategories
|
||||
$r .= "<div id=\"mw-subcategories\">\n";
|
||||
$r .= '<h2>' . wfMsg( 'subcategories' ) . "</h2>\n";
|
||||
|
|
@ -312,7 +314,7 @@ class CategoryViewer {
|
|||
$rescnt = count( $this->articles );
|
||||
$countmsg = $this->getCountMessage( $rescnt, $dbcnt, 'article' );
|
||||
|
||||
if( $rescnt > 0 ) {
|
||||
if ( $rescnt > 0 ) {
|
||||
$r = "<div id=\"mw-pages\">\n";
|
||||
$r .= '<h2>' . wfMsg( 'category_header', $ti ) . "</h2>\n";
|
||||
$r .= $countmsg;
|
||||
|
|
@ -323,7 +325,7 @@ class CategoryViewer {
|
|||
}
|
||||
|
||||
function getImageSection() {
|
||||
if( $this->showGallery && ! $this->gallery->isEmpty() ) {
|
||||
if ( $this->showGallery && ! $this->gallery->isEmpty() ) {
|
||||
$dbcnt = $this->cat->getFileCount();
|
||||
$rescnt = $this->gallery->count();
|
||||
$countmsg = $this->getCountMessage( $rescnt, $dbcnt, 'file' );
|
||||
|
|
@ -337,9 +339,9 @@ class CategoryViewer {
|
|||
}
|
||||
|
||||
function getCategoryBottom() {
|
||||
if( $this->until != '' ) {
|
||||
if ( $this->until != '' ) {
|
||||
return $this->pagingLinks( $this->title, $this->nextPage, $this->until, $this->limit );
|
||||
} elseif( $this->nextPage != '' || $this->from != '' ) {
|
||||
} elseif ( $this->nextPage != '' || $this->from != '' ) {
|
||||
return $this->pagingLinks( $this->title, $this->from, $this->nextPage, $this->limit );
|
||||
} else {
|
||||
return '';
|
||||
|
|
@ -359,7 +361,7 @@ class CategoryViewer {
|
|||
function formatList( $articles, $articles_start_char, $cutoff = 6 ) {
|
||||
if ( count ( $articles ) > $cutoff ) {
|
||||
return $this->columnList( $articles, $articles_start_char );
|
||||
} elseif ( count($articles) > 0) {
|
||||
} elseif ( count( $articles ) > 0 ) {
|
||||
// for short lists of articles in categories.
|
||||
return $this->shortList( $articles, $articles_start_char );
|
||||
}
|
||||
|
|
@ -384,7 +386,7 @@ class CategoryViewer {
|
|||
function columnList( $articles, $articles_start_char ) {
|
||||
$columns = array_combine( $articles, $articles_start_char );
|
||||
# Split into three columns
|
||||
$columns = array_chunk( $columns, ceil( count( $columns )/3 ), true /* preserve keys */ );
|
||||
$columns = array_chunk( $columns, ceil( count( $columns ) / 3 ), true /* preserve keys */ );
|
||||
|
||||
$ret = '<table width="100%"><tr valign="top"><td>';
|
||||
$prevchar = null;
|
||||
|
|
@ -435,10 +437,10 @@ class CategoryViewer {
|
|||
*/
|
||||
function shortList( $articles, $articles_start_char ) {
|
||||
$r = '<h3>' . htmlspecialchars( $articles_start_char[0] ) . "</h3>\n";
|
||||
$r .= '<ul><li>'.$articles[0].'</li>';
|
||||
for ($index = 1; $index < count($articles); $index++ )
|
||||
$r .= '<ul><li>' . $articles[0] . '</li>';
|
||||
for ( $index = 1; $index < count( $articles ); $index++ )
|
||||
{
|
||||
if ($articles_start_char[$index] != $articles_start_char[$index - 1])
|
||||
if ( $articles_start_char[$index] != $articles_start_char[$index - 1] )
|
||||
{
|
||||
$r .= "</ul><h3>" . htmlspecialchars( $articles_start_char[$index] ) . "</h3>\n<ul>";
|
||||
}
|
||||
|
|
@ -464,7 +466,8 @@ class CategoryViewer {
|
|||
$limitText = $wgLang->formatNum( $limit );
|
||||
|
||||
$prevLink = wfMsgExt( 'prevn', array( 'escape', 'parsemag' ), $limitText );
|
||||
if( $first != '' ) {
|
||||
|
||||
if ( $first != '' ) {
|
||||
$prevQuery = $query;
|
||||
$prevQuery['until'] = $first;
|
||||
$prevLink = $sk->linkKnown(
|
||||
|
|
@ -474,8 +477,10 @@ class CategoryViewer {
|
|||
$prevQuery
|
||||
);
|
||||
}
|
||||
|
||||
$nextLink = wfMsgExt( 'nextn', array( 'escape', 'parsemag' ), $limitText );
|
||||
if( $last != '' ) {
|
||||
|
||||
if ( $last != '' ) {
|
||||
$lastQuery = $query;
|
||||
$lastQuery['from'] = $last;
|
||||
$nextLink = $sk->linkKnown(
|
||||
|
|
@ -516,12 +521,14 @@ class CategoryViewer {
|
|||
# know the right figure.
|
||||
# 3) We have no idea.
|
||||
$totalrescnt = count( $this->articles ) + count( $this->children ) +
|
||||
($this->showGallery ? $this->gallery->count() : 0);
|
||||
if($dbcnt == $rescnt || (($totalrescnt == $this->limit || $this->from
|
||||
|| $this->until) && $dbcnt > $rescnt)){
|
||||
( $this->showGallery ? $this->gallery->count() : 0 );
|
||||
|
||||
if ( $dbcnt == $rescnt || ( ( $totalrescnt == $this->limit || $this->from
|
||||
|| $this->until ) && $dbcnt > $rescnt ) )
|
||||
{
|
||||
# Case 1: seems sane.
|
||||
$totalcnt = $dbcnt;
|
||||
} elseif($totalrescnt < $this->limit && !$this->from && !$this->until){
|
||||
} elseif ( $totalrescnt < $this->limit && !$this->from && !$this->until ) {
|
||||
# Case 2: not sane, but salvageable. Use the number of results.
|
||||
# Since there are fewer than 200, we can also take this opportunity
|
||||
# to refresh the incorrect category table entry -- which should be
|
||||
|
|
@ -530,10 +537,14 @@ class CategoryViewer {
|
|||
$this->cat->refreshCounts();
|
||||
} else {
|
||||
# Case 3: hopeless. Don't give a total count at all.
|
||||
return wfMsgExt("category-$type-count-limited", 'parse',
|
||||
return wfMsgExt( "category-$type-count-limited", 'parse',
|
||||
$wgLang->formatNum( $rescnt ) );
|
||||
}
|
||||
return wfMsgExt( "category-$type-count", 'parse', $wgLang->formatNum( $rescnt ),
|
||||
$wgLang->formatNum( $totalcnt ) );
|
||||
return wfMsgExt(
|
||||
"category-$type-count",
|
||||
'parse',
|
||||
$wgLang->formatNum( $rescnt ),
|
||||
$wgLang->formatNum( $totalcnt )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@
|
|||
*
|
||||
*/
|
||||
class Categoryfinder {
|
||||
|
||||
var $articles = array(); # The original article IDs passed to the seed function
|
||||
var $deadend = array(); # Array of DBKEY category names for categories that don't have a page
|
||||
var $parents = array(); # Array of [ID => array()]
|
||||
|
|
@ -53,7 +52,7 @@ class Categoryfinder {
|
|||
$this->targets = array();
|
||||
foreach ( $categories as $c ) {
|
||||
$ct = Title::makeTitleSafe( NS_CATEGORY, $c );
|
||||
if( $ct ) {
|
||||
if ( $ct ) {
|
||||
$c = $ct->getDBkey();
|
||||
$this->targets[$c] = $c;
|
||||
}
|
||||
|
|
@ -73,6 +72,7 @@ class Categoryfinder {
|
|||
|
||||
# Now check if this applies to the individual articles
|
||||
$ret = array();
|
||||
|
||||
foreach ( $this->articles as $article ) {
|
||||
$conds = $this->targets;
|
||||
if ( $this->check( $article, $conds ) ) {
|
||||
|
|
@ -92,14 +92,20 @@ class Categoryfinder {
|
|||
*/
|
||||
function check( $id , &$conds, $path = array() ) {
|
||||
// Check for loops and stop!
|
||||
if( in_array( $id, $path ) )
|
||||
if ( in_array( $id, $path ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$path[] = $id;
|
||||
|
||||
# Shortcut (runtime paranoia): No contitions=all matched
|
||||
if ( count( $conds ) == 0 ) return true;
|
||||
if ( count( $conds ) == 0 ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( !isset( $this->parents[$id] ) ) return false;
|
||||
if ( !isset( $this->parents[$id] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
# iterate through the parents
|
||||
foreach ( $this->parents[$id] as $p ) {
|
||||
|
|
@ -127,7 +133,7 @@ class Categoryfinder {
|
|||
# No sub-parent
|
||||
continue ;
|
||||
}
|
||||
$done = $this->check( $this->name2id[$pname], $conds,$path );
|
||||
$done = $this->check( $this->name2id[$pname], $conds, $path );
|
||||
if ( $done || count( $conds ) == 0 ) {
|
||||
# Subparents have done it!
|
||||
return true;
|
||||
|
|
@ -143,10 +149,10 @@ class Categoryfinder {
|
|||
# Find all parents of the article currently in $this->next
|
||||
$layer = array();
|
||||
$res = $this->dbr->select(
|
||||
/* FROM */ 'categorylinks',
|
||||
/* SELECT */ '*',
|
||||
/* WHERE */ array( 'cl_from' => $this->next ),
|
||||
__METHOD__ . "-1"
|
||||
/* FROM */ 'categorylinks',
|
||||
/* SELECT */ '*',
|
||||
/* WHERE */ array( 'cl_from' => $this->next ),
|
||||
__METHOD__ . "-1"
|
||||
);
|
||||
while ( $o = $this->dbr->fetchObject( $res ) ) {
|
||||
$k = $o->cl_to ;
|
||||
|
|
@ -159,6 +165,7 @@ class Categoryfinder {
|
|||
|
||||
# Ignore those we already have
|
||||
if ( in_array ( $k , $this->deadend ) ) continue;
|
||||
|
||||
if ( isset ( $this->name2id[$k] ) ) continue;
|
||||
|
||||
# Hey, new category!
|
||||
|
|
@ -170,10 +177,10 @@ class Categoryfinder {
|
|||
# Find the IDs of all category pages in $layer, if they exist
|
||||
if ( count ( $layer ) > 0 ) {
|
||||
$res = $this->dbr->select(
|
||||
/* FROM */ 'page',
|
||||
/* SELECT */ array( 'page_id', 'page_title' ),
|
||||
/* WHERE */ array( 'page_namespace' => NS_CATEGORY , 'page_title' => $layer ),
|
||||
__METHOD__ . "-2"
|
||||
/* FROM */ 'page',
|
||||
/* SELECT */ array( 'page_id', 'page_title' ),
|
||||
/* WHERE */ array( 'page_namespace' => NS_CATEGORY , 'page_title' => $layer ),
|
||||
__METHOD__ . "-2"
|
||||
);
|
||||
while ( $o = $this->dbr->fetchObject( $res ) ) {
|
||||
$id = $o->page_id;
|
||||
|
|
@ -190,4 +197,4 @@ class Categoryfinder {
|
|||
}
|
||||
}
|
||||
|
||||
} # END OF CLASS "Categoryfinder"
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue