Pergunta

I have an extension code that runs the hooks $wgHooks['ParserFirstCallInit'][] = 'AdsSetup'; $wgHooks['EditPage::showEditForm:initial'][] = 'CheckHasTag'; when you click edit on a page it will check the page using javascript for certain text, if it isn't there is adds a <Tag>.

Then you save the page and the tag is there. I have over 1,000 pages on my site. I don't want to have to click edit on each page to run the extension. Is there a way to mass edit the pages to run the extension?

I only want to run it on pages with the namespace = 'main' and I would like to exclude some pages.

This is my extension code:

<?php

  $wgHooks['ParserFirstCallInit'][] = 'AdsSetup';
  $wgHooks['EditPage::showEditForm:initial'][] = 'CheckHasTag';

function AdsSetup( &$parser ) {
    $parser->setHook( 'ads', 'AdsRender' );   return true;}

function AdsRender( $input, $args, $parser, $frame ) {

$output = '<div id="googlead"><script type="text/javascript">
google_ad_client = "xxx";
google_ad_width = 300;  google_ad_height = 250;
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>';
return array( $output, "markerType" => 'nowiki' );
  }
  // check if content has <googleAds1> tag
  function CheckHasTag($editPage){
global $wgOut;
$wgOut->addScript('<script type="text/javascript">
var editTextboxText = document.getElementById("wpTextbox1").value;
                var searchFor = "googleAds1";
                var searchResult = editTextboxText.search(searchFor);
        console.log("Testing console12");       
                if(searchResult == -1){
                var a = editTextboxText;
                var b = "\n<ads media=googleAds1 />\n";
                var findP = "\n"; 
                var p = editTextboxText.search(findP);
                var position = p;
    document.getElementById("wpTextbox1").value = a.substring(0, position) + b +  a.substring(position);
  } </script>');    return true; }

How do I run the extension without having to edit each page individually?

Foi útil?

Solução

Have you had a look at the Replace Text extension? That is an easy way to do a global search-and-replace in a certain namespace. The caveat is that it searches for the presence of a string or regex, rather than the absence.

There isn't enough detail in your description to know whether it's going to be possible to test for the absence of the string with a regex, but you might be able to do something like add <Tag> to all the pages, then search for pages containing <Tag> and your target string, and remove <Tag> from those pages.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top