MediaWiki  1.23.3
Categoryfinder.php
Go to the documentation of this file.
1 <?php
46  var $articles = array(); # The original article IDs passed to the seed function
47  var $deadend = array(); # Array of DBKEY category names for categories that don't have a page
48  var $parents = array(); # Array of [ID => array()]
49  var $next = array(); # Array of article/category IDs
50  var $targets = array(); # Array of DBKEY category names
51  var $name2id = array();
52  var $mode; # "AND" or "OR"
53 
57  var $dbr; # Read-DB slave
58 
62  function __construct() {
63  }
64 
72  function seed( $article_ids, $categories, $mode = 'AND' ) {
73  $this->articles = $article_ids;
74  $this->next = $article_ids;
75  $this->mode = $mode;
76 
77  # Set the list of target categories; convert them to DBKEY form first
78  $this->targets = array();
79  foreach ( $categories as $c ) {
80  $ct = Title::makeTitleSafe( NS_CATEGORY, $c );
81  if ( $ct ) {
82  $c = $ct->getDBkey();
83  $this->targets[$c] = $c;
84  }
85  }
86  }
87 
93  function run() {
94  $this->dbr = wfGetDB( DB_SLAVE );
95  while ( count( $this->next ) > 0 ) {
96  $this->scan_next_layer();
97  }
98 
99  # Now check if this applies to the individual articles
100  $ret = array();
101 
102  foreach ( $this->articles as $article ) {
103  $conds = $this->targets;
104  if ( $this->check( $article, $conds ) ) {
105  # Matches the conditions
106  $ret[] = $article;
107  }
108  }
109  return $ret;
110  }
111 
119  function check( $id, &$conds, $path = array() ) {
120  // Check for loops and stop!
121  if ( in_array( $id, $path ) ) {
122  return false;
123  }
124 
125  $path[] = $id;
126 
127  # Shortcut (runtime paranoia): No conditions=all matched
128  if ( count( $conds ) == 0 ) {
129  return true;
130  }
131 
132  if ( !isset( $this->parents[$id] ) ) {
133  return false;
134  }
135 
136  # iterate through the parents
137  foreach ( $this->parents[$id] as $p ) {
138  $pname = $p->cl_to;
139 
140  # Is this a condition?
141  if ( isset( $conds[$pname] ) ) {
142  # This key is in the category list!
143  if ( $this->mode == 'OR' ) {
144  # One found, that's enough!
145  $conds = array();
146  return true;
147  } else {
148  # Assuming "AND" as default
149  unset( $conds[$pname] );
150  if ( count( $conds ) == 0 ) {
151  # All conditions met, done
152  return true;
153  }
154  }
155  }
156 
157  # Not done yet, try sub-parents
158  if ( !isset( $this->name2id[$pname] ) ) {
159  # No sub-parent
160  continue;
161  }
162  $done = $this->check( $this->name2id[$pname], $conds, $path );
163  if ( $done || count( $conds ) == 0 ) {
164  # Subparents have done it!
165  return true;
166  }
167  }
168  return false;
169  }
170 
174  function scan_next_layer() {
175  wfProfileIn( __METHOD__ );
176 
177  # Find all parents of the article currently in $this->next
178  $layer = array();
179  $res = $this->dbr->select(
180  /* FROM */ 'categorylinks',
181  /* SELECT */ '*',
182  /* WHERE */ array( 'cl_from' => $this->next ),
183  __METHOD__ . '-1'
184  );
185  foreach ( $res as $o ) {
186  $k = $o->cl_to;
187 
188  # Update parent tree
189  if ( !isset( $this->parents[$o->cl_from] ) ) {
190  $this->parents[$o->cl_from] = array();
191  }
192  $this->parents[$o->cl_from][$k] = $o;
193 
194  # Ignore those we already have
195  if ( in_array( $k, $this->deadend ) ) {
196  continue;
197  }
198 
199  if ( isset( $this->name2id[$k] ) ) {
200  continue;
201  }
202 
203  # Hey, new category!
204  $layer[$k] = $k;
205  }
206 
207  $this->next = array();
208 
209  # Find the IDs of all category pages in $layer, if they exist
210  if ( count( $layer ) > 0 ) {
211  $res = $this->dbr->select(
212  /* FROM */ 'page',
213  /* SELECT */ array( 'page_id', 'page_title' ),
214  /* WHERE */ array( 'page_namespace' => NS_CATEGORY, 'page_title' => $layer ),
215  __METHOD__ . '-2'
216  );
217  foreach ( $res as $o ) {
218  $id = $o->page_id;
219  $name = $o->page_title;
220  $this->name2id[$name] = $id;
221  $this->next[] = $id;
222  unset( $layer[$name] );
223  }
224  }
225 
226  # Mark dead ends
227  foreach ( $layer as $v ) {
228  $this->deadend[$v] = $v;
229  }
230 
231  wfProfileOut( __METHOD__ );
232  }
233 }
check
in this case you re responsible for computing and outputting the entire conflict i the difference between revisions and your text headers and sections and Diff overridable Default is either copyrightwarning or copyrightwarning2 overridable Default is editpage tos summary such as anonymity and the real check
Definition: hooks.txt:1038
of
globals txt Globals are evil The original MediaWiki code relied on globals for processing context far too often MediaWiki development since then has been a story of slowly moving context out of global variables and into objects Storing processing context in object member variables allows those objects to be reused in a much more flexible way Consider the elegance of
Definition: globals.txt:10
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
wfProfileIn
wfProfileIn( $functionname)
Begin profiling of a function.
Definition: Profiler.php:33
Categoryfinder
The "Categoryfinder" class takes a list of articles, creates an internal representation of all their ...
Definition: Categoryfinder.php:45
Categoryfinder\$deadend
$deadend
Definition: Categoryfinder.php:47
Categoryfinder\seed
seed( $article_ids, $categories, $mode='AND')
Initializes the instance.
Definition: Categoryfinder.php:71
Categoryfinder\$articles
$articles
Definition: Categoryfinder.php:46
article
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling but I prefer the flexibility This should also do the output encoding The system allocates a global one in $wgOut Title Represents the title of an article
Definition: design.txt:25
wfProfileOut
wfProfileOut( $functionname='missing')
Stop profiling of a function.
Definition: Profiler.php:46
Categoryfinder\scan_next_layer
scan_next_layer()
Scans a "parent layer" of the articles/categories in $this->next.
Definition: Categoryfinder.php:173
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
NS_CATEGORY
const NS_CATEGORY
Definition: Defines.php:93
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:336
$path
$path
Definition: NoLocalSettings.php:35
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
that
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global then executing the whole list after the page is displayed We don t do anything smart like collating updates to the same table or such because the list is almost always going to have just one item on if that
Definition: deferred.txt:11
$res
$res
Definition: database.txt:21