]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - includes/TitleArray.php
MediaWiki 1.30.2-scripts
[autoinstalls/mediawiki.git] / includes / TitleArray.php
1 <?php
2 /**
3  * Class to walk into a list of Title objects.
4  *
5  * Note: this entire file is a byte-for-byte copy of UserArray.php with
6  * s/User/Title/.  If anyone can figure out how to do this nicely with
7  * inheritance or something, please do so.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22  * http://www.gnu.org/copyleft/gpl.html
23  *
24  * @file
25  */
26
27 use Wikimedia\Rdbms\ResultWrapper;
28
29 /**
30  * The TitleArray class only exists to provide the newFromResult method at pre-
31  * sent.
32  */
33 abstract class TitleArray implements Iterator {
34         /**
35          * @param ResultWrapper $res A SQL result including at least page_namespace and
36          *   page_title -- also can have page_id, page_len, page_is_redirect,
37          *   page_latest (if those will be used).  See Title::newFromRow.
38          * @return TitleArrayFromResult
39          */
40         static function newFromResult( $res ) {
41                 $array = null;
42                 if ( !Hooks::run( 'TitleArrayFromResult', [ &$array, $res ] ) ) {
43                         return null;
44                 }
45                 if ( $array === null ) {
46                         $array = self::newFromResult_internal( $res );
47                 }
48                 return $array;
49         }
50
51         /**
52          * @param ResultWrapper $res
53          * @return TitleArrayFromResult
54          */
55         protected static function newFromResult_internal( $res ) {
56                 $array = new TitleArrayFromResult( $res );
57                 return $array;
58         }
59 }