30 private static $instance;
44 if ( ( self::$instance === null ) || ( self::$instance->sourceNamespace != $title->getNamespace() ) ) {
45 self::$instance =
new Targets( $title, $config );
47 return self::$instance;
58 self::$instance = null;
88 $this->config = $config;
89 $this->sourceNamespace = $title->getNamespace();
98 ( $this->config->preferShortTitles ) ? $sortOrder =
'ASC' : $sortOrder =
'DESC';
102 if ( $this->config->blackList ) {
103 $blackList =
'page_title NOT IN ' .
104 str_replace(
' ',
'_',
'("' . implode(
'","', str_replace(
'"',
'\"', $this->config->blackList ) ) .
'")' );
109 if ( $this->config->sameNamespace ) {
111 $namespaces = array_diff( $this->config->targetNamespaces, [ $this->sourceNamespace ] );
112 array_unshift( $namespaces, $this->sourceNamespace );
114 $namespaces = $this->config->targetNamespaces;
124 $weightSelect =
"CASE page_namespace ";
126 foreach ($namespaces as &$namespaceValue) {
127 $currentWeight = $currentWeight + 100;
128 $weightSelect = $weightSelect .
" WHEN " . $namespaceValue .
" THEN " . $currentWeight . PHP_EOL;
130 $weightSelect = $weightSelect .
" END ";
131 $namespacesClause =
'(' . implode(
', ', $namespaces ) .
')';
137 $dbr = wfGetDB( DB_SLAVE );
138 $this->queryResult = $dbr->select(
140 array(
'page_title',
'page_namespace' ,
"weight" => $weightSelect),
143 'page_namespace IN ' . $namespacesClause,
144 $this->charLength() .
'(page_title) >= ' . $this->config->minimumTitleLength,
149 array(
'ORDER BY' =>
'weight ASC, ' . $this->charLength() .
'(page_title) ' . $sortOrder )
153 private function charLength() {
154 if ($this->charLengthFunction === null) {
155 $this->charLengthFunction = $this->config->sqliteDatabase() ?
'LENGTH' :
'CHAR_LENGTH';
157 return $this->charLengthFunction;
fetch()
Fetches the page titles from the database.
$charLengthFunction
Stores the CHAR_LENGTH function to be used with the database connection.
Fetches potential target page titles from the database.
static singleton(\Title $title, Config $config)
Singleton factory that returns a (cached) database query results with potential target page titles...
static invalidate()
Invalidates the cache; the next call of Targets::singleton() will trigger a database query...
__construct(\Title $title, Config $config)
The constructor is private to enforce using the singleton pattern.
$queryResult
Holds the results of a database query for target page titles, filtered and sorted.
$sourceNamespace
Holds the source page's namespace (integer) for which the list of target pages was built...
Holds LinkTitles configuration.
The LinkTitles class holds configuration for the LinkTitles extension.