コード例 #1
0
ファイル: ArticleTest.php プロジェクト: Tjorriemorrie/app
 /**
  * Checks for the existence of the backwards compatibility static functions (forwarders to WikiPage class)
  */
 function testStaticFunctions()
 {
     $this->assertEquals(WikiPage::selectFields(), Article::selectFields(), "Article static functions");
     $this->assertEquals(true, is_callable("Article::onArticleCreate"), "Article static functions");
     $this->assertEquals(true, is_callable("Article::onArticleDelete"), "Article static functions");
     $this->assertEquals(true, is_callable("ImagePage::onArticleEdit"), "Article static functions");
     $this->assertTrue(is_string(CategoryPage::getAutosummary('', '', 0)), "Article static functions");
 }
コード例 #2
0
ファイル: ArticleTest.php プロジェクト: claudinec/galan-wiki
 /**
  * Checks for the existence of the backwards compatibility static functions
  * (forwarders to WikiPage class)
  *
  * @covers Article::selectFields
  * @covers Article::onArticleCreate
  * @covers Article::onArticleDelete
  * @covers Article::onArticleEdit
  * @covers Article::getAutosummary
  */
 public function testStaticFunctions()
 {
     $this->hideDeprecated('Article::selectFields');
     $this->hideDeprecated('Article::getAutosummary');
     $this->hideDeprecated('WikiPage::getAutosummary');
     $this->hideDeprecated('CategoryPage::getAutosummary');
     // Inherited from Article
     $this->assertEquals(WikiPage::selectFields(), Article::selectFields(), "Article static functions");
     $this->assertEquals(true, is_callable("Article::onArticleCreate"), "Article static functions");
     $this->assertEquals(true, is_callable("Article::onArticleDelete"), "Article static functions");
     $this->assertEquals(true, is_callable("ImagePage::onArticleEdit"), "Article static functions");
     $this->assertTrue(is_string(CategoryPage::getAutosummary('', '', 0)), "Article static functions");
 }
コード例 #3
0
ファイル: Title.php プロジェクト: MediaWiki-stable/1.26.1
 /**
  * Get an array of Title objects linked from this Title
  * Also stores the IDs in the link cache.
  *
  * WARNING: do not use this function on arbitrary user-supplied titles!
  * On heavily-used templates it will max out the memory.
  *
  * @param array $options May be FOR UPDATE
  * @param string $table Table name
  * @param string $prefix Fields prefix
  * @return array Array of Title objects linking here
  */
 public function getLinksFrom($options = array(), $table = 'pagelinks', $prefix = 'pl')
 {
     $id = $this->getArticleID();
     # If the page doesn't exist; there can't be any link from this page
     if (!$id) {
         return array();
     }
     if (count($options) > 0) {
         $db = wfGetDB(DB_MASTER);
     } else {
         $db = wfGetDB(DB_SLAVE);
     }
     $blNamespace = "{$prefix}_namespace";
     $blTitle = "{$prefix}_title";
     $res = $db->select(array($table, 'page'), array_merge(array($blNamespace, $blTitle), WikiPage::selectFields()), array("{$prefix}_from" => $id), __METHOD__, $options, array('page' => array('LEFT JOIN', array("page_namespace={$blNamespace}", "page_title={$blTitle}"))));
     $retVal = array();
     $linkCache = LinkCache::singleton();
     foreach ($res as $row) {
         if ($row->page_id) {
             $titleObj = Title::newFromRow($row);
         } else {
             $titleObj = Title::makeTitle($row->{$blNamespace}, $row->{$blTitle});
             $linkCache->addBadLinkObj($titleObj);
         }
         $retVal[] = $titleObj;
     }
     return $retVal;
 }
コード例 #4
0
ファイル: Article.php プロジェクト: ngertrudiz/mediawiki
 /**
  * @return array
  *
  * @deprecated since 1.24, use WikiPage::selectFields() instead
  */
 public static function selectFields()
 {
     wfDeprecated(__METHOD__, '1.24');
     return WikiPage::selectFields();
 }
