Added namepsace-support to cli and specialpage

This commit is contained in:
c0nnex
2015-09-30 02:48:10 +02:00
parent c75fe391ce
commit 5e58bc0dfc
3 changed files with 19 additions and 11 deletions

View File

@ -239,13 +239,12 @@
/// If in doubt, call MediaWiki's `RequestContext::getMain()` /// If in doubt, call MediaWiki's `RequestContext::getMain()`
/// to obtain such an object. /// to obtain such an object.
/// @returns undefined /// @returns undefined
public static function processPage($title, RequestContext $context) { public static function processPage(Title $title, RequestContext $context) {
// TODO: make this namespace-aware // TODO: make this namespace-aware
$titleObj = Title::makeTitle(0, $title); $page = WikiPage::factory($title);
$page = WikiPage::factory($titleObj);
$content = $page->getContent(); $content = $page->getContent();
$text = $content->getContentHandler()->serializeContent($content); $text = $content->getContentHandler()->serializeContent($content);
$newText = LinkTitles::parseContent($titleObj, $text); $newText = LinkTitles::parseContent($title, $text);
if ( $text != $newText ) { if ( $text != $newText ) {
$content = $content->getContentHandler()->unserializeContent( $newText ); $content = $content->getContentHandler()->unserializeContent( $newText );
$page->doQuickEditContent($content, $page->doQuickEditContent($content,

View File

@ -71,20 +71,25 @@ class LinkTitlesCli extends Maintenance {
/// if the `--start` option is given) and call LinkTitles::processPage() for /// if the `--start` option is given) and call LinkTitles::processPage() for
/// each page. /// each page.
public function execute() { public function execute() {
global $wgLinkTitlesNamespaces;
$index = intval($this->getOption('start', 0)); $index = intval($this->getOption('start', 0));
if ( $index < 0 ) { if ( $index < 0 ) {
$this->error('FATAL: Start index must be 0 or greater.', 1); $this->error('FATAL: Start index must be 0 or greater.', 1);
}; };
// get our Namespaces
$namespacesClause = str_replace( '_', ' ','(' . implode( ', ',$wgLinkTitlesNamespaces ) . ')' );
// Connect to the database // Connect to the database
$dbr = $this->getDB( DB_SLAVE ); $dbr = $this->getDB( DB_SLAVE );
// Retrieve page names from the database. // Retrieve page names from the database.
$res = $dbr->select( $res = $dbr->select(
'page', 'page',
'page_title', array('page_title', 'page_namespace'),
array( array(
'page_namespace = 0', 'page_namespace IN ' . $namespacesClause,
), ),
__METHOD__, __METHOD__,
array( array(
@ -99,7 +104,7 @@ class LinkTitlesCli extends Maintenance {
// Iterate through the pages; break if a time limit is exceeded. // Iterate through the pages; break if a time limit is exceeded.
foreach ( $res as $row ) { foreach ( $res as $row ) {
$index += 1; $index += 1;
$curTitle = $row->page_title; $curTitle = Title::makeTitle( $row->page_namespace, $row->page_title);
$this->output( $this->output(
sprintf("\rPage #%d (%02.0f%%)", $index, $index / $numPages * 100) sprintf("\rPage #%d (%02.0f%%)", $index, $index / $numPages * 100)
); );

View File

@ -79,6 +79,10 @@ class SpecialLinkTitles extends SpecialPage {
/// @param OutputPage $output Output page for the special page. /// @param OutputPage $output Output page for the special page.
private function process( WebRequest &$request, OutputPage &$output) { private function process( WebRequest &$request, OutputPage &$output) {
global $wgLinkTitlesTimeLimit; global $wgLinkTitlesTimeLimit;
global $wgLinkTitlesNamespaces;
// get our Namespaces
$namespacesClause = str_replace( '_', ' ','(' . implode( ', ',$wgLinkTitlesNamespaces ) . ')' );
// Start the stopwatch // Start the stopwatch
$startTime = microtime(true); $startTime = microtime(true);
@ -111,9 +115,9 @@ class SpecialLinkTitles extends SpecialPage {
// Retrieve page names from the database. // Retrieve page names from the database.
$res = $dbr->select( $res = $dbr->select(
'page', 'page',
'page_title', array('page_title', 'page_namespace'),
array( array(
'page_namespace = 0', 'page_namespace IN ' . $namespacesClause,
), ),
__METHOD__, __METHOD__,
array( array(
@ -124,7 +128,7 @@ class SpecialLinkTitles extends SpecialPage {
// Iterate through the pages; break if a time limit is exceeded. // Iterate through the pages; break if a time limit is exceeded.
foreach ( $res as $row ) { foreach ( $res as $row ) {
$curTitle = $row->page_title; $curTitle = Title::makeTitle( $row->page_namespace, $row->page_title);
LinkTitles::processPage($curTitle, $this->getContext()); LinkTitles::processPage($curTitle, $this->getContext());
$start += 1; $start += 1;