コード例 #5
0
ファイル: Title.php プロジェクト: paladox/mediawiki
 /**
  * Get an array of Title objects linked from this Title
  * Also stores the IDs in the link cache.
  *
  * WARNING: do not use this function on arbitrary user-supplied titles!
  * On heavily-used templates it will max out the memory.
  *
  * @param array $options Query option to Database::select()
  * @param string $table Table name
  * @param string $prefix Fields prefix
  * @return array Array of Title objects linking here
  */
 public function getLinksFrom($options = [], $table = 'pagelinks', $prefix = 'pl')
 {
     $id = $this->getArticleID();
     # If the page doesn't exist; there can't be any link from this page
     if (!$id) {
         return [];
     }
     $db = wfGetDB(DB_REPLICA);
     $blNamespace = "{$prefix}_namespace";
     $blTitle = "{$prefix}_title";
     $res = $db->select([$table, 'page'], array_merge([$blNamespace, $blTitle], WikiPage::selectFields()), ["{$prefix}_from" => $id], __METHOD__, $options, ['page' => ['LEFT JOIN', ["page_namespace={$blNamespace}", "page_title={$blTitle}"]]]);
     $retVal = [];
     $linkCache = LinkCache::singleton();
     foreach ($res as $row) {
         if ($row->page_id) {
             $titleObj = Title::newFromRow($row);
         } else {
             $titleObj = Title::makeTitle($row->{$blNamespace}, $row->{$blTitle});
             $linkCache->addBadLinkObj($titleObj);
         }
         $retVal[] = $titleObj;
     }
     return $retVal;
 }
コード例 #6
0
ファイル: Article.php プロジェクト: nischayn22/mediawiki-core
 /**
  * @return array
  */
 public static function selectFields()
 {
     return WikiPage::selectFields();
 }
コード例 #7
0
 /**
  * Fetch a page record with the given conditions
  * @param $dbr Database object
  * @param $conditions Array
  * @return mixed Database result resource, or false on failure
  */
 protected function pageData($dbr, $conditions)
 {
     $row = $dbr->selectRow(array('page', 'flaggedpages', 'flaggedpage_config'), array_merge(WikiPage::selectFields(), FRPageConfig::selectFields(), array('fp_pending_since', 'fp_stable', 'fp_reviewed')), $conditions, __METHOD__, array(), array('flaggedpages' => array('LEFT JOIN', 'fp_page_id = page_id'), 'flaggedpage_config' => array('LEFT JOIN', 'fpc_page_id = page_id')));
     return $row;
 }
コード例 #8
0
 /**
  * @param ApiPageSet $resultPageSet
  * @return
  */
 private function run($resultPageSet = null)
 {
     $params = $this->extractRequestParams();
     $exclude = false;
     $this->requireOnlyOneParameter($params, 'coord', 'page');
     if (isset($params['coord'])) {
         $arr = explode('|', $params['coord']);
         if (count($arr) != 2 || !GeoData::validateCoord($arr[0], $arr[1], $params['globe'])) {
             $this->dieUsage('Invalid coordinate provided', '_invalid-coord');
         }
         $lat = $arr[0];
         $lon = $arr[1];
     } elseif (isset($params['page'])) {
         $t = Title::newFromText($params['page']);
         if (!$t || !$t->canExist()) {
             $this->dieUsage("Invalid page title ``{$params['page']}'' provided", '_invalid-page');
         }
         if (!$t->exists()) {
             $this->dieUsage("Page ``{$params['page']}'' does not exist", '_nonexistent-page');
         }
         $coord = GeoData::getPageCoordinates($t);
         if (!$coord) {
             $this->dieUsage('Page coordinates unknown', '_no-coordinates');
         }
         $lat = $coord->lat;
         $lon = $coord->lon;
         $exclude = $t->getArticleID();
     }
     $lat = floatval($lat);
     $lon = floatval($lon);
     $radius = intval($params['radius']);
     $rect = GeoMath::rectAround($lat, $lon, $radius);
     $dbr = wfGetDB(DB_SLAVE);
     $this->addTables(array('page', 'geo_tags'));
     $this->addFields(array('gt_lat', 'gt_lon', 'gt_primary'));
     // retrieve some fields only if page set needs them
     if (is_null($resultPageSet)) {
         $this->addFields(array('page_id', 'page_namespace', 'page_title'));
     } else {
         $this->addFields(WikiPage::selectFields());
     }
     foreach ($params['prop'] as $prop) {
         if (isset(Coord::$fieldMapping[$prop])) {
             $this->addFields(Coord::$fieldMapping[$prop]);
         }
     }
     $this->addWhereFld('gt_globe', $params['globe']);
     $this->addWhereFld('gt_lat_int', self::intRange($rect["minLat"], $rect["maxLat"]));
     $this->addWhereFld('gt_lon_int', self::intRange($rect["minLon"], $rect["maxLon"]));
     $this->addWhereRange('gt_lat', 'newer', $rect["minLat"], $rect["maxLat"], false);
     if ($rect["minLon"] > $rect["maxLon"]) {
         $this->addWhere("gt_lon < {$rect['maxLon']} OR gt_lon > {$rect['minLon']}");
     } else {
         $this->addWhereRange('gt_lon', 'newer', $rect["minLon"], $rect["maxLon"], false);
     }
     $this->addWhereFld('page_namespace', $params['namespace']);
     $this->addWhere('gt_page_id = page_id');
     if ($exclude) {
         $this->addWhere("gt_page_id <> {$exclude}");
     }
     if (isset($params['maxdim'])) {
         $this->addWhere('gt_dim < ' . intval($params['maxdim']));
     }
     $primary = array_flip($params['primary']);
     $this->addWhereIf(array('gt_primary' => 1), isset($primary['yes']) && !isset($primary['no']));
     $this->addWhereIf(array('gt_primary' => 0), !isset($primary['yes']) && isset($primary['no']));
     $this->addOption('USE INDEX', 'gt_spatial');
     $limit = $params['limit'];
     $res = $this->select(__METHOD__);
     $rows = array();
     foreach ($res as $row) {
         $row->dist = GeoMath::distance($lat, $lon, $row->gt_lat, $row->gt_lon);
         $rows[] = $row;
     }
     // sort in PHP because sorting via SQL involves a filesort
     usort($rows, 'ApiQueryGeoSearch::compareRows');
     $result = $this->getResult();
     foreach ($rows as $row) {
         if (!$limit--) {
             break;
         }
         if (is_null($resultPageSet)) {
             $title = Title::newFromRow($row);
             $vals = array('pageid' => intval($row->page_id), 'ns' => intval($title->getNamespace()), 'title' => $title->getPrefixedText(), 'lat' => floatval($row->gt_lat), 'lon' => floatval($row->gt_lon), 'dist' => round($row->dist, 1));
             if ($row->gt_primary) {
                 $vals['primary'] = '';
             }
             foreach ($params['prop'] as $prop) {
                 if (isset(Coord::$fieldMapping[$prop]) && isset($row->{Coord::$fieldMapping[$prop]})) {
                     $field = Coord::$fieldMapping[$prop];
                     $vals[$prop] = $row->{$field};
                 }
             }
             $fit = $result->addValue(array('query', $this->getModuleName()), null, $vals);
             if (!$fit) {
                 break;
             }
         } else {
             $resultPageSet->processDbRow($row);
         }
     }
     if (is_null($resultPageSet)) {
         $result->setIndexedTagName_internal(array('query', $this->getModuleName()), $this->getModulePrefix());
     }
 }